diff --git a/monkey/monkey_island/cc/services/infection_lifecycle.py b/monkey/monkey_island/cc/services/infection_lifecycle.py index e766d2e14..510e3deb6 100644 --- a/monkey/monkey_island/cc/services/infection_lifecycle.py +++ b/monkey/monkey_island/cc/services/infection_lifecycle.py @@ -33,11 +33,13 @@ def _is_monkey_marked_dead(monkey: Monkey) -> bool: def _is_monkey_killed_manually(monkey: Monkey) -> bool: + kill_timestamp = AgentControls.objects.first().last_stop_all + if kill_timestamp is None: + return False if monkey.has_parent(): launch_timestamp = monkey.get_parent().launch_time else: launch_timestamp = monkey.launch_time - kill_timestamp = AgentControls.objects.first().last_stop_all return int(kill_timestamp) >= int(launch_timestamp) diff --git a/monkey/tests/unit_tests/monkey_island/cc/services/test_infection_lifecycle.py b/monkey/tests/unit_tests/monkey_island/cc/services/test_infection_lifecycle.py index 389bf3c9c..4d4c229c8 100644 --- a/monkey/tests/unit_tests/monkey_island/cc/services/test_infection_lifecycle.py +++ b/monkey/tests/unit_tests/monkey_island/cc/services/test_infection_lifecycle.py @@ -30,6 +30,14 @@ def create_monkey(launch_time): return monkey +@pytest.mark.usefixtures("uses_database") +def test_should_agent_die_no_kill_event(): + monkey = create_monkey(launch_time=3) + kill_event = AgentControls() + kill_event.save() + assert not should_agent_die(monkey.guid) + + def create_kill_event(event_time): kill_event = AgentControls(last_stop_all=event_time) kill_event.save()