Adjusted unit tests to current code

pull/3/head
Thorsten Sick 3 years ago
parent 0ee814c2eb
commit 102077f147

@ -1,5 +1,5 @@
import unittest import unittest
from unittest.mock import patch from unittest.mock import patch, call
from app.calderacontrol import CalderaControl from app.calderacontrol import CalderaControl
from simplejson.errors import JSONDecodeError from simplejson.errors import JSONDecodeError
from app.exceptions import CalderaError from app.exceptions import CalderaError
@ -263,14 +263,23 @@ class TestExample(unittest.TestCase):
group = "test_group" group = "test_group"
advid = "test_id" advid = "test_id"
exp = {"index": "operations", exp1 = {"index": "sources",
"name": "source_test_name",
"rules": [],
"relationships": [],
"facts": []
}
exp2 = {"index": "sources",
"name": "source_name"
}
exp3 = {"index": "operations",
"name": name, "name": name,
"state": state, "state": state,
"autonomous": 1, "autonomous": 1,
'obfuscator': 'plain-text', 'obfuscator': 'plain-text',
'auto_close': '1', 'auto_close': '1',
'jitter': '4/8', 'jitter': '4/8',
'source': 'Alice Filters', 'source': 'source_test_name',
'visibility': '50', 'visibility': '50',
"group": group, "group": group,
"planner": "atomic", "planner": "atomic",
@ -278,29 +287,39 @@ class TestExample(unittest.TestCase):
} }
with patch.object(self.cc, "__contact_server__", return_value=None) as mock_method: with patch.object(self.cc, "__contact_server__", return_value=None) as mock_method:
self.cc.add_operation(name, advid, group, state) self.cc.add_operation(name, advid, group, state)
mock_method.assert_called_once_with(exp, method="put") # mock_method.assert_called_once_with(exp, method="put")
mock_method.assert_has_calls([call(exp1, method="put"), call(exp2), call(exp3, method="put")])
# add_operation defaults # add_operation defaults
def test_add_operation_defaults(self): def test_add_operation_defaults(self):
name = "test_name" name = "test_name"
advid = "test_id" advid = "test_id"
exp = {"index": "operations", exp1 = {"index": "sources",
"name": name, "name": "source_test_name",
"state": "running", # default "rules": [],
"autonomous": 1, "relationships": [],
'obfuscator': 'plain-text', "facts": []
'auto_close': '1',
'jitter': '4/8',
'source': 'Alice Filters',
'visibility': '50',
"group": "red", # default
"planner": "atomic",
"adversary_id": advid,
} }
exp2 = {"index": "sources",
"name": "source_name"
}
exp3 = {"index": "operations",
"name": name,
"state": "running", # default
"autonomous": 1,
'obfuscator': 'plain-text',
'auto_close': '1',
'jitter': '4/8',
'source': 'source_test_name',
'visibility': '50',
"group": "red", # default
"planner": "atomic",
"adversary_id": advid,
}
with patch.object(self.cc, "__contact_server__", return_value=None) as mock_method: with patch.object(self.cc, "__contact_server__", return_value=None) as mock_method:
self.cc.add_operation(name, advid) self.cc.add_operation(name, advid)
mock_method.assert_called_once_with(exp, method="put") mock_method.assert_has_calls([call(exp1, method="put"), call(exp2), call(exp3, method="put")])
# add_adversary # add_adversary
def test_add_adversary(self): def test_add_adversary(self):
@ -342,7 +361,8 @@ class TestExample(unittest.TestCase):
exp = {"paw": paw, exp = {"paw": paw,
"ability_id": ability_id, "ability_id": ability_id,
"obfuscator": obfuscator} "obfuscator": obfuscator,
"facts": []}
with patch.object(self.cc, "__contact_server__", return_value=None) as mock_method: with patch.object(self.cc, "__contact_server__", return_value=None) as mock_method:
self.cc.execute_ability(paw, ability_id, obfuscator) self.cc.execute_ability(paw, ability_id, obfuscator)
mock_method.assert_called_once_with(exp, rest_path="plugin/access/exploit_ex") mock_method.assert_called_once_with(exp, rest_path="plugin/access/exploit_ex")
@ -353,7 +373,8 @@ class TestExample(unittest.TestCase):
exp = {"paw": paw, exp = {"paw": paw,
"ability_id": ability_id, "ability_id": ability_id,
"obfuscator": "plain-text"} "obfuscator": "plain-text",
"facts": []}
with patch.object(self.cc, "__contact_server__", return_value=None) as mock_method: with patch.object(self.cc, "__contact_server__", return_value=None) as mock_method:
self.cc.execute_ability(paw, ability_id) self.cc.execute_ability(paw, ability_id)
mock_method.assert_called_once_with(exp, rest_path="plugin/access/exploit_ex") mock_method.assert_called_once_with(exp, rest_path="plugin/access/exploit_ex")

@ -532,8 +532,7 @@ class TestExperimentConfig(unittest.TestCase):
""" Getting kali config for a specific attack. Attack missing """ """ Getting kali config for a specific attack. Attack missing """
ex = ExperimentConfig("tests/data/basic.yaml") ex = ExperimentConfig("tests/data/basic.yaml")
with self.assertRaises(ConfigurationError): self.assertEqual(ex.kali_conf("BOOM"), {})
ex.kali_conf("BOOM")
def test_working_kali_config(self): def test_working_kali_config(self):
""" Getting kali config for a specific attack """ """ Getting kali config for a specific attack """

Loading…
Cancel
Save