Skip to content

Commit

Permalink
tests: update with latest models
Browse files Browse the repository at this point in the history
Signed-off-by: Anton Baliasnikov <anton.baliasnikov@iohk.io>
  • Loading branch information
Anton Baliasnikov committed Oct 24, 2023
1 parent 4db0af8 commit 99a1ae6
Show file tree
Hide file tree
Showing 23 changed files with 123 additions and 241 deletions.
2 changes: 1 addition & 1 deletion tests/integration-tests/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ dependencies {
implementation("io.ktor:ktor-server-netty:2.3.0")
implementation("io.ktor:ktor-client-apache:2.3.0")
// RestAPI client
implementation("io.iohk.atala.prism:prism-kotlin-client:1.15.0")
implementation("io.iohk.atala.prism:prism-kotlin-client:1.18.0")
// Test helpers library
testImplementation("io.iohk.atala:atala-automation:0.3.0")
// Hoplite for configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ object TestConstants {
)
val RANDOM_CONSTAND_UUID = UUID.randomUUID().toString()
val DID_UPDATE_PUBLISH_MAX_WAIT_5_MIN = Duration.ofSeconds(60L)
val PRISM_DID_AUTH_KEY = ManagedDIDKeyTemplate("auth-1", Purpose.authentication)
val PRISM_DID_ASSERTION_KEY = ManagedDIDKeyTemplate("assertion-1", Purpose.assertionMethod)
val PRISM_DID_UPDATE_NEW_AUTH_KEY = ManagedDIDKeyTemplate("auth-2", Purpose.authentication)
val PRISM_DID_AUTH_KEY = ManagedDIDKeyTemplate("auth-1", Purpose.AUTHENTICATION)
val PRISM_DID_ASSERTION_KEY = ManagedDIDKeyTemplate("assertion-1", Purpose.ASSERTION_METHOD)
val PRISM_DID_UPDATE_NEW_AUTH_KEY = ManagedDIDKeyTemplate("auth-2", Purpose.AUTHENTICATION)
val PRISM_DID_SERVICE = Service(
"https://foo.bar.com",
listOf("LinkedDomains"),
Expand Down
3 changes: 2 additions & 1 deletion tests/integration-tests/src/test/kotlin/config/AgentConf.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ import java.net.URL
data class AgentConf(
val url: URL,
@ConfigAlias("webhook_url") val webhookUrl: URL?,
var apikey: String?
var apikey: String?,
@ConfigAlias("multi-tenant") val multiTenant: Boolean?,
)
3 changes: 2 additions & 1 deletion tests/integration-tests/src/test/kotlin/config/GlobalConf.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ import com.sksamuel.hoplite.ConfigAlias
data class GlobalConf(
@ConfigAlias("auth_required") val authRequired: Boolean,
@ConfigAlias("auth_header") val authHeader: String,
@ConfigAlias("admin_auth_header") val adminAuthHeader: String
@ConfigAlias("admin_auth_header") val adminAuthHeader: String,
@ConfigAlias("admin_apikey") val adminApiKey: String
)
174 changes: 65 additions & 109 deletions tests/integration-tests/src/test/kotlin/features/CommonSteps.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package features

import com.sksamuel.hoplite.ConfigLoader
import common.ListenToEvents
import config.AgentConf
import config.Config
import features.connection.ConnectionSteps
import features.credentials.IssueCredentialsSteps
Expand All @@ -27,112 +28,91 @@ import java.util.*
import kotlin.random.Random

@OptIn(ExperimentalStdlibApi::class)
@BeforeAll
fun initializeIssuerVerifierMultitenantAgent() {
val eventSteps = EventsSteps()
val cast = Cast()

fun createWalletAndEntity(agentConf: AgentConf) {
val config = ConfigLoader().loadConfigOrThrow<Config>("/tests.conf")

cast.actorNamed("Admin", CallAnApi.at(config.admin.url.toExternalForm()))
cast.actorNamed(
"Acme",
CallAnApi.at(config.issuer.url.toExternalForm()),
ListenToEvents.at(config.issuer.webhookUrl!!)
)
cast.actorNamed(
"Bob",
CallAnApi.at(config.holder.url.toExternalForm()),
ListenToEvents.at(config.holder.webhookUrl!!)
)
cast.actorNamed(
"Faber",
CallAnApi.at(config.verifier.url.toExternalForm()),
ListenToEvents.at(config.verifier.webhookUrl!!)
)
OnStage.setTheStage(cast)

// Create issuer wallet and tenant
val createIssuerWalletResponse = RestAssured
val createWalletResponse = RestAssured
.given().body(
CreateWalletRequest(
name = "IssuerWallet",
name = UUID.randomUUID().toString(),
seed = Random.nextBytes(64).toHexString(),
id = UUID.randomUUID()
)
)
.header(config.global.adminAuthHeader, config.admin.apikey)
.post("${config.issuer.url}/wallets")
.header(config.global.adminAuthHeader, config.global.adminApiKey)
.post("${agentConf.url}/wallets")
.thenReturn()
Ensure.that(createIssuerWalletResponse.statusCode).isEqualTo(HttpStatus.SC_CREATED)
val issuerWallet = createIssuerWalletResponse.body.jsonPath().getObject("", WalletDetail::class.java)

val issuerTenantResponse = RestAssured
Ensure.that(createWalletResponse.statusCode).isEqualTo(HttpStatus.SC_CREATED)
val wallet = createWalletResponse.body.jsonPath().getObject("", WalletDetail::class.java)
val tenantResponse = RestAssured
.given().body(
CreateEntityRequest(
name = "Issuer",
walletId = issuerWallet.id
name = UUID.randomUUID().toString(),
walletId = wallet.id
)
)
.header(config.global.adminAuthHeader, config.admin.apikey)
.post("${config.issuer.url}/iam/entities")
.header(config.global.adminAuthHeader, config.global.adminApiKey)
.post("${agentConf.url}/iam/entities")
.thenReturn()
Ensure.that(issuerTenantResponse.statusCode).isEqualTo(HttpStatus.SC_CREATED)
val issuerEntity = issuerTenantResponse.body.jsonPath().getObject("", EntityResponse::class.java)

val issuerAddApiKeyResponse =
Ensure.that(tenantResponse.statusCode).isEqualTo(HttpStatus.SC_CREATED)
val entity = tenantResponse.body.jsonPath().getObject("", EntityResponse::class.java)
val addApiKeyResponse =
RestAssured
.given().body(
ApiKeyAuthenticationRequest(
entityId = issuerEntity.id,
apiKey = config.issuer.apikey!!
entityId = entity.id,
apiKey = agentConf.apikey!!
)
)
.header(config.global.adminAuthHeader, config.admin.apikey)
.post("${config.issuer.url}/iam/apikey-authentication")
.header(config.global.adminAuthHeader, config.global.adminApiKey)
.post("${agentConf.url}/iam/apikey-authentication")
.thenReturn()
Ensure.that(issuerAddApiKeyResponse.statusCode).isEqualTo(HttpStatus.SC_CREATED)

// Create verifier wallet
val createVerifierWalletResponse = RestAssured
.given().body(
CreateWalletRequest(
name = "VerifierWallet",
seed = Random.nextBytes(64).toHexString(),
id = UUID.randomUUID()
)
)
.header(config.global.adminAuthHeader, config.admin.apikey)
.post("${config.verifier.url}/wallets")
.thenReturn()
Ensure.that(createVerifierWalletResponse.statusCode).isEqualTo(HttpStatus.SC_CREATED)
val verifierWallet = createVerifierWalletResponse.body.jsonPath().getObject("", WalletDetail::class.java)
// Create verifier tenant
val verifierTenantResponse = RestAssured
.given().body(
CreateEntityRequest(
name = "Verifier",
walletId = verifierWallet.id
)
)
.header(config.global.adminAuthHeader, config.admin.apikey)
.post("${config.verifier.url}/iam/entities")
.thenReturn()
Ensure.that(verifierTenantResponse.statusCode).isEqualTo(HttpStatus.SC_CREATED)
val verifierEntity = verifierTenantResponse.body.jsonPath().getObject("", EntityResponse::class.java)
// Add verifier api key
val verifierAddApiKeyResponse =
Ensure.that(addApiKeyResponse.statusCode).isEqualTo(HttpStatus.SC_CREATED)
val registerIssuerWebhookResponse =
RestAssured
.given().body(
ApiKeyAuthenticationRequest(
entityId = verifierEntity.id,
apiKey = config.verifier.apikey!!
CreateWebhookNotification(
url = agentConf.webhookUrl!!.toExternalForm()
)
)
.header(config.global.adminAuthHeader, config.admin.apikey)
.post("${config.verifier.url}/iam/apikey-authentication")
.header(config.global.authHeader, agentConf.apikey)
.post("${agentConf.url}/events/webhooks")
.thenReturn()
Ensure.that(verifierAddApiKeyResponse.statusCode).isEqualTo(HttpStatus.SC_CREATED)
Ensure.that(registerIssuerWebhookResponse.statusCode).isEqualTo(HttpStatus.SC_CREATED)
}

@BeforeAll
fun initAgents() {
val cast = Cast()
val config = ConfigLoader().loadConfigOrThrow<Config>("/tests.conf")
cast.actorNamed(
"Admin",
CallAnApi.at(config.admin.url.toExternalForm())
)
cast.actorNamed(
"Acme",
CallAnApi.at(config.issuer.url.toExternalForm()),
ListenToEvents.at(config.issuer.webhookUrl!!)
)
cast.actorNamed(
"Bob",
CallAnApi.at(config.holder.url.toExternalForm()),
ListenToEvents.at(config.holder.webhookUrl!!)
)
cast.actorNamed(
"Faber",
CallAnApi.at(config.verifier.url.toExternalForm()),
ListenToEvents.at(config.verifier.webhookUrl!!)
)
OnStage.setTheStage(cast)

// Create issuer wallet and tenant
if (config.issuer.multiTenant!!) {
createWalletAndEntity(config.issuer)
}
// Create verifier wallet
if (config.verifier.multiTenant!!) {
createWalletAndEntity(config.verifier)
}

cast.actors.forEach { actor ->
when (actor.name) {
Expand All @@ -147,30 +127,6 @@ fun initializeIssuerVerifierMultitenantAgent() {
}
}
}

val registerIssuerWebhookResponse =
RestAssured
.given().body(
CreateWebhookNotification(
url = config.issuer.webhookUrl.toExternalForm()
)
)
.header(config.global.authHeader, config.issuer.apikey)
.post("${config.issuer.url}/events/webhooks")
.thenReturn()
Ensure.that(registerIssuerWebhookResponse.statusCode).isEqualTo(HttpStatus.SC_CREATED)

val registerVerifierWebhookResponse =
RestAssured
.given().body(
CreateWebhookNotification(
url = config.verifier.webhookUrl.toExternalForm()
)
)
.header(config.global.authHeader, config.verifier.apikey)
.post("${config.verifier.url}/events/webhooks")
.thenReturn()
Ensure.that(registerVerifierWebhookResponse.statusCode).isEqualTo(HttpStatus.SC_CREATED)
}

@AfterAll
Expand All @@ -193,7 +149,7 @@ class CommonSteps {
Ensure.thatTheLastResponse().statusCode().isEqualTo(SC_OK)
)
val receivedCredential = SerenityRest.lastResponse().get<IssueCredentialRecordPage>().contents!!.findLast { credential ->
credential.protocolState == IssueCredentialRecord.ProtocolState.credentialReceived
credential.protocolState == IssueCredentialRecord.ProtocolState.CREDENTIAL_RECEIVED
}

if (receivedCredential != null) {
Expand Down Expand Up @@ -221,7 +177,7 @@ class CommonSteps {
Ensure.thatTheLastResponse().statusCode().isEqualTo(SC_OK)
)
val inviterConnection = SerenityRest.lastResponse().get<ConnectionsPage>().contents!!.firstOrNull {
it.label == "Connection with ${invitee.name}" && it.state == Connection.State.connectionResponseSent
it.label == "Connection with ${invitee.name}" && it.state == Connection.State.CONNECTION_RESPONSE_SENT
}

var inviteeConnection: Connection? = null
Expand All @@ -233,7 +189,7 @@ class CommonSteps {
Ensure.thatTheLastResponse().statusCode().isEqualTo(SC_OK)
)
inviteeConnection = SerenityRest.lastResponse().get<ConnectionsPage>().contents!!.firstOrNull {
it.theirDid == inviterConnection.myDid && it.state == Connection.State.connectionResponseReceived
it.theirDid == inviterConnection.myDid && it.state == Connection.State.CONNECTION_RESPONSE_RECEIVED
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ class ConnectionSteps {
inviter.attemptsTo(
Ensure.thatTheLastResponse().statusCode().isEqualTo(SC_CREATED),
Ensure.that(connection.label!!).isEqualTo(connectionLabel),
Ensure.that(connection.state).isEqualTo(Connection.State.invitationGenerated),
Ensure.that(connection.role).isEqualTo(Connection.Role.inviter)
Ensure.that(connection.state).isEqualTo(Connection.State.INVITATION_GENERATED),
Ensure.that(connection.role).isEqualTo(Connection.Role.INVITER)
)

// Acme remembers connection to send it out of band to Bob
Expand Down Expand Up @@ -68,8 +68,8 @@ class ConnectionSteps {
Ensure.that(inviteeConnection.invitation.id).isEqualTo(inviterConnection.invitation.id),
Ensure.that(inviteeConnection.invitation.invitationUrl).isEqualTo(inviterConnection.invitation.invitationUrl),
Ensure.that(inviteeConnection.invitation.type).isEqualTo(inviterConnection.invitation.type),
Ensure.that(inviteeConnection.state).isEqualTo(Connection.State.connectionRequestPending),
Ensure.that(inviteeConnection.role).isEqualTo(Connection.Role.invitee)
Ensure.that(inviteeConnection.state).isEqualTo(Connection.State.CONNECTION_REQUEST_PENDING),
Ensure.that(inviteeConnection.role).isEqualTo(Connection.Role.INVITEE)
)

invitee.remember("connection", inviteeConnection)
Expand All @@ -83,9 +83,9 @@ class ConnectionSteps {
it.data.thid == inviter.recall<Connection>("connection").thid
}
lastEvent != null &&
lastEvent.data.state == Connection.State.connectionResponseSent
lastEvent.data.state == Connection.State.CONNECTION_RESPONSE_SENT
},
"Inviter connection didn't reach ${Connection.State.connectionResponseSent} state"
"Inviter connection didn't reach ${Connection.State.CONNECTION_RESPONSE_SENT} state"
)
}

Expand All @@ -98,9 +98,9 @@ class ConnectionSteps {
it.data.thid == invitee.recall<Connection>("connection").thid
}
lastEvent != null &&
lastEvent.data.state == Connection.State.connectionResponseReceived
lastEvent.data.state == Connection.State.CONNECTION_RESPONSE_RECEIVED
},
"Invitee connection didn't reach ${Connection.State.connectionResponseReceived} state."
"Invitee connection didn't reach ${Connection.State.CONNECTION_RESPONSE_RECEIVED} state."
)
}

