Skip to content

Commit

Permalink
test: add e2e test stub for different API variations
Browse files Browse the repository at this point in the history
Signed-off-by: Yurii Shynbuiev <[email protected]>
  • Loading branch information
yshyn-iohk committed Dec 12, 2024
1 parent 37b5db2 commit 27e3a27
Show file tree
Hide file tree
Showing 10 changed files with 207 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,11 @@ data class CreateIssueCredentialRecordRequest(
@SerializedName("goal")
val goal: kotlin.String? = null

// @SerializedName("jwtVcPropertiesV1")
// val jwtVcPropertiesV1: kotlin.collections.List<kotlin.String>? = null
// @SerializedName("jwtVcPropertiesV1")
// val anoncredsVcPropertiesV1: Option[AnonCredsVCPropertiesV1] = None
// @SerializedName("sdJwtVcPropertiesV1")
// val sdJwtVcPropertiesV1: Option[SDJWTVCPropertiesV1] = None
)

2 changes: 1 addition & 1 deletion tests/integration-tests/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ dependencies {
testImplementation("io.ktor:ktor-server-netty:2.3.0")
testImplementation("io.ktor:ktor-client-apache:2.3.0")
// RestAPI client
testImplementation("org.hyperledger.identus:cloud-agent-client-kotlin:1.40.1-c6a3e0c")
testImplementation("org.hyperledger.identus:cloud-agent-client-kotlin:1.40.1-248ba5f")
// Test helpers library
testImplementation("io.iohk.atala:atala-automation:0.4.0")
// Hoplite for configuration
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package common

import org.hyperledger.identus.client.models.CreateIssueCredentialRecordRequest
import java.util.UUID

enum class CreateCredentialOfferAPIVersion {
V0 {
override fun buildCredentialOfferRequest(
credentialType: CredentialType,
did: String,
assertionKey: String,
schemaUrl: String?,
claims: Map<String, Any>,
connectionId: UUID,
validityPeriod: Double?,
): CreateIssueCredentialRecordRequest {
return CreateIssueCredentialRecordRequest(
schemaId = schemaUrl?.let { listOf(it) },
claims = claims,
issuingDID = did,
issuingKid = assertionKey,
connectionId = connectionId,
validityPeriod = validityPeriod ?: 3600.0,
credentialFormat = credentialType.format,
automaticIssuance = false,
)
}
},

// TODO: it's a copy/paste from the V0, I have to regenerate the Kotlin HTTP client
V1 {
override fun buildCredentialOfferRequest(
credentialType: CredentialType,
did: String,
assertionKey: String,
schemaUrl: String?,
claims: Map<String, Any>,
connectionId: UUID,
validityPeriod: Double?,
): CreateIssueCredentialRecordRequest {
return CreateIssueCredentialRecordRequest(
schemaId = schemaUrl?.let { listOf(it) },
claims = claims,
issuingDID = did,
issuingKid = assertionKey,
connectionId = connectionId,
validityPeriod = validityPeriod ?: 3600.0,
credentialFormat = credentialType.format,
automaticIssuance = false,
)
}
},
;

abstract fun buildCredentialOfferRequest(
credentialType: CredentialType,
did: String,
assertionKey: String,
schemaUrl: String?,
claims: Map<String, Any>,
connectionId: UUID,
validityPeriod: Double? = null,
): CreateIssueCredentialRecordRequest
}
19 changes: 19 additions & 0 deletions tests/integration-tests/src/test/kotlin/common/CredentialClaims.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package common

enum class CredentialClaims {
STUDENT_CLAIMS {
override val claims: Map<String, Any> = linkedMapOf(
"name" to "Name",
"age" to 18,
)
},
ID_CLAIMS {
override val claims: Map<String, Any> = linkedMapOf(
"firstName" to "First Name",
"lastName" to "Last Name",
)
},
;

abstract val claims: Map<String, Any>
}
19 changes: 19 additions & 0 deletions tests/integration-tests/src/test/kotlin/common/CredentialType.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package common

enum class CredentialType {
JWT_VCDM_1_1 {
override val format: String = "JWT"
},
JWT_VCDM_2_0 {
override val format: String = "JWT"
},
ANONCREDS_V1 {
override val format: String = "AnonCreds"
},
SD_JWT_VCDM_1_1 {
override val format: String = "SD_JWT"
},
;

abstract val format: String
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package steps.credentials

import abilities.ListenToEvents
import common.*
import interactions.Post
import interactions.body
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.serenity.interactions.PollingWait
import net.serenitybdd.rest.SerenityRest
import net.serenitybdd.screenplay.Actor
import org.apache.http.HttpStatus.*
import org.hamcrest.CoreMatchers.equalTo
Expand Down Expand Up @@ -42,6 +46,69 @@ class CredentialSteps {
)
}

@When("{actor} prepares the credential in '{}' format using the '{}' API")
fun issuerPreparesTheCredentialInFormat(issuer: Actor, credentialType: CredentialType, apiVersion: CreateCredentialOfferAPIVersion) {
issuer.remember("currentCredentialType", credentialType)
issuer.remember("currentAPI", apiVersion)
}

@When("{actor} prepares the '{}' to issue the credential")
fun issuerPreparesTheSchemaToIssueTheCredential(issuer: Actor, schema: CredentialSchema) {
issuer.remember("currentSchema", schema)
}

@When("{actor} prepares to use a '{}' form of DID with key id '{}'")
fun issuerPreparesTheDIDWithTheKeyId(issuer: Actor, didForm: String, assertionKey: String) {
val did: String = if (didForm == "short") {
issuer.recall("shortFormDid")
} else {
issuer.recall("longFormDid")
}
issuer.remember("currentDID", did)
issuer.remember("currentAssertionKey", assertionKey)
}

@When("{actor} prepares the claims '{}' for the credential")
fun issuerPreparesTheClaims(issuer: Actor, credentialClaims: CredentialClaims) {
issuer.remember("currentClaims", credentialClaims.claims)
}

@When("{actor} sends the prepared credential offer to {actor}")
fun issuerSendsTheCredentialOfferToHolder(issuer: Actor, holder: Actor) {
val api = issuer.recall<CreateCredentialOfferAPIVersion>("currentAPI")
val credentialType = issuer.recall<CredentialType>("currentCredentialType")
val did = issuer.recall<String>("currentDID")
val assertionKey = issuer.recall<String>("currentAssertionKey")
val schema = issuer.recall<CredentialSchema>("currentSchema")
val schemaGuid = issuer.recall<String>(schema.name)
val claims = issuer.recall<Map<String, Any>>("currentClaims")

val connectionId = issuer.recall<Connection>("connection-with-${holder.name}").connectionId

val schemaUrl: String? = schemaGuid?.let {
"${issuer.recall<String>("baseUrl")}/schema-registry/schemas/$it"
}

val credentialOfferRequest = api.buildCredentialOfferRequest(credentialType, did, assertionKey, schemaUrl!!, claims, connectionId)

issuer.attemptsTo(
Post.to("/issue-credentials/credential-offers").body(credentialOfferRequest),
)

saveCredentialOffer(issuer, holder)
}

private fun saveCredentialOffer(issuer: Actor, holder: Actor) {
val credentialRecord = SerenityRest.lastResponse().get<IssueCredentialRecord>()

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

issuer.remember("thid", credentialRecord.thid)
holder.remember("thid", credentialRecord.thid)
}

@When("{actor} issues the credential")
fun issuerIssuesTheCredential(issuer: Actor) {
issuerTriesToIssueTheCredential(issuer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import java.util.UUID

class CredentialSchemasSteps {

@Given("{actor} has published '{}' schema")
@Given("{actor} has a published '{}' schema")
fun agentHasAPublishedSchema(agent: Actor, schema: CredentialSchema) {
if (agent.recallAll().containsKey(schema.name)) {
return
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
@jwt @issuance @compatibility
Feature: Issue JWT credential REST API compatibility

Background:
Given Issuer and Holder have an existing connection
And Issuer has a published DID for 'JWT'
And Issuer has a published 'STUDENT_SCHEMA' schema
And Holder has an unpublished DID for 'JWT'

Scenario Outline: Issuing jwt credential using different API version
When Issuer prepares the credential in 'JWT_VCDM_1_1' format using the '<createCredentialOfferApiVersion>' API
And Issuer prepares to use a 'short' form of DID with key id 'assertion-1'
And Issuer prepares the 'STUDENT_SCHEMA' to issue the credential
And Issuer prepares the claims '<claims>' for the credential
And Issuer sends the prepared credential offer to Holder
And Holder receives the credential offer
And Holder accepts jwt credential offer using 'auth-1' key id
And Issuer issues the credential
Then Holder receives the issued credential
Examples:
| createCredentialOfferApiVersion | claims |
| V0 | STUDENT_CLAIMS |

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Feature: Issue JWT credential
Given Issuer and Holder have an existing connection
And Holder creates unpublished DID for 'JWT'
When Issuer prepares a custom PRISM DID
And Issuer has published 'STUDENT_SCHEMA' schema
And Issuer has a published 'STUDENT_SCHEMA' schema
And Issuer adds a '<assertionMethod>' key for 'assertionMethod' purpose with '<assertionName>' name to the custom PRISM DID
And Issuer creates the custom PRISM DID
And Issuer publishes DID to ledger
Expand All @@ -28,7 +28,7 @@ Feature: Issue JWT credential
Scenario: Issuing jwt credential with published PRISM DID and student schema
Given Issuer and Holder have an existing connection
And Issuer has a published DID for 'JWT'
And Issuer has published 'STUDENT_SCHEMA' schema
And Issuer has a published 'STUDENT_SCHEMA' schema
And Holder has an unpublished DID for 'JWT'
When Issuer offers a jwt credential to Holder with 'short' form using 'STUDENT_SCHEMA' schema
And Holder receives the credential offer
Expand All @@ -39,15 +39,15 @@ Feature: Issue JWT credential
Scenario: Issuing jwt credential with wrong claim structure for schema
Given Issuer and Holder have an existing connection
And Issuer has a published DID for 'JWT'
And Issuer has published 'STUDENT_SCHEMA' schema
And Issuer has a published 'STUDENT_SCHEMA' schema
And Holder has an unpublished DID for 'JWT'
When Issuer offers a jwt credential to Holder with 'short' form DID with wrong claims structure using 'STUDENT_SCHEMA' schema
Then Issuer should see that credential issuance has failed

Scenario: Issuing jwt credential with unpublished PRISM DID
Given Issuer and Holder have an existing connection
And Issuer has an unpublished DID for 'JWT'
And Issuer has published 'STUDENT_SCHEMA' schema
And Issuer has a published 'STUDENT_SCHEMA' schema
And Holder has an unpublished DID for 'JWT'
And Issuer offers a jwt credential to Holder with 'long' form DID
And Holder receives the credential offer
Expand All @@ -57,7 +57,7 @@ Feature: Issue JWT credential

Scenario: Connectionless issuance of JWT credential using OOB invitation
Given Issuer has a published DID for 'JWT'
And Issuer has published 'STUDENT_SCHEMA' schema
And Issuer has a published 'STUDENT_SCHEMA' schema
And Holder has an unpublished DID for 'JWT'
When Issuer creates a 'JWT' credential offer invitation with 'short' form DID and STUDENT_SCHEMA schema
And Holder accepts the credential offer invitation from Issuer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Feature: Issue SD-JWT credential
Scenario: Issuing sd-jwt credential with holder binding
Given Issuer and Holder have an existing connection
And Issuer has a published DID for 'SD_JWT'
And Issuer has published 'ID_SCHEMA' schema
And Issuer has a published 'ID_SCHEMA' schema
And Holder has an unpublished DID for 'SD_JWT'
When Issuer offers a sd-jwt credential to Holder
And Holder receives the credential offer
Expand All @@ -34,7 +34,7 @@ Feature: Issue SD-JWT credential

Scenario: Connectionless issuance of sd-jwt credential with holder binding
And Issuer has a published DID for 'SD_JWT'
And Issuer has published 'ID_SCHEMA' schema
And Issuer has a published 'ID_SCHEMA' schema
And Holder has an unpublished DID for 'SD_JWT'
When Issuer creates a 'SDJWT' credential offer invitation with 'short' form DID and ID_SCHEMA schema
And Holder accepts the credential offer invitation from Issuer
Expand Down

0 comments on commit 27e3a27

Please sign in to comment.