From 0b383f2e5586e6c28b5e7ae43508acca44ffe606 Mon Sep 17 00:00:00 2001 From: Allain Magyar Date: Tue, 5 Dec 2023 08:39:16 -0300 Subject: [PATCH 1/5] test: add zkp issuance scenario (#104) --- .github/workflows/e2e-tests.yml | 50 +++---- .releaserc.yml | 3 +- tests/end-to-end/README.md | 17 +++ tests/end-to-end/build.gradle.kts | 2 +- tests/end-to-end/serenity.properties | 1 - .../kotlin/io/iohk/atala/prism/TestSuite.kt | 8 -- .../atala/prism/configuration/Environment.kt | 130 +++++++++++++----- .../atala/prism/configuration/HooksSetup.kt | 7 + .../iohk/atala/prism/models/AnoncredSchema.kt | 17 +++ .../prism/models/{Schema.kt => JwtSchema.kt} | 4 +- ...SchemaProperty.kt => JwtSchemaProperty.kt} | 2 +- .../iohk/atala/prism/steps/CloudAgentSteps.kt | 18 ++- .../iohk/atala/prism/steps/EdgeAgentSteps.kt | 7 +- .../kotlin/io/iohk/atala/prism/utils/Keys.kt | 6 + .../prism/workflow/CloudAgentWorkflow.kt | 43 +++++- .../atala/prism/workflow/EdgeAgentWorkflow.kt | 9 ++ .../connection/CreateConnection.feature | 14 +- .../features/credential/Anoncred.feature | 11 ++ .../test/resources/local.properties.example | 6 + 19 files changed, 268 insertions(+), 87 deletions(-) create mode 100644 tests/end-to-end/README.md create mode 100644 tests/end-to-end/src/test/kotlin/io/iohk/atala/prism/models/AnoncredSchema.kt rename tests/end-to-end/src/test/kotlin/io/iohk/atala/prism/models/{Schema.kt => JwtSchema.kt} (78%) rename tests/end-to-end/src/test/kotlin/io/iohk/atala/prism/models/{SchemaProperty.kt => JwtSchemaProperty.kt} (82%) create mode 100644 tests/end-to-end/src/test/kotlin/io/iohk/atala/prism/utils/Keys.kt create mode 100644 tests/end-to-end/src/test/resources/features/credential/Anoncred.feature create mode 100644 tests/end-to-end/src/test/resources/local.properties.example diff --git a/.github/workflows/e2e-tests.yml b/.github/workflows/e2e-tests.yml index ff1eef05f..38f9308b6 100644 --- a/.github/workflows/e2e-tests.yml +++ b/.github/workflows/e2e-tests.yml @@ -12,54 +12,49 @@ on: mediatorOobUrl: required: true description: Mediator out-of-band url - default: https://sit-prism-mediator.atalaprism.io/invitationOOB + default: https://beta-mediator.atalaprism.io/invitationOOB prismAgentUrl: required: true description: Prism-agent server url - default: https://sit-prism-agent-issuer.atalaprism.io/prism-agent + default: https://sit-prism-agent-issuer.atalaprism.io/prism-agent/ + apiKey: + required: false + description: Authorization key publishedDid: required: false description: Published DID - default: did:prism:dac7505c41dd8e380b187544e8ae77e1ff8e39f62cd4d8d83310e23 - schemaId: + jwtSchemaGuid: required: false - description: Schema ID - default: 99647c77-5074-369f-85ed-067bfe062f77 - apiKey: + description: JWT schema GUID + anoncredDefinitionGuid: required: false - description: Authorization key - default: 1gnp5fzLTwNBvLBXLk9THLgxe9SLoh+7 + description: Anoncred definition GUID push: branches: - main + - prerelease + - release env: - JAVA_VERSION: 11 ATALA_GITHUB_ACTOR: ${{ secrets.ATALA_GITHUB_ACTOR }} ATALA_GITHUB_TOKEN: ${{ secrets.ATALA_GITHUB_TOKEN }} - GITHUB_ACTOR: ${{ secrets.ATALA_GITHUB_ACTOR }} - GITHUB_TOKEN: ${{ secrets.ATALA_GITHUB_TOKEN }} - MEDIATOR_OOB_URL: ${{ inputs.mediatorOobUrl || vars.MEDIATOR_OOB_URL }} - PRISM_AGENT_URL: ${{ inputs.prismAgentUrl || vars.PRISM_AGENT_URL }} - PUBLISHED_DID: ${{ inputs.publishedDid || vars.PUBLISHED_DID }} - SCHEMA_ID: ${{ inputs.schemaId || vars.SCHEMA_ID }} - APIKEY: ${{ inputs.apiKey || secrets.APIKEY }} - NODE_AUTH_TOKEN: ${{ secrets.ATALA_GITHUB_TOKEN }} jobs: run-e2e-tests: - name: "Run" + name: 'Run' runs-on: ubuntu-latest steps: - name: Mask apikey + env: + APIKEY: ${{ inputs.apiKey || secrets.APIKEY }} run: echo "::add-mask::${{env.APIKEY}}" - - name: Install Java ${{ env.JAVA_VERSION }} + - name: Install Java 11 uses: actions/setup-java@v3 with: - java-version: ${{ env.JAVA_VERSION }} - distribution: "adopt" + java-version: 11 + distribution: 'adopt' - name: Checkout Code uses: actions/checkout@v3 @@ -72,11 +67,18 @@ jobs: uses: gradle/gradle-build-action@v2 - name: Publish to maven local - if: github.event_name == 'pull_request' + if: github.event_name == 'push' || github.event_name == 'schedule' run: | ./gradlew publishToMavenLocal - name: Run tests + env: + MEDIATOR_OOB_URL: ${{ inputs.mediatorOobUrl || vars.MEDIATOR_OOB_URL }} + PRISM_AGENT_URL: ${{ inputs.prismAgentUrl || vars.PRISM_AGENT_URL }} + PUBLISHED_DID: ${{ inputs.publishedDid || vars.PUBLISHED_DID }} + JWT_SCHEMA_GUID: ${{ inputs.jwtSchemaGuid || vars.SCHEMA_ID }} + ANONCRED_DEFINITION_GUID: ${{ input.anoncredDefinitionGuid || vars.ANONCRED_DEFINITION_GUID }} + APIKEY: ${{ inputs.apiKey || secrets.APIKEY }} working-directory: tests/end-to-end run: | ./gradlew test --tests "TestSuite" @@ -91,4 +93,4 @@ jobs: with: name: atala-prism-sdk-kmm path: tests/end-to-end/target/site/serenity - if-no-files-found: error + if-no-files-found: 'error' diff --git a/.releaserc.yml b/.releaserc.yml index a3dfa9ea5..c8111774b 100644 --- a/.releaserc.yml +++ b/.releaserc.yml @@ -1,6 +1,7 @@ branches: - name: "main" - - name: "beta" + - name: "release" + - name: "prerelease" prerelease: "snapshot" plugins: diff --git a/tests/end-to-end/README.md b/tests/end-to-end/README.md new file mode 100644 index 000000000..0a08c974e --- /dev/null +++ b/tests/end-to-end/README.md @@ -0,0 +1,17 @@ +# End-to-end tests + +## Preparation + +Duplicate `local.properties.example` file from `test/resources` and rename the copy to `local.properties` + +Setup properties: + +| Property | Explanation | +|--------------------------|------------------------------------| +| MEDIATOR_OOB_URL | Mediator OOB url invitation | +| PRISM_AGENT_URL | Open enterprise agent url | +| PUBLISHED_DID | Existing published DID | +| JWT_SCHEMA_GUID | Existing JWT schema guid | +| ANONCRED_DEFINITION_GUID | Existing Anoncred definition guid | +| APIKEY | APIKEY header token authentication | + diff --git a/tests/end-to-end/build.gradle.kts b/tests/end-to-end/build.gradle.kts index 0f9f122e6..9cf8d4a99 100644 --- a/tests/end-to-end/build.gradle.kts +++ b/tests/end-to-end/build.gradle.kts @@ -30,7 +30,7 @@ repositories { dependencies { testImplementation("io.iohk.atala.prism.walletsdk:atala-prism-sdk:2.6.0") - testImplementation("io.iohk.atala.prism:prism-kotlin-client:1.9.2") + testImplementation("io.iohk.atala.prism:prism-kotlin-client:1.19.1") testImplementation("io.iohk.atala:atala-automation:0.3.0") } diff --git a/tests/end-to-end/serenity.properties b/tests/end-to-end/serenity.properties index 3b12a41ae..36cda7917 100644 --- a/tests/end-to-end/serenity.properties +++ b/tests/end-to-end/serenity.properties @@ -4,5 +4,4 @@ serenity.report.show.manual.tests=false serenity.simplified.stack.traces=false serenity.report.accessibility=true json.pretty.printing=true -serenity.console.headings=normal serenity.console.colors=true diff --git a/tests/end-to-end/src/test/kotlin/io/iohk/atala/prism/TestSuite.kt b/tests/end-to-end/src/test/kotlin/io/iohk/atala/prism/TestSuite.kt index 1cbd0db80..3d6f84a74 100644 --- a/tests/end-to-end/src/test/kotlin/io/iohk/atala/prism/TestSuite.kt +++ b/tests/end-to-end/src/test/kotlin/io/iohk/atala/prism/TestSuite.kt @@ -1,8 +1,6 @@ package io.iohk.atala.prism -import io.cucumber.java.BeforeAll import io.cucumber.junit.CucumberOptions -import io.iohk.atala.prism.configuration.Environment import net.serenitybdd.cucumber.CucumberWithSerenity import org.junit.runner.RunWith @@ -12,9 +10,3 @@ import org.junit.runner.RunWith plugin = ["pretty"] ) class TestSuite - -// https://cucumber.io/docs/cucumber/api/?lang=kotlin -@BeforeAll -fun setupEnvironment() { - Environment.setup() -} diff --git a/tests/end-to-end/src/test/kotlin/io/iohk/atala/prism/configuration/Environment.kt b/tests/end-to-end/src/test/kotlin/io/iohk/atala/prism/configuration/Environment.kt index dd155107c..784f94a99 100644 --- a/tests/end-to-end/src/test/kotlin/io/iohk/atala/prism/configuration/Environment.kt +++ b/tests/end-to-end/src/test/kotlin/io/iohk/atala/prism/configuration/Environment.kt @@ -1,5 +1,6 @@ package io.iohk.atala.prism.configuration +import io.cucumber.java.BeforeAll import io.iohk.atala.automation.utils.Logger import io.iohk.atala.automation.utils.Wait import io.iohk.atala.prism.models.* @@ -9,7 +10,7 @@ import io.restassured.builder.RequestSpecBuilder import io.restassured.response.Response import net.serenitybdd.rest.SerenityRest import org.apache.http.HttpStatus -import org.assertj.core.api.Assertions +import org.assertj.core.api.Assertions.assertThat import java.io.File import java.util.* import kotlin.time.Duration.Companion.seconds @@ -20,7 +21,8 @@ object Environment { lateinit var agentUrl: String lateinit var mediatorOobUrl: String lateinit var publishedDid: String - lateinit var schemaId: String + lateinit var jwtSchemaGuid: String + lateinit var anoncredDefinitionId: String /** * Set up the variables based on the properties config file @@ -43,6 +45,9 @@ object Environment { mediatorOobUrl = properties.getProperty("MEDIATOR_OOB_URL") agentUrl = properties.getProperty("PRISM_AGENT_URL") + // set base uri for rest assured + RestAssured.baseURI = agentUrl + // configure rest assured if (properties.containsKey("APIKEY")) { val requestSpecification = RequestSpecBuilder() @@ -53,12 +58,14 @@ object Environment { // check if DID and schema exist preparePublishedDid(properties.getProperty("PUBLISHED_DID")) - checkSchema(properties.getProperty("SCHEMA_ID")) + checkJwtSchema(properties.getProperty("JWT_SCHEMA_GUID")) + checkAnonCredSchema(properties.getProperty("ANONCRED_DEFINITION_GUID")) Notes.appendMessage("Mediator: $mediatorOobUrl") Notes.appendMessage("Agent: $agentUrl") Notes.appendMessage("DID: $publishedDid") - Notes.appendMessage("Schema: $schemaId") + Notes.appendMessage("JWT Schema: $jwtSchemaGuid") + Notes.appendMessage("Anoncred Definition: $anoncredDefinitionId") Notes.appendMessage("SDK Version: ${getSdkVersion()}") } @@ -74,12 +81,10 @@ object Environment { */ private fun preparePublishedDid(publishedDid: String?) { try { + assertThat(publishedDid).isNotEmpty() val response = RestAssured - .given() - .get("${agentUrl}/did-registrar/dids/$publishedDid") - .then() - .assertThat() - .statusCode(200) + .given().get("did-registrar/dids/$publishedDid") + .then().assertThat().statusCode(200) this.publishedDid = publishedDid!! return } catch (e: AssertionError) { @@ -88,7 +93,7 @@ object Environment { val publicKey = ManagedDIDKeyTemplate( id = "key-1", - purpose = Purpose.assertionMethod + purpose = Purpose.ASSERTION_METHOD ) val documentTemplate = CreateManagedDidRequestDocumentTemplate( @@ -101,17 +106,15 @@ object Environment { ) val creationResponse = RestAssured - .given().body(creationData) - .post("${agentUrl}/did-registrar/dids") + .given().body(creationData).post("/did-registrar/dids") .thenReturn() val longFormDid = creationResponse.body.jsonPath().getString("longFormDid") val publicationResponse = RestAssured - .given() - .post("${agentUrl}/did-registrar/dids/$longFormDid/publications") + .given().post("/did-registrar/dids/$longFormDid/publications") .thenReturn() - Assertions.assertThat(publicationResponse.statusCode).isEqualTo(HttpStatus.SC_ACCEPTED) + assertThat(publicationResponse.statusCode).isEqualTo(HttpStatus.SC_ACCEPTED) val shortFormDid = publicationResponse.body.jsonPath().getString("scheduledOperation.didRef") lateinit var response: Response @@ -125,32 +128,30 @@ object Environment { } /** - * Checks if the environment SCHEMA_ID variable exists in prism-agent, otherwise it creates a new one. + * Checks if the environment variable exists in prism-agent, otherwise it creates a new one. */ - private fun checkSchema(schemaId: String?) { + private fun checkJwtSchema(schemaGuid: String?) { try { + assertThat(schemaGuid).isNotEmpty() RestAssured - .given() - .get("${agentUrl}/schema-registry/schemas/$schemaId") - .then() - .assertThat() - .statusCode(200) - this.schemaId = schemaId!! + .given().get("schema-registry/schemas/$schemaGuid") + .then().assertThat().statusCode(200) + this.jwtSchemaGuid = schemaGuid!! return } catch (e: AssertionError) { - Notes.appendMessage("Schema [${schemaId}] not found. Creating a new one.") + Notes.appendMessage("JWT schema [${schemaGuid}] not found. Creating a new one.") } - val schemaName = "automation-schema-" + UUID.randomUUID() + val schemaName = "automation-jwt-schema-" + UUID.randomUUID() - val schema = Schema() - schema.id = "https://example.com/$schemaName" - schema.schema = "https://json-schema.org/draft/2020-12/schema" - schema.description = "Automation schema description" - schema.type = "object" + val jwtSchema = JwtSchema() + jwtSchema.id = "https://example.com/$schemaName" + jwtSchema.schema = "https://json-schema.org/draft/2020-12/schema" + jwtSchema.description = "Automation schema description" + jwtSchema.type = "object" - schema.properties["automation-required"] = SchemaProperty("string") - schema.properties["automation-optional"] = SchemaProperty("string") + jwtSchema.properties["automation-required"] = JwtSchemaProperty("string") + jwtSchema.properties["automation-optional"] = JwtSchemaProperty("string") val credentialSchemaInput = CredentialSchemaInput( author = this.publishedDid, @@ -159,15 +160,74 @@ object Environment { tags = listOf("automation"), type = "https://w3c-ccg.github.io/vc-json-schemas/schema/2.0/schema.json", version = "0.0.1", - schema = schema + schema = jwtSchema ) val schemaCreationResponse = RestAssured.given() .body(credentialSchemaInput) - .post("${agentUrl}/schema-registry/schemas") + .post("/schema-registry/schemas") .thenReturn() - this.schemaId = schemaCreationResponse.body.jsonPath().getString("guid") + this.jwtSchemaGuid = schemaCreationResponse.body.jsonPath().getString("guid") } + private fun checkAnonCredSchema(definitionId: String?) { + try { + assertThat(definitionId).isNotEmpty() + RestAssured + .given().get("credential-definition-registry/definitions/${definitionId}") + .then().assertThat().statusCode(200) + + this.anoncredDefinitionId = definitionId!! + return + } catch (e: AssertionError) { + Notes.appendMessage("Anoncred Definition not found for [${definitionId}]. Creating a new one.") + } + + val schemaName = "automation-anoncred-schema-" + UUID.randomUUID() + + val anoncredSchema = AnoncredSchema() + anoncredSchema.name = "Automation Anoncred" + anoncredSchema.version = "1.0" + anoncredSchema.issuerId = this.publishedDid + anoncredSchema.attrNames = mutableListOf("name", "age") + + val credentialSchemaInput = CredentialSchemaInput( + author = this.publishedDid, + description = "Some description to automation generated schema", + name = schemaName, + tags = listOf("automation"), + type = "AnoncredSchemaV1", + version = "2.0.0", + schema = anoncredSchema + ) + + val schemaCreationResponse = RestAssured.given() + .body(credentialSchemaInput) + .post("/schema-registry/schemas") + .thenReturn() + + assertThat(schemaCreationResponse.statusCode).isEqualTo(HttpStatus.SC_CREATED) + + val newSchemaGuid = schemaCreationResponse.body.jsonPath().getString("guid") + + val definitionName = "automation-anoncred-definition-" + UUID.randomUUID() + val definition = CredentialDefinitionInput( + name = definitionName, + version = "1.0.0", + tag = "automation-test", + author = publishedDid, + schemaId = "${agentUrl}/schema-registry/schemas/${newSchemaGuid}", + signatureType = "CL", + supportRevocation = true, + description = "Test Automation Auto-Generated" + ) + + val credentialDefinition = RestAssured + .given().body(definition).post("/credential-definition-registry/definitions") + .then().assertThat().statusCode(201) + .extract().`as`(CredentialDefinitionResponse::class.java) + + this.anoncredDefinitionId = credentialDefinition.guid.toString() + } } diff --git a/tests/end-to-end/src/test/kotlin/io/iohk/atala/prism/configuration/HooksSetup.kt b/tests/end-to-end/src/test/kotlin/io/iohk/atala/prism/configuration/HooksSetup.kt index 4a62c4c7b..462cb0e65 100644 --- a/tests/end-to-end/src/test/kotlin/io/iohk/atala/prism/configuration/HooksSetup.kt +++ b/tests/end-to-end/src/test/kotlin/io/iohk/atala/prism/configuration/HooksSetup.kt @@ -1,6 +1,7 @@ package io.iohk.atala.prism.configuration import io.cucumber.java.Before +import io.cucumber.java.BeforeAll import io.cucumber.java.ParameterType import io.iohk.atala.prism.abilities.UseWalletSdk import net.serenitybdd.screenplay.Actor @@ -8,6 +9,12 @@ import net.serenitybdd.screenplay.actors.Cast import net.serenitybdd.screenplay.actors.OnStage import net.serenitybdd.screenplay.rest.abilities.CallAnApi +// https://cucumber.io/docs/cucumber/api/?lang=kotlin +@BeforeAll +fun setupEnvironment() { + Environment.setup() +} + class HooksSetup { @Before fun setStage() { diff --git a/tests/end-to-end/src/test/kotlin/io/iohk/atala/prism/models/AnoncredSchema.kt b/tests/end-to-end/src/test/kotlin/io/iohk/atala/prism/models/AnoncredSchema.kt new file mode 100644 index 000000000..3a6fe259a --- /dev/null +++ b/tests/end-to-end/src/test/kotlin/io/iohk/atala/prism/models/AnoncredSchema.kt @@ -0,0 +1,17 @@ +package io.iohk.atala.prism.models + +import com.google.gson.annotations.SerializedName + +data class AnoncredSchema( + @SerializedName("name") + var name: String = "", + + @SerializedName("version") + var version: String = "", + + @SerializedName("attrNames") + var attrNames: MutableList = mutableListOf(), + + @SerializedName("issuerId") + var issuerId: String = "" +) diff --git a/tests/end-to-end/src/test/kotlin/io/iohk/atala/prism/models/Schema.kt b/tests/end-to-end/src/test/kotlin/io/iohk/atala/prism/models/JwtSchema.kt similarity index 78% rename from tests/end-to-end/src/test/kotlin/io/iohk/atala/prism/models/Schema.kt rename to tests/end-to-end/src/test/kotlin/io/iohk/atala/prism/models/JwtSchema.kt index 2e3a2efab..da400ed20 100644 --- a/tests/end-to-end/src/test/kotlin/io/iohk/atala/prism/models/Schema.kt +++ b/tests/end-to-end/src/test/kotlin/io/iohk/atala/prism/models/JwtSchema.kt @@ -2,7 +2,7 @@ package io.iohk.atala.prism.models import com.google.gson.annotations.SerializedName -data class Schema ( +data class JwtSchema ( @SerializedName("\$id") var id: String = "", @@ -16,5 +16,5 @@ data class Schema ( var type: String = "", @SerializedName("properties") - val properties: MutableMap = mutableMapOf() + val properties: MutableMap = mutableMapOf() ) diff --git a/tests/end-to-end/src/test/kotlin/io/iohk/atala/prism/models/SchemaProperty.kt b/tests/end-to-end/src/test/kotlin/io/iohk/atala/prism/models/JwtSchemaProperty.kt similarity index 82% rename from tests/end-to-end/src/test/kotlin/io/iohk/atala/prism/models/SchemaProperty.kt rename to tests/end-to-end/src/test/kotlin/io/iohk/atala/prism/models/JwtSchemaProperty.kt index 51da95ec7..818147316 100644 --- a/tests/end-to-end/src/test/kotlin/io/iohk/atala/prism/models/SchemaProperty.kt +++ b/tests/end-to-end/src/test/kotlin/io/iohk/atala/prism/models/JwtSchemaProperty.kt @@ -2,7 +2,7 @@ package io.iohk.atala.prism.models import com.google.gson.annotations.SerializedName -data class SchemaProperty ( +data class JwtSchemaProperty ( @SerializedName("type") var type: String = "" ) diff --git a/tests/end-to-end/src/test/kotlin/io/iohk/atala/prism/steps/CloudAgentSteps.kt b/tests/end-to-end/src/test/kotlin/io/iohk/atala/prism/steps/CloudAgentSteps.kt index db88bc71a..b5778a30d 100644 --- a/tests/end-to-end/src/test/kotlin/io/iohk/atala/prism/steps/CloudAgentSteps.kt +++ b/tests/end-to-end/src/test/kotlin/io/iohk/atala/prism/steps/CloudAgentSteps.kt @@ -16,14 +16,17 @@ class CloudAgentSteps { @Inject private lateinit var edgeAgentWorkflow: EdgeAgentWorkflow - @Given("{actor} has a connection invitation") - fun `Cloud Agent has a connection invitation`(cloudAgent: Actor) { - cloudAgentWorkflow.createConnection(cloudAgent) + @Given("{actor} has a connection invitation with '{}', '{}' and '{}' parameters") + fun `Cloud Agent has a connection invitation`(cloudAgent: Actor, label: String, goalCode: String, goal: String) { + val mappedLabel = if (label == "null") { null } else { label } + val mappedGoalCode = if (goalCode == "null") { null } else { goalCode } + val mappedGoal = if (goal == "null") { null } else { goal } + cloudAgentWorkflow.createConnection(cloudAgent, mappedLabel, mappedGoalCode, mappedGoal) } @Given("{actor} is connected to {actor}") fun `Cloud Agent is connected to Edge Agent`(cloudAgent: Actor, edgeAgent: Actor) { - cloudAgentWorkflow.createConnection(cloudAgent) + cloudAgentWorkflow.createConnection(cloudAgent, "alice", "automation", "description") cloudAgentWorkflow.shareInvitation(cloudAgent, edgeAgent) edgeAgentWorkflow.connect(edgeAgent) cloudAgentWorkflow.waitForConnectionState(cloudAgent, "ConnectionResponseSent") @@ -39,6 +42,11 @@ class CloudAgentSteps { cloudAgentWorkflow.offerCredential(cloudAgent) } + @When("{actor} offers an anonymous credential") + fun `Cloud Agent offers an anonymous credential`(cloudAgent: Actor) { + cloudAgentWorkflow.offerAnonymousCredential(cloudAgent) + } + @When("{actor} should see the credential was accepted") fun `Cloud Agent should see the credential was accepted`(cloudAgent: Actor) { val recordId = cloudAgent.recall("recordId") @@ -51,7 +59,7 @@ class CloudAgentSteps { } @Then("{actor} should have the connection status updated to '{}'") - fun `Cloud Agent should have the connection status updated to '{}'`(cloudAgent: Actor, expectedState: String) { + fun `Cloud Agent should have the connection status updated`(cloudAgent: Actor, expectedState: String) { cloudAgentWorkflow.waitForConnectionState(cloudAgent, expectedState) } diff --git a/tests/end-to-end/src/test/kotlin/io/iohk/atala/prism/steps/EdgeAgentSteps.kt b/tests/end-to-end/src/test/kotlin/io/iohk/atala/prism/steps/EdgeAgentSteps.kt index c3c6af4a7..733465683 100644 --- a/tests/end-to-end/src/test/kotlin/io/iohk/atala/prism/steps/EdgeAgentSteps.kt +++ b/tests/end-to-end/src/test/kotlin/io/iohk/atala/prism/steps/EdgeAgentSteps.kt @@ -92,6 +92,11 @@ class EdgeAgentSteps { edgeAgentWorkflow.waitForCredentialOffer(edgeAgent, 1) } + @Then("{actor} should receive the anonymous credential") + fun `Edge Agent should receive the anonymous credential`(edgeAgent: Actor) { + edgeAgentWorkflow.waitToReceiveAnonymousCredential(edgeAgent, 1) + } + @Then("{actor} wait to receive {} issued credentials") fun `Edge Agent wait to receive issued credentials`(edgeAgent: Actor, expectedNumberOfCredentials: Int) { edgeAgentWorkflow.waitToReceiveCredentialIssuance(edgeAgent, expectedNumberOfCredentials) @@ -108,4 +113,4 @@ class EdgeAgentSteps { UseWalletSdk.stop() ) } -} \ No newline at end of file +} diff --git a/tests/end-to-end/src/test/kotlin/io/iohk/atala/prism/utils/Keys.kt b/tests/end-to-end/src/test/kotlin/io/iohk/atala/prism/utils/Keys.kt new file mode 100644 index 000000000..b654ba5cd --- /dev/null +++ b/tests/end-to-end/src/test/kotlin/io/iohk/atala/prism/utils/Keys.kt @@ -0,0 +1,6 @@ +package io.iohk.atala.prism.utils + +object Keys { + val CONNECTION_ID = "connectionId" + +} diff --git a/tests/end-to-end/src/test/kotlin/io/iohk/atala/prism/workflow/CloudAgentWorkflow.kt b/tests/end-to-end/src/test/kotlin/io/iohk/atala/prism/workflow/CloudAgentWorkflow.kt index d1c6b3bec..aead98490 100644 --- a/tests/end-to-end/src/test/kotlin/io/iohk/atala/prism/workflow/CloudAgentWorkflow.kt +++ b/tests/end-to-end/src/test/kotlin/io/iohk/atala/prism/workflow/CloudAgentWorkflow.kt @@ -15,8 +15,25 @@ import org.apache.http.HttpStatus import java.util.* class CloudAgentWorkflow { - fun createConnection(cloudAgent: Actor) { - val createConnection = CreateConnectionRequest("Alice") + fun createConnection(cloudAgent: Actor, label: String?, goalCode: String?, goal: String?) { + val createConnection = CreateConnectionRequest( + label, + goalCode, + goal + ) + + cloudAgent.attemptsTo( + Post.to("/connections").body(createConnection), + Ensure.thatTheLastResponse().statusCode().isEqualTo(HttpStatus.SC_CREATED) + ) + + cloudAgent.remember("invitation", lastResponse().get("invitation.invitationUrl")) + cloudAgent.remember("connectionId", lastResponse().get("connectionId")) + } + + fun createConnectionWithoutOptionalArguments(cloudAgent: Actor) { + val createConnection = CreateConnectionRequest() + cloudAgent.attemptsTo( Post.to("/connections").body(createConnection), Ensure.thatTheLastResponse().statusCode().isEqualTo(HttpStatus.SC_CREATED) @@ -46,8 +63,24 @@ class CloudAgentWorkflow { val credential = CreateIssueCredentialRecordRequest( claims = mapOf(Pair("automation-required", UUID.randomUUID())), issuingDID = Environment.publishedDid, - connectionId = connectionId, - schemaId = "${Environment.agentUrl}/schema-registry/schemas/${Environment.schemaId}" + connectionId = UUID.fromString(connectionId), + schemaId = "${Environment.agentUrl}/schema-registry/schemas/${Environment.jwtSchemaGuid}" + ) + cloudAgent.attemptsTo( + Post.to("/issue-credentials/credential-offers").body(credential) + ) + cloudAgent.remember("recordId", lastResponse().get("recordId")) + } + + fun offerAnonymousCredential(cloudAgent: Actor) { + val connectionId = cloudAgent.recall("connectionId") + val credential = CreateIssueCredentialRecordRequest( + claims = mapOf(Pair("name", "automation"), Pair("age", "99")), + automaticIssuance = true, + issuingDID = Environment.publishedDid, + connectionId = UUID.fromString(connectionId), + credentialFormat = "AnonCreds", + credentialDefinitionId = UUID.fromString(Environment.anoncredDefinitionId) ) cloudAgent.attemptsTo( Post.to("/issue-credentials/credential-offers").body(credential) @@ -68,7 +101,7 @@ class CloudAgentWorkflow { trustIssuers = listOf("") // TODO: use publicated DID ) val presentProofRequest = RequestPresentationInput( - connectionId = connectionId, + connectionId = UUID.fromString(connectionId), options = options, proofs = listOf(proofs) ) diff --git a/tests/end-to-end/src/test/kotlin/io/iohk/atala/prism/workflow/EdgeAgentWorkflow.kt b/tests/end-to-end/src/test/kotlin/io/iohk/atala/prism/workflow/EdgeAgentWorkflow.kt index b87f4f3a1..61af40d80 100644 --- a/tests/end-to-end/src/test/kotlin/io/iohk/atala/prism/workflow/EdgeAgentWorkflow.kt +++ b/tests/end-to-end/src/test/kotlin/io/iohk/atala/prism/workflow/EdgeAgentWorkflow.kt @@ -74,6 +74,15 @@ class EdgeAgentWorkflow { ) } + fun waitToReceiveAnonymousCredential(edgeAgent: Actor, numberOfCredentialOffer: Int) { + edgeAgent.attemptsTo( + PollingWait.until( + UseWalletSdk.credentialOfferStackSize(), + equalTo(numberOfCredentialOffer) + ) + ) + } + fun waitToReceiveCredentialIssuance(edgeAgent: Actor, expectedNumberOfCredentials: Int) { edgeAgent.attemptsTo( PollingWait.until( diff --git a/tests/end-to-end/src/test/resources/features/connection/CreateConnection.feature b/tests/end-to-end/src/test/resources/features/connection/CreateConnection.feature index a78709348..de4382125 100644 --- a/tests/end-to-end/src/test/resources/features/connection/CreateConnection.feature +++ b/tests/end-to-end/src/test/resources/features/connection/CreateConnection.feature @@ -1,8 +1,16 @@ Feature: Create connection The Edge Agent should be able to create a connection to prism-agent - Scenario: Create connection - Given Cloud Agent has a connection invitation + Scenario Outline: Create connection + Given Cloud Agent has a connection invitation with '