test(web): add test for maskAPIKey
This commit is contained in:
parent
f1ac1a1072
commit
66d2efc9d1
1 changed files with 53 additions and 0 deletions
|
|
@ -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|")
|
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)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue