Merge pull request #2118 from guardicore/2092-fix-bb-tests

2092 fix bb tests
This commit is contained in:
Mike Salvatore 2022-07-26 13:43:32 -04:00 committed by GitHub
commit 48e34049fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 40 additions and 8 deletions

View File

@ -74,11 +74,38 @@ class MonkeyIslandClient(object):
assert False assert False
@avoid_race_condition @avoid_race_condition
def reset_env(self): def reset_island(self):
if self.requests.get("api", {"action": "reset"}).ok: self._reset_agent_configuration()
LOGGER.info("Resetting environment after the test.") 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: 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 assert False
def find_monkeys_in_db(self, query): def find_monkeys_in_db(self, query):

View File

@ -12,7 +12,7 @@ class MonkeyLog(object):
self.log_dir_path = log_dir_path self.log_dir_path = log_dir_path
def download_log(self, island_client): 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: if not log:
LOGGER.error("Log for monkey {} not found".format(self.monkey["ip_addresses"][0])) LOGGER.error("Log for monkey {} not found".format(self.monkey["ip_addresses"][0]))
return False return False

View File

@ -10,6 +10,8 @@ LOGGER = logging.getLogger(__name__)
class TestLogsHandler(object): class TestLogsHandler(object):
__test__ = False
def __init__(self, test_name, island_client, log_dir_path): def __init__(self, test_name, island_client, log_dir_path):
self.test_name = test_name self.test_name = test_name
self.island_client = island_client self.island_client = island_client

View File

@ -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_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_exploiters(agent_configuration)
agent_configuration = _add_subnets(agent_configuration) agent_configuration = _add_subnets(agent_configuration)
agent_configuration = _add_tcp_ports(agent_configuration) agent_configuration = _add_tcp_ports(agent_configuration)

View File

@ -7,5 +7,6 @@ from common.credentials import Credentials
@dataclass @dataclass
class TestConfiguration: class TestConfiguration:
__test__ = False
agent_configuration: AgentConfiguration agent_configuration: AgentConfiguration
propagation_credentials: Tuple[Credentials, ...] propagation_credentials: Tuple[Credentials, ...]

View File

@ -32,7 +32,7 @@ class ExploitationTest(BasicTest):
self.wait_until_monkeys_die() self.wait_until_monkeys_die()
self.wait_for_monkey_process_to_finish() self.wait_for_monkey_process_to_finish()
self.parse_logs() self.parse_logs()
self.island_client.reset_env() self.island_client.reset_island()
def print_test_starting_info(self): def print_test_starting_info(self):
LOGGER.info("Started {} test".format(self.name)) LOGGER.info("Started {} test".format(self.name))

View File

@ -45,7 +45,9 @@ class NodeStates(Enum):
@staticmethod @staticmethod
def _is_state_from_keywords(group, keywords) -> bool: def _is_state_from_keywords(group, keywords) -> bool:
group_keywords = group.value.split("_") 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): class MultipleGroupsFoundException(Exception):