Files
mtusi2026lab2/evidence/storage/test-persistence.md
T
ricoromaandClaude Opus 5.5 0cef33335d docs: add session-auth evidence and report
- passwords and tokens: Argon2id hashes, no secrets in db and logs
- session expiry and database outage with a valid token
- make test-persistence and make test_isolated on ae4154e
- migration drops lab 1 data without passwords
- REPORT.md: sessions, defense scenario, evidence rows

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-01 18:59:53 +03:00

55 lines
3.0 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# `make test-persistence ACTION_SCRIPT=scripts/restart.sh`: данные и прежний токен после рестарта
| | |
|---|---|
| Спеки | `container-run` «Публичная проверка сохранности», «Рестарт hook-ом»; `sessions` «Прежний токен после рестарта»; `data-storage` «Прежний пользователь после рестарта» |
| Change | `session-auth`, задача 7.1 |
| Дата | 2026-10-01 15:51 UTC |
| Commit | `ae4154e` |
| Стенд | `make run_docker` (compose: postgres, migrate, api), API на `127.0.0.1:8080` |
| Хост | Docker Desktop 29.8.1, macOS arm64; ВМ Docker: 12 CPU, 7 GiB RAM; лимиты контейнерам не задавались |
Публичная проверка skeleton (`tests/resilience.py`, `tests/README.md`):
- создаёт пользователей с паролем, входит, создаёт чат и сообщение и
держит токен только в памяти процесса;
- запускает hook и ждёт готовности;
- проверяет те же данные **прежним токеном**, без повторного входа.
## Запуск
```text
$ make test-persistence ACTION_SCRIPT=scripts/restart.sh # exit 0, 4,9 с
python3 tests/resilience.py --mode persistence --action-script "scripts/restart.sh" --base-url "http://localhost:8080"
Executing explicit persistence hook; hook output suppressed to avoid leaking secrets.
PASS: persistence preserved confirmed data and existing session. Hook scope needs operator evidence.
```
## Что действительно перезапускалось
Проверка сама об этом не судит («Hook scope needs operator evidence»),
поэтому — `docker inspect` и `docker compose ps` до и после:
| Контейнер | `StartedAt` до | `StartedAt` после | Перезапущен |
|---|---|---|---|
| `mtusi-lab2-api-1` | 2026-10-01T15:51:18.217149927Z | 2026-10-01T15:51:46.585300051Z | да |
| `mtusi-lab2-postgres-1` | 2026-10-01T15:47:56.156435375Z | 2026-10-01T15:51:43.730010675Z | да |
```text
$ docker compose ps -a # до
mtusi-lab2-api-1 Up 24 seconds (healthy)
mtusi-lab2-migrate-1 Exited (0) 25 seconds ago
mtusi-lab2-postgres-1 Up 3 minutes (healthy)
$ docker compose ps -a # после
mtusi-lab2-api-1 Up 1 second (healthy)
mtusi-lab2-migrate-1 Exited (0) 1 second ago
mtusi-lab2-postgres-1 Up 4 seconds (healthy)
```
## Вывод
- Hook перезапустил API и Postgres (новый `StartedAt` у обоих), volume
`postgres_data` сохранён.
- После рестарта прежний токен прочитал те же подтверждённые данные:
сессии хранятся в PostgreSQL и рестарт их не теряет.
- `migrate` прошёл заново как зависимость `start api`, это no-op.