From d3de80feed658743893170e94d4563297c40436b Mon Sep 17 00:00:00 2001 From: Shreya Malviya Date: Fri, 16 Jul 2021 19:23:18 +0530 Subject: [PATCH 01/18] island: Add filters for default config as per mode --- monkey/monkey_island/cc/services/config.py | 17 +++++++++++++++++ .../monkey_island/cc/services/config_filters.py | 3 +++ 2 files changed, 20 insertions(+) create mode 100644 monkey/monkey_island/cc/services/config_filters.py diff --git a/monkey/monkey_island/cc/services/config.py b/monkey/monkey_island/cc/services/config.py index acb12d48a..b29ac56e7 100644 --- a/monkey/monkey_island/cc/services/config.py +++ b/monkey/monkey_island/cc/services/config.py @@ -2,13 +2,16 @@ import collections import copy import functools import logging +from typing import Dict from jsonschema import Draft4Validator, validators import monkey_island.cc.environment.environment_singleton as env_singleton +from monkey.monkey_island.cc.services.config_filters import FILTER_PER_MODE from monkey_island.cc.database import mongo from monkey_island.cc.server_utils.encryptor import get_encryptor from monkey_island.cc.services.config_schema.config_schema import SCHEMA +from monkey_island.cc.services.mode.island_mode_service import get_mode from monkey_island.cc.services.post_breach_files import PostBreachFilesService from monkey_island.cc.services.utils.network_utils import local_ip_addresses @@ -235,11 +238,25 @@ class ConfigService: def get_default_config(should_encrypt=False): ConfigService.init_default_config() config = copy.deepcopy(ConfigService.default_config) + mode = get_mode() + config = ConfigService._set_default_config_values_per_mode(mode, config) if should_encrypt: ConfigService.encrypt_config(config) logger.info("Default config was called") return config + @staticmethod + def _set_default_config_values_per_mode(mode: str, config: Dict) -> Dict: + if mode == "advanced": + return config + config_filter = FILTER_PER_MODE[mode] + config = ConfigService._apply_config_filter(config, config_filter) + + @staticmethod + def _apply_config_filter(config: Dict, config_filter: Dict): + config.update(config_filter) + return config + @staticmethod def init_config(): if ConfigService.get_config(should_decrypt=False) != {}: diff --git a/monkey/monkey_island/cc/services/config_filters.py b/monkey/monkey_island/cc/services/config_filters.py new file mode 100644 index 000000000..51db21b93 --- /dev/null +++ b/monkey/monkey_island/cc/services/config_filters.py @@ -0,0 +1,3 @@ +from monkey_island.cc.services.mode.mode_enum import IslandModeEnum + +FILTER_PER_MODE = {IslandModeEnum.RANSOMWARE.value: {"basic.monkey.post_breach.post_breach_actions": []}} From f1a3e1fc25e8f018074490cf884c7e87318c6145 Mon Sep 17 00:00:00 2001 From: Shreya Malviya Date: Mon, 19 Jul 2021 15:34:48 +0530 Subject: [PATCH 02/18] island: Separate `island_mode_service.py` to separate files for get and set mode services --- monkey/monkey_island/cc/resources/island_mode.py | 3 ++- ...land_mode_service.py => get_island_mode_service.py} | 7 ------- .../cc/services/mode/set_island_mode_service.py | 10 ++++++++++ 3 files changed, 12 insertions(+), 8 deletions(-) rename monkey/monkey_island/cc/services/mode/{island_mode_service.py => get_island_mode_service.py} (60%) create mode 100644 monkey/monkey_island/cc/services/mode/set_island_mode_service.py diff --git a/monkey/monkey_island/cc/resources/island_mode.py b/monkey/monkey_island/cc/resources/island_mode.py index 7698fca9d..ea2b8d946 100644 --- a/monkey/monkey_island/cc/resources/island_mode.py +++ b/monkey/monkey_island/cc/resources/island_mode.py @@ -5,7 +5,8 @@ import flask_restful from flask import make_response, request from monkey_island.cc.resources.auth.auth import jwt_required -from monkey_island.cc.services.mode.island_mode_service import ModeNotSetError, get_mode, set_mode +from monkey_island.cc.services.mode.get_island_mode_service import ModeNotSetError, get_mode +from monkey_island.cc.services.mode.set_island_mode_service import set_mode from monkey_island.cc.services.mode.mode_enum import IslandModeEnum logger = logging.getLogger(__name__) diff --git a/monkey/monkey_island/cc/services/mode/island_mode_service.py b/monkey/monkey_island/cc/services/mode/get_island_mode_service.py similarity index 60% rename from monkey/monkey_island/cc/services/mode/island_mode_service.py rename to monkey/monkey_island/cc/services/mode/get_island_mode_service.py index b745ebef1..1f27ad3b1 100644 --- a/monkey/monkey_island/cc/services/mode/island_mode_service.py +++ b/monkey/monkey_island/cc/services/mode/get_island_mode_service.py @@ -1,11 +1,4 @@ from monkey_island.cc.models.island_mode_model import IslandMode -from monkey_island.cc.services.mode.mode_enum import IslandModeEnum - - -def set_mode(mode: IslandModeEnum): - island_mode_model = IslandMode() - island_mode_model.mode = mode.value - island_mode_model.save() def get_mode() -> str: diff --git a/monkey/monkey_island/cc/services/mode/set_island_mode_service.py b/monkey/monkey_island/cc/services/mode/set_island_mode_service.py new file mode 100644 index 000000000..a1190e42a --- /dev/null +++ b/monkey/monkey_island/cc/services/mode/set_island_mode_service.py @@ -0,0 +1,10 @@ +from monkey_island.cc.models.island_mode_model import IslandMode +from monkey_island.cc.services.mode.mode_enum import IslandModeEnum +from monkey_island.cc.services.config import ConfigService + + +def set_mode(mode: IslandModeEnum): + island_mode_model = IslandMode() + island_mode_model.mode = mode.value + island_mode_model.save() + ConfigService.update_config_on_mode_set(mode.value) From 743619b81bb98b53586927aa422e6004f4d8051d Mon Sep 17 00:00:00 2001 From: Shreya Malviya Date: Mon, 19 Jul 2021 15:37:53 +0530 Subject: [PATCH 03/18] island: Apply config filter as per mode --- monkey/monkey_island/cc/services/config.py | 34 ++++++++++++++----- .../cc/services/config_filters.py | 2 +- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/monkey/monkey_island/cc/services/config.py b/monkey/monkey_island/cc/services/config.py index b29ac56e7..f70e8b611 100644 --- a/monkey/monkey_island/cc/services/config.py +++ b/monkey/monkey_island/cc/services/config.py @@ -1,17 +1,18 @@ import collections import copy +import dpath.util import functools import logging -from typing import Dict +from typing import Dict, Optional from jsonschema import Draft4Validator, validators import monkey_island.cc.environment.environment_singleton as env_singleton -from monkey.monkey_island.cc.services.config_filters import FILTER_PER_MODE +from monkey_island.cc.services.config_filters import FILTER_PER_MODE from monkey_island.cc.database import mongo from monkey_island.cc.server_utils.encryptor import get_encryptor from monkey_island.cc.services.config_schema.config_schema import SCHEMA -from monkey_island.cc.services.mode.island_mode_service import get_mode +from monkey_island.cc.services.mode.get_island_mode_service import ModeNotSetError, get_mode from monkey_island.cc.services.post_breach_files import PostBreachFilesService from monkey_island.cc.services.utils.network_utils import local_ip_addresses @@ -238,23 +239,34 @@ class ConfigService: def get_default_config(should_encrypt=False): ConfigService.init_default_config() config = copy.deepcopy(ConfigService.default_config) - mode = get_mode() - config = ConfigService._set_default_config_values_per_mode(mode, config) + if should_encrypt: ConfigService.encrypt_config(config) + logger.info("Default config was called") + return config + @staticmethod + def update_config_on_mode_set(mode: str) -> None: + config = ConfigService.get_config() + ConfigService.update_config_per_mode(mode, config, True) + + @staticmethod + def update_config_per_mode(mode: str, config: Dict, should_encrypt: bool) -> None: + config = ConfigService._set_default_config_values_per_mode(mode, config) + ConfigService.update_config(config_json=config, should_encrypt=True) + @staticmethod def _set_default_config_values_per_mode(mode: str, config: Dict) -> Dict: - if mode == "advanced": - return config config_filter = FILTER_PER_MODE[mode] config = ConfigService._apply_config_filter(config, config_filter) + return config @staticmethod def _apply_config_filter(config: Dict, config_filter: Dict): - config.update(config_filter) + for path, value in config_filter.items(): + dpath.util.set(config, path, value, ".") return config @staticmethod @@ -268,7 +280,11 @@ class ConfigService: PostBreachFilesService.remove_PBA_files() config = ConfigService.get_default_config(True) ConfigService.set_server_ips_in_config(config) - ConfigService.update_config(config, should_encrypt=False) + try: + mode = get_mode() + ConfigService.update_config_per_mode(mode, config, should_encrypt=False) + except ModeNotSetError: + ConfigService.update_config(config, should_encrypt=False) logger.info("Monkey config reset was called") @staticmethod diff --git a/monkey/monkey_island/cc/services/config_filters.py b/monkey/monkey_island/cc/services/config_filters.py index 51db21b93..2adda532a 100644 --- a/monkey/monkey_island/cc/services/config_filters.py +++ b/monkey/monkey_island/cc/services/config_filters.py @@ -1,3 +1,3 @@ from monkey_island.cc.services.mode.mode_enum import IslandModeEnum -FILTER_PER_MODE = {IslandModeEnum.RANSOMWARE.value: {"basic.monkey.post_breach.post_breach_actions": []}} +FILTER_PER_MODE = {IslandModeEnum.RANSOMWARE.value: {"monkey.post_breach.post_breach_actions": []}} From 28461bd607cc94f50990f106dc2bf3c5db45dc99 Mon Sep 17 00:00:00 2001 From: Shreya Date: Mon, 19 Jul 2021 17:20:31 +0530 Subject: [PATCH 04/18] tests: Monkeypath `ConfigService.update_config_on_mode_set` for POST test in `test_island_mode.py` --- .../monkey_island/cc/resources/test_island_mode.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/monkey/tests/unit_tests/monkey_island/cc/resources/test_island_mode.py b/monkey/tests/unit_tests/monkey_island/cc/resources/test_island_mode.py index 823f9dad5..dc1899e8c 100644 --- a/monkey/tests/unit_tests/monkey_island/cc/resources/test_island_mode.py +++ b/monkey/tests/unit_tests/monkey_island/cc/resources/test_island_mode.py @@ -13,7 +13,11 @@ def uses_database(): @pytest.mark.parametrize("mode", ["ransomware", "advanced"]) -def test_island_mode_post(flask_client, mode): +def test_island_mode_post(flask_client, mode, monkeypatch): + monkeypatch.setattr( + "monkey_island.cc.services.mode.set_island_mode_service.ConfigService.update_config_on_mode_set", # noqa: E501 + lambda _: None, + ) resp = flask_client.post( "/api/island-mode", data=json.dumps({"mode": mode}), follow_redirects=True ) From 5603773083263e2f061414d5a4469da4b597a830 Mon Sep 17 00:00:00 2001 From: Shreya Date: Mon, 19 Jul 2021 17:22:54 +0530 Subject: [PATCH 05/18] island: Remove unused import and sort imports --- monkey/monkey_island/cc/resources/island_mode.py | 2 +- monkey/monkey_island/cc/services/config.py | 6 +++--- .../cc/services/mode/set_island_mode_service.py | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/monkey/monkey_island/cc/resources/island_mode.py b/monkey/monkey_island/cc/resources/island_mode.py index ea2b8d946..a7d0a81de 100644 --- a/monkey/monkey_island/cc/resources/island_mode.py +++ b/monkey/monkey_island/cc/resources/island_mode.py @@ -6,8 +6,8 @@ from flask import make_response, request from monkey_island.cc.resources.auth.auth import jwt_required from monkey_island.cc.services.mode.get_island_mode_service import ModeNotSetError, get_mode -from monkey_island.cc.services.mode.set_island_mode_service import set_mode from monkey_island.cc.services.mode.mode_enum import IslandModeEnum +from monkey_island.cc.services.mode.set_island_mode_service import set_mode logger = logging.getLogger(__name__) diff --git a/monkey/monkey_island/cc/services/config.py b/monkey/monkey_island/cc/services/config.py index f70e8b611..82ab04864 100644 --- a/monkey/monkey_island/cc/services/config.py +++ b/monkey/monkey_island/cc/services/config.py @@ -1,16 +1,16 @@ import collections import copy -import dpath.util import functools import logging -from typing import Dict, Optional +from typing import Dict +import dpath.util from jsonschema import Draft4Validator, validators import monkey_island.cc.environment.environment_singleton as env_singleton -from monkey_island.cc.services.config_filters import FILTER_PER_MODE from monkey_island.cc.database import mongo from monkey_island.cc.server_utils.encryptor import get_encryptor +from monkey_island.cc.services.config_filters import FILTER_PER_MODE from monkey_island.cc.services.config_schema.config_schema import SCHEMA from monkey_island.cc.services.mode.get_island_mode_service import ModeNotSetError, get_mode from monkey_island.cc.services.post_breach_files import PostBreachFilesService diff --git a/monkey/monkey_island/cc/services/mode/set_island_mode_service.py b/monkey/monkey_island/cc/services/mode/set_island_mode_service.py index a1190e42a..b11aab8ca 100644 --- a/monkey/monkey_island/cc/services/mode/set_island_mode_service.py +++ b/monkey/monkey_island/cc/services/mode/set_island_mode_service.py @@ -1,6 +1,6 @@ from monkey_island.cc.models.island_mode_model import IslandMode -from monkey_island.cc.services.mode.mode_enum import IslandModeEnum from monkey_island.cc.services.config import ConfigService +from monkey_island.cc.services.mode.mode_enum import IslandModeEnum def set_mode(mode: IslandModeEnum): From 0681782505aaa8d5f0997dd3c1205835407ed010 Mon Sep 17 00:00:00 2001 From: Shreya Date: Tue, 20 Jul 2021 13:16:06 +0530 Subject: [PATCH 06/18] island: Pass `mode` as an enum instead of enum value when updating config, and update typehints --- monkey/monkey_island/cc/services/config.py | 9 +++++---- .../cc/services/mode/set_island_mode_service.py | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/monkey/monkey_island/cc/services/config.py b/monkey/monkey_island/cc/services/config.py index 82ab04864..e9c3598a3 100644 --- a/monkey/monkey_island/cc/services/config.py +++ b/monkey/monkey_island/cc/services/config.py @@ -13,6 +13,7 @@ from monkey_island.cc.server_utils.encryptor import get_encryptor from monkey_island.cc.services.config_filters import FILTER_PER_MODE from monkey_island.cc.services.config_schema.config_schema import SCHEMA from monkey_island.cc.services.mode.get_island_mode_service import ModeNotSetError, get_mode +from monkey_island.cc.services.mode.mode_enum import IslandModeEnum from monkey_island.cc.services.post_breach_files import PostBreachFilesService from monkey_island.cc.services.utils.network_utils import local_ip_addresses @@ -248,18 +249,18 @@ class ConfigService: return config @staticmethod - def update_config_on_mode_set(mode: str) -> None: + def update_config_on_mode_set(mode: IslandModeEnum) -> None: config = ConfigService.get_config() ConfigService.update_config_per_mode(mode, config, True) @staticmethod - def update_config_per_mode(mode: str, config: Dict, should_encrypt: bool) -> None: + def update_config_per_mode(mode: IslandModeEnum, config: Dict, should_encrypt: bool) -> None: config = ConfigService._set_default_config_values_per_mode(mode, config) ConfigService.update_config(config_json=config, should_encrypt=True) @staticmethod - def _set_default_config_values_per_mode(mode: str, config: Dict) -> Dict: - config_filter = FILTER_PER_MODE[mode] + def _set_default_config_values_per_mode(mode: IslandModeEnum, config: Dict) -> Dict: + config_filter = FILTER_PER_MODE[mode.value] config = ConfigService._apply_config_filter(config, config_filter) return config diff --git a/monkey/monkey_island/cc/services/mode/set_island_mode_service.py b/monkey/monkey_island/cc/services/mode/set_island_mode_service.py index b11aab8ca..dd70070d1 100644 --- a/monkey/monkey_island/cc/services/mode/set_island_mode_service.py +++ b/monkey/monkey_island/cc/services/mode/set_island_mode_service.py @@ -7,4 +7,4 @@ def set_mode(mode: IslandModeEnum): island_mode_model = IslandMode() island_mode_model.mode = mode.value island_mode_model.save() - ConfigService.update_config_on_mode_set(mode.value) + ConfigService.update_config_on_mode_set(mode) From fab77381744a183584deded75f27795ee9a7cdb3 Mon Sep 17 00:00:00 2001 From: Shreya Date: Tue, 20 Jul 2021 13:17:30 +0530 Subject: [PATCH 07/18] island: Add config filter for advanced mode --- monkey/monkey_island/cc/services/config_filters.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/monkey/monkey_island/cc/services/config_filters.py b/monkey/monkey_island/cc/services/config_filters.py index 2adda532a..f8afd114d 100644 --- a/monkey/monkey_island/cc/services/config_filters.py +++ b/monkey/monkey_island/cc/services/config_filters.py @@ -1,3 +1,6 @@ from monkey_island.cc.services.mode.mode_enum import IslandModeEnum -FILTER_PER_MODE = {IslandModeEnum.RANSOMWARE.value: {"monkey.post_breach.post_breach_actions": []}} +FILTER_PER_MODE = { + IslandModeEnum.ADVANCED.value: {}, + IslandModeEnum.RANSOMWARE.value: {"monkey.post_breach.post_breach_actions": []}, +} From 9c48c115be74f8301563c43b9734ac6fae844098 Mon Sep 17 00:00:00 2001 From: Shreya Date: Tue, 20 Jul 2021 14:01:20 +0530 Subject: [PATCH 08/18] island: Return and log if config update was not successful on mode set --- monkey/monkey_island/cc/services/config.py | 8 ++++---- .../cc/services/mode/set_island_mode_service.py | 9 ++++++++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/monkey/monkey_island/cc/services/config.py b/monkey/monkey_island/cc/services/config.py index e9c3598a3..416d85e5d 100644 --- a/monkey/monkey_island/cc/services/config.py +++ b/monkey/monkey_island/cc/services/config.py @@ -249,14 +249,14 @@ class ConfigService: return config @staticmethod - def update_config_on_mode_set(mode: IslandModeEnum) -> None: + def update_config_on_mode_set(mode: IslandModeEnum) -> bool: config = ConfigService.get_config() - ConfigService.update_config_per_mode(mode, config, True) + return ConfigService.update_config_per_mode(mode, config, True) @staticmethod - def update_config_per_mode(mode: IslandModeEnum, config: Dict, should_encrypt: bool) -> None: + def update_config_per_mode(mode: IslandModeEnum, config: Dict, should_encrypt: bool) -> bool: config = ConfigService._set_default_config_values_per_mode(mode, config) - ConfigService.update_config(config_json=config, should_encrypt=True) + return ConfigService.update_config(config_json=config, should_encrypt=True) @staticmethod def _set_default_config_values_per_mode(mode: IslandModeEnum, config: Dict) -> Dict: diff --git a/monkey/monkey_island/cc/services/mode/set_island_mode_service.py b/monkey/monkey_island/cc/services/mode/set_island_mode_service.py index dd70070d1..2e9e71691 100644 --- a/monkey/monkey_island/cc/services/mode/set_island_mode_service.py +++ b/monkey/monkey_island/cc/services/mode/set_island_mode_service.py @@ -1,10 +1,17 @@ +import logging + from monkey_island.cc.models.island_mode_model import IslandMode from monkey_island.cc.services.config import ConfigService from monkey_island.cc.services.mode.mode_enum import IslandModeEnum +LOG = logging.getLogger(__name__) + def set_mode(mode: IslandModeEnum): island_mode_model = IslandMode() island_mode_model.mode = mode.value island_mode_model.save() - ConfigService.update_config_on_mode_set(mode) + if not ConfigService.update_config_on_mode_set(mode): + LOG.error( + "Could not apply configuration changes per mode. Using default advanced configuration." + ) From 5159a577e4576efc62b0469be1a94f2323eac220 Mon Sep 17 00:00:00 2001 From: Shreya Date: Tue, 20 Jul 2021 14:15:27 +0530 Subject: [PATCH 09/18] tests: Add tests for config manipulator per mode --- .../monkey_island/cc/services/test_config.py | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/monkey/tests/unit_tests/monkey_island/cc/services/test_config.py b/monkey/tests/unit_tests/monkey_island/cc/services/test_config.py index cc0e94ceb..26addb732 100644 --- a/monkey/tests/unit_tests/monkey_island/cc/services/test_config.py +++ b/monkey/tests/unit_tests/monkey_island/cc/services/test_config.py @@ -2,6 +2,7 @@ import pytest from monkey_island.cc.environment import Environment from monkey_island.cc.services.config import ConfigService +from monkey_island.cc.services.mode.mode_enum import IslandModeEnum IPS = ["0.0.0.0", "9.9.9.9"] PORT = 9999 @@ -41,3 +42,27 @@ def test_set_server_ips_in_config_current_server(config): ConfigService.set_server_ips_in_config(config) expected_config_current_server = f"{IPS[0]}:{PORT}" assert config["internal"]["island_server"]["current_server"] == expected_config_current_server + + +def test_update_config_on_mode_set_advanced(config, monkeypatch): + monkeypatch.setattr("monkey_island.cc.services.config.ConfigService.get_config", lambda: config) + monkeypatch.setattr( + "monkey_island.cc.services.config.ConfigService.update_config", + lambda config_json, should_encrypt: config_json, + ) + + mode = IslandModeEnum.ADVANCED + manipulated_config = ConfigService.update_config_on_mode_set(mode) + assert manipulated_config == config + + +def test_update_config_on_mode_set_ransomware(config, monkeypatch): + monkeypatch.setattr("monkey_island.cc.services.config.ConfigService.get_config", lambda: config) + monkeypatch.setattr( + "monkey_island.cc.services.config.ConfigService.update_config", + lambda config_json, should_encrypt: config_json, + ) + + mode = IslandModeEnum.RANSOMWARE + manipulated_config = ConfigService.update_config_on_mode_set(mode) + assert manipulated_config["monkey"]["post_breach"]["post_breach_actions"] == [] From 9b2ec5c31655a166259f5c0ac070c48a2d79bdd9 Mon Sep 17 00:00:00 2001 From: Shreya Date: Tue, 20 Jul 2021 15:43:03 +0530 Subject: [PATCH 10/18] island: Move config manipulator functions from `config.py` to `config_manipulator.py` --- monkey/monkey_island/cc/services/config.py | 29 ++----------------- .../cc/services/config_manipulator.py | 29 +++++++++++++++++++ .../services/mode/set_island_mode_service.py | 4 +-- 3 files changed, 33 insertions(+), 29 deletions(-) create mode 100644 monkey/monkey_island/cc/services/config_manipulator.py diff --git a/monkey/monkey_island/cc/services/config.py b/monkey/monkey_island/cc/services/config.py index 416d85e5d..2dfcd175b 100644 --- a/monkey/monkey_island/cc/services/config.py +++ b/monkey/monkey_island/cc/services/config.py @@ -2,18 +2,15 @@ import collections import copy import functools import logging -from typing import Dict -import dpath.util from jsonschema import Draft4Validator, validators import monkey_island.cc.environment.environment_singleton as env_singleton from monkey_island.cc.database import mongo from monkey_island.cc.server_utils.encryptor import get_encryptor -from monkey_island.cc.services.config_filters import FILTER_PER_MODE +from monkey_island.cc.services.config_manipulator import update_config_per_mode from monkey_island.cc.services.config_schema.config_schema import SCHEMA from monkey_island.cc.services.mode.get_island_mode_service import ModeNotSetError, get_mode -from monkey_island.cc.services.mode.mode_enum import IslandModeEnum from monkey_island.cc.services.post_breach_files import PostBreachFilesService from monkey_island.cc.services.utils.network_utils import local_ip_addresses @@ -248,28 +245,6 @@ class ConfigService: return config - @staticmethod - def update_config_on_mode_set(mode: IslandModeEnum) -> bool: - config = ConfigService.get_config() - return ConfigService.update_config_per_mode(mode, config, True) - - @staticmethod - def update_config_per_mode(mode: IslandModeEnum, config: Dict, should_encrypt: bool) -> bool: - config = ConfigService._set_default_config_values_per_mode(mode, config) - return ConfigService.update_config(config_json=config, should_encrypt=True) - - @staticmethod - def _set_default_config_values_per_mode(mode: IslandModeEnum, config: Dict) -> Dict: - config_filter = FILTER_PER_MODE[mode.value] - config = ConfigService._apply_config_filter(config, config_filter) - return config - - @staticmethod - def _apply_config_filter(config: Dict, config_filter: Dict): - for path, value in config_filter.items(): - dpath.util.set(config, path, value, ".") - return config - @staticmethod def init_config(): if ConfigService.get_config(should_decrypt=False) != {}: @@ -283,7 +258,7 @@ class ConfigService: ConfigService.set_server_ips_in_config(config) try: mode = get_mode() - ConfigService.update_config_per_mode(mode, config, should_encrypt=False) + update_config_per_mode(mode, config, should_encrypt=False) except ModeNotSetError: ConfigService.update_config(config, should_encrypt=False) logger.info("Monkey config reset was called") diff --git a/monkey/monkey_island/cc/services/config_manipulator.py b/monkey/monkey_island/cc/services/config_manipulator.py new file mode 100644 index 000000000..8b92e1767 --- /dev/null +++ b/monkey/monkey_island/cc/services/config_manipulator.py @@ -0,0 +1,29 @@ +from typing import Dict + +import dpath.util + +from monkey_island.cc.services.config import ConfigService +from monkey_island.cc.services.config_filters import FILTER_PER_MODE +from monkey_island.cc.services.mode.mode_enum import IslandModeEnum + + +def update_config_on_mode_set(mode: IslandModeEnum) -> bool: + config = ConfigService.get_config() + return update_config_per_mode(mode, config, True) + + +def update_config_per_mode(mode: IslandModeEnum, config: Dict, should_encrypt: bool) -> bool: + config = _set_default_config_values_per_mode(mode, config) + return ConfigService.update_config(config_json=config, should_encrypt=True) + + +def _set_default_config_values_per_mode(mode: IslandModeEnum, config: Dict) -> Dict: + config_filter = FILTER_PER_MODE[mode.value] + config = _apply_config_filter(config, config_filter) + return config + + +def _apply_config_filter(config: Dict, config_filter: Dict): + for path, value in config_filter.items(): + dpath.util.set(config, path, value, ".") + return config diff --git a/monkey/monkey_island/cc/services/mode/set_island_mode_service.py b/monkey/monkey_island/cc/services/mode/set_island_mode_service.py index 2e9e71691..ef6f5e5b4 100644 --- a/monkey/monkey_island/cc/services/mode/set_island_mode_service.py +++ b/monkey/monkey_island/cc/services/mode/set_island_mode_service.py @@ -1,7 +1,7 @@ import logging from monkey_island.cc.models.island_mode_model import IslandMode -from monkey_island.cc.services.config import ConfigService +from monkey_island.cc.services.config_manipulator import update_config_on_mode_set from monkey_island.cc.services.mode.mode_enum import IslandModeEnum LOG = logging.getLogger(__name__) @@ -11,7 +11,7 @@ def set_mode(mode: IslandModeEnum): island_mode_model = IslandMode() island_mode_model.mode = mode.value island_mode_model.save() - if not ConfigService.update_config_on_mode_set(mode): + if not update_config_on_mode_set(mode): LOG.error( "Could not apply configuration changes per mode. Using default advanced configuration." ) From eabbca4f32e5bc7464b0ea2189c6ccfcc4a4d26c Mon Sep 17 00:00:00 2001 From: Shreya Date: Tue, 20 Jul 2021 16:10:22 +0530 Subject: [PATCH 11/18] island: Fix circular import error in `config_manipulator.py` --- monkey/monkey_island/cc/services/config_manipulator.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/monkey/monkey_island/cc/services/config_manipulator.py b/monkey/monkey_island/cc/services/config_manipulator.py index 8b92e1767..21ca693c1 100644 --- a/monkey/monkey_island/cc/services/config_manipulator.py +++ b/monkey/monkey_island/cc/services/config_manipulator.py @@ -2,19 +2,19 @@ from typing import Dict import dpath.util -from monkey_island.cc.services.config import ConfigService +import monkey_island.cc.services.config as config_service from monkey_island.cc.services.config_filters import FILTER_PER_MODE from monkey_island.cc.services.mode.mode_enum import IslandModeEnum def update_config_on_mode_set(mode: IslandModeEnum) -> bool: - config = ConfigService.get_config() + config = config_service.ConfigService.get_config() return update_config_per_mode(mode, config, True) def update_config_per_mode(mode: IslandModeEnum, config: Dict, should_encrypt: bool) -> bool: config = _set_default_config_values_per_mode(mode, config) - return ConfigService.update_config(config_json=config, should_encrypt=True) + return config_service.ConfigService.update_config(config_json=config, should_encrypt=True) def _set_default_config_values_per_mode(mode: IslandModeEnum, config: Dict) -> Dict: From 42b558674e0cfcc04bd5cd3d775fad113624e7d9 Mon Sep 17 00:00:00 2001 From: Shreya Date: Tue, 20 Jul 2021 16:11:35 +0530 Subject: [PATCH 12/18] tests: Fix/add unit tests based on addition of `config_manipulator.py` --- .../cc/resources/test_island_mode.py | 2 +- .../monkey_island/cc/services/conftest.py | 22 ++++++++++ .../monkey_island/cc/services/test_config.py | 44 ++----------------- .../cc/services/test_config_manipulator.py | 26 +++++++++++ 4 files changed, 52 insertions(+), 42 deletions(-) create mode 100644 monkey/tests/unit_tests/monkey_island/cc/services/conftest.py create mode 100644 monkey/tests/unit_tests/monkey_island/cc/services/test_config_manipulator.py diff --git a/monkey/tests/unit_tests/monkey_island/cc/resources/test_island_mode.py b/monkey/tests/unit_tests/monkey_island/cc/resources/test_island_mode.py index dc1899e8c..435680bfe 100644 --- a/monkey/tests/unit_tests/monkey_island/cc/resources/test_island_mode.py +++ b/monkey/tests/unit_tests/monkey_island/cc/resources/test_island_mode.py @@ -15,7 +15,7 @@ def uses_database(): @pytest.mark.parametrize("mode", ["ransomware", "advanced"]) def test_island_mode_post(flask_client, mode, monkeypatch): monkeypatch.setattr( - "monkey_island.cc.services.mode.set_island_mode_service.ConfigService.update_config_on_mode_set", # noqa: E501 + "monkey_island.cc.services.mode.set_island_mode_service.update_config_on_mode_set", lambda _: None, ) resp = flask_client.post( diff --git a/monkey/tests/unit_tests/monkey_island/cc/services/conftest.py b/monkey/tests/unit_tests/monkey_island/cc/services/conftest.py new file mode 100644 index 000000000..7b56c0c13 --- /dev/null +++ b/monkey/tests/unit_tests/monkey_island/cc/services/conftest.py @@ -0,0 +1,22 @@ +import pytest + +from monkey_island.cc.environment import Environment +from monkey_island.cc.services.config import ConfigService + + +@pytest.fixture +def IPS(): + return ["0.0.0.0", "9.9.9.9"] + + +@pytest.fixture +def PORT(): + return 9999 + + +@pytest.fixture +def config(monkeypatch, IPS, PORT): + monkeypatch.setattr("monkey_island.cc.services.config.local_ip_addresses", lambda: IPS) + monkeypatch.setattr(Environment, "_ISLAND_PORT", PORT) + config = ConfigService.get_default_config(True) + return config diff --git a/monkey/tests/unit_tests/monkey_island/cc/services/test_config.py b/monkey/tests/unit_tests/monkey_island/cc/services/test_config.py index 26addb732..799fc40e1 100644 --- a/monkey/tests/unit_tests/monkey_island/cc/services/test_config.py +++ b/monkey/tests/unit_tests/monkey_island/cc/services/test_config.py @@ -1,68 +1,30 @@ import pytest -from monkey_island.cc.environment import Environment from monkey_island.cc.services.config import ConfigService -from monkey_island.cc.services.mode.mode_enum import IslandModeEnum - -IPS = ["0.0.0.0", "9.9.9.9"] -PORT = 9999 - # If tests fail because config path is changed, sync with # monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/RunOptions.js -@pytest.fixture -def config(monkeypatch): - monkeypatch.setattr("monkey_island.cc.services.config.local_ip_addresses", lambda: IPS) - monkeypatch.setattr(Environment, "_ISLAND_PORT", PORT) - config = ConfigService.get_default_config(True) - return config - - class MockClass: pass @pytest.fixture(scope="function", autouse=True) -def mock_port_in_env_singleton(monkeypatch): +def mock_port_in_env_singleton(monkeypatch, PORT): mock_singleton = MockClass() mock_singleton.env = MockClass() mock_singleton.env.get_island_port = lambda: PORT monkeypatch.setattr("monkey_island.cc.services.config.env_singleton", mock_singleton) -def test_set_server_ips_in_config_command_servers(config): +def test_set_server_ips_in_config_command_servers(config, IPS, PORT): ConfigService.set_server_ips_in_config(config) expected_config_command_servers = [f"{ip}:{PORT}" for ip in IPS] assert config["internal"]["island_server"]["command_servers"] == expected_config_command_servers -def test_set_server_ips_in_config_current_server(config): +def test_set_server_ips_in_config_current_server(config, IPS, PORT): ConfigService.set_server_ips_in_config(config) expected_config_current_server = f"{IPS[0]}:{PORT}" assert config["internal"]["island_server"]["current_server"] == expected_config_current_server - - -def test_update_config_on_mode_set_advanced(config, monkeypatch): - monkeypatch.setattr("monkey_island.cc.services.config.ConfigService.get_config", lambda: config) - monkeypatch.setattr( - "monkey_island.cc.services.config.ConfigService.update_config", - lambda config_json, should_encrypt: config_json, - ) - - mode = IslandModeEnum.ADVANCED - manipulated_config = ConfigService.update_config_on_mode_set(mode) - assert manipulated_config == config - - -def test_update_config_on_mode_set_ransomware(config, monkeypatch): - monkeypatch.setattr("monkey_island.cc.services.config.ConfigService.get_config", lambda: config) - monkeypatch.setattr( - "monkey_island.cc.services.config.ConfigService.update_config", - lambda config_json, should_encrypt: config_json, - ) - - mode = IslandModeEnum.RANSOMWARE - manipulated_config = ConfigService.update_config_on_mode_set(mode) - assert manipulated_config["monkey"]["post_breach"]["post_breach_actions"] == [] diff --git a/monkey/tests/unit_tests/monkey_island/cc/services/test_config_manipulator.py b/monkey/tests/unit_tests/monkey_island/cc/services/test_config_manipulator.py new file mode 100644 index 000000000..12cd44c10 --- /dev/null +++ b/monkey/tests/unit_tests/monkey_island/cc/services/test_config_manipulator.py @@ -0,0 +1,26 @@ +from monkey_island.cc.services.config_manipulator import update_config_on_mode_set +from monkey_island.cc.services.mode.mode_enum import IslandModeEnum + + +def test_update_config_on_mode_set_advanced(config, monkeypatch): + monkeypatch.setattr("monkey_island.cc.services.config.ConfigService.get_config", lambda: config) + monkeypatch.setattr( + "monkey_island.cc.services.config.ConfigService.update_config", + lambda config_json, should_encrypt: config_json, + ) + + mode = IslandModeEnum.ADVANCED + manipulated_config = update_config_on_mode_set(mode) + assert manipulated_config == config + + +def test_update_config_on_mode_set_ransomware(config, monkeypatch): + monkeypatch.setattr("monkey_island.cc.services.config.ConfigService.get_config", lambda: config) + monkeypatch.setattr( + "monkey_island.cc.services.config.ConfigService.update_config", + lambda config_json, should_encrypt: config_json, + ) + + mode = IslandModeEnum.RANSOMWARE + manipulated_config = update_config_on_mode_set(mode) + assert manipulated_config["monkey"]["post_breach"]["post_breach_actions"] == [] From af86cb088f1fbd47068bbf30ad13a55a7dcb3692 Mon Sep 17 00:00:00 2001 From: Shreya Date: Tue, 20 Jul 2021 16:26:32 +0530 Subject: [PATCH 13/18] island: Fix stuff in `config_manipulator.py` after testing --- .../monkey_island/cc/services/config_manipulator.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/monkey/monkey_island/cc/services/config_manipulator.py b/monkey/monkey_island/cc/services/config_manipulator.py index 21ca693c1..c45ea6f00 100644 --- a/monkey/monkey_island/cc/services/config_manipulator.py +++ b/monkey/monkey_island/cc/services/config_manipulator.py @@ -9,16 +9,18 @@ from monkey_island.cc.services.mode.mode_enum import IslandModeEnum def update_config_on_mode_set(mode: IslandModeEnum) -> bool: config = config_service.ConfigService.get_config() - return update_config_per_mode(mode, config, True) + return update_config_per_mode(mode.value, config, True) -def update_config_per_mode(mode: IslandModeEnum, config: Dict, should_encrypt: bool) -> bool: +def update_config_per_mode(mode: str, config: Dict, should_encrypt: bool) -> bool: config = _set_default_config_values_per_mode(mode, config) - return config_service.ConfigService.update_config(config_json=config, should_encrypt=True) + return config_service.ConfigService.update_config( + config_json=config, should_encrypt=should_encrypt + ) -def _set_default_config_values_per_mode(mode: IslandModeEnum, config: Dict) -> Dict: - config_filter = FILTER_PER_MODE[mode.value] +def _set_default_config_values_per_mode(mode: str, config: Dict) -> Dict: + config_filter = FILTER_PER_MODE[mode] config = _apply_config_filter(config, config_filter) return config From 7b79c297b9a3616b1b8fd92f537dff42e4056b71 Mon Sep 17 00:00:00 2001 From: Shreya Date: Tue, 20 Jul 2021 16:31:28 +0530 Subject: [PATCH 14/18] island: Replace config "filter" for "manipulator" as file names/constants/functions --- monkey/monkey_island/cc/services/config_manipulator.py | 10 +++++----- .../{config_filters.py => config_manipulators.py} | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) rename monkey/monkey_island/cc/services/{config_filters.py => config_manipulators.py} (88%) diff --git a/monkey/monkey_island/cc/services/config_manipulator.py b/monkey/monkey_island/cc/services/config_manipulator.py index c45ea6f00..41f555be4 100644 --- a/monkey/monkey_island/cc/services/config_manipulator.py +++ b/monkey/monkey_island/cc/services/config_manipulator.py @@ -3,7 +3,7 @@ from typing import Dict import dpath.util import monkey_island.cc.services.config as config_service -from monkey_island.cc.services.config_filters import FILTER_PER_MODE +from monkey_island.cc.services.config_manipulators import MANIPULATOR_PER_MODE from monkey_island.cc.services.mode.mode_enum import IslandModeEnum @@ -20,12 +20,12 @@ def update_config_per_mode(mode: str, config: Dict, should_encrypt: bool) -> boo def _set_default_config_values_per_mode(mode: str, config: Dict) -> Dict: - config_filter = FILTER_PER_MODE[mode] - config = _apply_config_filter(config, config_filter) + config_manipulator = MANIPULATOR_PER_MODE[mode] + config = _apply_config_manipulator(config, config_manipulator) return config -def _apply_config_filter(config: Dict, config_filter: Dict): - for path, value in config_filter.items(): +def _apply_config_manipulator(config: Dict, config_manipulator: Dict): + for path, value in config_manipulator.items(): dpath.util.set(config, path, value, ".") return config diff --git a/monkey/monkey_island/cc/services/config_filters.py b/monkey/monkey_island/cc/services/config_manipulators.py similarity index 88% rename from monkey/monkey_island/cc/services/config_filters.py rename to monkey/monkey_island/cc/services/config_manipulators.py index f8afd114d..291892371 100644 --- a/monkey/monkey_island/cc/services/config_filters.py +++ b/monkey/monkey_island/cc/services/config_manipulators.py @@ -1,6 +1,6 @@ from monkey_island.cc.services.mode.mode_enum import IslandModeEnum -FILTER_PER_MODE = { +MANIPULATOR_PER_MODE = { IslandModeEnum.ADVANCED.value: {}, IslandModeEnum.RANSOMWARE.value: {"monkey.post_breach.post_breach_actions": []}, } From af7651c53b56431cc5da5d700c53545b8e9e20f6 Mon Sep 17 00:00:00 2001 From: Shreya Date: Wed, 21 Jul 2021 17:49:28 +0530 Subject: [PATCH 15/18] island: Move `get_mode()` and `set_mode()` to a single file `island_mode_service.py` --- monkey/monkey_island/cc/resources/island_mode.py | 3 +-- monkey/monkey_island/cc/services/config.py | 2 +- .../cc/services/mode/get_island_mode_service.py | 15 --------------- ...and_mode_service.py => island_mode_service.py} | 14 ++++++++++++++ 4 files changed, 16 insertions(+), 18 deletions(-) delete mode 100644 monkey/monkey_island/cc/services/mode/get_island_mode_service.py rename monkey/monkey_island/cc/services/mode/{set_island_mode_service.py => island_mode_service.py} (69%) diff --git a/monkey/monkey_island/cc/resources/island_mode.py b/monkey/monkey_island/cc/resources/island_mode.py index a7d0a81de..7698fca9d 100644 --- a/monkey/monkey_island/cc/resources/island_mode.py +++ b/monkey/monkey_island/cc/resources/island_mode.py @@ -5,9 +5,8 @@ import flask_restful from flask import make_response, request from monkey_island.cc.resources.auth.auth import jwt_required -from monkey_island.cc.services.mode.get_island_mode_service import ModeNotSetError, get_mode +from monkey_island.cc.services.mode.island_mode_service import ModeNotSetError, get_mode, set_mode from monkey_island.cc.services.mode.mode_enum import IslandModeEnum -from monkey_island.cc.services.mode.set_island_mode_service import set_mode logger = logging.getLogger(__name__) diff --git a/monkey/monkey_island/cc/services/config.py b/monkey/monkey_island/cc/services/config.py index 2dfcd175b..8a107f5b5 100644 --- a/monkey/monkey_island/cc/services/config.py +++ b/monkey/monkey_island/cc/services/config.py @@ -10,7 +10,7 @@ from monkey_island.cc.database import mongo from monkey_island.cc.server_utils.encryptor import get_encryptor from monkey_island.cc.services.config_manipulator import update_config_per_mode from monkey_island.cc.services.config_schema.config_schema import SCHEMA -from monkey_island.cc.services.mode.get_island_mode_service import ModeNotSetError, get_mode +from monkey_island.cc.services.mode.island_mode_service import ModeNotSetError, get_mode from monkey_island.cc.services.post_breach_files import PostBreachFilesService from monkey_island.cc.services.utils.network_utils import local_ip_addresses diff --git a/monkey/monkey_island/cc/services/mode/get_island_mode_service.py b/monkey/monkey_island/cc/services/mode/get_island_mode_service.py deleted file mode 100644 index 1f27ad3b1..000000000 --- a/monkey/monkey_island/cc/services/mode/get_island_mode_service.py +++ /dev/null @@ -1,15 +0,0 @@ -from monkey_island.cc.models.island_mode_model import IslandMode - - -def get_mode() -> str: - if IslandMode.objects: - mode = IslandMode.objects[0].mode - return mode - else: - raise ModeNotSetError - - -class ModeNotSetError(Exception): - """ - Throw this exception when island mode is not set. - """ diff --git a/monkey/monkey_island/cc/services/mode/set_island_mode_service.py b/monkey/monkey_island/cc/services/mode/island_mode_service.py similarity index 69% rename from monkey/monkey_island/cc/services/mode/set_island_mode_service.py rename to monkey/monkey_island/cc/services/mode/island_mode_service.py index ef6f5e5b4..5109c6910 100644 --- a/monkey/monkey_island/cc/services/mode/set_island_mode_service.py +++ b/monkey/monkey_island/cc/services/mode/island_mode_service.py @@ -15,3 +15,17 @@ def set_mode(mode: IslandModeEnum): LOG.error( "Could not apply configuration changes per mode. Using default advanced configuration." ) + + +def get_mode() -> str: + if IslandMode.objects: + mode = IslandMode.objects[0].mode + return mode + else: + raise ModeNotSetError + + +class ModeNotSetError(Exception): + """ + Throw this exception when island mode is not set. + """ From ad24a35acb7841cd4699df4f582353cd3e54a4f3 Mon Sep 17 00:00:00 2001 From: Shreya Date: Wed, 21 Jul 2021 17:50:52 +0530 Subject: [PATCH 16/18] tests: Fix function path in monkeypatch statement as per previous commit changes --- .../unit_tests/monkey_island/cc/resources/test_island_mode.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/monkey/tests/unit_tests/monkey_island/cc/resources/test_island_mode.py b/monkey/tests/unit_tests/monkey_island/cc/resources/test_island_mode.py index 435680bfe..0952f2b43 100644 --- a/monkey/tests/unit_tests/monkey_island/cc/resources/test_island_mode.py +++ b/monkey/tests/unit_tests/monkey_island/cc/resources/test_island_mode.py @@ -15,7 +15,7 @@ def uses_database(): @pytest.mark.parametrize("mode", ["ransomware", "advanced"]) def test_island_mode_post(flask_client, mode, monkeypatch): monkeypatch.setattr( - "monkey_island.cc.services.mode.set_island_mode_service.update_config_on_mode_set", + "monkey_island.cc.services.mode.island_mode_service.update_config_on_mode_set", lambda _: None, ) resp = flask_client.post( From 736c8008a01d17c9f71a5bbf58149f0c3bddb20d Mon Sep 17 00:00:00 2001 From: Shreya Date: Wed, 21 Jul 2021 18:00:55 +0530 Subject: [PATCH 17/18] island: Update config after mode set in island mode resource instead of island mode service --- monkey/monkey_island/cc/resources/island_mode.py | 9 ++++++++- .../cc/services/mode/island_mode_service.py | 5 ----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/monkey/monkey_island/cc/resources/island_mode.py b/monkey/monkey_island/cc/resources/island_mode.py index 7698fca9d..6df681fd7 100644 --- a/monkey/monkey_island/cc/resources/island_mode.py +++ b/monkey/monkey_island/cc/resources/island_mode.py @@ -5,10 +5,11 @@ import flask_restful from flask import make_response, request from monkey_island.cc.resources.auth.auth import jwt_required +from monkey_island.cc.services.config_manipulator import update_config_on_mode_set from monkey_island.cc.services.mode.island_mode_service import ModeNotSetError, get_mode, set_mode from monkey_island.cc.services.mode.mode_enum import IslandModeEnum -logger = logging.getLogger(__name__) +LOG = logging.getLogger(__name__) class IslandMode(flask_restful.Resource): @@ -21,6 +22,12 @@ class IslandMode(flask_restful.Resource): mode = IslandModeEnum(mode_str) set_mode(mode) + if not update_config_on_mode_set(mode): + LOG.error( + "Could not apply configuration changes per mode. " + "Using default advanced configuration." + ) + return make_response({}, 200) except (AttributeError, json.decoder.JSONDecodeError): return make_response({}, 400) diff --git a/monkey/monkey_island/cc/services/mode/island_mode_service.py b/monkey/monkey_island/cc/services/mode/island_mode_service.py index 5109c6910..c45e03116 100644 --- a/monkey/monkey_island/cc/services/mode/island_mode_service.py +++ b/monkey/monkey_island/cc/services/mode/island_mode_service.py @@ -1,7 +1,6 @@ import logging from monkey_island.cc.models.island_mode_model import IslandMode -from monkey_island.cc.services.config_manipulator import update_config_on_mode_set from monkey_island.cc.services.mode.mode_enum import IslandModeEnum LOG = logging.getLogger(__name__) @@ -11,10 +10,6 @@ def set_mode(mode: IslandModeEnum): island_mode_model = IslandMode() island_mode_model.mode = mode.value island_mode_model.save() - if not update_config_on_mode_set(mode): - LOG.error( - "Could not apply configuration changes per mode. Using default advanced configuration." - ) def get_mode() -> str: From 34495d36d4d9c7003bc978e4e249ac4589f82936 Mon Sep 17 00:00:00 2001 From: Shreya Date: Wed, 21 Jul 2021 18:05:07 +0530 Subject: [PATCH 18/18] tests: Fix function path in monkeypatch statement as per previous commit changes --- .../unit_tests/monkey_island/cc/resources/test_island_mode.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/monkey/tests/unit_tests/monkey_island/cc/resources/test_island_mode.py b/monkey/tests/unit_tests/monkey_island/cc/resources/test_island_mode.py index 0952f2b43..37b09aaed 100644 --- a/monkey/tests/unit_tests/monkey_island/cc/resources/test_island_mode.py +++ b/monkey/tests/unit_tests/monkey_island/cc/resources/test_island_mode.py @@ -15,7 +15,7 @@ def uses_database(): @pytest.mark.parametrize("mode", ["ransomware", "advanced"]) def test_island_mode_post(flask_client, mode, monkeypatch): monkeypatch.setattr( - "monkey_island.cc.services.mode.island_mode_service.update_config_on_mode_set", + "monkey_island.cc.resources.island_mode.update_config_on_mode_set", lambda _: None, ) resp = flask_client.post(