Skip to content

Commit fb505f8

Browse files
devGregAclaude
andcommitted
test(authorization): rewrite tests for legacy semantics
The pre-Track-B tests asserted RBAC role hierarchy (Reader can view but not edit, Maintainer can manage members, etc). The legacy rewrite collapses every per-product distinction to single-bit membership in authorized_users, so 73 of 121 authorization tests broke after the upstream merge. Changes: * Replace test_authorization.py with a legacy-faithful suite that exercises authorized_users, the Product_Type → Product → Engagement → Test → Finding membership chain, is_staff/is_superuser bypass, Action.SuperuserOnly / Delete / StaffOnly gates, the Permissions / Action / string input shapes, and the inert role-helper stubs. * Update test_authorization_tags.py: the template filter is now a pass-through (no Permissions[name] lookup), so unknown permission strings fall through to permission_to_action() defaults instead of raising KeyError. * Augment test_authorization_queries.py fixture to populate authorized_users for the directly-named users (so legacy queryset filters return the same set as the RBAC fixture), and flip assertions for users whose access path doesn't translate (Global_Role(Reader), Product_Group, Product_Type_Group) — those now correctly return empty querysets under legacy. * Fix _get_authorized_endpoints / _get_authorized_endpoint_status to accept the user= kwarg the dispatcher passes (was raising TypeError on every endpoint API call from a non-superuser). All 116 authorization tests pass (was 39/121). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent d3789c0 commit fb505f8

4 files changed

Lines changed: 355 additions & 635 deletions

File tree

dojo/authorization/query_registrations.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -376,16 +376,16 @@ def _get_authorized_location_product_reference(permission, queryset=None, user=N
376376
# ---------------------------------------------------------------------------
377377

378378

379-
def _get_authorized_endpoints(permission):
380-
return _filter_by_authorized_products(Endpoint.objects.all(), "product", permission)
379+
def _get_authorized_endpoints(permission, user=None):
380+
return _filter_by_authorized_products(Endpoint.objects.all(), "product", permission, user=user)
381381

382382

383383
register_auth_filter("endpoint.get_authorized_endpoints", _get_authorized_endpoints)
384384

385385

386-
def _get_authorized_endpoint_status(permission):
386+
def _get_authorized_endpoint_status(permission, user=None):
387387
return _filter_by_authorized_products(
388-
Endpoint_Status.objects.all(), "endpoint__product", permission,
388+
Endpoint_Status.objects.all(), "endpoint__product", permission, user=user,
389389
)
390390

391391

0 commit comments

Comments
 (0)