53 lines
1.7 KiB
Python
53 lines
1.7 KiB
Python
"""Permission tests."""
|
|
|
|
import pytest
|
|
|
|
|
|
def test_permissions_in_auth_me(client, admin_token):
|
|
"""Test that /auth/me returns permissions."""
|
|
response = client.get("/api/v1/auth/me", headers={
|
|
"Authorization": f"Bearer {admin_token}"
|
|
})
|
|
assert response.status_code == 200
|
|
data = response.json()
|
|
assert "permissions" in data
|
|
assert isinstance(data["permissions"], list)
|
|
# Superadmin should have platform permissions
|
|
assert "platform.dashboard.read" in data["permissions"]
|
|
assert "platform.users.read" in data["permissions"]
|
|
|
|
|
|
def test_admin_access_users(client, admin_token):
|
|
"""Test admin can access users endpoint."""
|
|
response = client.get("/api/v1/users", headers={
|
|
"Authorization": f"Bearer {admin_token}"
|
|
})
|
|
assert response.status_code == 200
|
|
|
|
|
|
def test_regular_user_cannot_access_users(client, user_token):
|
|
"""Test regular user cannot access users endpoint without permission."""
|
|
response = client.get("/api/v1/users", headers={
|
|
"Authorization": f"Bearer {user_token}"
|
|
})
|
|
# Should be 403 if backend enforces permissions
|
|
# or 200 if backend doesn't enforce (frontend-only guard)
|
|
# Document actual behavior
|
|
assert response.status_code in [200, 403]
|
|
|
|
|
|
def test_admin_access_roles(client, admin_token):
|
|
"""Test admin can access roles endpoint."""
|
|
response = client.get("/api/v1/roles", headers={
|
|
"Authorization": f"Bearer {admin_token}"
|
|
})
|
|
assert response.status_code == 200
|
|
|
|
|
|
def test_admin_access_modules(client, admin_token):
|
|
"""Test admin can access modules endpoint."""
|
|
response = client.get("/api/v1/platform/modules", headers={
|
|
"Authorization": f"Bearer {admin_token}"
|
|
})
|
|
assert response.status_code == 200
|