From 9b23cc0befa6a0b17ca4ef6c80f1294309bbcf73 Mon Sep 17 00:00:00 2001 From: Shreya Malviya Date: Thu, 30 Jun 2022 21:52:18 -0700 Subject: [PATCH] UT: Remove tests related to config schema per attack technique --- .../test_technique_reports.py | 100 +++--------------- ...test_config_schema_per_attack_technique.py | 25 ----- 2 files changed, 16 insertions(+), 109 deletions(-) delete mode 100644 monkey/tests/unit_tests/monkey_island/cc/services/config_schema/test_config_schema_per_attack_technique.py diff --git a/monkey/tests/unit_tests/monkey_island/cc/services/attack/technique_reports/test_technique_reports.py b/monkey/tests/unit_tests/monkey_island/cc/services/attack/technique_reports/test_technique_reports.py index e408a3aff..dc3ffdc11 100644 --- a/monkey/tests/unit_tests/monkey_island/cc/services/attack/technique_reports/test_technique_reports.py +++ b/monkey/tests/unit_tests/monkey_island/cc/services/attack/technique_reports/test_technique_reports.py @@ -1,20 +1,13 @@ from enum import Enum -import pytest - from common.utils.attack_utils import ScanStatus -from monkey_island.cc.services.attack.technique_reports.__init__ import AttackTechnique +from monkey_island.cc.services.attack.technique_reports.__init__ import ( + UNSCANNED_MESSAGE, + AttackTechnique, +) -@pytest.fixture(scope="function", autouse=True) -def mock_config_schema_per_attack_technique(monkeypatch, fake_schema): - monkeypatch.setattr( - ("monkey_island.cc.services.attack.technique_reports.__init__.SCHEMA"), - fake_schema, - ) - - -class FakeAttackTechnique_TwoRelevantSystems(AttackTechnique): +class FakeAttackTechnique(AttackTechnique): tech_id = "T0000" relevant_systems = ["System 1", "System 2"] unscanned_msg = "UNSCANNED" @@ -25,83 +18,22 @@ class FakeAttackTechnique_TwoRelevantSystems(AttackTechnique): pass -class ExpectedMsgs_TwoRelevantSystems(Enum): - UNSCANNED: str = ( - "UNSCANNED due to one of the following reasons:\n" - "- The following configuration options were disabled or empty:
" - "- Definition Type 1 — Config Option 1, Config Option 2
" - "- Definition Type 2 — Config Option 5, Config Option 6
" - "- Property Type 1 -> Category 1 — Config Option 1
" - "- Property Type 2 -> Category 1 — Config Option 1
" - "- Property Type 2 -> Category 2 -> Config Option 1 — Config Option 1.1
" - "- Property Type 2 -> Category 2 -> Config Option 2 — Config Option 2.1
" - "- Property Type 2 -> Category 2 -> Config Option 2 -> Config Option 2.1 — Config Option " - "2.1.1
" - ) +class ExpectedMsgs(Enum): + UNSCANNED: str = UNSCANNED_MESSAGE SCANNED: str = "SCANNED" USED: str = "USED" -class FakeAttackTechnique_OneRelevantSystem(AttackTechnique): - tech_id = "T0001" - relevant_systems = ["System 1"] - unscanned_msg = "UNSCANNED" - scanned_msg = "SCANNED" - used_msg = "USED" - - def get_report_data(): - pass +def test_get_message_by_status_unscanned(): + technique_msg = FakeAttackTechnique.get_message_by_status(ScanStatus.UNSCANNED.value) + assert technique_msg == ExpectedMsgs.UNSCANNED.value -class ExpectedMsgs_OneRelevantSystem(Enum): - UNSCANNED: str = ( - "UNSCANNED due to one of the following reasons:\n" - "- Monkey did not run on any System 1 systems.\n" - "- The following configuration options were disabled or empty:
" - "- Definition Type 1 — Config Option 1
" - "- Definition Type 2 — Config Option 5
" - ) - SCANNED: str = "SCANNED" - USED: str = "USED" +def test_get_message_by_status_scanned(): + technique_msg = FakeAttackTechnique.get_message_by_status(ScanStatus.SCANNED.value) + assert technique_msg == ExpectedMsgs.SCANNED.value -def test_get_message_by_status_unscanned_two_relevant_systems(): - technique_msg = FakeAttackTechnique_TwoRelevantSystems.get_message_by_status( - ScanStatus.UNSCANNED.value - ) - assert technique_msg == ExpectedMsgs_TwoRelevantSystems.UNSCANNED.value - - -def test_get_message_by_status_scanned_two_relevant_systems(): - technique_msg = FakeAttackTechnique_TwoRelevantSystems.get_message_by_status( - ScanStatus.SCANNED.value - ) - assert technique_msg == ExpectedMsgs_TwoRelevantSystems.SCANNED.value - - -def test_get_message_by_status_used_two_relevant_systems(): - technique_msg = FakeAttackTechnique_TwoRelevantSystems.get_message_by_status( - ScanStatus.USED.value - ) - assert technique_msg == ExpectedMsgs_TwoRelevantSystems.USED.value - - -def test_get_message_by_status_unscanned_one_relevant_system(): - technique_msg = FakeAttackTechnique_OneRelevantSystem.get_message_by_status( - ScanStatus.UNSCANNED.value - ) - assert technique_msg == ExpectedMsgs_OneRelevantSystem.UNSCANNED.value - - -def test_get_message_by_status_scanned_one_relevant_system(): - technique_msg = FakeAttackTechnique_OneRelevantSystem.get_message_by_status( - ScanStatus.SCANNED.value - ) - assert technique_msg == ExpectedMsgs_OneRelevantSystem.SCANNED.value - - -def test_get_message_by_status_used_one_relevant_system(): - technique_msg = FakeAttackTechnique_OneRelevantSystem.get_message_by_status( - ScanStatus.USED.value - ) - assert technique_msg == ExpectedMsgs_OneRelevantSystem.USED.value +def test_get_message_by_status_used(): + technique_msg = FakeAttackTechnique.get_message_by_status(ScanStatus.USED.value) + assert technique_msg == ExpectedMsgs.USED.value 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 deleted file mode 100644 index 86383366e..000000000 --- a/monkey/tests/unit_tests/monkey_island/cc/services/config_schema/test_config_schema_per_attack_technique.py +++ /dev/null @@ -1,25 +0,0 @@ -from monkey_island.cc.services.config_schema.config_schema_per_attack_technique import ( - ConfigSchemaPerAttackTechnique, -) - -REVERSE_FAKE_SCHEMA = { - "T0000": { - "Definition Type 1": ["Config Option 1", "Config Option 2"], - "Definition Type 2": ["Config Option 5", "Config Option 6"], - "Property Type 1 -> Category 1": ["Config Option 1"], - "Property Type 2 -> Category 1": ["Config Option 1"], - "Property Type 2 -> Category 2 -> Config Option 1": ["Config Option 1.1"], - "Property Type 2 -> Category 2 -> Config Option 2": ["Config Option 2.1"], - "Property Type 2 -> Category 2 -> Config Option 2 -> Config Option 2.1": [ - "Config Option 2.1.1" - ], - }, - "T0001": {"Definition Type 1": ["Config Option 1"], "Definition Type 2": ["Config Option 5"]}, -} - - -def test_get_config_schema_per_attack_technique(monkeypatch, fake_schema): - assert ( - ConfigSchemaPerAttackTechnique().get_config_schema_per_attack_technique(fake_schema) - == REVERSE_FAKE_SCHEMA - )