Browse Source

add SalityBotnet tests

Jonathan Speth 6 years ago
parent
commit
c1ba3d746d
2 changed files with 32 additions and 1 deletions
  1. 2 1
      code/Attack/SalityBotnet.py
  2. 30 0
      code/Test/test_SalityBotnet.py

+ 2 - 1
code/Attack/SalityBotnet.py

@@ -4,6 +4,7 @@ from random import randint
 from scapy.utils import RawPcapReader
 from scapy.layers.inet import Ether
 
+from definitions import ROOT_DIR
 from Attack import BaseAttack
 from Attack.AttackParameters import Parameter as Param
 from Attack.AttackParameters import ParameterTypes
@@ -14,7 +15,7 @@ logging.getLogger("scapy.runtime").setLevel(logging.ERROR)
 
 
 class SalityBotnet(BaseAttack.BaseAttack):
-    template_attack_pcap_path = "resources/sality_botnet.pcap"
+    template_attack_pcap_path = ROOT_DIR + "/../resources/sality_botnet.pcap"
 
     def __init__(self):
         """

+ 30 - 0
code/Test/test_SalityBotnet.py

@@ -0,0 +1,30 @@
+import unittest
+import unittest.mock as mock
+
+from Test.GenericTest import GenericTest
+from Test.Lib import test_pcap_ips
+
+sha_botnet_basic = 'bbe75f917933a9f7727d99137920a70a5f720cabc773da9e24acfd6cba45a87a'
+sha_botnet_most_used_ip_in_list ='8583e2563d2756347449aec4b1c7cf7bfc7c0a96db4885627dcf0afc9e59feff'
+
+"""
+CURRENT COVERAGE
+Name                             Stmts   Miss  Cover   Missing (lines)
+---------------------------------------------------------------------------
+Attack/SalityBotnet.py           77      0    100%   
+"""
+
+
+class UnitTestSalityBotnet(GenericTest):
+
+    def test_botnet_basic(self):
+        self.generic_test([['SalityBotnet']], sha_botnet_basic)
+
+    @mock.patch('ID2TLib.Statistics.Statistics.get_most_used_ip_address')
+    def test_botnet_most_used_ips(self, mock_most_used_ip_address):
+        mock_most_used_ip_address.return_value = test_pcap_ips
+        self.generic_test([['SalityBotnet']], sha_botnet_most_used_ip_in_list)
+
+
+if __name__ == '__main__':
+    unittest.main()