From d5ef22009c46a693f45e29b5e7d778a4c219d540 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francis=20Clairicia-Rose-Claire-Jos=C3=A9phine?= Date: Sun, 20 Oct 2024 14:40:49 +0200 Subject: [PATCH] CI (FreeBSD): Re-added tests which had been skipped by mistake (#368) --- .../test_communication/conftest.py | 32 ++++++++++++++----- .../test_async/test_client/test_tcp.py | 9 +++++- .../test_async/test_server/test_tcp.py | 15 ++++++--- .../test_sync/test_client/test_tcp.py | 5 ++- tox.ini | 5 +-- 5 files changed, 50 insertions(+), 16 deletions(-) diff --git a/tests/functional_test/test_communication/conftest.py b/tests/functional_test/test_communication/conftest.py index dd55706a..86af2932 100644 --- a/tests/functional_test/test_communication/conftest.py +++ b/tests/functional_test/test_communication/conftest.py @@ -125,27 +125,37 @@ def socket_pair(localhost_ip: str, tcp_socket_factory: Callable[[], Socket]) -> @pytest.fixture(scope="session") -def ssl_certificate_authority() -> trustme.CA: +def ssl_certificate_authority() -> trustme.CA | None: try: import trustme except ModuleNotFoundError: - pytest.skip("trustme is not installed") - - return trustme.CA() + return None + else: + return trustme.CA() @pytest.fixture(scope="session") -def server_certificate(ssl_certificate_authority: trustme.CA) -> trustme.LeafCert: +def server_certificate(ssl_certificate_authority: trustme.CA | None) -> trustme.LeafCert | None: + if ssl_certificate_authority is None: + return None return ssl_certificate_authority.issue_cert("*.example.com") @pytest.fixture(scope="session") -def client_certificate(ssl_certificate_authority: trustme.CA) -> trustme.LeafCert: +def client_certificate(ssl_certificate_authority: trustme.CA | None) -> trustme.LeafCert | None: + if ssl_certificate_authority is None: + return None return ssl_certificate_authority.issue_cert("client@example.com") @pytest.fixture -def server_ssl_context(ssl_certificate_authority: trustme.CA, server_certificate: trustme.LeafCert) -> ssl.SSLContext: +def server_ssl_context( + ssl_certificate_authority: trustme.CA | None, + server_certificate: trustme.LeafCert | None, +) -> ssl.SSLContext | None: + if ssl_certificate_authority is None or server_certificate is None: + return None + server_ssl_context = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH) server_certificate.configure_cert(server_ssl_context) @@ -157,7 +167,13 @@ def server_ssl_context(ssl_certificate_authority: trustme.CA, server_certificate @pytest.fixture -def client_ssl_context(ssl_certificate_authority: trustme.CA, client_certificate: trustme.LeafCert) -> ssl.SSLContext: +def client_ssl_context( + ssl_certificate_authority: trustme.CA | None, + client_certificate: trustme.LeafCert | None, +) -> ssl.SSLContext | None: + if ssl_certificate_authority is None or client_certificate is None: + return None + client_ssl_context = ssl.create_default_context() client_certificate.configure_cert(client_ssl_context) diff --git a/tests/functional_test/test_communication/test_async/test_client/test_tcp.py b/tests/functional_test/test_communication/test_async/test_client/test_tcp.py index d602447e..7e54ffe6 100644 --- a/tests/functional_test/test_communication/test_async/test_client/test_tcp.py +++ b/tests/functional_test/test_communication/test_async/test_client/test_tcp.py @@ -440,7 +440,14 @@ async def test____send_packet____recv_packet____implicit_connection( class TestAsyncSSLOverTCPNetworkClient: @pytest_asyncio.fixture(autouse=True) @staticmethod - async def server(localhost_ip: str, socket_family: int, server_ssl_context: ssl.SSLContext) -> AsyncIterator[asyncio.Server]: + async def server( + localhost_ip: str, + socket_family: int, + server_ssl_context: ssl.SSLContext | None, + ) -> AsyncIterator[asyncio.Server]: + if server_ssl_context is None: + pytest.skip("trustme is not installed") + async def client_connected_cb(reader: asyncio.StreamReader, writer: asyncio.StreamWriter) -> None: try: data: bytes = await reader.readline() diff --git a/tests/functional_test/test_communication/test_async/test_server/test_tcp.py b/tests/functional_test/test_communication/test_async/test_server/test_tcp.py index 512fbf19..4d1e9477 100644 --- a/tests/functional_test/test_communication/test_async/test_server/test_tcp.py +++ b/tests/functional_test/test_communication/test_async/test_server/test_tcp.py @@ -400,14 +400,18 @@ async def server( localhost_ip: str, stream_protocol: AnyStreamProtocolType[str, str], use_ssl: bool, - server_ssl_context: ssl.SSLContext, + server_ssl_context: ssl.SSLContext | None, ssl_handshake_timeout: float | None, ssl_standard_compatible: bool | None, caplog: pytest.LogCaptureFixture, logger_crash_threshold_level: dict[str, int], ) -> AsyncIterator[MyAsyncTCPServer]: - # Remove this option for non-regression - server_ssl_context.options &= ~ssl.OP_IGNORE_UNEXPECTED_EOF + if server_ssl_context is None: + if use_ssl: + pytest.skip("trustme is not installed") + else: + # Remove this option for non-regression + server_ssl_context.options &= ~ssl.OP_IGNORE_UNEXPECTED_EOF async with MyAsyncTCPServer( localhost_ip, @@ -449,8 +453,11 @@ async def client_factory_no_handshake( asyncio_backend: AsyncIOBackend, server_address: tuple[str, int], use_ssl: bool, - client_ssl_context: ssl.SSLContext, + client_ssl_context: ssl.SSLContext | None, ) -> AsyncIterator[Callable[[], Awaitable[tuple[asyncio.StreamReader, asyncio.StreamWriter]]]]: + if client_ssl_context is None and use_ssl: + pytest.skip("trustme is not installed") + async with contextlib.AsyncExitStack() as stack: stack.enter_context(contextlib.suppress(OSError)) diff --git a/tests/functional_test/test_communication/test_sync/test_client/test_tcp.py b/tests/functional_test/test_communication/test_sync/test_client/test_tcp.py index 7c1b7be6..9a1bf0a0 100644 --- a/tests/functional_test/test_communication/test_sync/test_client/test_tcp.py +++ b/tests/functional_test/test_communication/test_sync/test_client/test_tcp.py @@ -326,10 +326,13 @@ def server( cls, localhost_ip: str, socket_family: int, - server_ssl_context: ssl.SSLContext, + server_ssl_context: ssl.SSLContext | None, ) -> Iterator[socketserver.TCPServer]: from threading import Thread + if server_ssl_context is None: + pytest.skip("trustme is not installed") + with TCPServer((localhost_ip, 0), socket_family, ssl_context=server_ssl_context) as server: server_thread = Thread(target=server.serve_forever, daemon=True) server_thread.start() diff --git a/tox.ini b/tox.ini index eae9d0c0..c6cb9e6e 100644 --- a/tox.ini +++ b/tox.ini @@ -101,7 +101,7 @@ commands = msgpack: pytest -m "feature_msgpack" {posargs} {env:TESTS_ROOTDIR} trio: pytest -n "{env:PYTEST_MAX_WORKERS:auto}" -m "feature_trio" {posargs} {env:TESTS_ROOTDIR} -[testenv:{py311,py312,py313}-functional-{asyncio_proactor,uvloop}{,-bsd}] +[testenv:{py311,py312,py313}-functional-{asyncio_proactor,uvloop}] package = wheel wheel_build_env = {[base]wheel_build_env} platform = @@ -132,7 +132,8 @@ commands = skip_install = true depends = unit: {py311,py312,py313}-unit-{standard,cbor,msgpack,trio}{,-bsd} - functional: {py311,py312,py313}-functional-{standard,cbor,msgpack,trio,asyncio_proactor,uvloop}{,-bsd} + functional: {py311,py312,py313}-functional-{standard,cbor,msgpack,trio}{,-bsd} + functional: {py311,py312,py313}-functional-{asyncio_proactor,uvloop} full: coverage-{unit,functional} parallel_show_output = full: True