diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml index 6bdb3af7..13154906 100644 --- a/.github/workflows/integration-tests.yml +++ b/.github/workflows/integration-tests.yml @@ -25,7 +25,7 @@ jobs: ATALA_GITHUB_ACTOR: ${{ secrets.ATALA_GITHUB_ACTOR }} ATALA_GITHUB_TOKEN: ${{ secrets.ATALA_GITHUB_TOKEN }} REPORTS_DIR: "didcomm-v2-mediator-test-suite/target/site/serenity" - DIDCOMM_V2_TESTSUITE_VERSION: "v0.1.0" + DIDCOMM_V2_TESTSUITE_VERSION: "3ed43f8f864ef0ea1cd89a9f81d3f379e8c0c217" # old "v0.1.0" MEDIATOR_DID: "did:peer:2.Ez6LSghwSE437wnDE1pt3X6hVDUQzSjsHzinpX3XFvMjRAm7y.Vz6Mkhh1e5CEYYq6JBUcTZ6Cp2ranCWRrv7Yax3Le4N59R6dd.SeyJ0IjoiZG0iLCJzIjoiaHR0cDovL2xvY2FsaG9zdDo4MDgwIiwiciI6W10sImEiOlsiZGlkY29tbS92MiJdfQ" steps: - name: Checkout mediator @@ -35,7 +35,7 @@ jobs: uses: actions/checkout@v3 with: repository: input-output-hk/didcomm-v2-mediator-test-suite - path: './didcomm-v2-mediator-test-suite' + path: "./didcomm-v2-mediator-test-suite" ref: ${{ env.DIDCOMM_V2_TESTSUITE_VERSION }} - name: Setup Java and Scala @@ -62,7 +62,7 @@ jobs: uses: ndeloof/install-compose-action@v0.0.1 with: version: v2.19.1 # defaults to 'latest' - legacy: true # will also install in PATH as `docker-compose` + legacy: true # will also install in PATH as `docker-compose` - name: Build local version of Mediator Agent env: diff --git a/mediator/src/main/scala/io/iohk/atala/mediator/app/MediatorAgent.scala b/mediator/src/main/scala/io/iohk/atala/mediator/app/MediatorAgent.scala index 6da8785d..31ae6f06 100644 --- a/mediator/src/main/scala/io/iohk/atala/mediator/app/MediatorAgent.scala +++ b/mediator/src/main/scala/io/iohk/atala/mediator/app/MediatorAgent.scala @@ -24,6 +24,7 @@ import scala.util.Try import scala.io.Source import zio.http.Header.AccessControlAllowOrigin import zio.http.Header.AccessControlAllowMethods +import zio.http.Header.HeaderType case class MediatorAgent( override val id: DID, @@ -267,53 +268,62 @@ object MediatorAgent { } yield (ret) }, Method.POST / trailing -> handler { (req: Request) => - { - if ( - req.headers - .get("content-type") - .exists { h => h == MediaTypes.SIGNED.typ || h == MediaTypes.ENCRYPTED.typ } - ) { - for { - agent <- ZIO.service[MediatorAgent] - data <- req.body.asString - .catchAll(ex => ZIO.fail(Response.badRequest("Unable to read the body of the request"))) - ret <- agent - .receiveMessage(data) - .map { - case None => Response.ok - case Some(value: SignedMessage) => Response.json(value.toJson) - case Some(value: EncryptedMessage) => Response.json(value.toJson) - } - .catchAll { - case MediatorDidError(error) => - ZIO.logError(s"Error MediatorDidError: $error") *> - ZIO.succeed(Response.status(Status.BadRequest)) - case MediatorThrowable(error) => - ZIO.logError(s"Error MediatorThrowable: $error") *> - ZIO.succeed(Response.status(Status.BadRequest)) - case StorageCollection(error) => - ZIO.logError(s"Error StorageCollection: $error") *> - ZIO.succeed(Response.status(Status.BadRequest)) - case StorageThrowable(error) => - ZIO.logError(s"Error StorageThrowable: $error") *> - ZIO.succeed(Response.status(Status.BadRequest)) - case DuplicateMessage(error) => - ZIO.logError(s"Error DuplicateKeyError: $error") *> - ZIO.succeed(Response.status(Status.BadRequest)) - case MissingProtocolError(piuri) => - ZIO.logError(s"MissingProtocolError ('$piuri')") *> - ZIO.succeed(Response.status(Status.BadRequest)) // TODO - } - } yield ret - } else - ZIO - .logError(s"Request Headers: ${req.headers.mkString(",")}") - .as( - Response - .text(s"The content-type must be ${MediaTypes.SIGNED.typ} or ${MediaTypes.ENCRYPTED.typ}") - .copy(status = Status.BadRequest) - ) - } + if ( + req.headers + .get("content-type") + .exists { h => h == MediaTypes.SIGNED.typ || h == MediaTypes.ENCRYPTED.typ } + ) { + for { + agent <- ZIO.service[MediatorAgent] + data <- req.body.asString + .catchAll(ex => ZIO.fail(Response.badRequest("Unable to read the body of the request"))) + ret <- agent + .receiveMessage(data) + .map { + case None => Response(status = Status.Accepted) + case Some(value: SignedMessage) => + Response( + status = Status.Accepted, + headers = Headers(Header.ContentType(MediaType.apply("application", "didcomm-signed+json"))), + body = Body.fromCharSequence(value.toJson) + ) + case Some(value: EncryptedMessage) => + Response( + status = Status.Accepted, + headers = Headers(Header.ContentType(MediaType.apply("application", "didcomm-encrypted+json"))), + body = Body.fromCharSequence(value.toJson) + ) + } + .catchAll { + case MediatorDidError(error) => + ZIO.logError(s"Error MediatorDidError: $error") *> + ZIO.succeed(Response.status(Status.BadRequest)) + case MediatorThrowable(error) => + ZIO.logError(s"Error MediatorThrowable: $error") *> + ZIO.succeed(Response.status(Status.BadRequest)) + case StorageCollection(error) => + ZIO.logError(s"Error StorageCollection: $error") *> + ZIO.succeed(Response.status(Status.BadRequest)) + case StorageThrowable(error) => + ZIO.logError(s"Error StorageThrowable: $error") *> + ZIO.succeed(Response.status(Status.BadRequest)) + case DuplicateMessage(error) => + ZIO.logError(s"Error DuplicateKeyError: $error") *> + ZIO.succeed(Response.status(Status.BadRequest)) + case MissingProtocolError(piuri) => + ZIO.logError(s"MissingProtocolError ('$piuri')") *> + ZIO.succeed(Response.status(Status.BadRequest)) // TODO + } + } yield ret + } else + ZIO + .logError(s"Request Headers: ${req.headers.mkString(",")}") + .as( + Response + .text(s"The content-type must be ${MediaTypes.SIGNED.typ} or ${MediaTypes.ENCRYPTED.typ}") + .copy(status = Status.BadRequest) + ) + }, Method.GET / trailing -> handler { (req: Request) => for {