Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/test/keycloak-authz-test'
Browse files Browse the repository at this point in the history
# Conflicts:
#	build.sbt
#	shared-test/src/main/scala/io/iohk/atala/sharedtest/containers/KeycloakTestContainer.scala
#	shared-test/src/main/scala/io/iohk/atala/sharedtest/containers/KeycloakTestContainerSupport.scala
#	shared-test/src/main/scala/io/iohk/atala/sharedtest/containers/PostgresLayer.scala
#	shared-test/src/test/scala/io/iohk/atala/sharedtest/containers/KeycloakTestContainerSupportSpec.scala
  • Loading branch information
yshyn-iohk committed Nov 1, 2023
2 parents 0e396af + 7f02810 commit 6d8d05b
Show file tree
Hide file tree
Showing 47 changed files with 499 additions and 308 deletions.
5 changes: 4 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,7 @@ lazy val polluxDoobie = project
)
.dependsOn(polluxCore % "compile->compile;test->test")
.dependsOn(shared)
.dependsOn(sharedTest % Test)

// ########################
// ### Pollux Anoncreds ###
Expand Down Expand Up @@ -775,6 +776,7 @@ lazy val connectDoobie = project
libraryDependencies ++= D_Connect.sqlDoobieDependencies
)
.dependsOn(shared)
.dependsOn(sharedTest % Test)
.dependsOn(connectCore % "compile->compile;test->test")

// ############################
Expand Down Expand Up @@ -810,6 +812,7 @@ lazy val prismAgentWalletAPI = project
castorCore,
eventNotification
)
.dependsOn(sharedTest % Test)

lazy val prismAgentServer = project
.in(file("prism-agent/service/server"))
Expand All @@ -831,7 +834,6 @@ lazy val prismAgentServer = project
.enablePlugins(JavaAppPackaging, DockerPlugin, AshScriptPlugin)
.enablePlugins(BuildInfoPlugin)
.dependsOn(prismAgentWalletAPI % "compile->compile;test->test")
.dependsOn(sharedTest % "compile->compile;test->test")
.dependsOn(
agent,
polluxCore,
Expand All @@ -842,6 +844,7 @@ lazy val prismAgentServer = project
castorCore,
eventNotification
)
.dependsOn(sharedTest % Test)

