From 46d9c0a61c65fffa0339610aa6e423011045428d Mon Sep 17 00:00:00 2001 From: Brian Bouterse Date: Tue, 14 Sep 2021 16:46:50 -0400 Subject: [PATCH] Adds basic xfail tests for secure proxy support --- setup.cfg | 1 + setup.py | 1 + tests/test_proxy_functional.py | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/setup.cfg b/setup.cfg index a2420b14d15..6f0ac3810f2 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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 diff --git a/setup.py b/setup.py index 839010faae9..33db90facdc 100644 --- a/setup.py +++ b/setup.py @@ -89,6 +89,7 @@ def read(f): "pytest-timeout", "async-generator", "pytest-xdist", + "proxy.py", ] diff --git a/tests/test_proxy_functional.py b/tests/test_proxy_functional.py index 68763cd446e..1acf3acf948 100644 --- a/tests/test_proxy_functional.py +++ b/tests/test_proxy_functional.py @@ -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.