Public source validation / validate (push) Failing after 3m8s
27 lines
760 B
Go
27 lines
760 B
Go
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)
|
|
}
|
|
}
|