mirror of
https://github.com/Noooste/garage-ui.git
synced 2026-08-05 11:47:41 +00:00
dd275d2e78
Signed-off-by: Noooste <83548733+Noooste@users.noreply.github.com>
33 lines
799 B
Go
33 lines
799 B
Go
package logger
|
|
|
|
import "testing"
|
|
|
|
func TestRedactKey(t *testing.T) {
|
|
cases := []struct {
|
|
name string
|
|
in string
|
|
want string
|
|
}{
|
|
{"empty", "", "***"},
|
|
{"short", "abc", "***"},
|
|
{"just-under-threshold", "abcdefghijk", "***"}, // 11 chars
|
|
{"at-threshold", "abcdefghijkl", "abcd…ijkl"}, // 12 chars
|
|
{"long", "GK5a9bfcdefghijklzW9q", "GK5a…zW9q"},
|
|
}
|
|
for _, tc := range cases {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
if got := RedactKey(tc.in); got != tc.want {
|
|
t.Errorf("RedactKey(%q) = %q, want %q", tc.in, got, tc.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestRedactToken_AlwaysStars(t *testing.T) {
|
|
for _, in := range []string{"", "abc", "very-long-secret-token-value"} {
|
|
if got := RedactToken(in); got != "***" {
|
|
t.Errorf("RedactToken(%q) = %q, want ***", in, got)
|
|
}
|
|
}
|
|
}
|