Skip to content

Commit

Permalink
test: add DID Registrar test scenario to use new key types (#1071)
Browse files Browse the repository at this point in the history
Signed-off-by: Pat Losoponkul <[email protected]>
  • Loading branch information
patlo-iog committed Jun 13, 2024
1 parent 32b70ba commit 5b35d69
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 46 deletions.
2 changes: 1 addition & 1 deletion infrastructure/local/.env
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
AGENT_VERSION=1.33.1
PRISM_NODE_VERSION=2.2.1
PRISM_NODE_VERSION=2.3.0
VAULT_DEV_ROOT_TOKEN_ID=root
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.32.1")
testImplementation("org.hyperledger.identus:cloud-agent-client-kotlin:1.33.1")
// 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
Expand Up @@ -21,7 +21,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-2", 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
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,28 @@ import net.serenitybdd.rest.SerenityRest
import net.serenitybdd.screenplay.Actor
import net.serenitybdd.screenplay.actors.OnStage
import org.apache.http.HttpStatus
import org.hyperledger.identus.client.models.Connection
import org.hyperledger.identus.client.models.ConnectionsPage
import org.hyperledger.identus.client.models.IssueCredentialRecord
import org.hyperledger.identus.client.models.IssueCredentialRecordPage
import org.hyperledger.identus.client.models.*
import steps.connection.ConnectionSteps
import steps.credentials.IssueCredentialsSteps
import steps.did.PublishDidSteps
import java.lang.IllegalArgumentException

class CommonSteps {
@ParameterType(".*")
fun actor(actorName: String): Actor {
return OnStage.theActorCalled(actorName)
}

@ParameterType(".*")
fun curve(value: String): Curve {
return Curve.decode(value) ?: throw IllegalArgumentException("$value is not a valid Curve value")
}

@ParameterType(".*")
fun purpose(value: String): Purpose {
return Purpose.decode(value) ?: throw IllegalArgumentException("$value is not a valid Purpose value")
}

@Given("{actor} has an issued credential from {actor}")
fun holderHasIssuedCredentialFromIssuer(holder: Actor, issuer: Actor) {
holder.attemptsTo(
Expand Down
54 changes: 30 additions & 24 deletions tests/integration-tests/src/test/kotlin/steps/did/ManageDidSteps.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,27 @@ 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.hyperledger.identus.client.models.CreateManagedDidRequest
import org.hyperledger.identus.client.models.CreateManagedDidRequestDocumentTemplate
import org.hyperledger.identus.client.models.Json
import org.hyperledger.identus.client.models.ManagedDID
import org.hyperledger.identus.client.models.ManagedDIDKeyTemplate
import org.hyperledger.identus.client.models.ManagedDIDPage
import org.hyperledger.identus.client.models.Purpose
import org.hyperledger.identus.client.models.Service
import org.apache.http.HttpStatus.SC_UNPROCESSABLE_ENTITY
import org.hyperledger.identus.client.models.*

class ManageDidSteps {

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

@When("{actor} creates PRISM DID")
fun createManageDid(actor: Actor) {
val createDidRequest = createPrismDidRequest()
fun createManageDidWithSecp256k1Key(actor: Actor) {
createManageDid(actor, Curve.SECP256K1, Purpose.AUTHENTICATION)
}

@When("{actor} creates PRISM DID with {curve} key having {purpose} purpose")
fun createManageDid(actor: Actor, curve: Curve, purpose: Purpose) {
val createDidRequest = createPrismDidRequest(curve, purpose)

actor.attemptsTo(
Post.to("/did-registrar/dids")
Expand All @@ -40,19 +39,17 @@ class ManageDidSteps {
},
)

actor.attemptsTo(
Ensure.thatTheLastResponse().statusCode().isEqualTo(SC_CREATED),
)
if (SerenityRest.lastResponse().statusCode() == SC_CREATED) {
var createdDids = actor.recall<MutableList<String>>("createdDids")
if (createdDids == null) {
createdDids = mutableListOf()
}

var createdDids = actor.recall<MutableList<String>>("createdDids")
if (createdDids == null) {
createdDids = mutableListOf()
}
val managedDid = SerenityRest.lastResponse().get<ManagedDID>()

val managedDid = SerenityRest.lastResponse().get<ManagedDID>()

createdDids.add(managedDid.longFormDid!!)
actor.remember("createdDids", createdDids)
createdDids.add(managedDid.longFormDid!!)
actor.remember("createdDids", createdDids)
}
}

@When("{actor} lists all PRISM DIDs")
Expand All @@ -71,6 +68,15 @@ class ManageDidSteps {
)
}

@Then("{actor} sees PRISM DID was not successfully created")
fun theDidShouldNotBeRegisteredSuccessfully(actor: Actor) {
val error = SerenityRest.lastResponse().get<ErrorResponse>()
actor.attemptsTo(
Ensure.thatTheLastResponse().statusCode().isEqualTo(SC_UNPROCESSABLE_ENTITY),
Ensure.that(error.detail ?: "").isNotEmpty(),
)
}

@Then("{actor} sees the list contains all created DIDs")
fun seeTheListContainsAllCreatedDids(actor: Actor) {
val expectedDids = actor.recall<List<String>>("createdDids")
Expand All @@ -81,9 +87,9 @@ class ManageDidSteps {
)
}

private fun createPrismDidRequest(): CreateManagedDidRequest = CreateManagedDidRequest(
private fun createPrismDidRequest(curve: Curve, purpose: Purpose): CreateManagedDidRequest = CreateManagedDidRequest(
CreateManagedDidRequestDocumentTemplate(
publicKeys = listOf(ManagedDIDKeyTemplate("auth-1", Purpose.AUTHENTICATION)),
publicKeys = listOf(ManagedDIDKeyTemplate("auth-1", purpose, curve)),
services = listOf(
Service("https://foo.bar.com", listOf("LinkedDomains"), Json("https://foo.bar.com/")),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ class PublishDidSteps {
val createDidRequest = CreateManagedDidRequest(
CreateManagedDidRequestDocumentTemplate(
publicKeys = listOf(
ManagedDIDKeyTemplate("auth-1", Purpose.AUTHENTICATION),
ManagedDIDKeyTemplate("assertion-1", Purpose.ASSERTION_METHOD),
ManagedDIDKeyTemplate("auth-1", Purpose.AUTHENTICATION, Curve.SECP256K1),
ManagedDIDKeyTemplate("auth-2", Purpose.AUTHENTICATION, Curve.ED25519),
ManagedDIDKeyTemplate("assertion-1", Purpose.ASSERTION_METHOD, Curve.SECP256K1),
ManagedDIDKeyTemplate("comm-1", Purpose.KEY_AGREEMENT, Curve.X25519),
),
services = listOf(
Service("https://foo.bar.com", listOf("LinkedDomains"), Json("https://foo.bar.com/")),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ import org.hyperledger.identus.client.models.ActionType
import org.hyperledger.identus.client.models.DIDOperationResponse
import org.hyperledger.identus.client.models.DIDResolutionResult
import org.hyperledger.identus.client.models.Json
import org.hyperledger.identus.client.models.ManagedDIDKeyTemplate
import org.hyperledger.identus.client.models.Purpose
import org.hyperledger.identus.client.models.RemoveEntryById
import org.hyperledger.identus.client.models.Service
import org.hyperledger.identus.client.models.UpdateManagedDIDRequest
import org.hyperledger.identus.client.models.UpdateManagedDIDRequestAction
import org.hyperledger.identus.client.models.UpdateManagedDIDServiceAction
Expand All @@ -29,7 +26,7 @@ class UpdateDidSteps {
fun actorUpdatesPrismDidByAddingNewKeys(actor: Actor) {
val updatePrismDidAction = UpdateManagedDIDRequestAction(
actionType = ActionType.ADD_KEY,
ManagedDIDKeyTemplate("auth-2", Purpose.AUTHENTICATION),
addKey = TestConstants.PRISM_DID_UPDATE_NEW_AUTH_KEY,
)
actor.remember("updatePrismDidAction", updatePrismDidAction)
}
Expand All @@ -38,7 +35,7 @@ class UpdateDidSteps {
fun actorUpdatesPrismDidByRemovingKeys(actor: Actor) {
val updatePrismDidAction = UpdateManagedDIDRequestAction(
actionType = ActionType.REMOVE_KEY,
removeKey = RemoveEntryById("auth-1"),
removeKey = RemoveEntryById(TestConstants.PRISM_DID_AUTH_KEY.id),
)
actor.remember("updatePrismDidAction", updatePrismDidAction)
}
Expand All @@ -47,11 +44,7 @@ class UpdateDidSteps {
fun actorUpdatesPrismDidWithNewServices(actor: Actor) {
val updatePrismDidAction = UpdateManagedDIDRequestAction(
actionType = ActionType.ADD_SERVICE,
addService = Service(
"https://new.service.com",
listOf("LinkedDomains"),
Json("https://new.service.com/"),
),
addService = TestConstants.PRISM_DID_UPDATE_NEW_SERVICE,
)
actor.remember("updatePrismDidAction", updatePrismDidAction)
}
Expand All @@ -60,7 +53,7 @@ class UpdateDidSteps {
fun actorUpdatesPrismDidByRemovingServices(actor: Actor) {
val updatePrismDidAction = UpdateManagedDIDRequestAction(
actionType = ActionType.REMOVE_SERVICE,
removeService = RemoveEntryById("https://new.service.com"),
removeService = RemoveEntryById(TestConstants.PRISM_DID_UPDATE_NEW_SERVICE.id),
)
actor.remember("updatePrismDidAction", updatePrismDidAction)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
@dev
Feature: Create and publish DID

Scenario: Create PRISM DID
When Issuer creates PRISM 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
Examples:
| curve | purpose |
| secp256k1 | authentication |
| secp256k1 | assertionMethod |
| Ed25519 | authentication |
| Ed25519 | assertionMethod |
| X25519 | keyAgreement |

Scenario Outline: Create PRISM DID with disallowed key purpose
When Issuer creates PRISM DID with <curve> key having <purpose> purpose
Then He sees PRISM DID was not successfully created
Examples:
| curve | purpose |
| Ed25519 | keyAgreement |
| X25519 | authentication |
| X25519 | assertionMethod |

Scenario: Successfully publish DID to ledger
When Issuer creates unpublished DID
Expand Down

0 comments on commit 5b35d69

Please sign in to comment.