@@ -29,48 +29,56 @@ func TestParsePrivateKey(t *testing.T) {
29
29
assert .Equal (t , elliptic .P256 (), pkgt .Key .(* ecdsa.PrivateKey ).PublicKey .Curve )
30
30
}
31
31
32
- func TestCanSignHttpExchanges (t * testing.T ) {
32
+ func TestCanSignHttpExchangesExtension (t * testing.T ) {
33
+ // Before grace period, to allow the >90-day lifetime.
34
+ now := time .Date (2019 , time .July , 31 , 0 , 0 , 0 , 0 , time .UTC )
35
+
33
36
// Leaf node has the extension.
34
- assert .True (t , util .CanSignHttpExchanges (pkgt .Certs [0 ]))
37
+ assert .Nil (t , util .CanSignHttpExchanges (pkgt .Certs [0 ], now ))
35
38
// CA node does not.
36
- assert .False (t , util .CanSignHttpExchanges (pkgt .Certs [1 ]) )
39
+ assert .EqualError (t , util .CanSignHttpExchanges (pkgt .Certs [1 ], now ), "Certificate is missing CanSignHttpExchanges extension" )
37
40
}
38
41
39
42
func TestParseCertificate (t * testing.T ) {
40
- assert .Nil (t , util .CheckCertificate (pkgt .B3Certs [0 ], pkgt .B3Key , "amppackageexample.com" , time . Now () ))
43
+ assert .Nil (t , util .CertificateMatches (pkgt .B3Certs [0 ], pkgt .B3Key , "amppackageexample.com" ))
41
44
}
42
45
43
46
func TestParseCertificateSubjectAltName (t * testing.T ) {
44
- assert .Nil (t , util .CheckCertificate (pkgt .B3Certs [0 ], pkgt .B3Key , "www.amppackageexample.com" , time . Now () ))
47
+ assert .Nil (t , util .CertificateMatches (pkgt .B3Certs [0 ], pkgt .B3Key , "www.amppackageexample.com" ))
45
48
}
46
49
47
50
func TestParseCertificateNotMatchX (t * testing.T ) {
48
- assert .Contains (t , errorFrom (util .CheckCertificate (pkgt .B3Certs [0 ],
49
- pkgt .B3Key2 , "amppackageexample.com" , time . Now () )), "PublicKey.X not match" )
51
+ assert .Contains (t , errorFrom (util .CertificateMatches (pkgt .B3Certs [0 ],
52
+ pkgt .B3Key2 , "amppackageexample.com" )), "PublicKey.X not match" )
50
53
}
51
54
52
55
func TestParseCertificateNotMatchCurve (t * testing.T ) {
53
- assert .Contains (t , errorFrom (util .CheckCertificate (pkgt .B3Certs [0 ],
54
- pkgt .B3KeyP521 , "amppackageexample.com" , time . Now () )), "PublicKey.Curve not match" )
56
+ assert .Contains (t , errorFrom (util .CertificateMatches (pkgt .B3Certs [0 ],
57
+ pkgt .B3KeyP521 , "amppackageexample.com" )), "PublicKey.Curve not match" )
55
58
}
56
59
57
60
func TestParseCertificateNotMatchDomain (t * testing.T ) {
58
- assert .Contains (t , errorFrom (util .CheckCertificate (pkgt .B3Certs2 [0 ],
59
- pkgt .B3Key2 , "amppackageexample.com" , time .Now ())), "x509: certificate is valid for amppackageexample2.com, www.amppackageexample2.com, not amppackageexample.com" )
61
+ assert .Contains (t , errorFrom (util .CertificateMatches (pkgt .B3Certs2 [0 ],
62
+ pkgt .B3Key2 , "amppackageexample.com" )), "x509: certificate is valid for amppackageexample2.com, www.amppackageexample2.com, not amppackageexample.com" )
63
+ }
64
+
65
+ func TestParse90DaysCertificateAfterGracePeriod (t * testing.T ) {
66
+ now := time .Date (2019 , time .August , 1 , 0 , 0 , 0 , 1 , time .UTC )
67
+ assert .Nil (t , util .CanSignHttpExchanges (pkgt .B3Certs [0 ], now ))
60
68
}
61
69
62
70
func TestParse91DaysCertificate (t * testing.T ) {
63
- assert .Contains (t , errorFrom (util .CheckCertificate (pkgt .B3Certs91Days [0 ],
64
- pkgt . B3Key , "amppackageexample.com" , time .Now ())), "Certificate MUST have a Validity Period no greater than 90 days" )
71
+ assert .Contains (t , errorFrom (util .CanSignHttpExchanges (pkgt .B3Certs91Days [0 ],
72
+ time .Now ())), "Certificate MUST have a Validity Period no greater than 90 days" )
65
73
}
66
74
67
75
func TestParseCertificateIssuedBeforeMay1InGarcePeriod (t * testing.T ) {
68
76
now := time .Date (2019 , time .July , 31 , 0 , 0 , 0 , 0 , time .UTC )
69
- assert .Nil (t , util .CheckCertificate (pkgt .Certs [0 ], pkgt . Key , "amppackageexample.com" , now ))
77
+ assert .Nil (t , util .CanSignHttpExchanges (pkgt .Certs [0 ], now ))
70
78
}
71
79
72
80
func TestParseCertificateIssuedBeforeMay1AfterGracePeriod (t * testing.T ) {
73
81
now := time .Date (2019 , time .August , 1 , 0 , 0 , 0 , 1 , time .UTC )
74
- assert .Contains (t , errorFrom (util .CheckCertificate (pkgt .Certs [0 ],
75
- pkgt . Key , "amppackageexample.com" , now )), "Certificate MUST have a Validity Period no greater than 90 days" )
82
+ assert .Contains (t , errorFrom (util .CanSignHttpExchanges (pkgt .Certs [0 ],
83
+ now )), "Certificate MUST have a Validity Period no greater than 90 days" )
76
84
}
0 commit comments