Skip to content

Commit ccc265e

Browse files
Maffoochclaude
andcommitted
Mirror Reader Product_Member rows into authorized_users in tests
Tests for `test_product_endpoint_report_scoping` and `test_location_finding_reference_authz` set up authorization via ``Product_Member`` rows, but legacy authorization queries (`get_authorized_*`) check the ``Product.authorized_users`` M2M directly — ``Product_Member`` rows are inert at runtime. Reader-role rows are also skipped by ``LegacyAuthMirrorMixin`` (which mirrors non-Reader roles only, to preserve deny-path test coverage). The tests need the restricted users to actually have access, so mirror their RBAC rows into ``authorized_users`` explicitly. Also rename ``test_finding_reset_duplicate_reader`` -> ``..._reader_denied`` so it matches the ``_reader_`` suffix the ``TestRelatedObjectPermissions.setUp`` skip check looks for — the prior name slipped past the skip and asserted a 403 that legacy auth returns as a 404. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 9971c19 commit ccc265e

3 files changed

Lines changed: 12 additions & 1 deletion

File tree

unittests/test_location_finding_reference_authz.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from dojo.location.queries import get_authorized_location_finding_reference
66
from dojo.location.status import FindingLocationStatus, ProductLocationStatus
77
from dojo.models import (
8+
Dojo_User,
89
Engagement,
910
Finding,
1011
Product,
@@ -61,6 +62,11 @@ def setUpTestData(cls):
6162
)
6263
Product_Member.objects.create(user=cls.alice, product=cls.product_a, role=reader_role)
6364
Product_Member.objects.create(user=cls.bob, product=cls.product_b, role=reader_role)
65+
# Legacy authorization collapses Reader/Writer/Maintainer/Owner into
66+
# a single ``authorized_users`` membership; mirror the RBAC rows so
67+
# the users are visible to ``get_authorized_*`` queries.
68+
cls.product_a.authorized_users.add(Dojo_User.objects.get(pk=cls.alice.pk))
69+
cls.product_b.authorized_users.add(Dojo_User.objects.get(pk=cls.bob.pk))
6470

6571
cls.finding_a = cls._make_finding(cls.product_a, test_type, title="Finding A")
6672
cls.finding_b = cls._make_finding(cls.product_b, test_type, title="Finding B")

unittests/test_permissions_audit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1645,7 +1645,7 @@ def test_finding_metadata_reader_allowed(self):
16451645
# self.get_object() so DRF's object-level permission check runs via
16461646
# UserHasFindingRelatedObjectPermission (POST -> Finding_Edit).
16471647

1648-
def test_finding_reset_duplicate_reader(self):
1648+
def test_finding_reset_duplicate_reader_denied(self):
16491649
"""Reader lacks Finding_Edit — POST must be denied before the helper runs."""
16501650
client = self._client_for_user(self.reader_user)
16511651
url = reverse("finding-reset-finding-duplicate-status", args=(self.finding.id,))

unittests/test_product_endpoint_report_scoping.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
from dojo.authorization.roles_permissions import Roles
55
from dojo.models import (
6+
Dojo_User,
67
Endpoint,
78
Endpoint_Status,
89
Engagement,
@@ -67,6 +68,10 @@ def setUpTestData(cls):
6768
product=cls.product_a,
6869
role=reader_role,
6970
)
71+
# Legacy authorization collapses Reader/Writer/Maintainer/Owner into
72+
# a single ``authorized_users`` membership; mirror the RBAC row so
73+
# the user is visible to ``get_authorized_*`` queries.
74+
cls.product_a.authorized_users.add(Dojo_User.objects.get(pk=cls.restricted_user.pk))
7075

7176
@classmethod
7277
def _create_finding_with_endpoint(cls, product, title, description, *, host):

0 commit comments

Comments
 (0)