From c6d2f565c84b0a2b8a57d494094e4b70b17b78e9 Mon Sep 17 00:00:00 2001 From: Nikolaos Korasidis Date: Wed, 10 Jun 2015 23:10:43 +0300 Subject: [PATCH] Test receiving FIN packet while disconnected. --- tests/test_connection.py | 16 ++++++++++++++++ txrudp/connection.py | 9 +++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/tests/test_connection.py b/tests/test_connection.py index 13e9347..b3545da 100644 --- a/tests/test_connection.py +++ b/tests/test_connection.py @@ -148,3 +148,19 @@ def test_syn_repeat(self): self.assertEqual(json.loads(m_calls[-1][0][0]), expected_fin_packet) self.assertEqual(m_calls[-1][0][1], address) + + def test_receive_fin_packet_while_disconnected(self): + fin_rudp_packet = packet.RUDPPacket( + 0, + self.own_addr, + self.addr1, + fin=True + ) + + self.proto_mock.reset_mock() + self.handler_mock.reset_mock() + + self.con.receive_packet(fin_rudp_packet) + connection.REACTOR.runUntilCurrent() + + self.handler_mock.handle_shutdown.assert_not_called() diff --git a/txrudp/connection.py b/txrudp/connection.py index 4854297..d25fd7b 100644 --- a/txrudp/connection.py +++ b/txrudp/connection.py @@ -128,10 +128,11 @@ def receive_packet(self, rudp_packet): that the packet had already been validated against packet.RUDP_PACKET_JSON_SCHEMA. """ - if rudp_packet.fin: - self.shutdown() - elif self.connected: - self._process_casual_packet(rudp_packet) + if self.connected: + if rudp_packet.fin: + self.shutdown() + else: + self._process_casual_packet(rudp_packet) elif rudp_packet.syn: self._process_syn_packet(rudp_packet)