From: Shengjing Zhu Date: Thu, 19 Jan 2023 11:12:56 +0800 Subject: Unwrap errors before checking x509.UnknownAuthorityError Go1.20 this errors is wrapped as tls.CertificateVerificationError --- testing/httpsuite_test.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/testing/httpsuite_test.go b/testing/httpsuite_test.go index c93e723..7e22e52 100644 --- a/testing/httpsuite_test.go +++ b/testing/httpsuite_test.go @@ -3,11 +3,10 @@ package testing_test import ( "crypto/tls" "crypto/x509" + "errors" "io/ioutil" gc "launchpad.net/gocheck" "net/http" - "net/url" - "reflect" "testing" jt "github.com/joyent/gocommon/testing" @@ -53,7 +52,7 @@ func (s *HTTPSTestSuite) TestHelloWorldWithTLS(c *gc.C) { response, err := http.Get(s.Server.URL) // Default http.Get fails because the cert is self-signed c.Assert(err, gc.NotNil) - c.Assert(reflect.TypeOf(err.(*url.Error).Err), gc.Equals, reflect.TypeOf(x509.UnknownAuthorityError{})) + c.Assert(errors.As(err, &x509.UnknownAuthorityError{}), gc.Equals, true) // Connect again with a Client that doesn't validate the cert insecureClient := &http.Client{Transport: &http.Transport{ TLSClientConfig: &tls.Config{InsecureSkipVerify: true}}}