From c69e392f8fc201c788ff09f1cf3e479f6b313ac6 Mon Sep 17 00:00:00 2001 From: cdeler Date: Sat, 17 Oct 2020 19:30:27 +0300 Subject: [PATCH] Fixed some PR issues - renamed the blocked host to blockedhost.example.com - added some docs to http_proxy_server fixture --- tests/async_tests/test_interfaces.py | 4 ++-- tests/sync_tests/test_interfaces.py | 4 ++-- tests/utils.py | 18 ++++++++++++++++-- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/tests/async_tests/test_interfaces.py b/tests/async_tests/test_interfaces.py index 8603a854..233278da 100644 --- a/tests/async_tests/test_interfaces.py +++ b/tests/async_tests/test_interfaces.py @@ -202,8 +202,8 @@ async def test_proxy_socket_does_not_leak_when_the_connection_hasnt_been_added_t port: int, ): method = b"GET" - url = (protocol, b"example.com", port, b"/") - headers = [(b"host", b"example.org")] + url = (protocol, b"blockedhost.example.com", port, b"/") + headers = [(b"host", b"blockedhost.example.com")] with pytest.warns(None) as recorded_warnings: async with httpcore.AsyncHTTPProxy(proxy_server, proxy_mode=proxy_mode) as http: diff --git a/tests/sync_tests/test_interfaces.py b/tests/sync_tests/test_interfaces.py index 5d384c00..51d1ee13 100644 --- a/tests/sync_tests/test_interfaces.py +++ b/tests/sync_tests/test_interfaces.py @@ -202,8 +202,8 @@ def test_proxy_socket_does_not_leak_when_the_connection_hasnt_been_added_to_pool port: int, ): method = b"GET" - url = (protocol, b"example.com", port, b"/") - headers = [(b"host", b"example.org")] + url = (protocol, b"blockedhost.example.com", port, b"/") + headers = [(b"host", b"blockedhost.example.com")] with pytest.warns(None) as recorded_warnings: with httpcore.SyncHTTPProxy(proxy_server, proxy_mode=proxy_mode) as http: diff --git a/tests/utils.py b/tests/utils.py index bb6a125d..9145ec78 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -47,10 +47,19 @@ def host_header(self) -> Tuple[bytes, bytes]: @contextlib.contextmanager def http_proxy_server(proxy_host: str, proxy_port: int): - + """ + This function launches pproxy process like this: + $ pproxy -b -l http://127.0.0.1:8080 + What does it mean? + It runs HTTP proxy on 127.0.0.1:8080 and blocks access to some external hosts, + specified in blocked_hosts_file + + Relevant pproxy docs could be found in their github repo: + https://github.com/qwj/python-proxy + """ proc = None - with create_proxy_block_file(["example.com"]) as block_file_name: + with create_proxy_block_file(["blockedhost.example.com"]) as block_file_name: try: command = [ "pproxy", @@ -71,6 +80,11 @@ def http_proxy_server(proxy_host: str, proxy_port: int): @contextlib.contextmanager def create_proxy_block_file(blocked_domains: List[str]): + """ + The context manager yields pproxy block file. + This file should contain line delimited hostnames. We use it in the following test: + test_proxy_socket_does_not_leak_when_the_connection_hasnt_been_added_to_pool + """ with tempfile.NamedTemporaryFile(delete=True, mode="w+") as file: for domain in blocked_domains: