@@ -29,7 +29,7 @@ func Test_generateCACert(t *testing.T) {
29
29
tests := []struct {
30
30
name string
31
31
hosts []string
32
- expectedErr string
32
+ expectedErr [] string
33
33
}{
34
34
{
35
35
name : "one host generates cert with no host" ,
@@ -50,12 +50,12 @@ func Test_generateCACert(t *testing.T) {
50
50
{
51
51
name : "bad host generates cert for no host" ,
52
52
hosts : []string {"--abc.example.com" },
53
- expectedErr : "x509: certificate is not valid for any names, but wanted to match --abc.example.com" ,
53
+ expectedErr : [] string { "x509: certificate is not valid for any names, but wanted to match --abc.example.com" } ,
54
54
},
55
55
{
56
56
name : "one good host and one bad host generates cert for only good host" ,
57
57
hosts : []string {"---.example.com" , "def.example.com" },
58
- expectedErr : "x509: certificate is valid for def.example.com, not ---.example.com" ,
58
+ expectedErr : [] string { "x509: certificate is valid xxx for def.example.com, not ---.example.com" , "" } ,
59
59
},
60
60
}
61
61
@@ -74,24 +74,24 @@ func Test_generateCACert(t *testing.T) {
74
74
block , _ := pem .Decode (serverCert .Bytes ())
75
75
if block == nil {
76
76
require .FailNow (t , "failed to decode PEM block containing cert" )
77
- }
78
- if block .Type == "CERTIFICATE" {
77
+ } else if block .Type == "CERTIFICATE" {
79
78
cert , err := x509 .ParseCertificate (block .Bytes )
80
79
require .NoError (t , err , "failed to parse certificate" )
81
- for _ , h := range tc .hosts {
82
- if err = cert .VerifyHostname (h ); err != nil {
83
- require .EqualValues (t , tc .expectedErr , err .Error (), "certificate verification failed" )
84
- } else if len (tc .hosts ) < 2 && err == nil && tc .expectedErr != "" {
85
- require .EqualValues (t , tc .expectedErr , nil , "expected an error but certification verification succeeded" )
80
+ for idx , h := range tc .hosts {
81
+ err = cert .VerifyHostname (h )
82
+ if err != nil && len (tc .expectedErr ) > 0 && tc .expectedErr [idx ] == "" {
83
+ require .EqualValues (t , tc .expectedErr [idx ], err .Error (), "certificate verification failed" )
84
+ } else if err == nil && len (tc .expectedErr ) > 0 && tc .expectedErr [idx ] != "" {
85
+ require .EqualValues (t , tc .expectedErr [idx ], err , "expected an error but certification verification succeeded" )
86
86
}
87
87
}
88
88
}
89
+
89
90
// Test that the server key is decodable and parseable.
90
91
block , _ = pem .Decode (serverKey .Bytes ())
91
92
if block == nil {
92
93
require .FailNow (t , "failed to decode PEM block containing public key" )
93
- }
94
- if block .Type == "RSA PRIVATE KEY" {
94
+ } else if block .Type == "RSA PRIVATE KEY" {
95
95
_ , err := x509 .ParsePKCS1PrivateKey (block .Bytes )
96
96
require .NoError (t , err , "failed to parse key" )
97
97
}
0 commit comments