MCPcopy
hub / github.com/autobrr/qui / TestLoggerRedactsProxyAPIKeyPath

Function TestLoggerRedactsProxyAPIKeyPath

internal/api/middleware/logger_test.go:71–93  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

69}
70
71func TestLoggerRedactsProxyAPIKeyPath(t *testing.T) {
72 const proxyAPIKey = "SECRET-PROXY-API-KEY"
73
74 var buf bytes.Buffer
75 logger := zerolog.New(&buf).Level(zerolog.TraceLevel)
76 handler := Logger(logger)(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
77 w.WriteHeader(http.StatusOK)
78 }))
79
80 req := httptest.NewRequestWithContext(
81 t.Context(),
82 http.MethodGet,
83 "/proxy/"+proxyAPIKey+"/api/v2/torrents/info",
84 nil,
85 )
86 resp := httptest.NewRecorder()
87
88 handler.ServeHTTP(resp, req)
89
90 logLine := buf.String()
91 require.NotContains(t, logLine, proxyAPIKey)
92 require.Contains(t, logLine, `"url":"/proxy/REDACTED/api/v2/torrents/info"`)
93}

Callers

nothing calls this directly

Calls 4

LoggerFunction · 0.85
ServeHTTPMethod · 0.80
WriteHeaderMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected