Implementeaza PRD 5.6 complet (14 stories, TDD). Doua axe:
Lifecycle trimiteri blocate (Val A):
- submissions_admin.py: sterge/repune scoped (404 cross-account inaintea lui 409 stare)
- reactivare dedup peste `error` cu CAS (WHERE id=? AND status='error'), creds noi in
submissions + accounts.rar_creds_enc; worker invalideaza sesiunea RAR la creds proaspete
(JWT 30h vechi nu mai trimite cu parola gresita); camp aditiv `reactivated:true`
- retentie randuri blocate 30z; purge_expired exclude queued/sending; purge_after curatat
la reactivare/requeue
- API DELETE /v1/prezentari/{id} + /repune (200+JSON); UI butoane + bulk + banner actionabil
Observabilitate:
- app/observ.py log_event: dublu canal app_events (DB) + RotatingFileHandler per-proces,
redactare creds/PII la scriere (redact_pii/vin_partial)
- request_id middleware + X-Request-ID pe toate raspunsurile
- handler global excepții -> 500 envelope 6-chei + request_id (traceback doar in jurnal)
- audit cerere API (api_prezentari/api_auth_esuat) + audit worker (rar_login/tranzitii)
- tab "Jurnal" filtrabil scoped (non-admin doar contul sau); retentie jurnal 90z
- rar_error expus in GET /v1/prezentari/{id} (recovery observabil)
pytest -q: 741 passed, 0 failed. Docs: PRD raport VERIFY, contract endpointuri noi, ROADMAP.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
50 lines
1.5 KiB
Python
50 lines
1.5 KiB
Python
"""Teste US-002 (PRD 5.6): request_id per cerere + header X-Request-ID."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
import tempfile
|
|
|
|
import pytest
|
|
from fastapi.testclient import TestClient
|
|
|
|
|
|
@pytest.fixture()
|
|
def client(monkeypatch):
|
|
tmp = tempfile.mkdtemp()
|
|
monkeypatch.setenv("AUTOPASS_DB_PATH", os.path.join(tmp, "rid.db"))
|
|
monkeypatch.setenv("AUTOPASS_LOG_DIR", os.path.join(tmp, "logs"))
|
|
from app.config import get_settings
|
|
get_settings.cache_clear()
|
|
from app.main import app
|
|
with TestClient(app) as c:
|
|
yield c
|
|
get_settings.cache_clear()
|
|
|
|
|
|
def test_raspuns_are_header_x_request_id(client):
|
|
r = client.get("/healthz")
|
|
assert r.status_code == 200
|
|
assert r.headers.get("X-Request-ID"), "lipseste header X-Request-ID"
|
|
|
|
|
|
def test_request_id_distinct_pe_cereri(client):
|
|
a = client.get("/healthz").headers.get("X-Request-ID")
|
|
b = client.get("/healthz").headers.get("X-Request-ID")
|
|
assert a and b and a != b
|
|
|
|
|
|
def test_request_id_pastrat_daca_clientul_trimite(client):
|
|
r = client.get("/healthz", headers={"X-Request-ID": "corelare-abc"})
|
|
assert r.headers.get("X-Request-ID") == "corelare-abc"
|
|
|
|
|
|
def test_request_id_propagat_in_log(client):
|
|
"""request_id e disponibil in log_event pe durata cererii (contextvar)."""
|
|
from app import observ
|
|
|
|
r = client.get("/healthz", headers={"X-Request-ID": "rid-xyz"})
|
|
assert r.headers["X-Request-ID"] == "rid-xyz"
|
|
# In afara cererii, contextvar revine la None (reset in middleware)
|
|
assert observ.request_id_var.get() is None
|