@@ -278,7 +278,26 @@ class DbAuthorizationServiceTest : WordSpec() {
278278
279279 val effectiveRole = service.getEffectiveRole(USER_ID , repositoryCompoundId)
280280
281- checkPermissions(effectiveRole, OrganizationRole .ADMIN )
281+ checkPermissions(effectiveRole, OrganizationRole .ADMIN , expectedSuperuser = true )
282+ }
283+
284+ " allow querying super users only" {
285+ val normalUser = " normal-user"
286+ createAssignment(
287+ organizationRole = OrganizationRole .ADMIN
288+ )
289+ createAssignment(
290+ userId = normalUser,
291+ organizationId = dbExtension.fixtures.organization.id,
292+ organizationRole = OrganizationRole .READER
293+ )
294+ val service = createService()
295+
296+ val effectiveRoleNormal = service.getEffectiveRole(normalUser, CompoundHierarchyId .WILDCARD )
297+ val effectiveRoleSuper = service.getEffectiveRole(USER_ID , CompoundHierarchyId .WILDCARD )
298+
299+ checkPermissions(effectiveRoleNormal)
300+ checkPermissions(effectiveRoleSuper, OrganizationRole .ADMIN , expectedSuperuser = true )
282301 }
283302
284303 " not fail for invalid role names" {
@@ -332,7 +351,7 @@ class DbAuthorizationServiceTest : WordSpec() {
332351 checkPermissions(effectiveRole, ProductRole .WRITER )
333352
334353 val effectiveRoleOrg = service.getEffectiveRole(USER_ID , productCompoundId.parent!! )
335- checkPermissions(effectiveRoleOrg, ProductRole . WRITER )
354+ checkPermissions(effectiveRoleOrg)
336355 }
337356
338357 " create a new role assignment on organization level" {
@@ -354,7 +373,7 @@ class DbAuthorizationServiceTest : WordSpec() {
354373 checkPermissions(effectiveRoleRepo, OrganizationRole .WRITER )
355374 }
356375
357- " create a new role assignment for the WILDCARD ID " {
376+ " create a new superuser role assignment" {
358377 val service = createService()
359378
360379 service.assignRole(
@@ -364,7 +383,7 @@ class DbAuthorizationServiceTest : WordSpec() {
364383 )
365384
366385 val effectiveRole = service.getEffectiveRole(USER_ID , repositoryCompoundId())
367- checkPermissions(effectiveRole, OrganizationRole .ADMIN )
386+ checkPermissions(effectiveRole, OrganizationRole .ADMIN , expectedSuperuser = true )
368387 }
369388
370389 " replace an already exiting assignment" {
@@ -710,13 +729,15 @@ private const val USER_ID = "test-user"
710729
711730/* *
712731 * Check that the given [effectiveRole] contains exactly the specified [expectedOrganizationPermissions],
713- * [expectedProductPermissions], and [expectedRepositoryPermissions] on the different hierarchy levels.
732+ * [expectedProductPermissions], and [expectedRepositoryPermissions] on the different hierarchy levels. Also check the
733+ * [superuser][expectedSuperuser] flag.
714734 */
715735private fun checkPermissions (
716736 effectiveRole : EffectiveRole ,
717737 expectedOrganizationPermissions : Set <OrganizationPermission > = emptySet(),
718738 expectedProductPermissions : Set <ProductPermission > = emptySet(),
719- expectedRepositoryPermissions : Set <RepositoryPermission > = emptySet()
739+ expectedRepositoryPermissions : Set <RepositoryPermission > = emptySet(),
740+ expectedSuperuser : Boolean = false
720741) {
721742 OrganizationPermission .entries.forAll {
722743 effectiveRole.hasOrganizationPermission(it) shouldBe (it in expectedOrganizationPermissions)
@@ -727,15 +748,19 @@ private fun checkPermissions(
727748 RepositoryPermission .entries.forAll {
728749 effectiveRole.hasRepositoryPermission(it) shouldBe (it in expectedRepositoryPermissions)
729750 }
751+
752+ effectiveRole.isSuperuser shouldBe expectedSuperuser
730753}
731754
732755/* *
733- * Check that the given [effectiveRole] contains exactly the permissions as defined by the given [expectedRole].
756+ * Check that the given [effectiveRole] contains exactly the permissions as defined by the given [expectedRole]. Also
757+ * check the [superuser][expectedSuperuser] flag.
734758 */
735- private fun checkPermissions (effectiveRole : EffectiveRole , expectedRole : Role ) =
759+ private fun checkPermissions (effectiveRole : EffectiveRole , expectedRole : Role , expectedSuperuser : Boolean = false ) =
736760 checkPermissions(
737761 effectiveRole,
738762 expectedRole.organizationPermissions,
739763 expectedRole.productPermissions,
740- expectedRole.repositoryPermissions
764+ expectedRole.repositoryPermissions,
765+ expectedSuperuser
741766 )
0 commit comments