Files
traefik-llmgateway/sanitize_provider_err_residual_test.go
T
lukaszraczyloandGitHub f1b198bce4 fix(security): audit run-4 fixes and run-3 leftovers (#26)
Corrects passthrough metering, the cost gate, credential redaction, reload drain, response headers and the discovery cap.
2026-11-29 10:50:36 +00:00

45 lines
1.5 KiB
Go

package traefikllmgateway
import (
"errors"
"net/url"
"strings"
"testing"
)
func dialedErr(dialed string) string {
return (&url.Error{Op: "Get", URL: dialed, Err: errors.New("refused")}).Error()
}
func TestSanitizeProviderErr_ResidualShapes(t *testing.T) {
const base = "http://h.invalid:1/v1"
const dialedBase = "http://h.invalid:1/inserted/v1"
cases := []struct {
name, configured, dialed, leak string
}{
{"empty password username", "http://LONGSECRET1:@h.invalid:1/v1", "http://LONGSECRET1:@h.invalid:1/inserted/v1", "LONGSECRET1"},
{"lower-case percent escape", base + "?key=ABC%2FDEFGH", dialedBase + "?key=ABC%2fDEFGH", "DEFGH"},
{"valueless query key", base + "?LONGSECRET2", dialedBase + "?LONGSECRET2", "LONGSECRET2"},
{"semicolon separated", base + "?a=1;key=LONGSECRET3", dialedBase + "?a=1;key=LONGSECRET3", "LONGSECRET3"},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
got := sanitizeProviderErr(dialedErr(tc.dialed), tc.configured)
if strings.Contains(got, tc.leak) {
t.Fatalf("credential leaked: %q", got)
}
})
}
}
func TestSanitizeProviderErr_OverlappingSecretsDeterministic(t *testing.T) {
configured := "http://h.invalid:1/v1?a=LONGSECRET&b=LONGSECRET-EXTRA"
dialed := "http://h.invalid:1/inserted/v1?a=LONGSECRET&b=LONGSECRET-EXTRA"
for i := 0; i < 50; i++ {
got := sanitizeProviderErr(dialedErr(dialed), configured)
if strings.Contains(got, "EXTRA") || strings.Contains(got, "LONGSECRET") {
t.Fatalf("run %d: partial redaction left text behind: %q", i, got)
}
}
}