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 9fb1d3cdad231418155664450852011d571a67b3
Author: Benoit Tellier <btell...@linagora.com>
AuthorDate: Mon Aug 17 14:38:03 2020 +0700

    JAMES-3359 Mailbox/set update should handle Mailbox level errors
---
 .../contract/MailboxSetMethodContract.scala        | 114 ++++++++++++++++++++-
 .../james/jmap/method/MailboxSetMethod.scala       |   2 +
 2 files changed, 114 insertions(+), 2 deletions(-)

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 180a198..fefaebc 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
@@ -2165,9 +2165,119 @@ trait MailboxSetMethodContract {
          |}""".stripMargin)
   }
 
+  @Test
+  def updateShouldFailWhenTargetMailboxAlreadyExist(server: GuiceJamesServer): 
Unit = {
+    val mailboxId1: MailboxId = 
server.getProbe(classOf[MailboxProbeImpl]).createMailbox(MailboxPath.forUser(BOB,
 "previousName"))
+    
server.getProbe(classOf[MailboxProbeImpl]).createMailbox(MailboxPath.forUser(BOB,
 "newName"))
+    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": "invalidArguments",
+         |                                     "description": "Mailbox with 
name=#private:b...@domain.tld:newName already exists.",
+         |                                     "properties": {
+         |                                             "value": ["/name"]
+         |                                     }
+         |                             }
+         |                     }
+         |             }, "c1"]
+         |     ]
+         |}""".stripMargin)
+  }
+
+  @Test
+  def updateShouldFailWhenMailboxNameIsTooLong(server: GuiceJamesServer): Unit 
= {
+    val mailboxId1: MailboxId = 
server.getProbe(classOf[MailboxProbeImpl]).createMailbox(MailboxPath.forUser(BOB,
 "previousName"))
+    val request =
+      s"""
+        |{
+        |   "using": [ "urn:ietf:params:jmap:core", 
"urn:ietf:params:jmap:mail" ],
+        |   "methodCalls": [
+        |       ["Mailbox/set",
+        |           {
+        |                "accountId": 
"29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+        |                "update": {
+        |                    "${mailboxId1.serialize()}": {
+        |                      "/name": "${"a".repeat(201)}"
+        |                    }
+        |                }
+        |           },
+        |    "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": "invalidArguments",
+         |                                     "description": "Mailbox name 
exceeds maximum size of 200 characters",
+         |                                     "properties": {
+         |                                             "value": ["/name"]
+         |                                     }
+         |                             }
+         |                     }
+         |             }, "c1"]
+         |     ]
+         |}""".stripMargin)
+  }
+
   // TODO invalid path handling (unknown property, invalid name)
-  // TODO mailbox already exists, too long name
-  // TODO disable destroy / rename of sustem mailbox
+  // TODO disable destroy / rename of system mailbox
   // TODO test that renames keeps subscriptions
   // 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 e774a0b..8122a42 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,8 @@ 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: 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

Reply via email to