Skip to content

Commit

Permalink
PIN-4454 Allow document upload only on Draft descriptor (#227)
Browse files Browse the repository at this point in the history
  • Loading branch information
nttdata-rtorsoli authored Jan 31, 2024
1 parent 3adf411 commit e590ea9
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ final case class ProcessApiServiceImpl(
catalogItem <- catalogManagementService.getEServiceById(eServiceUuid)
_ <- assertRequesterAllowed(catalogItem.producerId)(organizationId)
descriptor <- assertDescriptorExists(catalogItem, descriptorUuid)
_ <- isDraftDescriptor(descriptor)
_ <-
if (documentSeed.kind == EServiceDocumentKind.INTERFACE) assertInterfaceDoesNotExists(descriptor)
else Future.unit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ object ResponseHandlers extends AkkaResponses {
)(result: Try[T])(implicit contexts: Seq[(String, String)], logger: LoggerTakingImplicit[ContextFieldsToLog]): Route =
result match {
case Success(s) => success(s)
case Failure(ex: NotValidDescriptor) => badRequest(ex, logMessage)
case Failure(ex: OperationForbidden.type) => forbidden(ex, logMessage)
case Failure(ex: InterfaceAlreadyExists) => badRequest(ex, logMessage)
case Failure(ex: EServiceNotFound) => notFound(ex, logMessage)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2352,7 +2352,7 @@ class CatalogProcessSpec extends SpecHelper with AnyWordSpecLike with ScalatestR
implicit val context: Seq[(String, String)] =
Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString)

val descriptor = SpecData.catalogDescriptor.copy(id = descriptorId)
val descriptor = SpecData.catalogDescriptor.copy(id = descriptorId, state = Draft)

val eService = SpecData.catalogItem.copy(descriptors = Seq(descriptor), producerId = requesterId)

Expand Down Expand Up @@ -2460,6 +2460,40 @@ class CatalogProcessSpec extends SpecHelper with AnyWordSpecLike with ScalatestR
status shouldEqual StatusCodes.NotFound
}
}
"fail if EService descriptor is not draft" in {

val requesterId = UUID.randomUUID()
val descriptorId = UUID.randomUUID()
implicit val context: Seq[(String, String)] =
Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString)

val descriptor = SpecData.catalogDescriptor.copy(id = descriptorId, state = Published)

val eService = SpecData.catalogItem.copy(descriptors = Seq(descriptor), producerId = requesterId)

val documentId = UUID.randomUUID()

val seed = CreateEServiceDescriptorDocumentSeed(
documentId = documentId,
kind = EServiceDocumentKind.DOCUMENT,
prettyName = "prettyName",
filePath = "filePath",
fileName = "fileName",
contentType = "application/pdf",
checksum = "checksum",
serverUrls = Seq.empty
)

(mockCatalogManagementService
.getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService))
.expects(SpecData.catalogItem.id, *, *)
.once()
.returns(Future.successful(eService))

Post() ~> service.createEServiceDocument(SpecData.catalogItem.id.toString, descriptorId.toString, seed) ~> check {
status shouldEqual StatusCodes.BadRequest
}
}
"fail if requester is not the Producer" in {
implicit val context: Seq[(String, String)] =
Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> UUID.randomUUID().toString)
Expand Down

0 comments on commit e590ea9

Please sign in to comment.