Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix usage of proxy.py in test_proxy_functional #7773

Merged
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
e425cf6
Fix test_https_proxy_unsupported_tls_in_tls on MacOS
bdraco Oct 31, 2023
032e7eb
Merge branch 'master' into fix_test_https_proxy_unsupported_tls_in_tl…
bdraco Nov 3, 2023
ea6be0b
Merge branch 'master' into fix_test_https_proxy_unsupported_tls_in_tl…
bdraco Nov 15, 2023
f95bdf0
adjust tests
bdraco Nov 15, 2023
c62cd79
adjust tests
bdraco Nov 15, 2023
d68b650
vierfy the proxy is actually running and we can connect
bdraco Nov 15, 2023
0b1a604
legacy
bdraco Nov 15, 2023
8bde66f
cond
bdraco Nov 15, 2023
2e5972d
adjust workers
bdraco Nov 15, 2023
e467cb9
try disabling verify
bdraco Nov 15, 2023
9f97902
debug logging
bdraco Nov 15, 2023
e708df2
debug
bdraco Nov 15, 2023
b297902
fix lgoger
bdraco Nov 15, 2023
62a279b
fix lgoger
bdraco Nov 15, 2023
6b91590
print log
bdraco Nov 15, 2023
f90eb89
more info
bdraco Nov 15, 2023
05e7afd
more info
bdraco Nov 15, 2023
d0e68a4
proxy seems to die on tls connect
bdraco Nov 15, 2023
8098b75
try rsa
bdraco Nov 15, 2023
f361328
maybe the proxy is dying off?
bdraco Nov 15, 2023
d3567f5
tweak
bdraco Nov 19, 2023
2449437
tweak
bdraco Nov 19, 2023
eca01be
revet
bdraco Nov 19, 2023
9160506
remove debug
bdraco Nov 19, 2023
2658afc
remove debug
bdraco Nov 19, 2023
cf216cb
remove debug
bdraco Nov 19, 2023
c9aa93e
fix
bdraco Nov 19, 2023
c6a93a4
fix
bdraco Nov 19, 2023
9f088f8
Merge branch 'master' into proxy_subproc
bdraco Nov 23, 2023
d0d5790
try threaded
bdraco Nov 23, 2023
07f97ba
empty
bdraco Nov 23, 2023
f6881fd
cleanups
bdraco Nov 23, 2023
4964b3e
Merge branch 'master' into fix_test_https_proxy_unsupported_tls_in_tl…
bdraco Nov 23, 2023
68a5577
preen
bdraco Nov 23, 2023
c44c7d8
Merge remote-tracking branch 'bdraco/fix_test_https_proxy_unsupported…
bdraco Nov 23, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 29 additions & 47 deletions tests/test_proxy_functional.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# type: ignore
import asyncio
import functools
import os
import pathlib
import platform
import ssl
import sys
from re import match as match_regex
from typing import Any
from unittest import mock
Expand All @@ -15,8 +15,7 @@

import aiohttp
from aiohttp import web
from aiohttp.client_exceptions import ClientConnectionError, ClientProxyConnectionError
from aiohttp.helpers import PY_310
from aiohttp.client_exceptions import ClientConnectionError

pytestmark = [
pytest.mark.filterwarnings(
Expand All @@ -30,20 +29,7 @@
]


secure_proxy_xfail = functools.partial(
pytest.mark.xfail,
(PY_310 and platform.system() != "Darwin") or platform.system() == "Windows",
reason=(
"The secure proxy fixture does not seem to work "
"under Python 3.10 on Linux and any Python on Windows. "
"See https://github.com/abhinavsingh/proxy.py/issues/622."
),
)

ASYNCIO_SUPPORTS_TLS_IN_TLS = hasattr(
asyncio.sslproto._SSLProtocolTransport,
"_start_tls_compatible",
)
ASYNCIO_SUPPORTS_TLS_IN_TLS = sys.version_info >= (3, 11)


@pytest.fixture
Expand All @@ -53,7 +39,9 @@ def secure_proxy_url(tls_certificate_pem_path):
This fixture also spawns that instance and tears it down after the test.
"""
proxypy_args = [
"--threadless", # use asyncio
# --threadless does not work on windows, see
# https://github.com/abhinavsingh/proxy.py/issues/492
"--threaded" if os.name == "nt" else "--threadless",
"--num-workers",
"1", # the tests only send one query anyway
"--hostname",
Expand Down Expand Up @@ -113,32 +101,20 @@ async def handler(*args, **kwargs):
)


@pytest.fixture
def _pretend_asyncio_supports_tls_in_tls(
monkeypatch,
web_server_endpoint_type,
):
if web_server_endpoint_type != "https" or ASYNCIO_SUPPORTS_TLS_IN_TLS:
return

# for https://github.com/python/cpython/pull/28073
# and https://bugs.python.org/issue37179
monkeypatch.setattr(
asyncio.sslproto._SSLProtocolTransport,
"_start_tls_compatible",
True,
raising=False,
)


@secure_proxy_xfail(raises=ClientProxyConnectionError)
@pytest.mark.skipif(
not ASYNCIO_SUPPORTS_TLS_IN_TLS,
reason="asyncio on this python does not support TLS in TLS",
)
@pytest.mark.parametrize("web_server_endpoint_type", ("http", "https"))
@pytest.mark.usefixtures("_pretend_asyncio_supports_tls_in_tls", "loop")
@pytest.mark.filterwarnings(r"ignore:.*ssl.OP_NO_SSL*")
Dreamsorcerer marked this conversation as resolved.
Show resolved Hide resolved
# Filter out the warning from
# https://github.com/abhinavsingh/proxy.py/blob/30574fd0414005dfa8792a6e797023e862bdcf43/proxy/common/utils.py#L226
# otherwise this test will fail because the proxy will die with an error.
async def test_secure_https_proxy_absolute_path(
client_ssl_ctx,
secure_proxy_url,
web_server_endpoint_url,
web_server_endpoint_payload,
client_ssl_ctx: ssl.SSLContext,
secure_proxy_url: URL,
web_server_endpoint_url: str,
web_server_endpoint_payload: str,
) -> None:
"""Ensure HTTP(S) sites are accessible through a secure proxy."""
conn = aiohttp.TCPConnector()
Expand All @@ -158,13 +134,19 @@ async def test_secure_https_proxy_absolute_path(
await conn.close()


@secure_proxy_xfail(raises=AssertionError)
@pytest.mark.parametrize("web_server_endpoint_type", ("https",))
@pytest.mark.usefixtures("loop")
@pytest.mark.skipif(
ASYNCIO_SUPPORTS_TLS_IN_TLS, reason="asyncio on this python supports TLS in TLS"
)
bdraco marked this conversation as resolved.
Show resolved Hide resolved
@pytest.mark.filterwarnings(r"ignore:.*ssl.OP_NO_SSL*")
# Filter out the warning from
# https://github.com/abhinavsingh/proxy.py/blob/30574fd0414005dfa8792a6e797023e862bdcf43/proxy/common/utils.py#L226
# otherwise this test will fail because the proxy will die with an error.
async def test_https_proxy_unsupported_tls_in_tls(
client_ssl_ctx,
secure_proxy_url,
web_server_endpoint_type,
client_ssl_ctx: ssl.SSLContext,
secure_proxy_url: URL,
web_server_endpoint_type: str,
) -> None:
"""Ensure connecting to TLS endpoints w/ HTTPS proxy needs patching.

Expand Down
Loading