Skip to content

Commit 95d1234

Browse files
committed
test: update test to use a namespaced global scope
1 parent 125894f commit 95d1234

File tree

1 file changed

+36
-29
lines changed

1 file changed

+36
-29
lines changed

openedx_authz/tests/test_enforcement.py

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from django.contrib.auth import get_user_model
1616

1717
from openedx_authz import ROOT_DIRECTORY
18+
from openedx_authz.api.data import GLOBAL_SCOPE_WILDCARD
1819
from openedx_authz.constants import roles
1920
from openedx_authz.engine.matcher import is_admin_or_superuser_check
2021
from openedx_authz.tests.test_utils import (
@@ -127,15 +128,15 @@ class SystemWideRoleTests(CasbinEnforcementTestCase):
127128
"""
128129

129130
POLICY = [
130-
["p", make_role_key("platform_admin"), make_action_key("manage"), "*", "allow"],
131-
["g", make_user_key("user-1"), make_role_key("platform_admin"), "*"],
131+
["p", make_role_key("platform_admin"), make_action_key("manage"), GLOBAL_SCOPE_WILDCARD, "allow"],
132+
["g", make_user_key("user-1"), make_role_key("platform_admin"), GLOBAL_SCOPE_WILDCARD],
132133
] + COMMON_ACTION_GROUPING
133134

134135
GENERAL_CASES = [
135136
{
136137
"subject": make_user_key("user-1"),
137138
"action": make_action_key("manage"),
138-
"scope": "*",
139+
"scope": make_scope_key("global", GLOBAL_SCOPE_WILDCARD),
139140
"expected_result": True,
140141
},
141142
{
@@ -179,7 +180,7 @@ class ActionGroupingTests(CasbinEnforcementTestCase):
179180
"p",
180181
make_role_key("role-1"),
181182
make_action_key("manage"),
182-
make_scope_key("org", "*"),
183+
make_scope_key("org", GLOBAL_SCOPE_WILDCARD),
183184
"allow",
184185
],
185186
[
@@ -234,65 +235,65 @@ class RoleAssignmentTests(CasbinEnforcementTestCase):
234235

235236
POLICY = [
236237
# Policies
237-
["p", make_role_key("platform_admin"), make_action_key("manage"), "*", "allow"],
238+
["p", make_role_key("platform_admin"), make_action_key("manage"), GLOBAL_SCOPE_WILDCARD, "allow"],
238239
[
239240
"p",
240241
make_role_key("org_admin"),
241242
make_action_key("manage"),
242-
make_scope_key("org", "*"),
243+
make_scope_key("org", GLOBAL_SCOPE_WILDCARD),
243244
"allow",
244245
],
245246
[
246247
"p",
247248
make_role_key("org_editor"),
248249
make_action_key("edit"),
249-
make_scope_key("org", "*"),
250+
make_scope_key("org", GLOBAL_SCOPE_WILDCARD),
250251
"allow",
251252
],
252253
[
253254
"p",
254255
make_role_key("org_author"),
255256
make_action_key("write"),
256-
make_scope_key("org", "*"),
257+
make_scope_key("org", GLOBAL_SCOPE_WILDCARD),
257258
"allow",
258259
],
259260
[
260261
"p",
261262
make_role_key("course_admin"),
262263
make_action_key("manage"),
263-
make_scope_key("course", "*"),
264+
make_scope_key("course", GLOBAL_SCOPE_WILDCARD),
264265
"allow",
265266
],
266267
[
267268
"p",
268269
make_role_key(roles.LIBRARY_ADMIN.external_key),
269270
make_action_key("manage"),
270-
make_scope_key("lib", "*"),
271+
make_scope_key("lib", GLOBAL_SCOPE_WILDCARD),
271272
"allow",
272273
],
273274
[
274275
"p",
275276
make_role_key("library_editor"),
276277
make_action_key("edit"),
277-
make_scope_key("lib", "*"),
278+
make_scope_key("lib", GLOBAL_SCOPE_WILDCARD),
278279
"allow",
279280
],
280281
[
281282
"p",
282283
make_role_key("library_reviewer"),
283284
make_action_key("read"),
284-
make_scope_key("lib", "*"),
285+
make_scope_key("lib", GLOBAL_SCOPE_WILDCARD),
285286
"allow",
286287
],
287288
[
288289
"p",
289290
make_role_key(roles.LIBRARY_AUTHOR.external_key),
290291
make_action_key("write"),
291-
make_scope_key("lib", "*"),
292+
make_scope_key("lib", GLOBAL_SCOPE_WILDCARD),
292293
"allow",
293294
],
294295
# Role assignments
295-
["g", make_user_key("user-1"), make_role_key("platform_admin"), "*"],
296+
["g", make_user_key("user-1"), make_role_key("platform_admin"), GLOBAL_SCOPE_WILDCARD],
296297
[
297298
"g",
298299
make_user_key("user-2"),
@@ -415,15 +416,15 @@ class DeniedAccessTests(CasbinEnforcementTestCase):
415416
"""
416417

417418
POLICY = [
418-
["p", make_role_key("platform_admin"), make_action_key("manage"), "*", "allow"],
419+
["p", make_role_key("platform_admin"), make_action_key("manage"), GLOBAL_SCOPE_WILDCARD, "allow"],
419420
[
420421
"p",
421422
make_role_key("platform_admin"),
422423
make_action_key("manage"),
423424
make_scope_key("org", "restricted-org"),
424425
"deny",
425426
],
426-
["g", make_user_key("user-1"), make_role_key("platform_admin"), "*"],
427+
["g", make_user_key("user-1"), make_role_key("platform_admin"), GLOBAL_SCOPE_WILDCARD],
427428
] + COMMON_ACTION_GROUPING
428429

429430
CASES = [
@@ -484,37 +485,37 @@ class WildcardScopeTests(CasbinEnforcementTestCase):
484485

485486
POLICY = [
486487
# Policies
487-
["p", make_role_key("platform_admin"), make_action_key("manage"), "*", "allow"],
488+
["p", make_role_key("platform_admin"), make_action_key("manage"), GLOBAL_SCOPE_WILDCARD, "allow"],
488489
[
489490
"p",
490491
make_role_key("org_admin"),
491492
make_action_key("manage"),
492-
make_scope_key("org", "*"),
493+
make_scope_key("org", GLOBAL_SCOPE_WILDCARD),
493494
"allow",
494495
],
495496
[
496497
"p",
497498
make_role_key("course_admin"),
498499
make_action_key("manage"),
499-
make_scope_key("course", "*"),
500+
make_scope_key("course", GLOBAL_SCOPE_WILDCARD),
500501
"allow",
501502
],
502503
[
503504
"p",
504505
make_role_key(roles.LIBRARY_ADMIN.external_key),
505506
make_action_key("manage"),
506-
make_scope_key("lib", "*"),
507+
make_scope_key("lib", GLOBAL_SCOPE_WILDCARD),
507508
"allow",
508509
],
509510
# Role assignments
510-
["g", make_user_key("user-1"), make_role_key("platform_admin"), "*"],
511-
["g", make_user_key("user-2"), make_role_key("org_admin"), "*"],
512-
["g", make_user_key("user-3"), make_role_key("course_admin"), "*"],
513-
["g", make_user_key("user-4"), make_role_key(roles.LIBRARY_ADMIN.external_key), "*"],
511+
["g", make_user_key("user-1"), make_role_key("platform_admin"), GLOBAL_SCOPE_WILDCARD],
512+
["g", make_user_key("user-2"), make_role_key("org_admin"), GLOBAL_SCOPE_WILDCARD],
513+
["g", make_user_key("user-3"), make_role_key("course_admin"), GLOBAL_SCOPE_WILDCARD],
514+
["g", make_user_key("user-4"), make_role_key(roles.LIBRARY_ADMIN.external_key), GLOBAL_SCOPE_WILDCARD],
514515
] + COMMON_ACTION_GROUPING
515516

516517
@data(
517-
("*", True),
518+
(make_scope_key("global", GLOBAL_SCOPE_WILDCARD), True),
518519
(make_scope_key("org", "MIT"), True),
519520
(make_scope_key("course", "course-v1:OpenedX+DemoX+CS101"), True),
520521
(make_library_key("lib:OpenedX:math-basics"), True),
@@ -531,7 +532,7 @@ def test_wildcard_global_access(self, scope: str, expected_result: bool):
531532
self._test_enforcement(self.POLICY, request)
532533

533534
@data(
534-
("*", False),
535+
(make_scope_key("global", GLOBAL_SCOPE_WILDCARD), False),
535536
(make_scope_key("org", "MIT"), True),
536537
(make_scope_key("course", "course-v1:OpenedX+DemoX+CS101"), False),
537538
(make_library_key("lib:OpenedX:math-basics"), False),
@@ -548,7 +549,7 @@ def test_wildcard_org_access(self, scope: str, expected_result: bool):
548549
self._test_enforcement(self.POLICY, request)
549550

550551
@data(
551-
("*", False),
552+
(make_scope_key("global", GLOBAL_SCOPE_WILDCARD), False),
552553
(make_scope_key("org", "MIT"), False),
553554
(make_scope_key("course", "course-v1:OpenedX+DemoX+CS101"), True),
554555
(make_library_key("lib:OpenedX:math-basics"), False),
@@ -565,7 +566,7 @@ def test_wildcard_course_access(self, scope: str, expected_result: bool):
565566
self._test_enforcement(self.POLICY, request)
566567

567568
@data(
568-
("*", False),
569+
(make_scope_key("global", GLOBAL_SCOPE_WILDCARD), False),
569570
(make_scope_key("org", "MIT"), False),
570571
(make_scope_key("course", "course-v1:OpenedX+DemoX+CS101"), False),
571572
(make_library_key("lib:OpenedX:math-basics"), True),
@@ -646,7 +647,13 @@ def setUp(self) -> None:
646647
),
647648
)
648649
@unpack
649-
def test_staff_superuser_guaranteed_permissions(self, subject: str, action: str, scope: str, expected_result: bool):
650+
def test_staff_superuser_guaranteed_permissions(
651+
self,
652+
subject: str,
653+
action: str,
654+
scope: str,
655+
expected_result: bool,
656+
):
650657
"""Test that staff and superusers have guaranteed permissions for ContentLibrary scopes.
651658
652659
This test validates that:

0 commit comments

Comments
 (0)