40 lines
1.1 KiB
Go
40 lines
1.1 KiB
Go
package logredact
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestRedactText_JSONLike(t *testing.T) {
|
|
in := `{"access_token":"ya29.a0AfH6SMDUMMY","refresh_token":"1//0gDUMMY","other":"ok"}`
|
|
out := RedactText(in)
|
|
if out == in {
|
|
t.Fatalf("expected redaction, got unchanged")
|
|
}
|
|
if want := `"access_token":"***"`; !strings.Contains(out, want) {
|
|
t.Fatalf("expected %q in %q", want, out)
|
|
}
|
|
if want := `"refresh_token":"***"`; !strings.Contains(out, want) {
|
|
t.Fatalf("expected %q in %q", want, out)
|
|
}
|
|
}
|
|
|
|
func TestRedactText_QueryLike(t *testing.T) {
|
|
in := "access_token=ya29.a0AfH6SMDUMMY refresh_token=1//0gDUMMY"
|
|
out := RedactText(in)
|
|
if strings.Contains(out, "ya29") || strings.Contains(out, "1//0") {
|
|
t.Fatalf("expected tokens redacted, got %q", out)
|
|
}
|
|
}
|
|
|
|
func TestRedactText_GOCSPX(t *testing.T) {
|
|
in := "client_secret=GOCSPX-your-client-secret"
|
|
out := RedactText(in)
|
|
if strings.Contains(out, "your-client-secret") {
|
|
t.Fatalf("expected secret redacted, got %q", out)
|
|
}
|
|
if !strings.Contains(out, "client_secret=***") {
|
|
t.Fatalf("expected key redacted, got %q", out)
|
|
}
|
|
}
|