diff --git a/monkey/monkey_island/cc/agent_event_handlers/handle_ping_scan_event.py b/monkey/monkey_island/cc/agent_event_handlers/handle_ping_scan_event.py index fe7a2f150..939261524 100644 --- a/monkey/monkey_island/cc/agent_event_handlers/handle_ping_scan_event.py +++ b/monkey/monkey_island/cc/agent_event_handlers/handle_ping_scan_event.py @@ -26,6 +26,9 @@ class handle_ping_scan_event: self._node_repository = node_repository def __call__(self, event: PingScanEvent): + if not event.response_received: + return + try: dest_machine = self._get_destination_machine(event) self._update_destination_machine(dest_machine, event) diff --git a/monkey/tests/unit_tests/monkey_island/cc/agent_event_handlers/test_handle_ping_scan_event.py b/monkey/tests/unit_tests/monkey_island/cc/agent_event_handlers/test_handle_ping_scan_event.py index d8c11f91e..7d1d0889d 100644 --- a/monkey/tests/unit_tests/monkey_island/cc/agent_event_handlers/test_handle_ping_scan_event.py +++ b/monkey/tests/unit_tests/monkey_island/cc/agent_event_handlers/test_handle_ping_scan_event.py @@ -234,3 +234,18 @@ def test_handle_scan_data__node_not_upserted_if_machine_storageerror( handler(EVENT) assert not node_repository.upsert_communication.called + + +def test_handle_scan_data__failed_ping( + handler: handle_ping_scan_event, + machine_repository: IMachineRepository, + node_repository: INodeRepository, +): + machine_repository.upsert_machine = MagicMock(side_effect=StorageError) + machine_repository.get_machine_by_id = MagicMock(side_effect=machine_from_id) + machine_repository.get_machines_by_ip = MagicMock(side_effect=machines_from_ip) + + handler(EVENT_NO_RESPONSE) + + assert not node_repository.upsert_communication.called + assert not machine_repository.upsert_machine.called