Sync and async sinks, redaction, and a queryable HTTP service keep concurrent logs tied to a trace id. Co-authored-by: Cursor <cursoragent@cursor.com>
37 lines
933 B
Go
37 lines
933 B
Go
package redact
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestBuiltinShapes(t *testing.T) {
|
|
r, err := New(nil)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
in := "token=eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxIn0.signatureX sk-abcdefghijklmnopqrstuvwxyz Bearer abcdefghijklmnop api_key=abcdefghijklmnop password=hunter2"
|
|
out := r.Apply(in)
|
|
for _, secret := range []string{"eyJhbGciOiJIUzI1NiJ9", "sk-abcdefghijklmnopqrstuvwxyz", "abcdefghijklmnop", "hunter2"} {
|
|
if strings.Contains(out, secret) {
|
|
t.Fatalf("leaked %s in %s", secret, out)
|
|
}
|
|
}
|
|
if !strings.Contains(out, "Bearer ***") || !strings.Contains(out, "password=***") {
|
|
t.Fatalf("markers missing: %s", out)
|
|
}
|
|
}
|
|
|
|
func TestExtraPattern(t *testing.T) {
|
|
r, err := New([]string{`session-[0-9]+`})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got := r.Apply("session-42"); got != "***" {
|
|
t.Fatal(got)
|
|
}
|
|
if _, err := New([]string{"("}); err == nil {
|
|
t.Fatal("expected bad pattern")
|
|
}
|
|
}
|