forked from p15670423/monkey
Use constants/literals for tests
This commit is contained in:
parent
a4603853a9
commit
15107eeea3
|
@ -5,7 +5,9 @@ from infection_monkey.model import VictimHost
|
||||||
from infection_monkey.telemetry.attack.t1197_telem import T1197Telem
|
from infection_monkey.telemetry.attack.t1197_telem import T1197Telem
|
||||||
|
|
||||||
|
|
||||||
MACHINE = VictimHost('127.0.0.1')
|
DOMAIN_NAME = 'domain-name'
|
||||||
|
IP = '127.0.0.1'
|
||||||
|
MACHINE = VictimHost(IP, DOMAIN_NAME)
|
||||||
STATUS = ScanStatus.USED
|
STATUS = ScanStatus.USED
|
||||||
USAGE_STR = '[Usage info]'
|
USAGE_STR = '[Usage info]'
|
||||||
|
|
||||||
|
@ -17,8 +19,8 @@ def T1197_telem_test_instance():
|
||||||
|
|
||||||
def test_T1197_send(T1197_telem_test_instance, spy_send_telemetry):
|
def test_T1197_send(T1197_telem_test_instance, spy_send_telemetry):
|
||||||
T1197_telem_test_instance.send()
|
T1197_telem_test_instance.send()
|
||||||
expected_data = {'machine': {'domain_name': MACHINE.domain_name,
|
expected_data = {'machine': {'domain_name': DOMAIN_NAME,
|
||||||
'ip_addr': MACHINE.ip_addr},
|
'ip_addr': IP},
|
||||||
'status': STATUS.value,
|
'status': STATUS.value,
|
||||||
'technique': 'T1197',
|
'technique': 'T1197',
|
||||||
'usage': USAGE_STR}
|
'usage': USAGE_STR}
|
||||||
|
|
|
@ -6,7 +6,9 @@ from infection_monkey.telemetry.attack.t1222_telem import T1222Telem
|
||||||
|
|
||||||
|
|
||||||
COMMAND = 'echo hi'
|
COMMAND = 'echo hi'
|
||||||
MACHINE = VictimHost('127.0.0.1')
|
DOMAIN_NAME = 'domain-name'
|
||||||
|
IP = '127.0.0.1'
|
||||||
|
MACHINE = VictimHost(IP, DOMAIN_NAME)
|
||||||
STATUS = ScanStatus.USED
|
STATUS = ScanStatus.USED
|
||||||
|
|
||||||
|
|
||||||
|
@ -17,8 +19,8 @@ def T1222_telem_test_instance():
|
||||||
|
|
||||||
def test_T1222_send(T1222_telem_test_instance, spy_send_telemetry):
|
def test_T1222_send(T1222_telem_test_instance, spy_send_telemetry):
|
||||||
T1222_telem_test_instance.send()
|
T1222_telem_test_instance.send()
|
||||||
expected_data = {'machine': {'domain_name': MACHINE.domain_name,
|
expected_data = {'machine': {'domain_name': DOMAIN_NAME,
|
||||||
'ip_addr': MACHINE.ip_addr},
|
'ip_addr': IP},
|
||||||
'status': STATUS.value,
|
'status': STATUS.value,
|
||||||
'technique': 'T1222',
|
'technique': 'T1222',
|
||||||
'command': COMMAND}
|
'command': COMMAND}
|
||||||
|
|
|
@ -5,7 +5,9 @@ from infection_monkey.model import VictimHost
|
||||||
from infection_monkey.telemetry.attack.victim_host_telem import VictimHostTelem
|
from infection_monkey.telemetry.attack.victim_host_telem import VictimHostTelem
|
||||||
|
|
||||||
|
|
||||||
MACHINE = VictimHost('127.0.0.1')
|
DOMAIN_NAME = 'domain-name'
|
||||||
|
IP = '127.0.0.1'
|
||||||
|
MACHINE = VictimHost(IP, DOMAIN_NAME)
|
||||||
STATUS = ScanStatus.USED
|
STATUS = ScanStatus.USED
|
||||||
TECHNIQUE = 'T9999'
|
TECHNIQUE = 'T9999'
|
||||||
|
|
||||||
|
@ -17,8 +19,8 @@ def victim_host_telem_test_instance():
|
||||||
|
|
||||||
def test_victim_host_telem_send(victim_host_telem_test_instance, spy_send_telemetry):
|
def test_victim_host_telem_send(victim_host_telem_test_instance, spy_send_telemetry):
|
||||||
victim_host_telem_test_instance.send()
|
victim_host_telem_test_instance.send()
|
||||||
expected_data = {'machine': {'domain_name': MACHINE.domain_name,
|
expected_data = {'machine': {'domain_name': DOMAIN_NAME,
|
||||||
'ip_addr': MACHINE.ip_addr},
|
'ip_addr': IP},
|
||||||
'status': STATUS.value,
|
'status': STATUS.value,
|
||||||
'technique': TECHNIQUE}
|
'technique': TECHNIQUE}
|
||||||
assert spy_send_telemetry.data == expected_data
|
assert spy_send_telemetry.data == expected_data
|
||||||
|
|
|
@ -5,11 +5,26 @@ from infection_monkey.model.host import VictimHost
|
||||||
from infection_monkey.telemetry.exploit_telem import ExploitTelem
|
from infection_monkey.telemetry.exploit_telem import ExploitTelem
|
||||||
|
|
||||||
|
|
||||||
HOSTNAME = "hostname"
|
|
||||||
DOMAIN_NAME = "domain-name"
|
DOMAIN_NAME = "domain-name"
|
||||||
IP = "0.0.0.0"
|
IP = "0.0.0.0"
|
||||||
HOST = VictimHost(IP, DOMAIN_NAME)
|
HOST = VictimHost(IP, DOMAIN_NAME)
|
||||||
|
HOST_AS_DICT = {'ip_addr': IP,
|
||||||
|
'domain_name': DOMAIN_NAME,
|
||||||
|
'os': {},
|
||||||
|
'services': {},
|
||||||
|
'icmp': False,
|
||||||
|
'monkey_exe': None,
|
||||||
|
'default_tunnel': None,
|
||||||
|
'default_server': None}
|
||||||
EXPLOITER = WmiExploiter(HOST)
|
EXPLOITER = WmiExploiter(HOST)
|
||||||
|
EXPLOITER_NAME = 'WmiExploiter'
|
||||||
|
EXPLOITER_INFO = {'display_name': WmiExploiter._EXPLOITED_SERVICE,
|
||||||
|
'started': '',
|
||||||
|
'finished': '',
|
||||||
|
'vulnerable_urls': [],
|
||||||
|
'vulnerable_ports': [],
|
||||||
|
'executed_cmds': []}
|
||||||
|
EXPLOITER_ATTEMPTS = []
|
||||||
RESULT = False
|
RESULT = False
|
||||||
|
|
||||||
|
|
||||||
|
@ -22,10 +37,10 @@ def test_exploit_telem_send(exploit_telem_test_instance, spy_send_telemetry):
|
||||||
exploit_telem_test_instance.send()
|
exploit_telem_test_instance.send()
|
||||||
expected_data = {
|
expected_data = {
|
||||||
"result": RESULT,
|
"result": RESULT,
|
||||||
"machine": HOST.as_dict(),
|
"machine": HOST_AS_DICT,
|
||||||
"exploiter": EXPLOITER.__class__.__name__,
|
"exploiter": EXPLOITER_NAME,
|
||||||
"info": EXPLOITER.exploit_info,
|
"info": EXPLOITER_INFO,
|
||||||
"attempts": EXPLOITER.exploit_attempts,
|
"attempts": EXPLOITER_ATTEMPTS,
|
||||||
}
|
}
|
||||||
assert spy_send_telemetry.data == expected_data
|
assert spy_send_telemetry.data == expected_data
|
||||||
assert spy_send_telemetry.telem_category == "exploit"
|
assert spy_send_telemetry.telem_category == "exploit"
|
||||||
|
|
|
@ -1,12 +1,21 @@
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
from common.data.post_breach_consts import POST_BREACH_JOB_SCHEDULING
|
||||||
from infection_monkey.post_breach.actions.schedule_jobs import ScheduleJobs
|
from infection_monkey.post_breach.actions.schedule_jobs import ScheduleJobs
|
||||||
|
from infection_monkey.post_breach.job_scheduling.linux_job_scheduling import \
|
||||||
|
get_linux_commands_to_schedule_jobs
|
||||||
|
from infection_monkey.post_breach.job_scheduling.windows_job_scheduling import \
|
||||||
|
get_windows_commands_to_schedule_jobs
|
||||||
from infection_monkey.telemetry.post_breach_telem import PostBreachTelem
|
from infection_monkey.telemetry.post_breach_telem import PostBreachTelem
|
||||||
|
from infection_monkey.utils.environment import is_windows_os
|
||||||
|
|
||||||
|
|
||||||
HOSTNAME = "hostname"
|
HOSTNAME = "hostname"
|
||||||
IP = "0.0.0.0"
|
IP = "0.0.0.0"
|
||||||
PBA = ScheduleJobs()
|
PBA = ScheduleJobs()
|
||||||
|
PBA_COMMAND = get_windows_commands_to_schedule_jobs() if is_windows_os() else\
|
||||||
|
' '.join(get_linux_commands_to_schedule_jobs())
|
||||||
|
PBA_NAME = POST_BREACH_JOB_SCHEDULING
|
||||||
RESULT = False
|
RESULT = False
|
||||||
|
|
||||||
|
|
||||||
|
@ -19,9 +28,9 @@ def post_breach_telem_test_instance(monkeypatch):
|
||||||
def test_post_breach_telem_send(post_breach_telem_test_instance, spy_send_telemetry):
|
def test_post_breach_telem_send(post_breach_telem_test_instance, spy_send_telemetry):
|
||||||
post_breach_telem_test_instance.send()
|
post_breach_telem_test_instance.send()
|
||||||
expected_data = {
|
expected_data = {
|
||||||
"command": PBA.command,
|
"command": PBA_COMMAND,
|
||||||
"result": RESULT,
|
"result": RESULT,
|
||||||
"name": PBA.name,
|
"name": PBA_NAME,
|
||||||
"hostname": HOSTNAME,
|
"hostname": HOSTNAME,
|
||||||
"ip": IP,
|
"ip": IP,
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,15 @@ from infection_monkey.model.host import VictimHost
|
||||||
DOMAIN_NAME = "domain-name"
|
DOMAIN_NAME = "domain-name"
|
||||||
IP = "0.0.0.0"
|
IP = "0.0.0.0"
|
||||||
HOST = VictimHost(IP, DOMAIN_NAME)
|
HOST = VictimHost(IP, DOMAIN_NAME)
|
||||||
|
HOST_AS_DICT = {'ip_addr': IP,
|
||||||
|
'domain_name': DOMAIN_NAME,
|
||||||
|
'os': {},
|
||||||
|
'services': {},
|
||||||
|
'icmp': False,
|
||||||
|
'monkey_exe': None,
|
||||||
|
'default_tunnel': None,
|
||||||
|
'default_server': None}
|
||||||
|
HOST_SERVICES = {}
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
|
@ -15,6 +24,6 @@ def scan_telem_test_instance():
|
||||||
|
|
||||||
def test_scan_telem_send(scan_telem_test_instance, spy_send_telemetry):
|
def test_scan_telem_send(scan_telem_test_instance, spy_send_telemetry):
|
||||||
scan_telem_test_instance.send()
|
scan_telem_test_instance.send()
|
||||||
expected_data = {"machine": HOST.as_dict(), "service_count": len(HOST.services)}
|
expected_data = {"machine": HOST_AS_DICT, "service_count": len(HOST_SERVICES)}
|
||||||
assert spy_send_telemetry.data == expected_data
|
assert spy_send_telemetry.data == expected_data
|
||||||
assert spy_send_telemetry.telem_category == "scan"
|
assert spy_send_telemetry.telem_category == "scan"
|
||||||
|
|
Loading…
Reference in New Issue