diff --git a/monkey/tests/unit_tests/infection_monkey/exploit/test_host_exploiter.py b/monkey/tests/unit_tests/infection_monkey/exploit/test_host_exploiter.py deleted file mode 100644 index 47d2cb106..000000000 --- a/monkey/tests/unit_tests/infection_monkey/exploit/test_host_exploiter.py +++ /dev/null @@ -1,100 +0,0 @@ -import threading -from ipaddress import IPv4Address -from unittest.mock import MagicMock -from uuid import UUID - -import pytest - -from common.agent_events import ExploitationEvent, PropagationEvent -from common.event_queue import IAgentEventQueue -from infection_monkey.exploit import IAgentBinaryRepository -from infection_monkey.exploit.HostExploiter import HostExploiter -from infection_monkey.model import VictimHost -from infection_monkey.telemetry.messengers.i_telemetry_messenger import ITelemetryMessenger - -AGENT_ID = UUID("faaca0a2-6270-46dc-b8c9-592880d6d5cd") -TARGET = IPv4Address("10.10.10.2") -VICTIM_HOST = VictimHost("10.10.10.1") - - -class FakeExploiter(HostExploiter): - _EXPLOITED_SERVICE = "Fake" - - def _exploit_host(self): - pass - - -@pytest.fixture(autouse=True) -def mock_get_agent_id(monkeypatch): - monkeypatch.setattr("infection_monkey.utils.ids", lambda _: AGENT_ID) - - -@pytest.fixture -def agent_binary_repository() -> IAgentBinaryRepository: - return MagicMock(spec=IAgentBinaryRepository) - - -@pytest.fixture -def agent_event_queue() -> IAgentEventQueue: - return MagicMock(spec=IAgentEventQueue) - - -@pytest.fixture -def telemetry_messenger() -> ITelemetryMessenger: - return MagicMock(spec=ITelemetryMessenger) - - -@pytest.fixture -def exploiter() -> HostExploiter: - return FakeExploiter() - - -def test_publish_exploitation_event__uses_exploiter_name_by_default( - exploiter: HostExploiter, - agent_binary_repository: IAgentBinaryRepository, - agent_event_queue: IAgentEventQueue, - telemetry_messenger: ITelemetryMessenger, -): - exploiter.exploit_host( - host=VICTIM_HOST, - servers=[], - current_depth=0, - telemetry_messenger=telemetry_messenger, - agent_event_queue=agent_event_queue, - agent_binary_repository=agent_binary_repository, - options={}, - interrupt=threading.Event(), - ) - exploiter._publish_exploitation_event(target=str(TARGET), exploitation_success=True) - expected_event = ExploitationEvent( - source=AGENT_ID, - target=TARGET, - success=True, - exploiter_name=FakeExploiter.__name__, - ) - - assert agent_event_queue.publish.called_with(expected_event) # type: ignore[attr-defined] - - -def test_publish_propagation_event__uses_exploiter_name_by_default( - exploiter: HostExploiter, - agent_binary_repository: IAgentBinaryRepository, - agent_event_queue: IAgentEventQueue, - telemetry_messenger: ITelemetryMessenger, -): - exploiter.exploit_host( - host=VICTIM_HOST, - servers=[], - current_depth=0, - telemetry_messenger=telemetry_messenger, - agent_event_queue=agent_event_queue, - agent_binary_repository=agent_binary_repository, - options={}, - interrupt=threading.Event(), - ) - exploiter._publish_propagation_event(target=str(TARGET), propagation_success=True) - expected_event = PropagationEvent( - source=AGENT_ID, target=TARGET, success=True, exploiter_name=FakeExploiter.__name__ - ) - - assert agent_event_queue.publish.called_with(expected_event) # type: ignore[attr-defined]