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

Function TestProxyContextApplyAuthHeaders_APIKey

internal/proxy/handler_test.go:230–275  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

228}
229
230func TestProxyContextApplyAuthHeaders_APIKey(t *testing.T) {
231 t.Helper()
232
233 cases := []struct {
234 name string
235 pc *proxyContext
236 incomingAuth string
237 wantAuthorization string
238 }{
239 {
240 name: "api key sets bearer header",
241 pc: &proxyContext{apiKey: "secret-key"},
242 wantAuthorization: "Bearer secret-key",
243 },
244 {
245 name: "api key overrides incoming authorization",
246 pc: &proxyContext{apiKey: "secret-key"},
247 incomingAuth: "Basic ZGFuZ2VyOnp1bw==",
248 wantAuthorization: "Bearer secret-key",
249 },
250 {
251 name: "api key overrides basic auth",
252 pc: &proxyContext{apiKey: "secret-key", basicAuth: &basicAuthCredentials{username: "u", password: "p"}},
253 wantAuthorization: "Bearer secret-key",
254 },
255 {
256 name: "no api key and no basic auth strips authorization",
257 pc: &proxyContext{},
258 incomingAuth: "Bearer should-be-removed",
259 wantAuthorization: "",
260 },
261 }
262
263 for _, tc := range cases {
264 t.Run(tc.name, func(t *testing.T) {
265 req := httptest.NewRequestWithContext(context.Background(), http.MethodGet, "http://example.com/api/v2/torrents/info", nil)
266 if tc.incomingAuth != "" {
267 req.Header.Set("Authorization", tc.incomingAuth)
268 }
269
270 tc.pc.applyAuthHeaders(req)
271
272 require.Equal(t, tc.wantAuthorization, req.Header.Get("Authorization"))
273 })
274 }
275}
276
277func TestParseCSVQueryValues(t *testing.T) {
278 t.Helper()

Callers

nothing calls this directly

Calls 4

RunMethod · 0.80
applyAuthHeadersMethod · 0.80
GetMethod · 0.65
SetMethod · 0.45

Tested by

no test coverage detected