Skip to content

Commit

Permalink
Adds basic xfail tests for secure proxy support
Browse files Browse the repository at this point in the history
  • Loading branch information
bmbouter committed Sep 14, 2021
1 parent 3cae27a commit 46d9c0a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ addopts =
filterwarnings =
error
ignore:module 'ssl' has no attribute 'OP_NO_COMPRESSION'. The Python interpreter is compiled against OpenSSL < 1.0.0. Ref. https.//docs.python.org/3/library/ssl.html#ssl.OP_NO_COMPRESSION:UserWarning
ignore:The loop argument is deprecated since Python 3.8, and scheduled for removal in Python 3.10.:DeprecationWarning
junit_suite_name = aiohttp_test_suite
norecursedirs = dist docs build .tox .eggs
minversion = 3.8.2
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def read(f):
"pytest-timeout",
"async-generator",
"pytest-xdist",
"proxy.py",
]


Expand Down
34 changes: 34 additions & 0 deletions tests/test_proxy_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,47 @@
import pathlib
from unittest import mock

import proxy
import pytest
import trustme
from yarl import URL

import aiohttp
from aiohttp import web


@pytest.fixture
def trustme_certs(tmp_path):
ca = trustme.CA()
ca.issue_cert(u"localhost")
ca_cert_path = tmp_path / "ca.pem"
ca.cert_pem.write_to_path(ca_cert_path)
ca_key_path = tmp_path / "server.key"
ca.private_key_pem.write_to_path(ca_key_path)
return (str(ca_cert_path), str(ca_key_path))


@pytest.fixture
def secure_proxy_url(trustme_certs):
port = proxy.common.utils.get_available_port()
input_args = [
'--num-workers', '1',
'--threadless',
'--hostname', '0.0.0.0',
'--port', str(port),
'--cert-file', trustme_certs[0],
'--key-file', trustme_certs[1],
]
proxy_url = "http://0.0.0.0:" + str(port)
with proxy.Proxy(input_args=input_args) as proxy_instance:
yield proxy_url


async def test_secure_proxy_http_absolute_path(secure_proxy_url, get_request) -> None:
url = "https://httpbin.org/get"
await get_request(url=url, proxy=secure_proxy_url, ssl=False)


@pytest.fixture
def proxy_test_server(aiohttp_raw_server, loop, monkeypatch):
# Handle all proxy requests and imitate remote server response.
Expand Down

0 comments on commit 46d9c0a

Please sign in to comment.