Skip to content

Commit

Permalink
CI (FreeBSD): Re-added tests which had been skipped by mistake
Browse files Browse the repository at this point in the history
  • Loading branch information
francis-clairicia committed Oct 20, 2024
1 parent 2821e97 commit fb8e96a
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 16 deletions.
32 changes: 24 additions & 8 deletions tests/functional_test/test_communication/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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("[email protected]")


@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)
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 3 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit fb8e96a

Please sign in to comment.