forked from mtusi2026/mtusi2026lab7
feat: separate PostgreSQL roles and Valkey ACL per service
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -22,6 +22,7 @@ from src.config.settings import (
|
||||
ApiTls,
|
||||
App,
|
||||
Auth,
|
||||
DbRoles,
|
||||
Settings,
|
||||
Telemetry,
|
||||
Uploads,
|
||||
@@ -254,6 +255,31 @@ def test_client_tls_from_environment(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
assert _EnvironmentOnly().client_tls.ca_file == "/run/secrets/ca.crt"
|
||||
|
||||
|
||||
def test_db_roles_from_environment(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
"""Спек `service-configuration`, «Подключение к PostgreSQL»: пароли ролей
|
||||
читает bootstrap из `DB_ROLES__*`, по умолчанию пусто; в шаблоне toml их
|
||||
нет (источник — `.env`)."""
|
||||
loaded = _EnvironmentOnly()
|
||||
assert loaded.db_roles == DbRoles()
|
||||
assert loaded.db_roles.api_password.get_secret_value() == ""
|
||||
monkeypatch.setenv("DB_ROLES__WORKER_PASSWORD", "worker-secret")
|
||||
loaded = _EnvironmentOnly()
|
||||
assert loaded.db_roles.worker_password.get_secret_value() == (
|
||||
"worker-secret"
|
||||
)
|
||||
assert "worker-secret" not in repr(loaded.db_roles)
|
||||
assert "db_roles" not in EXAMPLE_TOML_PATH.read_text()
|
||||
|
||||
|
||||
def test_cache_username_from_environment(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""Пользователь ACL Valkey: пусто — `default`, у API — `api`."""
|
||||
assert _EnvironmentOnly().cache.username == ""
|
||||
monkeypatch.setenv("CACHE__USERNAME", "api")
|
||||
assert _EnvironmentOnly().cache.username == "api"
|
||||
|
||||
|
||||
def test_s3_endpoint_is_https() -> None:
|
||||
"""Шлюз S3 — только HTTPS (change `storage-tls`): URL с именем хоста."""
|
||||
s3 = _ArgumentsOnly(s3={"host": "s3", "port": 8333}).s3
|
||||
|
||||
Reference in New Issue
Block a user