Skip to content

Commit

Permalink
PIN-3653: added tenant's attributes to computeAgreementsByAttribute (#…
Browse files Browse the repository at this point in the history
…242)

Co-authored-by: Fabrizio Musella <[email protected]>
Co-authored-by: Alessio Gallitano <[email protected]>
  • Loading branch information
3 people authored Jul 26, 2023
1 parent 124a2d2 commit 6d1ef1d
Show file tree
Hide file tree
Showing 13 changed files with 403 additions and 172 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import it.pagopa.interop.tenantmanagement.model.tenant.{
PersistentCertifiedAttribute,
PersistentDeclaredAttribute,
PersistentVerifiedAttribute,
PersistentTenant,
PersistentTenantAttribute,
PersistentTenantVerifier
}

Expand All @@ -29,10 +29,13 @@ object AttributesRules {
consumerAttributes.filter(_.revocationTimestamp.isEmpty).map(_.id)
)

def certifiedAttributesSatisfied(descriptor: CatalogDescriptor, consumer: PersistentTenant): Boolean =
def certifiedAttributesSatisfied(
descriptor: CatalogDescriptor,
consumerAttributes: List[PersistentTenantAttribute]
): Boolean =
certifiedAttributesSatisfied(
descriptor.attributes,
consumer.attributes.collect { case a: PersistentCertifiedAttribute => a }
consumerAttributes.collect { case a: PersistentCertifiedAttribute => a }
)

