forked from p15670423/monkey
tests: Add unit tests for `get_message_by_status()` in
monkey_island\cc\services\attack\technique_reports\__init__.py
This commit is contained in:
parent
f2470bb0e9
commit
90f3cff3cd
|
@ -0,0 +1,174 @@
|
||||||
|
from common.utils.attack_utils import ScanStatus
|
||||||
|
from monkey_island.cc.services.attack.technique_reports.__init__ import (
|
||||||
|
AttackTechnique,
|
||||||
|
disabled_msg,
|
||||||
|
)
|
||||||
|
|
||||||
|
FAKE_CONFIG_SCHEMA_PER_ATTACK_TECHNIQUE = {
|
||||||
|
"T0000": {
|
||||||
|
"Definition Type 1": ["Config Option 1", "Config Option 2"],
|
||||||
|
"Definition Type 2": ["Config Option 5", "Config Option 6"],
|
||||||
|
},
|
||||||
|
"T0001": {
|
||||||
|
"Definition Type 1": ["Config Option 1"],
|
||||||
|
"Definition Type 2": ["Config Option 5"],
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class FakeAttackTechnique(AttackTechnique):
|
||||||
|
tech_id = "T0001"
|
||||||
|
relevant_systems = ["System 1", "System 2"]
|
||||||
|
unscanned_msg = "UNSCANNED"
|
||||||
|
scanned_msg = "SCANNED"
|
||||||
|
used_msg = "USED"
|
||||||
|
|
||||||
|
def get_report_data():
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
EXPECTED_UNSCANNED_MSG = (
|
||||||
|
"UNSCANNED due to one of the following reasons:\n"
|
||||||
|
"- The following configuration options were disabled:<br/>"
|
||||||
|
"- Definition Type 1 — Config Option 1<br/>"
|
||||||
|
"- Definition Type 2 — Config Option 5<br/>"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
EXPECTED_SCANNED_MSG = "SCANNED"
|
||||||
|
|
||||||
|
|
||||||
|
EXPECTED_USED_MSG = "USED"
|
||||||
|
|
||||||
|
|
||||||
|
def test_get_message_by_status_disabled(monkeypatch):
|
||||||
|
monkeypatch.setattr(
|
||||||
|
(
|
||||||
|
"monkey_island.cc.services.attack.technique_reports."
|
||||||
|
"__init__.CONFIG_SCHEMA_PER_ATTACK_TECHNIQUE"
|
||||||
|
),
|
||||||
|
FAKE_CONFIG_SCHEMA_PER_ATTACK_TECHNIQUE,
|
||||||
|
)
|
||||||
|
technique_msg = FakeAttackTechnique.get_message_by_status(ScanStatus.DISABLED.value)
|
||||||
|
assert technique_msg == disabled_msg
|
||||||
|
|
||||||
|
|
||||||
|
def test_get_message_by_status_unscanned(monkeypatch):
|
||||||
|
monkeypatch.setattr(
|
||||||
|
(
|
||||||
|
"monkey_island.cc.services.attack.technique_reports."
|
||||||
|
"__init__.CONFIG_SCHEMA_PER_ATTACK_TECHNIQUE"
|
||||||
|
),
|
||||||
|
FAKE_CONFIG_SCHEMA_PER_ATTACK_TECHNIQUE,
|
||||||
|
)
|
||||||
|
technique_msg = FakeAttackTechnique.get_message_by_status(ScanStatus.UNSCANNED.value)
|
||||||
|
assert technique_msg == EXPECTED_UNSCANNED_MSG
|
||||||
|
|
||||||
|
|
||||||
|
def test_get_message_by_status_scanned(monkeypatch):
|
||||||
|
monkeypatch.setattr(
|
||||||
|
(
|
||||||
|
"monkey_island.cc.services.attack.technique_reports."
|
||||||
|
"__init__.CONFIG_SCHEMA_PER_ATTACK_TECHNIQUE"
|
||||||
|
),
|
||||||
|
FAKE_CONFIG_SCHEMA_PER_ATTACK_TECHNIQUE,
|
||||||
|
)
|
||||||
|
technique_msg = FakeAttackTechnique.get_message_by_status(ScanStatus.SCANNED.value)
|
||||||
|
assert technique_msg == EXPECTED_SCANNED_MSG
|
||||||
|
|
||||||
|
|
||||||
|
def test_get_message_by_status_used(monkeypatch):
|
||||||
|
monkeypatch.setattr(
|
||||||
|
(
|
||||||
|
"monkey_island.cc.services.attack.technique_reports."
|
||||||
|
"__init__.CONFIG_SCHEMA_PER_ATTACK_TECHNIQUE"
|
||||||
|
),
|
||||||
|
FAKE_CONFIG_SCHEMA_PER_ATTACK_TECHNIQUE,
|
||||||
|
)
|
||||||
|
technique_msg = FakeAttackTechnique.get_message_by_status(ScanStatus.USED.value)
|
||||||
|
assert technique_msg == EXPECTED_USED_MSG
|
||||||
|
|
||||||
|
|
||||||
|
###
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
EXPECTED_UNSCANNED_MSG_ONE_RELEVANT_SYSTEM = (
|
||||||
|
"UNSCANNED due to one of the following reasons:\n"
|
||||||
|
"- The Monkey did not run on any System 1 systems.\n"
|
||||||
|
"- The following configuration options were disabled:<br/>"
|
||||||
|
"- Definition Type 1 — Config Option 1<br/>"
|
||||||
|
"- Definition Type 2 — Config Option 5<br/>"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
EXPECTED_SCANNED_MSG_ONE_RELEVANT_SYSTEM = "SCANNED"
|
||||||
|
|
||||||
|
|
||||||
|
EXPECTED_USED_MSG_ONE_RELEVANT_SYSTEM = "USED"
|
||||||
|
|
||||||
|
|
||||||
|
def test_get_message_by_status_disabled_one_relevant_system(monkeypatch):
|
||||||
|
monkeypatch.setattr(
|
||||||
|
(
|
||||||
|
"monkey_island.cc.services.attack.technique_reports."
|
||||||
|
"__init__.CONFIG_SCHEMA_PER_ATTACK_TECHNIQUE"
|
||||||
|
),
|
||||||
|
FAKE_CONFIG_SCHEMA_PER_ATTACK_TECHNIQUE,
|
||||||
|
)
|
||||||
|
technique_msg = FakeAttackTechnique_OneRelevantSystem.get_message_by_status(
|
||||||
|
ScanStatus.DISABLED.value
|
||||||
|
)
|
||||||
|
assert technique_msg == disabled_msg
|
||||||
|
|
||||||
|
|
||||||
|
def test_get_message_by_status_unscanned_one_relevant_system(monkeypatch):
|
||||||
|
monkeypatch.setattr(
|
||||||
|
(
|
||||||
|
"monkey_island.cc.services.attack.technique_reports."
|
||||||
|
"__init__.CONFIG_SCHEMA_PER_ATTACK_TECHNIQUE"
|
||||||
|
),
|
||||||
|
FAKE_CONFIG_SCHEMA_PER_ATTACK_TECHNIQUE,
|
||||||
|
)
|
||||||
|
technique_msg = FakeAttackTechnique_OneRelevantSystem.get_message_by_status(
|
||||||
|
ScanStatus.UNSCANNED.value
|
||||||
|
)
|
||||||
|
assert technique_msg == EXPECTED_UNSCANNED_MSG_ONE_RELEVANT_SYSTEM
|
||||||
|
|
||||||
|
|
||||||
|
def test_get_message_by_status_scanned_one_relevant_system(monkeypatch):
|
||||||
|
monkeypatch.setattr(
|
||||||
|
(
|
||||||
|
"monkey_island.cc.services.attack.technique_reports."
|
||||||
|
"__init__.CONFIG_SCHEMA_PER_ATTACK_TECHNIQUE"
|
||||||
|
),
|
||||||
|
FAKE_CONFIG_SCHEMA_PER_ATTACK_TECHNIQUE,
|
||||||
|
)
|
||||||
|
technique_msg = FakeAttackTechnique_OneRelevantSystem.get_message_by_status(
|
||||||
|
ScanStatus.SCANNED.value
|
||||||
|
)
|
||||||
|
assert technique_msg == EXPECTED_SCANNED_MSG_ONE_RELEVANT_SYSTEM
|
||||||
|
|
||||||
|
|
||||||
|
def test_get_message_by_status_used_one_relevant_system(monkeypatch):
|
||||||
|
monkeypatch.setattr(
|
||||||
|
(
|
||||||
|
"monkey_island.cc.services.attack.technique_reports."
|
||||||
|
"__init__.CONFIG_SCHEMA_PER_ATTACK_TECHNIQUE"
|
||||||
|
),
|
||||||
|
FAKE_CONFIG_SCHEMA_PER_ATTACK_TECHNIQUE,
|
||||||
|
)
|
||||||
|
technique_msg = FakeAttackTechnique_OneRelevantSystem.get_message_by_status(
|
||||||
|
ScanStatus.USED.value
|
||||||
|
)
|
||||||
|
assert technique_msg == EXPECTED_USED_MSG_ONE_RELEVANT_SYSTEM
|
Loading…
Reference in New Issue