From 4c795343d0a4347a6b820cfd9e24c211cb06bb30 Mon Sep 17 00:00:00 2001 From: Kekoa Kaaikala Date: Wed, 7 Sep 2022 15:15:35 +0000 Subject: [PATCH] Agent: Fix maximum_depth_reached() --- monkey/infection_monkey/master/automated_master.py | 2 +- monkey/infection_monkey/monkey.py | 2 +- monkey/infection_monkey/utils/propagation.py | 10 +++++++++- .../infection_monkey/utils/test_propagation.py | 6 +++--- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/monkey/infection_monkey/master/automated_master.py b/monkey/infection_monkey/master/automated_master.py index 6959e6bf1..dcda3de2c 100644 --- a/monkey/infection_monkey/master/automated_master.py +++ b/monkey/infection_monkey/master/automated_master.py @@ -176,7 +176,7 @@ class AutomatedMaster(IMaster): current_depth = self._current_depth if self._current_depth is not None else 0 logger.info(f"Current depth is {current_depth}") - if maximum_depth_reached(config.propagation.maximum_depth, current_depth): + if not maximum_depth_reached(config.propagation.maximum_depth, current_depth): self._propagator.propagate(config.propagation, current_depth, self._servers, self._stop) else: logger.info("Skipping propagation: maximum depth reached") diff --git a/monkey/infection_monkey/monkey.py b/monkey/infection_monkey/monkey.py index d2ea3db0b..3d895d5a1 100644 --- a/monkey/infection_monkey/monkey.py +++ b/monkey/infection_monkey/monkey.py @@ -189,7 +189,7 @@ class InfectionMonkey: client_disconnect_timeout=config.keep_tunnel_open_time, ) - if maximum_depth_reached(config.propagation.maximum_depth, self._current_depth): + if not maximum_depth_reached(config.propagation.maximum_depth, self._current_depth): self._relay.start() StateTelem(is_done=False, version=get_version()).send() diff --git a/monkey/infection_monkey/utils/propagation.py b/monkey/infection_monkey/utils/propagation.py index 2da2e7bee..9b9f0a03d 100644 --- a/monkey/infection_monkey/utils/propagation.py +++ b/monkey/infection_monkey/utils/propagation.py @@ -1,2 +1,10 @@ def maximum_depth_reached(maximum_depth: int, current_depth: int) -> bool: - return maximum_depth > current_depth + """ + Return whether or not the current depth has eclipsed the maximum depth. + Values are nonnegative. Depth should increase from zero. + + :param maximum_depth: The maximum depth. + :param current_depth: The current depth. + :return: True if the current depth has reached the maximum depth, otherwise False. + """ + return current_depth >= maximum_depth diff --git a/monkey/tests/unit_tests/infection_monkey/utils/test_propagation.py b/monkey/tests/unit_tests/infection_monkey/utils/test_propagation.py index 19b2c18b5..77cbbc2ff 100644 --- a/monkey/tests/unit_tests/infection_monkey/utils/test_propagation.py +++ b/monkey/tests/unit_tests/infection_monkey/utils/test_propagation.py @@ -5,18 +5,18 @@ def test_maximum_depth_reached__current_less_than_max(): maximum_depth = 2 current_depth = 1 - assert maximum_depth_reached(maximum_depth, current_depth) is True + assert maximum_depth_reached(maximum_depth, current_depth) is False def test_maximum_depth_reached__current_greater_than_max(): maximum_depth = 2 current_depth = 3 - assert maximum_depth_reached(maximum_depth, current_depth) is False + assert maximum_depth_reached(maximum_depth, current_depth) is True def test_maximum_depth_reached__current_equal_to_max(): maximum_depth = 2 current_depth = maximum_depth - assert maximum_depth_reached(maximum_depth, current_depth) is False + assert maximum_depth_reached(maximum_depth, current_depth) is True