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 c688f988b6349585eb8d16e083d6a06bae968188
Author: Florent Azavant <fazav...@linagora.com>
AuthorDate: Wed Nov 6 11:10:21 2024 +0100

    [ISSUE-5314] integration tests for JMAP sharing with keyword `anyone`
---
 .../org/apache/james/modules/ACLProbeImpl.java     |  10 +-
 .../contract/MailboxGetMethodContract.scala        |  43 ++++++
 .../contract/MailboxSetMethodContract.scala        | 156 +++++++++++++++++++++
 3 files changed, 205 insertions(+), 4 deletions(-)

diff --git 
a/server/container/guice/mailbox/src/main/java/org/apache/james/modules/ACLProbeImpl.java
 
b/server/container/guice/mailbox/src/main/java/org/apache/james/modules/ACLProbeImpl.java
index 7a259000b7..60d527d98d 100644
--- 
a/server/container/guice/mailbox/src/main/java/org/apache/james/modules/ACLProbeImpl.java
+++ 
b/server/container/guice/mailbox/src/main/java/org/apache/james/modules/ACLProbeImpl.java
@@ -46,18 +46,20 @@ public class ACLProbeImpl implements GuiceProbe, ACLProbe {
     }
 
     @Override
-    public void replaceRights(MailboxPath mailboxPath, String targetUser, 
Rfc4314Rights rights) throws MailboxException {
+    public void replaceRights(MailboxPath mailboxPath, String 
targetIdentifier, Rfc4314Rights rights) throws MailboxException {
         MailboxSession mailboxSession = 
mailboxManager.createSystemSession(mailboxPath.getUser());
 
-        ACLCommand command = 
MailboxACL.command().forUser(Username.of(targetUser)).rights(rights).asReplacement();
+        MailboxACL.EntryKey targetEntryKey = 
MailboxACL.EntryKey.deserialize(targetIdentifier);
+        ACLCommand command = 
MailboxACL.command().key(targetEntryKey).rights(rights).asReplacement();
         mailboxManager.applyRightsCommand(mailboxPath, command, 
mailboxSession);
     }
 
     @Override
-    public void addRights(MailboxPath mailboxPath, String targetUser, 
Rfc4314Rights rights) throws MailboxException {
+    public void addRights(MailboxPath mailboxPath, String targetIdentifier, 
Rfc4314Rights rights) throws MailboxException {
         MailboxSession mailboxSession = 
mailboxManager.createSystemSession(mailboxPath.getUser());
-        ACLCommand command = 
MailboxACL.command().forUser(Username.of(targetUser)).rights(rights).asAddition();
 
+        MailboxACL.EntryKey targetEntryKey = 
MailboxACL.EntryKey.deserialize(targetIdentifier);
+        ACLCommand command = 
MailboxACL.command().key(targetEntryKey).rights(rights).asReplacement();
         mailboxManager.applyRightsCommand(mailboxPath, command, 
mailboxSession);
     }
 
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/MailboxGetMethodContract.scala
 
b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/MailboxGetMethodContract.scala
index 41d1c10bee..4b92d4bb47 100644
--- 
a/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/MailboxGetMethodContract.scala
+++ 
b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/MailboxGetMethodContract.scala
@@ -954,6 +954,49 @@ trait MailboxGetMethodContract {
       .body(s"$FIRST_MAILBOX.rights['$toUser1']", nullValue)
   }
 
+  @Test
+  @Tag(CategoryTags.BASIC_FEATURE)
+  def getMailboxesShouldNotReturnAnyoneRightsAsSharee(server: 
GuiceJamesServer): Unit = {
+    val toUser1: String = "touser1@" + DOMAIN.asString
+    val sharedMailboxName: String = "AndreShared"
+    val andreMailboxPath: MailboxPath = MailboxPath.forUser(ANDRE, 
sharedMailboxName)
+    val mailboxId: String = server.getProbe(classOf[MailboxProbeImpl])
+      .createMailbox(andreMailboxPath)
+      .serialize
+
+    server.getProbe(classOf[ACLProbeImpl])
+      .replaceRights(andreMailboxPath, BOB.asString, new 
MailboxACL.Rfc4314Rights(Right.Lookup))
+    server.getProbe(classOf[ACLProbeImpl])
+      .replaceRights(andreMailboxPath, toUser1, new 
MailboxACL.Rfc4314Rights(Right.Lookup))
+    server.getProbe(classOf[ACLProbeImpl])
+      .replaceRights(andreMailboxPath, "anyone", new 
MailboxACL.Rfc4314Rights(Right.Write))
+
+    `given`
+      .header(ACCEPT.toString, ACCEPT_RFC8621_VERSION_HEADER)
+      .body(s"""{
+               |  "using": [
+               |    "urn:ietf:params:jmap:core",
+               |    "urn:ietf:params:jmap:mail",
+               |    "urn:apache:james:params:jmap:mail:shares"],
+               |  "methodCalls": [[
+               |      "Mailbox/get",
+               |      {
+               |        "accountId": 
"29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+               |        "ids": ["${mailboxId}"]
+               |      },
+               |      "c1"]]
+               |}""".stripMargin)
+      .when
+      .post
+      .`then`
+      .statusCode(SC_OK)
+      .body(s"$ARGUMENTS.list", hasSize(1))
+      .body(s"$FIRST_MAILBOX.name", equalTo(sharedMailboxName))
+      .body(s"$FIRST_MAILBOX.rights['${BOB.asString}']", contains(LOOKUP))
+      .body(s"$FIRST_MAILBOX.rights['$toUser1']", nullValue)
+      .body(s"$FIRST_MAILBOX.rights['anyone']", nullValue)
+  }
+
   @Test
   def 
getMailboxesShouldReturnPartiallyAllowedMayPropertiesWhenDelegated(server: 
GuiceJamesServer): Unit = {
     val toUser1: String = "touser1@" + DOMAIN.asString
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 63e07bb3de..d93c732d31 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
@@ -5932,6 +5932,162 @@ trait MailboxSetMethodContract {
          |}""".stripMargin)
   }
 
+  @Test
+  def partialRightsUpdateShouldCorrectlyHandleAnyoneKeyword(server: 
GuiceJamesServer): Unit = {
+    val path = MailboxPath.forUser(BOB, "mailbox")
+    val mailboxId = 
server.getProbe(classOf[MailboxProbeImpl]).createMailbox(path)
+
+    val request =
+      s"""
+         |{
+         |   "using": [ "urn:ietf:params:jmap:core", 
"urn:ietf:params:jmap:mail", "urn:apache:james:params:jmap:mail:shares" ],
+         |   "methodCalls": [
+         |       [
+         |           "Mailbox/set",
+         |           {
+         |                "accountId": 
"29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+         |                "update": {
+         |                    "${mailboxId.serialize}": {
+         |                      "sharedWith/anyone": ["p"]
+         |                    }
+         |                }
+         |           },
+         |    "c1"
+         |       ],
+         |       ["Mailbox/get",
+         |         {
+         |           "accountId": 
"29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+         |           "properties": ["id", "rights"],
+         |           "ids": ["${mailboxId.serialize}"]
+         |          },
+         |       "c2"]
+         |   ]
+         |}
+         |""".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)
+      .whenIgnoringPaths("methodResponses[0][1].newState", 
"methodResponses[0][1].oldState",
+        "methodResponses[1][1].state")
+      .isEqualTo(
+        s"""{
+           |  "sessionState": "${SESSION_STATE.value}",
+           |  "methodResponses": [
+           |    ["Mailbox/set", {
+           |      "accountId": 
"29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+           |      "updated": {
+           |        "${mailboxId.serialize}": {}
+           |      }
+           |    }, "c1"],
+           |    ["Mailbox/get", {
+           |      "accountId": 
"29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+           |      "list": [{
+           |        "id": "${mailboxId.serialize}",
+           |        "rights": {
+           |          "anyone": ["p"]
+           |        }
+           |      }],
+           |      "notFound": []
+           |    }, "c2"]
+           |  ]
+           |}""".stripMargin)
+
+    assertThat(server.getProbe(classOf[ACLProbeImpl]).retrieveRights(path)
+      .getEntries)
+      .containsKey(MailboxACL.ANYONE_KEY)
+  }
+
+  @Test
+  def resetRightsUpdateShouldCorrectlyHandleAnyoneKeyword(server: 
GuiceJamesServer): Unit = {
+    val path = MailboxPath.forUser(BOB, "mailbox")
+    val mailboxId = 
server.getProbe(classOf[MailboxProbeImpl]).createMailbox(path)
+
+    val request =
+      s"""
+         |{
+         |   "using": [ "urn:ietf:params:jmap:core", 
"urn:ietf:params:jmap:mail", "urn:apache:james:params:jmap:mail:shares" ],
+         |   "methodCalls": [
+         |       [
+         |           "Mailbox/set",
+         |           {
+         |                "accountId": 
"29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+         |                "update": {
+         |                    "${mailboxId.serialize}": {
+         |                      "sharedWith": {
+         |                        "anyone":["p"]
+         |                      }
+         |                    }
+         |                }
+         |           },
+         |    "c1"
+         |       ],
+         |       ["Mailbox/get",
+         |         {
+         |           "accountId": 
"29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+         |           "properties": ["id", "rights"],
+         |           "ids": ["${mailboxId.serialize}"]
+         |          },
+         |       "c2"]
+         |   ]
+         |}
+         |""".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)
+      .whenIgnoringPaths("methodResponses[0][1].newState", 
"methodResponses[0][1].oldState",
+        "methodResponses[1][1].state")
+      .isEqualTo(
+        s"""{
+           |  "sessionState": "${SESSION_STATE.value}",
+           |  "methodResponses": [
+           |    ["Mailbox/set", {
+           |      "accountId": 
"29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+           |      "updated": {
+           |        "${mailboxId.serialize}": {}
+           |      }
+           |    }, "c1"],
+           |    ["Mailbox/get", {
+           |      "accountId": 
"29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+           |      "list": [{
+           |        "id": "${mailboxId.serialize}",
+           |        "rights": {
+           |          "anyone": ["p"]
+           |        }
+           |      }],
+           |      "notFound": []
+           |    }, "c2"]
+           |  ]
+           |}""".stripMargin)
+
+    assertThat(server.getProbe(classOf[ACLProbeImpl]).retrieveRights(path)
+      .getEntries)
+      .containsKey(MailboxACL.ANYONE_KEY)
+  }
+
   @Test
   def partialRightsUpdateShouldFailWhenInvalidRights(server: 
GuiceJamesServer): Unit = {
     val path = MailboxPath.forUser(BOB, "mailbox")


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

Reply via email to