Skip to content

Commit

Permalink
test: test
Browse files Browse the repository at this point in the history
  • Loading branch information
Anton Baliasnikov committed Dec 16, 2022
1 parent 369aaaa commit e038880
Show file tree
Hide file tree
Showing 12 changed files with 246 additions and 36 deletions.
2 changes: 1 addition & 1 deletion infrastructure/local/.env
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
MERCURY_MEDIATOR_VERSION=0.2.0
IRIS_SERVICE_VERSION=0.1.0
PRISM_AGENT_VERSION=0.17.0
PRISM_AGENT_VERSION=0.22.0
PORT=80
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package api_models

data class PresentationProof(
var presentationId: String? = null,
var status: String? = null,
var proofs: List<String>? = null
)
3 changes: 3 additions & 0 deletions tests/e2e-tests/src/test/kotlin/common/Agents.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ object Agents {
private set
lateinit var Mallory: Actor
private set
lateinit var Faber: Actor
private set

init {
if (Environments.AGENT_AUTH_REQUIRED) {
Expand All @@ -28,5 +30,6 @@ object Agents {
Acme = Actor.named("Acme").whoCan(CallAnApi.at(Environments.ACME_AGENT_URL))
Bob = Actor.named("Bob").whoCan(CallAnApi.at(Environments.BOB_AGENT_URL))
Mallory = Actor.named("Mallory").whoCan(CallAnApi.at(Environments.MALLORY_AGENT_URL))
Faber = Actor.named("Faber").whoCan(CallAnApi.at(Environments.FABER_AGENT_URL))
}
}
1 change: 1 addition & 0 deletions tests/e2e-tests/src/test/kotlin/common/Environments.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ object Environments {
val ACME_AGENT_URL = System.getenv("ACME_AGENT_URL") ?: "http://localhost:8080/prism-agent"
val BOB_AGENT_URL = System.getenv("BOB_AGENT_URL") ?: "http://localhost:8090/prism-agent"
val MALLORY_AGENT_URL = System.getenv("MALLORY_AGENT_URL") ?: "http://localhost:8100/prism-agent"
val FABER_AGENT_URL = System.getenv("FABER_AGENT_URL") ?: "http://localhost:8100/prism-agent"
}
83 changes: 82 additions & 1 deletion tests/e2e-tests/src/test/kotlin/features/CommonSteps.kt
Original file line number Diff line number Diff line change
@@ -1,22 +1,32 @@
package features

import api_models.Connection
import api_models.Credential
import common.Agents.Acme
import common.Agents.Bob
import common.Agents.Faber
import common.Agents.Mallory
import common.Agents.createAgents
import common.Utils.lastResponseList
import features.connection.ConnectionSteps
import features.issue_credentials.IssueCredentialsSteps
import io.cucumber.java.Before
import io.cucumber.java.ParameterType
import io.cucumber.java.en.Given
import net.serenitybdd.screenplay.Actor
import net.serenitybdd.screenplay.actors.Cast
import net.serenitybdd.screenplay.actors.OnStage
import net.serenitybdd.screenplay.rest.interactions.Get
import net.serenitybdd.screenplay.rest.questions.ResponseConsequence
import org.apache.http.HttpStatus.SC_OK

class CommonSteps {
@Before
fun setStage() {
createAgents()
val cast = object: Cast() {
override fun getActors(): MutableList<Actor> {
return mutableListOf(Acme, Bob, Mallory)
return mutableListOf(Acme, Bob, Mallory, Faber)
}
}
OnStage.setTheStage(cast)
Expand All @@ -26,4 +36,75 @@ class CommonSteps {
fun actor(actorName: String): Actor {
return OnStage.theActorCalled(actorName);
}

@Given("{actor} has an issued credential from {actor}")
fun holderHasIssuedCredentialFromIssuer(holder: Actor, issuer: Actor) {
holder.attemptsTo(
Get.resource("/issue-credentials/records")
)
holder.should(
ResponseConsequence.seeThatResponse("Credential records") {
it.statusCode(SC_OK)
}
)
val receivedCredential = lastResponseList("items", Credential::class).findLast { credential ->
credential.protocolState == "CredentialReceived"
}

if (receivedCredential != null) {
holder.remember("issuedCredential", receivedCredential)
} else {
val issueSteps = IssueCredentialsSteps()
actorsHaveExistingConnection(issuer, holder)
issueSteps.acmeOffersACredential(issuer, holder)
issueSteps.bobRequestsTheCredential(holder)
issueSteps.acmeIssuesTheCredential(issuer)
issueSteps.bobHasTheCredentialIssued(holder)
}
}

@Given("{actor} and {actor} have an existing connection")
fun actorsHaveExistingConnection(inviter: Actor, invitee: Actor) {
inviter.attemptsTo(
Get.resource("/connections")
)
inviter.should(
ResponseConsequence.seeThatResponse("Get connections") {
it.statusCode(200)
}
)
val inviterConnection = lastResponseList("contents", Connection::class).firstOrNull {
it.label == "Connection with ${invitee.name}" &&
(it.state == "ConnectionResponseSent" || it.state == "ConnectionResponseReceived")
}

var inviteeConnection: Connection? = null
if (inviterConnection != null) {
invitee.attemptsTo(
Get.resource("/connections")
)
invitee.should(
ResponseConsequence.seeThatResponse("Get connections") {
it.statusCode(SC_OK)
}
)
inviteeConnection = lastResponseList("contents", Connection::class).firstOrNull {
it.theirDid == inviterConnection.myDid
}
}

if (inviterConnection != null && inviteeConnection != null) {
inviter.remember("connection-with-${invitee.name}", inviterConnection)
invitee.remember("connection-with-${inviter.name}", inviteeConnection)
} else {
val connectionSteps = ConnectionSteps()
connectionSteps.inviterGeneratesAConnectionInvitation(inviter, invitee)
connectionSteps.inviteeReceivesTheConnectionInvitation(invitee, inviter)
connectionSteps.inviteeSendsAConnectionRequestToInviter(invitee, inviter)
connectionSteps.inviterReceivesTheConnectionRequest(inviter)
connectionSteps.inviterSendsAConnectionResponseToInvitee(inviter, invitee)
connectionSteps.inviteeReceivesTheConnectionResponse(invitee)
connectionSteps.inviterAndInviteeHaveAConnection(inviter, invitee)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ import org.hamcrest.CoreMatchers.*

class ConnectionSteps {

@When("{actor} generates a connection invitation")
fun inviterGeneratesAConnectionInvitation(inviter: Actor) {
@When("{actor} generates a connection invitation to {actor}")
fun inviterGeneratesAConnectionInvitation(inviter: Actor, invitee: Actor) {
// Acme(Issuer) initiates a connection
// and sends it to Bob(Holder) out-of-band, e.g. using QR-code
val connectionLabel = "New Connection"
val connectionLabel = "Connection with ${invitee.name}"
inviter.attemptsTo(
Post.to("/connections")
.with {
Expand Down Expand Up @@ -161,7 +161,7 @@ class ConnectionSteps {
it.statusCode(200)
}
)
inviter.remember("connection", lastResponseObject("", Connection::class))
inviter.remember("connection-with-${invitee.name}", lastResponseObject("", Connection::class))

invitee.attemptsTo(
Get.resource("/connections/${invitee.recall<String>("connectionId")}")
Expand All @@ -171,15 +171,15 @@ class ConnectionSteps {
it.statusCode(200)
}
)
invitee.remember("connection", lastResponseObject("", Connection::class))
invitee.remember("connection-with-${inviter.name}", lastResponseObject("", Connection::class))

assertThat(inviter.recall<Connection>("connection").myDid)
.isEqualTo(invitee.recall<Connection>("connection").theirDid)
assertThat(inviter.recall<Connection>("connection").theirDid)
.isEqualTo(invitee.recall<Connection>("connection").myDid)
assertThat(inviter.recall<Connection>("connection").state)
assertThat(inviter.recall<Connection>("connection-with-${invitee.name}").myDid)
.isEqualTo(invitee.recall<Connection>("connection-with-${inviter.name}").theirDid)
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("ConnectionResponseSent")
assertThat(invitee.recall<Connection>("connection").state)
assertThat(invitee.recall<Connection>("connection-with-${inviter.name}").state)
.isEqualTo("ConnectionResponseReceived")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,14 @@ import api_models.Credential
import common.Utils.lastResponseList
import common.Utils.lastResponseObject
import common.Utils.wait
import features.connection.ConnectionSteps
import net.serenitybdd.screenplay.Actor

class IssueCredentialsSteps {

@Given("{actor} and {actor} have an existing connection")
fun acmeAndBobHaveAnExistingConnection(issuer: Actor, holder: Actor) {
val connectionSteps = ConnectionSteps()
connectionSteps.inviterGeneratesAConnectionInvitation(issuer)
connectionSteps.inviteeReceivesTheConnectionInvitation(holder, issuer)
connectionSteps.inviteeSendsAConnectionRequestToInviter(holder, issuer)
connectionSteps.inviterReceivesTheConnectionRequest(issuer)
connectionSteps.inviterSendsAConnectionResponseToInvitee(issuer, holder)
connectionSteps.inviteeReceivesTheConnectionResponse(holder)
connectionSteps.inviterAndInviteeHaveAConnection(issuer, holder)
}

@Given("{actor} offers a credential")
fun acmeOffersACredential(issuer: Actor) {
@Given("{actor} offers a credential to {actor}")
fun acmeOffersACredential(issuer: Actor, holder: Actor) {
val newCredential = Credential(
schemaId = "schema:1234",
subjectId = issuer.recall<Connection>("connection").theirDid,
subjectId = issuer.recall<Connection>("connection-with-${holder.name}").theirDid,
validityPeriod = 3600,
automaticIssuance = false,
awaitConfirmation = false,
Expand Down Expand Up @@ -148,7 +134,6 @@ class IssueCredentialsSteps {
},
"Holder was unable to receive the credential from Issuer! Protocol state did not achieve CredentialReceived state."
)
val achievedCredential = lastResponseObject("", Credential::class)
println(achievedCredential)
holder.remember("issuedCredential", lastResponseObject("", Credential::class))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package features.present_proof

import api_models.Connection
import api_models.Credential
import api_models.PresentationProof
import common.Utils.lastResponseList
import common.Utils.lastResponseObject
import common.Utils.wait
import io.cucumber.java.en.Then
import io.cucumber.java.en.When
import net.serenitybdd.screenplay.Actor
import net.serenitybdd.screenplay.rest.interactions.Get
import net.serenitybdd.screenplay.rest.interactions.Patch
import net.serenitybdd.screenplay.rest.interactions.Post
import net.serenitybdd.screenplay.rest.questions.ResponseConsequence
import org.apache.http.HttpStatus.SC_CREATED
import org.apache.http.HttpStatus.SC_OK

class PresentProofSteps {
@When("{actor} sends a request for proof presentation to {actor}")
fun faberSendsARequestForProofPresentationToBob(faber: Actor, bob: Actor) {
faber.attemptsTo(
Post.to("/present-proof/presentations")
.with {
it.body("""
{ "connectionId": "${faber.recall<Connection>("connection-with-${bob.name}").connectionId}", "proofs":[] }
""".trimIndent()
)
}
)
faber.should(
ResponseConsequence.seeThatResponse("Presentation proof request created") {
it.statusCode(SC_CREATED)
}
)
faber.remember("presentationId", lastResponseObject("", PresentationProof::class).presentationId)
}

@When("{actor} makes the presentation of the proof to {actor}")
fun bobMakesThePresentationOfTheProof(bob: Actor, faber: Actor) {
wait(
{
bob.attemptsTo(
Get.resource("/present-proof/presentations")
)
bob.should(
ResponseConsequence.seeThatResponse("Get presentations") {
it.statusCode(SC_OK)
}
)
lastResponseList("", PresentationProof::class).findLast {
it.status == "RequestReceived"
} != null
},
"ERROR: Bob did not achieve any presentation request!"
)

val presentationId = lastResponseList("", PresentationProof::class).findLast {
it.status == "RequestReceived"
}!!.presentationId
bob.attemptsTo(
Patch.to("/present-proof/presentations/$presentationId").with {
it.body("""
{ "action": "request-accept", "proofId": ["${bob.recall<Credential>("issuedCredential").recordId}"] }
""".trimIndent()
)
}
)
}

@When("{actor} acknowledges the proof")
fun faberAcknowledgesTheProof(faber: Actor) {
wait(
{
faber.attemptsTo(
Get.resource("/present-proof/presentations")
)
faber.should(
ResponseConsequence.seeThatResponse("Get presentations") {
it.statusCode(SC_OK)
}
)
val presentation = lastResponseList("", PresentationProof::class).find {
it.presentationId == faber.recall<String>("presentationId")
}
presentation!= null && presentation.status == "PresentationReceived"
},
"ERROR: Faber did not receive presentation from Bob!"
)

}

@Then("{actor} has the proof verified")
fun faberHasTheProofVerified(faber: Actor) {
wait(
{
faber.attemptsTo(
Get.resource("/present-proof/presentations")
)
faber.should(
ResponseConsequence.seeThatResponse("Get presentations") {
it.statusCode(SC_OK)
}
)
val presentation = lastResponseList("", PresentationProof::class).find {
it.presentationId == faber.recall<String>("presentationId")
}
presentation!= null && presentation.status == "PresentationVerified"
},
"ERROR: presentation did not achieve PresentationVerified state!"
)
}
}
4 changes: 2 additions & 2 deletions tests/e2e-tests/src/test/kotlin/runners/E2eTestsRunner.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import org.junit.runner.RunWith

@CucumberOptions(
features = [
"src/test/resources/features"
"src/test/resources/features/present_proof"
],
glue = ["features", "extentions"],
snippets = CucumberOptions.SnippetType.CAMELCASE,
plugin = [
"pretty",
"json:target/serenity-reports/cucumber_report.json"
],
]
)
@RunWith(CucumberWithSerenity::class)
class E2eTestsRunner
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Feature: RFC 0160 Agent connection functions

Scenario: Establish a connection between two agents
When Acme generates a connection invitation
When Acme generates a connection invitation to Bob
And Bob receives the connection invitation from Acme
And Bob sends a connection request to Acme
And Acme receives the connection request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Feature: RFC0453 Issue Credentials Protocol

Scenario: Issue a credential with the Issuer beginning with an offer
Given Acme and Bob have an existing connection
When Acme offers a credential
When Acme offers a credential to Bob
And Bob requests the credential
And Acme issues the credential
# And Bob acknowledges the credential issue
Expand Down

0 comments on commit e038880

Please sign in to comment.