mirror of
https://github.com/sipeed/picoclaw.git
synced 2026-06-12 18:08:54 +00:00
test(web): add test for maskAPIKey
This commit is contained in:
@@ -315,3 +315,56 @@ func TestHandleListModels_NormalizesWildcardLocalAPIBaseForProbe(t *testing.T) {
|
||||
t.Fatalf("probe api base = %q, want %q", gotProbe, "http://127.0.0.1:8000/v1|custom-model|")
|
||||
}
|
||||
}
|
||||
|
||||
func TestMaskAPIKey(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
key string
|
||||
want string
|
||||
}{
|
||||
{
|
||||
name: "empty key",
|
||||
key: "",
|
||||
want: "",
|
||||
},
|
||||
{
|
||||
name: "short key fully masked",
|
||||
key: "abcd",
|
||||
want: "****",
|
||||
},
|
||||
{
|
||||
name: "length 8 boundary fully masked",
|
||||
key: "12345678",
|
||||
want: "****",
|
||||
},
|
||||
{
|
||||
name: "length 9 boundary shows last 2",
|
||||
key: "123456789",
|
||||
want: "123****89",
|
||||
},
|
||||
{
|
||||
name: "length 12 boundary shows last 2",
|
||||
key: "abcdefghijkl",
|
||||
want: "abc****kl",
|
||||
},
|
||||
{
|
||||
name: "length 13 boundary shows last 4",
|
||||
key: "abcdefghijklm",
|
||||
want: "abc****jklm",
|
||||
},
|
||||
{
|
||||
name: "typical api key",
|
||||
key: "sk-1234567890abcd",
|
||||
want: "sk-****abcd",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range tests {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
got := maskAPIKey(tc.key)
|
||||
if got != tc.want {
|
||||
t.Fatalf("maskAPIKey(%q) = %q, want %q", tc.key, got, tc.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user