File tree 5 files changed +53
-2
lines changed
5 files changed +53
-2
lines changed Original file line number Diff line number Diff line change
1
+ Disabled TLS in TLS warning (when using HTTPS proxies) for uvloop and newer Python versions -- by :user: `lezgomatt `.
Original file line number Diff line number Diff line change @@ -241,6 +241,7 @@ Martin Sucha
241
241
Mathias Fröjdman
242
242
Mathieu Dugré
243
243
Matt VanEseltine
244
+ Matthew Go
244
245
Matthias Marquardt
245
246
Matthieu Hauglustaine
246
247
Matthieu Rigal
Original file line number Diff line number Diff line change @@ -1203,7 +1203,13 @@ def _warn_about_tls_in_tls(
1203
1203
if req .request_info .url .scheme != "https" :
1204
1204
return
1205
1205
1206
- asyncio_supports_tls_in_tls = getattr (
1206
+ # Check if uvloop is being used, which supports TLS in TLS,
1207
+ # otherwise assume that asyncio's native transport is being used.
1208
+ if type (underlying_transport ).__module__ .startswith ("uvloop" ):
1209
+ return
1210
+
1211
+ # Support in asyncio was added in Python 3.11 (bpo-44011)
1212
+ asyncio_supports_tls_in_tls = sys .version_info >= (3 , 11 ) or getattr (
1207
1213
underlying_transport ,
1208
1214
"_start_tls_compatible" ,
1209
1215
False ,
Original file line number Diff line number Diff line change 7
7
from hashlib import md5 , sha1 , sha256
8
8
from pathlib import Path
9
9
from tempfile import TemporaryDirectory
10
- from typing import Any , Generator
10
+ from typing import Any , Generator , Iterator
11
11
from unittest import mock
12
12
from uuid import uuid4
13
13
27
27
except ImportError :
28
28
TRUSTME = False
29
29
30
+
31
+ try :
32
+ import uvloop
33
+ except ImportError :
34
+ uvloop = None # type: ignore[assignment]
35
+
30
36
pytest_plugins = ["aiohttp.pytest_plugin" , "pytester" ]
31
37
32
38
IS_HPUX = sys .platform .startswith ("hp-ux" )
@@ -193,6 +199,16 @@ def selector_loop():
193
199
yield _loop
194
200
195
201
202
+ @pytest .fixture
203
+ def uvloop_loop () -> Iterator [asyncio .AbstractEventLoop ]:
204
+ policy = uvloop .EventLoopPolicy ()
205
+ asyncio .set_event_loop_policy (policy )
206
+
207
+ with loop_context (policy .new_event_loop ) as _loop :
208
+ asyncio .set_event_loop (_loop )
209
+ yield _loop
210
+
211
+
196
212
@pytest .fixture
197
213
def netrc_contents (
198
214
tmp_path : Path ,
Original file line number Diff line number Diff line change 1
1
import asyncio
2
2
import os
3
3
import pathlib
4
+ import platform
4
5
import ssl
5
6
import sys
6
7
from re import match as match_regex
@@ -202,6 +203,32 @@ async def test_https_proxy_unsupported_tls_in_tls(
202
203
await asyncio .sleep (0.1 )
203
204
204
205
206
+ @pytest .mark .usefixtures ("uvloop_loop" )
207
+ @pytest .mark .skipif (
208
+ platform .system () == "Windows" or sys .implementation .name != "cpython" ,
209
+ reason = "uvloop is not supported on Windows and non-CPython implementations" ,
210
+ )
211
+ @pytest .mark .filterwarnings (r"ignore:.*ssl.OP_NO_SSL*" )
212
+ # Filter out the warning from
213
+ # https://github.com/abhinavsingh/proxy.py/blob/30574fd0414005dfa8792a6e797023e862bdcf43/proxy/common/utils.py#L226
214
+ # otherwise this test will fail because the proxy will die with an error.
215
+ async def test_uvloop_secure_https_proxy (
216
+ client_ssl_ctx : ssl .SSLContext ,
217
+ secure_proxy_url : URL ,
218
+ ) -> None :
219
+ """Ensure HTTPS sites are accessible through a secure proxy without warning when using uvloop."""
220
+ conn = aiohttp .TCPConnector ()
221
+ sess = aiohttp .ClientSession (connector = conn )
222
+ url = URL ("https://example.com" )
223
+
224
+ async with sess .get (url , proxy = secure_proxy_url , ssl = client_ssl_ctx ) as response :
225
+ assert response .status == 200
226
+
227
+ await sess .close ()
228
+ await conn .close ()
229
+ await asyncio .sleep (0.1 )
230
+
231
+
205
232
@pytest .fixture
206
233
def proxy_test_server (aiohttp_raw_server , loop , monkeypatch ):
207
234
# Handle all proxy requests and imitate remote server response.
You can’t perform that action at this time.
0 commit comments