package main import ( "strings" "testing" ) func TestDatabaseURLLogMetadataRedactsPassword(t *testing.T) { rawURL := "postgres://alt:alt_secret_password@localhost:5432/alt?sslmode=disable" redacted := redactDatabaseURL(rawURL) if strings.Contains(redacted, "alt_secret_password") { t.Errorf("expected password to be redacted, but redacted string still contains password: %s", redacted) } expected := "postgres://alt:xxxxx@localhost:5432/alt?sslmode=disable" if redacted != expected { t.Errorf("redacted URL mismatch: got %q, want %q", redacted, expected) } } func TestDatabaseURLLogMetadataRejectsRawSecret(t *testing.T) { // Handles invalid URL format gracefully invalidURL := "postgres://a b" // spaces are invalid in url.Parse redacted := redactDatabaseURL(invalidURL) if redacted != "[invalid database url]" { t.Errorf("expected invalid URL to be handled gracefully, got %q", redacted) } }