TT-007.1: establish module-owned authorization boundary
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
"""Authorization Boundary Tests — TT-007.1
|
||||
|
||||
Tests for Module-Owned Permission Boundary.
|
||||
Verifies that:
|
||||
- Module is authority for its own permissions
|
||||
- Platform does not compute module permissions
|
||||
- /auth/me returns identity + module_access, not module permissions
|
||||
"""
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
def test_auth_me_returns_module_access(client, admin_token):
|
||||
"""Test that /auth/me returns module_access field."""
|
||||
response = client.get("/api/v1/auth/me", headers={
|
||||
"Authorization": f"Bearer {admin_token}"
|
||||
})
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert "module_access" in data
|
||||
assert isinstance(data["module_access"], list)
|
||||
|
||||
|
||||
def test_auth_me_no_module_permissions(client, admin_token):
|
||||
"""Test that /auth/me does NOT return module permissions (request.*, etc.)."""
|
||||
response = client.get("/api/v1/auth/me", headers={
|
||||
"Authorization": f"Bearer {admin_token}"
|
||||
})
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
permissions = data.get("permissions", [])
|
||||
# Module permissions should NOT be in /auth/me
|
||||
module_perms = [p for p in permissions if p.startswith("request.")]
|
||||
assert len(module_perms) == 0, f"Module permissions found in /auth/me: {module_perms}"
|
||||
|
||||
|
||||
def test_auth_me_has_platform_permissions(client, admin_token):
|
||||
"""Test that /auth/me still returns platform permissions."""
|
||||
response = client.get("/api/v1/auth/me", headers={
|
||||
"Authorization": f"Bearer {admin_token}"
|
||||
})
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
# Platform permissions should still be there
|
||||
assert "platform.dashboard.read" in data["permissions"]
|
||||
assert "platform.users.read" in data["permissions"]
|
||||
|
||||
|
||||
def test_auth_me_identity_fields(client, admin_token):
|
||||
"""Test that /auth/me returns identity fields."""
|
||||
response = client.get("/api/v1/auth/me", headers={
|
||||
"Authorization": f"Bearer {admin_token}"
|
||||
})
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
# Identity fields
|
||||
assert "id" in data
|
||||
assert "email" in data
|
||||
assert "first_name" in data
|
||||
assert "last_name" in data
|
||||
assert "is_active" in data
|
||||
assert "is_superadmin" in data
|
||||
assert "roles" in data
|
||||
|
||||
|
||||
def test_login_returns_user_with_module_access(client, admin_user):
|
||||
"""Test that login response includes module_access."""
|
||||
response = client.post("/api/v1/auth/login", json={
|
||||
"email": "admin@test.com",
|
||||
"password": "admin123",
|
||||
})
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert "user" in data
|
||||
assert "module_access" in data["user"]
|
||||
Reference in New Issue
Block a user