(t *testing.T)
| 425 | } |
| 426 | |
| 427 | func 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 | |
| 459 | func TestGetTLSClientConfig(t *testing.T) { |
| 460 | c := tc() |
nothing calls this directly
no test coverage detected
searching dependent graphs…