JAMES-2249 add cucumber scenario for JMAP sharing with subfolder

This commit add a integration test in JMAP to check that sharee can read shared
folder without having access of subfolder that are not shared of this folder.


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/325df63c
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/325df63c
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/325df63c

Branch: refs/heads/master
Commit: 325df63c5eb34b892b4ab73fe228e75fc051c9b8
Parents: 3bb571b
Author: Luc DUZAN <ldu...@linagora.com>
Authored: Thu Dec 7 09:28:25 2017 +0100
Committer: Antoine Duprat <adup...@linagora.com>
Committed: Tue Dec 12 15:12:35 2017 +0100

----------------------------------------------------------------------
 ...arentMailboxWithAndWhithoutChildrenTest.java |  44 ++++++++
 .../cucumber/GetMailboxesMethodStepdefs.java    |  15 +++
 .../cucumber/GetMessageListMethodStepdefs.java  |  42 +++++++-
 ...gParentMailboxWithAndWithoutChildren.feature | 105 +++++++++++++++++++
 ...ParentMailboxWithAndWithoutChildrenTest.java |  32 ++++++
 5 files changed, 236 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/325df63c/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/cucumber/CassandraSharingParentMailboxWithAndWhithoutChildrenTest.java
----------------------------------------------------------------------
diff --git 
a/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/cucumber/CassandraSharingParentMailboxWithAndWhithoutChildrenTest.java
 
