Skip to content

Commit

Permalink
test(prism-agent): add wallet-api and key-management tests (#362)
Browse files Browse the repository at this point in the history
* WIP: add test containers

* WIP: make test container migration work

* WIP: add sample for JdbcDIDSecretStorage

* test(prism-agent): add DIDSecretStorage getKey tests

* test(prism-agent): add DIDSecretStorage insertKey tests

* test(prism-agent): add removeKey tests

* test(prism-agent): add removeDIDSecret tests

* fix(prism-agent): remove InMemoryStorage implementation

* test(prism-agent): add ManagedDIDState crud tests

* test(prism-agent): add DIDLineage crud tests

* build(prism-agent): use scala 3.2.2

* Revert "build(prism-agent): use scala 3.2.2"

This reverts commit 6b7c183.

* test(prism-agent): improve coverage on createAndStoreDID and publishStoredDID

* test(prism-agent): add updateManagedDID tests

* test(prism-agent): add deactivateManagedDID tests

* test(prism-agent): add DID update lineage assertion

* chore: docuemnt some logger config
  • Loading branch information
patlo-iog authored Feb 9, 2023
1 parent e1e5f42 commit 74e1d21
Show file tree
Hide file tree
Showing 15 changed files with 916 additions and 323 deletions.
3 changes: 2 additions & 1 deletion prism-agent/service/project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ object Dependencies {
baseDependencies ++
castorDependencies ++
mercuryDependencies ++
bouncyDependencies
bouncyDependencies ++
postgresDependencies

lazy val serverDependencies: Seq[ModuleID] =
baseDependencies ++
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@ import io.iohk.atala.agent.walletapi.model.{
import io.iohk.atala.agent.walletapi.model.ECCoordinates.*
import io.iohk.atala.agent.walletapi.model.error.{*, given}
import io.iohk.atala.agent.walletapi.service.ManagedDIDService.DEFAULT_MASTER_KEY_ID
import io.iohk.atala.agent.walletapi.storage.{
DIDNonSecretStorage,
DIDSecretStorage,
InMemoryDIDNonSecretStorage,
InMemoryDIDSecretStorage
}
import io.iohk.atala.agent.walletapi.storage.{DIDNonSecretStorage, DIDSecretStorage}
import io.iohk.atala.agent.walletapi.util.{
ManagedDIDTemplateValidator,
OperationFactory,
Expand Down Expand Up @@ -383,11 +378,6 @@ object ManagedDIDService {

val reservedKeyIds: Set[String] = Set(DEFAULT_MASTER_KEY_ID)

def inMemoryStorage: URLayer[DIDOperationValidator & DIDService, ManagedDIDService] =
(InMemoryDIDNonSecretStorage.layer ++ InMemoryDIDSecretStorage.layer) >>> ZLayer.fromFunction(
ManagedDIDService(_, _, _, _)
)

val layer: URLayer[DIDOperationValidator & DIDService & DIDSecretStorage & DIDNonSecretStorage, ManagedDIDService] =
ZLayer.fromFunction(ManagedDIDService(_, _, _, _))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import io.iohk.atala.agent.walletapi.model.ECKeyPair
import com.nimbusds.jose.jwk.OctetKeyPair
import io.iohk.atala.prism.crypto.EC
import io.iohk.atala.shared.utils.Base64Utils
import scala.collection.immutable.ArraySeq

class JdbcDIDSecretStorage(xa: Transactor[Task]) extends DIDSecretStorage {

Expand Down Expand Up @@ -106,17 +107,18 @@ class JdbcDIDSecretStorage(xa: Transactor[Task]) extends DIDSecretStorage {
Clock.instant.flatMap(cxnIO(_).run.transact(xa))
}

override def listKeys(did: PrismDID): Task[Map[String, ECKeyPair]] = {
override def listKeys(did: PrismDID): Task[Seq[(String, ArraySeq[Byte], ECKeyPair)]] = {
val cxnIO = sql"""
| SELECT
| key_id,
| operation_hash,
| key_pair
| FROM public.prism_did_secret_storage
| WHERE
| did = $did
""".stripMargin
.query[(String, ECKeyPair)]
.toMap
.query[(String, ArraySeq[Byte], ECKeyPair)]
.to[List]

cxnIO.transact(xa)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ import zio.*
import io.iohk.atala.mercury.PeerDID
import com.nimbusds.jose.jwk.OctetKeyPair
import io.iohk.atala.mercury.model.DidId
import scala.collection.immutable.ArraySeq

/** A simple single-user DID key storage */
trait DIDSecretStorage {

/** Returns a mapping of key-id to key-pair */
def listKeys(did: PrismDID): Task[Map[String, ECKeyPair]]
/** Returns a list of keys */
def listKeys(did: PrismDID): Task[Seq[(String, ArraySeq[Byte], ECKeyPair)]]

/** Returns the key of confirmed operation */
def getKey(did: PrismDID, keyId: String): Task[Option[ECKeyPair]]
Expand Down

This file was deleted.

This file was deleted.

20 changes: 20 additions & 0 deletions prism-agent/service/wallet-api/src/test/resources/logback.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<configuration>

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>[%level] %logger{15} - %message%n%rEx%xException{10}</pattern>
</encoder>
</appender>

<appender name="ASYNCSTDOUT" class="ch.qos.logback.classic.AsyncAppender">
<appender-ref ref="STDOUT"/>
</appender>

<!-- disable logger(s) that log too much when using test container -->
<logger name="com.zaxxer.hikari" level="OFF"/>

<root level="WARN">
<appender-ref ref="ASYNCSTDOUT"/>
</root>

</configuration>
Loading

0 comments on commit 74e1d21

Please sign in to comment.