Skip to content

Set ssl=True by default for AIOHTTPTransport #538

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/code_examples/fastapi_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from fastapi import FastAPI, HTTPException
from fastapi.responses import HTMLResponse

from gql import Client, gql
from gql.transport.aiohttp import AIOHTTPTransport

Expand Down
1 change: 1 addition & 0 deletions docs/code_examples/httpx_async_trio.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import trio

from gql import Client, gql
from gql.transport.httpx import HTTPXAsyncTransport

Expand Down
33 changes: 5 additions & 28 deletions gql/transport/aiohttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,8 @@
import io
import json
import logging
import warnings
from ssl import SSLContext
from typing import (
Any,
AsyncGenerator,
Callable,
Dict,
Optional,
Tuple,
Type,
Union,
cast,
)
from typing import Any, AsyncGenerator, Callable, Dict, Optional, Tuple, Type, Union

import aiohttp
from aiohttp.client_exceptions import ClientResponseError
Expand Down Expand Up @@ -57,7 +46,7 @@ def __init__(
headers: Optional[LooseHeaders] = None,
cookies: Optional[LooseCookies] = None,
auth: Optional[Union[BasicAuth, "AppSyncAuthentication"]] = None,
ssl: Union[SSLContext, bool, Fingerprint, str] = "ssl_warning",
ssl: Union[SSLContext, bool, Fingerprint] = True,
timeout: Optional[int] = None,
ssl_close_timeout: Optional[Union[int, float]] = 10,
json_serialize: Callable = json.dumps,
Expand All @@ -71,7 +60,8 @@ def __init__(
:param cookies: Dict of HTTP cookies.
:param auth: BasicAuth object to enable Basic HTTP auth if needed
Or Appsync Authentication class
:param ssl: ssl_context of the connection. Use ssl=False to disable encryption
:param ssl: ssl_context of the connection.
Use ssl=False to not verify ssl certificates.
:param ssl_close_timeout: Timeout in seconds to wait for the ssl connection
to close properly
:param json_serialize: Json serializer callable.
Expand All @@ -88,20 +78,7 @@ def __init__(
self.headers: Optional[LooseHeaders] = headers
self.cookies: Optional[LooseCookies] = cookies
self.auth: Optional[Union[BasicAuth, "AppSyncAuthentication"]] = auth

if ssl == "ssl_warning":
ssl = False
if str(url).startswith("https"):
warnings.warn(
"WARNING: By default, AIOHTTPTransport does not verify"
" ssl certificates. This will be fixed in the next major version."
" You can set ssl=True to force the ssl certificate verification"
" or ssl=False to disable this warning"
)

self.ssl: Union[SSLContext, bool, Fingerprint] = cast(
Union[SSLContext, bool, Fingerprint], ssl
)
self.ssl: Union[SSLContext, bool, Fingerprint] = ssl
self.timeout: Optional[int] = timeout
self.ssl_close_timeout: Optional[Union[int, float]] = ssl_close_timeout
self.client_session_args = client_session_args
Expand Down
11 changes: 3 additions & 8 deletions tests/test_aiohttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -1325,7 +1325,6 @@ async def handler(request):
assert africa["code"] == "AF"


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


@pytest.mark.asyncio
async def test_aiohttp_query_https_self_cert_warn(ssl_aiohttp_server):
async def test_aiohttp_query_https_self_cert_default(ssl_aiohttp_server):
from aiohttp import web
from gql.transport.aiohttp import AIOHTTPTransport

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

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

expected_warning = (
"WARNING: By default, AIOHTTPTransport does not verify ssl certificates."
" This will be fixed in the next major version."
)
transport = AIOHTTPTransport(url=url)

with pytest.warns(Warning, match=expected_warning):
AIOHTTPTransport(url=url, timeout=10)
assert transport.ssl is True


@pytest.mark.asyncio
Expand Down
Loading