Files
Enterprise-Knowledge-Base/internal/utils/log_sanitize_test.go
T
2026-07-16 00:17:16 +08:00

30 lines
875 B
Go

package utils
import (
"strings"
"testing"
)
func TestCompactImageDataURLForLogFullyRedactsImages(t *testing.T) {
cases := []string{
"data:image/png;base64,YWJj",
"DATA:image/png;BASE64," + strings.Repeat("QUJD", 100),
`{"image":"data:image\\/png;base64,TOPSECRET"}`,
"data:image/png,%89PNG%0D%0A",
"data:text/plain,NONIMAGESECRET",
"data%3Aimage%2Fpng%3Bbase64%2CENCODEDSECRET",
`data\u003aimage/png;base64,ESCAPEDSECRET`,
}
for _, raw := range cases {
got := CompactImageDataURLForLog(raw)
if !strings.Contains(got, "[image-data-redacted]") {
t.Fatalf("CompactImageDataURLForLog(%q) = %q", raw, got)
}
for _, secret := range []string{"YWJj", "QUJD", "TOPSECRET", "%89PNG", "NONIMAGESECRET", "ENCODEDSECRET", "ESCAPEDSECRET"} {
if strings.Contains(got, secret) {
t.Fatalf("sanitized output retained %q: %q", secret, got)
}
}
}
}