forked from p15670423/monkey
island: Add tests for default server config values
This commit is contained in:
parent
990244c3ac
commit
de7865aa21
|
@ -18,7 +18,7 @@ if "__main__" == __name__:
|
||||||
try:
|
try:
|
||||||
server_config_path = os.path.expanduser(island_args.server_config)
|
server_config_path = os.path.expanduser(island_args.server_config)
|
||||||
|
|
||||||
config = config_loader.load_server_config(server_config_path)
|
config = config_loader.load_server_config_from_file(server_config_path)
|
||||||
|
|
||||||
setup_logging(config["data_dir"], config["log_level"])
|
setup_logging(config["data_dir"], config["log_level"])
|
||||||
|
|
||||||
|
|
|
@ -6,15 +6,21 @@ from monkey_island.cc.server_utils.consts import DEFAULT_DATA_DIR
|
||||||
DEFAULT_LOG_LEVEL = "INFO"
|
DEFAULT_LOG_LEVEL = "INFO"
|
||||||
|
|
||||||
|
|
||||||
def load_server_config(server_config_path):
|
def load_server_config_from_file(server_config_path):
|
||||||
with open(server_config_path, "r") as f:
|
with open(server_config_path, "r") as f:
|
||||||
config_content = f.read()
|
config_content = f.read()
|
||||||
config = json.loads(config_content)
|
config = json.loads(config_content)
|
||||||
config["data_dir"] = os.path.abspath(
|
add_default_values_to_config(config)
|
||||||
os.path.expanduser(
|
|
||||||
os.path.expandvars(config["data_dir"] if "data_dir" in config else DEFAULT_DATA_DIR)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
config["log_level"] = config["log_level"] if "log_level" in config else DEFAULT_LOG_LEVEL
|
|
||||||
|
|
||||||
return config
|
return config
|
||||||
|
|
||||||
|
|
||||||
|
def add_default_values_to_config(config):
|
||||||
|
config["data_dir"] = os.path.abspath(
|
||||||
|
os.path.expanduser(
|
||||||
|
os.path.expandvars(config["data_dir"] if "data_dir" in config else DEFAULT_DATA_DIR)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
config["log_level"] = config["log_level"] if "log_level" in config else DEFAULT_LOG_LEVEL
|
||||||
|
|
||||||
|
return config
|
||||||
|
|
|
@ -1,10 +1,27 @@
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from monkey_island import config_loader
|
from monkey_island import config_loader
|
||||||
|
from monkey_island.cc.server_utils.consts import DEFAULT_DATA_DIR
|
||||||
|
|
||||||
|
|
||||||
def test_load_server_config_from_file(test_server_config, mock_home_env):
|
def test_load_server_config_from_file(test_server_config, mock_home_env):
|
||||||
config = config_loader.load_server_config(test_server_config)
|
config = config_loader.load_server_config_from_file(test_server_config)
|
||||||
|
|
||||||
assert config["data_dir"] == os.path.join(mock_home_env, ".monkey_island")
|
assert config["data_dir"] == os.path.join(mock_home_env, ".monkey_island")
|
||||||
assert config["log_level"] == "NOTICE"
|
assert config["log_level"] == "NOTICE"
|
||||||
|
|
||||||
|
|
||||||
|
def test_default_log_level():
|
||||||
|
test_config = {}
|
||||||
|
config = config_loader.add_default_values_to_config(test_config)
|
||||||
|
|
||||||
|
assert "log_level" in config
|
||||||
|
assert config["log_level"] == "INFO"
|
||||||
|
|
||||||
|
|
||||||
|
def test_default_data_dir(mock_home_env):
|
||||||
|
test_config = {}
|
||||||
|
config = config_loader.add_default_values_to_config(test_config)
|
||||||
|
|
||||||
|
assert "data_dir" in config
|
||||||
|
assert config["data_dir"] == DEFAULT_DATA_DIR
|
||||||
|
|
Loading…
Reference in New Issue