apiserver/pkg/apis/config/validation: Add invalidURLErrFmt

In go1.14, the following change to 'net/url' was made:
"When parsing of a URL fails (for example by Parse or ParseRequestURI),
the resulting Error message will now quote the unparsable URL. This
provides clearer structure and consistency with other parsing errors."

Here we add a new const, 'invalidURLErrFmt' to properly handle the now
quoted string in validation_test.go.

ref: https://golang.org/doc/go1.14#net/url

Signed-off-by: Stephen Augustus <saugustus@vmware.com>
This commit is contained in:
Stephen Augustus 2020-04-18 04:37:22 -04:00
parent 236ef23f46
commit b0f17c2918
2 changed files with 2 additions and 1 deletions

View File

@ -31,6 +31,7 @@ const (
keyLenErrFmt = "secret is not of the expected length, got %d, expected one of %v" keyLenErrFmt = "secret is not of the expected length, got %d, expected one of %v"
unsupportedSchemeErrFmt = "unsupported scheme %q for KMS provider, only unix is supported" unsupportedSchemeErrFmt = "unsupported scheme %q for KMS provider, only unix is supported"
atLeastOneRequiredErrFmt = "at least one %s is required" atLeastOneRequiredErrFmt = "at least one %s is required"
invalidURLErrFmt = "invalid endpoint for kms provider, error: parse %s: net/url: invalid control character in URL"
mandatoryFieldErrFmt = "%s is a mandatory field for a %s" mandatoryFieldErrFmt = "%s is a mandatory field for a %s"
base64EncodingErr = "secrets must be base64 encoded" base64EncodingErr = "secrets must be base64 encoded"
zeroOrNegativeErrFmt = "%s should be a positive value" zeroOrNegativeErrFmt = "%s should be a positive value"

View File

@ -296,7 +296,7 @@ func TestKMSEndpoint(t *testing.T) {
desc: "invalid url", desc: "invalid url",
in: &config.KMSConfiguration{Endpoint: "unix:///foo\n.socket"}, in: &config.KMSConfiguration{Endpoint: "unix:///foo\n.socket"},
want: field.ErrorList{ want: field.ErrorList{
field.Invalid(endpointField, "unix:///foo\n.socket", "invalid endpoint for kms provider, error: parse unix:///foo\n.socket: net/url: invalid control character in URL"), field.Invalid(endpointField, "unix:///foo\n.socket", fmt.Sprintf(invalidURLErrFmt, `"unix:///foo\n.socket"`)),
}, },
}, },
} }