diff options
author | Jeff Forcier <jeff@bitprophet.org> | 2023-12-16 13:02:05 -0500 |
---|---|---|
committer | Jeff Forcier <jeff@bitprophet.org> | 2023-12-16 16:16:32 -0500 |
commit | f4dedacb9040d27d9844f51c81c28e0247d3e4a3 (patch) | |
tree | 223c58a7b9921917ca34113e8d252f899eed78e8 /tests | |
parent | c32be441a5ff0dc4914b22d6d1efa392aebe862f (diff) |
Raise new exception type when unexpected messages appear
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_transport.py | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/tests/test_transport.py b/tests/test_transport.py index 12078ba7..060a6cae 100644 --- a/tests/test_transport.py +++ b/tests/test_transport.py @@ -35,6 +35,7 @@ from paramiko import ( AuthHandler, ChannelException, IncompatiblePeer, + MessageOrderError, Packetizer, RSAKey, SSHException, @@ -69,7 +70,7 @@ from ._util import ( TestServer as NullServer, ) from ._loop import LoopSocket -from pytest import skip, mark +from pytest import skip, mark, raises LONG_BANNER = """\ @@ -1279,5 +1280,20 @@ class TestStrictKex: def test_sequence_numbers_reset_on_newkeys(self): skip() - def test_error_raised_on_out_of_order_handshakes(self): - skip() + def test_MessageOrderError_raised_on_out_of_order_messages(self): + with raises(MessageOrderError): + with server() as (tc, _): + # A bit artificial as it's outside kexinit/handshake, but much + # easier to trigger and still in line with behavior under test + tc._expect_packet(MSG_KEXINIT) + tc.open_session() + + def test_SSHException_raised_on_out_of_order_messages_when_not_strict(self): + # This is kind of dumb (either situation is still fatal!) but whatever, + # may as well be strict with our new strict flag... + with raises(SSHException) as info: # would be true either way, but + with server(client_init=dict(strict_kex=False), + ) as (tc, _): + tc._expect_packet(MSG_KEXINIT) + tc.open_session() + assert info.type is SSHException # NOT MessageOrderError! |