Files
clawgo/pkg/agent/loop_secret_test.go
2026-02-19 21:11:27 +08:00

27 lines
751 B
Go

package agent
import "testing"
func TestRedactSecretsInText(t *testing.T) {
in := `{"token":"abc123","authorization":"Bearer sk-xyz","password":"p@ss","note":"ok"}`
out := redactSecretsInText(in)
if out == in {
t.Fatalf("expected redaction to change input")
}
if containsAnySubstring(out, "abc123", "sk-xyz", "p@ss") {
t.Fatalf("expected sensitive values to be redacted, got: %s", out)
}
}
func TestSanitizeSensitiveToolArgs(t *testing.T) {
args := map[string]interface{}{
"command": "git -c http.extraHeader='Authorization: token abc123' ls-remote https://example.com/repo.git",
"token": "abc123",
}
safe := sanitizeSensitiveToolArgs(args)
if safe["token"] == "abc123" {
t.Fatalf("expected token field to be redacted")
}
}