1
1
import asyncio
2
- import functools
3
2
import os
4
3
import pathlib
5
- import platform
4
+ import ssl
5
+ import sys
6
6
from re import match as match_regex
7
7
from unittest import mock
8
8
from uuid import uuid4
13
13
14
14
import aiohttp
15
15
from aiohttp import web
16
- from aiohttp .client_exceptions import ClientConnectionError , ClientProxyConnectionError
17
- from aiohttp .helpers import IS_MACOS , IS_WINDOWS , PY_310
16
+ from aiohttp .client_exceptions import ClientConnectionError
17
+ from aiohttp .helpers import IS_MACOS , IS_WINDOWS
18
18
19
19
pytestmark = [
20
20
pytest .mark .filterwarnings (
28
28
]
29
29
30
30
31
- secure_proxy_xfail_under_py310_linux = functools .partial (
32
- pytest .mark .xfail ,
33
- PY_310 and platform .system () == "Linux" ,
34
- reason = (
35
- "The secure proxy fixture does not seem to work "
36
- "under Python 3.10 on Linux. "
37
- "See https://github.com/abhinavsingh/proxy.py/issues/622."
38
- ),
39
- )
40
-
41
- ASYNCIO_SUPPORTS_TLS_IN_TLS = hasattr (
42
- asyncio .sslproto ._SSLProtocolTransport ,
43
- "_start_tls_compatible" ,
44
- )
31
+ ASYNCIO_SUPPORTS_TLS_IN_TLS = sys .version_info >= (3 , 11 )
45
32
46
33
47
34
@pytest .fixture
@@ -51,6 +38,9 @@ def secure_proxy_url(tls_certificate_pem_path):
51
38
This fixture also spawns that instance and tears it down after the test.
52
39
"""
53
40
proxypy_args = [
41
+ # --threadless does not work on windows, see
42
+ # https://github.com/abhinavsingh/proxy.py/issues/492
43
+ "--threaded" if os .name == "nt" else "--threadless" ,
54
44
"--num-workers" ,
55
45
"1" , # the tests only send one query anyway
56
46
"--hostname" ,
@@ -112,32 +102,20 @@ async def handler(*args, **kwargs):
112
102
)
113
103
114
104
115
- @pytest .fixture
116
- def _pretend_asyncio_supports_tls_in_tls (
117
- monkeypatch ,
118
- web_server_endpoint_type ,
119
- ):
120
- if web_server_endpoint_type != "https" or ASYNCIO_SUPPORTS_TLS_IN_TLS :
121
- return
122
-
123
- # for https://github.com/python/cpython/pull/28073
124
- # and https://bugs.python.org/issue37179
125
- monkeypatch .setattr (
126
- asyncio .sslproto ._SSLProtocolTransport ,
127
- "_start_tls_compatible" ,
128
- True ,
129
- raising = False ,
130
- )
131
-
132
-
133
- @secure_proxy_xfail_under_py310_linux (raises = ClientProxyConnectionError )
105
+ @pytest .mark .skipif (
106
+ not ASYNCIO_SUPPORTS_TLS_IN_TLS ,
107
+ reason = "asyncio on this python does not support TLS in TLS" ,
108
+ )
134
109
@pytest .mark .parametrize ("web_server_endpoint_type" , ("http" , "https" ))
135
- @pytest .mark .usefixtures ("_pretend_asyncio_supports_tls_in_tls" , "loop" )
110
+ @pytest .mark .filterwarnings (r"ignore:.*ssl.OP_NO_SSL*" )
111
+ # Filter out the warning from
112
+ # https://github.com/abhinavsingh/proxy.py/blob/30574fd0414005dfa8792a6e797023e862bdcf43/proxy/common/utils.py#L226
113
+ # otherwise this test will fail because the proxy will die with an error.
136
114
async def test_secure_https_proxy_absolute_path (
137
- client_ssl_ctx ,
138
- secure_proxy_url ,
139
- web_server_endpoint_url ,
140
- web_server_endpoint_payload ,
115
+ client_ssl_ctx : ssl . SSLContext ,
116
+ secure_proxy_url : URL ,
117
+ web_server_endpoint_url : str ,
118
+ web_server_endpoint_payload : str ,
141
119
) -> None :
142
120
"""Ensure HTTP(S) sites are accessible through a secure proxy."""
143
121
conn = aiohttp .TCPConnector ()
@@ -160,13 +138,19 @@ async def test_secure_https_proxy_absolute_path(
160
138
await asyncio .sleep (0.1 )
161
139
162
140
163
- @secure_proxy_xfail_under_py310_linux (raises = AssertionError )
164
141
@pytest .mark .parametrize ("web_server_endpoint_type" , ("https" ,))
165
142
@pytest .mark .usefixtures ("loop" )
143
+ @pytest .mark .skipif (
144
+ ASYNCIO_SUPPORTS_TLS_IN_TLS , reason = "asyncio on this python supports TLS in TLS"
145
+ )
146
+ @pytest .mark .filterwarnings (r"ignore:.*ssl.OP_NO_SSL*" )
147
+ # Filter out the warning from
148
+ # https://github.com/abhinavsingh/proxy.py/blob/30574fd0414005dfa8792a6e797023e862bdcf43/proxy/common/utils.py#L226
149
+ # otherwise this test will fail because the proxy will die with an error.
166
150
async def test_https_proxy_unsupported_tls_in_tls (
167
- client_ssl_ctx ,
168
- secure_proxy_url ,
169
- web_server_endpoint_type ,
151
+ client_ssl_ctx : ssl . SSLContext ,
152
+ secure_proxy_url : URL ,
153
+ web_server_endpoint_type : str ,
170
154
) -> None :
171
155
"""Ensure connecting to TLS endpoints w/ HTTPS proxy needs patching.
172
156
0 commit comments