Skip to content

Commit

Permalink
Fixed some PR issues
Browse files Browse the repository at this point in the history
- renamed the blocked host to blockedhost.example.com
- added some docs to http_proxy_server fixture
  • Loading branch information
cdeler committed Oct 17, 2020
1 parent 10df7fa commit c69e392
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
4 changes: 2 additions & 2 deletions tests/async_tests/test_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions tests/sync_tests/test_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
18 changes: 16 additions & 2 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <blocked_hosts_file> -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",
Expand All @@ -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:
Expand Down

0 comments on commit c69e392

Please sign in to comment.