From a4603853a92d7c6848893e674b1fb6c040405faf Mon Sep 17 00:00:00 2001 From: Shreya Date: Thu, 18 Feb 2021 22:35:26 +0530 Subject: [PATCH] Split test_attack_telem_classes.py and test_technique_telems.py into separate test files --- .../tests/attack/test_attack_telem.py | 21 +++ .../tests/attack/test_t1005_telem.py | 24 +++ .../tests/attack/test_t1035_telem.py | 22 +++ .../tests/attack/test_t1064_telem.py | 22 +++ .../tests/attack/test_t1105_telem.py | 26 +++ .../tests/attack/test_t1106_telem.py | 22 +++ .../tests/attack/test_t1107_telem.py | 22 +++ .../tests/attack/test_t1129_telem.py | 22 +++ .../tests/attack/test_t1197_telem.py | 26 +++ .../tests/attack/test_t1222_telem.py | 26 +++ .../tests/attack/test_usage_telem.py | 23 +++ .../tests/attack/test_victim_host_telem.py | 25 +++ .../tests/test_attack_telem_classes.py | 55 ------ .../telemetry/tests/test_technique_telems.py | 159 ------------------ 14 files changed, 281 insertions(+), 214 deletions(-) create mode 100644 monkey/infection_monkey/telemetry/tests/attack/test_attack_telem.py create mode 100644 monkey/infection_monkey/telemetry/tests/attack/test_t1005_telem.py create mode 100644 monkey/infection_monkey/telemetry/tests/attack/test_t1035_telem.py create mode 100644 monkey/infection_monkey/telemetry/tests/attack/test_t1064_telem.py create mode 100644 monkey/infection_monkey/telemetry/tests/attack/test_t1105_telem.py create mode 100644 monkey/infection_monkey/telemetry/tests/attack/test_t1106_telem.py create mode 100644 monkey/infection_monkey/telemetry/tests/attack/test_t1107_telem.py create mode 100644 monkey/infection_monkey/telemetry/tests/attack/test_t1129_telem.py create mode 100644 monkey/infection_monkey/telemetry/tests/attack/test_t1197_telem.py create mode 100644 monkey/infection_monkey/telemetry/tests/attack/test_t1222_telem.py create mode 100644 monkey/infection_monkey/telemetry/tests/attack/test_usage_telem.py create mode 100644 monkey/infection_monkey/telemetry/tests/attack/test_victim_host_telem.py delete mode 100644 monkey/infection_monkey/telemetry/tests/test_attack_telem_classes.py delete mode 100644 monkey/infection_monkey/telemetry/tests/test_technique_telems.py diff --git a/monkey/infection_monkey/telemetry/tests/attack/test_attack_telem.py b/monkey/infection_monkey/telemetry/tests/attack/test_attack_telem.py new file mode 100644 index 000000000..750075fb2 --- /dev/null +++ b/monkey/infection_monkey/telemetry/tests/attack/test_attack_telem.py @@ -0,0 +1,21 @@ +import pytest + +from common.utils.attack_utils import ScanStatus +from infection_monkey.telemetry.attack.attack_telem import AttackTelem + + +STATUS = ScanStatus.USED +TECHNIQUE = 'T9999' + + +@pytest.fixture +def attack_telem_test_instance(): + return AttackTelem(TECHNIQUE, STATUS) + + +def test_attack_telem_send(attack_telem_test_instance, spy_send_telemetry): + attack_telem_test_instance.send() + expected_data = {'status': STATUS.value, + 'technique': TECHNIQUE} + assert spy_send_telemetry.data == expected_data + assert spy_send_telemetry.telem_category == 'attack' diff --git a/monkey/infection_monkey/telemetry/tests/attack/test_t1005_telem.py b/monkey/infection_monkey/telemetry/tests/attack/test_t1005_telem.py new file mode 100644 index 000000000..757f0de13 --- /dev/null +++ b/monkey/infection_monkey/telemetry/tests/attack/test_t1005_telem.py @@ -0,0 +1,24 @@ +import pytest + +from common.utils.attack_utils import ScanStatus +from infection_monkey.telemetry.attack.t1005_telem import T1005Telem + + +GATHERED_DATA_TYPE = '[Type of data collected]' +INFO = '[Additional info]' +STATUS = ScanStatus.USED + + +@pytest.fixture +def T1005_telem_test_instance(): + return T1005Telem(STATUS, GATHERED_DATA_TYPE, INFO) + + +def test_T1005_send(T1005_telem_test_instance, spy_send_telemetry): + T1005_telem_test_instance.send() + expected_data = {'status': STATUS.value, + 'technique': 'T1005', + 'gathered_data_type': GATHERED_DATA_TYPE, + 'info': INFO} + assert spy_send_telemetry.data == expected_data + assert spy_send_telemetry.telem_category == 'attack' diff --git a/monkey/infection_monkey/telemetry/tests/attack/test_t1035_telem.py b/monkey/infection_monkey/telemetry/tests/attack/test_t1035_telem.py new file mode 100644 index 000000000..a3133fcb9 --- /dev/null +++ b/monkey/infection_monkey/telemetry/tests/attack/test_t1035_telem.py @@ -0,0 +1,22 @@ +import pytest + +from common.utils.attack_utils import ScanStatus, UsageEnum +from infection_monkey.telemetry.attack.t1035_telem import T1035Telem + + +STATUS = ScanStatus.USED +USAGE = UsageEnum.SMB + + +@pytest.fixture +def T1035_telem_test_instance(): + return T1035Telem(STATUS, USAGE) + + +def test_T1035_send(T1035_telem_test_instance, spy_send_telemetry): + T1035_telem_test_instance.send() + expected_data = {'status': STATUS.value, + 'technique': 'T1035', + 'usage': USAGE.name} + assert spy_send_telemetry.data == expected_data + assert spy_send_telemetry.telem_category == 'attack' diff --git a/monkey/infection_monkey/telemetry/tests/attack/test_t1064_telem.py b/monkey/infection_monkey/telemetry/tests/attack/test_t1064_telem.py new file mode 100644 index 000000000..575b57540 --- /dev/null +++ b/monkey/infection_monkey/telemetry/tests/attack/test_t1064_telem.py @@ -0,0 +1,22 @@ +import pytest + +from common.utils.attack_utils import ScanStatus +from infection_monkey.telemetry.attack.t1064_telem import T1064Telem + + +STATUS = ScanStatus.USED +USAGE_STR = '[Usage info]' + + +@pytest.fixture +def T1064_telem_test_instance(): + return T1064Telem(STATUS, USAGE_STR) + + +def test_T1064_send(T1064_telem_test_instance, spy_send_telemetry): + T1064_telem_test_instance.send() + expected_data = {'status': STATUS.value, + 'technique': 'T1064', + 'usage': USAGE_STR} + assert spy_send_telemetry.data == expected_data + assert spy_send_telemetry.telem_category == 'attack' diff --git a/monkey/infection_monkey/telemetry/tests/attack/test_t1105_telem.py b/monkey/infection_monkey/telemetry/tests/attack/test_t1105_telem.py new file mode 100644 index 000000000..050003e55 --- /dev/null +++ b/monkey/infection_monkey/telemetry/tests/attack/test_t1105_telem.py @@ -0,0 +1,26 @@ +import pytest + +from common.utils.attack_utils import ScanStatus +from infection_monkey.telemetry.attack.t1105_telem import T1105Telem + + +DST_IP = '0.0.0.1' +FILENAME = 'virus.exe' +SRC_IP = '0.0.0.0' +STATUS = ScanStatus.USED + + +@pytest.fixture +def T1105_telem_test_instance(): + return T1105Telem(STATUS, SRC_IP, DST_IP, FILENAME) + + +def test_T1105_send(T1105_telem_test_instance, spy_send_telemetry): + T1105_telem_test_instance.send() + expected_data = {'status': STATUS.value, + 'technique': 'T1105', + 'filename': FILENAME, + 'src': SRC_IP, + 'dst': DST_IP} + assert spy_send_telemetry.data == expected_data + assert spy_send_telemetry.telem_category == 'attack' diff --git a/monkey/infection_monkey/telemetry/tests/attack/test_t1106_telem.py b/monkey/infection_monkey/telemetry/tests/attack/test_t1106_telem.py new file mode 100644 index 000000000..e47568c03 --- /dev/null +++ b/monkey/infection_monkey/telemetry/tests/attack/test_t1106_telem.py @@ -0,0 +1,22 @@ +import pytest + +from common.utils.attack_utils import ScanStatus, UsageEnum +from infection_monkey.telemetry.attack.t1106_telem import T1106Telem + + +STATUS = ScanStatus.USED +USAGE = UsageEnum.SMB + + +@pytest.fixture +def T1106_telem_test_instance(): + return T1106Telem(STATUS, USAGE) + + +def test_T1106_send(T1106_telem_test_instance, spy_send_telemetry): + T1106_telem_test_instance.send() + expected_data = {'status': STATUS.value, + 'technique': 'T1106', + 'usage': USAGE.name} + assert spy_send_telemetry.data == expected_data + assert spy_send_telemetry.telem_category == 'attack' diff --git a/monkey/infection_monkey/telemetry/tests/attack/test_t1107_telem.py b/monkey/infection_monkey/telemetry/tests/attack/test_t1107_telem.py new file mode 100644 index 000000000..2635f429b --- /dev/null +++ b/monkey/infection_monkey/telemetry/tests/attack/test_t1107_telem.py @@ -0,0 +1,22 @@ +import pytest + +from common.utils.attack_utils import ScanStatus +from infection_monkey.telemetry.attack.t1107_telem import T1107Telem + + +PATH = 'path/to/file.txt' +STATUS = ScanStatus.USED + + +@pytest.fixture +def T1107_telem_test_instance(): + return T1107Telem(STATUS, PATH) + + +def test_T1107_send(T1107_telem_test_instance, spy_send_telemetry): + T1107_telem_test_instance.send() + expected_data = {'status': STATUS.value, + 'technique': 'T1107', + 'path': PATH} + assert spy_send_telemetry.data == expected_data + assert spy_send_telemetry.telem_category == 'attack' diff --git a/monkey/infection_monkey/telemetry/tests/attack/test_t1129_telem.py b/monkey/infection_monkey/telemetry/tests/attack/test_t1129_telem.py new file mode 100644 index 000000000..ce5562e1a --- /dev/null +++ b/monkey/infection_monkey/telemetry/tests/attack/test_t1129_telem.py @@ -0,0 +1,22 @@ +import pytest + +from common.utils.attack_utils import ScanStatus, UsageEnum +from infection_monkey.telemetry.attack.t1129_telem import T1129Telem + + +STATUS = ScanStatus.USED +USAGE = UsageEnum.SMB + + +@pytest.fixture +def T1129_telem_test_instance(): + return T1129Telem(STATUS, USAGE) + + +def test_T1129_send(T1129_telem_test_instance, spy_send_telemetry): + T1129_telem_test_instance.send() + expected_data = {'status': STATUS.value, + 'technique': 'T1129', + 'usage': USAGE.name} + assert spy_send_telemetry.data == expected_data + assert spy_send_telemetry.telem_category == 'attack' diff --git a/monkey/infection_monkey/telemetry/tests/attack/test_t1197_telem.py b/monkey/infection_monkey/telemetry/tests/attack/test_t1197_telem.py new file mode 100644 index 000000000..3c620e854 --- /dev/null +++ b/monkey/infection_monkey/telemetry/tests/attack/test_t1197_telem.py @@ -0,0 +1,26 @@ +import pytest + +from common.utils.attack_utils import ScanStatus +from infection_monkey.model import VictimHost +from infection_monkey.telemetry.attack.t1197_telem import T1197Telem + + +MACHINE = VictimHost('127.0.0.1') +STATUS = ScanStatus.USED +USAGE_STR = '[Usage info]' + + +@pytest.fixture +def T1197_telem_test_instance(): + return T1197Telem(STATUS, MACHINE, USAGE_STR) + + +def test_T1197_send(T1197_telem_test_instance, spy_send_telemetry): + T1197_telem_test_instance.send() + expected_data = {'machine': {'domain_name': MACHINE.domain_name, + 'ip_addr': MACHINE.ip_addr}, + 'status': STATUS.value, + 'technique': 'T1197', + 'usage': USAGE_STR} + assert spy_send_telemetry.data == expected_data + assert spy_send_telemetry.telem_category == 'attack' diff --git a/monkey/infection_monkey/telemetry/tests/attack/test_t1222_telem.py b/monkey/infection_monkey/telemetry/tests/attack/test_t1222_telem.py new file mode 100644 index 000000000..da87dfe7d --- /dev/null +++ b/monkey/infection_monkey/telemetry/tests/attack/test_t1222_telem.py @@ -0,0 +1,26 @@ +import pytest + +from common.utils.attack_utils import ScanStatus +from infection_monkey.model import VictimHost +from infection_monkey.telemetry.attack.t1222_telem import T1222Telem + + +COMMAND = 'echo hi' +MACHINE = VictimHost('127.0.0.1') +STATUS = ScanStatus.USED + + +@pytest.fixture +def T1222_telem_test_instance(): + return T1222Telem(STATUS, COMMAND, MACHINE) + + +def test_T1222_send(T1222_telem_test_instance, spy_send_telemetry): + T1222_telem_test_instance.send() + expected_data = {'machine': {'domain_name': MACHINE.domain_name, + 'ip_addr': MACHINE.ip_addr}, + 'status': STATUS.value, + 'technique': 'T1222', + 'command': COMMAND} + assert spy_send_telemetry.data == expected_data + assert spy_send_telemetry.telem_category == 'attack' diff --git a/monkey/infection_monkey/telemetry/tests/attack/test_usage_telem.py b/monkey/infection_monkey/telemetry/tests/attack/test_usage_telem.py new file mode 100644 index 000000000..b707242a3 --- /dev/null +++ b/monkey/infection_monkey/telemetry/tests/attack/test_usage_telem.py @@ -0,0 +1,23 @@ +import pytest + +from common.utils.attack_utils import ScanStatus, UsageEnum +from infection_monkey.telemetry.attack.usage_telem import UsageTelem + + +STATUS = ScanStatus.USED +TECHNIQUE = 'T9999' +USAGE = UsageEnum.SMB + + +@pytest.fixture +def usage_telem_test_instance(): + return UsageTelem(TECHNIQUE, STATUS, USAGE) + + +def test_usage_telem_send(usage_telem_test_instance, spy_send_telemetry): + usage_telem_test_instance.send() + expected_data = {'status': STATUS.value, + 'technique': TECHNIQUE, + 'usage': USAGE.name} + assert spy_send_telemetry.data == expected_data + assert spy_send_telemetry.telem_category == 'attack' diff --git a/monkey/infection_monkey/telemetry/tests/attack/test_victim_host_telem.py b/monkey/infection_monkey/telemetry/tests/attack/test_victim_host_telem.py new file mode 100644 index 000000000..3743b7d76 --- /dev/null +++ b/monkey/infection_monkey/telemetry/tests/attack/test_victim_host_telem.py @@ -0,0 +1,25 @@ +import pytest + +from common.utils.attack_utils import ScanStatus, UsageEnum +from infection_monkey.model import VictimHost +from infection_monkey.telemetry.attack.victim_host_telem import VictimHostTelem + + +MACHINE = VictimHost('127.0.0.1') +STATUS = ScanStatus.USED +TECHNIQUE = 'T9999' + + +@pytest.fixture +def victim_host_telem_test_instance(): + return VictimHostTelem(TECHNIQUE, STATUS, MACHINE) + + +def test_victim_host_telem_send(victim_host_telem_test_instance, spy_send_telemetry): + victim_host_telem_test_instance.send() + expected_data = {'machine': {'domain_name': MACHINE.domain_name, + 'ip_addr': MACHINE.ip_addr}, + 'status': STATUS.value, + 'technique': TECHNIQUE} + assert spy_send_telemetry.data == expected_data + assert spy_send_telemetry.telem_category == 'attack' diff --git a/monkey/infection_monkey/telemetry/tests/test_attack_telem_classes.py b/monkey/infection_monkey/telemetry/tests/test_attack_telem_classes.py deleted file mode 100644 index 13dc02322..000000000 --- a/monkey/infection_monkey/telemetry/tests/test_attack_telem_classes.py +++ /dev/null @@ -1,55 +0,0 @@ -import pytest - -from common.utils.attack_utils import ScanStatus, UsageEnum -from infection_monkey.model import VictimHost -from infection_monkey.telemetry.attack.attack_telem import AttackTelem -from infection_monkey.telemetry.attack.usage_telem import UsageTelem -from infection_monkey.telemetry.attack.victim_host_telem import VictimHostTelem - - -MACHINE = VictimHost('127.0.0.1') -STATUS = ScanStatus.USED -TECHNIQUE = 'T9999' -USAGE = UsageEnum.SMB - - -@pytest.fixture -def attack_telem_test_instance(): - return AttackTelem(TECHNIQUE, STATUS) - - -def test_attack_telem_send(attack_telem_test_instance, spy_send_telemetry): - attack_telem_test_instance.send() - expected_data = {'status': STATUS.value, - 'technique': TECHNIQUE} - assert spy_send_telemetry.data == expected_data - assert spy_send_telemetry.telem_category == 'attack' - - -@pytest.fixture -def usage_telem_test_instance(): - return UsageTelem(TECHNIQUE, STATUS, USAGE) - - -def test_usage_telem_send(usage_telem_test_instance, spy_send_telemetry): - usage_telem_test_instance.send() - expected_data = {'status': STATUS.value, - 'technique': TECHNIQUE, - 'usage': USAGE.name} - assert spy_send_telemetry.data == expected_data - assert spy_send_telemetry.telem_category == 'attack' - - -@pytest.fixture -def victim_host_telem_test_instance(): - return VictimHostTelem(TECHNIQUE, STATUS, MACHINE) - - -def test_victim_host_telem_send(victim_host_telem_test_instance, spy_send_telemetry): - victim_host_telem_test_instance.send() - expected_data = {'machine': {'domain_name': MACHINE.domain_name, - 'ip_addr': MACHINE.ip_addr}, - 'status': STATUS.value, - 'technique': TECHNIQUE} - assert spy_send_telemetry.data == expected_data - assert spy_send_telemetry.telem_category == 'attack' diff --git a/monkey/infection_monkey/telemetry/tests/test_technique_telems.py b/monkey/infection_monkey/telemetry/tests/test_technique_telems.py deleted file mode 100644 index b2c73867d..000000000 --- a/monkey/infection_monkey/telemetry/tests/test_technique_telems.py +++ /dev/null @@ -1,159 +0,0 @@ -import pytest - -from common.utils.attack_utils import ScanStatus, UsageEnum -from infection_monkey.model import VictimHost -from infection_monkey.telemetry.attack.t1005_telem import T1005Telem -from infection_monkey.telemetry.attack.t1035_telem import T1035Telem -from infection_monkey.telemetry.attack.t1064_telem import T1064Telem -from infection_monkey.telemetry.attack.t1105_telem import T1105Telem -from infection_monkey.telemetry.attack.t1106_telem import T1106Telem -from infection_monkey.telemetry.attack.t1107_telem import T1107Telem -from infection_monkey.telemetry.attack.t1129_telem import T1129Telem -from infection_monkey.telemetry.attack.t1197_telem import T1197Telem -from infection_monkey.telemetry.attack.t1222_telem import T1222Telem - - -COMMAND = 'echo hi' -DST_IP = '0.0.0.1' -FILENAME = 'virus.exe' -GATHERED_DATA_TYPE = '[Type of data collected]' -INFO = '[Additional info]' -MACHINE = VictimHost('127.0.0.1') -PATH = 'path/to/file.txt' -SRC_IP = '0.0.0.0' -STATUS = ScanStatus.USED -USAGE = UsageEnum.SMB -USAGE_STR = '[Usage info]' - - -@pytest.fixture -def T1005_telem_test_instance(): - return T1005Telem(STATUS, GATHERED_DATA_TYPE, INFO) - - -def test_T1005_send(T1005_telem_test_instance, spy_send_telemetry): - T1005_telem_test_instance.send() - expected_data = {'status': STATUS.value, - 'technique': 'T1005', - 'gathered_data_type': GATHERED_DATA_TYPE, - 'info': INFO} - assert spy_send_telemetry.data == expected_data - assert spy_send_telemetry.telem_category == 'attack' - - -@pytest.fixture -def T1035_telem_test_instance(): - return T1035Telem(STATUS, USAGE) - - -def test_T1035_send(T1035_telem_test_instance, spy_send_telemetry): - T1035_telem_test_instance.send() - expected_data = {'status': STATUS.value, - 'technique': 'T1035', - 'usage': USAGE.name} - assert spy_send_telemetry.data == expected_data - assert spy_send_telemetry.telem_category == 'attack' - - -@pytest.fixture -def T1064_telem_test_instance(): - return T1064Telem(STATUS, USAGE_STR) - - -def test_T1064_send(T1064_telem_test_instance, spy_send_telemetry): - T1064_telem_test_instance.send() - expected_data = {'status': STATUS.value, - 'technique': 'T1064', - 'usage': USAGE_STR} - assert spy_send_telemetry.data == expected_data - assert spy_send_telemetry.telem_category == 'attack' - - -@pytest.fixture -def T1105_telem_test_instance(): - return T1105Telem(STATUS, SRC_IP, DST_IP, FILENAME) - - -def test_T1105_send(T1105_telem_test_instance, spy_send_telemetry): - T1105_telem_test_instance.send() - expected_data = {'status': STATUS.value, - 'technique': 'T1105', - 'filename': FILENAME, - 'src': SRC_IP, - 'dst': DST_IP} - assert spy_send_telemetry.data == expected_data - assert spy_send_telemetry.telem_category == 'attack' - - -@pytest.fixture -def T1106_telem_test_instance(): - return T1106Telem(STATUS, USAGE) - - -def test_T1106_send(T1106_telem_test_instance, spy_send_telemetry): - T1106_telem_test_instance.send() - expected_data = {'status': STATUS.value, - 'technique': 'T1106', - 'usage': USAGE.name} - assert spy_send_telemetry.data == expected_data - assert spy_send_telemetry.telem_category == 'attack' - - -@pytest.fixture -def T1107_telem_test_instance(): - return T1107Telem(STATUS, PATH) - - -def test_T1107_send(T1107_telem_test_instance, spy_send_telemetry): - T1107_telem_test_instance.send() - expected_data = {'status': STATUS.value, - 'technique': 'T1107', - 'path': PATH} - assert spy_send_telemetry.data == expected_data - assert spy_send_telemetry.telem_category == 'attack' - - -@pytest.fixture -def T1129_telem_test_instance(): - return T1129Telem(STATUS, USAGE) - - -def test_T1129_send(T1129_telem_test_instance, spy_send_telemetry): - T1129_telem_test_instance.send() - expected_data = {'status': STATUS.value, - 'technique': 'T1129', - 'usage': USAGE.name} - assert spy_send_telemetry.data == expected_data - assert spy_send_telemetry.telem_category == 'attack' - - -@pytest.fixture -def T1197_telem_test_instance(): - return T1197Telem(STATUS, MACHINE, USAGE_STR) - - -def test_T1197_send(T1197_telem_test_instance, spy_send_telemetry): - T1197_telem_test_instance.send() - expected_data = {'machine': {'domain_name': MACHINE.domain_name, - 'ip_addr': MACHINE.ip_addr}, - 'status': STATUS.value, - 'technique': 'T1197', - 'usage': USAGE_STR} - assert spy_send_telemetry.data == expected_data - assert spy_send_telemetry.telem_category == 'attack' - - -@pytest.fixture -def T1222_telem_test_instance(): - return T1222Telem(STATUS, COMMAND, MACHINE) - - -def test_T1222_send(T1222_telem_test_instance, spy_send_telemetry): - T1222_telem_test_instance.send() - expected_data = {'machine': {'domain_name': MACHINE.domain_name, - 'ip_addr': MACHINE.ip_addr}, - 'status': STATUS.value, - 'technique': 'T1222', - 'command': COMMAND} - assert spy_send_telemetry.data == expected_data - assert spy_send_telemetry.telem_category == 'attack'