aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSlava <slovaricheg@gmail.com>2021-06-03 10:44:40 +0300
committerGitHub <noreply@github.com>2021-06-03 00:44:40 -0700
commit09e0389db72cc9d6c5dde34864cb54d717dc0b92 (patch)
tree27bd6c852f75ec8253f001442d3aff5667e608a6
parent9f83764d4ff3b5fa30d460b3f1f70a73351b0be0 (diff)
downloadgoogle-auth-library-python-09e0389db72cc9d6c5dde34864cb54d717dc0b92.tar.gz
fix: session object was never used in aiohttp request (#700) (#701)
* fix: session object was never used in aiohttp request (#700) * fixup! fix: session object was never used in aiohttp request (#700) * fixup! fixup! fix: session object was never used in aiohttp request (#700) Co-authored-by: arithmetic1728 <58957152+arithmetic1728@users.noreply.github.com>
-rw-r--r--google/auth/transport/_aiohttp_requests.py7
-rw-r--r--system_tests/system_tests_async/conftest.py14
-rw-r--r--tests_async/transport/test_aiohttp_requests.py15
3 files changed, 28 insertions, 8 deletions
diff --git a/google/auth/transport/_aiohttp_requests.py b/google/auth/transport/_aiohttp_requests.py
index 4293810..ab7dfef 100644
--- a/google/auth/transport/_aiohttp_requests.py
+++ b/google/auth/transport/_aiohttp_requests.py
@@ -138,7 +138,12 @@ class Request(transport.Request):
"""
def __init__(self, session=None):
- self.session = None
+ # TODO: Use auto_decompress property for aiohttp 3.7+
+ if session is not None and session._auto_decompress:
+ raise ValueError(
+ "Client sessions with auto_decompress=True are not supported."
+ )
+ self.session = session
async def __call__(
self,
diff --git a/system_tests/system_tests_async/conftest.py b/system_tests/system_tests_async/conftest.py
index 47a473e..9669099 100644
--- a/system_tests/system_tests_async/conftest.py
+++ b/system_tests/system_tests_async/conftest.py
@@ -26,9 +26,7 @@ import aiohttp
from google.auth.transport import _aiohttp_requests as aiohttp_requests
from system_tests.system_tests_sync import conftest as sync_conftest
-ASYNC_REQUESTS_SESSION = aiohttp.ClientSession()
-ASYNC_REQUESTS_SESSION.verify = False
TOKEN_INFO_URL = "https://www.googleapis.com/oauth2/v3/tokeninfo"
@@ -49,10 +47,18 @@ def authorized_user_file():
"""The full path to a valid authorized user file."""
yield sync_conftest.AUTHORIZED_USER_FILE
+
+@pytest.fixture
+async def aiohttp_session():
+ async with aiohttp.ClientSession(auto_decompress=False) as session:
+ yield session
+
+
@pytest.fixture(params=["aiohttp"])
-async def http_request(request):
+async def http_request(request, aiohttp_session):
"""A transport.request object."""
- yield aiohttp_requests.Request(ASYNC_REQUESTS_SESSION)
+ yield aiohttp_requests.Request(aiohttp_session)
+
@pytest.fixture
async def token_info(http_request):
diff --git a/tests_async/transport/test_aiohttp_requests.py b/tests_async/transport/test_aiohttp_requests.py
index 10c31db..a64a4ee 100644
--- a/tests_async/transport/test_aiohttp_requests.py
+++ b/tests_async/transport/test_aiohttp_requests.py
@@ -112,11 +112,18 @@ class TestRequestResponse(async_compliance.RequestResponseTests):
return aiohttp_requests.Request()
def make_with_parameter_request(self):
- http = mock.create_autospec(aiohttp.ClientSession, instance=True)
+ http = aiohttp.ClientSession(auto_decompress=False)
return aiohttp_requests.Request(http)
+ def test_unsupported_session(self):
+ http = aiohttp.ClientSession(auto_decompress=True)
+ with pytest.raises(ValueError):
+ aiohttp_requests.Request(http)
+
def test_timeout(self):
- http = mock.create_autospec(aiohttp.ClientSession, instance=True)
+ http = mock.create_autospec(
+ aiohttp.ClientSession, instance=True, _auto_decompress=False
+ )
request = aiohttp_requests.Request(http)
request(url="http://example.com", method="GET", timeout=5)
@@ -142,7 +149,9 @@ class TestAuthorizedSession(object):
assert authed_session.credentials == mock.sentinel.credentials
def test_constructor_with_auth_request(self):
- http = mock.create_autospec(aiohttp.ClientSession)
+ http = mock.create_autospec(
+ aiohttp.ClientSession, instance=True, _auto_decompress=False
+ )
auth_request = aiohttp_requests.Request(http)
authed_session = aiohttp_requests.AuthorizedSession(