JAMES-2219 Integration test about renaming a shared mailbox
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/48979015 Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/48979015 Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/48979015 Branch: refs/heads/master Commit: 48979015080c1215089ac461ecec061bcbdcb156 Parents: 29510c2 Author: Antoine Duprat <[email protected]> Authored: Wed Nov 15 15:32:43 2017 +0100 Committer: Antoine Duprat <[email protected]> Committed: Thu Nov 16 14:19:16 2017 +0100 ---------------------------------------------------------------------- .../mailbox/store/StoreMailboxManager.java | 9 +++ .../cucumber/GetMailboxesMethodStepdefs.java | 2 +- .../cucumber/SetMailboxesMethodStepdefs.java | 29 ++++++- .../resources/cucumber/GetMailboxes.feature | 82 ++++++++++++-------- 4 files changed, 87 insertions(+), 35 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/48979015/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java ---------------------------------------------------------------------- diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java index e76ea91..6a72340 100644 --- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java +++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java @@ -37,6 +37,7 @@ import org.apache.james.mailbox.MailboxPathLocker; import org.apache.james.mailbox.MailboxPathLocker.LockAwareExecution; import org.apache.james.mailbox.MailboxSession; import org.apache.james.mailbox.MailboxSession.SessionType; +import org.apache.james.mailbox.MailboxSession.User; import org.apache.james.mailbox.MailboxSessionIdGenerator; import org.apache.james.mailbox.MessageManager; import org.apache.james.mailbox.StandardMailboxMetaDataComparator; @@ -548,10 +549,18 @@ public class StoreMailboxManager implements MailboxManager { throw new MailboxExistsException(to.toString()); } + assertIsOwner(session.getUser(), from); MailboxMapper mapper = mailboxSessionMapperFactory.getMailboxMapper(session); mapper.execute(Mapper.toTransaction(() -> doRenameMailbox(from, to, session, mapper))); } + private void assertIsOwner(User user, MailboxPath mailboxPath) throws MailboxNotFoundException { + if (!user.isSameUser(mailboxPath.getUser())) { + LOGGER.info("Mailbox " + mailboxPath.asString() + " does not belong to " + user.getUserName()); + throw new MailboxNotFoundException(mailboxPath.asString()); + } + } + private void doRenameMailbox(MailboxPath from, MailboxPath to, MailboxSession session, MailboxMapper mapper) throws MailboxException { // TODO put this into a serilizable transaction Mailbox mailbox = Optional.ofNullable(mapper.findMailboxByPath(from)) http://git-wip-us.apache.org/repos/asf/james-project/blob/48979015/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMailboxesMethodStepdefs.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMailboxesMethodStepdefs.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMailboxesMethodStepdefs.java index 85e9af3..73272cf 100644 --- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMailboxesMethodStepdefs.java +++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMailboxesMethodStepdefs.java @@ -46,7 +46,7 @@ public class GetMailboxesMethodStepdefs { this.httpClient = httpClient; } - @When("^\"([^\"]*)\" ask for mailboxes$") + @When("^\"([^\"]*)\" lists mailboxes$") public void getMailboxes(String user) throws Throwable { userStepdefs.execWithUser(user, () -> httpClient.post("[[\"getMailboxes\", {}, \"#0\"]]")); http://git-wip-us.apache.org/repos/asf/james-project/blob/48979015/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/SetMailboxesMethodStepdefs.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/SetMailboxesMethodStepdefs.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/SetMailboxesMethodStepdefs.java index 3705db7..59c1fbd 100644 --- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/SetMailboxesMethodStepdefs.java +++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/SetMailboxesMethodStepdefs.java @@ -130,9 +130,20 @@ public class SetMailboxesMethodStepdefs { shareMailboxWithRight(owner, mailboxName, rights, shareTo); } - @When("^renaming mailbox \"([^\"]*)\" to \"([^\"]*)\"") - public void renamingMailbox(String actualMailboxName, String newMailboxName) throws Throwable { - Mailbox mailbox = mainStepdefs.mailboxProbe.getMailbox("#private", userStepdefs.getConnectedUser(), actualMailboxName); + @When("^\"([^\"]*)\" renames the mailbox, owned by \"([^\"]*)\", \"([^\"]*)\" to \"([^\"]*)\"$") + public void renamingMailbox(String user, String mailboxOwner, String currentMailboxName, String newMailboxName) throws Throwable { + Mailbox mailbox = mainStepdefs.mailboxProbe.getMailbox("#private", mailboxOwner, currentMailboxName); + userStepdefs.connectUser(user); + renamingMailbox(mailbox, newMailboxName); + } + + @When("^\"([^\"]*)\" renames (?:her|his) mailbox \"([^\"]*)\" to \"([^\"]*)\"$") + public void renamingMailbox(String user, String actualMailboxName, String newMailboxName) throws Throwable { + Mailbox mailbox = mainStepdefs.mailboxProbe.getMailbox("#private", user, actualMailboxName); + renamingMailbox(mailbox, newMailboxName); + } + + private void renamingMailbox(Mailbox mailbox, String newMailboxName) throws Exception { String mailboxId = mailbox.getMailboxId().serialize(); String requestBody = "[" + @@ -150,6 +161,11 @@ public class SetMailboxesMethodStepdefs { httpClient.post(requestBody); } + @When("^renaming mailbox \"([^\"]*)\" to \"([^\"]*)\"") + public void renamingMailbox(String actualMailboxName, String newMailboxName) throws Throwable { + renamingMailbox(userStepdefs.getConnectedUser(), actualMailboxName, newMailboxName); + } + @When("^moving mailbox \"([^\"]*)\" to \"([^\"]*)\"$") public void movingMailbox(String actualMailboxPath, String newParentMailboxPath) throws Throwable { String username = userStepdefs.getConnectedUser(); @@ -206,4 +222,11 @@ public class SetMailboxesMethodStepdefs { assertThat(parameters).contains(Maps.immutableEntry("type", type), Maps.immutableEntry("description", message)); } + + @Then("^mailbox \"([^\"]*)\" owned by \"([^\"]*)\" is not updated") + public void assertNotUpdated(String mailboxName, String owner) throws Exception { + Mailbox mailbox = mainStepdefs.mailboxProbe.getMailbox(MailboxConstants.USER_NAMESPACE, owner, mailboxName); + assertThat(httpClient.jsonPath.<Map<String, String>>read("[0][1].notUpdated")) + .containsOnlyKeys(mailbox.getMailboxId().serialize()); + } } http://git-wip-us.apache.org/repos/asf/james-project/blob/48979015/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/GetMailboxes.feature ---------------------------------------------------------------------- diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/GetMailboxes.feature b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/GetMailboxes.feature index 28f0011..34278c3 100644 --- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/GetMailboxes.feature +++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/GetMailboxes.feature @@ -32,63 +32,63 @@ Feature: GetMailboxes method Scenario: Sharer can read the total and unread counts on a shared folder Given "[email protected]" has a message "m1" in "shared" mailbox And "[email protected]" has a message "m2" in "shared" mailbox with subject "my test subject 2", content "testmail 2" - When "[email protected]" ask for mailboxes + When "[email protected]" lists mailboxes Then the mailbox "shared" has 2 messages And the mailbox "shared" has 2 unseen messages Scenario: Sharee can read the total and unread counts on a shared folder Given "[email protected]" has a message "m1" in "shared" mailbox And "[email protected]" has a message "m2" in "shared" mailbox with subject "my test subject 2", content "testmail 2" - When "[email protected]" ask for mailboxes + When "[email protected]" lists mailboxes Then the mailbox "shared" has 2 messages And the mailbox "shared" has 2 unseen messages Scenario: Copy message should update the total and the unread counts when asked by sharer Given "[email protected]" has a message "m1" in "INBOX" mailbox And "[email protected]" copies "m1" from mailbox "INBOX" to mailbox "shared" - When "[email protected]" ask for mailboxes + When "[email protected]" lists mailboxes Then the mailbox "shared" has 1 message And the mailbox "shared" has 1 unseen message Scenario: Copy message should update the total and the unread counts when asked by sharer / sharee view Given "[email protected]" has a message "m1" in "INBOX" mailbox And "[email protected]" copies "m1" from mailbox "INBOX" to mailbox "shared" - When "[email protected]" ask for mailboxes + When "[email protected]" lists mailboxes Then the mailbox "shared" has 1 message And the mailbox "shared" has 1 unseen message Scenario: Copy message should update the total and the unread counts when asked by sharee Given "[email protected]" has a message "m1" in "bobMailbox" mailbox And "[email protected]" copies "m1" from mailbox "bobMailbox" of user "[email protected]" to mailbox "shared" of user "[email protected]" - When "[email protected]" ask for mailboxes + When "[email protected]" lists mailboxes Then the mailbox "shared" has 1 message And the mailbox "shared" has 1 unseen message Scenario: Copy message should update the total and the unread counts when asked by sharee / sharee view Given "[email protected]" has a message "m1" in "bobMailbox" mailbox And "[email protected]" copies "m1" from mailbox "bobMailbox" of user "[email protected]" to mailbox "shared" of user "[email protected]" - When "[email protected]" ask for mailboxes + When "[email protected]" lists mailboxes Then the mailbox "shared" has 1 message And the mailbox "shared" has 1 unseen message Scenario: Move message should update the total and the unread counts when asked by sharer Given "[email protected]" has a message "m1" in "INBOX" mailbox And "[email protected]" moves "m1" to mailbox "shared" of user "[email protected]" - When "[email protected]" ask for mailboxes + When "[email protected]" lists mailboxes Then the mailbox "shared" has 1 message And the mailbox "shared" has 1 unseen message Scenario: Move message should update the total and the unread counts of origin mailbox when asked by sharer Given "[email protected]" has a message "m1" in "INBOX" mailbox And "[email protected]" moves "m1" to mailbox "shared" of user "[email protected]" - When "[email protected]" ask for mailboxes + When "[email protected]" lists mailboxes Then the mailbox "INBOX" has 0 messages And the mailbox "INBOX" has 0 unseen messages Scenario: Move message should update the total and the unread counts when asked by sharer / sharee view Given "[email protected]" has a message "m1" in "INBOX" mailbox And "[email protected]" moves "m1" to mailbox "shared" of user "[email protected]" - When "[email protected]" ask for mailboxes + When "[email protected]" lists mailboxes Then the mailbox "shared" has 1 message And the mailbox "shared" has 1 unseen message @@ -97,14 +97,14 @@ Feature: GetMailboxes method And "[email protected]" has a message "m1" in "sharedBis" mailbox And "[email protected]" shares her mailbox "sharedBis" with "[email protected]" with "aeilrwt" rights And "[email protected]" moves "m1" to mailbox "shared" of user "[email protected]" - When "[email protected]" ask for mailboxes + When "[email protected]" lists mailboxes Then the mailbox "sharedBis" has 0 messages And the mailbox "sharedBis" has 0 unseen messages Scenario: Move message should update the total and the unread counts when asked by sharee Given "[email protected]" has a message "m1" in "bobMailbox" mailbox And "[email protected]" moves "m1" to mailbox "shared" of user "[email protected]" - When "[email protected]" ask for mailboxes + When "[email protected]" lists mailboxes Then the mailbox "shared" has 1 message And the mailbox "shared" has 1 unseen message @@ -113,21 +113,21 @@ Feature: GetMailboxes method And "[email protected]" has a message "m1" in "sharedBis" mailbox And "[email protected]" shares her mailbox "sharedBis" with "[email protected]" with "aeilrwt" rights And "[email protected]" moves "m1" to mailbox "shared" of user "[email protected]" - When "[email protected]" ask for mailboxes + When "[email protected]" lists mailboxes Then the mailbox "sharedBis" has 0 messages And the mailbox "sharedBis" has 0 unseen messages Scenario: Move message should update the total and the unread counts when asked by sharee / sharee view Given "[email protected]" has a message "m1" in "bobMailbox" mailbox And "[email protected]" moves "m1" to mailbox "shared" of user "[email protected]" - When "[email protected]" ask for mailboxes + When "[email protected]" lists mailboxes Then the mailbox "shared" has 1 message And the mailbox "shared" has 1 unseen message Scenario: Move message should update the total and the unread counts of origin mailbox when asked by sharee / sharee view Given "[email protected]" has a message "m1" in "bobMailbox" mailbox And "[email protected]" moves "m1" to mailbox "shared" of user "[email protected]" - When "[email protected]" ask for mailboxes + When "[email protected]" lists mailboxes Then the mailbox "bobMailbox" has 0 messages And the mailbox "bobMailbox" has 0 unseen messages @@ -136,7 +136,7 @@ Feature: GetMailboxes method And "[email protected]" shares her mailbox "shared2" with "[email protected]" with "lr" rights And "[email protected]" has a message "m1" in "bobMailbox" mailbox And "[email protected]" moves "m1" to mailbox "shared2" of user "[email protected]" - When "[email protected]" ask for mailboxes + When "[email protected]" lists mailboxes Then the mailbox "shared" has 0 messages And the mailbox "shared" has 0 unseen messages @@ -145,28 +145,28 @@ Feature: GetMailboxes method And "[email protected]" shares her mailbox "shared2" with "[email protected]" with "lr" rights And "[email protected]" has a message "m1" in "bobMailbox" mailbox And "[email protected]" moves "m1" to mailbox "shared2" of user "[email protected]" - When "[email protected]" ask for mailboxes + When "[email protected]" lists mailboxes Then the mailbox "shared" has 0 messages And the mailbox "shared" has 0 unseen messages Scenario: Move message should update the total and the unread counts when asked by sharee and seen message Given "[email protected]" has a message "m1" in the "bobMailbox" mailbox with flags "$Seen" And "[email protected]" moves "m1" to mailbox "shared" of user "[email protected]" - When "[email protected]" ask for mailboxes + When "[email protected]" lists mailboxes Then the mailbox "shared" has 1 message And the mailbox "shared" has 0 unseen message Scenario: Move message should update the total and the unread counts when asked by sharee / sharee view and seen message Given "[email protected]" has a message "m1" in the "bobMailbox" mailbox with flags "$Seen" And "[email protected]" moves "m1" to mailbox "shared" of user "[email protected]" - When "[email protected]" ask for mailboxes + When "[email protected]" lists mailboxes Then the mailbox "shared" has 1 message And the mailbox "shared" has 0 unseen message Scenario: Move message should update the total and the unread counts of origin mailbox when asked by sharer and seen message Given "[email protected]" has a message "m1" in the "INBOX" mailbox with flags "$Seen" And "[email protected]" moves "m1" to mailbox "shared" of user "[email protected]" - When "[email protected]" ask for mailboxes + When "[email protected]" lists mailboxes Then the mailbox "INBOX" has 0 messages And the mailbox "INBOX" has 0 unseen messages @@ -175,7 +175,7 @@ Feature: GetMailboxes method And "[email protected]" shares her mailbox "shared2" with "[email protected]" with "lri" rights And "[email protected]" has a message "m1" in the "bobMailbox" mailbox with flags "$Seen" And "[email protected]" moves "m1" to mailbox "shared2" of user "[email protected]" - When "[email protected]" ask for mailboxes + When "[email protected]" lists mailboxes Then the mailbox "shared" has 0 messages And the mailbox "shared" has 0 unseen messages @@ -184,35 +184,35 @@ Feature: GetMailboxes method And "[email protected]" shares her mailbox "shared2" with "[email protected]" with "lri" rights And "[email protected]" has a message "m1" in the "bobMailbox" mailbox with flags "$Seen" And "[email protected]" moves "m1" to mailbox "shared2" of user "[email protected]" - When "[email protected]" ask for mailboxes + When "[email protected]" lists mailboxes Then the mailbox "shared" has 0 messages And the mailbox "shared" has 0 unseen messages Scenario: Set flags by sharer should update unseen count when read by sharer Given "[email protected]" has a message "m1" in "shared" mailbox When "[email protected]" sets flags "$Seen" on message "m1" - When "[email protected]" ask for mailboxes + When "[email protected]" lists mailboxes Then the mailbox "shared" has 1 message And the mailbox "shared" has 0 unseen messages Scenario: Set flags by sharer should update unseen count when read by sharee Given "[email protected]" has a message "m1" in "shared" mailbox When "[email protected]" sets flags "$Seen" on message "m1" - When "[email protected]" ask for mailboxes + When "[email protected]" lists mailboxes Then the mailbox "shared" has 1 message And the mailbox "shared" has 0 unseen messages Scenario: Set flags by sharee should update unseen count when read by sharer Given "[email protected]" has a message "m1" in "shared" mailbox When "[email protected]" sets flags "$Seen" on message "m1" - When "[email protected]" ask for mailboxes + When "[email protected]" lists mailboxes Then the mailbox "shared" has 1 message And the mailbox "shared" has 0 unseen messages Scenario: Set flags by sharee should update unseen count when read by sharee Given "[email protected]" has a message "m1" in "shared" mailbox When "[email protected]" sets flags "$Seen" on message "m1" - When "[email protected]" ask for mailboxes + When "[email protected]" lists mailboxes Then the mailbox "shared" has 1 message And the mailbox "shared" has 0 unseen messages @@ -221,7 +221,7 @@ Feature: GetMailboxes method And "[email protected]" shares her mailbox "shared2" with "[email protected]" with "lri" rights And "[email protected]" has a message "m1" in "shared2" mailbox When "[email protected]" sets flags "$Seen" on message "m1" - When "[email protected]" ask for mailboxes + When "[email protected]" lists mailboxes Then the mailbox "shared2" has 1 message And the mailbox "shared2" has 1 unseen message @@ -230,7 +230,7 @@ Feature: GetMailboxes method And "[email protected]" shares her mailbox "shared2" with "[email protected]" with "lri" rights And "[email protected]" has a message "m1" in "shared2" mailbox When "[email protected]" sets flags "$Seen" on message "m1" - When "[email protected]" ask for mailboxes + When "[email protected]" lists mailboxes Then the mailbox "shared2" has 1 message And the mailbox "shared2" has 1 unseen message @@ -238,7 +238,7 @@ Feature: GetMailboxes method Given "[email protected]" has a mailbox "shared2" And "[email protected]" shares her mailbox "shared2" with "[email protected]" with "l" rights And "[email protected]" has a message "m1" in "shared2" mailbox - When "[email protected]" ask for mailboxes + When "[email protected]" lists mailboxes Then the mailbox "shared2" has 0 messages And the mailbox "shared2" has 0 unseen messages @@ -246,7 +246,7 @@ Feature: GetMailboxes method Given "[email protected]" has a mailbox "mailbox1" And "[email protected]" has a mailbox "mailbox1.shared" And "[email protected]" shares her mailbox "mailbox1.shared" with "[email protected]" with "aeirwt" rights - When "[email protected]" ask for mailboxes + When "[email protected]" lists mailboxes Then the mailboxes should contain "shared" in "Delegated" namespace And the mailboxes should not contain "mailbox1" @@ -254,6 +254,26 @@ Feature: GetMailboxes method Given "[email protected]" has a mailbox "mailbox1" And "[email protected]" has a mailbox "mailbox1.shared" And "[email protected]" shares her mailbox "mailbox1.shared" with "[email protected]" with "l" rights - When "[email protected]" ask for mailboxes + When "[email protected]" lists mailboxes Then the mailboxes should contain "shared" in "Delegated" namespace - And the mailboxes should contain "mailbox1" in "Delegated" namespace \ No newline at end of file + And the mailboxes should contain "mailbox1" in "Delegated" namespace + + Scenario: A sharee should be able to access a shared mailbox after it has been renamed by the owner + Given "[email protected]" renames her mailbox "shared" to "mySharedMailbox" + When "[email protected]" lists mailboxes + Then the mailboxes should contain "mySharedMailbox" in "Delegated" namespace + + Scenario: A sharee should not be able to rename a shared mailbox + Given "[email protected]" renames the mailbox, owned by "[email protected]", "shared" to "mySharedMailbox" + When "[email protected]" lists mailboxes + Then the mailboxes should contain "shared" in "Personal" namespace + + Scenario: A user should not be able to rename an other user mailbox + Given "[email protected]" has a mailbox "mySecrets" + And "[email protected]" renames the mailbox, owned by "[email protected]", "mySecrets" to "revealMySecrets" + When "[email protected]" lists mailboxes + Then the mailboxes should contain "mySecrets" in "Personal" namespace + + Scenario: A sharee should receive a not updated response when trying to rename a shared mailbox + Given "[email protected]" renames the mailbox, owned by "[email protected]", "shared" to "mySharedMailbox" + Then mailbox "shared" owned by "[email protected]" is not updated --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
