test_DDoSAttack.py 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import unittest.mock as mock
  2. import ID2TLib.TestLibrary as Lib
  3. import Test.ID2TAttackTest as Test
  4. sha_basic_ddos = 'd30a14ba0568cb9c3be0db6a6d8e5d68b703d995015fc2215bfa150a8aff8b2a'
  5. sha_num_attackers_ddos = '0de1ac89bb02e0163a31a0215d59ef2e2d819ffb904f8a99be1ecb52a568a392'
  6. sha_dest_mac_length_zero_ddos = '55720bc3aa43a6abad2db1bd1f9c7ff71cb50f11ca5f17995b24184678c18226'
  7. sha_mss_none_ddos = 'd30a14ba0568cb9c3be0db6a6d8e5d68b703d995015fc2215bfa150a8aff8b2a'
  8. sha_one_attacker_ddos = '8bb7798e85cff15b91c5ee2c0bb65f01ff3097a417bdd2e58a540f89d542bea9'
  9. sha_ip_range_ddos = 'bef5deb3cc7ee7537a90a85323cf885cf5a0431e15ae7001c0c762afc643e7a6'
  10. sha_port_range_ddos = '082f9bee607931751087fc4004bc95bf225f23b2a54ce1f771969019a5443ee7'
  11. class UnitTestDDoS(Test.ID2TAttackTest):
  12. @mock.patch('ID2TLib.Utility.get_attacker_config', side_effect=Lib.get_attacker_config)
  13. def test_ddos_basic(self, mock_get_attacker_config):
  14. self.checksum_test([['DDoSAttack']],
  15. sha_basic_ddos)
  16. @mock.patch('ID2TLib.Utility.get_attacker_config', side_effect=Lib.get_attacker_config)
  17. def test_ddos_num_attackers(self, mock_get_attacker_config):
  18. self.checksum_test([['DDoSAttack', 'attackers.count=5']],
  19. sha_num_attackers_ddos)
  20. @mock.patch('ID2TLib.Utility.get_attacker_config', side_effect=Lib.get_attacker_config)
  21. @mock.patch('Core.Statistics.Statistics.get_mac_address', return_value=[])
  22. def test_ddos_dest_mac_length_zero(self, mock_dest_mac, mock_get_attacker_config):
  23. self.checksum_test([['DDoSAttack']], sha_dest_mac_length_zero_ddos)
  24. @mock.patch('ID2TLib.Utility.get_attacker_config', side_effect=Lib.get_attacker_config)
  25. @mock.patch('Core.Statistics.Statistics.get_most_used_mss', return_value=None)
  26. def test_ddos_mss_none(self, mock_mss, mock_get_attacker_config):
  27. self.checksum_test([['DDoSAttack']], sha_mss_none_ddos)
  28. @mock.patch('ID2TLib.Utility.get_attacker_config', side_effect=Lib.get_attacker_config)
  29. def test_ddos_one_attacker(self, mock_get_attacker_config):
  30. self.checksum_test([['DDoSAttack', 'ip.src=1.1.1.1']],
  31. sha_one_attacker_ddos)
  32. @mock.patch('ID2TLib.Utility.get_attacker_config', side_effect=Lib.get_attacker_config)
  33. def test_ddos_ip_range(self, mock_get_attacker_config):
  34. self.checksum_test([['DDoSAttack', 'ip.src=1.1.1.1-1.1.1.10']],
  35. sha_ip_range_ddos)
  36. @mock.patch('ID2TLib.Utility.get_attacker_config', side_effect=Lib.get_attacker_config)
  37. def test_ddos_port_range(self, mock_get_attacker_config):
  38. self.checksum_test([['DDoSAttack', 'attackers.count=5', 'port.src=1000-2000']],
  39. sha_port_range_ddos)
  40. def test_ddos_order(self):
  41. self.order_test([['DDoSAttack', 'attackers.count=5']])