mirror of
https://github.com/Zproger/Aurum.git
synced 2026-10-13 02:56:39 +07:00
Конфигурация и эксплуатационный слой: - nginx: client_max_body_size 64m — восстановление из бэкапа не работало вовсе, дефолтный лимит в 1 МБ резал дампы (реальный экспорт ~3.4 МБ) с 413 ещё до backend; - nginx: заголовки безопасности (nosniff, Referrer-Policy, Permissions-Policy) и полный Content-Security-Policy. Ради него inline-скрипт темы вынесен в public/theme-init.js; - nginx: limit_req на /api/ — перебор пароля Basic Auth шёл со скоростью сети, ни блокировки, ни задержки не было; - nginx: server_tokens off; - порт web привязан к 127.0.0.1, адрес настраивается через AURUM_BIND_ADDRESS (раньше слушался на всех интерфейсах); - backend работает от непривилегированного пользователя, no-new-privileges для backend и web; - дефолты пароля Postgres сведены к одному значению в обоих сервисах, в .env.example описана ловушка с инициализацией тома. Приложение: - версия убрана из неавторизованного /api/health и отдаётся как app_version в GET /api/settings; - /api/docs, /api/redoc и /api/openapi.json отключаются через AURUM_ENABLE_DOCS; - текст исключения при неудачном восстановлении уходит в лог, а не клиенту; - max_length для notes в схемах транзакций, активов и регулярных платежей (и в соответствующих полях UI); - срок «запомнить меня» сокращён с 30 дней до 7; - pytest обновлён до 9.0.3 (PYSEC-2026-1845), pytest-asyncio до 1.4.0; - CI: permissions contents:read для GITHUB_TOKEN.
44 lines
2.0 KiB
Markdown
44 lines
2.0 KiB
Markdown
# Backend tests
|
|
|
|
Real integration tests against a real Postgres database — a dedicated
|
|
`aurum_test` database created fresh, migrated, and dropped again on every
|
|
run. They never touch the real `aurum` database or its data: the app's
|
|
`lifespan` startup (which seeds against the real DB) is never triggered, and
|
|
every route's DB dependency is overridden to point at `aurum_test` instead.
|
|
|
|
## Running
|
|
|
|
The stack must already be up (`docker compose up -d`). Test dependencies
|
|
aren't baked into the production image, so install them once per container
|
|
lifetime, then run pytest inside the running `backend` container — it's the
|
|
only place with network access to Postgres:
|
|
|
|
```bash
|
|
docker compose exec backend pip install --user -r requirements-dev.txt
|
|
docker compose exec backend python -m pytest -v
|
|
```
|
|
|
|
Re-run just the `python -m pytest -v` line for subsequent runs; the
|
|
`pip install` only needs repeating after a container restart/rebuild.
|
|
|
|
Two details that both come from the container running as an unprivileged user
|
|
(`aurum`, uid 10001 — see backend/Dockerfile) rather than root:
|
|
|
|
- `--user` on the install: site-packages belongs to root and isn't writable.
|
|
The packages land in `/home/aurum/.local`, which isn't on `PATH`, hence
|
|
`python -m pytest` instead of a bare `pytest`.
|
|
- pytest prints a `PytestCacheWarning` about not being able to write
|
|
`/app/.pytest_cache`. Expected — the source tree is read-only to the app
|
|
user by design. Tests still pass; add `-p no:cacheprovider` to silence it.
|
|
|
|
## Adding a test
|
|
|
|
- Use the `client` fixture (an `httpx.AsyncClient` wired to the app) to hit
|
|
the API the same way the frontend does — prefer this over reaching into
|
|
services/models directly, so tests keep verifying the actual contract.
|
|
- `account_id` and `categories` fixtures give you the same default
|
|
account/categories a real fresh install seeds.
|
|
- Every table is truncated and reseeded before each test (see
|
|
`conftest.py::_clean_database`), so tests don't need to worry about
|
|
leftover state or guess at IDs from a previous test.
|