Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add new tests and refactoring #1442

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,29 @@ package abilities
import com.google.gson.GsonBuilder
import common.TestConstants
import io.iohk.atala.automation.restassured.CustomGsonObjectMapperFactory
import io.ktor.http.*
import io.ktor.server.application.*
import io.ktor.server.engine.*
import io.ktor.server.netty.*
import io.ktor.server.request.*
import io.ktor.server.response.*
import io.ktor.server.routing.*
import models.*
import io.ktor.http.HttpStatusCode
import io.ktor.server.application.Application
import io.ktor.server.application.call
import io.ktor.server.engine.ApplicationEngine
import io.ktor.server.engine.embeddedServer
import io.ktor.server.netty.Netty
import io.ktor.server.request.receiveText
import io.ktor.server.response.respond
import io.ktor.server.routing.get
import io.ktor.server.routing.post
import io.ktor.server.routing.routing
import models.ConnectionEvent
import models.CredentialEvent
import models.DidEvent
import models.Event
import models.PresentationEvent
import models.PresentationStatusAdapter
import net.serenitybdd.screenplay.Ability
import net.serenitybdd.screenplay.Actor
import net.serenitybdd.screenplay.HasTeardown
import net.serenitybdd.screenplay.Question
import org.hyperledger.identus.client.models.*
import org.hyperledger.identus.client.models.Connection
import org.hyperledger.identus.client.models.IssueCredentialRecord
import java.net.URL
import java.time.OffsetDateTime

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package common

import org.hyperledger.identus.client.models.ManagedDIDKeyTemplate
import org.hyperledger.identus.client.models.Service

data class DidDocumentTemplate (
val publicKeys: MutableList<ManagedDIDKeyTemplate>,
val services: MutableList<Service>
)
41 changes: 0 additions & 41 deletions tests/integration-tests/src/test/kotlin/common/DidPurpose.kt

This file was deleted.

50 changes: 50 additions & 0 deletions tests/integration-tests/src/test/kotlin/common/DidType.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package common

import org.hyperledger.identus.client.models.*

enum class DidType {
CUSTOM {
override val documentTemplate get() = DidDocumentTemplate(
publicKeys = mutableListOf(),
services = mutableListOf()
)
},
SD_JWT {
override val documentTemplate get() = DidDocumentTemplate(
publicKeys = mutableListOf(
ManagedDIDKeyTemplate("auth-1", Purpose.AUTHENTICATION, Curve.ED25519),
ManagedDIDKeyTemplate("assertion-1", Purpose.ASSERTION_METHOD, Curve.ED25519),
),
services = mutableListOf()
)
},
JWT {
override val documentTemplate get() = DidDocumentTemplate(
publicKeys = mutableListOf(
ManagedDIDKeyTemplate("auth-1", Purpose.AUTHENTICATION, Curve.SECP256K1),
ManagedDIDKeyTemplate("auth-2", Purpose.AUTHENTICATION, Curve.ED25519),
ManagedDIDKeyTemplate("assertion-1", Purpose.ASSERTION_METHOD, Curve.SECP256K1),
ManagedDIDKeyTemplate("assertion-2", Purpose.ASSERTION_METHOD, Curve.ED25519),
),
services = mutableListOf()
)
},
OIDC_JWT {
override val documentTemplate get() = DidDocumentTemplate(
publicKeys = mutableListOf(
ManagedDIDKeyTemplate("auth-1", Purpose.AUTHENTICATION, Curve.SECP256K1),
ManagedDIDKeyTemplate("auth-2", Purpose.AUTHENTICATION, Curve.ED25519),
ManagedDIDKeyTemplate("assertion-1", Purpose.ASSERTION_METHOD, Curve.SECP256K1),
),
services = mutableListOf()
)
},
ANONCRED {
override val documentTemplate get() = DidDocumentTemplate(
publicKeys = mutableListOf(),
services = mutableListOf()
)
}, ;

abstract val documentTemplate: DidDocumentTemplate
}
7 changes: 7 additions & 0 deletions tests/integration-tests/src/test/kotlin/steps/Setup.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.sksamuel.hoplite.ConfigLoader
import common.TestConstants
import config.*
import io.cucumber.java.AfterAll
import io.cucumber.java.Before
import io.cucumber.java.BeforeAll
import io.ktor.server.util.url
import io.restassured.RestAssured
Expand Down Expand Up @@ -197,6 +198,12 @@ object Setup {
}
}

@Before
fun clearScenario() {
// Setup.stopActors()
// Setup.initActors()
}

