Skip to content
Snippets Groups Projects
Commit b6d7fff9 authored by Daniel Yang's avatar Daniel Yang
Browse files

Fixed test_syn_flood_detection

parent c9f24015
No related branches found
No related tags found
No related merge requests found
......@@ -2,7 +2,7 @@ import time
import unittest
from scapy.layers.inet import IP, TCP
from unittest.mock import patch, MagicMock
from unittest.mock import patch
from scapy.layers.l2 import Ether
from packet_capturing import packet_handler, get_dict, dict_clear, syn_flood_detection, port_check, ip_spoofing, \
......@@ -60,7 +60,9 @@ class TestPacketCapturing(unittest.TestCase):
mock_print.assert_any_call("Illegal packet with source or destination port 0.")
def test_port_src_check(self):
packet = IP(src="100.84.6.141", dst="192.168.1.1") / TCP(dport=80, sport=0, flags="F") / Ether(src="00:11:22:33:44:55", dst="ff:ff:ff:ff:ff:ff")
packet = (IP(src="100.84.6.141", dst="192.168.1.1") /
TCP(dport=80, sport=0, flags="F") /
Ether(src="00:11:22:33:44:55", dst="ff:ff:ff:ff:ff:ff"))
with patch('builtins.print') as mock_print:
packet_handler(packet)
......@@ -72,12 +74,15 @@ class TestPacketCapturing(unittest.TestCase):
TCP(dport=80, sport=123, flags="S") /
Ether(src="00:11:22:33:44:55", dst="ff:ff:ff:ff:ff:ff"))
with patch('builtins.print') as mock_print:
for i in range(repetitions):
syn_flood_detection(packet)
time.sleep(10)
syn_flood_detection(packet)
mock_print.assert_called()
self.assertEqual({"100.84.6.141": repetitions}, get_dict(), f"Expected the packet's IP to contain {repetitions} entries.")
self.assertEqual({}, get_dict(), "Expected the packet's IP")
if __name__ == '__main__':
unittest.main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment