Skip to content
Closed
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 CHANGES/11465.contrib.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed tests to run without trustme installed -- by :user:`kumaraditya303`.
16 changes: 9 additions & 7 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,14 @@ def blockbuster(request: pytest.FixtureRequest) -> Iterator[None]:


@pytest.fixture
def tls_certificate_authority() -> trustme.CA:
def tls_certificate_authority() -> "trustme.CA":
if not TRUSTME:
pytest.xfail("trustme is not supported")
return trustme.CA()


@pytest.fixture
def tls_certificate(tls_certificate_authority: trustme.CA) -> trustme.LeafCert:
def tls_certificate(tls_certificate_authority: "trustme.CA") -> "trustme.LeafCert":
return tls_certificate_authority.issue_cert(
"localhost",
"xn--prklad-4va.localhost",
Expand All @@ -113,33 +113,35 @@ def tls_certificate(tls_certificate_authority: trustme.CA) -> trustme.LeafCert:


@pytest.fixture
def ssl_ctx(tls_certificate: trustme.LeafCert) -> ssl.SSLContext:
def ssl_ctx(tls_certificate: "trustme.LeafCert") -> ssl.SSLContext:
ssl_ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
tls_certificate.configure_cert(ssl_ctx)
return ssl_ctx


@pytest.fixture
def client_ssl_ctx(tls_certificate_authority: trustme.CA) -> ssl.SSLContext:
def client_ssl_ctx(tls_certificate_authority: "trustme.CA") -> ssl.SSLContext:
ssl_ctx = ssl.create_default_context(purpose=ssl.Purpose.SERVER_AUTH)
tls_certificate_authority.configure_trust(ssl_ctx)
return ssl_ctx


@pytest.fixture
def tls_ca_certificate_pem_path(tls_certificate_authority: trustme.CA) -> Iterator[str]:
def tls_ca_certificate_pem_path(
tls_certificate_authority: "trustme.CA",
) -> Iterator[str]:
with tls_certificate_authority.cert_pem.tempfile() as ca_cert_pem:
yield ca_cert_pem


@pytest.fixture
def tls_certificate_pem_path(tls_certificate: trustme.LeafCert) -> Iterator[str]:
def tls_certificate_pem_path(tls_certificate: "trustme.LeafCert") -> Iterator[str]:
with tls_certificate.private_key_and_cert_chain_pem.tempfile() as cert_pem:
yield cert_pem


@pytest.fixture
def tls_certificate_pem_bytes(tls_certificate: trustme.LeafCert) -> bytes:
def tls_certificate_pem_bytes(tls_certificate: "trustme.LeafCert") -> bytes:
return tls_certificate.cert_chain_pems[0].bytes()


Expand Down
7 changes: 5 additions & 2 deletions tests/test_client_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import zipfile
from contextlib import suppress
from typing import (
TYPE_CHECKING,
Any,
AsyncIterator,
Awaitable,
Expand All @@ -29,7 +30,6 @@
from unittest import mock

import pytest
import trustme
from multidict import MultiDict
from pytest_mock import MockerFixture
from yarl import URL
Expand Down Expand Up @@ -62,6 +62,9 @@
from aiohttp.test_utils import TestClient, TestServer, unused_port
from aiohttp.typedefs import Handler, Query

if TYPE_CHECKING:
import trustme


@pytest.fixture(autouse=True)
def cleanup(
Expand Down Expand Up @@ -3259,7 +3262,7 @@ async def close(self) -> None:

@pytest.fixture
def create_server_for_url_and_handler(
aiohttp_server: AiohttpServer, tls_certificate_authority: trustme.CA
aiohttp_server: AiohttpServer, tls_certificate_authority: "trustme.CA"
) -> Callable[[URL, Handler], Awaitable[TestServer]]:
def create(url: URL, srv: Handler) -> Awaitable[TestServer]:
app = web.Application()
Expand Down
Loading