Expand Down Expand Up @@ -128,8 +128,8 @@ class ConnectionSteps {
assertThat(inviter.recall<Connection>("connection-with-${invitee.name}").theirDid)
.isEqualTo(invitee.recall<Connection>("connection-with-${inviter.name}").myDid)
assertThat(inviter.recall<Connection>("connection-with-${invitee.name}").state)
.isEqualTo(Connection.State.connectionResponseSent)
.isEqualTo(Connection.State.CONNECTION_RESPONSE_SENT)
assertThat(invitee.recall<Connection>("connection-with-${inviter.name}").state)
.isEqualTo(Connection.State.connectionResponseReceived)
.isEqualTo(Connection.State.CONNECTION_RESPONSE_RECEIVED)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class IssueCredentialsSteps {
"lastName" to "LastName"
),
issuingDID = did,
connectionId = issuer.recall<Connection>("connection-with-${holder.name}").connectionId.toString(),
connectionId = issuer.recall<Connection>("connection-with-${holder.name}").connectionId,
validityPeriod = 3600.0,
automaticIssuance = false
)
Expand Down Expand Up @@ -66,9 +66,10 @@ class IssueCredentialsSteps {
it.data.thid == holder.recall<String>("thid")
}
credentialEvent != null &&
credentialEvent!!.data.protocolState == IssueCredentialRecord.ProtocolState.offerReceived
credentialEvent!!.data.protocolState == IssueCredentialRecord.ProtocolState.OFFER_RECEIVED
},
"Holder was unable to receive the credential offer from Issuer! Protocol state did not achieve OfferReceived state."
"Holder was unable to receive the credential offer from Issuer! " +
"Protocol state did not achieve ${IssueCredentialRecord.ProtocolState.OFFER_RECEIVED} state."
)

