@@ -27,6 +27,67 @@ import (
27
27
"github.com/transparency-dev/static-ct/internal/x509util"
28
28
)
29
29
30
+ func TestParseOIDs (t * testing.T ) {
31
+ for _ , tc := range []struct {
32
+ desc string
33
+ oids []string
34
+ wantOIDs []asn1.ObjectIdentifier
35
+ wantErr bool
36
+ }{
37
+ {
38
+ desc : "empty" ,
39
+ oids : []string {},
40
+ wantOIDs : []asn1.ObjectIdentifier {},
41
+ wantErr : false ,
42
+ },
43
+ {
44
+ desc : "valid-single" ,
45
+ oids : []string {"1.2.3" },
46
+ wantOIDs : []asn1.ObjectIdentifier {[]int {1 , 2 , 3 }},
47
+ wantErr : false ,
48
+ },
49
+ {
50
+ desc : "valid-multiple" ,
51
+ oids : []string {"1.2.3" , "4.5.6" },
52
+ wantOIDs : []asn1.ObjectIdentifier {[]int {1 , 2 , 3 }, []int {4 , 5 , 6 }},
53
+ wantErr : false ,
54
+ },
55
+ {
56
+ desc : "invalid" ,
57
+ oids : []string {"1.2.a" },
58
+ wantOIDs : nil ,
59
+ wantErr : true ,
60
+ },
61
+ {
62
+ desc : "mixed-valid-invalid" ,
63
+ oids : []string {"1.2.3" , "1.2.a" },
64
+ wantOIDs : nil ,
65
+ wantErr : true ,
66
+ },
67
+ } {
68
+ t .Run (tc .desc , func (t * testing.T ) {
69
+ got , err := ParseOIDs (tc .oids )
70
+ if tc .wantErr {
71
+ if err == nil {
72
+ t .Errorf ("ParseOIDs(%v) = nil, want error" , tc .oids )
73
+ }
74
+ return
75
+ }
76
+ if err != nil {
77
+ t .Fatalf ("ParseOIDs(%v) = %v, want nil" , tc .oids , err )
78
+ }
79
+ if len (got ) != len (tc .wantOIDs ) {
80
+ t .Errorf ("ParseOIDs(%v) = %v, want %v" , tc .oids , got , tc .wantOIDs )
81
+ }
82
+ for i , e := range tc .wantOIDs {
83
+ if ! got [i ].Equal (e ) {
84
+ t .Errorf ("ParseOIDs(%v) = %v, want %v" , tc .oids , got , tc .wantOIDs )
85
+ }
86
+ }
87
+ })
88
+ }
89
+ }
90
+
30
91
func wipeExtensions (cert * x509.Certificate ) * x509.Certificate {
31
92
cert .Extensions = cert .Extensions [:0 ]
32
93
return cert
0 commit comments