Test for AttackTechnique

This commit is contained in:
Shreya 2020-07-26 12:18:20 +05:30
parent a927da3bef
commit 92ab1ad2f2
2 changed files with 11 additions and 7 deletions

View File

@ -144,7 +144,7 @@ class AttackTechnique(object, metaclass=abc.ABCMeta):
@classmethod @classmethod
def _check_status(cls, status): def _check_status(cls, status):
if status == ScanStatus.UNSCANNED.value and cls._is_disabled_in_config(): if status == ScanStatus.UNSCANNED.value and not cls._is_enabled_in_config():
return ScanStatus.DISABLED.value return ScanStatus.DISABLED.value
return status return status

View File

@ -1,6 +1,9 @@
import copy
from unittest import TestCase from unittest import TestCase
from unittest.mock import patch
from common.utils.attack_utils import ScanStatus from common.utils.attack_utils import ScanStatus
from monkey_island.cc.services.attack.attack_config import AttackConfig
from .pba_technique import PostBreachTechnique from .pba_technique import PostBreachTechnique
@ -24,7 +27,7 @@ config =\
'necessary': False, 'necessary': False,
'title': '', 'title': '',
'type': 'bool', 'type': 'bool',
'value': False # this field denotes whether technique is enabled or disabled in config 'value': None # denotes whether technique is enabled/disabled in config (set below in param_list)
} }
} }
} }
@ -45,7 +48,7 @@ param_list = [
'status': ScanStatus.UNSCANNED.value, 'status': ScanStatus.UNSCANNED.value,
'title': 'Unscanned technique' 'title': 'Unscanned technique'
}, },
set_config(True), # configuration copy.deepcopy(set_config(True)), # configuration
ScanStatus.UNSCANNED.value # expected status ScanStatus.UNSCANNED.value # expected status
), ),
@ -57,7 +60,7 @@ param_list = [
'status': ScanStatus.SCANNED.value, 'status': ScanStatus.SCANNED.value,
'title': 'Scanned technique' 'title': 'Scanned technique'
}, },
set_config(True), # configuration copy.deepcopy(set_config(True)), # configuration
ScanStatus.SCANNED.value # expected status ScanStatus.SCANNED.value # expected status
), ),
@ -69,7 +72,7 @@ param_list = [
'status': ScanStatus.USED.value, 'status': ScanStatus.USED.value,
'title': 'Used technique' 'title': 'Used technique'
}, },
set_config(True), # configuration copy.deepcopy(set_config(True)), # configuration
ScanStatus.USED.value # expected status ScanStatus.USED.value # expected status
), ),
@ -81,7 +84,7 @@ param_list = [
'status': ScanStatus.UNSCANNED.value, 'status': ScanStatus.UNSCANNED.value,
'title': 'Disabled technique' 'title': 'Disabled technique'
}, },
set_config(False), # configuration copy.deepcopy(set_config(False)), # configuration
ScanStatus.DISABLED.value # expected status ScanStatus.DISABLED.value # expected status
) )
] ]
@ -91,4 +94,5 @@ class TestAttackTechnique(TestCase):
def test__check_status(self): def test__check_status(self):
for telem_data, config, expected_status in param_list: for telem_data, config, expected_status in param_list:
with self.subTest(msg=f"Checking if correct status is returned (status: {telem_data['message']})"): with self.subTest(msg=f"Checking if correct status is returned (status: {telem_data['message']})"):
self.assertEqual(T9999._check_status(telem_data['status']), expected_status) with patch.object(AttackConfig, 'get_config', return_value=config):
self.assertEqual(T9999._check_status(telem_data['status']), expected_status)