Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tomchop committed Jan 7, 2025
1 parent f14d9e1 commit 801f027
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
9 changes: 6 additions & 3 deletions core/schemas/rbac.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ async def wrapper(*args, httpreq: Request, **kwargs):
extended_id = extended_id.group(1)
if not httpreq.state.user.has_permissions(extended_id, permission):
raise HTTPException(
status_code=status.HTTP_403_FORBIDDEN, detail="Forbidden"
status_code=status.HTTP_403_FORBIDDEN,
detail=f"Forbidden: missing privileges {permission} on target",
)
return func(*args, httpreq=httpreq, **kwargs)

Expand All @@ -81,7 +82,8 @@ async def wrapper(*args, httpreq: Request, **kwargs):
extended_id = f"{prefix}/{id}"
if not httpreq.state.user.has_permissions(extended_id, permission):
raise HTTPException(
status_code=status.HTTP_403_FORBIDDEN, detail="Forbidden"
status_code=status.HTTP_403_FORBIDDEN,
detail=f"Forbidden: missing privileges {permission} on target {extended_id}",
)

return func(*args, httpreq=httpreq, **kwargs)
Expand All @@ -101,7 +103,8 @@ async def wrapper(*args, httpreq: Request, **kwargs):
return func(*args, httpreq=httpreq, **kwargs)

raise HTTPException(
status_code=status.HTTP_403_FORBIDDEN, detail="Forbidden"
status_code=status.HTTP_403_FORBIDDEN,
detail=f"Forbidden: missing global permission {permission}",
)

return wrapper
Expand Down
14 changes: 13 additions & 1 deletion tests/apiv2/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,20 @@ def test_create_group(self):
json={"name": "testGroup"},
headers={"Authorization": f"Bearer {self.user1_token}"},
)
self.assertEqual(response.status_code, 200)
data = response.json()
self.assertEqual(response.status_code, 403, data)
self.assertEqual(data["detail"], "Forbidden: missing global permission 2")

self.user1.global_role = graph.Role.WRITER
self.user1.save()

response = client.post(
"/api/v2/groups",
json={"name": "testGroup"},
headers={"Authorization": f"Bearer {self.user1_token}"},
)
data = response.json()
self.assertEqual(response.status_code, 200, data)
self.assertEqual(data["name"], "testGroup")

def test_delete_group(self):
Expand Down
4 changes: 2 additions & 2 deletions tests/apiv2/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def test_toggle_user_unprivileged(self):
)

data = response.json()
self.assertEqual(response.status_code, 401, data)
self.assertEqual(response.status_code, 403, data)
self.assertIsNotNone(data)
self.assertEqual(data["detail"], "user tomchop is not an admin")

Expand Down Expand Up @@ -189,7 +189,7 @@ def test_delete_user_unprivileged(self):
headers={"Authorization": f"Bearer {self.user_token}"},
)
data = response.json()
self.assertEqual(response.status_code, 401)
self.assertEqual(response.status_code, 403, data)
self.assertIsNotNone(data)
self.assertEqual(data["detail"], "user tomchop is not an admin")

Expand Down

0 comments on commit 801f027

Please sign in to comment.