test_DDoS.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334
  1. import unittest.mock as mock
  2. import Test.ID2TAttackTest as Test
  3. import ID2TLib.TestLibrary as Lib
  4. sha_basic_ddos = '87c6c9cf4b496b84fecfd758c1d891ff06fe234dba2f421a5ab8bd7d6d9239a5'
  5. sha_num_attackers_ddos = 'cbbb9b55d03a0efde965bbb8c38f6ba8a9acbd605cb2f3ac22a6ed6e3958f8e9'
  6. sha_dest_mac_length_zero_ddos = 'acf1d108ab3d4e76636c6b58e08296126a74fcf3936377588376a79716fffd60'
  7. sha_mss_none_ddos = '87c6c9cf4b496b84fecfd758c1d891ff06fe234dba2f421a5ab8bd7d6d9239a5'
  8. # TODO: improve coverage
  9. class UnitTestDDoS(Test.ID2TAttackTest):
  10. @mock.patch('ID2TLib.Utility.get_attacker_config', side_effect=Lib.get_attacker_config)
  11. def test_ddos_basic(self, mock_get_attacker_config):
  12. self.checksum_test([['DDoSAttack']],
  13. sha_basic_ddos)
  14. @mock.patch('ID2TLib.Utility.get_attacker_config', side_effect=Lib.get_attacker_config)
  15. def test_ddos_num_attackers(self, mock_get_attacker_config):
  16. self.checksum_test([['DDoSAttack', 'attackers.count=5']],
  17. sha_num_attackers_ddos)
  18. @mock.patch('ID2TLib.Utility.get_attacker_config', side_effect=Lib.get_attacker_config)
  19. @mock.patch('ID2TLib.Statistics.Statistics.get_mac_address', return_value=[])
  20. def test_ddos_dest_mac_length_zero(self, mock_dest_mac, mock_get_attacker_config):
  21. self.checksum_test([['DDoSAttack']], sha_dest_mac_length_zero_ddos)
  22. @mock.patch('ID2TLib.Utility.get_attacker_config', side_effect=Lib.get_attacker_config)
  23. @mock.patch('ID2TLib.Statistics.Statistics.get_most_used_mss', return_value=None)
  24. def test_ddos_mss_none(self, mock_mss, mock_get_attacker_config):
  25. self.checksum_test([['DDoSAttack']], sha_mss_none_ddos)