forked from p15670423/monkey
Lowered the amount of python lint warnings with small style improvements
This commit is contained in:
parent
90b05a184b
commit
9b5029a05c
|
@ -23,16 +23,20 @@ class TestPypykatzHandler(TestCase):
|
||||||
'password': 'canyoufindm3', 'luid': 123086}],
|
'password': 'canyoufindm3', 'luid': 123086}],
|
||||||
'dpapi_creds': [
|
'dpapi_creds': [
|
||||||
{'credtype': 'dpapi', 'key_guid': '9123-123ae123de4-121239-3123-421f',
|
{'credtype': 'dpapi', 'key_guid': '9123-123ae123de4-121239-3123-421f',
|
||||||
'masterkey': '6e81d0cfd5e9ec083cfbdaf4d25b9cc9cc6b72947f5e80920034d1275d8613532025975ef051e891c30e6e9af6db54500fedfed1c968389bf6262c77fbaa68c9',
|
'masterkey': '6e81d0cfd5e9ec083cfbdaf4d25b9cc9cc6b72947f5e80920034d1275d8613532025975e'
|
||||||
|
'f051e891c30e6e9af6db54500fedfed1c968389bf6262c77fbaa68c9',
|
||||||
'sha1_masterkey': 'bbdabc3cd2f6bcbe3e2cee6ce4ce4cebcef4c6da', 'luid': 123086},
|
'sha1_masterkey': 'bbdabc3cd2f6bcbe3e2cee6ce4ce4cebcef4c6da', 'luid': 123086},
|
||||||
{'credtype': 'dpapi', 'key_guid': '9123-123ae123de4-121239-3123-421f',
|
{'credtype': 'dpapi', 'key_guid': '9123-123ae123de4-121239-3123-421f',
|
||||||
'masterkey': '6e81d0cfd5e9ec083cfbdaf4d25b9cc9cc6b72947f5e80920034d1275d8613532025975ef051e891c30e6e9af6db54500fedfed1c968389bf6262c77fbaa68c9',
|
'masterkey': '6e81d0cfd5e9ec083cfbdaf4d25b9cc9cc6b72947f5e80920034d1275d8613532025975e'
|
||||||
|
'f051e891c30e6e9af6db54500fedfed1c968389bf6262c77fbaa68c9',
|
||||||
'sha1_masterkey': 'bbdabc3cd2f6bcbe3e2cee6ce4ce4cebcef4c6da', 'luid': 123086},
|
'sha1_masterkey': 'bbdabc3cd2f6bcbe3e2cee6ce4ce4cebcef4c6da', 'luid': 123086},
|
||||||
{'credtype': 'dpapi', 'key_guid': '9123-123ae123de4-121239-3123-421f',
|
{'credtype': 'dpapi', 'key_guid': '9123-123ae123de4-121239-3123-421f',
|
||||||
'masterkey': '6e81d0cfd5e9ec083cfbdaf4d25b9cc9cc6b72947f5e80920034d1275d8613532025975ef051e891c30e6e9af6db54500fedfed1c968389bf6262c77fbaa68c9',
|
'masterkey': '6e81d0cfd5e9ec083cfbdaf4d25b9cc9cc6b72947f5e80920034d1275d8613532025975e'
|
||||||
|
'f051e891c30e6e9af6db54500fedfed1c968389bf6262c77fbaa68c9',
|
||||||
'sha1_masterkey': 'bbdabc3cd2f6bcbe3e2cee6ce4ce4cebcef4c6da', 'luid': 123086},
|
'sha1_masterkey': 'bbdabc3cd2f6bcbe3e2cee6ce4ce4cebcef4c6da', 'luid': 123086},
|
||||||
{'credtype': 'dpapi', 'key_guid': '9123-123ae123de4-121239-3123-421f',
|
{'credtype': 'dpapi', 'key_guid': '9123-123ae123de4-121239-3123-421f',
|
||||||
'masterkey': '6e81d0cfd5e9ec083cfbdaf4d25b9cc9cc6b72947f5e80920034d1275d8613532025975ef051e891c30e6e9af6db54500fedfed1c968389bf6262c77fbaa68c9',
|
'masterkey': '6e81d0cfd5e9ec083cfbdaf4d25b9cc9cc6b72947f5e80920034d1275d8613532025975e'
|
||||||
|
'f051e891c30e6e9af6db54500fedfed1c968389bf6262c77fbaa68c9',
|
||||||
'sha1_masterkey': 'bbdabc3cd2f6bcbe3e2cee6ce4ce4cebcef4c6da', 'luid': 123086},
|
'sha1_masterkey': 'bbdabc3cd2f6bcbe3e2cee6ce4ce4cebcef4c6da', 'luid': 123086},
|
||||||
{'credtype': 'dpapi', 'key_guid': '9123-123ae123de4-121239-3123-421f'}],
|
{'credtype': 'dpapi', 'key_guid': '9123-123ae123de4-121239-3123-421f'}],
|
||||||
'kerberos_creds': [
|
'kerberos_creds': [
|
||||||
|
|
|
@ -7,7 +7,7 @@ from unittest.mock import patch, MagicMock
|
||||||
from common.utils.exceptions import InvalidRegistrationCredentialsError, AlreadyRegisteredError, \
|
from common.utils.exceptions import InvalidRegistrationCredentialsError, AlreadyRegisteredError, \
|
||||||
CredentialsNotRequiredError, RegistrationNotNeededError
|
CredentialsNotRequiredError, RegistrationNotNeededError
|
||||||
from monkey_island.cc.environment import Environment, EnvironmentConfig, UserCreds
|
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():
|
def get_server_config_file_path_test_version():
|
||||||
|
@ -75,32 +75,32 @@ class TestEnvironment(TestCase):
|
||||||
|
|
||||||
def test_needs_registration(self):
|
def test_needs_registration(self):
|
||||||
env = TestEnvironment.EnvironmentCredentialsRequired()
|
env = TestEnvironment.EnvironmentCredentialsRequired()
|
||||||
self._test_bool_env_method("needs_registration", env, CONFIG_WITH_CREDENTIALS, False)
|
self._test_bool_env_method("needs_registration", env, config_mocks.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_mocks.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_PARTIAL_CREDENTIALS, True)
|
||||||
|
|
||||||
env = TestEnvironment.EnvironmentCredentialsNotRequired()
|
env = TestEnvironment.EnvironmentCredentialsNotRequired()
|
||||||
self._test_bool_env_method("needs_registration", env, CONFIG_STANDARD_ENV, False)
|
self._test_bool_env_method("needs_registration", env, config_mocks.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_WITH_CREDENTIALS, False)
|
||||||
|
|
||||||
def test_is_registered(self):
|
def test_is_registered(self):
|
||||||
env = TestEnvironment.EnvironmentCredentialsRequired()
|
env = TestEnvironment.EnvironmentCredentialsRequired()
|
||||||
self._test_bool_env_method("_is_registered", env, CONFIG_WITH_CREDENTIALS, True)
|
self._test_bool_env_method("_is_registered", env, config_mocks.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_mocks.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_PARTIAL_CREDENTIALS, False)
|
||||||
|
|
||||||
env = TestEnvironment.EnvironmentCredentialsNotRequired()
|
env = TestEnvironment.EnvironmentCredentialsNotRequired()
|
||||||
self._test_bool_env_method("_is_registered", env, CONFIG_STANDARD_ENV, False)
|
self._test_bool_env_method("_is_registered", env, config_mocks.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_WITH_CREDENTIALS, False)
|
||||||
|
|
||||||
def test_is_credentials_set_up(self):
|
def test_is_credentials_set_up(self):
|
||||||
env = TestEnvironment.EnvironmentCredentialsRequired()
|
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_mocks.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_mocks.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_PARTIAL_CREDENTIALS, False)
|
||||||
|
|
||||||
env = TestEnvironment.EnvironmentCredentialsNotRequired()
|
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):
|
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))
|
env._config = EnvironmentConfig.get_from_json(json.dumps(config))
|
||||||
|
|
|
@ -8,7 +8,7 @@ from unittest.mock import patch, MagicMock
|
||||||
from monkey_island.cc.consts import MONKEY_ISLAND_ABS_PATH
|
from monkey_island.cc.consts import MONKEY_ISLAND_ABS_PATH
|
||||||
from monkey_island.cc.environment.environment_config import EnvironmentConfig
|
from monkey_island.cc.environment.environment_config import EnvironmentConfig
|
||||||
from monkey_island.cc.environment.user_creds import UserCreds
|
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():
|
def get_server_config_file_path_test_version():
|
||||||
|
@ -18,9 +18,9 @@ def get_server_config_file_path_test_version():
|
||||||
class TestEnvironmentConfig(TestCase):
|
class TestEnvironmentConfig(TestCase):
|
||||||
|
|
||||||
def test_get_from_json(self):
|
def test_get_from_json(self):
|
||||||
self._test_get_from_json(CONFIG_WITH_CREDENTIALS)
|
self._test_get_from_json(config_mocks.CONFIG_WITH_CREDENTIALS)
|
||||||
self._test_get_from_json(CONFIG_NO_CREDENTIALS)
|
self._test_get_from_json(config_mocks.CONFIG_NO_CREDENTIALS)
|
||||||
self._test_get_from_json(CONFIG_PARTIAL_CREDENTIALS)
|
self._test_get_from_json(config_mocks.CONFIG_PARTIAL_CREDENTIALS)
|
||||||
|
|
||||||
def _test_get_from_json(self, config: Dict):
|
def _test_get_from_json(self, config: Dict):
|
||||||
config_json = json.dumps(config)
|
config_json = json.dumps(config)
|
||||||
|
@ -35,9 +35,9 @@ class TestEnvironmentConfig(TestCase):
|
||||||
self.assertEqual(config['aws'], env_config_object.aws)
|
self.assertEqual(config['aws'], env_config_object.aws)
|
||||||
|
|
||||||
def test_save_to_file(self):
|
def test_save_to_file(self):
|
||||||
self._test_save_to_file(CONFIG_WITH_CREDENTIALS)
|
self._test_save_to_file(config_mocks.CONFIG_WITH_CREDENTIALS)
|
||||||
self._test_save_to_file(CONFIG_NO_CREDENTIALS)
|
self._test_save_to_file(config_mocks.CONFIG_NO_CREDENTIALS)
|
||||||
self._test_save_to_file(CONFIG_PARTIAL_CREDENTIALS)
|
self._test_save_to_file(config_mocks.CONFIG_PARTIAL_CREDENTIALS)
|
||||||
|
|
||||||
@patch.object(target=EnvironmentConfig, attribute="get_config_file_path",
|
@patch.object(target=EnvironmentConfig, attribute="get_config_file_path",
|
||||||
new=MagicMock(return_value=get_server_config_file_path_test_version()))
|
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)
|
self.assertEqual(EnvironmentConfig.get_config_file_path(), server_file_path)
|
||||||
|
|
||||||
def test_get_from_dict(self):
|
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)
|
env_conf = EnvironmentConfig.get_from_dict(config_dict)
|
||||||
self.assertEqual(env_conf.server_config, config_dict['server_config'])
|
self.assertEqual(env_conf.server_config, config_dict['server_config'])
|
||||||
self.assertEqual(env_conf.deployment, config_dict['deployment'])
|
self.assertEqual(env_conf.deployment, config_dict['deployment'])
|
||||||
self.assertEqual(env_conf.user_creds.username, config_dict['user'])
|
self.assertEqual(env_conf.user_creds.username, config_dict['user'])
|
||||||
self.assertEqual(env_conf.aws, None)
|
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)
|
env_conf = EnvironmentConfig.get_from_dict(config_dict)
|
||||||
self.assertEqual(env_conf.server_config, config_dict['server_config'])
|
self.assertEqual(env_conf.server_config, config_dict['server_config'])
|
||||||
self.assertEqual(env_conf.deployment, config_dict['deployment'])
|
self.assertEqual(env_conf.deployment, config_dict['deployment'])
|
||||||
|
@ -78,13 +78,13 @@ class TestEnvironmentConfig(TestCase):
|
||||||
self.assertEqual(env_conf.aws, config_dict['aws'])
|
self.assertEqual(env_conf.aws, config_dict['aws'])
|
||||||
|
|
||||||
def test_to_dict(self):
|
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))
|
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))
|
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))
|
self._test_to_dict(EnvironmentConfig.get_from_json(conf_json3))
|
||||||
|
|
||||||
def _test_to_dict(self, env_config_object: EnvironmentConfig):
|
def _test_to_dict(self, env_config_object: EnvironmentConfig):
|
||||||
|
|
Loading…
Reference in New Issue