Skip to content

Commit

Permalink
Avoid mypy failure, use aiohttp_client, aiohttp_raw_server fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
auxsvr committed Mar 13, 2023
1 parent f032de8 commit 62435c0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 29 deletions.
6 changes: 1 addition & 5 deletions aiohttp/client_reqrep.py
Original file line number Diff line number Diff line change
Expand Up @@ -861,11 +861,7 @@ async def start(self, connection: "Connection") -> "ClientResponse":
set_result(self._continue, True)
self._continue = None

# certificate
is_tls_transport = (
self._connection is not None and self._connection.transport is not None
)
if is_tls_transport:
if self._connection is not None and self._connection.transport is not None:
self.certificate = self._connection.transport.get_extra_info("peercert")

# payload eof handler
Expand Down
2 changes: 1 addition & 1 deletion docs/client_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1363,7 +1363,7 @@ Response object
.. attribute:: certificate

The server certificate. This is available with TLS connections,
if the certificate is retrieved before the connection or the TLS session are
if the certificate is retrieved before the connection or the TLS session is
closed, otherwise it is ``None``.

.. method:: close()
Expand Down
43 changes: 20 additions & 23 deletions tests/test_client_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -1232,29 +1232,26 @@ def test_gen_default_accept_encoding(has_brotli: Any, expected: Any) -> None:
assert _gen_default_accept_encoding() == expected


async def test_certificate_exists(ssl_ctx, client_ssl_ctx) -> None:
async def test_certificate_exists(
ssl_ctx: Any, client_ssl_ctx: Any, aiohttp_client: Any, aiohttp_raw_server: Any
) -> None:
async def handler(request):
return web.Response(text="ok")

server = web.Server(handler)
runner = web.ServerRunner(server)
await runner.setup()
site = web.TCPSite(runner, ssl_context=ssl_ctx)
await site.start()

async with aiohttp.ClientSession() as session:
resp = await session.get("https://127.0.0.1:8443", ssl=client_ssl_ctx)
assert frozenset(resp.certificate) >= frozenset(
(
"subject",
"issuer",
"version",
"serialNumber",
"notBefore",
"notAfter",
"subjectAltName",
)
)
resp.close()
await site.stop()
await server.shutdown()
server = await aiohttp_raw_server(handler, ssl=ssl_ctx)

async with await aiohttp_client(
server, connector=aiohttp.TCPConnector(ssl=client_ssl_ctx)
) as client:
async with await client.get("/") as resp:
assert frozenset(resp.certificate) >= frozenset(
(
"subject",
"issuer",
"version",
"serialNumber",
"notBefore",
"notAfter",
"subjectAltName",
)
)

0 comments on commit 62435c0

Please sign in to comment.