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

added more tests

parent 0e5b618e
No related branches found
No related tags found
No related merge requests found
import unittest
from scapy.layers.inet import IP, TCP
from unittest.mock import patch
from scapy.layers.l2 import Ether
from src.packet_capturing import packet_handler
......@@ -24,5 +25,34 @@ class TestPacketCapturing(unittest.TestCase):
packet_handler(packet)
mock_print.assert_called_with("Possible IP spoofing using private networks detected.")
def test_syn_fin(self):
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:
packet_handler(packet)
mock_print.assert_any_call("Malicious packet detected: SYN-FIN combination.")
def test_null_packet(self):
packet = IP(src = "100.84.6.141", dst = "192.168.1.1") / TCP(dport = 80, flags = 0) / 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)
mock_print.assert_any_call("Malicious null packet found.")
def test_port_dest_check(self):
packet = IP(src="100.84.6.141", dst="192.168.1.1") / TCP(dport = 0, sport = 200, 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)
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")
with patch('builtins.print') as mock_print:
packet_handler(packet)
mock_print.assert_any_call("Illegal packet with source or destination port 0.")
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