(t *testing.T)
| 53 | } |
| 54 | |
| 55 | func TestCacheCertificate(t *testing.T) { |
| 56 | certCache := &Cache{cache: make(map[string]Certificate), cacheIndex: make(map[string][]string), logger: defaultTestLogger} |
| 57 | |
| 58 | certCache.cacheCertificate(Certificate{Names: []string{"example.com", "sub.example.com"}, hash: "foobar", Certificate: tls.Certificate{Leaf: &x509.Certificate{NotAfter: time.Now()}}}) |
| 59 | if len(certCache.cache) != 1 { |
| 60 | t.Errorf("Expected length of certificate cache to be 1") |
| 61 | } |
| 62 | if _, ok := certCache.cache["foobar"]; !ok { |
| 63 | t.Error("Expected first cert to be cached by key 'foobar', but it wasn't") |
| 64 | } |
| 65 | if _, ok := certCache.cacheIndex["example.com"]; !ok { |
| 66 | t.Error("Expected first cert to be keyed by 'example.com', but it wasn't") |
| 67 | } |
| 68 | if _, ok := certCache.cacheIndex["sub.example.com"]; !ok { |
| 69 | t.Error("Expected first cert to be keyed by 'sub.example.com', but it wasn't") |
| 70 | } |
| 71 | |
| 72 | // using same cache; and has cert with overlapping name, but different hash |
| 73 | certCache.cacheCertificate(Certificate{Names: []string{"example.com"}, hash: "barbaz", Certificate: tls.Certificate{Leaf: &x509.Certificate{NotAfter: time.Now()}}}) |
| 74 | if _, ok := certCache.cache["barbaz"]; !ok { |
| 75 | t.Error("Expected second cert to be cached by key 'barbaz.com', but it wasn't") |
| 76 | } |
| 77 | if hashes, ok := certCache.cacheIndex["example.com"]; !ok { |
| 78 | t.Error("Expected second cert to be keyed by 'example.com', but it wasn't") |
| 79 | } else if !reflect.DeepEqual(hashes, []string{"foobar", "barbaz"}) { |
| 80 | t.Errorf("Expected second cert to map to 'barbaz' but it was %v instead", hashes) |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | func TestSubjectQualifiesForCert(t *testing.T) { |
| 85 | for i, test := range []struct { |
nothing calls this directly
no test coverage detected
searching dependent graphs…