mirror of
https://github.com/grafana/grafana.git
synced 2024-11-24 09:50:29 -06:00
Settings: Do not hide sensitive values if it's empty (#68088)
* Settings: Do not hide sensitive values if it's empty * Fix implementation * Add tests for RedactedValue function
This commit is contained in:
parent
e059ce9c8a
commit
0b6ae0d119
@ -561,6 +561,10 @@ func ToAbsUrl(relativeUrl string) string {
|
||||
}
|
||||
|
||||
func RedactedValue(key, value string) string {
|
||||
if value == "" {
|
||||
return ""
|
||||
}
|
||||
|
||||
uppercased := strings.ToUpper(key)
|
||||
// Sensitive information: password, secrets etc
|
||||
for _, pattern := range []string{
|
||||
|
@ -782,3 +782,37 @@ func TestAlertingEnabled(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestRedactedValue(t *testing.T) {
|
||||
testCases := []struct {
|
||||
desc string
|
||||
key string
|
||||
value string
|
||||
expected string
|
||||
}{
|
||||
{
|
||||
desc: "non-sensitive key",
|
||||
key: "admin_user",
|
||||
value: "admin",
|
||||
expected: "admin",
|
||||
},
|
||||
{
|
||||
desc: "sensitive key with non-empty value",
|
||||
key: "private_key_path",
|
||||
value: "/path/to/key",
|
||||
expected: RedactedPassword,
|
||||
},
|
||||
{
|
||||
desc: "sensitive key with empty value",
|
||||
key: "private_key_path",
|
||||
value: "",
|
||||
expected: "",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
require.Equal(t, tc.expected, RedactedValue(tc.key, tc.value))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user