From fa21336ff259696ac78110f3f8631853ae54c87d Mon Sep 17 00:00:00 2001 From: Shreya Date: Fri, 16 Apr 2021 12:53:51 +0530 Subject: [PATCH 01/16] Move all unit test files to a separate directory --- monkey/{ => tests}/common/cloud/aws/test_aws_instance.py | 0 monkey/{ => tests}/common/cloud/aws/test_aws_service.py | 0 monkey/{ => tests}/common/cloud/azure/test_azure_instance.py | 0 monkey/{ => tests}/common/cloud/gcp/test_gcp_instance.py | 0 monkey/{ => tests}/common/network/test_network_utils.py | 0 monkey/{ => tests}/common/network/test_segmentation_utils.py | 0 monkey/{ => tests}/common/utils/test_shellcode_obfuscator.py | 0 .../{ => tests}/infection_monkey/exploit/tests/test_zerologon.py | 0 .../exploit/tests/zerologon_utils/test_vuln_assessment.py | 0 monkey/{ => tests}/infection_monkey/exploit/tools/test_helpers.py | 0 monkey/{ => tests}/infection_monkey/exploit/tools/test_payload.py | 0 .../infection_monkey/model/test_victim_host_generator.py | 0 .../infection_monkey/network/test_postgresql_finger.py | 0 .../post_breach/tests/actions/test_users_custom_pba.py | 0 .../system_info/windows_cred_collector/test_pypykatz_handler.py | 0 .../infection_monkey/telemetry/tests/attack/test_attack_telem.py | 0 .../infection_monkey/telemetry/tests/attack/test_t1005_telem.py | 0 .../infection_monkey/telemetry/tests/attack/test_t1035_telem.py | 0 .../infection_monkey/telemetry/tests/attack/test_t1064_telem.py | 0 .../infection_monkey/telemetry/tests/attack/test_t1105_telem.py | 0 .../infection_monkey/telemetry/tests/attack/test_t1106_telem.py | 0 .../infection_monkey/telemetry/tests/attack/test_t1107_telem.py | 0 .../infection_monkey/telemetry/tests/attack/test_t1129_telem.py | 0 .../infection_monkey/telemetry/tests/attack/test_t1197_telem.py | 0 .../infection_monkey/telemetry/tests/attack/test_t1222_telem.py | 0 .../infection_monkey/telemetry/tests/attack/test_usage_telem.py | 0 .../telemetry/tests/attack/test_victim_host_telem.py | 0 .../infection_monkey/telemetry/tests/test_exploit_telem.py | 0 .../infection_monkey/telemetry/tests/test_post_breach_telem.py | 0 .../infection_monkey/telemetry/tests/test_scan_telem.py | 0 .../infection_monkey/telemetry/tests/test_state_telem.py | 0 .../infection_monkey/telemetry/tests/test_system_info_telem.py | 0 .../infection_monkey/telemetry/tests/test_trace_telem.py | 0 .../infection_monkey/telemetry/tests/test_tunnel_telem.py | 0 monkey/{ => tests}/infection_monkey/utils/linux/test_users.py | 0 monkey/{ => tests}/infection_monkey/utils/plugins/test_plugin.py | 0 .../infection_monkey/utils/test_auto_new_user_factory.py | 0 .../{ => tests}/monkey_island/cc/environment/test_environment.py | 0 .../monkey_island/cc/environment/test_environment_config.py | 0 .../{ => tests}/monkey_island/cc/environment/test_user_creds.py | 0 monkey/{ => tests}/monkey_island/cc/models/test_monkey.py | 0 monkey/{ => tests}/monkey_island/cc/models/test_telem.py | 0 .../{ => tests}/monkey_island/cc/models/zero_trust/test_event.py | 0 .../monkey_island/cc/models/zero_trust/test_monkey_finding.py | 0 .../monkey_island/cc/models/zero_trust/test_scoutsuite_finding.py | 0 monkey/{ => tests}/monkey_island/cc/resources/test_bootloader.py | 0 .../monkey_island/cc/server_utils/test_island_logger.py | 0 .../monkey_island/cc/services/attack/test_mitre_api_interface.py | 0 .../monkey_island/cc/services/edge/test_displayed_edge_service.py | 0 .../monkey_island/cc/services/edge/test_edge_service.py | 0 .../monkey_island/cc/services/reporting/test_report.py | 0 .../test_environment_telemetry_processing.py | 0 .../test_system_info_telemetry_dispatcher.py | 0 .../cc/services/telemetry/processing/test_post_breach.py | 0 .../telemetry/zero_trust_checks/test_segmentation_checks.py | 0 .../monkey_island/cc/services/test_bootloader_service.py | 0 .../{ => tests}/monkey_island/cc/services/test_representations.py | 0 .../monkey_island/cc/services/tests/reporting/test_report.py | 0 monkey/{ => tests}/monkey_island/cc/services/tests/test_config.py | 0 .../monkey_island/cc/services/utils/test_node_states.py | 0 .../zero_trust/monkey_findings/test_monkey_zt_details_service.py | 0 .../zero_trust/monkey_findings/test_monkey_zt_finding_service.py | 0 .../zero_trust/scoutsuite/data_parsing/test_rule_parser.py | 0 .../zero_trust/scoutsuite/test_scoutsuite_auth_service.py | 0 .../zero_trust/scoutsuite/test_scoutsuite_rule_service.py | 0 .../zero_trust/scoutsuite/test_scoutsuite_zt_finding_service.py | 0 .../services/zero_trust/zero_trust_report/test_finding_service.py | 0 .../services/zero_trust/zero_trust_report/test_pillar_service.py | 0 .../zero_trust/zero_trust_report/test_principle_service.py | 0 monkey/{ => tests}/monkey_island/cc/test_consts.py | 0 monkey/{ => tests}/monkey_island/cc/test_encryptor.py | 0 71 files changed, 0 insertions(+), 0 deletions(-) rename monkey/{ => tests}/common/cloud/aws/test_aws_instance.py (100%) rename monkey/{ => tests}/common/cloud/aws/test_aws_service.py (100%) rename monkey/{ => tests}/common/cloud/azure/test_azure_instance.py (100%) rename monkey/{ => tests}/common/cloud/gcp/test_gcp_instance.py (100%) rename monkey/{ => tests}/common/network/test_network_utils.py (100%) rename monkey/{ => tests}/common/network/test_segmentation_utils.py (100%) rename monkey/{ => tests}/common/utils/test_shellcode_obfuscator.py (100%) rename monkey/{ => tests}/infection_monkey/exploit/tests/test_zerologon.py (100%) rename monkey/{ => tests}/infection_monkey/exploit/tests/zerologon_utils/test_vuln_assessment.py (100%) rename monkey/{ => tests}/infection_monkey/exploit/tools/test_helpers.py (100%) rename monkey/{ => tests}/infection_monkey/exploit/tools/test_payload.py (100%) rename monkey/{ => tests}/infection_monkey/model/test_victim_host_generator.py (100%) rename monkey/{ => tests}/infection_monkey/network/test_postgresql_finger.py (100%) rename monkey/{ => tests}/infection_monkey/post_breach/tests/actions/test_users_custom_pba.py (100%) rename monkey/{ => tests}/infection_monkey/system_info/windows_cred_collector/test_pypykatz_handler.py (100%) rename monkey/{ => tests}/infection_monkey/telemetry/tests/attack/test_attack_telem.py (100%) rename monkey/{ => tests}/infection_monkey/telemetry/tests/attack/test_t1005_telem.py (100%) rename monkey/{ => tests}/infection_monkey/telemetry/tests/attack/test_t1035_telem.py (100%) rename monkey/{ => tests}/infection_monkey/telemetry/tests/attack/test_t1064_telem.py (100%) rename monkey/{ => tests}/infection_monkey/telemetry/tests/attack/test_t1105_telem.py (100%) rename monkey/{ => tests}/infection_monkey/telemetry/tests/attack/test_t1106_telem.py (100%) rename monkey/{ => tests}/infection_monkey/telemetry/tests/attack/test_t1107_telem.py (100%) rename monkey/{ => tests}/infection_monkey/telemetry/tests/attack/test_t1129_telem.py (100%) rename monkey/{ => tests}/infection_monkey/telemetry/tests/attack/test_t1197_telem.py (100%) rename monkey/{ => tests}/infection_monkey/telemetry/tests/attack/test_t1222_telem.py (100%) rename monkey/{ => tests}/infection_monkey/telemetry/tests/attack/test_usage_telem.py (100%) rename monkey/{ => tests}/infection_monkey/telemetry/tests/attack/test_victim_host_telem.py (100%) rename monkey/{ => tests}/infection_monkey/telemetry/tests/test_exploit_telem.py (100%) rename monkey/{ => tests}/infection_monkey/telemetry/tests/test_post_breach_telem.py (100%) rename monkey/{ => tests}/infection_monkey/telemetry/tests/test_scan_telem.py (100%) rename monkey/{ => tests}/infection_monkey/telemetry/tests/test_state_telem.py (100%) rename monkey/{ => tests}/infection_monkey/telemetry/tests/test_system_info_telem.py (100%) rename monkey/{ => tests}/infection_monkey/telemetry/tests/test_trace_telem.py (100%) rename monkey/{ => tests}/infection_monkey/telemetry/tests/test_tunnel_telem.py (100%) rename monkey/{ => tests}/infection_monkey/utils/linux/test_users.py (100%) rename monkey/{ => tests}/infection_monkey/utils/plugins/test_plugin.py (100%) rename monkey/{ => tests}/infection_monkey/utils/test_auto_new_user_factory.py (100%) rename monkey/{ => tests}/monkey_island/cc/environment/test_environment.py (100%) rename monkey/{ => tests}/monkey_island/cc/environment/test_environment_config.py (100%) rename monkey/{ => tests}/monkey_island/cc/environment/test_user_creds.py (100%) rename monkey/{ => tests}/monkey_island/cc/models/test_monkey.py (100%) rename monkey/{ => tests}/monkey_island/cc/models/test_telem.py (100%) rename monkey/{ => tests}/monkey_island/cc/models/zero_trust/test_event.py (100%) rename monkey/{ => tests}/monkey_island/cc/models/zero_trust/test_monkey_finding.py (100%) rename monkey/{ => tests}/monkey_island/cc/models/zero_trust/test_scoutsuite_finding.py (100%) rename monkey/{ => tests}/monkey_island/cc/resources/test_bootloader.py (100%) rename monkey/{ => tests}/monkey_island/cc/server_utils/test_island_logger.py (100%) rename monkey/{ => tests}/monkey_island/cc/services/attack/test_mitre_api_interface.py (100%) rename monkey/{ => tests}/monkey_island/cc/services/edge/test_displayed_edge_service.py (100%) rename monkey/{ => tests}/monkey_island/cc/services/edge/test_edge_service.py (100%) rename monkey/{ => tests}/monkey_island/cc/services/reporting/test_report.py (100%) rename monkey/{ => tests}/monkey_island/cc/services/telemetry/processing/system_info_collectors/test_environment_telemetry_processing.py (100%) rename monkey/{ => tests}/monkey_island/cc/services/telemetry/processing/system_info_collectors/test_system_info_telemetry_dispatcher.py (100%) rename monkey/{ => tests}/monkey_island/cc/services/telemetry/processing/test_post_breach.py (100%) rename monkey/{ => tests}/monkey_island/cc/services/telemetry/zero_trust_checks/test_segmentation_checks.py (100%) rename monkey/{ => tests}/monkey_island/cc/services/test_bootloader_service.py (100%) rename monkey/{ => tests}/monkey_island/cc/services/test_representations.py (100%) rename monkey/{ => tests}/monkey_island/cc/services/tests/reporting/test_report.py (100%) rename monkey/{ => tests}/monkey_island/cc/services/tests/test_config.py (100%) rename monkey/{ => tests}/monkey_island/cc/services/utils/test_node_states.py (100%) rename monkey/{ => tests}/monkey_island/cc/services/zero_trust/monkey_findings/test_monkey_zt_details_service.py (100%) rename monkey/{ => tests}/monkey_island/cc/services/zero_trust/monkey_findings/test_monkey_zt_finding_service.py (100%) rename monkey/{ => tests}/monkey_island/cc/services/zero_trust/scoutsuite/data_parsing/test_rule_parser.py (100%) rename monkey/{ => tests}/monkey_island/cc/services/zero_trust/scoutsuite/test_scoutsuite_auth_service.py (100%) rename monkey/{ => tests}/monkey_island/cc/services/zero_trust/scoutsuite/test_scoutsuite_rule_service.py (100%) rename monkey/{ => tests}/monkey_island/cc/services/zero_trust/scoutsuite/test_scoutsuite_zt_finding_service.py (100%) rename monkey/{ => tests}/monkey_island/cc/services/zero_trust/zero_trust_report/test_finding_service.py (100%) rename monkey/{ => tests}/monkey_island/cc/services/zero_trust/zero_trust_report/test_pillar_service.py (100%) rename monkey/{ => tests}/monkey_island/cc/services/zero_trust/zero_trust_report/test_principle_service.py (100%) rename monkey/{ => tests}/monkey_island/cc/test_consts.py (100%) rename monkey/{ => tests}/monkey_island/cc/test_encryptor.py (100%) diff --git a/monkey/common/cloud/aws/test_aws_instance.py b/monkey/tests/common/cloud/aws/test_aws_instance.py similarity index 100% rename from monkey/common/cloud/aws/test_aws_instance.py rename to monkey/tests/common/cloud/aws/test_aws_instance.py diff --git a/monkey/common/cloud/aws/test_aws_service.py b/monkey/tests/common/cloud/aws/test_aws_service.py similarity index 100% rename from monkey/common/cloud/aws/test_aws_service.py rename to monkey/tests/common/cloud/aws/test_aws_service.py diff --git a/monkey/common/cloud/azure/test_azure_instance.py b/monkey/tests/common/cloud/azure/test_azure_instance.py similarity index 100% rename from monkey/common/cloud/azure/test_azure_instance.py rename to monkey/tests/common/cloud/azure/test_azure_instance.py diff --git a/monkey/common/cloud/gcp/test_gcp_instance.py b/monkey/tests/common/cloud/gcp/test_gcp_instance.py similarity index 100% rename from monkey/common/cloud/gcp/test_gcp_instance.py rename to monkey/tests/common/cloud/gcp/test_gcp_instance.py diff --git a/monkey/common/network/test_network_utils.py b/monkey/tests/common/network/test_network_utils.py similarity index 100% rename from monkey/common/network/test_network_utils.py rename to monkey/tests/common/network/test_network_utils.py diff --git a/monkey/common/network/test_segmentation_utils.py b/monkey/tests/common/network/test_segmentation_utils.py similarity index 100% rename from monkey/common/network/test_segmentation_utils.py rename to monkey/tests/common/network/test_segmentation_utils.py diff --git a/monkey/common/utils/test_shellcode_obfuscator.py b/monkey/tests/common/utils/test_shellcode_obfuscator.py similarity index 100% rename from monkey/common/utils/test_shellcode_obfuscator.py rename to monkey/tests/common/utils/test_shellcode_obfuscator.py diff --git a/monkey/infection_monkey/exploit/tests/test_zerologon.py b/monkey/tests/infection_monkey/exploit/tests/test_zerologon.py similarity index 100% rename from monkey/infection_monkey/exploit/tests/test_zerologon.py rename to monkey/tests/infection_monkey/exploit/tests/test_zerologon.py diff --git a/monkey/infection_monkey/exploit/tests/zerologon_utils/test_vuln_assessment.py b/monkey/tests/infection_monkey/exploit/tests/zerologon_utils/test_vuln_assessment.py similarity index 100% rename from monkey/infection_monkey/exploit/tests/zerologon_utils/test_vuln_assessment.py rename to monkey/tests/infection_monkey/exploit/tests/zerologon_utils/test_vuln_assessment.py diff --git a/monkey/infection_monkey/exploit/tools/test_helpers.py b/monkey/tests/infection_monkey/exploit/tools/test_helpers.py similarity index 100% rename from monkey/infection_monkey/exploit/tools/test_helpers.py rename to monkey/tests/infection_monkey/exploit/tools/test_helpers.py diff --git a/monkey/infection_monkey/exploit/tools/test_payload.py b/monkey/tests/infection_monkey/exploit/tools/test_payload.py similarity index 100% rename from monkey/infection_monkey/exploit/tools/test_payload.py rename to monkey/tests/infection_monkey/exploit/tools/test_payload.py diff --git a/monkey/infection_monkey/model/test_victim_host_generator.py b/monkey/tests/infection_monkey/model/test_victim_host_generator.py similarity index 100% rename from monkey/infection_monkey/model/test_victim_host_generator.py rename to monkey/tests/infection_monkey/model/test_victim_host_generator.py diff --git a/monkey/infection_monkey/network/test_postgresql_finger.py b/monkey/tests/infection_monkey/network/test_postgresql_finger.py similarity index 100% rename from monkey/infection_monkey/network/test_postgresql_finger.py rename to monkey/tests/infection_monkey/network/test_postgresql_finger.py diff --git a/monkey/infection_monkey/post_breach/tests/actions/test_users_custom_pba.py b/monkey/tests/infection_monkey/post_breach/tests/actions/test_users_custom_pba.py similarity index 100% rename from monkey/infection_monkey/post_breach/tests/actions/test_users_custom_pba.py rename to monkey/tests/infection_monkey/post_breach/tests/actions/test_users_custom_pba.py diff --git a/monkey/infection_monkey/system_info/windows_cred_collector/test_pypykatz_handler.py b/monkey/tests/infection_monkey/system_info/windows_cred_collector/test_pypykatz_handler.py similarity index 100% rename from monkey/infection_monkey/system_info/windows_cred_collector/test_pypykatz_handler.py rename to monkey/tests/infection_monkey/system_info/windows_cred_collector/test_pypykatz_handler.py diff --git a/monkey/infection_monkey/telemetry/tests/attack/test_attack_telem.py b/monkey/tests/infection_monkey/telemetry/tests/attack/test_attack_telem.py similarity index 100% rename from monkey/infection_monkey/telemetry/tests/attack/test_attack_telem.py rename to monkey/tests/infection_monkey/telemetry/tests/attack/test_attack_telem.py diff --git a/monkey/infection_monkey/telemetry/tests/attack/test_t1005_telem.py b/monkey/tests/infection_monkey/telemetry/tests/attack/test_t1005_telem.py similarity index 100% rename from monkey/infection_monkey/telemetry/tests/attack/test_t1005_telem.py rename to monkey/tests/infection_monkey/telemetry/tests/attack/test_t1005_telem.py diff --git a/monkey/infection_monkey/telemetry/tests/attack/test_t1035_telem.py b/monkey/tests/infection_monkey/telemetry/tests/attack/test_t1035_telem.py similarity index 100% rename from monkey/infection_monkey/telemetry/tests/attack/test_t1035_telem.py rename to monkey/tests/infection_monkey/telemetry/tests/attack/test_t1035_telem.py diff --git a/monkey/infection_monkey/telemetry/tests/attack/test_t1064_telem.py b/monkey/tests/infection_monkey/telemetry/tests/attack/test_t1064_telem.py similarity index 100% rename from monkey/infection_monkey/telemetry/tests/attack/test_t1064_telem.py rename to monkey/tests/infection_monkey/telemetry/tests/attack/test_t1064_telem.py diff --git a/monkey/infection_monkey/telemetry/tests/attack/test_t1105_telem.py b/monkey/tests/infection_monkey/telemetry/tests/attack/test_t1105_telem.py similarity index 100% rename from monkey/infection_monkey/telemetry/tests/attack/test_t1105_telem.py rename to monkey/tests/infection_monkey/telemetry/tests/attack/test_t1105_telem.py diff --git a/monkey/infection_monkey/telemetry/tests/attack/test_t1106_telem.py b/monkey/tests/infection_monkey/telemetry/tests/attack/test_t1106_telem.py similarity index 100% rename from monkey/infection_monkey/telemetry/tests/attack/test_t1106_telem.py rename to monkey/tests/infection_monkey/telemetry/tests/attack/test_t1106_telem.py diff --git a/monkey/infection_monkey/telemetry/tests/attack/test_t1107_telem.py b/monkey/tests/infection_monkey/telemetry/tests/attack/test_t1107_telem.py similarity index 100% rename from monkey/infection_monkey/telemetry/tests/attack/test_t1107_telem.py rename to monkey/tests/infection_monkey/telemetry/tests/attack/test_t1107_telem.py diff --git a/monkey/infection_monkey/telemetry/tests/attack/test_t1129_telem.py b/monkey/tests/infection_monkey/telemetry/tests/attack/test_t1129_telem.py similarity index 100% rename from monkey/infection_monkey/telemetry/tests/attack/test_t1129_telem.py rename to monkey/tests/infection_monkey/telemetry/tests/attack/test_t1129_telem.py diff --git a/monkey/infection_monkey/telemetry/tests/attack/test_t1197_telem.py b/monkey/tests/infection_monkey/telemetry/tests/attack/test_t1197_telem.py similarity index 100% rename from monkey/infection_monkey/telemetry/tests/attack/test_t1197_telem.py rename to monkey/tests/infection_monkey/telemetry/tests/attack/test_t1197_telem.py diff --git a/monkey/infection_monkey/telemetry/tests/attack/test_t1222_telem.py b/monkey/tests/infection_monkey/telemetry/tests/attack/test_t1222_telem.py similarity index 100% rename from monkey/infection_monkey/telemetry/tests/attack/test_t1222_telem.py rename to monkey/tests/infection_monkey/telemetry/tests/attack/test_t1222_telem.py diff --git a/monkey/infection_monkey/telemetry/tests/attack/test_usage_telem.py b/monkey/tests/infection_monkey/telemetry/tests/attack/test_usage_telem.py similarity index 100% rename from monkey/infection_monkey/telemetry/tests/attack/test_usage_telem.py rename to monkey/tests/infection_monkey/telemetry/tests/attack/test_usage_telem.py diff --git a/monkey/infection_monkey/telemetry/tests/attack/test_victim_host_telem.py b/monkey/tests/infection_monkey/telemetry/tests/attack/test_victim_host_telem.py similarity index 100% rename from monkey/infection_monkey/telemetry/tests/attack/test_victim_host_telem.py rename to monkey/tests/infection_monkey/telemetry/tests/attack/test_victim_host_telem.py diff --git a/monkey/infection_monkey/telemetry/tests/test_exploit_telem.py b/monkey/tests/infection_monkey/telemetry/tests/test_exploit_telem.py similarity index 100% rename from monkey/infection_monkey/telemetry/tests/test_exploit_telem.py rename to monkey/tests/infection_monkey/telemetry/tests/test_exploit_telem.py diff --git a/monkey/infection_monkey/telemetry/tests/test_post_breach_telem.py b/monkey/tests/infection_monkey/telemetry/tests/test_post_breach_telem.py similarity index 100% rename from monkey/infection_monkey/telemetry/tests/test_post_breach_telem.py rename to monkey/tests/infection_monkey/telemetry/tests/test_post_breach_telem.py diff --git a/monkey/infection_monkey/telemetry/tests/test_scan_telem.py b/monkey/tests/infection_monkey/telemetry/tests/test_scan_telem.py similarity index 100% rename from monkey/infection_monkey/telemetry/tests/test_scan_telem.py rename to monkey/tests/infection_monkey/telemetry/tests/test_scan_telem.py diff --git a/monkey/infection_monkey/telemetry/tests/test_state_telem.py b/monkey/tests/infection_monkey/telemetry/tests/test_state_telem.py similarity index 100% rename from monkey/infection_monkey/telemetry/tests/test_state_telem.py rename to monkey/tests/infection_monkey/telemetry/tests/test_state_telem.py diff --git a/monkey/infection_monkey/telemetry/tests/test_system_info_telem.py b/monkey/tests/infection_monkey/telemetry/tests/test_system_info_telem.py similarity index 100% rename from monkey/infection_monkey/telemetry/tests/test_system_info_telem.py rename to monkey/tests/infection_monkey/telemetry/tests/test_system_info_telem.py diff --git a/monkey/infection_monkey/telemetry/tests/test_trace_telem.py b/monkey/tests/infection_monkey/telemetry/tests/test_trace_telem.py similarity index 100% rename from monkey/infection_monkey/telemetry/tests/test_trace_telem.py rename to monkey/tests/infection_monkey/telemetry/tests/test_trace_telem.py diff --git a/monkey/infection_monkey/telemetry/tests/test_tunnel_telem.py b/monkey/tests/infection_monkey/telemetry/tests/test_tunnel_telem.py similarity index 100% rename from monkey/infection_monkey/telemetry/tests/test_tunnel_telem.py rename to monkey/tests/infection_monkey/telemetry/tests/test_tunnel_telem.py diff --git a/monkey/infection_monkey/utils/linux/test_users.py b/monkey/tests/infection_monkey/utils/linux/test_users.py similarity index 100% rename from monkey/infection_monkey/utils/linux/test_users.py rename to monkey/tests/infection_monkey/utils/linux/test_users.py diff --git a/monkey/infection_monkey/utils/plugins/test_plugin.py b/monkey/tests/infection_monkey/utils/plugins/test_plugin.py similarity index 100% rename from monkey/infection_monkey/utils/plugins/test_plugin.py rename to monkey/tests/infection_monkey/utils/plugins/test_plugin.py diff --git a/monkey/infection_monkey/utils/test_auto_new_user_factory.py b/monkey/tests/infection_monkey/utils/test_auto_new_user_factory.py similarity index 100% rename from monkey/infection_monkey/utils/test_auto_new_user_factory.py rename to monkey/tests/infection_monkey/utils/test_auto_new_user_factory.py diff --git a/monkey/monkey_island/cc/environment/test_environment.py b/monkey/tests/monkey_island/cc/environment/test_environment.py similarity index 100% rename from monkey/monkey_island/cc/environment/test_environment.py rename to monkey/tests/monkey_island/cc/environment/test_environment.py diff --git a/monkey/monkey_island/cc/environment/test_environment_config.py b/monkey/tests/monkey_island/cc/environment/test_environment_config.py similarity index 100% rename from monkey/monkey_island/cc/environment/test_environment_config.py rename to monkey/tests/monkey_island/cc/environment/test_environment_config.py diff --git a/monkey/monkey_island/cc/environment/test_user_creds.py b/monkey/tests/monkey_island/cc/environment/test_user_creds.py similarity index 100% rename from monkey/monkey_island/cc/environment/test_user_creds.py rename to monkey/tests/monkey_island/cc/environment/test_user_creds.py diff --git a/monkey/monkey_island/cc/models/test_monkey.py b/monkey/tests/monkey_island/cc/models/test_monkey.py similarity index 100% rename from monkey/monkey_island/cc/models/test_monkey.py rename to monkey/tests/monkey_island/cc/models/test_monkey.py diff --git a/monkey/monkey_island/cc/models/test_telem.py b/monkey/tests/monkey_island/cc/models/test_telem.py similarity index 100% rename from monkey/monkey_island/cc/models/test_telem.py rename to monkey/tests/monkey_island/cc/models/test_telem.py diff --git a/monkey/monkey_island/cc/models/zero_trust/test_event.py b/monkey/tests/monkey_island/cc/models/zero_trust/test_event.py similarity index 100% rename from monkey/monkey_island/cc/models/zero_trust/test_event.py rename to monkey/tests/monkey_island/cc/models/zero_trust/test_event.py diff --git a/monkey/monkey_island/cc/models/zero_trust/test_monkey_finding.py b/monkey/tests/monkey_island/cc/models/zero_trust/test_monkey_finding.py similarity index 100% rename from monkey/monkey_island/cc/models/zero_trust/test_monkey_finding.py rename to monkey/tests/monkey_island/cc/models/zero_trust/test_monkey_finding.py diff --git a/monkey/monkey_island/cc/models/zero_trust/test_scoutsuite_finding.py b/monkey/tests/monkey_island/cc/models/zero_trust/test_scoutsuite_finding.py similarity index 100% rename from monkey/monkey_island/cc/models/zero_trust/test_scoutsuite_finding.py rename to monkey/tests/monkey_island/cc/models/zero_trust/test_scoutsuite_finding.py diff --git a/monkey/monkey_island/cc/resources/test_bootloader.py b/monkey/tests/monkey_island/cc/resources/test_bootloader.py similarity index 100% rename from monkey/monkey_island/cc/resources/test_bootloader.py rename to monkey/tests/monkey_island/cc/resources/test_bootloader.py diff --git a/monkey/monkey_island/cc/server_utils/test_island_logger.py b/monkey/tests/monkey_island/cc/server_utils/test_island_logger.py similarity index 100% rename from monkey/monkey_island/cc/server_utils/test_island_logger.py rename to monkey/tests/monkey_island/cc/server_utils/test_island_logger.py diff --git a/monkey/monkey_island/cc/services/attack/test_mitre_api_interface.py b/monkey/tests/monkey_island/cc/services/attack/test_mitre_api_interface.py similarity index 100% rename from monkey/monkey_island/cc/services/attack/test_mitre_api_interface.py rename to monkey/tests/monkey_island/cc/services/attack/test_mitre_api_interface.py diff --git a/monkey/monkey_island/cc/services/edge/test_displayed_edge_service.py b/monkey/tests/monkey_island/cc/services/edge/test_displayed_edge_service.py similarity index 100% rename from monkey/monkey_island/cc/services/edge/test_displayed_edge_service.py rename to monkey/tests/monkey_island/cc/services/edge/test_displayed_edge_service.py diff --git a/monkey/monkey_island/cc/services/edge/test_edge_service.py b/monkey/tests/monkey_island/cc/services/edge/test_edge_service.py similarity index 100% rename from monkey/monkey_island/cc/services/edge/test_edge_service.py rename to monkey/tests/monkey_island/cc/services/edge/test_edge_service.py diff --git a/monkey/monkey_island/cc/services/reporting/test_report.py b/monkey/tests/monkey_island/cc/services/reporting/test_report.py similarity index 100% rename from monkey/monkey_island/cc/services/reporting/test_report.py rename to monkey/tests/monkey_island/cc/services/reporting/test_report.py diff --git a/monkey/monkey_island/cc/services/telemetry/processing/system_info_collectors/test_environment_telemetry_processing.py b/monkey/tests/monkey_island/cc/services/telemetry/processing/system_info_collectors/test_environment_telemetry_processing.py similarity index 100% rename from monkey/monkey_island/cc/services/telemetry/processing/system_info_collectors/test_environment_telemetry_processing.py rename to monkey/tests/monkey_island/cc/services/telemetry/processing/system_info_collectors/test_environment_telemetry_processing.py diff --git a/monkey/monkey_island/cc/services/telemetry/processing/system_info_collectors/test_system_info_telemetry_dispatcher.py b/monkey/tests/monkey_island/cc/services/telemetry/processing/system_info_collectors/test_system_info_telemetry_dispatcher.py similarity index 100% rename from monkey/monkey_island/cc/services/telemetry/processing/system_info_collectors/test_system_info_telemetry_dispatcher.py rename to monkey/tests/monkey_island/cc/services/telemetry/processing/system_info_collectors/test_system_info_telemetry_dispatcher.py diff --git a/monkey/monkey_island/cc/services/telemetry/processing/test_post_breach.py b/monkey/tests/monkey_island/cc/services/telemetry/processing/test_post_breach.py similarity index 100% rename from monkey/monkey_island/cc/services/telemetry/processing/test_post_breach.py rename to monkey/tests/monkey_island/cc/services/telemetry/processing/test_post_breach.py diff --git a/monkey/monkey_island/cc/services/telemetry/zero_trust_checks/test_segmentation_checks.py b/monkey/tests/monkey_island/cc/services/telemetry/zero_trust_checks/test_segmentation_checks.py similarity index 100% rename from monkey/monkey_island/cc/services/telemetry/zero_trust_checks/test_segmentation_checks.py rename to monkey/tests/monkey_island/cc/services/telemetry/zero_trust_checks/test_segmentation_checks.py diff --git a/monkey/monkey_island/cc/services/test_bootloader_service.py b/monkey/tests/monkey_island/cc/services/test_bootloader_service.py similarity index 100% rename from monkey/monkey_island/cc/services/test_bootloader_service.py rename to monkey/tests/monkey_island/cc/services/test_bootloader_service.py diff --git a/monkey/monkey_island/cc/services/test_representations.py b/monkey/tests/monkey_island/cc/services/test_representations.py similarity index 100% rename from monkey/monkey_island/cc/services/test_representations.py rename to monkey/tests/monkey_island/cc/services/test_representations.py diff --git a/monkey/monkey_island/cc/services/tests/reporting/test_report.py b/monkey/tests/monkey_island/cc/services/tests/reporting/test_report.py similarity index 100% rename from monkey/monkey_island/cc/services/tests/reporting/test_report.py rename to monkey/tests/monkey_island/cc/services/tests/reporting/test_report.py diff --git a/monkey/monkey_island/cc/services/tests/test_config.py b/monkey/tests/monkey_island/cc/services/tests/test_config.py similarity index 100% rename from monkey/monkey_island/cc/services/tests/test_config.py rename to monkey/tests/monkey_island/cc/services/tests/test_config.py diff --git a/monkey/monkey_island/cc/services/utils/test_node_states.py b/monkey/tests/monkey_island/cc/services/utils/test_node_states.py similarity index 100% rename from monkey/monkey_island/cc/services/utils/test_node_states.py rename to monkey/tests/monkey_island/cc/services/utils/test_node_states.py diff --git a/monkey/monkey_island/cc/services/zero_trust/monkey_findings/test_monkey_zt_details_service.py b/monkey/tests/monkey_island/cc/services/zero_trust/monkey_findings/test_monkey_zt_details_service.py similarity index 100% rename from monkey/monkey_island/cc/services/zero_trust/monkey_findings/test_monkey_zt_details_service.py rename to monkey/tests/monkey_island/cc/services/zero_trust/monkey_findings/test_monkey_zt_details_service.py diff --git a/monkey/monkey_island/cc/services/zero_trust/monkey_findings/test_monkey_zt_finding_service.py b/monkey/tests/monkey_island/cc/services/zero_trust/monkey_findings/test_monkey_zt_finding_service.py similarity index 100% rename from monkey/monkey_island/cc/services/zero_trust/monkey_findings/test_monkey_zt_finding_service.py rename to monkey/tests/monkey_island/cc/services/zero_trust/monkey_findings/test_monkey_zt_finding_service.py diff --git a/monkey/monkey_island/cc/services/zero_trust/scoutsuite/data_parsing/test_rule_parser.py b/monkey/tests/monkey_island/cc/services/zero_trust/scoutsuite/data_parsing/test_rule_parser.py similarity index 100% rename from monkey/monkey_island/cc/services/zero_trust/scoutsuite/data_parsing/test_rule_parser.py rename to monkey/tests/monkey_island/cc/services/zero_trust/scoutsuite/data_parsing/test_rule_parser.py diff --git a/monkey/monkey_island/cc/services/zero_trust/scoutsuite/test_scoutsuite_auth_service.py b/monkey/tests/monkey_island/cc/services/zero_trust/scoutsuite/test_scoutsuite_auth_service.py similarity index 100% rename from monkey/monkey_island/cc/services/zero_trust/scoutsuite/test_scoutsuite_auth_service.py rename to monkey/tests/monkey_island/cc/services/zero_trust/scoutsuite/test_scoutsuite_auth_service.py diff --git a/monkey/monkey_island/cc/services/zero_trust/scoutsuite/test_scoutsuite_rule_service.py b/monkey/tests/monkey_island/cc/services/zero_trust/scoutsuite/test_scoutsuite_rule_service.py similarity index 100% rename from monkey/monkey_island/cc/services/zero_trust/scoutsuite/test_scoutsuite_rule_service.py rename to monkey/tests/monkey_island/cc/services/zero_trust/scoutsuite/test_scoutsuite_rule_service.py diff --git a/monkey/monkey_island/cc/services/zero_trust/scoutsuite/test_scoutsuite_zt_finding_service.py b/monkey/tests/monkey_island/cc/services/zero_trust/scoutsuite/test_scoutsuite_zt_finding_service.py similarity index 100% rename from monkey/monkey_island/cc/services/zero_trust/scoutsuite/test_scoutsuite_zt_finding_service.py rename to monkey/tests/monkey_island/cc/services/zero_trust/scoutsuite/test_scoutsuite_zt_finding_service.py diff --git a/monkey/monkey_island/cc/services/zero_trust/zero_trust_report/test_finding_service.py b/monkey/tests/monkey_island/cc/services/zero_trust/zero_trust_report/test_finding_service.py similarity index 100% rename from monkey/monkey_island/cc/services/zero_trust/zero_trust_report/test_finding_service.py rename to monkey/tests/monkey_island/cc/services/zero_trust/zero_trust_report/test_finding_service.py diff --git a/monkey/monkey_island/cc/services/zero_trust/zero_trust_report/test_pillar_service.py b/monkey/tests/monkey_island/cc/services/zero_trust/zero_trust_report/test_pillar_service.py similarity index 100% rename from monkey/monkey_island/cc/services/zero_trust/zero_trust_report/test_pillar_service.py rename to monkey/tests/monkey_island/cc/services/zero_trust/zero_trust_report/test_pillar_service.py diff --git a/monkey/monkey_island/cc/services/zero_trust/zero_trust_report/test_principle_service.py b/monkey/tests/monkey_island/cc/services/zero_trust/zero_trust_report/test_principle_service.py similarity index 100% rename from monkey/monkey_island/cc/services/zero_trust/zero_trust_report/test_principle_service.py rename to monkey/tests/monkey_island/cc/services/zero_trust/zero_trust_report/test_principle_service.py diff --git a/monkey/monkey_island/cc/test_consts.py b/monkey/tests/monkey_island/cc/test_consts.py similarity index 100% rename from monkey/monkey_island/cc/test_consts.py rename to monkey/tests/monkey_island/cc/test_consts.py diff --git a/monkey/monkey_island/cc/test_encryptor.py b/monkey/tests/monkey_island/cc/test_encryptor.py similarity index 100% rename from monkey/monkey_island/cc/test_encryptor.py rename to monkey/tests/monkey_island/cc/test_encryptor.py From c08dbf937608da1c664c15e70d732045ae8a467b Mon Sep 17 00:00:00 2001 From: Shreya Date: Fri, 16 Apr 2021 13:17:32 +0530 Subject: [PATCH 02/16] Move conftest files to tests/ directory --- monkey/{ => tests}/infection_monkey/telemetry/tests/conftest.py | 0 monkey/{ => tests}/monkey_island/cc/conftest.py | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename monkey/{ => tests}/infection_monkey/telemetry/tests/conftest.py (100%) rename monkey/{ => tests}/monkey_island/cc/conftest.py (100%) diff --git a/monkey/infection_monkey/telemetry/tests/conftest.py b/monkey/tests/infection_monkey/telemetry/tests/conftest.py similarity index 100% rename from monkey/infection_monkey/telemetry/tests/conftest.py rename to monkey/tests/infection_monkey/telemetry/tests/conftest.py diff --git a/monkey/monkey_island/cc/conftest.py b/monkey/tests/monkey_island/cc/conftest.py similarity index 100% rename from monkey/monkey_island/cc/conftest.py rename to monkey/tests/monkey_island/cc/conftest.py From f8936f61bba88f05d6884aaf5f5d864e5970fd36 Mon Sep 17 00:00:00 2001 From: Shreya Date: Fri, 16 Apr 2021 13:19:39 +0530 Subject: [PATCH 03/16] Move all tests for monkey_island/cc/services/reporting/report.py to one file --- .../cc/services/reporting/test_report.py | 116 +++++++++++++++++ .../services/tests/reporting/test_report.py | 117 ------------------ 2 files changed, 116 insertions(+), 117 deletions(-) delete mode 100644 monkey/tests/monkey_island/cc/services/tests/reporting/test_report.py diff --git a/monkey/tests/monkey_island/cc/services/reporting/test_report.py b/monkey/tests/monkey_island/cc/services/reporting/test_report.py index cf446c757..cbc9777d3 100644 --- a/monkey/tests/monkey_island/cc/services/reporting/test_report.py +++ b/monkey/tests/monkey_island/cc/services/reporting/test_report.py @@ -1,8 +1,81 @@ import datetime from copy import deepcopy +import mongomock +import pytest +from bson import ObjectId + from monkey_island.cc.services.reporting.report import ReportService +TELEM_ID = { + "exploit_creds": ObjectId(b"123456789000"), + "system_info_creds": ObjectId(b"987654321000"), + "no_creds": ObjectId(b"112233445566"), + "monkey": ObjectId(b"665544332211"), +} +MONKEY_GUID = "67890" +USER = "user-name" +PWD = "password123" +LM_HASH = "e52cac67419a9a22664345140a852f61" +NT_HASH = "a9fdfa038c4b75ebc76dc855dd74f0da" +VICTIM_IP = "0.0.0.0" +VICTIM_DOMAIN_NAME = "domain-name" +HOSTNAME = "name-of-host" +EXPLOITER_CLASS_NAME = "exploiter-name" + +# Below telem constants only contain fields relevant to current tests + +EXPLOIT_TELEMETRY_TELEM = { + "_id": TELEM_ID["exploit_creds"], + "monkey_guid": MONKEY_GUID, + "telem_category": "exploit", + "data": { + "machine": { + "ip_addr": VICTIM_IP, + "domain_name": VICTIM_DOMAIN_NAME, + }, + "info": { + "credentials": { + USER: { + "username": USER, + "lm_hash": LM_HASH, + "ntlm_hash": NT_HASH, + } + } + }, + }, +} + +SYSTEM_INFO_TELEMETRY_TELEM = { + "_id": TELEM_ID["system_info_creds"], + "monkey_guid": MONKEY_GUID, + "telem_category": "system_info", + "data": { + "credentials": { + USER: { + "password": PWD, + "lm_hash": LM_HASH, + "ntlm_hash": NT_HASH, + } + } + }, +} + +NO_CREDS_TELEMETRY_TELEM = { + "_id": TELEM_ID["no_creds"], + "monkey_guid": MONKEY_GUID, + "telem_category": "exploit", + "data": { + "machine": { + "ip_addr": VICTIM_IP, + "domain_name": VICTIM_DOMAIN_NAME, + }, + "info": {"credentials": {}}, + }, +} + +MONKEY_TELEM = {"_id": TELEM_ID["monkey"], "guid": MONKEY_GUID, "hostname": HOSTNAME} + NODE_DICT = { "id": "602f62118e30cf35830ff8e4", "label": "WinDev2010Eval.mshome.net", @@ -51,6 +124,49 @@ NODE_DICT_FAILED_EXPLOITS["exploits"][0]["result"] = False NODE_DICT_FAILED_EXPLOITS["exploits"][1]["result"] = False +@pytest.fixture +def fake_mongo(monkeypatch): + mongo = mongomock.MongoClient() + monkeypatch.setattr("monkey_island.cc.services.reporting.report.mongo", mongo) + monkeypatch.setattr("monkey_island.cc.services.node.mongo", mongo) + return mongo + + +def test_get_stolen_creds_exploit(fake_mongo): + fake_mongo.db.telemetry.insert_one(EXPLOIT_TELEMETRY_TELEM) + + stolen_creds_exploit = ReportService.get_stolen_creds() + expected_stolen_creds_exploit = [ + {"origin": VICTIM_DOMAIN_NAME, "type": "LM hash", "username": USER}, + {"origin": VICTIM_DOMAIN_NAME, "type": "NTLM hash", "username": USER}, + ] + + assert expected_stolen_creds_exploit == stolen_creds_exploit + + +def test_get_stolen_creds_system_info(fake_mongo): + fake_mongo.db.monkey.insert_one(MONKEY_TELEM) + fake_mongo.db.telemetry.insert_one(SYSTEM_INFO_TELEMETRY_TELEM) + + stolen_creds_system_info = ReportService.get_stolen_creds() + expected_stolen_creds_system_info = [ + {"origin": HOSTNAME, "type": "Clear Password", "username": USER}, + {"origin": HOSTNAME, "type": "LM hash", "username": USER}, + {"origin": HOSTNAME, "type": "NTLM hash", "username": USER}, + ] + + assert expected_stolen_creds_system_info == stolen_creds_system_info + + +def test_get_stolen_creds_no_creds(fake_mongo): + fake_mongo.db.telemetry.insert_one(NO_CREDS_TELEMETRY_TELEM) + + stolen_creds_no_creds = ReportService.get_stolen_creds() + expected_stolen_creds_no_creds = [] + + assert expected_stolen_creds_no_creds == stolen_creds_no_creds + + def test_get_exploits_used_on_node(): exploits = ReportService.get_exploits_used_on_node(NODE_DICT) assert sorted(exploits) == sorted(["Elastic Groovy Exploiter", "Drupal Server Exploiter"]) diff --git a/monkey/tests/monkey_island/cc/services/tests/reporting/test_report.py b/monkey/tests/monkey_island/cc/services/tests/reporting/test_report.py deleted file mode 100644 index 65f5d2758..000000000 --- a/monkey/tests/monkey_island/cc/services/tests/reporting/test_report.py +++ /dev/null @@ -1,117 +0,0 @@ -import mongomock -import pytest -from bson import ObjectId - -from monkey_island.cc.services.reporting.report import ReportService - -TELEM_ID = { - "exploit_creds": ObjectId(b"123456789000"), - "system_info_creds": ObjectId(b"987654321000"), - "no_creds": ObjectId(b"112233445566"), - "monkey": ObjectId(b"665544332211"), -} -MONKEY_GUID = "67890" -USER = "user-name" -PWD = "password123" -LM_HASH = "e52cac67419a9a22664345140a852f61" -NT_HASH = "a9fdfa038c4b75ebc76dc855dd74f0da" -VICTIM_IP = "0.0.0.0" -VICTIM_DOMAIN_NAME = "domain-name" -HOSTNAME = "name-of-host" -EXPLOITER_CLASS_NAME = "exploiter-name" - -# Below telem constants only contain fields relevant to current tests - -EXPLOIT_TELEMETRY_TELEM = { - "_id": TELEM_ID["exploit_creds"], - "monkey_guid": MONKEY_GUID, - "telem_category": "exploit", - "data": { - "machine": { - "ip_addr": VICTIM_IP, - "domain_name": VICTIM_DOMAIN_NAME, - }, - "info": { - "credentials": { - USER: { - "username": USER, - "lm_hash": LM_HASH, - "ntlm_hash": NT_HASH, - } - } - }, - }, -} - -SYSTEM_INFO_TELEMETRY_TELEM = { - "_id": TELEM_ID["system_info_creds"], - "monkey_guid": MONKEY_GUID, - "telem_category": "system_info", - "data": { - "credentials": { - USER: { - "password": PWD, - "lm_hash": LM_HASH, - "ntlm_hash": NT_HASH, - } - } - }, -} - -NO_CREDS_TELEMETRY_TELEM = { - "_id": TELEM_ID["no_creds"], - "monkey_guid": MONKEY_GUID, - "telem_category": "exploit", - "data": { - "machine": { - "ip_addr": VICTIM_IP, - "domain_name": VICTIM_DOMAIN_NAME, - }, - "info": {"credentials": {}}, - }, -} - -MONKEY_TELEM = {"_id": TELEM_ID["monkey"], "guid": MONKEY_GUID, "hostname": HOSTNAME} - - -@pytest.fixture -def fake_mongo(monkeypatch): - mongo = mongomock.MongoClient() - monkeypatch.setattr("monkey_island.cc.services.reporting.report.mongo", mongo) - monkeypatch.setattr("monkey_island.cc.services.node.mongo", mongo) - return mongo - - -def test_get_stolen_creds_exploit(fake_mongo): - fake_mongo.db.telemetry.insert_one(EXPLOIT_TELEMETRY_TELEM) - - stolen_creds_exploit = ReportService.get_stolen_creds() - expected_stolen_creds_exploit = [ - {"origin": VICTIM_DOMAIN_NAME, "type": "LM hash", "username": USER}, - {"origin": VICTIM_DOMAIN_NAME, "type": "NTLM hash", "username": USER}, - ] - - assert expected_stolen_creds_exploit == stolen_creds_exploit - - -def test_get_stolen_creds_system_info(fake_mongo): - fake_mongo.db.monkey.insert_one(MONKEY_TELEM) - fake_mongo.db.telemetry.insert_one(SYSTEM_INFO_TELEMETRY_TELEM) - - stolen_creds_system_info = ReportService.get_stolen_creds() - expected_stolen_creds_system_info = [ - {"origin": HOSTNAME, "type": "Clear Password", "username": USER}, - {"origin": HOSTNAME, "type": "LM hash", "username": USER}, - {"origin": HOSTNAME, "type": "NTLM hash", "username": USER}, - ] - - assert expected_stolen_creds_system_info == stolen_creds_system_info - - -def test_get_stolen_creds_no_creds(fake_mongo): - fake_mongo.db.telemetry.insert_one(NO_CREDS_TELEMETRY_TELEM) - - stolen_creds_no_creds = ReportService.get_stolen_creds() - expected_stolen_creds_no_creds = [] - - assert expected_stolen_creds_no_creds == stolen_creds_no_creds From a2115e4254861f24af77af5aa820252a54a37b32 Mon Sep 17 00:00:00 2001 From: Shreya Date: Fri, 16 Apr 2021 13:20:04 +0530 Subject: [PATCH 04/16] Fix imports for unit test files --- monkey/tests/common/cloud/aws/test_aws_service.py | 2 +- monkey/tests/infection_monkey/exploit/tools/test_payload.py | 2 +- monkey/tests/monkey_island/cc/models/test_monkey.py | 5 ++--- .../cc/services/telemetry/processing/test_post_breach.py | 3 +-- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/monkey/tests/common/cloud/aws/test_aws_service.py b/monkey/tests/common/cloud/aws/test_aws_service.py index 95fa6329b..33dc40b54 100644 --- a/monkey/tests/common/cloud/aws/test_aws_service.py +++ b/monkey/tests/common/cloud/aws/test_aws_service.py @@ -1,7 +1,7 @@ import json from unittest import TestCase -from .aws_service import filter_instance_data_from_aws_response +from common.cloud.aws.aws_service import filter_instance_data_from_aws_response __author__ = "shay.nehmad" diff --git a/monkey/tests/infection_monkey/exploit/tools/test_payload.py b/monkey/tests/infection_monkey/exploit/tools/test_payload.py index 18dcf6df2..2656a7ada 100644 --- a/monkey/tests/infection_monkey/exploit/tools/test_payload.py +++ b/monkey/tests/infection_monkey/exploit/tools/test_payload.py @@ -1,6 +1,6 @@ from unittest import TestCase -from .payload_parsing import LimitedSizePayload, Payload +from infection_monkey.exploit.tools.payload_parsing import LimitedSizePayload, Payload class TestPayload(TestCase): diff --git a/monkey/tests/monkey_island/cc/models/test_monkey.py b/monkey/tests/monkey_island/cc/models/test_monkey.py index 92ad2fb90..542309ae5 100644 --- a/monkey/tests/monkey_island/cc/models/test_monkey.py +++ b/monkey/tests/monkey_island/cc/models/test_monkey.py @@ -5,9 +5,8 @@ from time import sleep import pytest from monkey_island.cc.models.monkey import Monkey, MonkeyNotFoundError - -from ..test_common.fixtures import FixtureEnum -from .monkey_ttl import MonkeyTtl +from monkey_island.cc.models.monkey_ttl import MonkeyTtl +from monkey_island.cc.test_common.fixtures import FixtureEnum logger = logging.getLogger(__name__) diff --git a/monkey/tests/monkey_island/cc/services/telemetry/processing/test_post_breach.py b/monkey/tests/monkey_island/cc/services/telemetry/processing/test_post_breach.py index 882339119..f6d33b930 100644 --- a/monkey/tests/monkey_island/cc/services/telemetry/processing/test_post_breach.py +++ b/monkey/tests/monkey_island/cc/services/telemetry/processing/test_post_breach.py @@ -1,8 +1,7 @@ from unittest.mock import Mock import monkey_island.cc.services.telemetry.processing.post_breach as post_breach - -from .post_breach import EXECUTION_WITHOUT_OUTPUT +from monkey_island.cc.services.telemetry.processing.post_breach import EXECUTION_WITHOUT_OUTPUT original_telem_multiple_results = { "data": { From 468019337558b6cfd5d4da346181073fd46a1cb2 Mon Sep 17 00:00:00 2001 From: Shreya Date: Fri, 16 Apr 2021 13:30:05 +0530 Subject: [PATCH 05/16] Put unit test files in the right directories Some test files were in their own "tests/" directory. Deleted the extra "tests/" directories. --- .../tests/infection_monkey/exploit/{tests => }/test_zerologon.py | 0 .../exploit/{tests => }/zerologon_utils/test_vuln_assessment.py | 0 .../post_breach/{tests => }/actions/test_users_custom_pba.py | 0 .../telemetry/{tests => }/attack/test_attack_telem.py | 0 .../telemetry/{tests => }/attack/test_t1005_telem.py | 0 .../telemetry/{tests => }/attack/test_t1035_telem.py | 0 .../telemetry/{tests => }/attack/test_t1064_telem.py | 0 .../telemetry/{tests => }/attack/test_t1105_telem.py | 0 .../telemetry/{tests => }/attack/test_t1106_telem.py | 0 .../telemetry/{tests => }/attack/test_t1107_telem.py | 0 .../telemetry/{tests => }/attack/test_t1129_telem.py | 0 .../telemetry/{tests => }/attack/test_t1197_telem.py | 0 .../telemetry/{tests => }/attack/test_t1222_telem.py | 0 .../telemetry/{tests => }/attack/test_usage_telem.py | 0 .../telemetry/{tests => }/attack/test_victim_host_telem.py | 0 monkey/tests/infection_monkey/telemetry/{tests => }/conftest.py | 0 .../infection_monkey/telemetry/{tests => }/test_exploit_telem.py | 0 .../telemetry/{tests => }/test_post_breach_telem.py | 0 .../infection_monkey/telemetry/{tests => }/test_scan_telem.py | 0 .../infection_monkey/telemetry/{tests => }/test_state_telem.py | 0 .../telemetry/{tests => }/test_system_info_telem.py | 0 .../infection_monkey/telemetry/{tests => }/test_trace_telem.py | 0 .../infection_monkey/telemetry/{tests => }/test_tunnel_telem.py | 0 monkey/tests/monkey_island/cc/services/{tests => }/test_config.py | 0 24 files changed, 0 insertions(+), 0 deletions(-) rename monkey/tests/infection_monkey/exploit/{tests => }/test_zerologon.py (100%) rename monkey/tests/infection_monkey/exploit/{tests => }/zerologon_utils/test_vuln_assessment.py (100%) rename monkey/tests/infection_monkey/post_breach/{tests => }/actions/test_users_custom_pba.py (100%) rename monkey/tests/infection_monkey/telemetry/{tests => }/attack/test_attack_telem.py (100%) rename monkey/tests/infection_monkey/telemetry/{tests => }/attack/test_t1005_telem.py (100%) rename monkey/tests/infection_monkey/telemetry/{tests => }/attack/test_t1035_telem.py (100%) rename monkey/tests/infection_monkey/telemetry/{tests => }/attack/test_t1064_telem.py (100%) rename monkey/tests/infection_monkey/telemetry/{tests => }/attack/test_t1105_telem.py (100%) rename monkey/tests/infection_monkey/telemetry/{tests => }/attack/test_t1106_telem.py (100%) rename monkey/tests/infection_monkey/telemetry/{tests => }/attack/test_t1107_telem.py (100%) rename monkey/tests/infection_monkey/telemetry/{tests => }/attack/test_t1129_telem.py (100%) rename monkey/tests/infection_monkey/telemetry/{tests => }/attack/test_t1197_telem.py (100%) rename monkey/tests/infection_monkey/telemetry/{tests => }/attack/test_t1222_telem.py (100%) rename monkey/tests/infection_monkey/telemetry/{tests => }/attack/test_usage_telem.py (100%) rename monkey/tests/infection_monkey/telemetry/{tests => }/attack/test_victim_host_telem.py (100%) rename monkey/tests/infection_monkey/telemetry/{tests => }/conftest.py (100%) rename monkey/tests/infection_monkey/telemetry/{tests => }/test_exploit_telem.py (100%) rename monkey/tests/infection_monkey/telemetry/{tests => }/test_post_breach_telem.py (100%) rename monkey/tests/infection_monkey/telemetry/{tests => }/test_scan_telem.py (100%) rename monkey/tests/infection_monkey/telemetry/{tests => }/test_state_telem.py (100%) rename monkey/tests/infection_monkey/telemetry/{tests => }/test_system_info_telem.py (100%) rename monkey/tests/infection_monkey/telemetry/{tests => }/test_trace_telem.py (100%) rename monkey/tests/infection_monkey/telemetry/{tests => }/test_tunnel_telem.py (100%) rename monkey/tests/monkey_island/cc/services/{tests => }/test_config.py (100%) diff --git a/monkey/tests/infection_monkey/exploit/tests/test_zerologon.py b/monkey/tests/infection_monkey/exploit/test_zerologon.py similarity index 100% rename from monkey/tests/infection_monkey/exploit/tests/test_zerologon.py rename to monkey/tests/infection_monkey/exploit/test_zerologon.py diff --git a/monkey/tests/infection_monkey/exploit/tests/zerologon_utils/test_vuln_assessment.py b/monkey/tests/infection_monkey/exploit/zerologon_utils/test_vuln_assessment.py similarity index 100% rename from monkey/tests/infection_monkey/exploit/tests/zerologon_utils/test_vuln_assessment.py rename to monkey/tests/infection_monkey/exploit/zerologon_utils/test_vuln_assessment.py diff --git a/monkey/tests/infection_monkey/post_breach/tests/actions/test_users_custom_pba.py b/monkey/tests/infection_monkey/post_breach/actions/test_users_custom_pba.py similarity index 100% rename from monkey/tests/infection_monkey/post_breach/tests/actions/test_users_custom_pba.py rename to monkey/tests/infection_monkey/post_breach/actions/test_users_custom_pba.py diff --git a/monkey/tests/infection_monkey/telemetry/tests/attack/test_attack_telem.py b/monkey/tests/infection_monkey/telemetry/attack/test_attack_telem.py similarity index 100% rename from monkey/tests/infection_monkey/telemetry/tests/attack/test_attack_telem.py rename to monkey/tests/infection_monkey/telemetry/attack/test_attack_telem.py diff --git a/monkey/tests/infection_monkey/telemetry/tests/attack/test_t1005_telem.py b/monkey/tests/infection_monkey/telemetry/attack/test_t1005_telem.py similarity index 100% rename from monkey/tests/infection_monkey/telemetry/tests/attack/test_t1005_telem.py rename to monkey/tests/infection_monkey/telemetry/attack/test_t1005_telem.py diff --git a/monkey/tests/infection_monkey/telemetry/tests/attack/test_t1035_telem.py b/monkey/tests/infection_monkey/telemetry/attack/test_t1035_telem.py similarity index 100% rename from monkey/tests/infection_monkey/telemetry/tests/attack/test_t1035_telem.py rename to monkey/tests/infection_monkey/telemetry/attack/test_t1035_telem.py diff --git a/monkey/tests/infection_monkey/telemetry/tests/attack/test_t1064_telem.py b/monkey/tests/infection_monkey/telemetry/attack/test_t1064_telem.py similarity index 100% rename from monkey/tests/infection_monkey/telemetry/tests/attack/test_t1064_telem.py rename to monkey/tests/infection_monkey/telemetry/attack/test_t1064_telem.py diff --git a/monkey/tests/infection_monkey/telemetry/tests/attack/test_t1105_telem.py b/monkey/tests/infection_monkey/telemetry/attack/test_t1105_telem.py similarity index 100% rename from monkey/tests/infection_monkey/telemetry/tests/attack/test_t1105_telem.py rename to monkey/tests/infection_monkey/telemetry/attack/test_t1105_telem.py diff --git a/monkey/tests/infection_monkey/telemetry/tests/attack/test_t1106_telem.py b/monkey/tests/infection_monkey/telemetry/attack/test_t1106_telem.py similarity index 100% rename from monkey/tests/infection_monkey/telemetry/tests/attack/test_t1106_telem.py rename to monkey/tests/infection_monkey/telemetry/attack/test_t1106_telem.py diff --git a/monkey/tests/infection_monkey/telemetry/tests/attack/test_t1107_telem.py b/monkey/tests/infection_monkey/telemetry/attack/test_t1107_telem.py similarity index 100% rename from monkey/tests/infection_monkey/telemetry/tests/attack/test_t1107_telem.py rename to monkey/tests/infection_monkey/telemetry/attack/test_t1107_telem.py diff --git a/monkey/tests/infection_monkey/telemetry/tests/attack/test_t1129_telem.py b/monkey/tests/infection_monkey/telemetry/attack/test_t1129_telem.py similarity index 100% rename from monkey/tests/infection_monkey/telemetry/tests/attack/test_t1129_telem.py rename to monkey/tests/infection_monkey/telemetry/attack/test_t1129_telem.py diff --git a/monkey/tests/infection_monkey/telemetry/tests/attack/test_t1197_telem.py b/monkey/tests/infection_monkey/telemetry/attack/test_t1197_telem.py similarity index 100% rename from monkey/tests/infection_monkey/telemetry/tests/attack/test_t1197_telem.py rename to monkey/tests/infection_monkey/telemetry/attack/test_t1197_telem.py diff --git a/monkey/tests/infection_monkey/telemetry/tests/attack/test_t1222_telem.py b/monkey/tests/infection_monkey/telemetry/attack/test_t1222_telem.py similarity index 100% rename from monkey/tests/infection_monkey/telemetry/tests/attack/test_t1222_telem.py rename to monkey/tests/infection_monkey/telemetry/attack/test_t1222_telem.py diff --git a/monkey/tests/infection_monkey/telemetry/tests/attack/test_usage_telem.py b/monkey/tests/infection_monkey/telemetry/attack/test_usage_telem.py similarity index 100% rename from monkey/tests/infection_monkey/telemetry/tests/attack/test_usage_telem.py rename to monkey/tests/infection_monkey/telemetry/attack/test_usage_telem.py diff --git a/monkey/tests/infection_monkey/telemetry/tests/attack/test_victim_host_telem.py b/monkey/tests/infection_monkey/telemetry/attack/test_victim_host_telem.py similarity index 100% rename from monkey/tests/infection_monkey/telemetry/tests/attack/test_victim_host_telem.py rename to monkey/tests/infection_monkey/telemetry/attack/test_victim_host_telem.py diff --git a/monkey/tests/infection_monkey/telemetry/tests/conftest.py b/monkey/tests/infection_monkey/telemetry/conftest.py similarity index 100% rename from monkey/tests/infection_monkey/telemetry/tests/conftest.py rename to monkey/tests/infection_monkey/telemetry/conftest.py diff --git a/monkey/tests/infection_monkey/telemetry/tests/test_exploit_telem.py b/monkey/tests/infection_monkey/telemetry/test_exploit_telem.py similarity index 100% rename from monkey/tests/infection_monkey/telemetry/tests/test_exploit_telem.py rename to monkey/tests/infection_monkey/telemetry/test_exploit_telem.py diff --git a/monkey/tests/infection_monkey/telemetry/tests/test_post_breach_telem.py b/monkey/tests/infection_monkey/telemetry/test_post_breach_telem.py similarity index 100% rename from monkey/tests/infection_monkey/telemetry/tests/test_post_breach_telem.py rename to monkey/tests/infection_monkey/telemetry/test_post_breach_telem.py diff --git a/monkey/tests/infection_monkey/telemetry/tests/test_scan_telem.py b/monkey/tests/infection_monkey/telemetry/test_scan_telem.py similarity index 100% rename from monkey/tests/infection_monkey/telemetry/tests/test_scan_telem.py rename to monkey/tests/infection_monkey/telemetry/test_scan_telem.py diff --git a/monkey/tests/infection_monkey/telemetry/tests/test_state_telem.py b/monkey/tests/infection_monkey/telemetry/test_state_telem.py similarity index 100% rename from monkey/tests/infection_monkey/telemetry/tests/test_state_telem.py rename to monkey/tests/infection_monkey/telemetry/test_state_telem.py diff --git a/monkey/tests/infection_monkey/telemetry/tests/test_system_info_telem.py b/monkey/tests/infection_monkey/telemetry/test_system_info_telem.py similarity index 100% rename from monkey/tests/infection_monkey/telemetry/tests/test_system_info_telem.py rename to monkey/tests/infection_monkey/telemetry/test_system_info_telem.py diff --git a/monkey/tests/infection_monkey/telemetry/tests/test_trace_telem.py b/monkey/tests/infection_monkey/telemetry/test_trace_telem.py similarity index 100% rename from monkey/tests/infection_monkey/telemetry/tests/test_trace_telem.py rename to monkey/tests/infection_monkey/telemetry/test_trace_telem.py diff --git a/monkey/tests/infection_monkey/telemetry/tests/test_tunnel_telem.py b/monkey/tests/infection_monkey/telemetry/test_tunnel_telem.py similarity index 100% rename from monkey/tests/infection_monkey/telemetry/tests/test_tunnel_telem.py rename to monkey/tests/infection_monkey/telemetry/test_tunnel_telem.py diff --git a/monkey/tests/monkey_island/cc/services/tests/test_config.py b/monkey/tests/monkey_island/cc/services/test_config.py similarity index 100% rename from monkey/tests/monkey_island/cc/services/tests/test_config.py rename to monkey/tests/monkey_island/cc/services/test_config.py From dc0e155c316cbdb3c42bc18d02080032bc3e1152 Mon Sep 17 00:00:00 2001 From: Shreya Date: Mon, 19 Apr 2021 17:28:40 +0530 Subject: [PATCH 06/16] Add pytest to pre-commit --- .pre-commit-config.yaml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2bceacbcc..8e668f8b8 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -33,3 +33,13 @@ repos: hooks: - id: eslint args: ["monkey/monkey_island/cc/ui/src/", "--fix", "--max-warnings=0"] + - repo: local + hooks: + - id: pytest + name: pytest + entry: bash -c "cd monkey && pytest" + language: system + pass_filenames: false + # alternatively you could `types: [python]` so it only runs when python files change + # though tests might be invalidated if you were to say change a data file + always_run: true From c37ae1e0eaa5ab3850020f109e6bb7fb9e8f3ed3 Mon Sep 17 00:00:00 2001 From: Shreya Date: Mon, 19 Apr 2021 17:31:01 +0530 Subject: [PATCH 07/16] Modify pytest configuration Shift it from monkey/pytest.ini to pyproject.toml. Add conftest.py in tests/ to add monkey directory to sys.path so test files recognize paths. --- monkey/pytest.ini | 7 ------- monkey/tests/conftest.py | 5 +++++ pyproject.toml | 10 ++++++++++ 3 files changed, 15 insertions(+), 7 deletions(-) delete mode 100644 monkey/pytest.ini create mode 100644 monkey/tests/conftest.py diff --git a/monkey/pytest.ini b/monkey/pytest.ini deleted file mode 100644 index 9b1766fc2..000000000 --- a/monkey/pytest.ini +++ /dev/null @@ -1,7 +0,0 @@ -[pytest] -log_cli = 1 -log_cli_level = DEBUG -log_cli_format = %(asctime)s [%(levelname)s] %(module)s.%(funcName)s.%(lineno)d: %(message)s -log_cli_date_format=%H:%M:%S -addopts = -v --capture=sys --ignore=common/cloud/scoutsuite -norecursedirs = node_modules dist diff --git a/monkey/tests/conftest.py b/monkey/tests/conftest.py new file mode 100644 index 000000000..12602eae4 --- /dev/null +++ b/monkey/tests/conftest.py @@ -0,0 +1,5 @@ +import sys +from pathlib import Path + +MONKEY_BASE_PATH = str(Path(__file__).parent.parent) +sys.path.insert(0, MONKEY_BASE_PATH) diff --git a/pyproject.toml b/pyproject.toml index 077d3aeb8..bbf778536 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,3 +12,13 @@ include_trailing_comma = true force_grid_wrap = 0 use_parentheses = true ensure_newline_before_comments = true + +[tool.pytest.ini_options] +minversion = "6.0" +log_cli = 1 +log_cli_level = "DEBUG" +log_cli_format = "%(asctime)s [%(levelname)s] %(module)s.%(funcName)s.%(lineno)d: %(message)s" +log_cli_date_format = "%H:%M:%S" +addopts = "-v --capture=sys" +norecursedirs = "node_modules dist" +testpaths = "monkey/tests" From 3f66e95a90fd2ee73a90888de97db5c3a41fb4d2 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Mon, 19 Apr 2021 14:39:39 -0400 Subject: [PATCH 08/16] Use addopts instead of testpaths to specify path in pytest config The pytest documentation states that the testpaths configuration option "Sets list of directories that should be searched ... when executing pytest from the rootdir directory." Since pytest is not executed from the rootdir directory, testpaths has no effect. Appending the "tests/" directory to the end of addopts reduces the time required to run the test suite by approximately 6 seconds. --- pyproject.toml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index bbf778536..0245f12a0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -19,6 +19,5 @@ log_cli = 1 log_cli_level = "DEBUG" log_cli_format = "%(asctime)s [%(levelname)s] %(module)s.%(funcName)s.%(lineno)d: %(message)s" log_cli_date_format = "%H:%M:%S" -addopts = "-v --capture=sys" +addopts = "-v --capture=sys tests" norecursedirs = "node_modules dist" -testpaths = "monkey/tests" From 83e93928e7bca8b3000aebab2c565f1c3b8cb339 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Mon, 19 Apr 2021 14:57:40 -0400 Subject: [PATCH 09/16] Only run pytest pre-commit hook when files in monkey/ are modified --- .pre-commit-config.yaml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8e668f8b8..33b42663b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -39,7 +39,5 @@ repos: name: pytest entry: bash -c "cd monkey && pytest" language: system - pass_filenames: false - # alternatively you could `types: [python]` so it only runs when python files change - # though tests might be invalidated if you were to say change a data file - always_run: true + files: "monkey/" + exclude: "monkey/monkey_island/cc/ui" From 88a3ab5bf18a2c4811bdb3f4e814916ee9504520 Mon Sep 17 00:00:00 2001 From: shreyamalviya Date: Tue, 20 Apr 2021 18:49:40 +0530 Subject: [PATCH 10/16] Modify pre-commit-config.yaml to make pytest run only pre-push (Run `pre-commit install --hook-type pre-push`) --- .pre-commit-config.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 33b42663b..877a1b57d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -41,3 +41,4 @@ repos: language: system files: "monkey/" exclude: "monkey/monkey_island/cc/ui" + stages: [push] From 753c0586c150b0d0b4f2d6516bc53c05f2b8c7b3 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Tue, 20 Apr 2021 11:27:30 -0400 Subject: [PATCH 11/16] cc: Move config files and other testing resources to tests/ dir --- monkey/tests/conftest.py | 46 +++++++++++++++++++ .../cc/environment/test_environment.py | 38 +++++++++++---- .../cc/environment/test_environment_config.py | 45 +++++++----------- .../cc/server_utils/test_island_logger.py | 12 ++--- .../tests/monkey_island/cc/test_encryptor.py | 14 +++--- .../server_config_no_credentials.json | 0 .../server_config_partial_credentials.json | 0 .../server_config_standard_env.json | 0 ...rver_config_standard_with_credentials.json | 0 .../server_config_with_credentials.json | 0 .../server_config_with_data_dir.json | 0 .../server_config_with_data_dir_home.json | 0 .../resources}/logger_config.json | 0 .../testing => tests/resources}/mongo_key.bin | 0 .../server_config_no_credentials.json | 4 ++ .../server_config_with_credentials.json | 4 ++ 16 files changed, 112 insertions(+), 51 deletions(-) rename monkey/{monkey_island/cc/testing => tests/resources}/environment/server_config_no_credentials.json (100%) rename monkey/{monkey_island/cc/testing => tests/resources}/environment/server_config_partial_credentials.json (100%) rename monkey/{monkey_island/cc/testing => tests/resources}/environment/server_config_standard_env.json (100%) rename monkey/{monkey_island/cc/testing => tests/resources}/environment/server_config_standard_with_credentials.json (100%) rename monkey/{monkey_island/cc/testing => tests/resources}/environment/server_config_with_credentials.json (100%) rename monkey/{monkey_island/cc/testing => tests/resources}/environment/server_config_with_data_dir.json (100%) rename monkey/{monkey_island/cc/testing => tests/resources}/environment/server_config_with_data_dir_home.json (100%) rename monkey/{monkey_island/cc/testing => tests/resources}/logger_config.json (100%) rename monkey/{monkey_island/cc/testing => tests/resources}/mongo_key.bin (100%) create mode 100644 monkey/tests/resources/server_config_no_credentials.json create mode 100644 monkey/tests/resources/server_config_with_credentials.json diff --git a/monkey/tests/conftest.py b/monkey/tests/conftest.py index 12602eae4..89de33109 100644 --- a/monkey/tests/conftest.py +++ b/monkey/tests/conftest.py @@ -1,5 +1,51 @@ +import os import sys from pathlib import Path +import pytest + MONKEY_BASE_PATH = str(Path(__file__).parent.parent) sys.path.insert(0, MONKEY_BASE_PATH) + + +print("imported") + + +@pytest.fixture(scope="session") +def resources_dir(pytestconfig): + return os.path.join(pytestconfig.rootdir, "monkey", "tests", "resources") + + +@pytest.fixture(scope="session") +def environment_resources_dir(resources_dir): + return os.path.join(resources_dir, "environment") + + +@pytest.fixture(scope="session") +def with_credentials(environment_resources_dir): + return os.path.join(environment_resources_dir, "server_config_with_credentials.json") + + +@pytest.fixture(scope="session") +def no_credentials(environment_resources_dir): + return os.path.join(environment_resources_dir, "server_config_no_credentials.json") + + +@pytest.fixture(scope="session") +def partial_credentials(environment_resources_dir): + return os.path.join(environment_resources_dir, "server_config_partial_credentials.json") + + +@pytest.fixture(scope="session") +def standard_with_credentials(environment_resources_dir): + return os.path.join(environment_resources_dir, "server_config_standard_with_credentials.json") + + +@pytest.fixture(scope="session") +def with_data_dir(environment_resources_dir): + return os.path.join(environment_resources_dir, "server_config_with_data_dir.json") + + +@pytest.fixture(scope="session") +def with_data_dir_home(environment_resources_dir): + return os.path.join(environment_resources_dir, "server_config_with_data_dir_home.json") diff --git a/monkey/tests/monkey_island/cc/environment/test_environment.py b/monkey/tests/monkey_island/cc/environment/test_environment.py index dbf98eefe..0c98d1ccf 100644 --- a/monkey/tests/monkey_island/cc/environment/test_environment.py +++ b/monkey/tests/monkey_island/cc/environment/test_environment.py @@ -4,6 +4,8 @@ from typing import Dict from unittest import TestCase from unittest.mock import MagicMock, patch +import pytest + from common.utils.exceptions import ( AlreadyRegisteredError, CredentialsNotRequiredError, @@ -11,17 +13,35 @@ from common.utils.exceptions import ( RegistrationNotNeededError, ) from monkey_island.cc.environment import Environment, EnvironmentConfig, UserCreds -from monkey_island.cc.server_utils.consts import MONKEY_ISLAND_ABS_PATH -TEST_RESOURCES_DIR = os.path.join(MONKEY_ISLAND_ABS_PATH, "cc", "testing", "environment") +WITH_CREDENTIALS = None +NO_CREDENTIALS = None +PARTIAL_CREDENTIALS = None +STANDARD_WITH_CREDENTIALS = None +STANDARD_ENV = None -WITH_CREDENTIALS = os.path.join(TEST_RESOURCES_DIR, "server_config_with_credentials.json") -NO_CREDENTIALS = os.path.join(TEST_RESOURCES_DIR, "server_config_no_credentials.json") -PARTIAL_CREDENTIALS = os.path.join(TEST_RESOURCES_DIR, "server_config_partial_credentials.json") -STANDARD_WITH_CREDENTIALS = os.path.join( - TEST_RESOURCES_DIR, "server_config_standard_with_credentials.json" -) -STANDARD_ENV = os.path.join(TEST_RESOURCES_DIR, "server_config_standard_env.json") + +# This fixture is a dirty hack that can be removed once these tests are converted from +# unittest to pytest. Instead, the appropriate fixtures from conftest.py can be used. +@pytest.fixture(scope="module", autouse=True) +def configure_resources(environment_resources_dir): + global WITH_CREDENTIALS + global NO_CREDENTIALS + global PARTIAL_CREDENTIALS + global STANDARD_WITH_CREDENTIALS + global STANDARD_ENV + + WITH_CREDENTIALS = os.path.join( + environment_resources_dir, "server_config_with_credentials.json" + ) + NO_CREDENTIALS = os.path.join(environment_resources_dir, "server_config_no_credentials.json") + PARTIAL_CREDENTIALS = os.path.join( + environment_resources_dir, "server_config_partial_credentials.json" + ) + STANDARD_WITH_CREDENTIALS = os.path.join( + environment_resources_dir, "server_config_standard_with_credentials.json" + ) + STANDARD_ENV = os.path.join(environment_resources_dir, "server_config_standard_env.json") def get_tmp_file(): diff --git a/monkey/tests/monkey_island/cc/environment/test_environment_config.py b/monkey/tests/monkey_island/cc/environment/test_environment_config.py index 9bf6bfc2b..6f9170f2f 100644 --- a/monkey/tests/monkey_island/cc/environment/test_environment_config.py +++ b/monkey/tests/monkey_island/cc/environment/test_environment_config.py @@ -6,18 +6,7 @@ import pytest from monkey_island.cc.environment.environment_config import EnvironmentConfig from monkey_island.cc.environment.user_creds import UserCreds -from monkey_island.cc.server_utils.consts import DEFAULT_DATA_DIR, MONKEY_ISLAND_ABS_PATH - -TEST_RESOURCES_DIR = os.path.join(MONKEY_ISLAND_ABS_PATH, "cc", "testing", "environment") - -WITH_CREDENTIALS = os.path.join(TEST_RESOURCES_DIR, "server_config_with_credentials.json") -NO_CREDENTIALS = os.path.join(TEST_RESOURCES_DIR, "server_config_no_credentials.json") -PARTIAL_CREDENTIALS = os.path.join(TEST_RESOURCES_DIR, "server_config_partial_credentials.json") -STANDARD_WITH_CREDENTIALS = os.path.join( - TEST_RESOURCES_DIR, "server_config_standard_with_credentials.json" -) -WITH_DATA_DIR = os.path.join(TEST_RESOURCES_DIR, "server_config_with_data_dir.json") -WITH_DATA_DIR_HOME = os.path.join(TEST_RESOURCES_DIR, "server_config_with_data_dir_home.json") +from monkey_island.cc.server_utils.consts import DEFAULT_DATA_DIR @pytest.fixture @@ -25,8 +14,8 @@ def config_file(tmpdir): return os.path.join(tmpdir, "test_config.json") -def test_get_with_credentials(): - config_dict = EnvironmentConfig(WITH_CREDENTIALS).to_dict() +def test_get_with_credentials(with_credentials): + config_dict = EnvironmentConfig(with_credentials).to_dict() assert len(config_dict.keys()) == 5 assert config_dict["server_config"] == "password" @@ -36,8 +25,8 @@ def test_get_with_credentials(): assert config_dict["data_dir"] == DEFAULT_DATA_DIR -def test_get_with_no_credentials(): - config_dict = EnvironmentConfig(NO_CREDENTIALS).to_dict() +def test_get_with_no_credentials(no_credentials): + config_dict = EnvironmentConfig(no_credentials).to_dict() assert len(config_dict.keys()) == 3 assert config_dict["server_config"] == "password" @@ -45,8 +34,8 @@ def test_get_with_no_credentials(): assert config_dict["data_dir"] == DEFAULT_DATA_DIR -def test_get_with_partial_credentials(): - config_dict = EnvironmentConfig(PARTIAL_CREDENTIALS).to_dict() +def test_get_with_partial_credentials(partial_credentials): + config_dict = EnvironmentConfig(partial_credentials).to_dict() assert len(config_dict.keys()) == 4 assert config_dict["server_config"] == "password" @@ -55,8 +44,8 @@ def test_get_with_partial_credentials(): assert config_dict["data_dir"] == DEFAULT_DATA_DIR -def test_save_to_file(config_file): - shutil.copyfile(STANDARD_WITH_CREDENTIALS, config_file) +def test_save_to_file(config_file, standard_with_credentials): + shutil.copyfile(standard_with_credentials, config_file) environment_config = EnvironmentConfig(config_file) environment_config.aws = "test_aws" @@ -74,12 +63,12 @@ def test_save_to_file(config_file): assert from_file["data_dir"] == DEFAULT_DATA_DIR -def test_add_user(config_file): +def test_add_user(config_file, standard_with_credentials): new_user = "new_user" new_password_hash = "fedcba" new_user_creds = UserCreds(new_user, new_password_hash) - shutil.copyfile(STANDARD_WITH_CREDENTIALS, config_file) + shutil.copyfile(standard_with_credentials, config_file) environment_config = EnvironmentConfig(config_file) environment_config.add_user(new_user_creds) @@ -92,8 +81,8 @@ def test_add_user(config_file): assert from_file["password_hash"] == new_password_hash -def test_get_users(): - environment_config = EnvironmentConfig(STANDARD_WITH_CREDENTIALS) +def test_get_users(standard_with_credentials): + environment_config = EnvironmentConfig(standard_with_credentials) users = environment_config.get_users() assert len(users) == 1 @@ -115,8 +104,8 @@ def test_generate_default_file(config_file): assert environment_config.data_dir == DEFAULT_DATA_DIR -def test_data_dir(): - environment_config = EnvironmentConfig(WITH_DATA_DIR) +def test_data_dir(with_data_dir): + environment_config = EnvironmentConfig(with_data_dir) assert environment_config.data_dir == "/test/data/dir" @@ -124,8 +113,8 @@ def set_home_env(monkeypatch, tmpdir): monkeypatch.setenv("HOME", str(tmpdir)) -def test_data_dir_abs_path_from_file(monkeypatch, tmpdir): +def test_data_dir_abs_path_from_file(monkeypatch, tmpdir, with_data_dir_home): set_home_env(monkeypatch, tmpdir) - config = EnvironmentConfig(WITH_DATA_DIR_HOME) + config = EnvironmentConfig(with_data_dir_home) assert config.data_dir_abs_path == os.path.join(tmpdir, "data_dir") diff --git a/monkey/tests/monkey_island/cc/server_utils/test_island_logger.py b/monkey/tests/monkey_island/cc/server_utils/test_island_logger.py index af58f4b75..57f0cc5b0 100644 --- a/monkey/tests/monkey_island/cc/server_utils/test_island_logger.py +++ b/monkey/tests/monkey_island/cc/server_utils/test_island_logger.py @@ -3,12 +3,12 @@ import os import pytest -from monkey_island.cc.server_utils.consts import MONKEY_ISLAND_ABS_PATH from monkey_island.cc.server_utils.island_logger import json_setup_logging -TEST_LOGGER_CONFIG_PATH = os.path.join( - MONKEY_ISLAND_ABS_PATH, "cc", "testing", "logger_config.json" -) + +@pytest.fixture() +def test_logger_config_path(resources_dir): + return os.path.join(resources_dir, "logger_config.json") # TODO move into monkey/monkey_island/cc/test_common/fixtures after rebase/backmerge @@ -17,11 +17,11 @@ def mock_home_env(monkeypatch, tmpdir): monkeypatch.setenv("HOME", str(tmpdir)) -def test_expanduser_filename(mock_home_env, tmpdir): +def test_expanduser_filename(mock_home_env, tmpdir, test_logger_config_path): INFO_LOG = os.path.join(tmpdir, "info.log") TEST_STRING = "Hello, Monkey!" - json_setup_logging(TEST_LOGGER_CONFIG_PATH) + json_setup_logging(test_logger_config_path) logger = logging.getLogger("TestLogger") logger.info(TEST_STRING) diff --git a/monkey/tests/monkey_island/cc/test_encryptor.py b/monkey/tests/monkey_island/cc/test_encryptor.py index 7823c64ec..a7ad9e6b6 100644 --- a/monkey/tests/monkey_island/cc/test_encryptor.py +++ b/monkey/tests/monkey_island/cc/test_encryptor.py @@ -1,29 +1,27 @@ import os -from monkey_island.cc.server_utils.consts import MONKEY_ISLAND_ABS_PATH from monkey_island.cc.server_utils.encryptor import get_encryptor, initialize_encryptor -TEST_DATA_DIR = os.path.join(MONKEY_ISLAND_ABS_PATH, "cc", "testing") PASSWORD_FILENAME = "mongo_key.bin" PLAINTEXT = "Hello, Monkey!" CYPHERTEXT = "vKgvD6SjRyIh1dh2AM/rnTa0NI/vjfwnbZLbMocWtE4e42WJmSUz2ordtbQrH1Fq" -def test_aes_cbc_encryption(): - initialize_encryptor(TEST_DATA_DIR) +def test_aes_cbc_encryption(resources_dir): + initialize_encryptor(resources_dir) assert get_encryptor().enc(PLAINTEXT) != PLAINTEXT -def test_aes_cbc_decryption(): - initialize_encryptor(TEST_DATA_DIR) +def test_aes_cbc_decryption(resources_dir): + initialize_encryptor(resources_dir) assert get_encryptor().dec(CYPHERTEXT) == PLAINTEXT -def test_aes_cbc_enc_dec(): - initialize_encryptor(TEST_DATA_DIR) +def test_aes_cbc_enc_dec(resources_dir): + initialize_encryptor(resources_dir) assert get_encryptor().dec(get_encryptor().enc(PLAINTEXT)) == PLAINTEXT diff --git a/monkey/monkey_island/cc/testing/environment/server_config_no_credentials.json b/monkey/tests/resources/environment/server_config_no_credentials.json similarity index 100% rename from monkey/monkey_island/cc/testing/environment/server_config_no_credentials.json rename to monkey/tests/resources/environment/server_config_no_credentials.json diff --git a/monkey/monkey_island/cc/testing/environment/server_config_partial_credentials.json b/monkey/tests/resources/environment/server_config_partial_credentials.json similarity index 100% rename from monkey/monkey_island/cc/testing/environment/server_config_partial_credentials.json rename to monkey/tests/resources/environment/server_config_partial_credentials.json diff --git a/monkey/monkey_island/cc/testing/environment/server_config_standard_env.json b/monkey/tests/resources/environment/server_config_standard_env.json similarity index 100% rename from monkey/monkey_island/cc/testing/environment/server_config_standard_env.json rename to monkey/tests/resources/environment/server_config_standard_env.json diff --git a/monkey/monkey_island/cc/testing/environment/server_config_standard_with_credentials.json b/monkey/tests/resources/environment/server_config_standard_with_credentials.json similarity index 100% rename from monkey/monkey_island/cc/testing/environment/server_config_standard_with_credentials.json rename to monkey/tests/resources/environment/server_config_standard_with_credentials.json diff --git a/monkey/monkey_island/cc/testing/environment/server_config_with_credentials.json b/monkey/tests/resources/environment/server_config_with_credentials.json similarity index 100% rename from monkey/monkey_island/cc/testing/environment/server_config_with_credentials.json rename to monkey/tests/resources/environment/server_config_with_credentials.json diff --git a/monkey/monkey_island/cc/testing/environment/server_config_with_data_dir.json b/monkey/tests/resources/environment/server_config_with_data_dir.json similarity index 100% rename from monkey/monkey_island/cc/testing/environment/server_config_with_data_dir.json rename to monkey/tests/resources/environment/server_config_with_data_dir.json diff --git a/monkey/monkey_island/cc/testing/environment/server_config_with_data_dir_home.json b/monkey/tests/resources/environment/server_config_with_data_dir_home.json similarity index 100% rename from monkey/monkey_island/cc/testing/environment/server_config_with_data_dir_home.json rename to monkey/tests/resources/environment/server_config_with_data_dir_home.json diff --git a/monkey/monkey_island/cc/testing/logger_config.json b/monkey/tests/resources/logger_config.json similarity index 100% rename from monkey/monkey_island/cc/testing/logger_config.json rename to monkey/tests/resources/logger_config.json diff --git a/monkey/monkey_island/cc/testing/mongo_key.bin b/monkey/tests/resources/mongo_key.bin similarity index 100% rename from monkey/monkey_island/cc/testing/mongo_key.bin rename to monkey/tests/resources/mongo_key.bin diff --git a/monkey/tests/resources/server_config_no_credentials.json b/monkey/tests/resources/server_config_no_credentials.json new file mode 100644 index 000000000..ecc4c1708 --- /dev/null +++ b/monkey/tests/resources/server_config_no_credentials.json @@ -0,0 +1,4 @@ +{ + "server_config": "password", + "deployment": "develop" +} diff --git a/monkey/tests/resources/server_config_with_credentials.json b/monkey/tests/resources/server_config_with_credentials.json new file mode 100644 index 000000000..ecc4c1708 --- /dev/null +++ b/monkey/tests/resources/server_config_with_credentials.json @@ -0,0 +1,4 @@ +{ + "server_config": "password", + "deployment": "develop" +} From 6571e0e4faacce1f105dee6f5f4712a78ea6e372 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Tue, 20 Apr 2021 12:11:46 -0400 Subject: [PATCH 12/16] Install pre-push hooks in deployment scripts --- deployment_scripts/deploy_linux.sh | 2 +- deployment_scripts/deploy_windows.ps1 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/deployment_scripts/deploy_linux.sh b/deployment_scripts/deploy_linux.sh index 940b763d5..072e14af8 100755 --- a/deployment_scripts/deploy_linux.sh +++ b/deployment_scripts/deploy_linux.sh @@ -26,7 +26,7 @@ log_message() { configure_precommit() { $1 -m pip install --user pre-commit pushd "$2" - $HOME/.local/bin/pre-commit install + $HOME/.local/bin/pre-commit install -t pre-commit -t pre-push popd } diff --git a/deployment_scripts/deploy_windows.ps1 b/deployment_scripts/deploy_windows.ps1 index 28d34904c..3438c554b 100644 --- a/deployment_scripts/deploy_windows.ps1 +++ b/deployment_scripts/deploy_windows.ps1 @@ -18,7 +18,7 @@ function Configure-precommit([String] $git_repo_dir) if ($LastExitCode) { exit } - pre-commit install + pre-commit install -t pre-commit -t pre-push if ($LastExitCode) { exit } From 4b02e3bc636d6137bd9f5cd9beb15675e643223d Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Tue, 20 Apr 2021 12:13:00 -0400 Subject: [PATCH 13/16] docs: Add pre-push hooks to manual pre-commit install instructions --- deployment_scripts/README.md | 2 +- docs/content/development/setup-development-environment.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/deployment_scripts/README.md b/deployment_scripts/README.md index ff767b33b..7281d0d4f 100644 --- a/deployment_scripts/README.md +++ b/deployment_scripts/README.md @@ -81,4 +81,4 @@ been run or all issues have not been resolved. To install and configure pre-commit manually, run `pip install --user pre-commit`. Next, go to the top level directory of this repository and run -`pre-commit install` Now, pre-commit will automatically run whenever you `git commit`. +`pre-commit install -t pre-commit -t pre-push` Now, pre-commit will automatically run whenever you `git commit`. diff --git a/docs/content/development/setup-development-environment.md b/docs/content/development/setup-development-environment.md index af4aa5e8a..b7d122778 100644 --- a/docs/content/development/setup-development-environment.md +++ b/docs/content/development/setup-development-environment.md @@ -30,4 +30,4 @@ Pre-commit is a multi-language package manager for pre-commit hooks. It will run Our CI system runs the same checks when pull requests are submitted. This system may report that the build has failed if the pre-commit hooks have not been run or all issues have not been resolved. -To install and configure pre-commit, run `pip install --user pre-commit`. Next, go to the top level directory of this repository and run `pre-commit install`. Pre-commit will now run automatically whenever you `git commit`. +To install and configure pre-commit, run `pip install --user pre-commit`. Next, go to the top level directory of this repository and run `pre-commit install -t pre-commit -t pre-push`. Pre-commit will now run automatically whenever you `git commit`. From e3a0105b04795ed460de42450c1b64085781bd3e Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Tue, 20 Apr 2021 12:16:13 -0400 Subject: [PATCH 14/16] Set default_stages to commit only --- .pre-commit-config.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 877a1b57d..4717c0f32 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,3 +1,4 @@ +default_stages: [commit] repos: - repo: https://github.com/pycqa/isort rev: 5.8.0 From a42e6312b1a2928ba9ee8a6b450e3b76736331d5 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Wed, 21 Apr 2021 08:00:24 -0400 Subject: [PATCH 15/16] tests: Remove unnecessary server configs --- monkey/tests/resources/server_config_no_credentials.json | 4 ---- monkey/tests/resources/server_config_with_credentials.json | 4 ---- 2 files changed, 8 deletions(-) delete mode 100644 monkey/tests/resources/server_config_no_credentials.json delete mode 100644 monkey/tests/resources/server_config_with_credentials.json diff --git a/monkey/tests/resources/server_config_no_credentials.json b/monkey/tests/resources/server_config_no_credentials.json deleted file mode 100644 index ecc4c1708..000000000 --- a/monkey/tests/resources/server_config_no_credentials.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "server_config": "password", - "deployment": "develop" -} diff --git a/monkey/tests/resources/server_config_with_credentials.json b/monkey/tests/resources/server_config_with_credentials.json deleted file mode 100644 index ecc4c1708..000000000 --- a/monkey/tests/resources/server_config_with_credentials.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "server_config": "password", - "deployment": "develop" -} From 7c452d0c6f9a10650b0f9a776d66d3db32d43880 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Wed, 21 Apr 2021 08:03:01 -0400 Subject: [PATCH 16/16] tests: Remove debug print statement in conftest.py --- monkey/tests/conftest.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/monkey/tests/conftest.py b/monkey/tests/conftest.py index 89de33109..81806ef69 100644 --- a/monkey/tests/conftest.py +++ b/monkey/tests/conftest.py @@ -8,9 +8,6 @@ MONKEY_BASE_PATH = str(Path(__file__).parent.parent) sys.path.insert(0, MONKEY_BASE_PATH) -print("imported") - - @pytest.fixture(scope="session") def resources_dir(pytestconfig): return os.path.join(pytestconfig.rootdir, "monkey", "tests", "resources")