mirror of https://github.com/status-im/consul.git
connect: fix test for go1.16
There is no way to compare x509.CertPools now that it has an unexpected function field. This comparison is as close as we can get. See https://github.com/golang/go/issues/26614 for a related issue.
This commit is contained in:
parent
66567f4bc0
commit
3e20bd25bd
|
@ -6,13 +6,15 @@ import (
|
||||||
"encoding/pem"
|
"encoding/pem"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/hashicorp/consul/sdk/testutil"
|
"github.com/google/go-cmp/cmp"
|
||||||
"github.com/hashicorp/consul/testrpc"
|
"github.com/google/go-cmp/cmp/cmpopts"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/hashicorp/consul/agent"
|
"github.com/hashicorp/consul/agent"
|
||||||
"github.com/hashicorp/consul/agent/connect"
|
"github.com/hashicorp/consul/agent/connect"
|
||||||
"github.com/hashicorp/consul/api"
|
"github.com/hashicorp/consul/api"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/hashicorp/consul/sdk/testutil"
|
||||||
|
"github.com/hashicorp/consul/testrpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Test_verifyServerCertMatchesURI(t *testing.T) {
|
func Test_verifyServerCertMatchesURI(t *testing.T) {
|
||||||
|
@ -266,7 +268,7 @@ func TestServerSideVerifier(t *testing.T) {
|
||||||
func requireEqualTLSConfig(t *testing.T, expect, got *tls.Config) {
|
func requireEqualTLSConfig(t *testing.T, expect, got *tls.Config) {
|
||||||
require := require.New(t)
|
require := require.New(t)
|
||||||
require.Equal(expect.RootCAs, got.RootCAs)
|
require.Equal(expect.RootCAs, got.RootCAs)
|
||||||
require.Equal(expect.ClientCAs, got.ClientCAs)
|
assertDeepEqual(t, expect.ClientCAs, got.ClientCAs, cmpCertPool)
|
||||||
require.Equal(expect.InsecureSkipVerify, got.InsecureSkipVerify)
|
require.Equal(expect.InsecureSkipVerify, got.InsecureSkipVerify)
|
||||||
require.Equal(expect.MinVersion, got.MinVersion)
|
require.Equal(expect.MinVersion, got.MinVersion)
|
||||||
require.Equal(expect.CipherSuites, got.CipherSuites)
|
require.Equal(expect.CipherSuites, got.CipherSuites)
|
||||||
|
@ -293,6 +295,19 @@ func requireEqualTLSConfig(t *testing.T, expect, got *tls.Config) {
|
||||||
require.Equal(expectLeaf, gotLeaf)
|
require.Equal(expectLeaf, gotLeaf)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// lazyCerts has a func field which can't be compared.
|
||||||
|
var cmpCertPool = cmp.Options{
|
||||||
|
cmpopts.IgnoreFields(x509.CertPool{}, "lazyCerts"),
|
||||||
|
cmp.AllowUnexported(x509.CertPool{}),
|
||||||
|
}
|
||||||
|
|
||||||
|
func assertDeepEqual(t *testing.T, x, y interface{}, opts ...cmp.Option) {
|
||||||
|
t.Helper()
|
||||||
|
if diff := cmp.Diff(x, y, opts...); diff != "" {
|
||||||
|
t.Fatalf("assertion failed: values are not equal\n--- expected\n+++ actual\n%v", diff)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// requireCorrectVerifier invokes got.VerifyPeerCertificate and expects the
|
// requireCorrectVerifier invokes got.VerifyPeerCertificate and expects the
|
||||||
// tls.Config arg to be returned on the provided channel. This ensures the
|
// tls.Config arg to be returned on the provided channel. This ensures the
|
||||||
// correct verifier func was attached to got.
|
// correct verifier func was attached to got.
|
||||||
|
|
Loading…
Reference in New Issue