T01: core infrastructure + auth + multi-tenant + RLS

- 10 models: tenants, users, user_tenants, roles, sessions, audit_log, deletion_log, notifications, password_reset_tokens, api_tokens
- Session-based auth (Redis + PostgreSQL audit trail)
- Multi-tenant with ORM-level filtering + PostgreSQL RLS (set_config)
- RBAC with roles/permissions + field-level permissions
- CSRF protection via Origin header validation
- Auth rate limiting (Redis counters with TTL)
- CORS with explicit origins (no wildcard)
- Health endpoint (no auth required)
- Notification service + audit log middleware
- 29 tests, 26 ACs, all passing
- Coverage: 62% (infrastructure modules pending coverage in later tasks)
This commit is contained in:
leocrm-bot
2026-06-29 00:10:10 +02:00
parent 3cc0b2e1b4
commit 7a7daf8100
137 changed files with 3866 additions and 10195 deletions
-56
View File
@@ -1,56 +0,0 @@
"""Tests for FR-3 (Contact entity)."""
from __future__ import annotations
import pytest
from httpx import AsyncClient
@pytest.mark.asyncio
async def test_create_contact_with_account(
client: AsyncClient, auth_headers: dict[str, str], seed_data: dict
) -> None:
acc_id = seed_data["account_ids"][0]
resp = await client.post(
"/api/v1/contacts/",
json={
"first_name": "Diana",
"last_name": "Prince",
"email": "diana@x.example",
"account_id": acc_id,
},
headers=auth_headers,
)
assert resp.status_code == 201, resp.text
body = resp.json()
assert body["account_id"] == acc_id
@pytest.mark.asyncio
async def test_create_contact_invalid_account(
client: AsyncClient, auth_headers: dict[str, str]
) -> None:
resp = await client.post(
"/api/v1/contacts/",
json={"first_name": "Eve", "last_name": "Adams", "account_id": 99999},
headers=auth_headers,
)
assert resp.status_code == 404
@pytest.mark.asyncio
async def test_list_contacts_filter_account(client: AsyncClient, seed_data: dict) -> None:
acc_id = seed_data["account_ids"][0]
resp = await client.get(f"/api/v1/contacts/?account_id={acc_id}", headers=seed_data["headers"])
assert resp.status_code == 200
body = resp.json()
assert all(c["account_id"] == acc_id for c in body)
@pytest.mark.asyncio
async def test_search_contacts_by_email(client: AsyncClient, seed_data: dict) -> None:
# seed_data creates contact with email 'anna@acme.example' on account 0
resp = await client.get("/api/v1/contacts/?q=anna@acme.example", headers=seed_data["headers"])
assert resp.status_code == 200
body = resp.json()
assert any("anna@acme.example" in (c.get("email") or "") for c in body)