Explorar el Código

first test working, 91% coverage

Jonathan Speth hace 6 años
padre
commit
40377a03ee
Se han modificado 3 ficheros con 18 adiciones y 14 borrados
  1. 1 1
      code/ID2TLib/Statistics.py
  2. 3 2
      code/Test/Lib.py
  3. 14 11
      code/Test/test_DDoS.py

+ 1 - 1
code/ID2TLib/Statistics.py

@@ -558,7 +558,7 @@ class Statistics:
             return None
 
     def get_rnd_win_size(self, pkts_num):
-        return self.statistics.process_db_query(
+        return self.process_db_query(
             "SELECT DISTINCT winSize FROM tcp_win ORDER BY RANDOM() LIMIT "+str(pkts_num)+";")
 
     def get_statistics_database(self):

+ 3 - 2
code/Test/Lib.py

@@ -76,8 +76,9 @@ def get_win_size(pkts_num):
         result.append(10)
     return result
 
-def get_attacker_config(ipAddress: str):
+
+def get_attacker_config(ip_source_list, ipAddress: str):
     next_port = randint(0, 2 ** 16 - 1)
     ttl = randint(1, 255)
 
-    return next_port,
+    return next_port, ttl

+ 14 - 11
code/Test/test_DDoS.py

@@ -1,30 +1,33 @@
 import unittest
 import unittest.mock as mock
-from random import randint
 
 from ID2TLib.Statistics import Statistics
 from Test.GenericTest import GenericTest
 from Test.Lib import get_win_size, get_attacker_config
 
 # FIXME: create new hashes
-sha_two_attackers = 'c0a494e8553ebd937941bdfb0529b699ca00b7150af92d1152cf1c8ddaebe426'
+sha_basic_ddos = 'f05ce7842014fd90098c06b97f1b6276d93beed3ce5906e2d4281096e383fe0a'
 
+"""
+Name                             Stmts   Miss  Cover   Missing
+--------------------------------------------------------------------------------------------
+Attack/DDoSAttack.py                124     11    91%   70, 81-84, 105-106, 120, 123, 141, 146, 187
+"""
 
-# seeds: for 5, 23 for 10, 27 for 16, 31 for 1
 class UnitTestDDoS(GenericTest):
 
     @mock.patch.object(Statistics, 'get_rnd_win_size', side_effect=get_win_size)
-    @mock.patch('Attack.DDoSAttack.get_attacker_config', side_effect=get_attacker_config)
+    @mock.patch('ID2TLib.Utility.get_attacker_config', side_effect=get_attacker_config)
     def test_two_attackers(self, mock_get_attacker_config, mock_get_rnd_win_size):
         self.generic_test([['DDoSAttack',
-                            'attack.duration=10',
-                            'inject.after-pkt=1',
-                            'ip.src=192.168.189.143,192.168.189.144',
-                            'ip.dst=192.168.189.1',
-                            'packets.per-second=10',
-                            'victim.buffer=1000'
+                            #'attack.duration=10',
+                            #'inject.after-pkt=1',
+                            #'ip.src=192.168.189.143,192.168.189.144',
+                            #'ip.dst=192.168.189.1',
+                            #'packets.per-second=10',
+                            #'victim.buffer=1000'
                             ]],
-                          sha_two_attackers)
+                          sha_basic_ddos)
 
 if __name__ == '__main__':
     unittest.main()