diff --git a/monkey/monkey_island/cc/services/config_schema/config_schema_per_attack_technique.py b/monkey/monkey_island/cc/services/config_schema/config_schema_per_attack_technique.py index 61fcae807..4aeab0085 100644 --- a/monkey/monkey_island/cc/services/config_schema/config_schema_per_attack_technique.py +++ b/monkey/monkey_island/cc/services/config_schema/config_schema_per_attack_technique.py @@ -1,9 +1,7 @@ from typing import Dict, List -from monkey_island.cc.services.config_schema.config_schema import SCHEMA - -def get_config_schema_per_attack_technique() -> Dict[str, Dict[str, List[str]]]: +def get_config_schema_per_attack_technique(schema: Dict) -> Dict[str, Dict[str, List[str]]]: """ :return: dictionary mapping each attack technique to relevant config fields; example - { @@ -17,7 +15,7 @@ def get_config_schema_per_attack_technique() -> Dict[str, Dict[str, List[str]]]: """ reverse_schema = {} - definitions = SCHEMA["definitions"] + definitions = schema["definitions"] for definition in definitions: definition_type = definitions[definition]["title"] for field in definitions[definition]["anyOf"]: @@ -37,6 +35,3 @@ def _add_config_field_to_reverse_schema( reverse_schema[attack_technique].setdefault(definition_type, []).append(config_field) else: reverse_schema[attack_technique] = {definition_type: [config_field]} - - -CONFIG_SCHEMA_PER_ATTACK_TECHNIQUE = get_config_schema_per_attack_technique() diff --git a/monkey/tests/unit_tests/monkey_island/cc/services/config_schema/test_config_schema_per_attack_technique.py b/monkey/tests/unit_tests/monkey_island/cc/services/config_schema/test_config_schema_per_attack_technique.py index 2827fd302..bacdae5dd 100644 --- a/monkey/tests/unit_tests/monkey_island/cc/services/config_schema/test_config_schema_per_attack_technique.py +++ b/monkey/tests/unit_tests/monkey_island/cc/services/config_schema/test_config_schema_per_attack_technique.py @@ -2,51 +2,6 @@ from monkey_island.cc.services.config_schema.config_schema_per_attack_technique get_config_schema_per_attack_technique, ) -FAKE_SCHEMA = { - "definitions": { - "definition_type_1": { - "title": "Definition Type 1", - "anyOf": [ - { - "title": "Config Option 1", - "attack_techniques": ["T0000", "T0001"], - }, - { - "title": "Config Option 2", - "attack_techniques": ["T0000"], - }, - { - "title": "Config Option 3", - "attack_techniques": [], - }, - { - "title": "Config Option 4", - }, - ], - }, - "definition_type_2": { - "title": "Definition Type 2", - "anyOf": [ - { - "title": "Config Option 5", - "attack_techniques": ["T0000", "T0001"], - }, - { - "title": "Config Option 6", - "attack_techniques": ["T0000"], - }, - { - "title": "Config Option 7", - "attack_techniques": [], - }, - { - "title": "Config Option 8", - }, - ], - }, - } -} - REVERSE_FAKE_SCHEMA = { "T0000": { "Definition Type 1": ["Config Option 1", "Config Option 2"], @@ -59,9 +14,5 @@ REVERSE_FAKE_SCHEMA = { } -def test_get_config_schema_per_attack_technique(monkeypatch): - monkeypatch.setattr( - "monkey_island.cc.services.config_schema.config_schema_per_attack_technique.SCHEMA", - FAKE_SCHEMA, - ) - assert get_config_schema_per_attack_technique() == REVERSE_FAKE_SCHEMA +def test_get_config_schema_per_attack_technique(monkeypatch, fake_schema): + assert get_config_schema_per_attack_technique(fake_schema) == REVERSE_FAKE_SCHEMA diff --git a/monkey/tests/unit_tests/monkey_island/cc/services/conftest.py b/monkey/tests/unit_tests/monkey_island/cc/services/conftest.py index 7b56c0c13..b89be55f9 100644 --- a/monkey/tests/unit_tests/monkey_island/cc/services/conftest.py +++ b/monkey/tests/unit_tests/monkey_island/cc/services/conftest.py @@ -20,3 +20,51 @@ def config(monkeypatch, IPS, PORT): monkeypatch.setattr(Environment, "_ISLAND_PORT", PORT) config = ConfigService.get_default_config(True) return config + + +@pytest.fixture +def fake_schema(): + return { + "definitions": { + "definition_type_1": { + "title": "Definition Type 1", + "anyOf": [ + { + "title": "Config Option 1", + "attack_techniques": ["T0000", "T0001"], + }, + { + "title": "Config Option 2", + "attack_techniques": ["T0000"], + }, + { + "title": "Config Option 3", + "attack_techniques": [], + }, + { + "title": "Config Option 4", + }, + ], + }, + "definition_type_2": { + "title": "Definition Type 2", + "anyOf": [ + { + "title": "Config Option 5", + "attack_techniques": ["T0000", "T0001"], + }, + { + "title": "Config Option 6", + "attack_techniques": ["T0000"], + }, + { + "title": "Config Option 7", + "attack_techniques": [], + }, + { + "title": "Config Option 8", + }, + ], + }, + } + }