Skip to content

Commit

Permalink
PIN-4504 revoke certified attribute return 409 if certified attribute…
Browse files Browse the repository at this point in the history
… is already revoked and filter list from the revoked ones
  • Loading branch information
nttdata-rtorsoli committed Feb 2, 2024
1 parent 2739d4e commit fd614db
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,10 @@ final case class TenantApiServiceImpl(
attribute.code.getOrElse("none")
)
)
_ <- attributeToRevoke.revocationTimestamp
.fold(Future.unit)(_ =>
Future.failed(AttributeAlreadyRevoked(targetTenantUuid, requesterTenantUuid, attributeUuid))
)
revokedAttribute = attributeToRevoke.copy(revocationTimestamp = now.some)
updatedTenant <- tenantManagementService
.updateTenantAttribute(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ object ReadModelTenantQueries extends ReadModelQuery {
val filterPipeline: Seq[Bson] = Seq(
`match`(query),
lookup(from = "tenants", localField = "data.id", foreignField = "data.attributes.id", as = "tenants"),
unwind("$tenants")
unwind("$tenants"),
`match`(Filters.not(Filters.exists("tenants.data.attributes.revocationTimestamp")))
)

val projection: Bson = project(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ object ResponseHandlers extends AkkaResponses {
case Failure(ex: CertifiedAttributeNotFoundInTenant) => notFound(ex, logMessage)
case Failure(ex: TenantByIdNotFound) => notFound(ex, logMessage)
case Failure(ex: RegistryAttributeIdNotFound) => notFound(ex, logMessage)
case Failure(ex: AttributeAlreadyRevoked) => conflict(ex, logMessage)
case Failure(ex) => internalServerError(ex, logMessage)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,37 @@ class CertifiedAttributeSpec extends AnyWordSpecLike with SpecHelper with Scalat
assert(status == StatusCodes.Forbidden)
}
}
"fail if certified attribute already revoked" in {
implicit val context: Seq[(String, String)] = adminContext

val tenantId = UUID.randomUUID()
val attributeId = UUID.randomUUID()

val requester = persistentTenant.copy(
id = organizationId,
kind = Some(PersistentTenantKind.PA),
features = List(PersistentTenantFeature.PersistentCertifier("IPA"))
)

val tenant = persistentTenant.copy(
id = tenantId,
kind = Some(PersistentTenantKind.PA),
attributes = List(
persistentCertifiedAttribute.copy(id = attributeId, revocationTimestamp = Some(timestamp)),
persistentDeclaredAttribute,
persistentVerifiedAttribute
)
)

mockDateTimeGet()
mockGetTenantById(organizationId, requester)
mockGetTenantById(tenantId, tenant)
mockGetAttributeById(attributeId, persistentAttribute.copy(id = attributeId, origin = Some("IPA")))

Delete() ~> tenantService.revokeCertifiedAttributeById(tenantId.toString, attributeId.toString) ~> check {
assert(status == StatusCodes.Conflict)
}
}
"fail if attribute does not exists on tenant" in {
implicit val context: Seq[(String, String)] = adminContext

Expand Down

0 comments on commit fd614db

Please sign in to comment.