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

Added more test cases

parent c1e08c29
No related branches found
No related tags found
No related merge requests found
import time
import unittest
from scapy.layers.inet import IP, TCP
......@@ -14,7 +15,10 @@ class TestPacketCapturing(unittest.TestCase):
def test_baseCase(self):
# Create a dummy packet
packet = IP(src = "100.84.6.141", dst = "192.168.1.1") / TCP(dport = 80, sport = 12345, flags = "S")
# Ether addresses are placeholders
packet = (IP(src = "100.84.6.141", dst = "192.168.1.1") /
TCP(dport = 80, sport = 12345, flags = "S") /
Ether(src="00:11:22:33:44:55", dst="ff:ff:ff:ff:ff:ff"))
# Show detailed information about the package
print(packet.show())
......@@ -33,7 +37,7 @@ class TestPacketCapturing(unittest.TestCase):
def test_syn_fin(self):
# Has S and F flags, which is also known as SYN-FIN, which is a malicious packet signature
# Ether addresses are placeholders
packet = IP(src = "100.84.6.141", dst = "192.168.1.1") / TCP(dport = 80, flags = "SF") / Ether(src="00:11:22:33:44:55", dst="ff:ff:ff:ff:ff:ff")
with patch('builtins.print') as mock_print:
......@@ -62,11 +66,16 @@ class TestPacketCapturing(unittest.TestCase):
mock_print.assert_any_call("Illegal packet with source or destination port 0.")
def test_syn_flood_detection(self):
packet = IP(src="100.84.6.141", dst="192.168.1.1") / TCP(dport=80, sport=0, flags="S")
for i in range (101):
syn_flood_detection(packet)
packet = (IP(src="100.84.6.141", dst="192.168.1.1") /
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(101):
syn_flood_detection(packet)
self.assertEqual({"100.84.6.141": 101}, get_dict(), "Expected the packet's IP with 101 entries")
mock_print.assert_called()
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