diff --git a/CHANGELOG.md b/CHANGELOG.md index 23ab53eaf..e377c841e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed + +- Fixed `Path` variables in EmpireConfig not properly expanding `~` (@Vinnybod) + ## [5.8.3] - 2023-12-15 ### Fixed diff --git a/empire/server/core/config.py b/empire/server/core/config.py index 79f6fabe7..3c7045434 100644 --- a/empire/server/core/config.py +++ b/empire/server/core/config.py @@ -9,8 +9,8 @@ class EmpireBaseModel(BaseModel): - @classmethod @field_validator("*") + @classmethod def set_path(cls, v): if isinstance(v, Path): return v.expanduser().resolve() diff --git a/empire/test/conftest.py b/empire/test/conftest.py index 9bae10299..3300a3c9a 100644 --- a/empire/test/conftest.py +++ b/empire/test/conftest.py @@ -5,6 +5,7 @@ from pathlib import Path import pytest +import yaml from starlette.testclient import TestClient from empire.client.src.utils.data_util import get_random_string @@ -442,3 +443,9 @@ def client_config_dict(): config_dict = yaml.safe_load(f) yield config_dict + + +def load_test_config(): + with open(SERVER_CONFIG_LOC) as f: + loaded = yaml.safe_load(f) + return loaded diff --git a/empire/test/test_config.py b/empire/test/test_config.py new file mode 100644 index 000000000..84a06ad14 --- /dev/null +++ b/empire/test/test_config.py @@ -0,0 +1,12 @@ +from pathlib import Path + +from empire.server.core.config import EmpireConfig +from empire.test.conftest import load_test_config + + +def test_config_resolves_path(): + server_config_dict = load_test_config() + server_config_dict["directories"]["downloads"] = "~/.empire/server/downloads" + empire_config = EmpireConfig(server_config_dict) + assert isinstance(empire_config.directories.downloads, Path) + assert not str(empire_config.directories.downloads).startswith("~") diff --git a/empire/test/test_logs.py b/empire/test/test_logs.py index 45bd4d46a..fa8b654e0 100644 --- a/empire/test/test_logs.py +++ b/empire/test/test_logs.py @@ -4,9 +4,7 @@ from pathlib import Path from unittest.mock import MagicMock -import yaml - -from empire.test.conftest import SERVER_CONFIG_LOC +from empire.test.conftest import SERVER_CONFIG_LOC, load_test_config def test_simple_log_format(monkeypatch): @@ -43,7 +41,7 @@ def test_extended_log_format(monkeypatch): from empire.server.server import setup_logging from empire.server.utils.log_util import LOG_FORMAT, ColorFormatter - test_config = _load_test_config() + test_config = load_test_config() test_config["logging"]["simple_console"] = False modified_config = EmpireConfig(test_config) monkeypatch.setattr("empire.server.server.empire_config", modified_config) @@ -70,7 +68,7 @@ def test_log_level_by_config(monkeypatch): from empire.server.core.config import EmpireConfig from empire.server.server import setup_logging - test_config = _load_test_config() + test_config = load_test_config() test_config["logging"]["level"] = "WaRNiNG" # case insensitive modified_config = EmpireConfig(test_config) monkeypatch.setattr("empire.server.server.empire_config", modified_config) @@ -101,7 +99,7 @@ def test_log_level_by_arg(): from empire.server.server import setup_logging config_mock = MagicMock() - test_config = _load_test_config() + test_config = load_test_config() test_config["logging"]["level"] = "WaRNiNG" # Should be overwritten by arg config_mock.yaml = test_config @@ -124,7 +122,7 @@ def test_log_level_by_debug_arg(): from empire.server.server import setup_logging config_mock = MagicMock() - test_config = _load_test_config() + test_config = load_test_config() test_config["logging"]["level"] = "WaRNiNG" # Should be overwritten by arg config_mock.yaml = test_config @@ -132,9 +130,3 @@ def test_log_level_by_debug_arg(): setup_logging(args) assert logging.getLogger().level == logging.DEBUG - - -def _load_test_config(): - with open(SERVER_CONFIG_LOC) as f: - loaded = yaml.safe_load(f) - return loaded