import unittest.mock as mock import ID2TLib.TestLibrary as Lib import Test.ID2TAttackTest as Test sha_basic_ddos = 'a9b75322e2a331f617250d14935b0235aa818dd08803584d9cc3560b8305b459' sha_num_attackers_ddos = '86f13efe33d3e07c282d0111da09dead12bda1c2047d85e3a2c2f8d02b49e151' sha_dest_mac_length_zero_ddos = 'df4c55d25c3e13e38294f036e8ce17d7aaea309ecb9ade4eb551ed61589c0648' sha_mss_none_ddos = 'a9b75322e2a331f617250d14935b0235aa818dd08803584d9cc3560b8305b459' sha_one_attacker_ddos = 'd706c8594f54ab31f02700366fb9bfa872f9cc0e6393a9ed80bf255432e9cce8' sha_ip_range_ddos = '867b560a415562ffb6e973e57cdddf856826e6931dd1dbd732c6799fdc078f25' sha_port_range_ddos = 'f9adfe2d86fca0c66904a9b358e4bf31e122095eb2877f4ebcaec8e60b482ade' class UnitTestDDoS(Test.ID2TAttackTest): @mock.patch('ID2TLib.Utility.get_attacker_config', side_effect=Lib.get_attacker_config) def test_ddos_basic(self, mock_get_attacker_config): self.checksum_test([['DDoSAttack']], sha_basic_ddos) @mock.patch('ID2TLib.Utility.get_attacker_config', side_effect=Lib.get_attacker_config) def test_ddos_num_attackers(self, mock_get_attacker_config): self.checksum_test([['DDoSAttack', 'attackers.count=5']], sha_num_attackers_ddos) @mock.patch('ID2TLib.Utility.get_attacker_config', side_effect=Lib.get_attacker_config) @mock.patch('Core.Statistics.Statistics.get_mac_address', return_value=[]) def test_ddos_dest_mac_length_zero(self, mock_dest_mac, mock_get_attacker_config): self.checksum_test([['DDoSAttack']], sha_dest_mac_length_zero_ddos) @mock.patch('ID2TLib.Utility.get_attacker_config', side_effect=Lib.get_attacker_config) @mock.patch('Core.Statistics.Statistics.get_most_used_mss', return_value=None) def test_ddos_mss_none(self, mock_mss, mock_get_attacker_config): self.checksum_test([['DDoSAttack']], sha_mss_none_ddos) @mock.patch('ID2TLib.Utility.get_attacker_config', side_effect=Lib.get_attacker_config) def test_ddos_one_attacker(self, mock_get_attacker_config): self.checksum_test([['DDoSAttack', 'ip.src=1.1.1.1']], sha_one_attacker_ddos) @mock.patch('ID2TLib.Utility.get_attacker_config', side_effect=Lib.get_attacker_config) def test_ddos_ip_range(self, mock_get_attacker_config): self.checksum_test([['DDoSAttack', 'ip.src=1.1.1.1-1.1.1.10']], sha_ip_range_ddos) @mock.patch('ID2TLib.Utility.get_attacker_config', side_effect=Lib.get_attacker_config) def test_ddos_port_range(self, mock_get_attacker_config): self.checksum_test([['DDoSAttack', 'attackers.count=5', 'port.src=1000-2000']], sha_port_range_ddos) def test_ddos_order(self): self.order_test([['DDoSAttack', 'attackers.count=5']])