@@ -27,6 +27,7 @@ import io.ktor.client.request.setBody
2727import io.ktor.http.HttpStatusCode
2828
2929import org.eclipse.apoapsis.ortserver.components.authorization.rights.OrganizationRole
30+ import org.eclipse.apoapsis.ortserver.components.authorization.rights.ProductRole
3031import org.eclipse.apoapsis.ortserver.components.authorization.rights.RepositoryRole
3132import org.eclipse.apoapsis.ortserver.components.infrastructureservices.InfrastructureServiceService
3233import org.eclipse.apoapsis.ortserver.components.infrastructureservices.PatchInfrastructureService
@@ -44,18 +45,25 @@ import org.eclipse.apoapsis.ortserver.shared.ktorutils.AbstractAuthorizationTest
4445
4546class InfrastructureServicesAuthorizationTest : AbstractAuthorizationTest ({
4647 var orgId = 0L
48+ var prodId = 0L
4749 var repoId = 0L
4850 lateinit var orgHierarchyId : CompoundHierarchyId
51+ lateinit var prodHierarchyId : CompoundHierarchyId
4952 lateinit var repoHierarchyId : CompoundHierarchyId
5053 lateinit var infrastructureServiceService : InfrastructureServiceService
5154
5255 beforeEach {
5356 orgId = dbExtension.fixtures.organization.id
57+ prodId = dbExtension.fixtures.product.id
5458 repoId = dbExtension.fixtures.repository.id
5559 orgHierarchyId = CompoundHierarchyId .forOrganization(OrganizationId (orgId))
60+ prodHierarchyId = CompoundHierarchyId .forProduct(
61+ OrganizationId (orgId),
62+ ProductId (prodId)
63+ )
5664 repoHierarchyId = CompoundHierarchyId .forRepository(
5765 OrganizationId (orgId),
58- ProductId (dbExtension.fixtures.product.id ),
66+ ProductId (prodId ),
5967 RepositoryId (repoId)
6068 )
6169
@@ -150,6 +158,87 @@ class InfrastructureServicesAuthorizationTest : AbstractAuthorizationTest({
150158 }
151159 }
152160
161+ " DeleteProductInfrastructureService" should {
162+ " require ProductPermission.WRITE" {
163+ requestShouldRequireRole(
164+ routes = { infrastructureServicesRoutes(infrastructureServiceService) },
165+ role = ProductRole .WRITER ,
166+ successStatus = HttpStatusCode .NotFound ,
167+ hierarchyId = prodHierarchyId
168+ ) {
169+ delete("/products/$prodId/infrastructure-services/name")
170+ }
171+ }
172+ }
173+
174+ " GetProductInfrastructureService" should {
175+ " require ProductPermission.READ" {
176+ requestShouldRequireRole(
177+ routes = { infrastructureServicesRoutes(infrastructureServiceService) },
178+ role = ProductRole .READER ,
179+ successStatus = HttpStatusCode .NotFound ,
180+ hierarchyId = prodHierarchyId
181+ ) {
182+ get("/products/$prodId/infrastructure-services/not-found")
183+ }
184+ }
185+ }
186+
187+ " GetProductInfrastructureServices" should {
188+ " require ProductPermission.READ" {
189+ requestShouldRequireRole(
190+ routes = { infrastructureServicesRoutes(infrastructureServiceService) },
191+ role = ProductRole .READER ,
192+ hierarchyId = prodHierarchyId
193+ ) {
194+ get("/products/$prodId/infrastructure-services")
195+ }
196+ }
197+ }
198+
199+ " PatchProductInfrastructureService" should {
200+ " require ProductPermission.WRITE" {
201+ requestShouldRequireRole(
202+ routes = { infrastructureServicesRoutes(infrastructureServiceService) },
203+ role = ProductRole .WRITER ,
204+ successStatus = HttpStatusCode .NotFound ,
205+ hierarchyId = prodHierarchyId
206+ ) {
207+ patch("/products/$prodId/infrastructure-services/name") {
208+ setBody(
209+ PatchInfrastructureService (
210+ description = null.asPresent(),
211+ url = "https://repo2.example.org/test2".asPresent()
212+ )
213+ )
214+ }
215+ }
216+ }
217+ }
218+
219+ " PostProductInfrastructureService" should {
220+ " require ProductPermission.WRITE" {
221+ requestShouldRequireRole(
222+ routes = { infrastructureServicesRoutes(infrastructureServiceService) },
223+ role = ProductRole .WRITER ,
224+ successStatus = HttpStatusCode .InternalServerError ,
225+ hierarchyId = prodHierarchyId
226+ ) {
227+ post("/products/$prodId/infrastructure-services") {
228+ setBody(
229+ PostInfrastructureService (
230+ "testRepository",
231+ "https://repo.example.org/test",
232+ "test description",
233+ "userSecret",
234+ "passSecret"
235+ )
236+ )
237+ }
238+ }
239+ }
240+ }
241+
153242 " DeleteRepositoryInfrastructureService" should {
154243 " require RepositoryPermission.WRITE" {
155244 requestShouldRequireRole(
0 commit comments