Skip to content

Commit

Permalink
test: add checks for prism did creation (#1144)
Browse files Browse the repository at this point in the history
Signed-off-by: Allain Magyar <[email protected]>
Signed-off-by: Hyperledger Bot <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Hyperledger Bot <[email protected]>
Co-authored-by: Yurii Shynbuiev - IOHK <[email protected]>
  • Loading branch information
4 people authored Jun 6, 2024
1 parent 2cc6c4d commit 022ed81
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 49 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package common

import org.hyperledger.identus.client.models.*
import java.time.Duration

object TestConstants {
val TESTS_CONFIG = System.getProperty("TESTS_CONFIG") ?: "/configs/basic.conf"
Expand All @@ -19,9 +18,7 @@ object TestConstants {
),
)

val DID_UPDATE_PUBLISH_MAX_WAIT_5_MIN = Duration.ofSeconds(60L)
val PRISM_DID_AUTH_KEY = ManagedDIDKeyTemplate("auth-1", Purpose.AUTHENTICATION)
val PRISM_DID_UPDATE_NEW_AUTH_KEY = ManagedDIDKeyTemplate("auth-42", Purpose.AUTHENTICATION)
val PRISM_DID_SERVICE_FOR_UPDATE = Service(
"https://update.com",
listOf("LinkedDomains"),
Expand Down
83 changes: 71 additions & 12 deletions tests/integration-tests/src/test/kotlin/steps/did/ManageDidSteps.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ package steps.did

import interactions.Get
import interactions.Post
import io.cucumber.java.en.Given
import io.cucumber.java.en.Then
import io.cucumber.java.en.When
import io.cucumber.java.en.*
import io.iohk.atala.automation.extensions.get
import io.iohk.atala.automation.serenity.ensure.Ensure
import net.serenitybdd.rest.SerenityRest
import net.serenitybdd.screenplay.Actor
import org.apache.http.HttpStatus.SC_CREATED
import org.apache.http.HttpStatus.SC_UNPROCESSABLE_ENTITY
import org.apache.http.HttpStatus.*
import org.assertj.core.api.Assertions
import org.hyperledger.identus.client.models.*

class ManageDidSteps {
Expand Down Expand Up @@ -68,6 +66,66 @@ class ManageDidSteps {
)
}

@Then("{actor} sees PRISM DID data was stored correctly with {curve} and {purpose}")
fun agentSeesPrismDidWasStoredCorrectly(actor: Actor, curve: Curve, purpose: Purpose) {
val managedDid = SerenityRest.lastResponse().get<ManagedDID>()
Assertions.assertThat(managedDid.longFormDid).isNotNull()

val longFormDid = managedDid.longFormDid!!
actor.attemptsTo(
Get("/dids/$longFormDid"),
Ensure.thatTheLastResponse().statusCode().isEqualTo(SC_OK),
)

val resolvedDid = SerenityRest.lastResponse().get<DIDResolutionResult>()
Assertions.assertThat(resolvedDid.didDocument).isNotNull()

val didDocument = resolvedDid.didDocument!!

actor.attemptsTo(
Ensure.that(didDocument.id).isEqualTo(longFormDid),
Ensure.that(didDocument.controller!!).contains(longFormDid),
Ensure.that(didDocument.verificationMethod!!.size).isEqualTo(1),
Ensure.that(didDocument.verificationMethod!![0].id).contains(longFormDid),
Ensure.that(didDocument.verificationMethod!![0].controller).contains(longFormDid),
Ensure.that(didDocument.verificationMethod!![0].publicKeyJwk.crv!!).isEqualTo(curve.value),
Ensure.that(didDocument.service!!.size).isGreaterThanOrEqualTo(1),
Ensure.that(didDocument.service!![0].id).contains(longFormDid),
)

when (purpose) {
Purpose.ASSERTION_METHOD -> {
actor.attemptsTo(
Ensure.that(resolvedDid.didDocument!!.assertionMethod!!.size).isEqualTo(1),
)
}

Purpose.AUTHENTICATION -> {
actor.attemptsTo(
Ensure.that(didDocument.authentication!!.size).isEqualTo(1),
)
}

Purpose.CAPABILITY_DELEGATION -> {
actor.attemptsTo(
Ensure.that(didDocument.capabilityDelegation!!.size).isEqualTo(1),
)
}

Purpose.CAPABILITY_INVOCATION -> {
actor.attemptsTo(
Ensure.that(didDocument.capabilityInvocation!!.size).isEqualTo(1),
)
}

Purpose.KEY_AGREEMENT -> {
actor.attemptsTo(
Ensure.that(resolvedDid.didDocument!!.keyAgreement!!.size).isEqualTo(1),
)
}
}
}

@Then("{actor} sees PRISM DID was not successfully created")
fun theDidShouldNotBeRegisteredSuccessfully(actor: Actor) {
val error = SerenityRest.lastResponse().get<ErrorResponse>()
Expand All @@ -87,12 +145,13 @@ class ManageDidSteps {
)
}

private fun createPrismDidRequest(curve: Curve, purpose: Purpose): CreateManagedDidRequest = CreateManagedDidRequest(
CreateManagedDidRequestDocumentTemplate(
publicKeys = listOf(ManagedDIDKeyTemplate("auth-1", purpose, curve)),
services = listOf(
Service("https://foo.bar.com", listOf("LinkedDomains"), Json("https://foo.bar.com/")),
private fun createPrismDidRequest(curve: Curve, purpose: Purpose): CreateManagedDidRequest =
CreateManagedDidRequest(
CreateManagedDidRequestDocumentTemplate(
publicKeys = listOf(ManagedDIDKeyTemplate("auth-1", purpose, curve)),
services = listOf(
Service("https://foo.bar.com", listOf("LinkedDomains"), Json("https://foo.bar.com/")),
),
),
),
)
)
}
37 changes: 25 additions & 12 deletions tests/integration-tests/src/test/kotlin/steps/did/UpdateDidSteps.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,23 @@ import net.serenitybdd.rest.SerenityRest
import net.serenitybdd.screenplay.Actor
import org.apache.http.HttpStatus
import org.hyperledger.identus.client.models.*
import java.util.UUID

class UpdateDidSteps {

@When("{actor} updates PRISM DID by adding new keys")
fun actorUpdatesPrismDidByAddingNewKeys(actor: Actor) {
@When("{actor} updates PRISM DID by adding new key with {curve} curve and {purpose} purpose")
fun actorUpdatesPrismDidByAddingNewKeys(actor: Actor, curve: Curve, purpose: Purpose) {
val newDidKeyId = UUID.randomUUID().toString()
val didKey = ManagedDIDKeyTemplate(
id = newDidKeyId,
purpose = purpose,
curve = curve,
)
val updatePrismDidAction = UpdateManagedDIDRequestAction(
actionType = ActionType.ADD_KEY,
addKey = TestConstants.PRISM_DID_UPDATE_NEW_AUTH_KEY,
addKey = didKey,
)
actor.remember("newDidKeyId", newDidKeyId)
actor.remember("updatePrismDidAction", updatePrismDidAction)
}

Expand Down Expand Up @@ -83,21 +91,26 @@ class UpdateDidSteps {
)
}

@Then("{actor} sees PRISM DID was successfully updated with new keys")
fun actorSeesDidSuccessfullyUpdatedWithNewKeys(actor: Actor) {
@Then("{actor} sees PRISM DID was successfully updated with new keys of {purpose} purpose")
fun actorSeesDidSuccessfullyUpdatedWithNewKeys(actor: Actor, purpose: Purpose) {
val newDidKeyId = actor.recall<String>("newDidKeyId")
var i = 0
Wait.until(
errorMessage = "ERROR: DID UPDATE operation did not succeed on the ledger!",
) {
actor.attemptsTo(
Get.resource("/dids/${actor.recall<String>("shortFormDid")}"),
)
val authUris = SerenityRest.lastResponse().get<DIDResolutionResult>().didDocument!!.authentication!!
val verificationMethods = SerenityRest.lastResponse()
.get<DIDResolutionResult>().didDocument!!.verificationMethod!!.map { it.id }
authUris.any {
it == "${actor.recall<String>("shortFormDid")}#${TestConstants.PRISM_DID_UPDATE_NEW_AUTH_KEY.id}"
} && verificationMethods.any {
it == "${actor.recall<String>("shortFormDid")}#${TestConstants.PRISM_DID_AUTH_KEY.id}"
val didKey = "${actor.recall<String>("shortFormDid")}#$newDidKeyId"
val didDocument = SerenityRest.lastResponse().get<DIDResolutionResult>().didDocument!!
val foundVerificationMethod = didDocument.verificationMethod!!.map { it.id }.any { it == didKey }

foundVerificationMethod && when (purpose) {
Purpose.ASSERTION_METHOD -> didDocument.assertionMethod!!.any { it == didKey }
Purpose.AUTHENTICATION -> didDocument.authentication!!.any { it == didKey }
Purpose.CAPABILITY_DELEGATION -> didDocument.capabilityDelegation!!.any { it == didKey }
Purpose.CAPABILITY_INVOCATION -> didDocument.capabilityInvocation!!.any { it == didKey }
Purpose.KEY_AGREEMENT -> didDocument.keyAgreement!!.any { it == didKey }
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Feature: Create and publish DID
Scenario Outline: Create PRISM DID
When Issuer creates PRISM DID with <curve> key having <purpose> purpose
Then He sees PRISM DID was created successfully
And He sees PRISM DID data was stored correctly with <curve> and <purpose>
Examples:
| curve | purpose |
| secp256k1 | authentication |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,37 @@
@DLT @did @update
Feature: Update DID

Background: Published DID is created
Given Issuer has a published DID
Background: Published DID is created
Given Issuer has a published DID

Scenario: Update PRISM DID by adding new services
When Issuer updates PRISM DID with new services
And He submits PRISM DID update operation
Then He sees PRISM DID was successfully updated with new services
Scenario: Update PRISM DID by adding new services
When Issuer updates PRISM DID with new services
And He submits PRISM DID update operation
Then He sees PRISM DID was successfully updated with new services

Scenario: Update PRISM DID by removing services
When Issuer updates PRISM DID by removing services
And He submits PRISM DID update operation
Then He sees PRISM DID was successfully updated by removing services
Scenario: Update PRISM DID by removing services
When Issuer updates PRISM DID by removing services
And He submits PRISM DID update operation
Then He sees PRISM DID was successfully updated by removing services

Scenario: Update PRISM DID by updating services
When Issuer updates PRISM DID by updating services
And He submits PRISM DID update operation
Then He sees PRISM DID was successfully updated by updating services
Scenario: Update PRISM DID by updating services
When Issuer updates PRISM DID by updating services
And He submits PRISM DID update operation
Then He sees PRISM DID was successfully updated by updating services

Scenario: Update PRISM DID by adding new keys
When Issuer updates PRISM DID by adding new keys
And He submits PRISM DID update operation
Then He sees PRISM DID was successfully updated with new keys
Scenario Outline: Update PRISM DID by adding new keys
When Issuer updates PRISM DID by adding new key with <curve> curve and <purpose> purpose
And He submits PRISM DID update operation
Then He sees PRISM DID was successfully updated with new keys of <purpose> purpose
Examples:
| curve | purpose |
| secp256k1 | authentication |
| secp256k1 | assertionMethod |
| Ed25519 | authentication |
| Ed25519 | assertionMethod |
| X25519 | keyAgreement |

Scenario: Update PRISM DID by removing keys
When Issuer updates PRISM DID by removing keys
And He submits PRISM DID update operation
Then He sees PRISM DID was successfully updated and keys removed
Scenario: Update PRISM DID by removing keys
When Issuer updates PRISM DID by removing keys
And He submits PRISM DID update operation
Then He sees PRISM DID was successfully updated and keys removed

0 comments on commit 022ed81

Please sign in to comment.