Combined admin/info endpoint, replaces old separate endpoints.
This commit is contained in:
+18
-12
@@ -179,7 +179,7 @@ class TestExceptionHandlers:
|
||||
async def test_auth_exception_handler(self, client: httpx.AsyncClient):
|
||||
"""AuthException should return proper JSON with auth info."""
|
||||
# Accessing admin without auth triggers AuthException
|
||||
response = await client.get("/auth/api/admin/orgs")
|
||||
response = await client.get("/auth/api/admin/info")
|
||||
assert response.status_code == 401
|
||||
data = response.json()
|
||||
assert "detail" in data
|
||||
@@ -216,7 +216,7 @@ class TestAdminOrganizations:
|
||||
@pytest.mark.asyncio
|
||||
async def test_list_orgs_requires_auth(self, client: httpx.AsyncClient):
|
||||
"""List orgs without auth should return 401."""
|
||||
response = await client.get("/auth/api/admin/orgs")
|
||||
response = await client.get("/auth/api/admin/info")
|
||||
assert response.status_code == 401
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -225,7 +225,7 @@ class TestAdminOrganizations:
|
||||
):
|
||||
"""List orgs without admin permission should return 403."""
|
||||
response = await client.get(
|
||||
"/auth/api/admin/orgs",
|
||||
"/auth/api/admin/info",
|
||||
headers={
|
||||
**auth_headers(regular_session_token),
|
||||
"Host": "localhost:4401",
|
||||
@@ -239,15 +239,18 @@ class TestAdminOrganizations:
|
||||
):
|
||||
"""Admin user should be able to list organizations."""
|
||||
response = await client.get(
|
||||
"/auth/api/admin/orgs",
|
||||
"/auth/api/admin/info",
|
||||
headers={**auth_headers(session_token), "Host": "localhost:4401"},
|
||||
)
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert isinstance(data, dict)
|
||||
assert len(data) >= 1
|
||||
assert "orgs" in data
|
||||
orgs_data = data["orgs"]
|
||||
assert isinstance(orgs_data, dict)
|
||||
assert len(orgs_data) >= 1
|
||||
# Check org structure
|
||||
org_data = list(data.values())[0]
|
||||
org_data = list(orgs_data.values())[0]
|
||||
assert "org" in org_data
|
||||
org = org_data["org"]
|
||||
assert "uuid" in org
|
||||
@@ -265,13 +268,13 @@ class TestAdminOrganizations:
|
||||
):
|
||||
"""Org admin should only see their own organization."""
|
||||
response = await client.get(
|
||||
"/auth/api/admin/orgs",
|
||||
"/auth/api/admin/info",
|
||||
headers={**auth_headers(org_admin_session_token), "Host": "localhost:4401"},
|
||||
)
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
# Should only see their own org, not the second org
|
||||
org_uuids = [org_data["org"]["uuid"] for org_data in data.values()]
|
||||
org_uuids = [org_data["org"]["uuid"] for org_data in data["orgs"].values()]
|
||||
assert str(test_org.uuid) in org_uuids
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -1396,14 +1399,17 @@ class TestAdminPermissions:
|
||||
):
|
||||
"""Admin should be able to list all permissions."""
|
||||
response = await client.get(
|
||||
"/auth/api/admin/permissions",
|
||||
"/auth/api/admin/info",
|
||||
headers={**auth_headers(session_token), "Host": "localhost:4401"},
|
||||
)
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert isinstance(data, dict)
|
||||
assert "permissions" in data
|
||||
permissions_data = data["permissions"]
|
||||
assert isinstance(permissions_data, dict)
|
||||
# Should include at least auth:admin
|
||||
perm_scopes = [p["scope"] for p in data.values()]
|
||||
perm_scopes = [p["scope"] for p in permissions_data.values()]
|
||||
assert "auth:admin" in perm_scopes
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -1416,13 +1422,13 @@ class TestAdminPermissions:
|
||||
):
|
||||
"""Org admin should only see permissions their org can grant."""
|
||||
response = await client.get(
|
||||
"/auth/api/admin/permissions",
|
||||
"/auth/api/admin/info",
|
||||
headers={**auth_headers(org_admin_session_token), "Host": "localhost:4401"},
|
||||
)
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
# Should only see permissions the org can grant
|
||||
perm_scopes = [p["scope"] for p in data.values()]
|
||||
perm_scopes = [p["scope"] for p in data["permissions"].values()]
|
||||
assert grantable_permission.scope in perm_scopes
|
||||
# test_org CAN grant auth:admin (it's in org.permissions), so org admin sees it
|
||||
assert "auth:admin" in perm_scopes
|
||||
|
||||
Reference in New Issue
Block a user