File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree 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
241241Mathias Fröjdman
242242Mathieu Dugré
243243Matt VanEseltine
244+ Matthew Go
244245Matthias Marquardt
245246Matthieu Hauglustaine
246247Matthieu Rigal
Original file line number Diff line number Diff line change @@ -1203,7 +1203,13 @@ def _warn_about_tls_in_tls(
12031203 if req .request_info .url .scheme != "https" :
12041204 return
12051205
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 (
12071213 underlying_transport ,
12081214 "_start_tls_compatible" ,
12091215 False ,
Original file line number Diff line number Diff line change 77from hashlib import md5 , sha1 , sha256
88from pathlib import Path
99from tempfile import TemporaryDirectory
10- from typing import Any , Generator
10+ from typing import Any , Generator , Iterator
1111from unittest import mock
1212from uuid import uuid4
1313
2727except ImportError :
2828 TRUSTME = False
2929
30+
31+ try :
32+ import uvloop
33+ except ImportError :
34+ uvloop = None # type: ignore[assignment]
35+
3036pytest_plugins = ["aiohttp.pytest_plugin" , "pytester" ]
3137
3238IS_HPUX = sys .platform .startswith ("hp-ux" )
@@ -193,6 +199,16 @@ def selector_loop():
193199 yield _loop
194200
195201
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+
196212@pytest .fixture
197213def netrc_contents (
198214 tmp_path : Path ,
Original file line number Diff line number Diff line change 11import asyncio
22import os
33import pathlib
4+ import platform
45import ssl
56import sys
67from re import match as match_regex
@@ -202,6 +203,32 @@ async def test_https_proxy_unsupported_tls_in_tls(
202203 await asyncio .sleep (0.1 )
203204
204205
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+
205232@pytest .fixture
206233def proxy_test_server (aiohttp_raw_server , loop , monkeypatch ):
207234 # Handle all proxy requests and imitate remote server response.
You can’t perform that action at this time.
0 commit comments