TorbatYar/backend/services/experience/app/tests/test_security.py
Mortezakoohjani 203671a7bf feat(experience): ship Experience Platform phases 11.0-11.10
Add the experience service with sites through analytics/AI hooks, migrations through 0011, and phase docs/manifests marking the track complete.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-27 11:43:10 +03:30

26 lines
834 B
Python

"""Security validation — auth gate when AUTH_REQUIRED is true."""
from __future__ import annotations
import pytest
from httpx import ASGITransport, AsyncClient
from app.core.config import settings
from app.main import app
from app.tests.conftest import TENANT_A, tenant_headers
@pytest.mark.asyncio
async def test_auth_required_rejects_anonymous():
original = settings.auth_required
settings.auth_required = True
try:
transport = ASGITransport(app=app)
async with AsyncClient(transport=transport, base_url="http://testserver") as client:
resp = await client.get(
"/api/v1/workspaces",
headers=tenant_headers(TENANT_A),
)
assert resp.status_code == 401
finally:
settings.auth_required = original