forked from p15670423/monkey
island: Remove all references to data_dir in EnvironmentConfig
This commit is contained in:
parent
fb3e66f75e
commit
c832738a8a
|
@ -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})
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
{
|
||||
"data_dir": "/test/data/dir",
|
||||
"environment" : {
|
||||
"server_config": "password",
|
||||
"deployment": "develop",
|
||||
"user": "test",
|
||||
"password_hash": "abcdef"
|
||||
}
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
{
|
||||
"data_dir": "~/data_dir",
|
||||
"environment" : {
|
||||
"server_config": "password",
|
||||
"deployment": "develop",
|
||||
"user": "test",
|
||||
"password_hash": "abcdef"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue