This is an automated email from the ASF dual-hosted git repository. rcordier pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/james-project.git
commit b4427970abd7ab64a672fcfd797da50b40d3572d Author: Benoit Tellier <btell...@linagora.com> AuthorDate: Mon Aug 17 14:55:57 2020 +0700 JAMES-3359 Mailbox/set update should fail on delegated mailboxes --- .../contract/MailboxSetMethodContract.scala | 108 ++++++++++++++++++++- .../james/jmap/method/MailboxSetMethod.scala | 1 + 2 files changed, 108 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 d57b247..3436f8f 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 @@ -2318,7 +2318,113 @@ trait MailboxSetMethodContract { |}""".stripMargin) } + @Test + def updateShouldFailWhenMailboxNotFound(): Unit = { + val mailboxId1: MailboxId = randomMailboxId + val request = + s""" + |{ + | "using": [ "urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail" ], + | "methodCalls": [ + | ["Mailbox/set", + | { + | "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6", + | "update": { + | "${mailboxId1.serialize()}": { + | "/name": "newName" + | } + | } + | }, + | "c1"]] + |} + |""".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": { + | "${mailboxId1.serialize()}": { + | "type": "notFound", + | "description": "${mailboxId1.serialize()} can not be found" + | } + | } + | }, "c1"] + | ] + |}""".stripMargin) + } + + @Test + def updateShouldNotRenameDelegtedMailboxes(server: GuiceJamesServer): Unit = { + val path = MailboxPath.forUser(ANDRE, "previousName") + val mailboxId1: MailboxId = server.getProbe(classOf[MailboxProbeImpl]).createMailbox(path) + server.getProbe(classOf[ACLProbeImpl]) + .replaceRights(path, BOB.asString, MailboxACL.FULL_RIGHTS) + val request = + s""" + |{ + | "using": [ "urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail" ], + | "methodCalls": [ + | ["Mailbox/set", + | { + | "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6", + | "update": { + | "${mailboxId1.serialize()}": { + | "/name": "newName" + | } + | } + | }, + | "c1"]] + |} + |""".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": { + | "${mailboxId1.serialize()}": { + | "type": "notFound", + | "description": "#private:an...@domain.tld:previousName" + | } + | } + | }, "c1"] + | ] + |}""".stripMargin) + } + // TODO invalid path handling (unknown property, invalid name) // TODO disable destroy / rename of system mailbox - // TODO renaming delegated mailboxes is not allowed } diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MailboxSetMethod.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MailboxSetMethod.scala index 8122a42..ea79a9c 100644 --- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MailboxSetMethod.scala +++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MailboxSetMethod.scala @@ -118,6 +118,7 @@ sealed trait UpdateResult case class UpdateSuccess(mailboxId: MailboxId) extends UpdateResult case class UpdateFailure(mailboxId: UnparsedMailboxId, exception: Throwable) extends UpdateResult { def asMailboxSetError: MailboxSetError = exception match { + case e: MailboxNotFoundException => MailboxSetError.notFound(Some(SetErrorDescription(e.getMessage))) case e: MailboxNameException => MailboxSetError.invalidArgument(Some(SetErrorDescription(e.getMessage)), Some(Properties(List("/name")))) case e: MailboxExistsException => MailboxSetError.invalidArgument(Some(SetErrorDescription(e.getMessage)), Some(Properties(List("/name")))) case _ => MailboxSetError.serverFail(Some(SetErrorDescription(exception.getMessage)), None) --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org