From c832738a8a109582a9eabe033a655c91252d6949 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Tue, 11 May 2021 14:36:19 -0400 Subject: [PATCH] island: Remove all references to data_dir in EnvironmentConfig --- .../cc/environment/environment_config.py | 9 ------ monkey/tests/conftest.py | 10 ------ .../cc/environment/test_environment_config.py | 32 +++---------------- .../server_config_with_data_dir.json | 9 ------ .../server_config_with_data_dir_home.json | 9 ------ 5 files changed, 5 insertions(+), 64 deletions(-) delete mode 100644 monkey/tests/resources/environment/server_config_with_data_dir.json delete mode 100644 monkey/tests/resources/environment/server_config_with_data_dir_home.json diff --git a/monkey/monkey_island/cc/environment/environment_config.py b/monkey/monkey_island/cc/environment/environment_config.py index d2974e058..6f4626c9e 100644 --- a/monkey/monkey_island/cc/environment/environment_config.py +++ b/monkey/monkey_island/cc/environment/environment_config.py @@ -9,7 +9,6 @@ import monkey_island.cc.environment.server_config_generator as server_config_gen from monkey_island.cc.environment.user_creds import UserCreds from monkey_island.cc.resources.auth.auth_user import User from monkey_island.cc.resources.auth.user_store import UserStore -from monkey_island.cc.server_utils.consts import DEFAULT_DATA_DIR class EnvironmentConfig: @@ -19,7 +18,6 @@ class EnvironmentConfig: self.deployment = None self.user_creds = None self.aws = None - self.data_dir = None self._load_from_file(self._server_config_path) @@ -39,17 +37,11 @@ class EnvironmentConfig: def _load_from_dict(self, dict_data: Dict): aws = dict_data["aws"] if "aws" in dict_data else None - data_dir = dict_data["data_dir"] if "data_dir" in dict_data else DEFAULT_DATA_DIR self.server_config = dict_data["server_config"] self.deployment = dict_data["deployment"] self.user_creds = _get_user_credentials_from_config(dict_data) self.aws = aws - self.data_dir = data_dir - - @property - def data_dir_abs_path(self): - return os.path.abspath(os.path.expanduser(os.path.expandvars(self.data_dir))) def save_to_file(self): with open(self._server_config_path, "r") as f: @@ -64,7 +56,6 @@ class EnvironmentConfig: config_dict = { "server_config": self.server_config, "deployment": self.deployment, - "data_dir": self.data_dir, } if self.aws: config_dict.update({"aws": self.aws}) diff --git a/monkey/tests/conftest.py b/monkey/tests/conftest.py index 328cb109c..20e57f4d0 100644 --- a/monkey/tests/conftest.py +++ b/monkey/tests/conftest.py @@ -38,16 +38,6 @@ 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") - - @pytest.fixture(scope="session") def server_config_resources_dir(resources_dir): return os.path.join(resources_dir, "server_configs") 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 a5efe40f9..6968a18aa 100644 --- a/monkey/tests/monkey_island/cc/environment/test_environment_config.py +++ b/monkey/tests/monkey_island/cc/environment/test_environment_config.py @@ -6,7 +6,6 @@ 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 @pytest.fixture @@ -17,31 +16,28 @@ def config_file(tmpdir): def test_get_with_credentials(with_credentials): config_dict = EnvironmentConfig(with_credentials).to_dict() - assert len(config_dict.keys()) == 5 + assert len(config_dict.keys()) == 4 assert config_dict["server_config"] == "password" assert config_dict["deployment"] == "develop" assert config_dict["user"] == "test" assert config_dict["password_hash"] == "abcdef" - assert config_dict["data_dir"] == DEFAULT_DATA_DIR def test_get_with_no_credentials(no_credentials): config_dict = EnvironmentConfig(no_credentials).to_dict() - assert len(config_dict.keys()) == 3 + assert len(config_dict.keys()) == 2 assert config_dict["server_config"] == "password" assert config_dict["deployment"] == "develop" - assert config_dict["data_dir"] == DEFAULT_DATA_DIR def test_get_with_partial_credentials(partial_credentials): config_dict = EnvironmentConfig(partial_credentials).to_dict() - assert len(config_dict.keys()) == 4 + assert len(config_dict.keys()) == 3 assert config_dict["server_config"] == "password" assert config_dict["deployment"] == "develop" assert config_dict["user"] == "test" - assert config_dict["data_dir"] == DEFAULT_DATA_DIR def test_save_to_file(config_file, standard_with_credentials): @@ -55,13 +51,12 @@ def test_save_to_file(config_file, standard_with_credentials): from_file = json.load(f) assert len(from_file.keys()) == 2 - assert len(from_file["environment"].keys()) == 6 + assert len(from_file["environment"].keys()) == 5 assert from_file["environment"]["server_config"] == "standard" assert from_file["environment"]["deployment"] == "develop" assert from_file["environment"]["user"] == "test" assert from_file["environment"]["password_hash"] == "abcdef" assert from_file["environment"]["aws"] == "test_aws" - assert from_file["environment"]["data_dir"] == DEFAULT_DATA_DIR def test_save_to_file_preserve_log_level(config_file, standard_with_credentials): @@ -92,7 +87,7 @@ def test_add_user(config_file, standard_with_credentials): with open(config_file, "r") as f: from_file = json.load(f) - assert len(from_file["environment"].keys()) == 5 + assert len(from_file["environment"].keys()) == 4 assert from_file["environment"]["user"] == new_user assert from_file["environment"]["password_hash"] == new_password_hash @@ -117,20 +112,3 @@ def test_generate_default_file(config_file): assert environment_config.user_creds.username == "" assert environment_config.user_creds.password_hash == "" assert environment_config.aws is None - assert environment_config.data_dir == DEFAULT_DATA_DIR - - -def test_data_dir(with_data_dir): - environment_config = EnvironmentConfig(with_data_dir) - assert environment_config.data_dir == "/test/data/dir" - - -def set_home_env(monkeypatch, tmpdir): - monkeypatch.setenv("HOME", str(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) - assert config.data_dir_abs_path == os.path.join(tmpdir, "data_dir") diff --git a/monkey/tests/resources/environment/server_config_with_data_dir.json b/monkey/tests/resources/environment/server_config_with_data_dir.json deleted file mode 100644 index 8a9b7d75e..000000000 --- a/monkey/tests/resources/environment/server_config_with_data_dir.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "data_dir": "/test/data/dir", - "environment" : { - "server_config": "password", - "deployment": "develop", - "user": "test", - "password_hash": "abcdef" - } -} diff --git a/monkey/tests/resources/environment/server_config_with_data_dir_home.json b/monkey/tests/resources/environment/server_config_with_data_dir_home.json deleted file mode 100644 index 88f44e164..000000000 --- a/monkey/tests/resources/environment/server_config_with_data_dir_home.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "data_dir": "~/data_dir", - "environment" : { - "server_config": "password", - "deployment": "develop", - "user": "test", - "password_hash": "abcdef" - } -}