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