Add gostringer to client_secret (#1315)

This commit is contained in:
Louis Ruch authored and GitHub committed 2021-06-16 11:44:08 -07:00
1 parent 8e4323c31c
commit 466219f109
2 files changed
+25 -2

No files matched your search

+5
View File
@@ -16,6 +16,11 @@ func (s ClientSecret) String() string {
return redactedClientSecret
}
// GoString will redact the client_secret.
func (s ClientSecret) GoString() string {
return redactedClientSecret
}
// MarshalJSON will redact the client_secret.
func (s ClientSecret) MarshalJSON() ([]byte, error) {
return json.Marshal(redactedClientSecret)
+20 -2
View File
@@ -14,7 +14,25 @@ func TestClientSecret_String(t *testing.T) {
assert := assert.New(t)
const want = redactedClientSecret
tk := ClientSecret("super secret token")
assert.Equalf(want, tk.String(), "AccessToken.String() = %v, want %v", tk.String(), want)
assert.Equalf(want, tk.String(), "ClientSecret.String() = %v, want %v", tk.String(), want)
// Verify stringer is called
s := fmt.Sprintf("%#v", tk)
assert.Equalf(want, s, "ClientSecret.String() = %v, want %v", s, want)
})
}
func TestClientSecret_GoString(t *testing.T) {
t.Parallel()
t.Run("redacted", func(t *testing.T) {
assert := assert.New(t)
const want = redactedClientSecret
tk := ClientSecret("super secret token")
assert.Equalf(want, tk.GoString(), "ClientSecret.GoString() = %v, want %v", tk.GoString(), want)
// Verify gostringer is called
s := fmt.Sprintf("%#v", tk)
assert.Equalf(want, s, "ClientSecret.GoString() = %v, want %v", s, want)
})
}
@@ -26,6 +44,6 @@ func TestClientSecret_MarshalJSON(t *testing.T) {
tk := ClientSecret("super secret token")
got, err := tk.MarshalJSON()
require.NoError(err)
assert.Equalf([]byte(want), got, "AccessToken.MarshalJSON() = %s, want %s", got, want)
assert.Equalf([]byte(want), got, "ClientSecret.MarshalJSON() = %s, want %s", got, want)
})
}