瀏覽代碼

Added two tests for BaseAttack.add_param_value()

Stefan Schmidt 6 年之前
父節點
當前提交
773b82d4f1
共有 1 個文件被更改,包括 15 次插入0 次删除
  1. 15 0
      code/Test/test_BaseAttack.py

+ 15 - 0
code/Test/test_BaseAttack.py

@@ -1,3 +1,4 @@
+import unittest.mock as mock
 import unittest
 
 import Attack.BaseAttack as BAtk
@@ -153,6 +154,20 @@ class TestBaseAttack(unittest.TestCase):
     def test_is_valid_ipaddress_invalid(self):
         self.assertFalse(BAtk.BaseAttack.is_valid_ip_address("192.168.1789.42"))
 
+    @mock.patch.multiple(BAtk.BaseAttack, __abstractmethods__=set())
+    def test_add_param_value_invalid_param_name(self):
+        base_attack = BAtk.BaseAttack("testname", "testdescription", "testtype")
+        with self.assertRaises(SystemExit):
+            base_attack.add_param_value("nonexistent_param", "testvalue")
+
+    @mock.patch.multiple(BAtk.BaseAttack, __abstractmethods__=set())
+    def test_add_param_value_missing_statistics(self):
+        base_attack = BAtk.BaseAttack("testname", "testdescription", "testtype")
+        with self.assertRaises(RuntimeError) as ex:
+            base_attack.add_param_value('inject.after-pkt', 1234)
+        self.assertEqual(str(ex.exception),
+                         'Error: Statistics-dependent attack parameter added without setting a statistics object first.')
+
     def test_ip_src_dst_equal_check_equal(self):
         with self.assertRaises(SystemExit):
             BAtk.BaseAttack.ip_src_dst_equal_check("192.168.178.42", "192.168.178.42")