From 63fcea39ed43ead337c0505ff1dab31e8e4e33df Mon Sep 17 00:00:00 2001 From: Kekoa Kaaikala Date: Wed, 21 Sep 2022 20:19:20 +0000 Subject: [PATCH] Agent: Fix VictimHost mypy issues --- monkey/infection_monkey/model/host.py | 2 +- .../infection_monkey/model/test_victim_host_factory.py | 4 ++-- .../infection_monkey/telemetry/test_exploit_telem.py | 7 ++++--- .../infection_monkey/telemetry/test_scan_telem.py | 5 +++-- .../cc/services/edge/test_displayed_edge_service.py | 2 +- 5 files changed, 11 insertions(+), 9 deletions(-) diff --git a/monkey/infection_monkey/model/host.py b/monkey/infection_monkey/model/host.py index 170e6fea4..acf57dcdf 100644 --- a/monkey/infection_monkey/model/host.py +++ b/monkey/infection_monkey/model/host.py @@ -10,7 +10,7 @@ class VictimHost(object): self.os: Dict[str, Any] = {} self.services: Dict[str, Any] = {} self.icmp = False - self.default_server = None + self.default_server = "" def as_dict(self): return self.__dict__ diff --git a/monkey/tests/unit_tests/infection_monkey/model/test_victim_host_factory.py b/monkey/tests/unit_tests/infection_monkey/model/test_victim_host_factory.py index a584dca17..20db6ac51 100644 --- a/monkey/tests/unit_tests/infection_monkey/model/test_victim_host_factory.py +++ b/monkey/tests/unit_tests/infection_monkey/model/test_victim_host_factory.py @@ -13,7 +13,7 @@ def mock_get_interface_to_target(monkeypatch): def test_factory_no_tunnel(): factory = VictimHostFactory(island_ip="192.168.56.1", island_port="5000", on_island=False) - network_address = NetworkAddress("192.168.56.2", None) + network_address = NetworkAddress("192.168.56.2", "") victim = factory.build_victim_host(network_address) @@ -49,4 +49,4 @@ def test_factory_no_default_server(): victim = factory.build_victim_host(network_address) - assert victim.default_server is None + assert not victim.default_server diff --git a/monkey/tests/unit_tests/infection_monkey/telemetry/test_exploit_telem.py b/monkey/tests/unit_tests/infection_monkey/telemetry/test_exploit_telem.py index c38c1d130..8b9f2ead7 100644 --- a/monkey/tests/unit_tests/infection_monkey/telemetry/test_exploit_telem.py +++ b/monkey/tests/unit_tests/infection_monkey/telemetry/test_exploit_telem.py @@ -1,11 +1,12 @@ import json +from typing import Iterable import pytest from infection_monkey.exploit.sshexec import SSHExploiter +from infection_monkey.i_puppet.i_puppet import ExploiterResultData from infection_monkey.model.host import VictimHost from infection_monkey.telemetry.exploit_telem import ExploitTelem -from monkey.infection_monkey.i_puppet.i_puppet import ExploiterResultData DOMAIN_NAME = "domain-name" IP = "0.0.0.0" @@ -16,7 +17,7 @@ HOST_AS_DICT = { "os": {}, "services": {}, "icmp": False, - "default_server": None, + "default_server": "", } EXPLOITER_NAME = "SSHExploiter" EXPLOITER_INFO = { @@ -27,7 +28,7 @@ EXPLOITER_INFO = { "vulnerable_ports": [], "executed_cmds": [], } -EXPLOITER_ATTEMPTS = [] +EXPLOITER_ATTEMPTS: Iterable = [] RESULT = False OS_LINUX = "linux" ERROR_MSG = "failed because yolo" diff --git a/monkey/tests/unit_tests/infection_monkey/telemetry/test_scan_telem.py b/monkey/tests/unit_tests/infection_monkey/telemetry/test_scan_telem.py index 837b7d782..12ca1354e 100644 --- a/monkey/tests/unit_tests/infection_monkey/telemetry/test_scan_telem.py +++ b/monkey/tests/unit_tests/infection_monkey/telemetry/test_scan_telem.py @@ -1,4 +1,5 @@ import json +from typing import Any, Dict import pytest @@ -14,9 +15,9 @@ HOST_AS_DICT = { "os": {}, "services": {}, "icmp": False, - "default_server": None, + "default_server": "", } -HOST_SERVICES = {} +HOST_SERVICES: Dict[str, Any] = {} @pytest.fixture diff --git a/monkey/tests/unit_tests/monkey_island/cc/services/edge/test_displayed_edge_service.py b/monkey/tests/unit_tests/monkey_island/cc/services/edge/test_displayed_edge_service.py index 90195f980..a4e1ceaec 100644 --- a/monkey/tests/unit_tests/monkey_island/cc/services/edge/test_displayed_edge_service.py +++ b/monkey/tests/unit_tests/monkey_island/cc/services/edge/test_displayed_edge_service.py @@ -18,7 +18,7 @@ SCAN_DATA_MOCK = [ }, }, "monkey_exe": None, - "default_server": None, + "default_server": "", }, } ]