Skip to content

Commit

Permalink
test: add basic keylist-query integration test (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
Anton Baliasnikov authored and mineme0110 committed Apr 30, 2024
1 parent 38b6ed7 commit b071fcc
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,20 @@ data class MediationKeylistRequest(
): JsonEncoded

@Serializable
data class MediationKeylistResponse(
data class MediationKeylistUpdateResponse(
val updated: List<MediationKeylistResponseMessage>
): JsonEncoded

@Serializable
data class MediationKeylistResponse(
val keys: List<MediationKeylistKey>
): JsonEncoded

@Serializable
data class MediationKeylistKey(
val recipient_did: String
): JsonEncoded

@Serializable
data class MediationKeylistRequestMessage(
val action: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ object DidcommMessageTypes {
const val MEDIATE_REQUEST = "https://didcomm.org/coordinate-mediation/2.0/mediate-request"
const val MEDIATE_GRANT = "https://didcomm.org/coordinate-mediation/2.0/mediate-grant"
const val MEDIATE_KEYLIST_UPDATE = "https://didcomm.org/coordinate-mediation/2.0/keylist-update"
const val MEDIATE_KEYLIST_RESPONSE = "https://didcomm.org/coordinate-mediation/2.0/keylist-update-response"
const val MEDIATE_KEYLIST_UPDATE_RESPONSE = "https://didcomm.org/coordinate-mediation/2.0/keylist-update-response"
const val MEDIATE_KEYLIST = "https://didcomm.org/coordinate-mediation/2.0/keylist"
const val MEDIATE_KEYLIST_QUERY = "https://didcomm.org/coordinate-mediation/2.0/keylist-query"
const val FORWARD_REQUEST = "https://didcomm.org/routing/2.0/forward"
const val BASIC_MESSAGE = "https://didcomm.org/basicmessage/2.0/message"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import io.iohk.atala.prism.walletsdk.domain.models.DID
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.json.Json
import models.*
import net.serenitybdd.core.Serenity

class MediationCoordinationSteps {

Expand Down Expand Up @@ -81,9 +80,9 @@ class MediationCoordinationSteps {
@Then("Mediator responds to {actor} with a correct keylist update add message")
fun mediatorRespondsToHimWithACorrectKeylistUpdateAddMessage(recipient: Actor) {
val didcommMessage = EdgeAgent.unpackLastDidcommMessage()
val didcommBody = Json.decodeFromString<MediationKeylistResponse>(didcommMessage.body)
val didcommBody = Json.decodeFromString<MediationKeylistUpdateResponse>(didcommMessage.body)
recipient.attemptsTo(
Ensure.that(didcommMessage.piuri).isEqualTo(DidcommMessageTypes.MEDIATE_KEYLIST_RESPONSE),
Ensure.that(didcommMessage.piuri).isEqualTo(DidcommMessageTypes.MEDIATE_KEYLIST_UPDATE_RESPONSE),
Ensure.that(didcommBody.updated.size).isGreaterThan(0),
Ensure.that(didcommBody.updated[0].result).isEqualTo(TestConstants.MEDIATOR_COORDINATION_ACTION_RESULT_SUCCESS),
Ensure.that(didcommBody.updated[0].action).isEqualTo(TestConstants.MEDIATOR_COORDINATION_ACTION_ADD),
Expand All @@ -97,7 +96,7 @@ class MediationCoordinationSteps {
fun recipientSendsAKeylistQueryMessageToTheMediator(recipient: Actor) {
val keyListQueryMessage = Message(
piuri = DidcommMessageTypes.MEDIATE_KEYLIST_QUERY,
from = EdgeAgent.peerDID,
from = recipient.recall<DID>("peerDid"),
to = Environments.MEDIATOR_PEER_DID,
body = MediationKeylistQueryRequest(
paginate = Paginate(
Expand All @@ -114,8 +113,11 @@ class MediationCoordinationSteps {
@Then("Mediator responds to {actor} with keylist message containing the current list of keys")
fun mediatorRespondsToRecipientWithKeylistMessageContainingTheCurrentListOfKeys(recipient: Actor) {
val didcommMessage = EdgeAgent.unpackLastDidcommMessage()
val didcommBody = Json.decodeFromString<MediationKeylistResponse>(didcommMessage.body)
recipient.attemptsTo(
Ensure.that(didcommMessage.piuri).isEqualTo(DidcommMessageTypes.MEDIATE_KEYLIST_RESPONSE)
Ensure.that(didcommMessage.piuri).isEqualTo(DidcommMessageTypes.MEDIATE_KEYLIST),
Ensure.that(didcommBody.keys.size).isGreaterThan(0),
Ensure.that(didcommBody.keys.last().recipient_did).isEqualTo(recipient.recall<DID>("peerDid").toString())
)
}

Expand Down Expand Up @@ -162,9 +164,9 @@ class MediationCoordinationSteps {
@Then("Mediator responds to {actor} with a correct keylist update remove message")
fun mediatorRespondsToRecipientWithACorrectKeylistUpdateRemoveMessage(recipient: Actor) {
val didcommMessage = EdgeAgent.unpackLastDidcommMessage()
val didcommBody = Json.decodeFromString<MediationKeylistResponse>(didcommMessage.body)
val didcommBody = Json.decodeFromString<MediationKeylistUpdateResponse>(didcommMessage.body)
recipient.attemptsTo(
Ensure.that(didcommMessage.piuri).isEqualTo(DidcommMessageTypes.MEDIATE_KEYLIST_RESPONSE),
Ensure.that(didcommMessage.piuri).isEqualTo(DidcommMessageTypes.MEDIATE_KEYLIST_UPDATE_RESPONSE),
Ensure.that(didcommBody.updated.size).isGreaterThan(0),
Ensure.that(didcommBody.updated[0].result).isEqualTo(TestConstants.MEDIATOR_COORDINATION_ACTION_RESULT_SUCCESS),
Ensure.that(didcommBody.updated[0].action).isEqualTo(TestConstants.MEDIATOR_COORDINATION_ACTION_REMOVE),
Expand Down Expand Up @@ -196,9 +198,9 @@ class MediationCoordinationSteps {
@Then("Mediator responds to {actor} with a message with no_change status")
fun mediatorRespondsToRecipientWithAMessageWithNo_changeStatus(recipient: Actor) {
val didcommMessage = EdgeAgent.unpackLastDidcommMessage()
val didcommBody = Json.decodeFromString<MediationKeylistResponse>(didcommMessage.body)
val didcommBody = Json.decodeFromString<MediationKeylistUpdateResponse>(didcommMessage.body)
recipient.attemptsTo(
Ensure.that(didcommMessage.piuri).isEqualTo(DidcommMessageTypes.MEDIATE_KEYLIST_RESPONSE),
Ensure.that(didcommMessage.piuri).isEqualTo(DidcommMessageTypes.MEDIATE_KEYLIST_UPDATE_RESPONSE),
Ensure.that(didcommBody.updated.size).isGreaterThan(0),
Ensure.that(didcommBody.updated[0].result).isEqualTo(TestConstants.MEDIATOR_COORDINATION_ACTION_RESULT_NO_CHANGE),
Ensure.that(didcommBody.updated[0].action).isEqualTo(TestConstants.MEDIATOR_COORDINATION_ACTION_REMOVE),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Scenario: Recipient removes the last alias from keylist
Then Mediator responds to Recipient with a correct keylist update remove message

# NOT SUPPORTED YET
#Scenario: Recipient query keylist
# Given Recipient successfully set up a connection with the mediator
# When Recipient sends a keylist query message to the mediator
# Then Mediator responds to Recipient with keylist message containing the current list of keys
Scenario: Recipient query keylist
Given Recipient successfully set up a connection with the mediator
When Recipient sends a keylist query message to the mediator
Then Mediator responds to Recipient with keylist message containing the current list of keys

0 comments on commit b071fcc

Please sign in to comment.