Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 16 additions & 13 deletions pkg/lipsdk/auth/sanitize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,28 @@ func TestSanitizePublicChallengeSummary(t *testing.T) {
t.Parallel()
fb := "fallback-msg"
cases := []struct {
name string
in string
want string
name string
in string
maxRunes int
want string
}{
{"empty uses fallback", "", fb},
{"whitespace uses fallback", " \t ", fb},
{"plain short unchanged", "Sign in to continue.", "Sign in to continue."},
{"collapses internal space", "a \tb", "a b"},
{"strips controls", "line1\x00line2", "line1 line2"},
{"bearer triggers fallback", "Please use Bearer sk-abc", fb},
{"access_token triggers fallback", "Open https://x?access_token=secret", fb},
{"long truncates", strings.Repeat("x", 400), strings.Repeat("x", 254) + "…"},
{"empty uses fallback", "", 255, fb},
{"whitespace uses fallback", " \t ", 255, fb},
{"plain short unchanged", "Sign in to continue.", 255, "Sign in to continue."},
{"collapses internal space", "a \tb", 255, "a b"},
{"strips controls", "line1\x00line2", 255, "line1 line2"},
{"bearer triggers fallback", "Please use Bearer sk-abc", 255, fb},
{"access_token triggers fallback", "Open https://x?access_token=secret", 255, fb},
{"long truncates", strings.Repeat("x", 400), 255, strings.Repeat("x", 254) + "…"},
{"zero maxRunes defaults to 256", strings.Repeat("x", 400), 0, strings.Repeat("x", 255) + "…"},
{"negative maxRunes defaults to 256", strings.Repeat("x", 400), -1, strings.Repeat("x", 255) + "…"},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
got := SanitizePublicChallengeSummary(tc.in, fb, 255)
got := SanitizePublicChallengeSummary(tc.in, fb, tc.maxRunes)
if got != tc.want {
t.Fatalf("SanitizePublicChallengeSummary(%q) = %q, want %q", tc.in, got, tc.want)
t.Fatalf("SanitizePublicChallengeSummary(%q, %d) = %q, want %q", tc.in, tc.maxRunes, got, tc.want)
}
})
}
Expand Down