feat(sync): full code sync from release

This commit is contained in:
yangjianbo
2026-02-28 15:01:20 +08:00
parent bfc7b339f7
commit bb664d9bbf
338 changed files with 54513 additions and 2011 deletions

View File

@@ -37,3 +37,48 @@ func TestRedactText_GOCSPX(t *testing.T) {
t.Fatalf("expected key redacted, got %q", out)
}
}
func TestRedactText_ExtraKeyCacheUsesNormalizedSortedKey(t *testing.T) {
clearExtraTextPatternCache()
out1 := RedactText("custom_secret=abc", "Custom_Secret", " custom_secret ")
out2 := RedactText("custom_secret=xyz", "custom_secret")
if !strings.Contains(out1, "custom_secret=***") {
t.Fatalf("expected custom key redacted in first call, got %q", out1)
}
if !strings.Contains(out2, "custom_secret=***") {
t.Fatalf("expected custom key redacted in second call, got %q", out2)
}
if got := countExtraTextPatternCacheEntries(); got != 1 {
t.Fatalf("expected 1 cached pattern set, got %d", got)
}
}
func TestRedactText_DefaultPathDoesNotUseExtraCache(t *testing.T) {
clearExtraTextPatternCache()
out := RedactText("access_token=abc")
if !strings.Contains(out, "access_token=***") {
t.Fatalf("expected default key redacted, got %q", out)
}
if got := countExtraTextPatternCacheEntries(); got != 0 {
t.Fatalf("expected extra cache to remain empty, got %d", got)
}
}
func clearExtraTextPatternCache() {
extraTextPatternCache.Range(func(key, value any) bool {
extraTextPatternCache.Delete(key)
return true
})
}
func countExtraTextPatternCacheEntries() int {
count := 0
extraTextPatternCache.Range(func(key, value any) bool {
count++
return true
})
return count
}