def declaredAttributesSatisfied(
Expand All @@ -41,10 +44,13 @@ object AttributesRules {
): Boolean =
attributesSatisfied(eServiceAttributes.declared, consumerAttributes.filter(_.revocationTimestamp.isEmpty).map(_.id))

def declaredAttributesSatisfied(descriptor: CatalogDescriptor, consumer: PersistentTenant): Boolean =
def declaredAttributesSatisfied(
descriptor: CatalogDescriptor,
consumerAttributes: List[PersistentTenantAttribute]
): Boolean =
declaredAttributesSatisfied(
descriptor.attributes,
consumer.attributes.collect { case a: PersistentDeclaredAttribute => a }
consumerAttributes.collect { case a: PersistentDeclaredAttribute => a }
)

def verifiedAttributesSatisfied(
Expand All @@ -64,12 +70,12 @@ object AttributesRules {
def verifiedAttributesSatisfied(
agreement: PersistentAgreement,
descriptor: CatalogDescriptor,
consumer: PersistentTenant
consumerAttributes: List[PersistentTenantAttribute]
): Boolean =
verifiedAttributesSatisfied(
agreement.producerId,
descriptor.attributes,
consumer.attributes.collect { case a: PersistentVerifiedAttribute => a }
consumerAttributes.collect { case a: PersistentVerifiedAttribute => a }
)

private def attributesSatisfied(requested: Seq[CatalogAttribute], assigned: Seq[UUID]): Boolean = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class AttributesRulesSpec extends AnyWordSpecLike {
val descriptor: CatalogDescriptor = SpecData.descriptor.copy(attributes = descriptorAttr)
val consumer: PersistentTenant = SpecData.tenant.copy(attributes = tenantAttr)

certifiedAttributesSatisfied(descriptor, consumer) shouldBe true
certifiedAttributesSatisfied(descriptor, consumer.attributes) shouldBe true
}

"return true if at least one attribute in every CatalogItem group attribute is satisfied" in {
Expand All @@ -57,7 +57,7 @@ class AttributesRulesSpec extends AnyWordSpecLike {
val descriptor: CatalogDescriptor = SpecData.descriptor.copy(attributes = descriptorAttr)
val consumer: PersistentTenant = SpecData.tenant.copy(attributes = tenantAttr)

certifiedAttributesSatisfied(descriptor, consumer) shouldBe true
certifiedAttributesSatisfied(descriptor, consumer.attributes) shouldBe true
}

"return true if CatalogItem single and group attributes are satisfied" in {
Expand All @@ -79,7 +79,7 @@ class AttributesRulesSpec extends AnyWordSpecLike {
val descriptor: CatalogDescriptor = SpecData.descriptor.copy(attributes = descriptorAttr)
val consumer: PersistentTenant = SpecData.tenant.copy(attributes = tenantAttr)

certifiedAttributesSatisfied(descriptor, consumer) shouldBe true
certifiedAttributesSatisfied(descriptor, consumer.attributes) shouldBe true
}

"return false if at least one CatalogItem single attribute is not satisfied" in {
Expand All @@ -95,7 +95,7 @@ class AttributesRulesSpec extends AnyWordSpecLike {
val descriptor: CatalogDescriptor = SpecData.descriptor.copy(attributes = descriptorAttr)
val consumer: PersistentTenant = SpecData.tenant.copy(attributes = tenantAttr)

certifiedAttributesSatisfied(descriptor, consumer) shouldBe false
certifiedAttributesSatisfied(descriptor, consumer.attributes) shouldBe false
}

"return false if at least one CatalogItem group attribute is not satisfied" in {
Expand All @@ -116,7 +116,7 @@ class AttributesRulesSpec extends AnyWordSpecLike {
val descriptor: CatalogDescriptor = SpecData.descriptor.copy(attributes = descriptorAttr)
val consumer: PersistentTenant = SpecData.tenant.copy(attributes = tenantAttr)

certifiedAttributesSatisfied(descriptor, consumer) shouldBe false
certifiedAttributesSatisfied(descriptor, consumer.attributes) shouldBe false
}

"return false if an CatalogItem single attribute is assigned but revoked" in {
Expand All @@ -131,7 +131,7 @@ class AttributesRulesSpec extends AnyWordSpecLike {
val descriptor: CatalogDescriptor = SpecData.descriptor.copy(attributes = descriptorAttr)
val consumer: PersistentTenant = SpecData.tenant.copy(attributes = tenantAttr)

certifiedAttributesSatisfied(descriptor, consumer) shouldBe false
certifiedAttributesSatisfied(descriptor, consumer.attributes) shouldBe false
}

"return false if the CatalogItem group attribute is assigned but revoked" in {
Expand All @@ -146,7 +146,7 @@ class AttributesRulesSpec extends AnyWordSpecLike {
val descriptor: CatalogDescriptor = SpecData.descriptor.copy(attributes = descriptorAttr)
val consumer: PersistentTenant = SpecData.tenant.copy(attributes = tenantAttr)

certifiedAttributesSatisfied(descriptor, consumer) shouldBe false
certifiedAttributesSatisfied(descriptor, consumer.attributes) shouldBe false
}
}

Expand All @@ -168,7 +168,7 @@ class AttributesRulesSpec extends AnyWordSpecLike {
val descriptor: CatalogDescriptor = SpecData.descriptor.copy(attributes = descriptorAttr)
val consumer: PersistentTenant = SpecData.tenant.copy(attributes = tenantAttr)

declaredAttributesSatisfied(descriptor, consumer) shouldBe true
declaredAttributesSatisfied(descriptor, consumer.attributes) shouldBe true
}

"return true if at least one attribute in every CatalogItem group attribute is satisfied" in {
Expand All @@ -193,7 +193,7 @@ class AttributesRulesSpec extends AnyWordSpecLike {
val descriptor: CatalogDescriptor = SpecData.descriptor.copy(attributes = descriptorAttr)
val consumer: PersistentTenant = SpecData.tenant.copy(attributes = tenantAttr)

declaredAttributesSatisfied(descriptor, consumer) shouldBe true
declaredAttributesSatisfied(descriptor, consumer.attributes) shouldBe true
}

"return true if CatalogItem single and group attributes are satisfied" in {
Expand All @@ -215,7 +215,7 @@ class AttributesRulesSpec extends AnyWordSpecLike {
val descriptor: CatalogDescriptor = SpecData.descriptor.copy(attributes = descriptorAttr)
val consumer: PersistentTenant = SpecData.tenant.copy(attributes = tenantAttr)

declaredAttributesSatisfied(descriptor, consumer) shouldBe true
declaredAttributesSatisfied(descriptor, consumer.attributes) shouldBe true
}

"return false if at least one CatalogItem single attribute is not satisfied" in {
Expand All @@ -231,7 +231,7 @@ class AttributesRulesSpec extends AnyWordSpecLike {
val descriptor: CatalogDescriptor = SpecData.descriptor.copy(attributes = descriptorAttr)
val consumer: PersistentTenant = SpecData.tenant.copy(attributes = tenantAttr)

declaredAttributesSatisfied(descriptor, consumer) shouldBe false
declaredAttributesSatisfied(descriptor, consumer.attributes) shouldBe false
}

"return false if at least one CatalogItem group attribute is not satisfied" in {
Expand All @@ -252,7 +252,7 @@ class AttributesRulesSpec extends AnyWordSpecLike {
val descriptor: CatalogDescriptor = SpecData.descriptor.copy(attributes = descriptorAttr)
val consumer: PersistentTenant = SpecData.tenant.copy(attributes = tenantAttr)

declaredAttributesSatisfied(descriptor, consumer) shouldBe false
declaredAttributesSatisfied(descriptor, consumer.attributes) shouldBe false
}

"return false if an CatalogItem single attribute is assigned but revoked" in {
Expand All @@ -267,7 +267,7 @@ class AttributesRulesSpec extends AnyWordSpecLike {
val descriptor: CatalogDescriptor = SpecData.descriptor.copy(attributes = descriptorAttr)
val consumer: PersistentTenant = SpecData.tenant.copy(attributes = tenantAttr)

declaredAttributesSatisfied(descriptor, consumer) shouldBe false
declaredAttributesSatisfied(descriptor, consumer.attributes) shouldBe false
}

"return false if the CatalogItem group attribute is assigned but revoked" in {
Expand All @@ -281,7 +281,7 @@ class AttributesRulesSpec extends AnyWordSpecLike {
val descriptor: CatalogDescriptor = SpecData.descriptor.copy(attributes = descriptorAttr)
val consumer: PersistentTenant = SpecData.tenant.copy(attributes = tenantAttr)

declaredAttributesSatisfied(descriptor, consumer) shouldBe false
declaredAttributesSatisfied(descriptor, consumer.attributes) shouldBe false
}
}

Expand All @@ -305,7 +305,7 @@ class AttributesRulesSpec extends AnyWordSpecLike {
val descriptor: CatalogDescriptor = SpecData.descriptor.copy(attributes = descriptorAttr)
val consumer: PersistentTenant = SpecData.tenant.copy(attributes = tenantAttr)

verifiedAttributesSatisfied(agreement, descriptor, consumer) shouldBe true
verifiedAttributesSatisfied(agreement, descriptor, consumer.attributes) shouldBe true
}

"return true if at least one attribute in every CatalogItem group attribute is satisfied" in {
Expand All @@ -332,7 +332,7 @@ class AttributesRulesSpec extends AnyWordSpecLike {
val descriptor: CatalogDescriptor = SpecData.descriptor.copy(attributes = descriptorAttr)
val consumer: PersistentTenant = SpecData.tenant.copy(attributes = tenantAttr)

verifiedAttributesSatisfied(agreement, descriptor, consumer) shouldBe true
verifiedAttributesSatisfied(agreement, descriptor, consumer.attributes) shouldBe true
}

"return true if CatalogItem single and group attributes are satisfied" in {
Expand All @@ -356,7 +356,7 @@ class AttributesRulesSpec extends AnyWordSpecLike {
val descriptor: CatalogDescriptor = SpecData.descriptor.copy(attributes = descriptorAttr)
val consumer: PersistentTenant = SpecData.tenant.copy(attributes = tenantAttr)

verifiedAttributesSatisfied(agreement, descriptor, consumer) shouldBe true
verifiedAttributesSatisfied(agreement, descriptor, consumer.attributes) shouldBe true
}

"return false if at least one CatalogItem single attribute is not satisfied" in {
Expand All @@ -377,7 +377,7 @@ class AttributesRulesSpec extends AnyWordSpecLike {
val descriptor: CatalogDescriptor = SpecData.descriptor.copy(attributes = descriptorAttr)
val consumer: PersistentTenant = SpecData.tenant.copy(attributes = tenantAttr)

verifiedAttributesSatisfied(agreement, descriptor, consumer) shouldBe false
verifiedAttributesSatisfied(agreement, descriptor, consumer.attributes) shouldBe false
}

"return false if at least one CatalogItem group attribute is not satisfied" in {
Expand All @@ -403,7 +403,7 @@ class AttributesRulesSpec extends AnyWordSpecLike {
val descriptor: CatalogDescriptor = SpecData.descriptor.copy(attributes = descriptorAttr)
val consumer: PersistentTenant = SpecData.tenant.copy(attributes = tenantAttr)

verifiedAttributesSatisfied(agreement, descriptor, consumer) shouldBe false
verifiedAttributesSatisfied(agreement, descriptor, consumer.attributes) shouldBe false
}

"return false if an CatalogItem single attribute is assigned but not verified" in {
Expand All @@ -420,7 +420,7 @@ class AttributesRulesSpec extends AnyWordSpecLike {
val descriptor: CatalogDescriptor = SpecData.descriptor.copy(attributes = descriptorAttr)
val consumer: PersistentTenant = SpecData.tenant.copy(attributes = tenantAttr)

verifiedAttributesSatisfied(agreement, descriptor, consumer) shouldBe false
verifiedAttributesSatisfied(agreement, descriptor, consumer.attributes) shouldBe false
}

"return false if the CatalogItem group attribute is assigned but not verified" in {
Expand All @@ -437,7 +437,7 @@ class AttributesRulesSpec extends AnyWordSpecLike {
val descriptor: CatalogDescriptor = SpecData.descriptor.copy(attributes = descriptorAttr)
val consumer: PersistentTenant = SpecData.tenant.copy(attributes = tenantAttr)

verifiedAttributesSatisfied(agreement, descriptor, consumer) shouldBe false
verifiedAttributesSatisfied(agreement, descriptor, consumer.attributes) shouldBe false
}

"return false if a single attribute is verified but not by the PersistentAgreement producer" in {
Expand All @@ -457,7 +457,7 @@ class AttributesRulesSpec extends AnyWordSpecLike {
val descriptor: CatalogDescriptor = SpecData.descriptor.copy(attributes = descriptorAttr)
val consumer: PersistentTenant = SpecData.tenant.copy(attributes = tenantAttr)

verifiedAttributesSatisfied(agreement, descriptor, consumer) shouldBe false
verifiedAttributesSatisfied(agreement, descriptor, consumer.attributes) shouldBe false
}

"return false if a group attribute is verified but not by the PersistentAgreement producer" in {
Expand All @@ -477,7 +477,7 @@ class AttributesRulesSpec extends AnyWordSpecLike {
val descriptor: CatalogDescriptor = SpecData.descriptor.copy(attributes = descriptorAttr)
val consumer: PersistentTenant = SpecData.tenant.copy(attributes = tenantAttr)

verifiedAttributesSatisfied(agreement, descriptor, consumer) shouldBe false
verifiedAttributesSatisfied(agreement, descriptor, consumer.attributes) shouldBe false
}

"return false if at least one single attribute is expired" in {
Expand All @@ -502,7 +502,7 @@ class AttributesRulesSpec extends AnyWordSpecLike {
val descriptor: CatalogDescriptor = SpecData.descriptor.copy(attributes = descriptorAttr)
val consumer: PersistentTenant = SpecData.tenant.copy(attributes = tenantAttr)

verifiedAttributesSatisfied(agreement, descriptor, consumer) shouldBe false
verifiedAttributesSatisfied(agreement, descriptor, consumer.attributes) shouldBe false
}

"return false if at least one group attribute is expired" in {
Expand Down Expand Up @@ -532,7 +532,7 @@ class AttributesRulesSpec extends AnyWordSpecLike {
val descriptor: CatalogDescriptor = SpecData.descriptor.copy(attributes = descriptorAttr)
val consumer: PersistentTenant = SpecData.tenant.copy(attributes = tenantAttr)

verifiedAttributesSatisfied(agreement, descriptor, consumer) shouldBe false
verifiedAttributesSatisfied(agreement, descriptor, consumer.attributes) shouldBe false
}
}
}
Loading

0 comments on commit 6d1ef1d

Please sign in to comment.