forked from p15670423/monkey
CR fixes
This commit is contained in:
parent
e815ac53da
commit
afbc13a06b
|
@ -7,6 +7,14 @@ from envs.monkey_zoo.blackbox.island_client.monkey_island_client import MonkeyIs
|
|||
MAX_ALLOWED_SINGLE_PAGE_TIME = timedelta(seconds=2)
|
||||
MAX_ALLOWED_TOTAL_TIME = timedelta(seconds=5)
|
||||
|
||||
REPORT_URLS = [
|
||||
"api/report/security",
|
||||
"api/attack/report",
|
||||
"api/report/zero_trust/findings",
|
||||
"api/report/zero_trust/principles",
|
||||
"api/report/zero_trust/pillars"
|
||||
]
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
|
@ -18,12 +26,17 @@ class PerformanceAnalyzer(Analyzer):
|
|||
|
||||
def analyze_test_results(self) -> bool:
|
||||
if not self.island_client.is_all_monkeys_dead():
|
||||
logger.info("Can't test report times since not all Monkeys have died.")
|
||||
return False
|
||||
raise RuntimeError("Can't test report times since not all Monkeys have died.")
|
||||
|
||||
total_time = timedelta()
|
||||
|
||||
self.island_client.clear_caches()
|
||||
|
||||
report_resource_to_response_time = {}
|
||||
|
||||
for url in REPORT_URLS:
|
||||
report_resource_to_response_time[url] = self.island_client.get_elapsed_for_get_request(url)
|
||||
|
||||
timings = self.island_client.time_all_report_pages()
|
||||
|
||||
single_page_time_less_then_max = True
|
||||
|
|
|
@ -113,13 +113,16 @@ class MonkeyIslandClient(object):
|
|||
report_resource_to_response_time = {}
|
||||
|
||||
for url in REPORT_URLS:
|
||||
response = self.requests.get(url)
|
||||
if response.ok:
|
||||
LOGGER.debug(f"Got ok for {url} content peek:\n{response.content[:120].strip()}")
|
||||
report_resource_to_response_time[url] = response.elapsed
|
||||
else:
|
||||
LOGGER.error(f"Trying to get {url} but got unexpected {str(response)}")
|
||||
# instead of raising for status, mark failed responses as maxtime
|
||||
report_resource_to_response_time[url] = timedelta.max()
|
||||
report_resource_to_response_time[url] = self.get_elapsed_for_get_request(url)
|
||||
|
||||
return report_resource_to_response_time
|
||||
|
||||
def get_elapsed_for_get_request(self, url):
|
||||
response = self.requests.get(url)
|
||||
if response.ok:
|
||||
LOGGER.debug(f"Got ok for {url} content peek:\n{response.content[:120].strip()}")
|
||||
return response.elapsed
|
||||
else:
|
||||
LOGGER.error(f"Trying to get {url} but got unexpected {str(response)}")
|
||||
# instead of raising for status, mark failed responses as maxtime
|
||||
return timedelta.max()
|
||||
|
|
|
@ -13,7 +13,6 @@ from envs.monkey_zoo.blackbox.tests.basic_test import BasicTest
|
|||
from envs.monkey_zoo.blackbox.log_handlers.test_logs_handler import TestLogsHandler
|
||||
|
||||
DEFAULT_TIMEOUT_SECONDS = 5*60
|
||||
PERFORMANCE_TIMEOUT_SECONDS = 10*60
|
||||
MACHINE_BOOTUP_WAIT_SECONDS = 30
|
||||
GCP_TEST_MACHINE_LIST = ['sshkeys-11', 'sshkeys-12', 'elastic-4', 'elastic-5', 'hadoop-2', 'hadoop-3', 'mssql-16',
|
||||
'mimikatz-14', 'mimikatz-15', 'struts2-23', 'struts2-24', 'tunneling-9', 'tunneling-10',
|
||||
|
@ -70,7 +69,7 @@ class TestMonkeyBlackbox(object):
|
|||
log_handler=log_handler).run()
|
||||
|
||||
@staticmethod
|
||||
def run_performance_test(island_client, conf_filename, test_name, timeout_in_seconds=DEFAULT_TIMEOUT_SECONDS):
|
||||
def run_performance_test(island_client, conf_filename, test_name, timeout_in_seconds):
|
||||
config_parser = IslandConfigParser(conf_filename)
|
||||
log_handler = TestLogsHandler(test_name, island_client, TestMonkeyBlackbox.get_log_dir_path())
|
||||
BasicTest(
|
||||
|
@ -141,4 +140,4 @@ class TestMonkeyBlackbox(object):
|
|||
island_client,
|
||||
"PERFORMANCE.conf",
|
||||
"test_report_performance",
|
||||
timeout_in_seconds=PERFORMANCE_TIMEOUT_SECONDS)
|
||||
timeout_in_seconds=10*60)
|
||||
|
|
Loading…
Reference in New Issue