Skip to content
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
7 changes: 3 additions & 4 deletions packages/google-auth/google/auth/aio/transport/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,13 @@ async def _do_configure():
) = await mtls.get_client_cert_and_key(client_cert_callback)

if is_mtls:
ssl_context = await mtls._run_in_executor(
mtls.make_client_cert_ssl_context, cert, key
)

# Re-create the auth request with the new SSL context
if AIOHTTP_INSTALLED and isinstance(
self._auth_request, AiohttpRequest
):
ssl_context = await mtls._run_in_executor(
mtls.make_client_cert_ssl_context, cert, key
)
connector = aiohttp.TCPConnector(ssl=ssl_context)
new_session = aiohttp.ClientSession(connector=connector)

Expand Down
26 changes: 26 additions & 0 deletions packages/google-auth/tests/transport/aio/test_sessions.py

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe there is a small formatting change needed here to "fix" the failing lint CI.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed ✅

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks - small nit on workflow - in the future try to avoid force pushing, especially after reviews have started, as it can makes following the changes a bit more challenging (though in this case, no harm was really done given the scope of the PR).

Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,32 @@ async def test_http_delete_method_success(self):
assert await response.read() == expected_payload
response = await authed_session.close()

@pytest.mark.asyncio
async def test_configure_mtls_channel_with_custom_transport_and_broken_cert(self):
auth_request = MockRequest()
authed_session = sessions.AsyncAuthorizedSession(
self.credentials, auth_request=auth_request
)

with patch(
"google.auth.transport._mtls_helper.check_use_client_cert",
return_value=True,
):

def callback():
return b"invalid-cert", b"invalid-key"

with pytest.warns(
UserWarning,
match="Attempted to establish mTLS, but a custom async transport was provided",
):
await authed_session.configure_mtls_channel(callback)

assert authed_session._is_mtls is False
assert authed_session._cached_cert is None

await authed_session.close()


def test_mock_request_clone():
request = MockRequest()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,7 @@ async def test_configure_mtls_channel_custom_request(self):
# If the request handler is not an AiohttpRequest, the library cannot configure
# the connection to use mTLS, so _is_mtls must be False to reflect this unconfigured state.
assert session._is_mtls is False
mock_make_context.assert_called_once_with(
b"fake_cert_data", b"fake_key_data"
)
mock_make_context.assert_not_called()
await session.close()

@pytest.mark.asyncio
Expand Down
Loading