Fix: Hide config.SecretURL when the URL is incorrect. (#3887)

* fix: Hide config.SecretURL when the URL is incorrect.

    Updated the config.go to redact the URL.
    Added test cases to check URL stays hidden.
Signed-off-by: Kapil Ramwani(kanishkramwani6@gmail.com)

---------

Signed-off-by: Simon Pasquier <spasquie@redhat.com>
Co-authored-by: Simon Pasquier <spasquie@redhat.com>
This commit is contained in:
Kapil Ramwani 2024-06-21 19:49:06 +05:30 committed by GitHub
parent 52eb1fc4aa
commit 25def02a7f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 1 deletions

View File

@ -165,7 +165,12 @@ func (s *SecretURL) UnmarshalJSON(data []byte) error {
s.URL = &url.URL{} s.URL = &url.URL{}
return nil return nil
} }
return json.Unmarshal(data, (*URL)(s)) // Redact the secret URL in case of errors
if err := json.Unmarshal(data, (*URL)(s)); err != nil {
return errors.New(strings.ReplaceAll(err.Error(), string(data), "[REDACTED]"))
}
return nil
} }
// Load parses the YAML input s into a Config. // Load parses the YAML input s into a Config.

View File

@ -602,6 +602,15 @@ func TestUnmarshalSecretURL(t *testing.T) {
require.Equal(t, "http://example.com/se%20cret", u.String(), "SecretURL not properly unmarshaled in YAML.") require.Equal(t, "http://example.com/se%20cret", u.String(), "SecretURL not properly unmarshaled in YAML.")
} }
func TestHideSecretURL(t *testing.T) {
b := []byte(`"://wrongurl/"`)
var u SecretURL
err := json.Unmarshal(b, &u)
require.Error(t, err)
require.NotContains(t, err.Error(), "wrongurl")
}
func TestMarshalURL(t *testing.T) { func TestMarshalURL(t *testing.T) {
for name, tc := range map[string]struct { for name, tc := range map[string]struct {
input *URL input *URL