@@ -224,3 +224,51 @@ func TestGetCommandType(t *testing.T) {
224224 })
225225 }
226226}
227+
228+ func TestRedactConnectionString (t * testing.T ) {
229+ tests := []struct {
230+ name string
231+ input string
232+ expected string
233+ }{
234+ {
235+ name : "postgres connection string with password" ,
236+ input : "postgres:host=localhost user=postgres password=secretpass dbname=ducklake" ,
237+ expected : "postgres:host=localhost user=postgres password=[REDACTED] dbname=ducklake" ,
238+ },
239+ {
240+ name : "connection string with password= format" ,
241+ input : "host=localhost password=mysecret user=admin" ,
242+ expected : "host=localhost password=[REDACTED] user=admin" ,
243+ },
244+ {
245+ name : "connection string with PASSWORD uppercase" ,
246+ input : "host=localhost PASSWORD=mysecret user=admin" ,
247+ expected : "host=localhost PASSWORD=[REDACTED] user=admin" ,
248+ },
249+ {
250+ name : "connection string without password" ,
251+ input : "host=localhost user=postgres dbname=test" ,
252+ expected : "host=localhost user=postgres dbname=test" ,
253+ },
254+ {
255+ name : "empty string" ,
256+ input : "" ,
257+ expected : "" ,
258+ },
259+ {
260+ name : "password with special characters" ,
261+ input : "host=localhost password=p@ss!word123 user=admin" ,
262+ expected : "host=localhost password=[REDACTED] user=admin" ,
263+ },
264+ }
265+
266+ for _ , tt := range tests {
267+ t .Run (tt .name , func (t * testing.T ) {
268+ result := redactConnectionString (tt .input )
269+ if result != tt .expected {
270+ t .Errorf ("redactConnectionString(%q) = %q, want %q" , tt .input , result , tt .expected )
271+ }
272+ })
273+ }
274+ }
0 commit comments