b/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/cucumber/CassandraSharingParentMailboxWithAndWhithoutChildrenTest.java
new file mode 100644
index 0000000..67ba269
--- /dev/null
+++ 
b/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/cucumber/CassandraSharingParentMailboxWithAndWhithoutChildrenTest.java
@@ -0,0 +1,44 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.jmap.cassandra.cucumber;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.runner.RunWith;
+
+import cucumber.api.CucumberOptions;
+import cucumber.api.junit.Cucumber;
+
+@RunWith(Cucumber.class)
+@CucumberOptions(features="classpath:cucumber/SharingParentMailboxWithAndWithoutChildren.feature",
+    glue={"org.apache.james.jmap.methods.integration", 
"org.apache.james.jmap.cassandra.cucumber"},
+    strict = true)
+public class CassandraSharingParentMailboxWithAndWhithoutChildrenTest {
+
+    @BeforeClass
+    public static void init() {
+        CucumberCassandraSingleton.cassandraServer.start();
+    }
+
+    @AfterClass
+    public static void after() {
+        CucumberCassandraSingleton.cassandraServer.stop();
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/325df63c/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 677ebfa..3f94b85 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
@@ -77,6 +77,13 @@ public class GetMailboxesMethodStepdefs {
             .containsOnly(namespace);
     }
 
+    @Then("^the mailboxes should not contain \"([^\"]*)\" in \"([^\"]*)\" 
namespace$")
+    public void assertNotMailboxesNames(String mailboxName, String namespace) 
throws Exception {
+        assertThat(httpClient.jsonPath.<List<String>>read(ARGUMENTS + 
".list[?].namespace.type",
+            filter(where("name").is(mailboxName))))
+            .doesNotContain(namespace);
+    }
+
     @Then("^the mailboxes should contain \"([^\"]*)\" in \"([^\"]*)\" 
namespace, with parent mailbox \"([^\"]*)\" of user \"([^\"]*)\"$")
     public void assertMailboxesNames(String mailboxName, String namespace, 
String parentName, String parentOwner) throws Exception {
         Mailbox parentMailbox = 
mainStepdefs.mailboxProbe.getMailbox(MailboxConstants.USER_NAMESPACE, 
parentOwner, parentName);
@@ -89,6 +96,14 @@ public class GetMailboxesMethodStepdefs {
             .containsOnly(parentMailbox.getMailboxId().serialize());
     }
 
+    @Then("^the mailboxes should not contain \"([^\"]*)\" in \"([^\"]*)\" 
namespace, with parent mailbox \"([^\"]*)\" of user \"([^\"]*)\"$")
+    public void assertNotMailboxesNames(String mailboxName, String namespace, 
String parentName, String parentOwner) throws Exception {
+        Mailbox parentMailbox = 
mainStepdefs.mailboxProbe.getMailbox(MailboxConstants.USER_NAMESPACE, 
parentOwner, parentName);
+        assertThat(httpClient.jsonPath.<List<String>>read(ARGUMENTS + 
".list[?].parentId",
+            
filter(where("name").is(mailboxName).and("namespace.type").is(namespace))))
+            .doesNotContain(parentMailbox.getMailboxId().serialize());
+    }
+
     @Then("^the mailboxes should contain \"([^\"]*)\" in \"([^\"]*)\" 
namespace, with no parent mailbox$")
     public void assertMailboxesNamesNoParent(String mailboxName, String 
namespace) throws Exception {
         ArrayList<Object> noParent = new ArrayList<>();

http://git-wip-us.apache.org/repos/asf/james-project/blob/325df63c/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMessageListMethodStepdefs.java
----------------------------------------------------------------------
diff --git 
a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMessageListMethodStepdefs.java
 
b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMessageListMethodStepdefs.java
index d4de2ec..3e97ab1 100644
--- 
a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMessageListMethodStepdefs.java
+++ 
b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMessageListMethodStepdefs.java
@@ -44,16 +44,18 @@ public class GetMessageListMethodStepdefs {
     private final MainStepdefs mainStepdefs;
     private final HttpClient httpClient;
     private final MessageIdStepdefs messageIdStepdefs;
+    private final UserStepdefs userStepdefs;
 
     @Inject
-    private GetMessageListMethodStepdefs(MainStepdefs mainStepdefs, HttpClient 
httpClient, MessageIdStepdefs messageIdStepdefs) {
+    private GetMessageListMethodStepdefs(MainStepdefs mainStepdefs, HttpClient 
httpClient, MessageIdStepdefs messageIdStepdefs, UserStepdefs userStepdefs) {
         this.mainStepdefs = mainStepdefs;
         this.httpClient = httpClient;
         this.messageIdStepdefs = messageIdStepdefs;
+        this.userStepdefs = userStepdefs;
     }
 
     @When("^\"([^\"]*)\" asks for message list in mailboxes \"([^\"]*)\" with 
flag \"([^\"]*)\"$")
-    public void getMessageList(String username, List<String> mailboxes, String 
flag) throws Exception {
+    public void getMessageListWithFlag(String username, List<String> 
mailboxes, String flag) throws Exception {
         String mailboxIds = Joiner.on("\",\"")
             .join(mailboxes.stream()
                 .map(mailbox -> mainStepdefs.jmapServer
@@ -72,6 +74,42 @@ public class GetMessageListMethodStepdefs {
             flag));
     }
 
+    @When("^\"([^\"]*)\" asks for message list in (?:mailboxes|mailbox) 
\"([^\"]*)\"$")
+    public void getMessageList(String username, List<String> mailboxes) throws 
Exception {
+        String mailboxIds = Joiner.on("\",\"")
+            .join(mailboxes.stream()
+                .map(mailbox -> mainStepdefs.jmapServer
+                    .getProbe(MailboxProbeImpl.class)
+                    .getMailbox(MailboxConstants.USER_NAMESPACE, username, 
mailbox)
+                    .getMailboxId()
+                    .serialize())
+                .collect(Guavate.toImmutableList()));
+
+        getMessageListFromMailboxIds(mailboxIds);
+    }
+
+    @When("^\"([^\"]*)\" asks for message list in delegated 
(?:mailboxes|mailbox) \"([^\"]*)\" from \"([^\"]*)\"$")
+    public void getMessageListFromDelegated(String sharee, List<String> 
mailboxes, String sharer) throws Exception {
+        String mailboxIds = Joiner.on("\",\"")
+            .join(mailboxes.stream()
+                .map(mailbox -> mainStepdefs.jmapServer
+                    .getProbe(MailboxProbeImpl.class)
+                    .getMailbox(MailboxConstants.USER_NAMESPACE, sharer, 
mailbox)
+                    .getMailboxId()
+                    .serialize())
+                .collect(Guavate.toImmutableList()));
+
+        userStepdefs.execWithUser(sharee, () -> 
getMessageListFromMailboxIds(mailboxIds));
+    }
+
+    private void getMessageListFromMailboxIds(String mailboxIds) throws 
Exception {
+        httpClient.post(String.format(
+            "[[\"getMessageList\", {\"filter\":{" +
+                "    \"inMailboxes\":[\"%s\"]" +
+                "}}, \"#0\"]]",
+            mailboxIds));
+    }
+
     @When("^\"([^\"]*)\" asks for message list in mailbox \"([^\"]*)\" with 
flag \"([^\"]*)\"$")
     public void getMessageList(String username, String mailbox, String flag) 
throws Exception {
         MailboxId mailboxId = mainStepdefs.jmapServer

http://git-wip-us.apache.org/repos/asf/james-project/blob/325df63c/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/SharingParentMailboxWithAndWithoutChildren.feature
----------------------------------------------------------------------
diff --git 
a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/SharingParentMailboxWithAndWithoutChildren.feature
 
b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/SharingParentMailboxWithAndWithoutChildren.feature
new file mode 100644
index 0000000..4c6e6b8
--- /dev/null
+++ 
b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/SharingParentMailboxWithAndWithoutChildren.feature
@@ -0,0 +1,105 @@
+#***************************************************************
+# Licensed to the Apache Software Foundation (ASF) under one   *
+# or more contributor license agreements.  See the NOTICE file *
+# distributed with this work for additional information        *
+# regarding copyright ownership.  The ASF licenses this file   *
+# to you under the Apache License, Version 2.0 (the            *
+# "License"); you may not use this file except in compliance   *
+# with the License.  You may obtain a copy of the License at   *
+#                                                              *
+#   http://www.apache.org/licenses/LICENSE-2.0                 *
+#                                                              *
+# Unless required by applicable law or agreed to in writing,   *
+# software distributed under the License is distributed on an  *
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+# KIND, either express or implied.  See the License for the    *
+# specific language governing permissions and limitations      *
+# under the License.                                           *
+# **************************************************************/
+
+Feature: Share parent mailbox without sharing submailbox
+  As a James user
+  I want to be able to retrieve my mailboxes
+
+  Background:
+    Given a domain named "domain.tld"
+    And a user "al...@domain.tld"
+    And a user "b...@domain.tld"
+    And "al...@domain.tld" has a mailbox "shared"
+    And "al...@domain.tld" has a mailbox "shared.secret"
+    And "al...@domain.tld" has a mailbox "shared.notsecret"
+    And "al...@domain.tld" shares her mailbox "shared" with "b...@domain.tld" 
with "aeilrwt" rights
+    And "al...@domain.tld" shares her mailbox "shared.notsecret" with 
"b...@domain.tld" with "aeilrwt" rights
+    And "al...@domain.tld" has a message "m1" in "shared" mailbox
+    And "al...@domain.tld" has a message "m2" in "shared.secret" mailbox
+    And "al...@domain.tld" has a message "m3" in "shared.notsecret" mailbox
+
+  Scenario: Bob can see shared mailbox and explicitly shared children mailbox
+    When "b...@domain.tld" lists mailboxes
+    Then the mailboxes should contain "shared" in "Delegated" namespace
+    And the mailboxes should contain "notsecret" in "Delegated" namespace, 
with parent mailbox "shared" of user "al...@domain.tld"
+    And the mailbox "shared" has 1 messages
+    And the mailbox "notsecret" has 1 messages
+
+  Scenario: Bob can not see not explicitly shared children mailbox
+    When "b...@domain.tld" lists mailboxes
+    And the mailboxes should not contain "shared.secret" in "Delegated" 
namespace
+    And the mailboxes should not contain "secret" in "Personal" namespace
+    And the mailboxes should not contain "secret" in "Delegated" namespace, 
with parent mailbox "shared" of user "al...@domain.tld"
+
+  Scenario: Alice can see all her shared mailbox
+    When "al...@domain.tld" lists mailboxes
+    And the mailboxes should contain "shared" in "Personal" namespace
+    And the mailboxes should contain "notsecret" in "Personal" namespace, with 
parent mailbox "shared" of user "al...@domain.tld"
+    And the mailbox "shared" has 1 messages
+    And the mailbox "notsecret" has 1 messages
+
+  Scenario: Alice can see all her not shared mailbox
+    When "al...@domain.tld" lists mailboxes
+    And the mailboxes should contain "secret" in "Personal" namespace, with 
parent mailbox "shared" of user "al...@domain.tld"
+    And the mailbox "secret" has 1 messages
+
+  Scenario: Alice can get message from her shared mailbox
+    When "al...@domain.tld" ask for messages "m1"
+    Then no error is returned
+    And the list should contain 1 message
+    When "al...@domain.tld" ask for messages "m3"
+    Then no error is returned
+    And the list should contain 1 message
+
+  Scenario: Alice can get message from her not shared mailbox
+    When "al...@domain.tld" ask for messages "m2"
+    Then no error is returned
+    And the list should contain 1 message
+
+  Scenario: Bob can get message from all his shared mailbox
+    When "b...@domain.tld" ask for messages "m1"
+    Then no error is returned
+    And the list should contain 1 message
+    When "b...@domain.tld" ask for messages "m3"
+    Then no error is returned
+    And the list should contain 1 message
+
+  Scenario: Bob can not get message from mailbox not shared with him
+    When "b...@domain.tld" ask for messages "m2"
+    And the list should contain 0 message
+
+  Scenario: Alice can list message from all her shared mailbox
+    When "al...@domain.tld" asks for message list in mailbox "shared"
+    Then the message list has size 1
+    When "al...@domain.tld" asks for message list in mailbox "shared.notsecret"
+    Then the message list has size 1
+
+  Scenario: Alice can list message from all her mailbox she is not sharing
+    When "al...@domain.tld" asks for message list in mailbox "shared.secret"
+    Then the message list has size 1
+
+  Scenario: Bob can list message from all mailbox that are shared to him
+    When "b...@domain.tld" asks for message list in delegated mailbox "shared" 
from "al...@domain.tld"
+    Then the message list has size 1
+    When "b...@domain.tld" asks for message list in delegated mailbox 
"shared.notsecret" from "al...@domain.tld"
+    Then the message list has size 1
+
+  Scenario: Bob can not list message from mailbox that are not shared to him
+    When "b...@domain.tld" asks for message list in delegated mailbox 
"shared.secret" from "al...@domain.tld"
+    Then the message list has size 0

http://git-wip-us.apache.org/repos/asf/james-project/blob/325df63c/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/cucumber/MemorySharingParentMailboxWithAndWithoutChildrenTest.java
----------------------------------------------------------------------
diff --git 
a/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/cucumber/MemorySharingParentMailboxWithAndWithoutChildrenTest.java
 
b/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/cucumber/MemorySharingParentMailboxWithAndWithoutChildrenTest.java
new file mode 100644
index 0000000..312d4fd
--- /dev/null
+++ 
b/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/cucumber/MemorySharingParentMailboxWithAndWithoutChildrenTest.java
@@ -0,0 +1,32 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.jmap.memory.cucumber;
+
+import org.junit.runner.RunWith;
+
+import cucumber.api.CucumberOptions;
+import cucumber.api.junit.Cucumber;
+
+@RunWith(Cucumber.class)
+@CucumberOptions(features="classpath:cucumber/SharingParentMailboxWithAndWithoutChildren.feature",
+    glue={"org.apache.james.jmap.methods.integration", 
"org.apache.james.jmap.memory.cucumber"},
+    strict = true)
+public class MemorySharingParentMailboxWithAndWithoutChildrenTest {
+}


---------------------------------------------------------------------
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