Skip to content

Commit

Permalink
fix: create peer DID with updateMediator false does not ignore provid…
Browse files Browse the repository at this point in the history
…ed services (#73)

Co-authored-by: Ahmed Moussa <[email protected]>
  • Loading branch information
cristianIOHK and hamada147 authored Jun 2, 2023
1 parent 4812016 commit 662c845
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .markdownlint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"MD013": false
}
2 changes: 1 addition & 1 deletion .mega-linter.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
APPLY_FIXES: none
FILTER_REGEX_EXCLUDE: (karma.config.js|polyfill.js|timeout.js)
FILTER_REGEX_EXCLUDE: (karma.config.js|polyfill.js|timeout.js|CHANGELOG.md)
VALIDATE_ALL_CODEBASE: true
REPOSITORY_DEVSKIM_DISABLE_ERRORS: true
REPOSITORY_CHECKOV_DISABLE_ERRORS: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ internal class CastorShared {
id = it.id,
type = it.type[0],
serviceEndpoint = it.serviceEndpoint.uri,
routingKeys = listOf(),
routingKeys = it.serviceEndpoint.routingKeys?.toList() ?: listOf(),
accept = it.serviceEndpoint.accept?.asList() ?: listOf(),
).toDict().toJsonElement(),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,9 @@ class PrismAgent {
val authenticationKeyPair =
apollo.createKeyPair(seed = seed, curve = KeyCurve(Curve.ED25519))

var tmpServices = arrayOf<DIDDocument.Service>()
var tmpServices = services
if (updateMediator) {
tmpServices = services.plus(
tmpServices.plus(
DIDDocument.Service(
id = DIDCOMM1,
type = arrayOf(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
package io.iohk.atala.prism.walletsdk.prismagent

/* ktlint-disable import-ordering */
import io.iohk.atala.prism.walletsdk.apollo.ApolloImpl
import io.iohk.atala.prism.walletsdk.castor.CastorImpl
import io.iohk.atala.prism.walletsdk.domain.models.Curve
import io.iohk.atala.prism.walletsdk.domain.models.DID
import io.iohk.atala.prism.walletsdk.domain.models.DIDDocument
import io.iohk.atala.prism.walletsdk.domain.models.KeyCurve
import io.iohk.atala.prism.walletsdk.domain.models.PrismAgentError
import io.iohk.atala.prism.walletsdk.domain.models.PrivateKey
import io.iohk.atala.prism.walletsdk.domain.models.Seed
import io.iohk.atala.prism.walletsdk.domain.models.Signature
import io.iohk.atala.prism.walletsdk.mercury.ApiMock
import io.iohk.atala.prism.walletsdk.prismagent.protocols.ProtocolType
import io.iohk.atala.prism.walletsdk.prismagent.protocols.outOfBand.OutOfBandInvitation
import io.iohk.atala.prism.walletsdk.prismagent.protocols.outOfBand.PrismOnboardingInvitation
import io.iohk.atala.prism.walletsdk.prismagent.protocols.ProtocolType
import io.ktor.http.HttpStatusCode
import io.ktor.utils.io.core.toByteArray
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.test.runTest
import kotlin.test.BeforeTest
Expand All @@ -22,6 +24,7 @@ import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
import kotlin.test.assertFalse
import kotlin.test.assertTrue

/* ktlint-disable import-ordering */

@OptIn(kotlinx.coroutines.ExperimentalCoroutinesApi::class)
Expand Down Expand Up @@ -84,13 +87,49 @@ class PrismAgentTests {
null,
null,
)

val newDID = agent.createNewPeerDID(services = emptyArray(), updateMediator = false)

assertEquals(newDID, validDID)
assertEquals(newDID, plutoMock.storedPeerDID.first())
assertTrue { plutoMock.wasStorePeerDIDAndPrivateKeysCalled }
}

@Test
fun testCreateNewPeerDID_whenUpdateMediatorFalse_thenShouldUseProvidedServices() = runTest {
val apollo = ApolloImpl()
val castor = CastorImpl(apollo)
val agent = PrismAgent(
apollo,
castor,
plutoMock,
mercuryMock,
polluxMock,
connectionManager,
null,
null,
)

val seAccept = arrayOf("someAccepts")
val seRoutingKeys = arrayOf("someRoutingKey")
val service = DIDDocument.Service(
id = "DIDCommV2",
type = arrayOf(DIDCOMM_MESSAGING),
serviceEndpoint = DIDDocument.ServiceEndpoint(
uri = "localhost:8082",
accept = seAccept,
routingKeys = seRoutingKeys,
),
)
val newDID = agent.createNewPeerDID(services = arrayOf(service), updateMediator = false)

val document = castor.resolveDID(newDID.toString())
val services = document.services
assertTrue(services.isNotEmpty())
assertEquals(service.type.first(), services.first().type.first())
assertEquals(service.serviceEndpoint, services.first().serviceEndpoint)
}

@Test
fun testPrismAgentOnboardingInvitation_shouldAcceptOnboardingInvitation_whenStatusIs200() = runTest {
val agent = PrismAgent(
Expand Down Expand Up @@ -317,7 +356,8 @@ class PrismAgentTests {

@Test
fun test_OOPInvitationInURLFormat() = runTest {
val oob = "https://my.domain.com/path?_oob=eyJpZCI6ImQzNjM3NzlhLWYyMmItNGFiNC1hYjY0LTkxZjkxNjgzNzYwNyIsInR5cGUiOiJodHRwczovL2RpZGNvbW0ub3JnL291dC1vZi1iYW5kLzIuMC9pbnZpdGF0aW9uIiwiZnJvbSI6ImRpZDpwZWVyOjIuRXo2TFNjcGZReGJ2VEhLaGpvbzVvMzlmc254VEp1RTRobVp3ckROUE5BVzI0dmFORi5WejZNa3UzSkpVTDNkaHpYQXB0RWpuUDFpNkF0TDlTNGlwRTNYOHM3MWV4MW9WVGNHLlNleUowSWpvaVpHMGlMQ0p6SWpvaWFIUjBjSE02THk5ck9ITXRaR1YyTG1GMFlXeGhjSEpwYzIwdWFXOHZjSEpwYzIwdFlXZGxiblF2Wkdsa1kyOXRiU0lzSW5JaU9sdGRMQ0poSWpwYkltUnBaR052YlcwdmRqSWlYWDAiLCJib2R5Ijp7ImdvYWxfY29kZSI6ImlvLmF0YWxhcHJpc20uY29ubmVjdCIsImdvYWwiOiJFc3RhYmxpc2ggYSB0cnVzdCBjb25uZWN0aW9uIGJldHdlZW4gdHdvIHBlZXJzIHVzaW5nIHRoZSBwcm90b2NvbCAnaHR0cHM6Ly9hdGFsYXByaXNtLmlvL21lcmN1cnkvY29ubmVjdGlvbnMvMS4wL3JlcXVlc3QnIiwiYWNjZXB0IjpbXX19"
val oob =
"https://my.domain.com/path?_oob=eyJpZCI6ImQzNjM3NzlhLWYyMmItNGFiNC1hYjY0LTkxZjkxNjgzNzYwNyIsInR5cGUiOiJodHRwczovL2RpZGNvbW0ub3JnL291dC1vZi1iYW5kLzIuMC9pbnZpdGF0aW9uIiwiZnJvbSI6ImRpZDpwZWVyOjIuRXo2TFNjcGZReGJ2VEhLaGpvbzVvMzlmc254VEp1RTRobVp3ckROUE5BVzI0dmFORi5WejZNa3UzSkpVTDNkaHpYQXB0RWpuUDFpNkF0TDlTNGlwRTNYOHM3MWV4MW9WVGNHLlNleUowSWpvaVpHMGlMQ0p6SWpvaWFIUjBjSE02THk5ck9ITXRaR1YyTG1GMFlXeGhjSEpwYzIwdWFXOHZjSEpwYzIwdFlXZGxiblF2Wkdsa1kyOXRiU0lzSW5JaU9sdGRMQ0poSWpwYkltUnBaR052YlcwdmRqSWlYWDAiLCJib2R5Ijp7ImdvYWxfY29kZSI6ImlvLmF0YWxhcHJpc20uY29ubmVjdCIsImdvYWwiOiJFc3RhYmxpc2ggYSB0cnVzdCBjb25uZWN0aW9uIGJldHdlZW4gdHdvIHBlZXJzIHVzaW5nIHRoZSBwcm90b2NvbCAnaHR0cHM6Ly9hdGFsYXByaXNtLmlvL21lcmN1cnkvY29ubmVjdGlvbnMvMS4wL3JlcXVlc3QnIiwiYWNjZXB0IjpbXX19"
val agent = PrismAgent(
apollo = apolloMock,
castor = castorMock,
Expand Down

0 comments on commit 662c845

Please sign in to comment.