From 9b5029a05c63ad0e9067eab709833046d96baa9b Mon Sep 17 00:00:00 2001 From: VakarisZ Date: Mon, 22 Jun 2020 16:59:51 +0300 Subject: [PATCH] Lowered the amount of python lint warnings with small style improvements --- .../test_pypykatz_handler.py | 12 +++++--- .../cc/environment/test__init__.py | 30 +++++++++---------- .../cc/environment/test_environment_config.py | 24 +++++++-------- 3 files changed, 35 insertions(+), 31 deletions(-) diff --git a/monkey/infection_monkey/system_info/windows_cred_collector/test_pypykatz_handler.py b/monkey/infection_monkey/system_info/windows_cred_collector/test_pypykatz_handler.py index b0ae2d751..165b00cf2 100644 --- a/monkey/infection_monkey/system_info/windows_cred_collector/test_pypykatz_handler.py +++ b/monkey/infection_monkey/system_info/windows_cred_collector/test_pypykatz_handler.py @@ -23,16 +23,20 @@ class TestPypykatzHandler(TestCase): 'password': 'canyoufindm3', 'luid': 123086}], 'dpapi_creds': [ {'credtype': 'dpapi', 'key_guid': '9123-123ae123de4-121239-3123-421f', - 'masterkey': '6e81d0cfd5e9ec083cfbdaf4d25b9cc9cc6b72947f5e80920034d1275d8613532025975ef051e891c30e6e9af6db54500fedfed1c968389bf6262c77fbaa68c9', + 'masterkey': '6e81d0cfd5e9ec083cfbdaf4d25b9cc9cc6b72947f5e80920034d1275d8613532025975e' + 'f051e891c30e6e9af6db54500fedfed1c968389bf6262c77fbaa68c9', 'sha1_masterkey': 'bbdabc3cd2f6bcbe3e2cee6ce4ce4cebcef4c6da', 'luid': 123086}, {'credtype': 'dpapi', 'key_guid': '9123-123ae123de4-121239-3123-421f', - 'masterkey': '6e81d0cfd5e9ec083cfbdaf4d25b9cc9cc6b72947f5e80920034d1275d8613532025975ef051e891c30e6e9af6db54500fedfed1c968389bf6262c77fbaa68c9', + 'masterkey': '6e81d0cfd5e9ec083cfbdaf4d25b9cc9cc6b72947f5e80920034d1275d8613532025975e' + 'f051e891c30e6e9af6db54500fedfed1c968389bf6262c77fbaa68c9', 'sha1_masterkey': 'bbdabc3cd2f6bcbe3e2cee6ce4ce4cebcef4c6da', 'luid': 123086}, {'credtype': 'dpapi', 'key_guid': '9123-123ae123de4-121239-3123-421f', - 'masterkey': '6e81d0cfd5e9ec083cfbdaf4d25b9cc9cc6b72947f5e80920034d1275d8613532025975ef051e891c30e6e9af6db54500fedfed1c968389bf6262c77fbaa68c9', + 'masterkey': '6e81d0cfd5e9ec083cfbdaf4d25b9cc9cc6b72947f5e80920034d1275d8613532025975e' + 'f051e891c30e6e9af6db54500fedfed1c968389bf6262c77fbaa68c9', 'sha1_masterkey': 'bbdabc3cd2f6bcbe3e2cee6ce4ce4cebcef4c6da', 'luid': 123086}, {'credtype': 'dpapi', 'key_guid': '9123-123ae123de4-121239-3123-421f', - 'masterkey': '6e81d0cfd5e9ec083cfbdaf4d25b9cc9cc6b72947f5e80920034d1275d8613532025975ef051e891c30e6e9af6db54500fedfed1c968389bf6262c77fbaa68c9', + 'masterkey': '6e81d0cfd5e9ec083cfbdaf4d25b9cc9cc6b72947f5e80920034d1275d8613532025975e' + 'f051e891c30e6e9af6db54500fedfed1c968389bf6262c77fbaa68c9', 'sha1_masterkey': 'bbdabc3cd2f6bcbe3e2cee6ce4ce4cebcef4c6da', 'luid': 123086}, {'credtype': 'dpapi', 'key_guid': '9123-123ae123de4-121239-3123-421f'}], 'kerberos_creds': [ diff --git a/monkey/monkey_island/cc/environment/test__init__.py b/monkey/monkey_island/cc/environment/test__init__.py index 870673013..6e571ad2c 100644 --- a/monkey/monkey_island/cc/environment/test__init__.py +++ b/monkey/monkey_island/cc/environment/test__init__.py @@ -7,7 +7,7 @@ from unittest.mock import patch, MagicMock from common.utils.exceptions import InvalidRegistrationCredentialsError, AlreadyRegisteredError, \ CredentialsNotRequiredError, RegistrationNotNeededError from monkey_island.cc.environment import Environment, EnvironmentConfig, UserCreds -from monkey_island.cc.testing.environment.server_config_mocks import * +import monkey_island.cc.testing.environment.server_config_mocks as config_mocks def get_server_config_file_path_test_version(): @@ -75,32 +75,32 @@ class TestEnvironment(TestCase): def test_needs_registration(self): env = TestEnvironment.EnvironmentCredentialsRequired() - self._test_bool_env_method("needs_registration", env, CONFIG_WITH_CREDENTIALS, False) - self._test_bool_env_method("needs_registration", env, CONFIG_NO_CREDENTIALS, True) - self._test_bool_env_method("needs_registration", env, CONFIG_PARTIAL_CREDENTIALS, True) + self._test_bool_env_method("needs_registration", env, config_mocks.CONFIG_WITH_CREDENTIALS, False) + self._test_bool_env_method("needs_registration", env, config_mocks.CONFIG_NO_CREDENTIALS, True) + self._test_bool_env_method("needs_registration", env, config_mocks.CONFIG_PARTIAL_CREDENTIALS, True) env = TestEnvironment.EnvironmentCredentialsNotRequired() - self._test_bool_env_method("needs_registration", env, CONFIG_STANDARD_ENV, False) - self._test_bool_env_method("needs_registration", env, CONFIG_STANDARD_WITH_CREDENTIALS, False) + self._test_bool_env_method("needs_registration", env, config_mocks.CONFIG_STANDARD_ENV, False) + self._test_bool_env_method("needs_registration", env, config_mocks.CONFIG_STANDARD_WITH_CREDENTIALS, False) def test_is_registered(self): env = TestEnvironment.EnvironmentCredentialsRequired() - self._test_bool_env_method("_is_registered", env, CONFIG_WITH_CREDENTIALS, True) - self._test_bool_env_method("_is_registered", env, CONFIG_NO_CREDENTIALS, False) - self._test_bool_env_method("_is_registered", env, CONFIG_PARTIAL_CREDENTIALS, False) + self._test_bool_env_method("_is_registered", env, config_mocks.CONFIG_WITH_CREDENTIALS, True) + self._test_bool_env_method("_is_registered", env, config_mocks.CONFIG_NO_CREDENTIALS, False) + self._test_bool_env_method("_is_registered", env, config_mocks.CONFIG_PARTIAL_CREDENTIALS, False) env = TestEnvironment.EnvironmentCredentialsNotRequired() - self._test_bool_env_method("_is_registered", env, CONFIG_STANDARD_ENV, False) - self._test_bool_env_method("_is_registered", env, CONFIG_STANDARD_WITH_CREDENTIALS, False) + self._test_bool_env_method("_is_registered", env, config_mocks.CONFIG_STANDARD_ENV, False) + self._test_bool_env_method("_is_registered", env, config_mocks.CONFIG_STANDARD_WITH_CREDENTIALS, False) def test_is_credentials_set_up(self): env = TestEnvironment.EnvironmentCredentialsRequired() - self._test_bool_env_method("_is_credentials_set_up", env, CONFIG_NO_CREDENTIALS, False) - self._test_bool_env_method("_is_credentials_set_up", env, CONFIG_WITH_CREDENTIALS, True) - self._test_bool_env_method("_is_credentials_set_up", env, CONFIG_PARTIAL_CREDENTIALS, False) + self._test_bool_env_method("_is_credentials_set_up", env, config_mocks.CONFIG_NO_CREDENTIALS, False) + self._test_bool_env_method("_is_credentials_set_up", env, config_mocks.CONFIG_WITH_CREDENTIALS, True) + self._test_bool_env_method("_is_credentials_set_up", env, config_mocks.CONFIG_PARTIAL_CREDENTIALS, False) env = TestEnvironment.EnvironmentCredentialsNotRequired() - self._test_bool_env_method("_is_credentials_set_up", env, CONFIG_STANDARD_ENV, False) + self._test_bool_env_method("_is_credentials_set_up", env, config_mocks.CONFIG_STANDARD_ENV, False) def _test_bool_env_method(self, method_name: str, env: Environment, config: Dict, expected_result: bool): env._config = EnvironmentConfig.get_from_json(json.dumps(config)) diff --git a/monkey/monkey_island/cc/environment/test_environment_config.py b/monkey/monkey_island/cc/environment/test_environment_config.py index c49444ce4..95882e63e 100644 --- a/monkey/monkey_island/cc/environment/test_environment_config.py +++ b/monkey/monkey_island/cc/environment/test_environment_config.py @@ -8,7 +8,7 @@ from unittest.mock import patch, MagicMock from monkey_island.cc.consts import MONKEY_ISLAND_ABS_PATH from monkey_island.cc.environment.environment_config import EnvironmentConfig from monkey_island.cc.environment.user_creds import UserCreds -from monkey_island.cc.testing.environment.server_config_mocks import * +import monkey_island.cc.testing.environment.server_config_mocks as config_mocks def get_server_config_file_path_test_version(): @@ -18,9 +18,9 @@ def get_server_config_file_path_test_version(): class TestEnvironmentConfig(TestCase): def test_get_from_json(self): - self._test_get_from_json(CONFIG_WITH_CREDENTIALS) - self._test_get_from_json(CONFIG_NO_CREDENTIALS) - self._test_get_from_json(CONFIG_PARTIAL_CREDENTIALS) + self._test_get_from_json(config_mocks.CONFIG_WITH_CREDENTIALS) + self._test_get_from_json(config_mocks.CONFIG_NO_CREDENTIALS) + self._test_get_from_json(config_mocks.CONFIG_PARTIAL_CREDENTIALS) def _test_get_from_json(self, config: Dict): config_json = json.dumps(config) @@ -35,9 +35,9 @@ class TestEnvironmentConfig(TestCase): self.assertEqual(config['aws'], env_config_object.aws) def test_save_to_file(self): - self._test_save_to_file(CONFIG_WITH_CREDENTIALS) - self._test_save_to_file(CONFIG_NO_CREDENTIALS) - self._test_save_to_file(CONFIG_PARTIAL_CREDENTIALS) + self._test_save_to_file(config_mocks.CONFIG_WITH_CREDENTIALS) + self._test_save_to_file(config_mocks.CONFIG_NO_CREDENTIALS) + self._test_save_to_file(config_mocks.CONFIG_PARTIAL_CREDENTIALS) @patch.object(target=EnvironmentConfig, attribute="get_config_file_path", new=MagicMock(return_value=get_server_config_file_path_test_version())) @@ -63,14 +63,14 @@ class TestEnvironmentConfig(TestCase): self.assertEqual(EnvironmentConfig.get_config_file_path(), server_file_path) def test_get_from_dict(self): - config_dict = CONFIG_WITH_CREDENTIALS + config_dict = config_mocks.CONFIG_WITH_CREDENTIALS env_conf = EnvironmentConfig.get_from_dict(config_dict) self.assertEqual(env_conf.server_config, config_dict['server_config']) self.assertEqual(env_conf.deployment, config_dict['deployment']) self.assertEqual(env_conf.user_creds.username, config_dict['user']) self.assertEqual(env_conf.aws, None) - config_dict = CONFIG_BOGUS_VALUES + config_dict = config_mocks.CONFIG_BOGUS_VALUES env_conf = EnvironmentConfig.get_from_dict(config_dict) self.assertEqual(env_conf.server_config, config_dict['server_config']) self.assertEqual(env_conf.deployment, config_dict['deployment']) @@ -78,13 +78,13 @@ class TestEnvironmentConfig(TestCase): self.assertEqual(env_conf.aws, config_dict['aws']) def test_to_dict(self): - conf_json1 = json.dumps(CONFIG_WITH_CREDENTIALS) + conf_json1 = json.dumps(config_mocks.CONFIG_WITH_CREDENTIALS) self._test_to_dict(EnvironmentConfig.get_from_json(conf_json1)) - conf_json2 = json.dumps(CONFIG_NO_CREDENTIALS) + conf_json2 = json.dumps(config_mocks.CONFIG_NO_CREDENTIALS) self._test_to_dict(EnvironmentConfig.get_from_json(conf_json2)) - conf_json3 = json.dumps(CONFIG_PARTIAL_CREDENTIALS) + conf_json3 = json.dumps(config_mocks.CONFIG_PARTIAL_CREDENTIALS) self._test_to_dict(EnvironmentConfig.get_from_json(conf_json3)) def _test_to_dict(self, env_config_object: EnvironmentConfig):