diff --git a/envs/monkey_zoo/blackbox/island_client/monkey_island_client.py b/envs/monkey_zoo/blackbox/island_client/monkey_island_client.py index 1e6387283..4319b1eff 100644 --- a/envs/monkey_zoo/blackbox/island_client/monkey_island_client.py +++ b/envs/monkey_zoo/blackbox/island_client/monkey_island_client.py @@ -74,11 +74,38 @@ class MonkeyIslandClient(object): assert False @avoid_race_condition - def reset_env(self): - if self.requests.get("api", {"action": "reset"}).ok: - LOGGER.info("Resetting environment after the test.") + def reset_island(self): + self._reset_agent_configuration() + self._reset_simulation_data() + self._reset_credentials() + self._reset_island_mode() + + def _reset_agent_configuration(self): + if self.requests.post("api/reset-agent-configuration", data=None).ok: + LOGGER.info("Resetting agent-configuration after the test.") else: - LOGGER.error("Failed to reset the environment.") + LOGGER.error("Failed to reset agent configuration.") + assert False + + def _reset_simulation_data(self): + if self.requests.post("api/clear-simulation-data", data=None).ok: + LOGGER.info("Clearing simulation data.") + else: + LOGGER.error("Failed to clear simulation data") + assert False + + def _reset_credentials(self): + if self.requests.delete("api/propagation-credentials/configured-credentials").ok: + LOGGER.info("Resseting configured credentials after the test.") + else: + LOGGER.error("Failed to reset configured credentials") + assert False + + def _reset_island_mode(self): + if self.requests.post("api/island-mode", data='{"mode": "unset"}').ok: + LOGGER.info("Resseting island mode after the test.") + else: + LOGGER.error("Failed to reset island mode") assert False def find_monkeys_in_db(self, query): diff --git a/envs/monkey_zoo/blackbox/log_handlers/monkey_log.py b/envs/monkey_zoo/blackbox/log_handlers/monkey_log.py index f49b199a1..2086accbe 100644 --- a/envs/monkey_zoo/blackbox/log_handlers/monkey_log.py +++ b/envs/monkey_zoo/blackbox/log_handlers/monkey_log.py @@ -12,7 +12,7 @@ class MonkeyLog(object): self.log_dir_path = log_dir_path def download_log(self, island_client): - log = island_client.find_log_in_db({"monkey_id": ObjectId(self.monkey["id"])}) + log = island_client.find_log_in_db({"monkey_id": ObjectId(self.monkey["_id"])}) if not log: LOGGER.error("Log for monkey {} not found".format(self.monkey["ip_addresses"][0])) return False diff --git a/envs/monkey_zoo/blackbox/log_handlers/test_logs_handler.py b/envs/monkey_zoo/blackbox/log_handlers/test_logs_handler.py index 55a242bec..026bf917f 100644 --- a/envs/monkey_zoo/blackbox/log_handlers/test_logs_handler.py +++ b/envs/monkey_zoo/blackbox/log_handlers/test_logs_handler.py @@ -10,6 +10,8 @@ LOGGER = logging.getLogger(__name__) class TestLogsHandler(object): + __test__ = False + def __init__(self, test_name, island_client, log_dir_path): self.test_name = test_name self.island_client = island_client diff --git a/envs/monkey_zoo/blackbox/test_configurations/smb_pth.py b/envs/monkey_zoo/blackbox/test_configurations/smb_pth.py index bb1686385..84b386d21 100644 --- a/envs/monkey_zoo/blackbox/test_configurations/smb_pth.py +++ b/envs/monkey_zoo/blackbox/test_configurations/smb_pth.py @@ -34,7 +34,7 @@ def _add_tcp_ports(agent_configuration: AgentConfiguration) -> AgentConfiguratio agent_configuration = set_maximum_depth(noop_test_configuration.agent_configuration, 3) -agent_configuration = set_keep_tunnel_open_time(noop_test_configuration.agent_configuration, 20) +agent_configuration = set_keep_tunnel_open_time(agent_configuration, 20) agent_configuration = _add_exploiters(agent_configuration) agent_configuration = _add_subnets(agent_configuration) agent_configuration = _add_tcp_ports(agent_configuration) diff --git a/envs/monkey_zoo/blackbox/test_configurations/test_configuration.py b/envs/monkey_zoo/blackbox/test_configurations/test_configuration.py index 290af53b9..1bbfec7fd 100644 --- a/envs/monkey_zoo/blackbox/test_configurations/test_configuration.py +++ b/envs/monkey_zoo/blackbox/test_configurations/test_configuration.py @@ -7,5 +7,6 @@ from common.credentials import Credentials @dataclass class TestConfiguration: + __test__ = False agent_configuration: AgentConfiguration propagation_credentials: Tuple[Credentials, ...] diff --git a/envs/monkey_zoo/blackbox/tests/exploitation.py b/envs/monkey_zoo/blackbox/tests/exploitation.py index b4cf40eba..e794321f7 100644 --- a/envs/monkey_zoo/blackbox/tests/exploitation.py +++ b/envs/monkey_zoo/blackbox/tests/exploitation.py @@ -32,7 +32,7 @@ class ExploitationTest(BasicTest): self.wait_until_monkeys_die() self.wait_for_monkey_process_to_finish() self.parse_logs() - self.island_client.reset_env() + self.island_client.reset_island() def print_test_starting_info(self): LOGGER.info("Started {} test".format(self.name)) diff --git a/monkey/monkey_island/cc/services/utils/node_states.py b/monkey/monkey_island/cc/services/utils/node_states.py index cb8024bd2..a4b708bce 100644 --- a/monkey/monkey_island/cc/services/utils/node_states.py +++ b/monkey/monkey_island/cc/services/utils/node_states.py @@ -45,7 +45,9 @@ class NodeStates(Enum): @staticmethod def _is_state_from_keywords(group, keywords) -> bool: group_keywords = group.value.split("_") - return collections.Counter(group_keywords) == collections.Counter(keywords) + return collections.Counter(group_keywords) == collections.Counter( + [word.lower() for word in keywords] + ) class MultipleGroupsFoundException(Exception):