(t *testing.T)
| 1613 | } |
| 1614 | |
| 1615 | func TestIPEncodingHeadersSendsEncodedLocalhostVariants(t *testing.T) { |
| 1616 | resetTestState() |
| 1617 | |
| 1618 | var mu sync.Mutex |
| 1619 | var sawIntegerIP bool |
| 1620 | var sawIPv6 bool |
| 1621 | |
| 1622 | ts, _ := testServer(t, func(w http.ResponseWriter, r *http.Request) { |
| 1623 | mu.Lock() |
| 1624 | for _, value := range []string{ |
| 1625 | r.Header.Get("X-Forwarded-For"), |
| 1626 | r.Header.Get("Client-IP"), |
| 1627 | r.Header.Get("True-Client-IP"), |
| 1628 | r.Header.Get("X-Real-Ip"), |
| 1629 | r.Header.Get("Cf-Connecting-Ip"), |
| 1630 | } { |
| 1631 | if value == "2130706433" { |
| 1632 | sawIntegerIP = true |
| 1633 | } |
| 1634 | if value == "[::1]" || value == "::ffff:127.0.0.1" { |
| 1635 | sawIPv6 = true |
| 1636 | } |
| 1637 | } |
| 1638 | mu.Unlock() |
| 1639 | w.WriteHeader(http.StatusForbidden) |
| 1640 | fmt.Fprint(w, "Forbidden") |
| 1641 | }) |
| 1642 | defer ts.Close() |
| 1643 | |
| 1644 | opts := RequestOptions{ |
| 1645 | uri: ts.URL + "/admin", |
| 1646 | headers: []header{{"User-Agent", "test"}}, |
| 1647 | method: "GET", |
| 1648 | proxy: &url.URL{}, |
| 1649 | timeout: 5000, |
| 1650 | rateLimit: false, |
| 1651 | redirect: false, |
| 1652 | verbose: true, |
| 1653 | } |
| 1654 | |
| 1655 | requestIPEncodingHeaders(opts) |
| 1656 | |
| 1657 | mu.Lock() |
| 1658 | defer mu.Unlock() |
| 1659 | if !sawIntegerIP || !sawIPv6 { |
| 1660 | t.Fatalf("expected ip encoding technique to send encoded localhost variants") |
| 1661 | } |
| 1662 | } |
| 1663 | |
| 1664 | func TestRawAuthoritySendsDuplicateHostHeaders(t *testing.T) { |
| 1665 | resetTestState() |
nothing calls this directly
no test coverage detected