Skip to content

Commit

Permalink
PIN-3794 Prevent the creation of the EService for not IPA organization (
Browse files Browse the repository at this point in the history
#203)

Co-authored-by: nttdata-rtorsoli <[email protected]>
  • Loading branch information
nttdata-rtorsoli and nttdata-rtorsoli authored Aug 21, 2023
1 parent 487ba11 commit 8875ac6
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/main/resources/interface-specification.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,12 @@ paths:
application/problem+json:
schema:
$ref: '#/components/schemas/Problem'
'403':
description: Forbidden
content:
application/problem+json:
schema:
$ref: '#/components/schemas/Problem'
'409':
description: Name Conflict
content:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import it.pagopa.interop.commons.cqrs.service.ReadModelService
import it.pagopa.interop.commons.files.service.FileManager
import it.pagopa.interop.commons.jwt._
import it.pagopa.interop.commons.logging.{CanLogContextFields, ContextFieldsToLog}
import it.pagopa.interop.commons.utils.AkkaUtils.getOrganizationIdFutureUUID
import it.pagopa.interop.commons.utils.AkkaUtils._
import it.pagopa.interop.commons.utils.OpenapiUtils.parseArrayParameters
import it.pagopa.interop.commons.utils.TypeConversions._
import it.pagopa.interop.commons.utils.errors.GenericComponentErrors
Expand Down Expand Up @@ -49,6 +49,8 @@ final case class ProcessApiServiceImpl(
implicit val logger: LoggerTakingImplicit[ContextFieldsToLog] =
Logger.takingImplicit[ContextFieldsToLog](this.getClass)

val IPA = "IPA"

override def createEService(eServiceSeed: EServiceSeed)(implicit
contexts: Seq[(String, String)],
toEntityMarshallerProblem: ToEntityMarshaller[Problem],
Expand All @@ -59,6 +61,8 @@ final case class ProcessApiServiceImpl(

val result: Future[EService] = for {
organizationId <- getOrganizationIdFutureUUID(contexts)
origin <- getExternalIdOriginFuture(contexts)
_ <- if (origin == IPA) Future.unit else Future.failed(OriginIsNotCompliant(IPA))
clientSeed = eServiceSeed.toDependency(organizationId)
maybeEservice <- catalogManagementService
.getEServices(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,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: OriginIsNotCompliant) => forbidden(ex, logMessage)
case Failure(ex: DuplicatedEServiceName) => conflict(ex, logMessage)
case Failure(ex) => internalServerError(ex, logMessage)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,7 @@ object CatalogProcessErrors {
final case class DuplicatedEServiceName(name: String)
extends ComponentError("0010", s"EService with name: $name already in use")

final case class OriginIsNotCompliant(origin: String)
extends ComponentError("0011", s"Requester has not origin: $origin")

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import it.pagopa.interop.catalogmanagement.client.model.AgreementApprovalPolicy.
import it.pagopa.interop.catalogmanagement.client.{model => CatalogManagementDependency}
import it.pagopa.interop.catalogprocess.api.impl.Converter._
import it.pagopa.interop.catalogprocess.api.impl._
import it.pagopa.interop.commons.utils.{ORGANIZATION_ID_CLAIM, USER_ROLES}
import it.pagopa.interop.commons.utils._
import it.pagopa.interop.commons.cqrs.service.ReadModelService
import it.pagopa.interop.catalogprocess.errors.CatalogProcessErrors.{EServiceNotFound, DescriptorDocumentNotFound}
import it.pagopa.interop.catalogmanagement.model.{
Expand Down Expand Up @@ -274,7 +274,13 @@ class CatalogProcessSpec extends SpecHelper with AnyWordSpecLike with ScalatestR
val catalogItems: Seq[CatalogItem] = Seq.empty

implicit val context: Seq[(String, String)] =
Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString)
Seq(
"bearer" -> bearerToken,
USER_ROLES -> "admin",
ORGANIZATION_ID_CLAIM -> requesterId.toString,
ORGANIZATION_EXTERNAL_ID_ORIGIN -> "IPA",
ORGANIZATION_EXTERNAL_ID_VALUE -> "12345"
)

val apiSeed: EServiceSeed =
EServiceSeed(name = "MyService", description = "My Service", technology = EServiceTechnology.REST)
Expand Down Expand Up @@ -380,7 +386,13 @@ class CatalogProcessSpec extends SpecHelper with AnyWordSpecLike with ScalatestR
val requesterId = UUID.randomUUID()

implicit val context: Seq[(String, String)] =
Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString)
Seq(
"bearer" -> bearerToken,
USER_ROLES -> "admin",
ORGANIZATION_ID_CLAIM -> requesterId.toString,
ORGANIZATION_EXTERNAL_ID_ORIGIN -> "IPA",
ORGANIZATION_EXTERNAL_ID_VALUE -> "12345"
)

val catalogItems: Seq[CatalogItem] = Seq(SpecData.catalogItem)

Expand All @@ -406,6 +418,26 @@ class CatalogProcessSpec extends SpecHelper with AnyWordSpecLike with ScalatestR
status shouldEqual StatusCodes.Conflict
}
}
"fail with forbidden requester origin is not IPA" in {

val requesterId = UUID.randomUUID()

implicit val context: Seq[(String, String)] =
Seq(
"bearer" -> bearerToken,
USER_ROLES -> "admin",
ORGANIZATION_ID_CLAIM -> requesterId.toString,
ORGANIZATION_EXTERNAL_ID_ORIGIN -> "NOT_IPA",
ORGANIZATION_EXTERNAL_ID_VALUE -> "12345"
)

val apiSeed: EServiceSeed =
EServiceSeed(name = "MyService", description = "My Service", technology = EServiceTechnology.REST)

Post() ~> service.createEService(apiSeed) ~> check {
status shouldEqual StatusCodes.Forbidden
}
}
}
"EService update" should {
"succeed" in {
Expand Down

0 comments on commit 8875ac6

Please sign in to comment.