MCPcopy Create free account
hub / github.com/imroc/req / TestSensitiveHeadersRedirectPolicy

Function TestSensitiveHeadersRedirectPolicy

client_test.go:427–457  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

425}
426
427func TestSensitiveHeadersRedirectPolicy(t *testing.T) {
428 // Cross-domain redirect: sensitive header should be stripped
429 crossDomainReq := &http.Request{
430 Header: http.Header{},
431 URL: &url.URL{Host: "evil.com"},
432 }
433 crossDomainReq.Header.Set("X-API-Key", "secret")
434 via := []*http.Request{{
435 Header: http.Header{},
436 URL: &url.URL{Host: "api.example.com"},
437 }}
438 via[0].Header.Set("X-API-Key", "secret")
439
440 tc().SetRedirectPolicy(SensitiveHeadersRedirectPolicy("X-API-Key")).GetClient().CheckRedirect(crossDomainReq, via)
441 tests.AssertEqual(t, "", crossDomainReq.Header.Get("X-API-Key"))
442
443 // Same-domain redirect: sensitive header should be kept
444 sameDomainReq := &http.Request{
445 Header: http.Header{},
446 URL: &url.URL{Host: "sub.example.com"},
447 }
448 sameDomainReq.Header.Set("X-API-Key", "secret")
449 viaSame := []*http.Request{{
450 Header: http.Header{},
451 URL: &url.URL{Host: "api.example.com"},
452 }}
453 viaSame[0].Header.Set("X-API-Key", "secret")
454
455 tc().SetRedirectPolicy(SensitiveHeadersRedirectPolicy("X-API-Key")).GetClient().CheckRedirect(sameDomainReq, viaSame)
456 tests.AssertEqual(t, "secret", sameDomainReq.Header.Get("X-API-Key"))
457}
458
459func TestGetTLSClientConfig(t *testing.T) {
460 c := tc()

Callers

nothing calls this directly

Calls 6

AssertEqualFunction · 0.92
tcFunction · 0.85
SetRedirectPolicyMethod · 0.80
GetClientMethod · 0.45
GetMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…