...
1 package main
2
3 import (
4 "crypto"
5 "testing"
6
7 "github.com/letsencrypt/boulder/core"
8 "github.com/letsencrypt/boulder/test"
9 )
10
11 func TestKeyBlocking(t *testing.T) {
12 testCases := []struct {
13 name string
14 certPath string
15 jwkPath string
16 expected string
17 }{
18
19
20
21
22 {
23 name: "P-256 ECDSA JWK",
24 jwkPath: "test/test.ecdsa.jwk.json",
25 expected: "cuwGhNNI6nfob5aqY90e7BleU6l7rfxku4X3UTJ3Z7M=",
26 },
27 {
28 name: "2048 RSA JWK",
29 jwkPath: "test/test.rsa.jwk.json",
30 expected: "Qebc1V3SkX3izkYRGNJilm9Bcuvf0oox4U2Rn+b4JOE=",
31 },
32 {
33 name: "P-256 ECDSA Certificate",
34 certPath: "test/test.ecdsa.cert.pem",
35 expected: "cuwGhNNI6nfob5aqY90e7BleU6l7rfxku4X3UTJ3Z7M=",
36 },
37 {
38 name: "2048 RSA Certificate",
39 certPath: "test/test.rsa.cert.pem",
40 expected: "Qebc1V3SkX3izkYRGNJilm9Bcuvf0oox4U2Rn+b4JOE=",
41 },
42 }
43
44 for _, tc := range testCases {
45 t.Run(tc.name, func(t *testing.T) {
46 var key crypto.PublicKey
47 var err error
48 if tc.jwkPath != "" {
49 key, err = keyFromJWK(tc.jwkPath)
50 } else {
51 key, err = keyFromCert(tc.certPath)
52 }
53 test.AssertNotError(t, err, "error getting key from input file")
54 spkiHash, err := core.KeyDigestB64(key)
55 test.AssertNotError(t, err, "error computing spki hash")
56 test.AssertEquals(t, spkiHash, tc.expected)
57 })
58 }
59 }
60
View as plain text