|
37 | 37 | serve, |
38 | 38 | ) |
39 | 39 |
|
40 | | -from .harness import FakeWeb, connect, raw_request |
| 40 | +from .harness import PUBLIC_IP, FakeWeb, connect, raw_request |
41 | 41 |
|
42 | 42 | PAGE = "https://example.com/page" |
43 | 43 | ROBOTS = "https://example.com/robots.txt" |
@@ -950,6 +950,34 @@ async def test_unresolvable_host_is_left_to_the_transport(web: FakeWeb) -> None: |
950 | 950 | assert web.lookups == ["only-the-proxy-knows.example"] |
951 | 951 |
|
952 | 952 |
|
| 953 | +@pytest.mark.parametrize( |
| 954 | + "url, connected_host", |
| 955 | + [ |
| 956 | + # IDNA 2003 (the codec getaddrinfo applies to a Unicode name) maps ß |
| 957 | + # and final sigma to ss and σ; IDNA 2008, which httpx connects with, |
| 958 | + # keeps them. The guard must resolve the name the connection uses. |
| 959 | + ("http://faß.example.com/", "xn--fa-hia.example.com"), |
| 960 | + ("http://xn--fa-hia.example.com/", "xn--fa-hia.example.com"), |
| 961 | + ("http://σοφος.example.com/", "xn--0xaajbq.example.com"), |
| 962 | + ], |
| 963 | +) |
| 964 | +async def test_guard_resolves_the_name_the_connection_uses( |
| 965 | + web: FakeWeb, url: str, connected_host: str |
| 966 | +) -> None: |
| 967 | + web.dns["fass.example.com"] = [PUBLIC_IP] |
| 968 | + web.dns["σοφοσ.example.com"] = [PUBLIC_IP] |
| 969 | + web.dns[connected_host] = ["127.0.0.1"] |
| 970 | + web.add(f"http://{connected_host}/", plain("internal-secret")) |
| 971 | + async with connect(ignore_robots_txt=True) as (session, _): |
| 972 | + result = await call(session, {"url": url}) |
| 973 | + assert wire(result)["isError"] is True |
| 974 | + assert f": {connected_host} resolves to 127.0.0.1, which is not a public" in ( |
| 975 | + text_of(result) |
| 976 | + ) |
| 977 | + assert web.lookups == [connected_host] |
| 978 | + assert web.requests == [] |
| 979 | + |
| 980 | + |
953 | 981 | async def test_allow_private_ips_follows_redirect_to_private_address( |
954 | 982 | web: FakeWeb, |
955 | 983 | ) -> None: |
|
0 commit comments