// ############################
// #### Release process #####
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import io.iohk.atala.mercury.protocol.connection.{ConnectionRequest, ConnectionR
import io.iohk.atala.mercury.protocol.invitation.v2.Invitation

import java.time.Instant
import java.time.temporal.ChronoUnit
import java.util.UUID

/** @param id
Expand Down Expand Up @@ -38,7 +39,13 @@ case class ConnectionRecord(
metaRetries: Int,
metaNextRetry: Option[Instant],
metaLastFailure: Option[String]
)
) {
def withTruncatedTimestamp(unit: ChronoUnit = ChronoUnit.MICROS): ConnectionRecord = copy(
createdAt = createdAt.truncatedTo(unit),
updatedAt = updatedAt.map(_.truncatedTo(unit)),
metaNextRetry = metaNextRetry.map(_.truncatedTo(unit))
)
}

object ConnectionRecord {
enum Role:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ object ConnectionRepositorySpecSuite {
maxRetries,
Some(Instant.now),
None
)
).withTruncatedTimestamp()

private def connectionRequest = ConnectionRequest(
from = DidId("did:prism:aaa"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package io.iohk.atala.connect.sql.repository
import com.dimafeng.testcontainers.PostgreSQLContainer
import io.iohk.atala.connect.core.repository.{ConnectionRepository, ConnectionRepositorySpecSuite}
import io.iohk.atala.shared.db.DbConfig
import io.iohk.atala.shared.test.containers.PostgresTestContainerSupport
import io.iohk.atala.sharedtest.containers.PostgresTestContainerSupport
import zio.*
import zio.test.*

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package io.iohk.atala.test.container

import com.dimafeng.testcontainers.PostgreSQLContainer
import io.iohk.atala.sharedtest.containers.PostgresTestContainer.postgresContainer
import zio.*
import zio.ZIO.*
import io.iohk.atala.shared.test.containers.PostgresTestContainer.postgresContainer

object PostgresLayer {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@ import zio.*
import java.net.URL
import java.time.Instant
import java.util.UUID
import java.time.temporal.ChronoUnit

final case class EventNotificationConfig(
id: UUID,
walletId: WalletId,
url: URL,
customHeaders: Map[String, String],
createdAt: Instant
)
) {
def withTruncatedTimestamp(unit: ChronoUnit = ChronoUnit.MICROS): EventNotificationConfig =
copy(createdAt = createdAt.truncatedTo(unit))
}

object EventNotificationConfig {
def apply(walletId: WalletId, url: URL, customHeaders: Map[String, String] = Map.empty): EventNotificationConfig =
Expand All @@ -24,7 +28,7 @@ object EventNotificationConfig {
url = url,
customHeaders = customHeaders,
createdAt = Instant.now
)
).withTruncatedTimestamp()

def applyWallet(url: URL, customHeaders: Map[String, String]): URIO[WalletAccessContext, EventNotificationConfig] =
ZIO.serviceWith[WalletAccessContext](ctx => apply(ctx.walletId, url, customHeaders))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import io.iohk.atala.pollux.anoncreds.CredentialRequestMetadata
import io.iohk.atala.pollux.core.model.IssueCredentialRecord.*

import java.time.Instant
import java.time.temporal.ChronoUnit
import java.util.UUID

final case class IssueCredentialRecord(
Expand Down Expand Up @@ -57,7 +58,14 @@ final case class IssueCredentialRecord(
case CredentialFormat.AnonCreds => (IssueCredentialIssuedFormat.Anoncred, data)
}

def withTruncatedTimestamp(unit: ChronoUnit = ChronoUnit.MICROS): IssueCredentialRecord =
copy(
createdAt = createdAt.truncatedTo(unit),
updatedAt = updatedAt.map(_.truncatedTo(unit)),
metaNextRetry = metaNextRetry.map(_.truncatedTo(unit)),
)
}

final case class ValidIssuedCredentialRecord(
id: DidCommID,
issuedCredentialRaw: Option[String],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import io.iohk.atala.mercury.protocol.presentproof.ProposePresentation
import io.iohk.atala.mercury.protocol.presentproof.RequestPresentation
import io.iohk.atala.mercury.protocol.presentproof.Presentation
import io.iohk.atala.mercury.model.DidId

import java.time.Instant
import java.time.temporal.ChronoUnit

final case class PresentationRecord(
id: DidCommID,
Expand All @@ -24,7 +26,14 @@ final case class PresentationRecord(
metaRetries: Int,
metaNextRetry: Option[Instant],
metaLastFailure: Option[String],
)
) {
def withTruncatedTimestamp(unit: ChronoUnit = ChronoUnit.MICROS): PresentationRecord =
copy(
createdAt = createdAt.truncatedTo(unit),
updatedAt = updatedAt.map(_.truncatedTo(unit)),
metaNextRetry = metaNextRetry.map(_.truncatedTo(unit)),
)
}

object PresentationRecord {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ object CredentialRepositorySpecSuite {
metaRetries = maxRetries,
metaNextRetry = Some(Instant.now()),
metaLastFailure = None,
)
).withTruncatedTimestamp()

private def requestCredential = RequestCredential(
from = DidId("did:prism:aaa"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ object PresentationRepositorySpecSuite {
metaRetries = maxRetries,
metaNextRetry = Some(Instant.now()),
metaLastFailure = None,
)
).withTruncatedTimestamp()

private def requestPresentation = RequestPresentation(
from = DidId("did:prism:aaa"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import io.iohk.atala.pollux.core.model.schema.{CorrectnessProof, Definition}
import io.iohk.atala.shared.models.WalletId

import java.time.OffsetDateTime
import java.time.temporal.ChronoUnit
import java.util.UUID

case class CredentialDefinition(
Expand All @@ -29,6 +30,9 @@ case class CredentialDefinition(
walletId: WalletId
) {
lazy val uniqueConstraintKey = author + name + version

def withTruncatedTimestamp(unit: ChronoUnit = ChronoUnit.MICROS): CredentialDefinition =
copy(authored = authored.truncatedTo(unit))
}

object CredentialDefinition {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import io.iohk.atala.pollux.core.model.schema.Schema
import io.iohk.atala.shared.models.WalletId

import java.time.OffsetDateTime
import java.time.temporal.ChronoUnit
import java.util.UUID

case class CredentialSchema(
Expand All @@ -24,6 +25,10 @@ case class CredentialSchema(
walletId: WalletId
) {
lazy val uniqueConstraintKey = author + name + version

def withTruncatedTimestamp(unit: ChronoUnit = ChronoUnit.MICROS): CredentialSchema =
copy(authored = authored.truncatedTo(unit))

}

object CredentialSchema {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import io.iohk.atala.pollux.sql.model.db.{CredentialDefinition, CredentialDefini
import io.iohk.atala.shared.db.ContextAwareTask
import io.iohk.atala.shared.db.Implicits.*
import io.iohk.atala.shared.models.{WalletAccessContext, WalletId}
import io.iohk.atala.shared.test.containers.PostgresTestContainerSupport
import io.iohk.atala.sharedtest.containers.PostgresTestContainerSupport
import io.iohk.atala.test.container.MigrationAspects.*
import zio.*
import zio.json.ast.Json
Expand Down Expand Up @@ -110,7 +110,7 @@ object CredentialDefinitionSqlIntegrationSpec extends ZIOSpecDefault with Postgr
signatureType = signatureType,
supportRevocation = supportRevocation,
walletId = walletId
)
).withTruncatedTimestamp()

private val unique = mutable.Set.empty[String]
val credentialDefinitionUnique = for {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import io.iohk.atala.shared.db.ContextAwareTask
import io.iohk.atala.shared.db.Implicits.*
import io.iohk.atala.shared.models.WalletAccessContext
import io.iohk.atala.shared.models.WalletId
import io.iohk.atala.shared.test.containers.PostgresTestContainerSupport
import io.iohk.atala.sharedtest.containers.PostgresTestContainerSupport
import io.iohk.atala.test.container.MigrationAspects.*
import zio.*
import zio.json.ast.Json
Expand Down Expand Up @@ -88,7 +88,7 @@ object CredentialSchemaSqlIntegrationSpec extends ZIOSpecDefault, PostgresTestCo
authored = authored,
tags = tags,
walletId = walletId
)
).withTruncatedTimestamp()

private val unique = mutable.Set.empty[String]
val schemaUnique = for {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import io.iohk.atala.shared.db.ContextAwareTask
import io.iohk.atala.shared.db.Implicits.*
import io.iohk.atala.shared.models.WalletAccessContext
import io.iohk.atala.shared.models.WalletId
import io.iohk.atala.shared.test.containers.PostgresTestContainerSupport
import io.iohk.atala.sharedtest.containers.PostgresTestContainerSupport
import io.iohk.atala.test.container.MigrationAspects.*
import zio.*
import zio.test.*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package io.iohk.atala.pollux.sql.repository
import com.dimafeng.testcontainers.PostgreSQLContainer
import io.iohk.atala.pollux.core.repository._
import io.iohk.atala.shared.db.DbConfig
import io.iohk.atala.shared.test.containers.PostgresTestContainerSupport
import io.iohk.atala.sharedtest.containers.PostgresTestContainerSupport
import zio._
import zio.test._

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package io.iohk.atala.pollux.sql.repository
import com.dimafeng.testcontainers.PostgreSQLContainer
import io.iohk.atala.pollux.core.repository._
import io.iohk.atala.shared.db.DbConfig
import io.iohk.atala.shared.test.containers.PostgresTestContainerSupport
import io.iohk.atala.sharedtest.containers.PostgresTestContainerSupport
import zio._
import zio.test._

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package io.iohk.atala.pollux.vc.jwt

import com.nimbusds.jose.jwk.{Curve, ECKey}
import com.nimbusds.jose.crypto.bc.BouncyCastleProviderSingleton
import com.nimbusds.jose.jwk.gen.ECKeyGenerator
import com.nimbusds.jose.jwk.{Curve, ECKey}
import io.circe.*
import io.circe.syntax.*
import io.iohk.atala.castor.core.model.did.VerificationRelationship
Expand All @@ -10,10 +11,13 @@ import zio.*
import zio.test.*
import zio.test.Assertion.*

import java.security.Security
import java.time.Instant

object JWTVerificationTest extends ZIOSpecDefault {

Security.insertProviderAt(BouncyCastleProviderSingleton.getInstance(), 2)

case class IssuerWithKey(issuer: Issuer, key: ECKey)

private def createUser(did: DID): IssuerWithKey = {
Expand Down Expand Up @@ -252,6 +256,6 @@ object JWTVerificationTest extends ZIOSpecDefault {
validation <- JwtCredential.validateEncodedJWT(jwtCredential)(resolver)
} yield assert(validation.fold(_ => false, _ => true))(equalTo(false))
}
).when(!sys.props.get("os.name").contains("Mac OS X")) // Mac OS X throws `Curve not supported: secp256k1`
)

}
Loading

0 comments on commit 6d8d05b

Please sign in to comment.