forked from p15670423/monkey
tests: Remove/modify tests and test data related to standard environment
This commit is contained in:
parent
739a017e91
commit
94878a0196
|
@ -1,9 +0,0 @@
|
||||||
{
|
|
||||||
"environment" : {
|
|
||||||
"server_config": "standard",
|
|
||||||
"deployment": "develop"
|
|
||||||
},
|
|
||||||
"mongodb": {
|
|
||||||
"start_mongodb": true
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,12 +0,0 @@
|
||||||
{
|
|
||||||
"log_level": "NOTICE",
|
|
||||||
"environment" : {
|
|
||||||
"server_config": "standard",
|
|
||||||
"deployment": "develop",
|
|
||||||
"user": "test",
|
|
||||||
"password_hash": "abcdef"
|
|
||||||
},
|
|
||||||
"mongodb": {
|
|
||||||
"start_mongodb": true
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,4 +1,5 @@
|
||||||
{
|
{
|
||||||
|
"log_level": "NOTICE",
|
||||||
"environment" : {
|
"environment" : {
|
||||||
"server_config": "password",
|
"server_config": "password",
|
||||||
"deployment": "develop",
|
"deployment": "develop",
|
||||||
|
|
|
@ -16,8 +16,3 @@ def no_credentials(server_configs_dir):
|
||||||
@pytest.fixture(scope="module")
|
@pytest.fixture(scope="module")
|
||||||
def partial_credentials(server_configs_dir):
|
def partial_credentials(server_configs_dir):
|
||||||
return os.path.join(server_configs_dir, "server_config_partial_credentials.json")
|
return os.path.join(server_configs_dir, "server_config_partial_credentials.json")
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="module")
|
|
||||||
def standard_with_credentials(server_configs_dir):
|
|
||||||
return os.path.join(server_configs_dir, "server_config_standard_with_credentials.json")
|
|
||||||
|
|
|
@ -17,8 +17,6 @@ from monkey_island.cc.environment import Environment, EnvironmentConfig, UserCre
|
||||||
WITH_CREDENTIALS = None
|
WITH_CREDENTIALS = None
|
||||||
NO_CREDENTIALS = None
|
NO_CREDENTIALS = None
|
||||||
PARTIAL_CREDENTIALS = None
|
PARTIAL_CREDENTIALS = None
|
||||||
STANDARD_WITH_CREDENTIALS = None
|
|
||||||
STANDARD_ENV = None
|
|
||||||
|
|
||||||
EMPTY_USER_CREDENTIALS = UserCreds("", "")
|
EMPTY_USER_CREDENTIALS = UserCreds("", "")
|
||||||
FULL_USER_CREDENTIALS = UserCreds(username="test", password_hash="1231234")
|
FULL_USER_CREDENTIALS = UserCreds(username="test", password_hash="1231234")
|
||||||
|
@ -31,16 +29,10 @@ def configure_resources(server_configs_dir):
|
||||||
global WITH_CREDENTIALS
|
global WITH_CREDENTIALS
|
||||||
global NO_CREDENTIALS
|
global NO_CREDENTIALS
|
||||||
global PARTIAL_CREDENTIALS
|
global PARTIAL_CREDENTIALS
|
||||||
global STANDARD_WITH_CREDENTIALS
|
|
||||||
global STANDARD_ENV
|
|
||||||
|
|
||||||
WITH_CREDENTIALS = os.path.join(server_configs_dir, "server_config_with_credentials.json")
|
WITH_CREDENTIALS = os.path.join(server_configs_dir, "server_config_with_credentials.json")
|
||||||
NO_CREDENTIALS = os.path.join(server_configs_dir, "server_config_no_credentials.json")
|
NO_CREDENTIALS = os.path.join(server_configs_dir, "server_config_no_credentials.json")
|
||||||
PARTIAL_CREDENTIALS = os.path.join(server_configs_dir, "server_config_partial_credentials.json")
|
PARTIAL_CREDENTIALS = os.path.join(server_configs_dir, "server_config_partial_credentials.json")
|
||||||
STANDARD_WITH_CREDENTIALS = os.path.join(
|
|
||||||
server_configs_dir, "server_config_standard_with_credentials.json"
|
|
||||||
)
|
|
||||||
STANDARD_ENV = os.path.join(server_configs_dir, "server_config_standard_env.json")
|
|
||||||
|
|
||||||
|
|
||||||
def get_tmp_file():
|
def get_tmp_file():
|
||||||
|
@ -123,29 +115,18 @@ class TestEnvironment(TestCase):
|
||||||
self._test_bool_env_method("needs_registration", env, NO_CREDENTIALS, True)
|
self._test_bool_env_method("needs_registration", env, NO_CREDENTIALS, True)
|
||||||
self._test_bool_env_method("needs_registration", env, PARTIAL_CREDENTIALS, True)
|
self._test_bool_env_method("needs_registration", env, PARTIAL_CREDENTIALS, True)
|
||||||
|
|
||||||
env = TestEnvironment.EnvironmentCredentialsNotRequired()
|
|
||||||
self._test_bool_env_method("needs_registration", env, STANDARD_ENV, False)
|
|
||||||
self._test_bool_env_method("needs_registration", env, 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, WITH_CREDENTIALS, True)
|
self._test_bool_env_method("_is_registered", env, WITH_CREDENTIALS, True)
|
||||||
self._test_bool_env_method("_is_registered", env, NO_CREDENTIALS, False)
|
self._test_bool_env_method("_is_registered", env, NO_CREDENTIALS, False)
|
||||||
self._test_bool_env_method("_is_registered", env, PARTIAL_CREDENTIALS, False)
|
self._test_bool_env_method("_is_registered", env, PARTIAL_CREDENTIALS, False)
|
||||||
|
|
||||||
env = TestEnvironment.EnvironmentCredentialsNotRequired()
|
|
||||||
self._test_bool_env_method("_is_registered", env, STANDARD_ENV, False)
|
|
||||||
self._test_bool_env_method("_is_registered", env, 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, NO_CREDENTIALS, False)
|
self._test_bool_env_method("_is_credentials_set_up", env, NO_CREDENTIALS, False)
|
||||||
self._test_bool_env_method("_is_credentials_set_up", env, WITH_CREDENTIALS, True)
|
self._test_bool_env_method("_is_credentials_set_up", env, WITH_CREDENTIALS, True)
|
||||||
self._test_bool_env_method("_is_credentials_set_up", env, PARTIAL_CREDENTIALS, False)
|
self._test_bool_env_method("_is_credentials_set_up", env, PARTIAL_CREDENTIALS, False)
|
||||||
|
|
||||||
env = TestEnvironment.EnvironmentCredentialsNotRequired()
|
|
||||||
self._test_bool_env_method("_is_credentials_set_up", env, STANDARD_ENV, False)
|
|
||||||
|
|
||||||
def _test_bool_env_method(
|
def _test_bool_env_method(
|
||||||
self, method_name: str, env: Environment, config: Dict, expected_result: bool
|
self, method_name: str, env: Environment, config: Dict, expected_result: bool
|
||||||
):
|
):
|
||||||
|
|
|
@ -40,8 +40,8 @@ def test_get_with_partial_credentials(partial_credentials):
|
||||||
assert config_dict["user"] == "test"
|
assert config_dict["user"] == "test"
|
||||||
|
|
||||||
|
|
||||||
def test_save_to_file(config_file, standard_with_credentials):
|
def test_save_to_file(config_file, with_credentials):
|
||||||
shutil.copyfile(standard_with_credentials, config_file)
|
shutil.copyfile(with_credentials, config_file)
|
||||||
|
|
||||||
environment_config = EnvironmentConfig(config_file)
|
environment_config = EnvironmentConfig(config_file)
|
||||||
environment_config.aws = "test_aws"
|
environment_config.aws = "test_aws"
|
||||||
|
@ -53,8 +53,8 @@ def test_save_to_file(config_file, standard_with_credentials):
|
||||||
assert environment_config.to_dict() == from_file["environment"]
|
assert environment_config.to_dict() == from_file["environment"]
|
||||||
|
|
||||||
|
|
||||||
def test_save_to_file_preserve_log_level(config_file, standard_with_credentials):
|
def test_save_to_file_preserve_log_level(config_file, with_credentials):
|
||||||
shutil.copyfile(standard_with_credentials, config_file)
|
shutil.copyfile(with_credentials, config_file)
|
||||||
|
|
||||||
environment_config = EnvironmentConfig(config_file)
|
environment_config = EnvironmentConfig(config_file)
|
||||||
environment_config.aws = "test_aws"
|
environment_config.aws = "test_aws"
|
||||||
|
@ -67,12 +67,12 @@ def test_save_to_file_preserve_log_level(config_file, standard_with_credentials)
|
||||||
assert from_file["log_level"] == "NOTICE"
|
assert from_file["log_level"] == "NOTICE"
|
||||||
|
|
||||||
|
|
||||||
def test_add_user(config_file, standard_with_credentials):
|
def test_add_user(config_file, with_credentials):
|
||||||
new_user = "new_user"
|
new_user = "new_user"
|
||||||
new_password_hash = "fedcba"
|
new_password_hash = "fedcba"
|
||||||
new_user_creds = UserCreds(new_user, new_password_hash)
|
new_user_creds = UserCreds(new_user, new_password_hash)
|
||||||
|
|
||||||
shutil.copyfile(standard_with_credentials, config_file)
|
shutil.copyfile(with_credentials, config_file)
|
||||||
|
|
||||||
environment_config = EnvironmentConfig(config_file)
|
environment_config = EnvironmentConfig(config_file)
|
||||||
environment_config.add_user(new_user_creds)
|
environment_config.add_user(new_user_creds)
|
||||||
|
@ -85,8 +85,8 @@ def test_add_user(config_file, standard_with_credentials):
|
||||||
assert from_file["environment"]["password_hash"] == new_password_hash
|
assert from_file["environment"]["password_hash"] == new_password_hash
|
||||||
|
|
||||||
|
|
||||||
def test_get_users(standard_with_credentials):
|
def test_get_users(with_credentials):
|
||||||
environment_config = EnvironmentConfig(standard_with_credentials)
|
environment_config = EnvironmentConfig(with_credentials)
|
||||||
users = environment_config.get_users()
|
users = environment_config.get_users()
|
||||||
|
|
||||||
assert len(users) == 1
|
assert len(users) == 1
|
||||||
|
|
Loading…
Reference in New Issue