(t *testing.T)
| 14 | "testing" |
| 15 | "time" |
| 16 | ) |
| 17 | |
| 18 | func TestCancelQueryDoesNotLogSecretKey(t *testing.T) { |
| 19 | var logs bytes.Buffer |
| 20 | previousLogger := slog.Default() |
| 21 | slog.SetDefault(slog.New(slog.NewTextHandler(&logs, &slog.HandlerOptions{Level: slog.LevelDebug}))) |
| 22 | t.Cleanup(func() { slog.SetDefault(previousLogger) }) |
| 23 | |
| 24 | key := BackendKey{Pid: 42, SecretKey: 987654321} |
| 25 | s := &Server{activeQueries: map[BackendKey]context.CancelFunc{key: func() {}}} |
| 26 | if !s.CancelQuery(key) { |
| 27 | t.Fatal("CancelQuery returned false for a registered key") |
| 28 | } |
| 29 | if strings.Contains(logs.String(), "987654321") { |
| 30 | t.Fatalf("cancel secret key leaked to logs: %s", logs.String()) |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | // TestDefaultControlPlaneIdleTimeout pins the control-plane idle-timeout |
| 35 | // default. The value is a product decision, not an implementation detail: it |
| 36 | // decides whether a client that pauses between statements keeps its connection. |
nothing calls this directly
no test coverage detected