Skip to content

Commit 9244f23

Browse files
committed
programs: Add end-to-end D/TLS tests
1 parent fef5e60 commit 9244f23

File tree

3 files changed

+79
-1
lines changed

3 files changed

+79
-1
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ jobs:
5050
&& powershell %CD%\scripts\install-mbedtls.ps1 -ConfigurationType DynamicLibrary %HOMEDRIVE%%HOMEPATH%\mbedtls
5151
&& dir %LIB%
5252
CIBW_TEST_REQUIRES: -rrequirements/tests.txt
53-
CIBW_TEST_COMMAND: pytest {project}/tests
53+
CIBW_TEST_COMMAND: pytest -m "not local" {project}/tests
5454
- name: Inventory
5555
run: ls wheelhouse
5656
- name: Upload wheels

pytest.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[pytest]
2+
markers =
3+
local: Socket, I/O, multiprocessing... Would be flaky on a CI.

tests/test_tls.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import datetime as dt
22
import pickle
33
import socket
4+
import subprocess
45
from contextlib import suppress
6+
from pathlib import Path
57

68
import pytest
79

@@ -618,3 +620,76 @@ def test_dtls(self):
618620
amt = server.write(secret)
619621
do_io(src=server, dst=client)
620622
assert client.read(amt) == secret
623+
624+
625+
@pytest.mark.local
626+
class TestPrograms:
627+
@pytest.fixture
628+
def rootpath(self):
629+
return Path(__file__).parent.parent
630+
631+
@pytest.fixture
632+
def tls_server(self, rootpath):
633+
proc = subprocess.Popen(
634+
[
635+
rootpath / "programs" / "server.py",
636+
"--tls",
637+
"--psk-store",
638+
"cli=secret",
639+
]
640+
)
641+
yield proc
642+
proc.kill()
643+
proc.wait(1.0)
644+
645+
@pytest.fixture
646+
def dtls_server(self, rootpath):
647+
proc = subprocess.Popen(
648+
[
649+
rootpath / "programs" / "server.py",
650+
"--dtls",
651+
"--psk-store",
652+
"cli=secret",
653+
]
654+
)
655+
yield proc
656+
proc.kill()
657+
proc.wait(1.0)
658+
659+
@pytest.mark.usefixtures("tls_server")
660+
@pytest.mark.timeout(10)
661+
def test_e2e_tls(self, rootpath):
662+
secret = b"a very secret message"
663+
664+
for _ in range(3):
665+
with subprocess.Popen(
666+
[
667+
rootpath / "programs" / "client.py",
668+
"--tls",
669+
"--psk",
670+
"cli=secret",
671+
secret,
672+
],
673+
stdout=subprocess.PIPE,
674+
) as client:
675+
out, err = client.communicate()
676+
assert out == secret + b"\n"
677+
678+
@pytest.mark.usefixtures("dtls_server")
679+
@pytest.mark.timeout(10)
680+
def test_e2e_dtls(self, rootpath):
681+
secret = b"a very secret message"
682+
683+
for _ in range(3):
684+
with subprocess.Popen(
685+
[
686+
rootpath / "programs" / "client.py",
687+
"--dtls",
688+
"--psk",
689+
"cli=secret",
690+
secret,
691+
],
692+
stdout=subprocess.PIPE,
693+
) as client:
694+
out, err = client.communicate()
695+
assert out == secret + b"\n"

0 commit comments

Comments
 (0)