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 fa5bcc0af53e0075fb0e1336de95d6b5669dd337
Author: Benoit Tellier <[email protected]>
AuthorDate: Fri Oct 2 16:50:59 2020 +0700

    JAMES-3359 Mailbox/set update should handle clientId resolution failures
---
 .../contract/MailboxSetMethodContract.scala        | 53 ++++++++++++++++++++++
 .../james/jmap/method/MailboxSetMethod.scala       |  2 +-
 2 files changed, 54 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 106194c..413aadb 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
@@ -7313,4 +7313,57 @@ trait MailboxSetMethodContract {
          |    "c1"]]
          |}""".stripMargin)
   }
+
+  @Test
+  def updateShouldHandleNotFoundClientId(server: GuiceJamesServer): Unit = {
+    val mailboxProbe = server.getProbe(classOf[MailboxProbeImpl])
+    val mailboxId: MailboxId = 
mailboxProbe.createMailbox(MailboxPath.forUser(BOB, "mailbox"))
+
+    val response = `given`
+      .header(ACCEPT.toString, ACCEPT_RFC8621_VERSION_HEADER)
+      .body(s"""{
+               |  "using": [ "urn:ietf:params:jmap:core", 
"urn:ietf:params:jmap:mail" ],
+               |  "methodCalls": [
+               |    [
+               |     "Mailbox/set",
+               |     {
+               |       "accountId": 
"29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+               |       "update": {
+               |         "#invalid": {
+               |           "name": "newName"
+               |         }
+               |       }
+               |     },
+               |     "c1"]]
+               |}""".stripMargin)
+    .when
+      .post
+    .`then`
+      .statusCode(SC_OK)
+      .contentType(JSON)
+      .extract
+      .body
+      .asString
+
+    assertThatJson(response).isEqualTo(
+      s"""{
+         |    "sessionState": "75128aab4b1b",
+         |    "methodResponses": [
+         |        [
+         |            "Mailbox/set",
+         |            {
+         |                "accountId": 
"29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+         |                "newState": "000001",
+         |                "notUpdated": {
+         |                    "#invalid": {
+         |                        "type": "invalidArguments",
+         |                        "description": "ClientId(#invalid) was not 
used in previously defined creationIds"
+         |                    }
+         |                }
+         |            },
+         |            "c1"
+         |        ]
+         |    ]
+         |}""".stripMargin)
+  }
 }
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 df6b77c..5c9a50a 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
@@ -37,7 +37,6 @@ import 
org.apache.james.mailbox.exception.{InsufficientRightsException, MailboxE
 import org.apache.james.mailbox.model.{FetchGroup, MailboxId, MailboxPath, 
MessageRange}
 import org.apache.james.mailbox.{MailboxManager, MailboxSession, 
MessageManager, Role, SubscriptionManager}
 import org.apache.james.metrics.api.MetricFactory
-import org.reactivestreams.Publisher
 import play.api.libs.json.{JsError, JsObject, JsPath, JsSuccess, Json, 
JsonValidationError}
 import reactor.core.scala.publisher.{SFlux, SMono}
 import reactor.core.scheduler.Schedulers
@@ -128,6 +127,7 @@ case class UpdateFailure(mailboxId: UnparsedMailboxId, 
exception: Throwable, pat
     case e: LoopInMailboxGraphException => 
SetError.invalidArguments(SetErrorDescription("A mailbox parentId property can 
not be set to itself or one of its child"), Some(Properties("parentId")))
     case e: InsufficientRightsException => 
SetError.invalidArguments(SetErrorDescription("Invalid change to a delegated 
mailbox"))
     case e: MailboxHasChildException => 
SetError.invalidArguments(SetErrorDescription(s"${e.mailboxId.serialize()} 
parentId property cannot be updated as this mailbox has child mailboxes"), 
Some(Properties("parentId")))
+    case e: IllegalArgumentException => 
SetError.invalidArguments(SetErrorDescription(e.getMessage), None)
     case _ => SetError.serverFail(SetErrorDescription(exception.getMessage))
   }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to