Spaces:
Sleeping
Sleeping
File size: 1,319 Bytes
1e6a9db | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | from pathlib import Path
import pytest
from backend.src.services import config as config_module
@pytest.fixture(autouse=True)
def restore_config_cache():
"""
Ensure configuration cache is cleared between tests.
"""
config_module.reload_config()
yield
config_module.reload_config()
def test_get_config_allows_missing_jwt_secret(monkeypatch, tmp_path: Path) -> None:
monkeypatch.delenv("JWT_SECRET_KEY", raising=False)
monkeypatch.setenv("VAULT_BASE_PATH", str(tmp_path))
cfg = config_module.reload_config()
assert cfg.jwt_secret_key is None
assert cfg.vault_base_path == tmp_path.resolve()
def test_get_config_rejects_short_jwt_secret(monkeypatch, tmp_path: Path) -> None:
monkeypatch.setenv("VAULT_BASE_PATH", str(tmp_path))
monkeypatch.setenv("JWT_SECRET_KEY", "short")
with pytest.raises(ValueError):
config_module.reload_config()
def test_relative_vault_base_path_resolves_from_project_root(monkeypatch, tmp_path: Path) -> None:
relative_path = "data/relative-vaults"
monkeypatch.delenv("JWT_SECRET_KEY", raising=False)
monkeypatch.setenv("VAULT_BASE_PATH", relative_path)
cfg = config_module.reload_config()
expected = config_module.PROJECT_ROOT / relative_path
assert cfg.vault_base_path == expected.resolve()
|