github.com/mre-fog/trillianxx@v1.1.2-0.20180615153820-ae375a99d36a/examples/ct/ctmapper/mapper/mapper_test.go (about) 1 // Copyright 2016 Google Inc. All Rights Reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package main 16 17 import ( 18 "testing" 19 20 "github.com/google/certificate-transparency-go/x509" 21 "github.com/google/certificate-transparency-go/x509/pkix" 22 "github.com/google/trillian/examples/ct/ctmapper/ctmapperpb" 23 "github.com/kylelemons/godebug/pretty" 24 ) 25 26 func TestUpdateDomainMap(t *testing.T) { 27 vector := []struct { 28 commonName string 29 subjectNames []string 30 index int64 31 precert bool 32 }{ 33 {"commonName", nil, 0, false}, 34 {"commonName", nil, 10, false}, 35 {"", []string{"commonName"}, 11, false}, 36 {"commonName", []string{"commonName"}, 12, false}, 37 {"", []string{"commonName", "commonName"}, 13, false}, 38 39 {"anotherName", []string{"alt1", "alt2"}, 20, false}, 40 {"anotherName", []string{"alt1", "alt2"}, 21, true}, 41 {"", []string{"", ""}, 30, false}, 42 } 43 44 expected := map[string]ctmapperpb.EntryList{ 45 "commonName": {Domain: "commonName", CertIndex: []int64{0, 10, 11, 12, 13}}, 46 "anotherName": {Domain: "anotherName", CertIndex: []int64{20}, PrecertIndex: []int64{21}}, 47 "alt1": {Domain: "alt1", CertIndex: []int64{20}, PrecertIndex: []int64{21}}, 48 "alt2": {Domain: "alt2", CertIndex: []int64{20}, PrecertIndex: []int64{21}}, 49 } 50 51 m := make(map[string]ctmapperpb.EntryList) 52 53 for _, v := range vector { 54 c := x509.Certificate{} 55 if len(v.commonName) > 0 { 56 c.Subject = pkix.Name{CommonName: v.commonName} 57 } 58 if len(v.subjectNames) > 0 { 59 c.DNSNames = v.subjectNames 60 } 61 updateDomainMap(m, c, v.index, v.precert) 62 } 63 64 if diff := pretty.Compare(m, expected); diff != "" { 65 t.Fatalf("Built incorrect map, diff:\n%v", diff) 66 } 67 }