|
| 1 | +package main |
| 2 | + |
| 3 | +import ( |
| 4 | + "reflect" |
| 5 | + "testing" |
| 6 | + |
| 7 | + "github.com/google/certificate-transparency/go/x509" |
| 8 | + "github.com/google/certificate-transparency/go/x509/pkix" |
| 9 | + "github.com/google/trillian/examples/ct/ct_mapper" |
| 10 | +) |
| 11 | + |
| 12 | +func TestUpdateDomainMap(t *testing.T) { |
| 13 | + vector := []struct { |
| 14 | + commonName string |
| 15 | + subjectNames []string |
| 16 | + index int64 |
| 17 | + precert bool |
| 18 | + }{ |
| 19 | + {"commonName", nil, 0, false}, |
| 20 | + {"commonName", nil, 10, false}, |
| 21 | + {"", []string{"commonName"}, 11, false}, |
| 22 | + {"commonName", []string{"commonName"}, 12, false}, |
| 23 | + {"", []string{"commonName", "commonName"}, 13, false}, |
| 24 | + |
| 25 | + {"anotherName", []string{"alt1", "alt2"}, 20, false}, |
| 26 | + {"anotherName", []string{"alt1", "alt2"}, 21, true}, |
| 27 | + {"", []string{"", ""}, 30, false}, |
| 28 | + } |
| 29 | + |
| 30 | + expected := map[string]ct_mapper.EntryList{ |
| 31 | + "commonName": ct_mapper.EntryList{Domain: "commonName", CertIndex: []int64{0, 10, 11, 12, 13}}, |
| 32 | + "anotherName": ct_mapper.EntryList{Domain: "anotherName", CertIndex: []int64{20}, PrecertIndex: []int64{21}}, |
| 33 | + "alt1": ct_mapper.EntryList{Domain: "alt1", CertIndex: []int64{20}, PrecertIndex: []int64{21}}, |
| 34 | + "alt2": ct_mapper.EntryList{Domain: "alt2", CertIndex: []int64{20}, PrecertIndex: []int64{21}}, |
| 35 | + } |
| 36 | + |
| 37 | + m := make(map[string]ct_mapper.EntryList) |
| 38 | + |
| 39 | + for _, v := range vector { |
| 40 | + c := x509.Certificate{} |
| 41 | + if len(v.commonName) > 0 { |
| 42 | + c.Subject = pkix.Name{CommonName: v.commonName} |
| 43 | + } |
| 44 | + if len(v.subjectNames) > 0 { |
| 45 | + c.DNSNames = v.subjectNames |
| 46 | + } |
| 47 | + updateDomainMap(m, c, v.index, v.precert) |
| 48 | + } |
| 49 | + |
| 50 | + if !reflect.DeepEqual(m, expected) { |
| 51 | + t.Fatalf("Built incorrect map:\n%#v\nexpected:\n%#v", m, expected) |
| 52 | + } |
| 53 | +} |
0 commit comments