From 6456564cae8594938c5ab04e486d132f9342b203 Mon Sep 17 00:00:00 2001 From: Shreya Date: Sat, 18 Jul 2020 19:10:34 +0530 Subject: [PATCH] Add test for AttackTechnique Issue with `_check_status` function since it tries to fetch from mongodb which doesn't exist in testing env --- .../attack_technique_test.py | 57 +++++++++---------- 1 file changed, 27 insertions(+), 30 deletions(-) diff --git a/monkey/monkey_island/cc/services/attack/technique_reports/attack_technique_test.py b/monkey/monkey_island/cc/services/attack/technique_reports/attack_technique_test.py index 94facd1b9..ca58f9fd5 100644 --- a/monkey/monkey_island/cc/services/attack/technique_reports/attack_technique_test.py +++ b/monkey/monkey_island/cc/services/attack/technique_reports/attack_technique_test.py @@ -1,7 +1,10 @@ +import json from unittest import TestCase from common.utils.attack_utils import ScanStatus +from monkey_island.cc.database import mongo +from . import AttackTechnique from .pba_technique import PostBreachTechnique @@ -13,27 +16,27 @@ class T9999(PostBreachTechnique): pba_names = ["PBA Name"] -# config =\ -# { -# 'category': { -# 'link': '', -# 'properties': { -# 'T9999': { -# 'description': '', -# 'link': '', -# 'necessary': False, -# 'title': '', -# 'type': 'bool', -# 'value': False # this field denotes whether technique is enabled or disabled in config -# } -# } -# } -# } +config =\ + { + 'category': { + 'link': '', + 'properties': { + 'T9999': { + 'description': '', + 'link': '', + 'necessary': False, + 'title': '', + 'type': 'bool', + 'value': False # this field denotes whether technique is enabled or disabled in config + } + } + } + } -# def set_config(value: bool): -# config['category']['properties']['T9999']['value'] = value -# return config +def set_config(value: bool): + config['category']['properties']['T9999']['value'] = value + return config param_list = [ @@ -45,8 +48,7 @@ param_list = [ 'status': 0, 'title': 'Unscanned technique' }, - # set_config(True), # configuration - True, # configuration + set_config(True), # configuration ScanStatus.UNSCANNED.value # expected status ), @@ -58,8 +60,7 @@ param_list = [ 'status': 1, 'title': 'Scanned technique' }, - # set_config(True), # configuration - True, # configuration + set_config(True), # configuration ScanStatus.SCANNED.value # expected status ), @@ -71,8 +72,7 @@ param_list = [ 'status': 2, 'title': 'Used technique' }, - # set_config(True), # configuration - True, # configuration + set_config(True), # configuration ScanStatus.USED.value # expected status ), @@ -84,8 +84,7 @@ param_list = [ 'status': 0, 'title': 'Disabled technique' }, - # set_config(False), # configuration - False, # configuration + set_config(False), # configuration ScanStatus.DISABLED.value # expected status ) ] @@ -95,6 +94,4 @@ class TestAttackTechnique(TestCase): def test__check_status(self): for telem_data, config, expected_status in param_list: 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) - self.assertEqual(T9999._check_status(telem_data['status'], config), - expected_status) + self.assertEqual(T9999._check_status(telem_data['status']), expected_status)