@BeforeAll
fun init() {
Security.insertProviderAt(BouncyCastleProviderSingleton.getInstance(), 2)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package steps.common

import common.CredentialSchema
import common.DidPurpose
import common.DidType
import interactions.Get
import io.cucumber.java.en.Given
import io.iohk.atala.automation.extensions.get
Expand All @@ -13,39 +13,39 @@ import org.hyperledger.identus.client.models.Connection
import org.hyperledger.identus.client.models.ConnectionsPage
import steps.connection.ConnectionSteps
import steps.credentials.*
import steps.did.PublishDidSteps
import steps.did.CreateDidSteps
import steps.schemas.CredentialSchemasSteps

class CommonSteps {
@Given("{actor} has a jwt issued credential from {actor}")
fun holderHasIssuedJwtCredentialFromIssuer(holder: Actor, issuer: Actor) {
actorsHaveExistingConnection(issuer, holder)

val publishDidSteps = PublishDidSteps()
publishDidSteps.agentHasAnUnpublishedDID(holder, DidPurpose.JWT)
publishDidSteps.agentHasAPublishedDID(issuer, DidPurpose.JWT)
val createDidSteps = CreateDidSteps()
createDidSteps.agentHasAnUnpublishedDID(holder, DidType.JWT)
createDidSteps.agentHasAPublishedDID(issuer, DidType.JWT)

val jwtCredentialSteps = JwtCredentialSteps()
val credentialSteps = CredentialSteps()

jwtCredentialSteps.issuerOffersAJwtCredential(issuer, holder, "short")
credentialSteps.holderReceivesCredentialOffer(holder)
jwtCredentialSteps.holderAcceptsJwtCredentialOfferForJwt(holder)
jwtCredentialSteps.holderAcceptsJwtCredentialOfferForJwt(holder, "auth-1")
credentialSteps.issuerIssuesTheCredential(issuer)
credentialSteps.holderReceivesTheIssuedCredential(holder)
}

@Given("{actor} has a jwt issued credential with {} schema from {actor}")
@Given("{actor} has a jwt issued credential with '{}' schema from {actor}")
fun holderHasIssuedJwtCredentialFromIssuerWithSchema(
holder: Actor,
schema: CredentialSchema,
issuer: Actor,
) {
actorsHaveExistingConnection(issuer, holder)

val publishDidSteps = PublishDidSteps()
publishDidSteps.agentHasAnUnpublishedDID(holder, DidPurpose.JWT)
publishDidSteps.agentHasAPublishedDID(issuer, DidPurpose.JWT)
val createDidSteps = CreateDidSteps()
createDidSteps.agentHasAnUnpublishedDID(holder, DidType.JWT)
createDidSteps.agentHasAPublishedDID(issuer, DidType.JWT)

val schemaSteps = CredentialSchemasSteps()
schemaSteps.agentHasAPublishedSchema(issuer, schema)
Expand All @@ -54,7 +54,7 @@ class CommonSteps {
val credentialSteps = CredentialSteps()
jwtCredentialSteps.issuerOffersJwtCredentialToHolderUsingSchema(issuer, holder, "short", schema)
credentialSteps.holderReceivesCredentialOffer(holder)
jwtCredentialSteps.holderAcceptsJwtCredentialOfferForJwt(holder)
jwtCredentialSteps.holderAcceptsJwtCredentialOfferForJwt(holder, "auth-1")
credentialSteps.issuerIssuesTheCredential(issuer)
credentialSteps.holderReceivesTheIssuedCredential(holder)
}
Expand All @@ -63,9 +63,9 @@ class CommonSteps {
fun holderHasIssuedSdJwtCredentialFromIssuer(holder: Actor, issuer: Actor) {
actorsHaveExistingConnection(issuer, holder)

val publishDidSteps = PublishDidSteps()
publishDidSteps.agentHasAnUnpublishedDID(holder, DidPurpose.SD_JWT)
publishDidSteps.agentHasAPublishedDID(issuer, DidPurpose.SD_JWT)
val createDidSteps = CreateDidSteps()
createDidSteps.agentHasAnUnpublishedDID(holder, DidType.SD_JWT)
createDidSteps.agentHasAPublishedDID(issuer, DidType.SD_JWT)

val sdJwtCredentialSteps = SdJwtCredentialSteps()
val credentialSteps = CredentialSteps()
Expand All @@ -80,9 +80,9 @@ class CommonSteps {
fun holderHasIssuedSdJwtCredentialFromIssuerWithKeyBind(holder: Actor, issuer: Actor) {
actorsHaveExistingConnection(issuer, holder)

val publishDidSteps = PublishDidSteps()
publishDidSteps.agentHasAnUnpublishedDID(holder, DidPurpose.SD_JWT)
publishDidSteps.agentHasAPublishedDID(issuer, DidPurpose.SD_JWT)
val createDidSteps = CreateDidSteps()
createDidSteps.agentHasAnUnpublishedDID(holder, DidType.SD_JWT)
createDidSteps.agentHasAPublishedDID(issuer, DidType.SD_JWT)

val sdJwtCredentialSteps = SdJwtCredentialSteps()
val credentialSteps = CredentialSteps()
Expand All @@ -97,8 +97,6 @@ class CommonSteps {
fun actorsHaveExistingConnection(inviter: Actor, invitee: Actor) {
inviter.attemptsTo(
Get.resource("/connections"),
)
inviter.attemptsTo(
Ensure.thatTheLastResponse().statusCode().isEqualTo(HttpStatus.SC_OK),
)
val inviterConnection = SerenityRest.lastResponse().get<ConnectionsPage>().contents!!.firstOrNull {
Expand All @@ -109,8 +107,6 @@ class CommonSteps {
if (inviterConnection != null) {
invitee.attemptsTo(
Get.resource("/connections"),
)
invitee.attemptsTo(
Ensure.thatTheLastResponse().statusCode().isEqualTo(HttpStatus.SC_OK),
)
inviteeConnection = SerenityRest.lastResponse().get<ConnectionsPage>().contents!!.firstOrNull {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,14 @@ import org.apache.http.HttpStatus.SC_CREATED
import org.apache.http.HttpStatus.SC_OK
import org.assertj.core.api.Assertions.assertThat
import org.hamcrest.CoreMatchers
import org.hyperledger.identus.client.models.*
import org.hyperledger.identus.client.models.AcceptConnectionInvitationRequest
import org.hyperledger.identus.client.models.Connection
import org.hyperledger.identus.client.models.Connection.State.CONNECTION_REQUEST_RECEIVED
import org.hyperledger.identus.client.models.Connection.State.CONNECTION_RESPONSE_RECEIVED
import org.hyperledger.identus.client.models.Connection.State.CONNECTION_RESPONSE_SENT
import org.hyperledger.identus.client.models.Connection.State.INVITATION_GENERATED
import org.hyperledger.identus.client.models.CreateConnectionRequest
import kotlin.time.Duration.Companion.seconds

class ConnectionSteps {

Expand All @@ -29,12 +34,11 @@ class ConnectionSteps {

inviter.attemptsTo(
Post.to("/connections").body(CreateConnectionRequest(label = connectionLabel)),
Ensure.thatTheLastResponse().statusCode().isEqualTo(SC_CREATED),
)

val connection = SerenityRest.lastResponse().get<Connection>()

inviter.attemptsTo(
Ensure.thatTheLastResponse().statusCode().isEqualTo(SC_CREATED),
Ensure.that(connection.label!!).isEqualTo(connectionLabel),
Ensure.that(connection.state).isEqualTo(Connection.State.INVITATION_GENERATED),
Ensure.that(connection.role).isEqualTo(Connection.Role.INVITER),
Expand All @@ -48,20 +52,14 @@ class ConnectionSteps {
fun inviteeSendsAConnectionRequestToInviter(invitee: Actor, inviter: Actor) {
// Bob accepts connection using achieved out-of-band invitation
val inviterConnection = inviter.recall<Connection>("connection")
val body = AcceptConnectionInvitationRequest(inviterConnection.invitation.invitationUrl.split("=")[1])
invitee.attemptsTo(
Post.to("/connection-invitations")
.with {
it.body(
AcceptConnectionInvitationRequest(
inviterConnection.invitation.invitationUrl.split("=")[1],
),
)
},
Post.to("/connection-invitations").body(body),
Ensure.thatTheLastResponse().statusCode().isEqualTo(SC_OK),
)
val inviteeConnection = SerenityRest.lastResponse().get<Connection>()

val inviteeConnection = SerenityRest.lastResponse().get<Connection>()
invitee.attemptsTo(
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import org.hyperledger.identus.client.models.*

class ConnectionLessSteps {

@When("{actor} creates a {string} credential offer invitation with {string} form DID")
@When("{actor} creates a '{}' credential offer invitation with '{}' form DID")
fun inviterGeneratesACredentialOfferInvitation(issuer: Actor, credentialFormat: String, didForm: String) {
val claims = linkedMapOf(
"firstName" to "Automation",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,12 @@ class CredentialSteps {

issuer.attemptsTo(
Ensure.thatTheLastResponse().statusCode().isEqualTo(SC_OK),
)

issuer.attemptsTo(
PollingWait.until(
ListenToEvents.credentialState(issuer),
equalTo(CREDENTIAL_SENT),
),
)
println("new issued credential: ${ListenToEvents.with(issuer).credentialEvents.last().data}")
issuer.remember("issuedCredential", ListenToEvents.with(issuer).credentialEvents.last().data)
}

Expand All @@ -67,6 +65,7 @@ class CredentialSteps {
equalTo(CREDENTIAL_RECEIVED),
),
)
println("new received credential: ${ListenToEvents.with(holder).credentialEvents.last().data}")
holder.remember("issuedCredential", ListenToEvents.with(holder).credentialEvents.last().data)
}

Expand Down
Loading
Loading