1919
2020package org.eclipse.apoapsis.ortserver.components.authorization.service
2121
22+ import io.kotest.assertions.throwables.shouldThrow
2223import io.kotest.core.spec.style.WordSpec
2324import io.kotest.inspectors.forAll
2425import io.kotest.matchers.collections.shouldBeSingleton
@@ -29,6 +30,7 @@ import io.kotest.matchers.nulls.beNull
2930import io.kotest.matchers.nulls.shouldNotBeNull
3031import io.kotest.matchers.should
3132import io.kotest.matchers.shouldBe
33+ import io.kotest.matchers.string.shouldContain
3234
3335import org.eclipse.apoapsis.ortserver.components.authorization.db.RoleAssignmentsTable
3436import org.eclipse.apoapsis.ortserver.components.authorization.rights.EffectiveRole
@@ -105,36 +107,33 @@ class DbAuthorizationServiceTest : WordSpec() {
105107 }
106108 }
107109
108- " return an object with no permissions if resolving the product ID fails" {
110+ " throw an InvalidHierarchyIdException if resolving the product ID fails" {
109111 val service = createService()
110-
111112 val missingProductId = ProductId (- 1L )
112113
113- val effectiveRole = service.getEffectiveRole(
114- USER_ID ,
115- missingProductId
116- )
114+ val exception = shouldThrow<InvalidHierarchyIdException > {
115+ service.getEffectiveRole(
116+ USER_ID ,
117+ missingProductId
118+ )
119+ }
117120
118- effectiveRole.elementId shouldBe CompoundHierarchyId .forProduct(OrganizationId (- 1L ), missingProductId)
119- checkPermissions(effectiveRole)
121+ exception.hierarchyId shouldBe missingProductId
120122 }
121123
122- " return an object with no permissions if resolving the repository ID fails" {
124+ " throw an IllegalHierarchyIdException if resolving the repository ID fails" {
123125 val service = createService()
124126
125127 val missingRepositoryId = RepositoryId (- 1L )
126128
127- val effectiveRole = service.getEffectiveRole(
128- USER_ID ,
129- missingRepositoryId
130- )
129+ val exception = shouldThrow<InvalidHierarchyIdException > {
130+ service.getEffectiveRole(
131+ USER_ID ,
132+ missingRepositoryId
133+ )
134+ }
131135
132- effectiveRole.elementId shouldBe CompoundHierarchyId .forRepository(
133- OrganizationId (- 1L ),
134- ProductId (- 1L ),
135- missingRepositoryId
136- )
137- checkPermissions(effectiveRole)
136+ exception.hierarchyId shouldBe missingRepositoryId
138137 }
139138
140139 " return an object with no permissions for a user without role assignments" {
@@ -434,16 +433,20 @@ class DbAuthorizationServiceTest : WordSpec() {
434433 }
435434 }
436435
437- " handle an invalid compound hierarchy ID gracefully " {
436+ " throw an InvalidHierarchyIdException for an invalid hierarchy ID" {
438437 val service = createService()
438+ val invalidId = ProductId (- 1L )
439439
440- val effectiveRole = service.checkPermissions(
441- USER_ID ,
442- ProductId (- 1L ),
443- HierarchyPermissions .permissions(ProductPermission .READ )
444- )
440+ val exception = shouldThrow<InvalidHierarchyIdException > {
441+ service.checkPermissions(
442+ USER_ID ,
443+ invalidId,
444+ HierarchyPermissions .permissions(ProductPermission .READ )
445+ )
446+ }
445447
446- effectiveRole should beNull()
448+ exception.hierarchyId shouldBe invalidId
449+ exception.message shouldContain " Could not resolve hierarchy ID"
447450 }
448451 }
449452
0 commit comments