You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by rc...@apache.org on 2021/11/26 04:34:59 UTC

[james-project] 03/03: JAMES-3534 Identity/get should not fail when response with empty List[Identity]

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 95f8e7703ac98ab72e80a682d7ca342d3fc856ca
Author: Quan Tran <hq...@linagora.com>
AuthorDate: Wed Nov 24 14:06:23 2021 +0700

    JAMES-3534 Identity/get should not fail when response with empty List[Identity]
    
    Otherwise we have NoSuchElementException when get a None
---
 .../rfc8621/contract/IdentityGetContract.scala     | 50 ++++++++++++++++++++++
 .../org/apache/james/jmap/mail/IdentityGet.scala   |  6 +--
 2 files changed, 53 insertions(+), 3 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/IdentityGetContract.scala b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/IdentityGetContract.scala
index ee6e70d..69219e0 100644
--- a/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/IdentityGetContract.scala
+++ b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/IdentityGetContract.scala
@@ -19,6 +19,8 @@
 
 package org.apache.james.jmap.rfc8621.contract
 
+import java.util.UUID
+
 import com.google.inject.AbstractModule
 import com.google.inject.multibindings.Multibinder
 import io.netty.handler.codec.http.HttpHeaderNames.ACCEPT
@@ -516,4 +518,52 @@ trait IdentityGetContract {
           |    ]
           |}""".stripMargin)
   }
+
+  @Test
+  def getRandomIdShouldNotFail(): Unit = {
+    val id = UUID.randomUUID().toString
+    val request =
+      s"""{
+         |  "using": ["urn:ietf:params:jmap:core", "urn:ietf:params:jmap:submission"],
+         |  "methodCalls": [[
+         |    "Identity/get",
+         |    {
+         |      "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+         |      "ids": ["$id"]
+         |    },
+         |    "c1"]]
+         |}""".stripMargin
+
+    val response =  `given`
+      .header(ACCEPT.toString, ACCEPT_RFC8621_VERSION_HEADER)
+      .body(request)
+    .when
+      .post
+    .`then`
+      .statusCode(SC_OK)
+      .contentType(JSON)
+      .extract
+      .body
+      .asString
+
+    assertThatJson(response)
+      .isEqualTo(
+        s"""{
+           |	"sessionState": "2c9f1b12-b35a-43e6-9af2-0106fb53a943",
+           |	"methodResponses": [
+           |		[
+           |			"Identity/get",
+           |			{
+           |				"accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+           |				"notFound": [
+           |					"$id"
+           |				],
+           |				"state": "2c9f1b12-b35a-43e6-9af2-0106fb53a943",
+           |				"list": []
+           |			},
+           |			"c1"
+           |		]
+           |	]
+           |}""".stripMargin)
+  }
 }
diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/IdentityGet.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/IdentityGet.scala
index 9047d64..1ab37e5 100644
--- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/IdentityGet.scala
+++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/IdentityGet.scala
@@ -59,9 +59,9 @@ case class IdentityGetRequest(accountId: AccountId,
                               ids: Option[IdentityIds],
                               properties: Option[Properties]) extends WithAccountId {
   def computeResponse(identities: List[Identity]): IdentityGetResponse = {
-    val list: Option[List[Identity]] = Some(identities.filter(identity => isRequested(identity.id))).filter(_.nonEmpty)
+    val list: List[Identity] = identities.filter(identity => isRequested(identity.id))
     val notFound: Option[IdentityIds] = ids
-      .map(ids => ids.distinct(list.getOrElse(List()).map(_.id)))
+      .map(ids => ids.distinct(list.map(_.id)))
       .filter(_.nonEmpty)
 
     IdentityGetResponse(
@@ -76,5 +76,5 @@ case class IdentityGetRequest(accountId: AccountId,
 
 case class IdentityGetResponse(accountId: AccountId,
                                state: UuidState,
-                               list: Option[List[Identity]],
+                               list: List[Identity],
                                notFound: Option[IdentityIds])

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org