val recordId = ListenToEvents.`as`(holder).credentialEvents.last().data.recordId
Expand All @@ -95,7 +96,7 @@ class IssueCredentialsSteps {
it.data.thid == issuer.recall<String>("thid")
}
credentialEvent != null &&
credentialEvent!!.data.protocolState == IssueCredentialRecord.ProtocolState.requestReceived
credentialEvent!!.data.protocolState == IssueCredentialRecord.ProtocolState.REQUEST_RECEIVED
},
"Issuer was unable to receive the credential request from Holder! Protocol state did not achieve RequestReceived state."
)
Expand All @@ -113,10 +114,10 @@ class IssueCredentialsSteps {
it.data.thid == issuer.recall<String>("thid")
}
credentialEvent != null &&
credentialEvent!!.data.protocolState == IssueCredentialRecord.ProtocolState.credentialSent
credentialEvent!!.data.protocolState == IssueCredentialRecord.ProtocolState.CREDENTIAL_SENT
},
"Issuer was unable to issue the credential! " +
"Protocol state did not achieve ${IssueCredentialRecord.ProtocolState.credentialSent} state."
"Protocol state did not achieve ${IssueCredentialRecord.ProtocolState.CREDENTIAL_SENT} state."
)
}

Expand All @@ -128,10 +129,10 @@ class IssueCredentialsSteps {
it.data.thid == holder.recall<String>("thid")
}
credentialEvent != null &&
credentialEvent!!.data.protocolState == IssueCredentialRecord.ProtocolState.credentialReceived
credentialEvent!!.data.protocolState == IssueCredentialRecord.ProtocolState.CREDENTIAL_RECEIVED
},
"Holder was unable to receive the credential from Issuer! " +
"Protocol state did not achieve ${IssueCredentialRecord.ProtocolState.credentialReceived} state."
"Protocol state did not achieve ${IssueCredentialRecord.ProtocolState.CREDENTIAL_RECEIVED} state."
)
holder.remember("issuedCredential", ListenToEvents.`as`(holder).credentialEvents.last().data)
}
Expand Down
Loading

0 comments on commit 99a1ae6

Please sign in to comment.