MCPcopy Create free account
hub / github.com/PostHog/duckgres / TestRedactConnectionString

Function TestRedactConnectionString

server/conn_test.go:437–493  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

435 }
436}
437
438func TestRedactConnectionString(t *testing.T) {
439 tests := []struct {
440 name string
441 input string
442 expected string
443 }{
444 {
445 name: "postgres connection string with password",
446 input: "postgres:host=localhost user=postgres password=secretpass dbname=ducklake",
447 expected: "postgres:host=localhost user=postgres password=[REDACTED] dbname=ducklake",
448 },
449 {
450 name: "connection string with password= format",
451 input: "host=localhost password=mysecret user=admin",
452 expected: "host=localhost password=[REDACTED] user=admin",
453 },
454 {
455 name: "connection string with PASSWORD uppercase",
456 input: "host=localhost PASSWORD=mysecret user=admin",
457 expected: "host=localhost PASSWORD=[REDACTED] user=admin",
458 },
459 {
460 name: "connection string without password",
461 input: "host=localhost user=postgres dbname=test",
462 expected: "host=localhost user=postgres dbname=test",
463 },
464 {
465 name: "empty string",
466 input: "",
467 expected: "",
468 },
469 {
470 name: "password with special characters",
471 input: "host=localhost password=p@ss!word123 user=admin",
472 expected: "host=localhost password=[REDACTED] user=admin",
473 },
474 {
475 name: "password at end of quoted DSN",
476 input: `"host=localhost password=secret"`,
477 expected: `"host=localhost password=[REDACTED]"`,
478 },
479 {
480 name: "quoted password value",
481 input: `host=localhost password="my secret" dbname=test`,
482 expected: `host=localhost password=[REDACTED] dbname=test`,
483 },
484 }
485
486 for _, tt := range tests {
487 t.Run(tt.name, func(t *testing.T) {
488 result := redactConnectionString(tt.input)
489 if result != tt.expected {
490 t.Errorf("redactConnectionString(%q) = %q, want %q", tt.input, result, tt.expected)
491 }
492 })
493 }
494}

Callers

nothing calls this directly

Calls 2

redactConnectionStringFunction · 0.85
RunMethod · 0.65

Tested by

no test coverage detected