Skip to content

Commit

Permalink
test: finish fixing jwt revocation
Browse files Browse the repository at this point in the history
Signed-off-by: Allain Magyar <allain.magyar@iohk.io>
  • Loading branch information
amagyar-iohk committed May 7, 2024
1 parent ab8ffcb commit 8684124
Show file tree
Hide file tree
Showing 18 changed files with 280 additions and 381 deletions.
28 changes: 0 additions & 28 deletions tests/integration-tests/src/test/kotlin/common/Utils.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class CommonSteps {

val publishDidSteps = PublishDidSteps()
publishDidSteps.createsUnpublishedDid(holder)
publishDidSteps.actorHavePublishedPrismDid(issuer)
publishDidSteps.agentHasAPublishedDID(issuer)

val issueSteps = IssueCredentialsSteps()
issueSteps.issuerOffersACredential(issuer, holder, "short")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
package steps.connection

import abilities.ListenToEvents
import common.Utils.wait
import interactions.Get
import interactions.Post
import io.cucumber.java.en.Then
import io.cucumber.java.en.When
import io.iohk.atala.automation.extensions.get
import io.iohk.atala.automation.serenity.ensure.Ensure
import io.iohk.atala.automation.utils.Wait
import net.serenitybdd.rest.SerenityRest
import net.serenitybdd.screenplay.Actor
import org.apache.http.HttpStatus.SC_CREATED
import org.apache.http.HttpStatus.SC_OK
import org.assertj.core.api.Assertions.assertThat
import org.hyperledger.identus.client.models.AcceptConnectionInvitationRequest
import org.hyperledger.identus.client.models.Connection
import org.hyperledger.identus.client.models.CreateConnectionRequest
import org.hyperledger.identus.client.models.*

class ConnectionSteps {

Expand Down Expand Up @@ -66,7 +64,8 @@ class ConnectionSteps {
Ensure.thatTheLastResponse().statusCode().isEqualTo(SC_OK),
Ensure.that(inviteeConnection.invitation.from).isEqualTo(inviterConnection.invitation.from),
Ensure.that(inviteeConnection.invitation.id).isEqualTo(inviterConnection.invitation.id),
Ensure.that(inviteeConnection.invitation.invitationUrl).isEqualTo(inviterConnection.invitation.invitationUrl),
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.CONNECTION_REQUEST_PENDING),
Ensure.that(inviteeConnection.role).isEqualTo(Connection.Role.INVITEE),
Expand All @@ -77,31 +76,27 @@ class ConnectionSteps {

@When("{actor} receives the connection request and sends back the response")
fun inviterReceivesTheConnectionRequest(inviter: Actor) {
wait(
{
val lastEvent = ListenToEvents.with(inviter).connectionEvents.lastOrNull {
it.data.thid == inviter.recall<Connection>("connection").thid
}
lastEvent != null &&
lastEvent.data.state == Connection.State.CONNECTION_RESPONSE_SENT
},
"Inviter connection didn't reach ${Connection.State.CONNECTION_RESPONSE_SENT} state",
)
Wait.until(
errorMessage = "Inviter connection didn't reach ${Connection.State.CONNECTION_RESPONSE_SENT} state"
) {
val lastEvent = ListenToEvents.with(inviter).connectionEvents.lastOrNull {
it.data.thid == inviter.recall<Connection>("connection").thid
}
lastEvent != null && lastEvent.data.state == Connection.State.CONNECTION_RESPONSE_SENT
}
}

@When("{actor} receives the connection response")
fun inviteeReceivesTheConnectionResponse(invitee: Actor) {
// Bob (Holder) receives final connection response
wait(
{
val lastEvent = ListenToEvents.with(invitee).connectionEvents.lastOrNull {
it.data.thid == invitee.recall<Connection>("connection").thid
}
lastEvent != null &&
Wait.until(
errorMessage = "Invitee connection didn't reach ${Connection.State.CONNECTION_RESPONSE_RECEIVED} state."
) {
val lastEvent = ListenToEvents.with(invitee).connectionEvents.lastOrNull {
it.data.thid == invitee.recall<Connection>("connection").thid
}
lastEvent != null &&
lastEvent.data.state == Connection.State.CONNECTION_RESPONSE_RECEIVED
},
"Invitee connection didn't reach ${Connection.State.CONNECTION_RESPONSE_RECEIVED} state.",
)
}
}

@Then("{actor} and {actor} have a connection")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,17 @@ package steps.credentials

import abilities.ListenToEvents
import common.CredentialSchema
import common.Utils.wait
import interactions.Post
import io.cucumber.java.en.Then
import io.cucumber.java.en.When
import io.iohk.atala.automation.extensions.get
import io.iohk.atala.automation.serenity.ensure.Ensure
import models.AnoncredsSchema
import io.iohk.atala.automation.utils.Wait
import models.CredentialEvent
import net.serenitybdd.rest.SerenityRest
import net.serenitybdd.screenplay.Actor
import net.serenitybdd.screenplay.rest.abilities.CallAnApi
import org.apache.http.HttpStatus.*
import org.hyperledger.identus.client.models.*
import java.util.UUID

class IssueCredentialsSteps {

Expand Down Expand Up @@ -108,65 +105,7 @@ class IssueCredentialsSteps {
"name" to "Name",
"surname" to "Surname",
)
sendCredentialOffer(issuer, holder, "short", schemaGuid, claims)
}

@When("{actor} creates anoncred schema")
fun acmeCreatesAnoncredSchema(issuer: Actor) {
issuer.attemptsTo(
Post.to("/schema-registry/schemas")
.with {
it.body(
CredentialSchemaInput(
author = issuer.recall("shortFormDid"),
name = UUID.randomUUID().toString(),
description = "Simple student credentials schema",
type = "AnoncredSchemaV1",
schema = AnoncredsSchema(
name = "StudentCredential",
version = "1.0",
issuerId = issuer.recall("shortFormDid"),
attrNames = listOf("name", "age", "sex"),
),
tags = listOf("school", "students"),
version = "1.0.0",
),
)
},
)
issuer.attemptsTo(
Ensure.thatTheLastResponse().statusCode().isEqualTo(SC_CREATED),
)
val schema = SerenityRest.lastResponse().get<CredentialSchemaResponse>()
issuer.remember("anoncredsSchema", schema)
}

@When("{actor} creates anoncred credential definition")
fun acmeCreatesAnoncredCredentialDefinition(issuer: Actor) {
val schemaRegistryUrl = issuer.usingAbilityTo(CallAnApi::class.java).resolve("/schema-registry/schemas")
.replace("localhost", "host.docker.internal")
issuer.attemptsTo(
Post.to("/credential-definition-registry/definitions")
.with {
it.body(
CredentialDefinitionInput(
name = "StudentCredential",
version = "1.0.0",
schemaId = "$schemaRegistryUrl/${issuer.recall<CredentialSchemaResponse>("anoncredsSchema").guid}/schema",
description = "Simple student credentials definition",
author = issuer.recall("shortFormDid"),
signatureType = "CL",
tag = "student",
supportRevocation = false,
),
)
},
)
issuer.attemptsTo(
Ensure.thatTheLastResponse().statusCode().isEqualTo(SC_CREATED),
)
val credentialDefinition = SerenityRest.lastResponse().get<CredentialDefinitionResponse>()
issuer.remember("anoncredsCredentialDefinition", credentialDefinition)
sendCredentialOffer(issuer, holder, format, schemaGuid, claims)
}

@When("{actor} offers anoncred to {actor}")
Expand Down Expand Up @@ -204,17 +143,16 @@ class IssueCredentialsSteps {

@When("{actor} receives the credential offer")
fun holderReceivesCredentialOffer(holder: Actor) {
wait(
{
credentialEvent = ListenToEvents.with(holder).credentialEvents.lastOrNull {
it.data.thid == holder.recall<String>("thid")
}
credentialEvent != null &&
Wait.until(
errorMessage = "Holder was unable to receive the credential offer from Issuer! " +
"Protocol state did not achieve ${IssueCredentialRecord.ProtocolState.OFFER_RECEIVED} state.",
) {
credentialEvent = ListenToEvents.with(holder).credentialEvents.lastOrNull {
it.data.thid == holder.recall<String>("thid")
}
credentialEvent != null &&
credentialEvent!!.data.protocolState == IssueCredentialRecord.ProtocolState.OFFER_RECEIVED
},
"Holder was unable to receive the credential offer from Issuer! " +
"Protocol state did not achieve ${IssueCredentialRecord.ProtocolState.OFFER_RECEIVED} state.",
)
}

val recordId = ListenToEvents.with(holder).credentialEvents.last().data.recordId
holder.remember("recordId", recordId)
Expand Down Expand Up @@ -252,16 +190,15 @@ class IssueCredentialsSteps {

@When("{actor} issues the credential")
fun acmeIssuesTheCredential(issuer: Actor) {
wait(
{
credentialEvent = ListenToEvents.with(issuer).credentialEvents.lastOrNull {
it.data.thid == issuer.recall<String>("thid")
}
credentialEvent != null &&
Wait.until(
errorMessage = "Issuer was unable to receive the credential request from Holder! Protocol state did not achieve RequestReceived state."
) {
credentialEvent = ListenToEvents.with(issuer).credentialEvents.lastOrNull {
it.data.thid == issuer.recall<String>("thid")
}
credentialEvent != null &&
credentialEvent!!.data.protocolState == IssueCredentialRecord.ProtocolState.REQUEST_RECEIVED
},
"Issuer was unable to receive the credential request from Holder! Protocol state did not achieve RequestReceived state.",
)
}
val recordId = credentialEvent!!.data.recordId
issuer.attemptsTo(
Post.to("/issue-credentials/records/$recordId/issue-credential"),
Expand All @@ -270,33 +207,31 @@ class IssueCredentialsSteps {
Ensure.thatTheLastResponse().statusCode().isEqualTo(SC_OK),
)

wait(
{
credentialEvent = ListenToEvents.with(issuer).credentialEvents.lastOrNull {
it.data.thid == issuer.recall<String>("thid")
}
issuer.remember("issuedCredential", credentialEvent!!.data)
credentialEvent != null &&
Wait.until(
errorMessage = "Issuer was unable to issue the credential! " +
"Protocol state did not achieve ${IssueCredentialRecord.ProtocolState.CREDENTIAL_SENT} state."
) {
credentialEvent = ListenToEvents.with(issuer).credentialEvents.lastOrNull {
it.data.thid == issuer.recall<String>("thid")
}
issuer.remember("issuedCredential", credentialEvent!!.data)
credentialEvent != null &&
credentialEvent!!.data.protocolState == IssueCredentialRecord.ProtocolState.CREDENTIAL_SENT
},
"Issuer was unable to issue the credential! " +
"Protocol state did not achieve ${IssueCredentialRecord.ProtocolState.CREDENTIAL_SENT} state.",
)
}
}

@Then("{actor} receives the issued credential")
fun bobHasTheCredentialIssued(holder: Actor) {
wait(
{
credentialEvent = ListenToEvents.with(holder).credentialEvents.lastOrNull {
it.data.thid == holder.recall<String>("thid")
}
credentialEvent != null &&
Wait.until(
errorMessage = "Holder was unable to receive the credential from Issuer! " +
"Protocol state did not achieve ${IssueCredentialRecord.ProtocolState.CREDENTIAL_RECEIVED} state."
) {
credentialEvent = ListenToEvents.with(holder).credentialEvents.lastOrNull {
it.data.thid == holder.recall<String>("thid")
}
credentialEvent != null &&
credentialEvent!!.data.protocolState == IssueCredentialRecord.ProtocolState.CREDENTIAL_RECEIVED
},
"Holder was unable to receive the credential from Issuer! " +
"Protocol state did not achieve ${IssueCredentialRecord.ProtocolState.CREDENTIAL_RECEIVED} state.",
)
}
holder.remember("issuedCredential", ListenToEvents.with(holder).credentialEvents.last().data)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package steps.credentials
import interactions.*
import io.cucumber.java.en.Then
import io.cucumber.java.en.When
import io.iohk.atala.automation.extensions.get
import io.iohk.atala.automation.serenity.ensure.Ensure
import io.iohk.atala.automation.utils.Wait
import models.JwtCredential
Expand All @@ -23,7 +24,7 @@ class RevokeCredentialSteps {
issuer.attemptsTo(
Get.resource("/credential-status/${statusListId}")
)
val encodedList = SerenityRest.lastResponse().jsonPath().get<String>("credentialSubject.encodedList")
val encodedList = SerenityRest.lastResponse().get<String>("credentialSubject.encodedList")
issuer.remember("encodedStatusList", encodedList)

issuer.attemptsTo(
Expand All @@ -49,16 +50,17 @@ class RevokeCredentialSteps {
@Then("{actor} should see the credential was revoked")
fun credentialShouldBeRevoked(issuer: Actor) {
Wait.until(
timeout = 30.seconds,
timeout = 60.seconds,
errorMessage = "Encoded Status List didn't change after revoking."
) {
val statusListId = issuer.recall<String>("statusListId")
val encodedList = issuer.recall<String>("statusEncodedList")
val statusListId: String = issuer.recall("statusListId")
val encodedStatusList: String = issuer.recall("encodedStatusList")
issuer.attemptsTo(
Get.resource("/credential-status/$statusListId")
)
val actualEncodedList = SerenityRest.lastResponse().jsonPath().get<String>("credentialSubject.encodedList")
actualEncodedList != encodedList
val actualEncodedList: String = SerenityRest.lastResponse().jsonPath().get("credentialSubject.encodedList")
println("actual encoded $actualEncodedList | before encoded $encodedStatusList")
actualEncodedList != encodedStatusList
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package steps.did

import common.TestConstants
import common.Utils.wait
import interactions.Get
import interactions.Post
import io.cucumber.java.en.Then
import io.cucumber.java.en.When
import io.iohk.atala.automation.extensions.get
import io.iohk.atala.automation.serenity.ensure.Ensure
import io.iohk.atala.automation.utils.Wait
import net.serenitybdd.rest.SerenityRest
import net.serenitybdd.screenplay.Actor
import org.apache.http.HttpStatus
Expand All @@ -29,19 +28,19 @@ class DeactivateDidSteps {
Ensure.that(didOperationResponse.scheduledOperation.didRef).isNotEmpty(),
Ensure.that(didOperationResponse.scheduledOperation.id).isNotEmpty(),
)
actor.forget<String>("hasPublishedDid")
val deactivatedDid = actor.forget<String>("shortFormDid")
actor.forget<String>("longFormDid")
actor.remember("deactivatedDid", deactivatedDid)

}

@Then("{actor} sees that PRISM DID is successfully deactivated")
fun actorSeesThatPrismDidIsSuccessfullyDeactivated(actor: Actor) {
wait(
{
actor.attemptsTo(
Get.resource("/dids/${actor.recall<String>("shortFormDid")}"),
)
SerenityRest.lastResponse().get<DIDResolutionResult>().didDocumentMetadata.deactivated!!
},
"ERROR: DID deactivate operation did not succeed on the ledger!",
timeout = TestConstants.DID_UPDATE_PUBLISH_MAX_WAIT_5_MIN,
)
val deactivatedDid = actor.recall<String>("deactivatedDid")
Wait.until(errorMessage = "ERROR: DID deactivate operation did not succeed on the ledger!") {
actor.attemptsTo(Get.resource("/dids/$deactivatedDid"))
SerenityRest.lastResponse().get<DIDResolutionResult>().didDocumentMetadata.deactivated!!
}
}
}

0 comments on commit 8684124

Please sign in to comment.