From bf92f246699be17822598d3933bb34b8815023cc Mon Sep 17 00:00:00 2001 From: Carey Metcalfe Date: Wed, 16 Oct 2019 23:24:49 -0400 Subject: [PATCH] Add test for invalid packets --- tests.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests.py b/tests.py index 713ad5f..0dcc9a6 100755 --- a/tests.py +++ b/tests.py @@ -33,6 +33,8 @@ PACKETS = [ '0009000c000000035c9f55980000000400000000040001e47f0000017f000001fb3d7ba2fb3d7ba00000004c0000000100000000000000000035a399110004007f0000017f000001fb3d7ba2fb3d7ba00000003c000000010000000000000000a3990035110004007f0000017f000001fb3d8f85fb3d7b9f000003070000000500000000000000000050943c061b04007f0000017f000001fb3d8f85fb3d7b9f000002a2000000050000000000000000943c0050061b04007f0000017f000001fb3d9165fb3d7f6d0000c97b0000002a000000000000000001bbae48061b04007f0000017f000001fb3d9165fb3d7f6d000007f40000001a0000000000000000ae4801bb061b04007f0000017f000001fb3dbc96fb3dbc7e0000011e0000000200000000000000000035bd4f110004007f0000017f000001fb3dbc96fb3dbc7e0000008e000000020000000000000000bd4f0035110004007f0000017f000001fb3ddbb3fb3c1a180000bfee0000002f00000000000000000050ae56061b04007f0000017f000001fb3ddbb3fb3c1a1800000982000000270000000000000000ae560050061b04007f0000017f000001fb3ddbb3fb3c1a180000130e0000001200000000000000000050e820061b04007f0000017f000001fb3ddbb3fb3c1a180000059c000000140000000000000000e8200050061b0400' ] +INVALID_PACKET = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" + CONNECTION = ('127.0.0.1', 1337) NUM_PACKETS = 500 @@ -114,6 +116,15 @@ class TestSoftFlowExport(unittest.TestCase): """Test all packets are received when things are sent slooooowwwwwwwwlllllllyyyyyy""" self._test_recv_all_packets(3, 0, delay=1) + def test_ignore_invalid_packets(self): + """Test that invlalid packets log a warning but are otherwise ignored""" + with self.assertLogs(level='WARNING'): + pkts, _, _ = send_recv_packets([ + INVALID_PACKET, TEMPLATE_PACKET, random.choice(PACKETS), INVALID_PACKET, + random.choice(PACKETS), INVALID_PACKET + ]) + self.assertEqual(len(pkts), 3) + def test_analyzer(self): """Test thar the analyzer doesn't break and outputs the correct number of lines""" pkts, _, _ = send_recv_packets([TEMPLATE_PACKET, *PACKETS])