From 788641b7d6c6bfcd40395d9e366343cb1b4c01d4 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Wed, 2 Feb 2022 13:33:30 -0500 Subject: [PATCH] UT: Fix test_principle_service tests And modify data in test_pillar_service.py accordingly --- .../test_common/example_finding_data.py | 43 +------------------ .../zero_trust/test_common/finding_data.py | 13 ------ .../zero_trust_report/test_pillar_service.py | 14 +++--- .../test_principle_service.py | 14 ++---- 4 files changed, 12 insertions(+), 72 deletions(-) diff --git a/monkey/tests/unit_tests/monkey_island/cc/services/zero_trust/test_common/example_finding_data.py b/monkey/tests/unit_tests/monkey_island/cc/services/zero_trust/test_common/example_finding_data.py index 31cd709b9..5f40f9a42 100644 --- a/monkey/tests/unit_tests/monkey_island/cc/services/zero_trust/test_common/example_finding_data.py +++ b/monkey/tests/unit_tests/monkey_island/cc/services/zero_trust/test_common/example_finding_data.py @@ -1,35 +1,17 @@ from tests.unit_tests.monkey_island.cc.services.zero_trust.test_common.finding_data import ( get_monkey_finding_dto, - get_scoutsuite_finding_dto, ) from common.common_consts import zero_trust_consts def save_example_findings(): - # devices passed = 1 - _save_finding_with_status( - "scoutsuite", - zero_trust_consts.TEST_ENDPOINT_SECURITY_EXISTS, - zero_trust_consts.STATUS_PASSED, - ) - # devices passed = 2 - _save_finding_with_status( - "scoutsuite", - zero_trust_consts.TEST_ENDPOINT_SECURITY_EXISTS, - zero_trust_consts.STATUS_PASSED, - ) # devices failed = 1 _save_finding_with_status( "monkey", zero_trust_consts.TEST_ENDPOINT_SECURITY_EXISTS, zero_trust_consts.STATUS_FAILED ) # people verify = 1 # networks verify = 1 - _save_finding_with_status( - "scoutsuite", zero_trust_consts.TEST_SCHEDULED_EXECUTION, zero_trust_consts.STATUS_VERIFY - ) - # people verify = 2 - # networks verify = 2 _save_finding_with_status( "monkey", zero_trust_consts.TEST_SCHEDULED_EXECUTION, zero_trust_consts.STATUS_VERIFY ) @@ -39,24 +21,12 @@ def save_example_findings(): ) # data failed 2 _save_finding_with_status( - "scoutsuite", - zero_trust_consts.TEST_SCOUTSUITE_UNENCRYPTED_DATA, - zero_trust_consts.STATUS_FAILED, + "monkey", zero_trust_consts.TEST_DATA_ENDPOINT_HTTP, zero_trust_consts.STATUS_FAILED ) # data failed 3 _save_finding_with_status( "monkey", zero_trust_consts.TEST_DATA_ENDPOINT_HTTP, zero_trust_consts.STATUS_FAILED ) - # data failed 4 - _save_finding_with_status( - "monkey", zero_trust_consts.TEST_DATA_ENDPOINT_HTTP, zero_trust_consts.STATUS_FAILED - ) - # data failed 5 - _save_finding_with_status( - "scoutsuite", - zero_trust_consts.TEST_SCOUTSUITE_UNENCRYPTED_DATA, - zero_trust_consts.STATUS_FAILED, - ) # data verify 1 _save_finding_with_status( "monkey", zero_trust_consts.TEST_DATA_ENDPOINT_HTTP, zero_trust_consts.STATUS_VERIFY @@ -65,19 +35,10 @@ def save_example_findings(): _save_finding_with_status( "monkey", zero_trust_consts.TEST_DATA_ENDPOINT_HTTP, zero_trust_consts.STATUS_VERIFY ) - # data passed 1 - _save_finding_with_status( - "scoutsuite", - zero_trust_consts.TEST_SCOUTSUITE_UNENCRYPTED_DATA, - zero_trust_consts.STATUS_PASSED, - ) def _save_finding_with_status(finding_type: str, test: str, status: str): - if finding_type == "scoutsuite": - finding = get_scoutsuite_finding_dto() - else: - finding = get_monkey_finding_dto() + finding = get_monkey_finding_dto() finding.test = test finding.status = status finding.save() diff --git a/monkey/tests/unit_tests/monkey_island/cc/services/zero_trust/test_common/finding_data.py b/monkey/tests/unit_tests/monkey_island/cc/services/zero_trust/test_common/finding_data.py index 838035cbf..0304b8523 100644 --- a/monkey/tests/unit_tests/monkey_island/cc/services/zero_trust/test_common/finding_data.py +++ b/monkey/tests/unit_tests/monkey_island/cc/services/zero_trust/test_common/finding_data.py @@ -1,27 +1,14 @@ from tests.unit_tests.monkey_island.cc.services.zero_trust.test_common.monkey_finding_data import ( get_monkey_details_dto, ) -from tests.unit_tests.monkey_island.cc.services.zero_trust.test_common.scoutsuite_finding_data import ( # noqa: E501 - get_scoutsuite_details_dto, -) from common.common_consts.zero_trust_consts import ( STATUS_FAILED, STATUS_PASSED, TEST_ENDPOINT_SECURITY_EXISTS, - TEST_SCOUTSUITE_SERVICE_SECURITY, ) from monkey_island.cc.models.zero_trust.finding import Finding from monkey_island.cc.models.zero_trust.monkey_finding import MonkeyFinding -from monkey_island.cc.models.zero_trust.scoutsuite_finding import ScoutSuiteFinding - - -def get_scoutsuite_finding_dto() -> Finding: - scoutsuite_details = get_scoutsuite_details_dto() - scoutsuite_details.save() - return ScoutSuiteFinding( - test=TEST_SCOUTSUITE_SERVICE_SECURITY, status=STATUS_FAILED, details=scoutsuite_details - ) def get_monkey_finding_dto() -> Finding: diff --git a/monkey/tests/unit_tests/monkey_island/cc/services/zero_trust/zero_trust_report/test_pillar_service.py b/monkey/tests/unit_tests/monkey_island/cc/services/zero_trust/zero_trust_report/test_pillar_service.py index 1be9f2fcb..53eca4f49 100644 --- a/monkey/tests/unit_tests/monkey_island/cc/services/zero_trust/zero_trust_report/test_pillar_service.py +++ b/monkey/tests/unit_tests/monkey_island/cc/services/zero_trust/zero_trust_report/test_pillar_service.py @@ -29,16 +29,16 @@ def test_get_pillars_grades(): def _get_expected_pillar_grades() -> List[dict]: return [ { - zero_trust_consts.STATUS_FAILED: 5, + zero_trust_consts.STATUS_FAILED: 3, zero_trust_consts.STATUS_VERIFY: 2, - zero_trust_consts.STATUS_PASSED: 1, - # 2 different tests of DATA pillar were executed in _save_findings() - zero_trust_consts.STATUS_UNEXECUTED: _get_cnt_of_tests_in_pillar(DATA) - 2, + zero_trust_consts.STATUS_PASSED: 0, + # 1 test of DATA pillar was executed in _save_findings() + zero_trust_consts.STATUS_UNEXECUTED: _get_cnt_of_tests_in_pillar(DATA) - 1, "pillar": "Data", }, { zero_trust_consts.STATUS_FAILED: 0, - zero_trust_consts.STATUS_VERIFY: 2, + zero_trust_consts.STATUS_VERIFY: 1, zero_trust_consts.STATUS_PASSED: 0, # 1 test of PEOPLE pillar were executed in _save_findings() zero_trust_consts.STATUS_UNEXECUTED: _get_cnt_of_tests_in_pillar(PEOPLE) - 1, @@ -46,7 +46,7 @@ def _get_expected_pillar_grades() -> List[dict]: }, { zero_trust_consts.STATUS_FAILED: 0, - zero_trust_consts.STATUS_VERIFY: 2, + zero_trust_consts.STATUS_VERIFY: 1, zero_trust_consts.STATUS_PASSED: 0, # 1 different tests of NETWORKS pillar were executed in _save_findings() zero_trust_consts.STATUS_UNEXECUTED: _get_cnt_of_tests_in_pillar(NETWORKS) - 1, @@ -55,7 +55,7 @@ def _get_expected_pillar_grades() -> List[dict]: { zero_trust_consts.STATUS_FAILED: 1, zero_trust_consts.STATUS_VERIFY: 0, - zero_trust_consts.STATUS_PASSED: 2, + zero_trust_consts.STATUS_PASSED: 0, # 1 different tests of DEVICES pillar were executed in _save_findings() zero_trust_consts.STATUS_UNEXECUTED: _get_cnt_of_tests_in_pillar(DEVICES) - 1, "pillar": "Devices", diff --git a/monkey/tests/unit_tests/monkey_island/cc/services/zero_trust/zero_trust_report/test_principle_service.py b/monkey/tests/unit_tests/monkey_island/cc/services/zero_trust/zero_trust_report/test_principle_service.py index 7bd2b01c7..c1639b9d8 100644 --- a/monkey/tests/unit_tests/monkey_island/cc/services/zero_trust/zero_trust_report/test_principle_service.py +++ b/monkey/tests/unit_tests/monkey_island/cc/services/zero_trust/zero_trust_report/test_principle_service.py @@ -1,7 +1,6 @@ import pytest from tests.unit_tests.monkey_island.cc.services.zero_trust.test_common.finding_data import ( get_monkey_finding_dto, - get_scoutsuite_finding_dto, ) from common.common_consts import zero_trust_consts @@ -13,10 +12,9 @@ EXPECTED_DICT = { "test_pillar1": [ { "principle": "Test principle description2", - "status": zero_trust_consts.STATUS_FAILED, + "status": zero_trust_consts.STATUS_PASSED, "tests": [ {"status": zero_trust_consts.STATUS_PASSED, "test": "You ran a test2"}, - {"status": zero_trust_consts.STATUS_FAILED, "test": "You ran a test3"}, ], } ], @@ -28,10 +26,9 @@ EXPECTED_DICT = { }, { "principle": "Test principle description2", - "status": zero_trust_consts.STATUS_FAILED, + "status": zero_trust_consts.STATUS_PASSED, "tests": [ {"status": zero_trust_consts.STATUS_PASSED, "test": "You ran a test2"}, - {"status": zero_trust_consts.STATUS_FAILED, "test": "You ran a test3"}, ], }, ], @@ -46,7 +43,7 @@ def test_get_principles_status(): principles_to_tests = { "network_policies": ["segmentation"], - "endpoint_security": ["tunneling", "scoutsuite_service_security"], + "endpoint_security": ["tunneling"], } zero_trust_consts.PRINCIPLES_TO_TESTS = principles_to_tests @@ -65,7 +62,6 @@ def test_get_principles_status(): tests_map = { "segmentation": {"explanation": "You ran a test1"}, "tunneling": {"explanation": "You ran a test2"}, - "scoutsuite_service_security": {"explanation": "You ran a test3"}, } zero_trust_consts.TESTS_MAP = tests_map @@ -77,10 +73,6 @@ def test_get_principles_status(): monkey_finding.test = "tunneling" monkey_finding.save() - scoutsuite_finding = get_scoutsuite_finding_dto() - scoutsuite_finding.test = "scoutsuite_service_security" - scoutsuite_finding.save() - expected = dict(EXPECTED_DICT) # new mutable result = PrincipleService.get_principles_status()