-
Notifications
You must be signed in to change notification settings - Fork 8.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update x509.CertPool equality checks (#2879)
Go 1.16 changed the CertPool implementation to employ functions to lazily acquire certificates. This change effectively breaks `reflect.DeepEqual` used by our test assertions. This commit changes the assertions compare certificate subjects instead of the entire pool. While not the same, it's a close approximation. See https://go-review.googlesource.com/c/go/+/229917 Signed-off-by: Matthew Sykes <[email protected]> Co-authored-by: Matthew Sykes <[email protected]>
- Loading branch information
Showing
2 changed files
with
13 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -125,38 +125,25 @@ func TestAddRootCA(t *testing.T) { | |
t.Parallel() | ||
|
||
caPEM, err := ioutil.ReadFile(filepath.Join("testdata", "certs", "Org1-cert.pem")) | ||
if err != nil { | ||
t.Fatalf("failed to read root certificate: %v", err) | ||
} | ||
|
||
cert := &x509.Certificate{ | ||
EmailAddresses: []string{"[email protected]"}, | ||
} | ||
require.NoError(t, err, "failed to read root certificate") | ||
|
||
expectedCertPool := x509.NewCertPool() | ||
ok := expectedCertPool.AppendCertsFromPEM(caPEM) | ||
if !ok { | ||
t.Fatalf("failed to create expected certPool") | ||
} | ||
require.True(t, ok, "failed to create expected certPool") | ||
|
||
cert := &x509.Certificate{EmailAddresses: []string{"[email protected]"}} | ||
expectedCertPool.AddCert(cert) | ||
|
||
certPool := x509.NewCertPool() | ||
ok = certPool.AppendCertsFromPEM(caPEM) | ||
if !ok { | ||
t.Fatalf("failed to create certPool") | ||
} | ||
require.True(t, ok, "failed to create certPool") | ||
|
||
tlsConfig := &tls.Config{ | ||
ClientCAs: certPool, | ||
} | ||
config := comm.NewTLSConfig(tlsConfig) | ||
|
||
require.Equal(t, config.Config().ClientCAs, certPool) | ||
config := comm.NewTLSConfig(&tls.Config{ClientCAs: certPool}) | ||
require.Same(t, config.Config().ClientCAs, certPool) | ||
|
||
// https://go-review.googlesource.com/c/go/+/229917 | ||
config.AddClientRootCA(cert) | ||
|
||
require.Equal(t, config.Config().ClientCAs, expectedCertPool, "The CertPools should be equal") | ||
require.Equal(t, certPool.Subjects(), expectedCertPool.Subjects(), "subjects in the pool should be equal") | ||
} | ||
|
||
func TestSetClientCAs(t *testing.T) { | ||
|