Skip to content

Commit 5a9f983

Browse files
authored
Set ssl=True by default for AIOHTTPTransport (#538)
1 parent fdc3b28 commit 5a9f983

File tree

4 files changed

+10
-36
lines changed

4 files changed

+10
-36
lines changed

docs/code_examples/fastapi_async.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
from fastapi import FastAPI, HTTPException
1212
from fastapi.responses import HTMLResponse
13+
1314
from gql import Client, gql
1415
from gql.transport.aiohttp import AIOHTTPTransport
1516

docs/code_examples/httpx_async_trio.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import trio
2+
23
from gql import Client, gql
34
from gql.transport.httpx import HTTPXAsyncTransport
45

gql/transport/aiohttp.py

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,8 @@
22
import io
33
import json
44
import logging
5-
import warnings
65
from ssl import SSLContext
7-
from typing import (
8-
Any,
9-
AsyncGenerator,
10-
Callable,
11-
Dict,
12-
Optional,
13-
Tuple,
14-
Type,
15-
Union,
16-
cast,
17-
)
6+
from typing import Any, AsyncGenerator, Callable, Dict, Optional, Tuple, Type, Union
187

198
import aiohttp
209
from aiohttp.client_exceptions import ClientResponseError
@@ -57,7 +46,7 @@ def __init__(
5746
headers: Optional[LooseHeaders] = None,
5847
cookies: Optional[LooseCookies] = None,
5948
auth: Optional[Union[BasicAuth, "AppSyncAuthentication"]] = None,
60-
ssl: Union[SSLContext, bool, Fingerprint, str] = "ssl_warning",
49+
ssl: Union[SSLContext, bool, Fingerprint] = True,
6150
timeout: Optional[int] = None,
6251
ssl_close_timeout: Optional[Union[int, float]] = 10,
6352
json_serialize: Callable = json.dumps,
@@ -71,7 +60,8 @@ def __init__(
7160
:param cookies: Dict of HTTP cookies.
7261
:param auth: BasicAuth object to enable Basic HTTP auth if needed
7362
Or Appsync Authentication class
74-
:param ssl: ssl_context of the connection. Use ssl=False to disable encryption
63+
:param ssl: ssl_context of the connection.
64+
Use ssl=False to not verify ssl certificates.
7565
:param ssl_close_timeout: Timeout in seconds to wait for the ssl connection
7666
to close properly
7767
:param json_serialize: Json serializer callable.
@@ -88,20 +78,7 @@ def __init__(
8878
self.headers: Optional[LooseHeaders] = headers
8979
self.cookies: Optional[LooseCookies] = cookies
9080
self.auth: Optional[Union[BasicAuth, "AppSyncAuthentication"]] = auth
91-
92-
if ssl == "ssl_warning":
93-
ssl = False
94-
if str(url).startswith("https"):
95-
warnings.warn(
96-
"WARNING: By default, AIOHTTPTransport does not verify"
97-
" ssl certificates. This will be fixed in the next major version."
98-
" You can set ssl=True to force the ssl certificate verification"
99-
" or ssl=False to disable this warning"
100-
)
101-
102-
self.ssl: Union[SSLContext, bool, Fingerprint] = cast(
103-
Union[SSLContext, bool, Fingerprint], ssl
104-
)
81+
self.ssl: Union[SSLContext, bool, Fingerprint] = ssl
10582
self.timeout: Optional[int] = timeout
10683
self.ssl_close_timeout: Optional[Union[int, float]] = ssl_close_timeout
10784
self.client_session_args = client_session_args

tests/test_aiohttp.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1325,7 +1325,6 @@ async def handler(request):
13251325
assert africa["code"] == "AF"
13261326

13271327

1328-
@pytest.mark.skip(reason="We will change the default to fix this in a future version")
13291328
@pytest.mark.asyncio
13301329
async def test_aiohttp_query_https_self_cert_fail(ssl_aiohttp_server):
13311330
"""By default, we should verify the ssl certificate"""
@@ -1360,7 +1359,7 @@ async def handler(request):
13601359

13611360

13621361
@pytest.mark.asyncio
1363-
async def test_aiohttp_query_https_self_cert_warn(ssl_aiohttp_server):
1362+
async def test_aiohttp_query_https_self_cert_default(ssl_aiohttp_server):
13641363
from aiohttp import web
13651364
from gql.transport.aiohttp import AIOHTTPTransport
13661365

@@ -1375,13 +1374,9 @@ async def handler(request):
13751374

13761375
assert str(url).startswith("https://")
13771376

1378-
expected_warning = (
1379-
"WARNING: By default, AIOHTTPTransport does not verify ssl certificates."
1380-
" This will be fixed in the next major version."
1381-
)
1377+
transport = AIOHTTPTransport(url=url)
13821378

1383-
with pytest.warns(Warning, match=expected_warning):
1384-
AIOHTTPTransport(url=url, timeout=10)
1379+
assert transport.ssl is True
13851380

13861381

13871382
@pytest.mark.asyncio

0 commit comments

Comments
 (0)