Test that we detect bad noise psks (#688)

This commit is contained in:
J. Nick Koston 2023-11-24 10:29:55 -06:00 committed by GitHub
parent 837d6ad650
commit 412a78aa04
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 21 additions and 0 deletions

View File

@ -715,3 +715,24 @@ async def test_connection_lost_closes_connection_and_logs(
assert "original message" in caplog.text
with pytest.raises(APIConnectionError, match="original message"):
await connect_task
@pytest.mark.asyncio
@pytest.mark.parametrize(
("bad_psk", "error"),
(
("dGhpc2lzbm90MzJieXRlcw==", "expected 32-bytes of base64 data"),
("QRTIErOb/fcE9Ukd/5qA3RGYMn0Y+p06U58SCtOXvPc", "Malformed PSK"),
),
)
async def test_noise_bad_psks(bad_psk: str, error: str) -> None:
"""Test we raise on bad psks."""
connection, _ = _make_mock_connection()
with pytest.raises(InvalidEncryptionKeyAPIError, match=error):
MockAPINoiseFrameHelper(
connection=connection,
noise_psk=bad_psk,
expected_name="wrongname",
client_info="my client",
log_name="test",
)