Skip to content

Commit c7c5185

Browse files
committed
Add unit test for pskproxy
Rudamentary, as it only checks gen_psk() and not ssl.wrap_socket (and as such won't catch issues like sslpsk#16), but the best we can do for now and without modifying the code itself.
1 parent 5fa9208 commit c7c5185

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

tests/test_psk.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env python3
2+
"""Test the smarthack.pskproxy module."""
3+
4+
# Copyright (c) 2020 Faidon Liambotis
5+
# SPDX-License-Identifier: MIT
6+
7+
import pytest # type: ignore
8+
9+
from smarthack.pskproxy import IDENTITY_PREFIX, gen_psk
10+
11+
12+
PREFIX = b"\x01" + IDENTITY_PREFIX
13+
HINT = b"1dHRsc2NjbHltbGx3eWh5" b"0000000000000000" # taken from the code being tested
14+
PRECOMPUTED = (
15+
("", "310ab75a8d067ccea734482eb07adf04"),
16+
("00" * 16, "3100cad5df5a8f719407b55e0ff55e883c53ab665efe02bd1bb93d7eda9e15e2"),
17+
("80" * 16, "36ac9fe6f25bb46b652eeb78c9dbf2c6675f82bf574808da316295cab811efc5"),
18+
(
19+
"fef0f7f7d1fff1602f64cbdb482d86dc5f35949857a88ba085f9c17b7cae02ed95",
20+
"5578f55f9e82e8ab7ea053cbacc7a3f4cc1cfd51ac202a447c5e3155bf347078",
21+
),
22+
)
23+
24+
25+
def test_gen_psk() -> None:
26+
"""Test the gen_psk() method against precomputed data."""
27+
for clear, encrypted in PRECOMPUTED:
28+
identity = PREFIX + bytes.fromhex(clear)
29+
assert gen_psk(identity, HINT).hex() == encrypted
30+
31+
with pytest.raises(ValueError):
32+
assert gen_psk(b"not 16 chars", HINT)

0 commit comments

Comments
 (0)