This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
package redaction
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestStringRedactsSecretFixtures(t *testing.T) {
|
||||
input := "authorization=Bearer abc123 password=hunter2 token=secret-token endpoint=https://example"
|
||||
output := String(input)
|
||||
for _, secret := range []string{"abc123", "hunter2", "secret-token"} {
|
||||
if strings.Contains(output, secret) {
|
||||
t.Errorf("secret %q leaked in %q", secret, output)
|
||||
}
|
||||
}
|
||||
if !strings.Contains(output, "<redacted>") {
|
||||
t.Fatal("redaction marker missing")
|
||||
}
|
||||
}
|
||||
|
||||
func TestMapRedactsSensitiveKeysOnly(t *testing.T) {
|
||||
output := Map(map[string]any{"client_secret": "secret", "display_name": "Pulse"})
|
||||
if output["client_secret"] != replacement || output["display_name"] != "Pulse" {
|
||||
t.Fatalf("unexpected map: %#v", output)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user