Tolerate additional error messages in TLS unit tests

This commit is contained in:
Jordan Liggitt 2022-03-29 08:57:31 -04:00
parent 1ea07d482a
commit cff4eeef9f
2 changed files with 5 additions and 5 deletions

View File

@ -26,7 +26,7 @@ import (
"net/http/httptest"
"net/url"
"reflect"
"strings"
"regexp"
"testing"
"k8s.io/apimachinery/pkg/util/diff"
@ -56,7 +56,7 @@ func TestDialURL(t *testing.T) {
},
"secure, no roots": {
TLSConfig: &tls.Config{InsecureSkipVerify: false},
ExpectError: "unknown authority",
ExpectError: "unknown authority|not trusted",
},
"secure with roots": {
TLSConfig: &tls.Config{InsecureSkipVerify: false, RootCAs: roots},
@ -76,7 +76,7 @@ func TestDialURL(t *testing.T) {
"secure, no roots, custom dial": {
TLSConfig: &tls.Config{InsecureSkipVerify: false},
Dial: d.DialContext,
ExpectError: "unknown authority",
ExpectError: "unknown authority|not trusted",
},
"secure with roots, custom dial": {
TLSConfig: &tls.Config{InsecureSkipVerify: false, RootCAs: roots},
@ -154,7 +154,7 @@ func TestDialURL(t *testing.T) {
if tc.ExpectError == "" {
t.Errorf("%s: expected no error, got %q", k, err.Error())
}
if !strings.Contains(err.Error(), tc.ExpectError) {
if tc.ExpectError != "" && !regexp.MustCompile(tc.ExpectError).MatchString(err.Error()) {
t.Errorf("%s: expected error containing %q, got %q", k, tc.ExpectError, err.Error())
}
return

View File

@ -50,7 +50,7 @@ const (
errBadCertificate = "Get .*: remote error: tls: bad certificate"
errNoConfiguration = "invalid configuration: no configuration has been provided"
errMissingCertPath = "invalid configuration: unable to read %s %s for %s due to open %s: .*"
errSignedByUnknownCA = "Get .*: x509: certificate signed by unknown authority"
errSignedByUnknownCA = "Get .*: x509: .*(unknown authority|not standards compliant|not trusted)"
)
var (