...
1
2
3
4
5
6
7
8
9
10
11
12
13
14 package ctpolicy
15
16 import (
17 "testing"
18
19 "github.com/google/certificate-transparency-go/x509"
20
21 "github.com/kylelemons/godebug/pretty"
22 )
23
24 func wantedAppleGroups(count int) LogPolicyData {
25 gi := LogPolicyData{
26 BaseName: {
27 Name: BaseName,
28 LogURLs: map[string]bool{
29 "https://ct.googleapis.com/aviator/": true,
30 "https://ct.googleapis.com/icarus/": true,
31 "https://ct.googleapis.com/rocketeer/": true,
32 "https://ct.googleapis.com/racketeer/": true,
33 "https://ct.googleapis.com/logs/argon2020/": true,
34 "https://log.bob.io": true,
35 },
36 MinInclusions: count,
37 IsBase: true,
38 LogWeights: map[string]float32{
39 "https://ct.googleapis.com/aviator/": 1.0,
40 "https://ct.googleapis.com/icarus/": 1.0,
41 "https://ct.googleapis.com/rocketeer/": 1.0,
42 "https://ct.googleapis.com/racketeer/": 1.0,
43 "https://ct.googleapis.com/logs/argon2020/": 1.0,
44 "https://log.bob.io": 1.0,
45 },
46 },
47 }
48 return gi
49 }
50
51 func TestCheckApplePolicy(t *testing.T) {
52 tests := []struct {
53 name string
54 cert *x509.Certificate
55 want LogPolicyData
56 }{
57 {
58 name: "Short",
59 cert: getTestCertPEMShort(),
60 want: wantedAppleGroups(2),
61 },
62 {
63 name: "2-year",
64 cert: getTestCertPEM2Years(),
65 want: wantedAppleGroups(3),
66 },
67 {
68 name: "3-year",
69 cert: getTestCertPEM3Years(),
70 want: wantedAppleGroups(4),
71 },
72 {
73 name: "Long",
74 cert: getTestCertPEMLongOriginal(),
75 want: wantedAppleGroups(5),
76 },
77 }
78
79 var policy AppleCTPolicy
80 sampleLogList := sampleLogList(t)
81
82 for _, test := range tests {
83 t.Run(test.name, func(t *testing.T) {
84 groups, err := policy.LogsByGroup(test.cert, sampleLogList)
85 if err != nil {
86 t.Errorf("LogsByGroup returned an error: %v", err)
87 }
88 if diff := pretty.Compare(test.want, groups); diff != "" {
89 t.Errorf("LogsByGroup: (-want +got)\n%s", diff)
90 }
91 })
92 }
93 }
94
View as plain text