(t *testing.T)
| 69 | } |
| 70 | |
| 71 | func 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 | } |
nothing calls this directly
no test coverage detected