forked from p15670423/monkey
Island: Remove disused config_manipulator "service"
This commit is contained in:
parent
c1994f5d60
commit
6459da1d15
|
@ -1,31 +0,0 @@
|
||||||
from typing import Dict
|
|
||||||
|
|
||||||
import dpath.util
|
|
||||||
|
|
||||||
import monkey_island.cc.services.config as config_service
|
|
||||||
from monkey_island.cc.services.config_manipulators import MANIPULATOR_PER_MODE
|
|
||||||
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.value, config, True)
|
|
||||||
|
|
||||||
|
|
||||||
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=should_encrypt
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def _set_default_config_values_per_mode(mode: str, config: Dict) -> Dict:
|
|
||||||
config_manipulator = MANIPULATOR_PER_MODE[mode]
|
|
||||||
config = _apply_config_manipulator(config, config_manipulator)
|
|
||||||
return config
|
|
||||||
|
|
||||||
|
|
||||||
def _apply_config_manipulator(config: Dict, config_manipulator: Dict):
|
|
||||||
for path, value in config_manipulator.items():
|
|
||||||
dpath.util.set(config, path, value, ".")
|
|
||||||
return config
|
|
|
@ -1,32 +0,0 @@
|
||||||
import pytest
|
|
||||||
|
|
||||||
from monkey_island.cc.services.config_manipulator import update_config_on_mode_set
|
|
||||||
from monkey_island.cc.services.mode.mode_enum import IslandModeEnum
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.slow
|
|
||||||
@pytest.mark.usefixtures("uses_encryptor")
|
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.slow
|
|
||||||
@pytest.mark.usefixtures("uses_encryptor")
|
|
||||||
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"] == []
|
|
Loading…
Reference in New Issue