Skip to content

Commit

Permalink
PIN-4123 Resolved PR issues
Browse files Browse the repository at this point in the history
  • Loading branch information
nttdata-rtorsoli committed Oct 18, 2023
1 parent 274ba81 commit 85f41b9
Show file tree
Hide file tree
Showing 9 changed files with 10 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/main/resources/application-standalone.conf
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ authorization-process {
user-registry = "a_secret_key"
}
selfcare-product-id = ${SELFCARE_PRODUCT_ID}
threshold-keys = 1000
max-keys-per-client = 100
jwt {
audience = ${ACCEPTED_AUDIENCES}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ authorization-process {
user-registry = ${USER_REGISTRY_API_KEY}
}
selfcare-product-id = ${SELFCARE_PRODUCT_ID}
threshold-keys = ${THRESHOLD_KEYS}
max-keys-per-client = ${MAX_KEYS_PER_CLIENT}
jwt {
audience = ${ACCEPTED_AUDIENCES}
}
Expand Down
6 changes: 0 additions & 6 deletions src/main/resources/interface-specification.yml
Original file line number Diff line number Diff line change
Expand Up @@ -506,12 +506,6 @@ paths:
application/problem+json:
schema:
$ref: '#/components/schemas/Problem'
'429':
description: Too many keys
content:
application/problem+json:
schema:
$ref: '#/components/schemas/Problem'
requestBody:
required: true
description: an array of base64 encoded PEM keys.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@ object ClientApiHandlers extends AkkaResponses {
result match {
case Success(s) => success(s)
case Failure(ex: CreateKeysBadRequest) => badRequest(ex, logMessage)
case Failure(ex: TooManyKeysPerClient) => badRequest(ex, logMessage)
case Failure(ex: SecurityOperatorRelationshipNotFound) => forbidden(ex, logMessage)
case Failure(ex: OrganizationNotAllowedOnClient) => forbidden(ex, logMessage)
case Failure(ex: ClientNotFound) => notFound(ex, logMessage)
case Failure(ex: KeysAlreadyExist) => conflict(ex, logMessage)
case Failure(ex: TheNumberOfkeysExceedMaximumAllowed) => tooManyRequests(ex, logMessage)
case Failure(ex) => internalServerError(ex, logMessage)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,8 @@ final case class ClientApiServiceImpl(
logger.info(operationLabel)

def assertKeyIsBelowThreshold(clientId: UUID, size: Int): Future[Unit] =
if (size > ApplicationConfiguration.thresholdKeys)
Future.failed(TheNumberOfkeysExceedMaximumAllowed(clientId, size))
if (size > ApplicationConfiguration.maxKeysPerClient)
Future.failed(TooManyKeysPerClient(clientId, size))
else Future.unit

val result: Future[Keys] = for {
Expand All @@ -277,8 +277,7 @@ final case class ClientApiServiceImpl(
client <- authorizationManagementService
.getClient(clientUuid)
.ensureOr(client => OrganizationNotAllowedOnClient(clientId, client.consumerId))(_.consumerId == organizationId)
keys <- authorizationManagementService
.getClientKeys(clientUuid)
keys <- authorizationManagementService.getClientKeys(clientUuid)
_ <- assertKeyIsBelowThreshold(clientUuid, keys.size + keysSeeds.size)
relationshipId <- securityOperatorRelationship(client.consumerId, userId).map(_.id)
seeds = keysSeeds.map(_.toDependency(relationshipId, dateTimeSupplier.get()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ object ApplicationConfiguration {

val selfcareProductId: String = config.getString("authorization-process.selfcare-product-id")

val thresholdKeys: Int = config.getInt("authorization-process.threshold-keys")
val maxKeysPerClient: Int = config.getInt("authorization-process.max-keys-per-client")

val readModelConfig: ReadModelConfig = {
val connectionString: String = config.getString("authorization-process.read-model.db.connection-string")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ object AuthorizationProcessErrors {
final case class EServiceNotFound(eServiceId: UUID)
extends ComponentError("0019", s"EService ${eServiceId.toString} not found")

final case class TheNumberOfkeysExceedMaximumAllowed(clientId: UUID, size: Int)
final case class TooManyKeysPerClient(clientId: UUID, size: Int)
extends ComponentError(
"0020",
s"The number of the keys ${size.toString} for the client ${clientId.toString} exceed maximun allowed"
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/application-test.conf
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ authorization-process {
user-registry = "a_secret_key"
}
selfcare-product-id = "selfcare-product-id"
threshold-keys = 5
max-keys-per-client = 5
jwt {
audience = "audience"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ class KeyOperationSpec
.returns(Future.successful(Seq(persistentKey.copy(relationshipId = relationship.id))))

Get() ~> service.createKeys(client.id.toString, keySeeds) ~> check {
status shouldEqual StatusCodes.TooManyRequests
status shouldEqual StatusCodes.BadRequest
entityAs[Problem].errors.head.code shouldBe "007-0020"
}
}
Expand Down

0 comments on commit 85f41b9

Please sign in to comment.