Skip to content

Commit

Permalink
test: add zkp issuance scenario (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
amagyar-iohk authored Dec 5, 2023
1 parent b96501f commit 0b383f2
Show file tree
Hide file tree
Showing 19 changed files with 268 additions and 87 deletions.
50 changes: 26 additions & 24 deletions .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand All @@ -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'
3 changes: 2 additions & 1 deletion .releaserc.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
branches:
- name: "main"
- name: "beta"
- name: "release"
- name: "prerelease"
prerelease: "snapshot"

plugins:
Expand Down
17 changes: 17 additions & 0 deletions tests/end-to-end/README.md
Original file line number Diff line number Diff line change
@@ -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 |

2 changes: 1 addition & 1 deletion tests/end-to-end/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down
1 change: 0 additions & 1 deletion tests/end-to-end/serenity.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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()
}
Original file line number Diff line number Diff line change
@@ -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.*
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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()
Expand All @@ -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()}")
}

Expand All @@ -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) {
Expand All @@ -88,7 +93,7 @@ object Environment {

val publicKey = ManagedDIDKeyTemplate(
id = "key-1",
purpose = Purpose.assertionMethod
purpose = Purpose.ASSERTION_METHOD
)

val documentTemplate = CreateManagedDidRequestDocumentTemplate(
Expand All @@ -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
Expand All @@ -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,
Expand All @@ -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()
}
}
Loading

0 comments on commit 0b383f2

Please sign in to comment.