Skip to content

Commit

Permalink
tests: update DID tests with update and deactivation (#404)
Browse files Browse the repository at this point in the history
  • Loading branch information
abalias authored Mar 3, 2023
1 parent 8582dd6 commit 226a481
Show file tree
Hide file tree
Showing 18 changed files with 391 additions and 47 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ on:
pull_request:
paths:
- ".github/workflows/e2e-tests.yml"
- "infrastructure/shared/docker-compose.yml"
- "tests/e2e-tests/**"
push:
branches:
Expand Down Expand Up @@ -67,6 +68,7 @@ jobs:
- name: Start services for issuer
env:
PORT: 8080
NETWORK: prism
uses: isbang/[email protected]
with:
compose-file: "./infrastructure/shared/docker-compose.yml"
Expand All @@ -77,6 +79,7 @@ jobs:
- name: Start services for holder
env:
PORT: 8090
NETWORK: prism
uses: isbang/[email protected]
with:
compose-file: "./infrastructure/shared/docker-compose.yml"
Expand Down Expand Up @@ -160,4 +163,4 @@ jobs:
Skipped (known bugs): ${{ steps.analyze_test_results.outputs.skipped }}
SLACK_TITLE: "Atala PRISM V2 E2E tests: ${{ steps.analyze_test_results.outputs.conclusion }}"
SLACK_USERNAME: circleci
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
SLACK_WEBHOOK: ${{ secrets.E2E_TESTS_SLACK_WEBHOOK }}
2 changes: 1 addition & 1 deletion infrastructure/local/.env
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MERCURY_MEDIATOR_VERSION=0.2.0
IRIS_SERVICE_VERSION=0.1.0
PRISM_AGENT_VERSION=0.45.1
PRISM_AGENT_VERSION=0.48.3
PRISM_NODE_VERSION=v2.1.0
PORT=80
NETWORK=prism
8 changes: 5 additions & 3 deletions infrastructure/shared/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ volumes:
pg_data_db:
pgadmin:

networks:
default:
name: ${NETWORK}
# Temporary commit network setting due to e2e CI bug
# to be enabled later after debugging
#networks:
# default:
# name: ${NETWORK}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package api_models

data class CreateManagedDidRequest(
data class CreatePrismDidRequest(
val documentTemplate: DocumentTemplate,
)
5 changes: 5 additions & 0 deletions tests/e2e-tests/src/main/kotlin/api_models/ManagedDid.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@ data class ManagedDid(
var longFormDid: String = "",
var status: String = "",
)

object ManagedDidStatuses {
val PUBLISHED = "PUBLISHED"
val CREATED = "CREATED"
}
6 changes: 3 additions & 3 deletions tests/e2e-tests/src/main/kotlin/api_models/Service.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package api_models

data class Service(
val id: String,
val type: String,
val serviceEndpoint: List<String>,
var id: String = "",
var serviceEndpoint: List<String> = listOf(""),
var type: String = "",
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package api_models

data class UpdatePrismDidRequest(
val actions: List<UpdatePrismDidAction>,
)

data class UpdatePrismDidAction(
val actionType: String? = null,
val addKey: PublicKey? = null,
val removeKey: PublicKey? = null,
val addService: Service? = null,
val removeService: Service? = null,
val updateService: Service? = null,
)
29 changes: 29 additions & 0 deletions tests/e2e-tests/src/test/kotlin/common/TestConstants.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,37 @@
package common

import api_models.PublicKey
import api_models.Purpose
import api_models.Service
import java.time.Duration
import java.util.UUID

object TestConstants {
val CREDENTIAL_SCHEMAS = CredentialSchemas
val RANDOM_CONSTAND_UUID = UUID.randomUUID().toString()
val DID_UPDATE_PUBLISH_MAX_WAIT_5_MIN = Duration.ofSeconds(60L)
val PRISM_DID_AUTH_KEY = PublicKey("auth-1", Purpose.AUTHENTICATION)
val PRISM_DID_ASSERTION_KEY = PublicKey("assertion-1", Purpose.ASSERTION_METHOD)
val PRISM_DID_UPDATE_NEW_AUTH_KEY = PublicKey("auth-2", Purpose.AUTHENTICATION)
val PRISM_DID_SERVICE = Service(
"https://foo.bar.com",
listOf("https://foo.bar.com/"),
"LinkedDomains",
)
val PRISM_DID_SERVICE_FOR_UPDATE = Service(
"https://update.com",
listOf("https://update.com/"),
"LinkedDomains",
)
val PRISM_DID_SERVICE_TO_REMOVE = Service(
"https://remove.com",
listOf("https://remove.com/"),
"LinkedDomains",
)
val PRISM_DID_UPDATE_NEW_SERVICE_URL = "https://bar.foo.com/"
val PRISM_DID_UPDATE_NEW_SERVICE = Service(
"https://new.service.com",
listOf("https://new.service.com/"),
"LinkedDomains",
)
}
1 change: 1 addition & 0 deletions tests/e2e-tests/src/test/kotlin/features/CommonSteps.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import net.serenitybdd.screenplay.rest.questions.ResponseConsequence
import org.apache.http.HttpStatus.SC_OK

class CommonSteps {

@Before
fun setStage() {
createAgents()
Expand Down
44 changes: 44 additions & 0 deletions tests/e2e-tests/src/test/kotlin/features/did/DeactivateDidSteps.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package features.did

import common.TestConstants
import common.Utils
import common.Utils.lastResponseObject
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.Post
import net.serenitybdd.screenplay.rest.questions.ResponseConsequence
import org.apache.http.HttpStatus
import org.hamcrest.Matchers

class DeactivateDidSteps {

@When("{actor} deactivates PRISM DID")
fun actorIssuesDeactivateDidOperation(actor: Actor) {
actor.attemptsTo(
Post.to("/did-registrar/dids/${actor.recall<String>("shortFormDid")}/deactivations"),
)
actor.should(
ResponseConsequence.seeThatResponse {
it.statusCode(HttpStatus.SC_ACCEPTED)
it.body("scheduledOperation.didRef", Matchers.not(Matchers.emptyString()))
it.body("scheduledOperation.id", Matchers.not(Matchers.emptyString()))
},
)
}

@Then("{actor} sees that PRISM DID is successfully deactivated")
fun actorSeesThatPrismDidIsSuccessfullyDeactivated(actor: Actor) {
Utils.wait(
{
actor.attemptsTo(
Get.resource("/dids/${actor.recall<String>("shortFormDid")}"),
)
lastResponseObject("metadata.deactivated", String::class) == "true"
},
"ERROR: DID deactivate operation did not succeed on the ledger!",
timeout = TestConstants.DID_UPDATE_PUBLISH_MAX_WAIT_5_MIN,
)
}
}
31 changes: 18 additions & 13 deletions tests/e2e-tests/src/test/kotlin/features/did/ManageDidSteps.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package features.did

import api_models.*
import common.TestConstants
import common.Utils.lastResponseList
import common.Utils.lastResponseObject
import common.Utils.toJsonPath
Expand All @@ -18,17 +19,17 @@ import org.hamcrest.Matchers.*

class ManageDidSteps {

@Given("{actor} creates {int} managed DIDs")
@Given("{actor} creates {int} PRISM DIDs")
fun createsMultipleManagedDids(actor: Actor, number: Int) {
repeat(number) {
createManageDid(actor)
}
actor.remember("number", number)
}

@When("{actor} create a managed DID")
@When("{actor} creates PRISM DID")
fun createManageDid(actor: Actor) {
val createDidRequest = createManagedDidRequest()
val createDidRequest = createPrismDidRequest()

actor.attemptsTo(
Post.to("/did-registrar/dids")
Expand All @@ -44,9 +45,9 @@ class ManageDidSteps {
actor.remember("createdDids", createdDids)
}

@When("{actor} tries to create a managed DID with missing {word}")
@When("{actor} tries to create PRISM DID with missing {word}")
fun triesToCreateManagedDidWithMissingField(actor: Actor, missingFieldPath: String) {
val createDidRequest = createManagedDidRequest()
val createDidRequest = createPrismDidRequest()
val requestBody = toJsonPath(createDidRequest).delete(missingFieldPath).jsonString()
actor.attemptsTo(
Post.to("/did-registrar/dids")
Expand All @@ -58,7 +59,7 @@ class ManageDidSteps {

@When("{actor} tries to create a managed DID with value {word} in {word}")
fun trisToCreateManagedDidWithValueInField(actor: Actor, value: String, fieldPath: String) {
val createDidRequest = createManagedDidRequest()
val createDidRequest = createPrismDidRequest()
val requestBody = toJsonPath(createDidRequest).set(fieldPath, value).jsonString()
actor.attemptsTo(
Post.to("/did-registrar/dids")
Expand All @@ -68,14 +69,14 @@ class ManageDidSteps {
)
}

@When("{actor} lists all the managed DIDs")
@When("{actor} lists all PRISM DIDs")
fun iListManagedDids(actor: Actor) {
actor.attemptsTo(
Get.resource("/did-registrar/dids"),
)
}

@Then("{actor} sees the managed DID was created successfully")
@Then("{actor} sees PRISM DID was created successfully")
fun theDidShouldBeRegisteredSuccessfully(actor: Actor) {
actor.should(
ResponseConsequence.seeThatResponse {
Expand All @@ -97,15 +98,19 @@ class ManageDidSteps {
val managedDidList = lastResponseList("contents", ManagedDid::class)
Assertions.assertThat(managedDidList)
.filteredOn {
expectedDids.contains(it.longFormDid) && it.status == "CREATED"
expectedDids.contains(it.longFormDid) && it.status == ManagedDidStatuses.CREATED
}
.hasSize(expectedDidsCount)
}

private fun createManagedDidRequest(): CreateManagedDidRequest {
val publicKeys = listOf(PublicKey("123", Purpose.AUTHENTICATION))
val services = listOf(Service("did:prism:321", "LinkedDomains", listOf("https://foo.bar.com")))
private fun createPrismDidRequest(): CreatePrismDidRequest {
val publicKeys = listOf(
TestConstants.PRISM_DID_AUTH_KEY,
)
val services = listOf(
TestConstants.PRISM_DID_SERVICE,
)
val documentTemplate = DocumentTemplate(publicKeys, services)
return CreateManagedDidRequest(documentTemplate)
return CreatePrismDidRequest(documentTemplate)
}
}
52 changes: 39 additions & 13 deletions tests/e2e-tests/src/test/kotlin/features/did/PublishDidSteps.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package features.did

import api_models.*
import common.TestConstants
import common.Utils.lastResponseList
import common.Utils.lastResponseObject
import common.Utils.wait
import io.cucumber.java.en.Given
Expand All @@ -14,28 +16,52 @@ import net.serenitybdd.screenplay.rest.questions.ResponseConsequence
import org.apache.http.HttpStatus.*
import org.assertj.core.api.Assertions.assertThat
import org.hamcrest.Matchers.*
import java.time.Duration

class PublishDidSteps {

@Given("{actor} have published PRISM DID")
fun actorHavePublishedPrismDid(actor: Actor) {
actor.attemptsTo(
Get.resource("/did-registrar/dids"),
)
actor.should(
ResponseConsequence.seeThatResponse {
it.statusCode(SC_OK)
},
)
val publishedDids = lastResponseList("contents", ManagedDid::class).filter {
it.status == ManagedDidStatuses.PUBLISHED
}
val did = publishedDids.firstOrNull {
actor.attemptsTo(
Get.resource("/dids/${it.did}"),
)
lastResponseObject("metadata.deactivated", String::class) == "false"
}
if (did == null) {
createsUnpublishedDid(actor)
hePublishesDidToLedger(actor)
} else {
actor.remember("shortFormDid", did.did)
}
}

@Given("{actor} creates unpublished DID")
fun createsUnpublishedDid(actor: Actor) {
val publicKeys = listOf(
PublicKey("key1", Purpose.AUTHENTICATION),
PublicKey("key2", Purpose.ASSERTION_METHOD),
TestConstants.PRISM_DID_AUTH_KEY,
TestConstants.PRISM_DID_ASSERTION_KEY,
)
val services = listOf(
Service(
"https://foo.bar.com",
"LinkedDomains",
listOf("https://foo.bar.com"),
),
TestConstants.PRISM_DID_SERVICE,
TestConstants.PRISM_DID_SERVICE_FOR_UPDATE,
TestConstants.PRISM_DID_SERVICE_TO_REMOVE,
)
val documentTemplate = DocumentTemplate(publicKeys, services)
actor.attemptsTo(
Post.to("/did-registrar/dids")
.with {
it.body(CreateManagedDidRequest(documentTemplate))
it.body(CreatePrismDidRequest(documentTemplate))
},
)
actor.should(
Expand All @@ -45,6 +71,7 @@ class PublishDidSteps {
},
)
val longFormDid = lastResponseObject("longFormDid", String::class)
actor.remember("longFormDid", longFormDid)

actor.attemptsTo(
Get.resource("/did-registrar/dids/$longFormDid"),
Expand All @@ -58,7 +85,6 @@ class PublishDidSteps {
"shortFormDid",
lastResponseObject("", ManagedDid::class).did,
)
actor.remember("longFormDid", longFormDid)
}

@When("{actor} publishes DID to ledger")
Expand All @@ -81,7 +107,7 @@ class PublishDidSteps {
SerenityRest.lastResponse().statusCode == SC_OK
},
"ERROR: DID was not published to ledger!",
timeout = Duration.ofSeconds(600L),
timeout = TestConstants.DID_UPDATE_PUBLISH_MAX_WAIT_5_MIN,
)
actor.should(
ResponseConsequence.seeThatResponse {
Expand Down Expand Up @@ -110,11 +136,11 @@ class PublishDidSteps {

assertThat(didDocument.authentication!![0])
.hasFieldOrPropertyWithValue("type", "REFERENCED")
.hasFieldOrPropertyWithValue("uri", "$shortFormDid#key1")
.hasFieldOrPropertyWithValue("uri", "$shortFormDid#${TestConstants.PRISM_DID_AUTH_KEY.id}")

assertThat(didDocument.verificationMethod!![0])
.hasFieldOrPropertyWithValue("controller", shortFormDid)
.hasFieldOrPropertyWithValue("id", "$shortFormDid#key1")
.hasFieldOrPropertyWithValue("id", "$shortFormDid#${TestConstants.PRISM_DID_ASSERTION_KEY.id}")
.hasFieldOrProperty("publicKeyJwk")

assertThat(lastResponseObject("", DidDocument::class).metadata!!)
Expand Down
Loading

0 comments on commit 226a481

Please sign in to comment.