This is an automated email from the ASF dual-hosted git repository. btellier pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 811cc24b94810e172ad2dc03e465ccb62bc43080 Author: Rene Cordier <[email protected]> AuthorDate: Fri Aug 21 10:32:43 2020 +0700 JAMES-3359 Mailbox/set update isSubscribed patch validation --- .../contract/MailboxSetMethodContract.scala | 56 ++++++++++++++++++++++ .../org/apache/james/jmap/mail/MailboxSet.scala | 2 +- 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/MailboxSetMethodContract.scala b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/MailboxSetMethodContract.scala index 4adc902..e431c0c 100644 --- a/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/MailboxSetMethodContract.scala +++ b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/MailboxSetMethodContract.scala @@ -4134,6 +4134,62 @@ trait MailboxSetMethodContract { |}""".stripMargin) } + + @Test + def updateShouldFailWhenInvalidIsSubscribedJSON(server: GuiceJamesServer): Unit = { + val mailboxId: MailboxId = server.getProbe(classOf[MailboxProbeImpl]).createMailbox(MailboxPath.forUser(BOB, "mailbox")) + + val request = + s""" + |{ + | "using": [ "urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail" ], + | "methodCalls": [ + | ["Mailbox/set", + | { + | "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6", + | "update": { + | "${mailboxId.serialize()}" : { + | "/isSubscribed": "invalid" + | } + | } + | }, + | "c3"] + | ] + |} + |""".stripMargin + + val response = `given` + .header(ACCEPT.toString, ACCEPT_RFC8621_VERSION_HEADER) + .body(request) + .when + .post + .`then` + .log().ifValidationFails() + .statusCode(SC_OK) + .contentType(JSON) + .extract + .body + .asString + + assertThatJson(response).isEqualTo( + s"""{ + | "sessionState": "75128aab4b1b", + | "methodResponses": [ + | ["Mailbox/set", { + | "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6", + | "newState": "000001", + | "notUpdated": { + | "${mailboxId.serialize()}": { + | "type": "invalidArguments", + | "description": "Expecting a JSON boolean as an argument", + | "properties": ["/isSubscribed"] + | } + | } + | }, "c3"] + | ] + |}""".stripMargin) + } + @Test def deleteShouldNotRemoveMessageWhenMailboxIsNotEmptyAndOnDestroyRemoveEmailsIsFalse(server: GuiceJamesServer): Unit = { val message: Message = Message.Builder diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/MailboxSet.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/MailboxSet.scala index c4f6bcd..44bb866 100644 --- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/MailboxSet.scala +++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/MailboxSet.scala @@ -182,7 +182,7 @@ object IsSubscribedUpdate { def parse(newValue: JsValue): Either[PatchUpdateValidationException, Update] = newValue match { case JsBoolean(value) => scala.Right(IsSubscribedUpdate(IsSubscribed(value))) case JsNull => scala.Right(IsSubscribedUpdate(IsSubscribed(true))) - case _ => Left(InvalidUpdateException("/isSubscribed", "Expecting a JSON string as an argument")) + case _ => Left(InvalidUpdateException("/isSubscribed", "Expecting a JSON boolean as an argument")) } } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
