eda033ff9b
Addresses errcheck, gosec, revive, staticcheck, and unused findings
across the codebase (unchecked error returns, unsafe file inclusion
warnings on operator/test-controlled paths, missing package comments,
unused parameters, deprecated API usage). Also fixes two suppression
comments that were silently no-ops due to wrong syntax (#nosec needs
a leading '#', nolint reasons need '//' not '--').
With the backlog clear, drop continue-on-error from the CI lint job
per the plan left in b4b4806.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
64 lines
1.9 KiB
Go
64 lines
1.9 KiB
Go
package config
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestSanitizeDatabaseURL(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
input string
|
|
expected string
|
|
}{
|
|
{ //nolint:gosec // test fixture URL, not a real credential
|
|
name: "PostgreSQL with password",
|
|
input: "postgresql://user:password@localhost:5432/dbname",
|
|
expected: "postgresql://user:***REDACTED***@localhost:5432/dbname",
|
|
},
|
|
{
|
|
name: "PostgreSQL without password",
|
|
input: "postgresql://user@localhost:5432/dbname",
|
|
expected: "postgresql://user@localhost:5432/dbname",
|
|
},
|
|
{ //nolint:gosec // test fixture URL, not a real credential
|
|
name: "MySQL with special characters in password",
|
|
input: "mysql://root:SuperSecret123!@db.example.com:3306/mydb",
|
|
expected: "mysql://root:***REDACTED***@db.example.com:3306/mydb",
|
|
},
|
|
{
|
|
name: "Empty URL",
|
|
input: "",
|
|
expected: "",
|
|
},
|
|
{
|
|
name: "Invalid URL without protocol",
|
|
input: "invalid-url",
|
|
expected: "invalid-url",
|
|
},
|
|
{
|
|
name: "URL without credentials",
|
|
input: "postgresql://localhost:5432/dbname",
|
|
expected: "postgresql://localhost:5432/dbname",
|
|
},
|
|
{ //nolint:gosec // test fixture URL, not a real credential
|
|
name: "PostgreSQL with password containing colons",
|
|
input: "postgresql://user:pass:word@localhost:5432/dbname",
|
|
expected: "postgresql://user:***REDACTED***@localhost:5432/dbname",
|
|
},
|
|
{ //nolint:gosec // test fixture URL, not a real credential
|
|
name: "PostgreSQL with complex hostname and port",
|
|
input: "postgresql://admin:p@ssw0rd!@db-prod.example.com:5432/production",
|
|
expected: "postgresql://admin:***REDACTED***@db-prod.example.com:5432/production",
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
result := SanitizeDatabaseURL(tt.input)
|
|
if result != tt.expected {
|
|
t.Errorf("SanitizeDatabaseURL(%q) = %q, want %q", tt.input, result, tt.expected)
|
|
}
|
|
})
|
|
}
|
|
}
|