JAMES-2195 Allow fine grained right delegation with Cucumber

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

Branch: refs/heads/master
Commit: 940b85f37d2dc69bb993440dc8da99f0c175cb72
Parents: f9ab357
Author: benwa <[email protected]>
Authored: Thu Oct 19 16:07:19 2017 +0700
Committer: Antoine Duprat <[email protected]>
Committed: Thu Oct 26 08:44:41 2017 +0200

----------------------------------------------------------------------
 .../org/apache/james/mailbox/model/MailboxACL.java |  2 +-
 .../integration/cucumber/MailboxStepdefs.java      | 17 +++++++++--------
 .../methods/integration/cucumber/UserStepdefs.java |  2 +-
 .../resources/cucumber/DownloadEndpoint.feature    |  2 +-
 .../test/resources/cucumber/DownloadGet.feature    |  8 ++++----
 .../test/resources/cucumber/GetMessages.feature    |  4 ++--
 6 files changed, 18 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/940b85f3/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxACL.java
----------------------------------------------------------------------
diff --git 
a/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxACL.java 
b/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxACL.java
index cf22364..934caa1 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxACL.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxACL.java
@@ -198,7 +198,7 @@ public class MailboxACL {
             return new 
Rfc4314Rights(rightListFromSerializedRfc4314Rights(serializedRfc4314Rights));
         }
 
-        private static List<Right> rightListFromSerializedRfc4314Rights(String 
serializedRfc4314Rights) throws UnsupportedRightException {
+        public static List<Right> rightListFromSerializedRfc4314Rights(String 
serializedRfc4314Rights) throws UnsupportedRightException {
             return serializedRfc4314Rights.chars()
                 .mapToObj(i -> (char) i)
                 
.flatMap(Throwing.function(Rfc4314Rights::convert).sneakyThrow())

http://git-wip-us.apache.org/repos/asf/james-project/blob/940b85f3/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/MailboxStepdefs.java
----------------------------------------------------------------------
diff --git 
a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/MailboxStepdefs.java
 
b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/MailboxStepdefs.java
index 00b3e40..fca2cb9 100644
--- 
a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/MailboxStepdefs.java
+++ 
b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/MailboxStepdefs.java
@@ -24,6 +24,7 @@ import javax.inject.Inject;
 import org.apache.james.mailbox.model.MailboxACL;
 import org.apache.james.mailbox.model.MailboxConstants;
 import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.modules.ACLProbeImpl;
 
 import cucumber.api.java.en.Given;
 import cucumber.runtime.java.guice.ScenarioScoped;
@@ -43,18 +44,18 @@ public class MailboxStepdefs {
         
mainStepdefs.mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, 
username, mailbox);
     }
 
-    @Given("^\"([^\"]*)\" shares its mailbox \"([^\"]*)\" with \"([^\"]*)\"$")
-    public void shareMailbox(String owner, String mailbox, String shareTo) 
throws Throwable {
-        MailboxPath mailboxPath = MailboxPath.forUser(owner, mailbox);
-        MailboxACL.Rfc4314Rights rights = new 
MailboxACL.Rfc4314Rights(MailboxACL.Right.Lookup, MailboxACL.Right.Read);
-
-        mainStepdefs.aclProbe.addRights(mailboxPath, shareTo, rights);
-    }
-
     @Given("^\"([^\"]*)\" shares its mailbox \"([^\"]*)\" with rights 
\"([^\"]*)\" with \"([^\"]*)\"$")
     public void shareMailboxWithRight(String owner, String mailbox, String 
rights, String shareTo) throws Throwable {
         MailboxPath mailboxPath = MailboxPath.forUser(owner, mailbox);
 
         mainStepdefs.aclProbe.replaceRights(mailboxPath, shareTo, 
MailboxACL.Rfc4314Rights.fromSerializedRfc4314Rights(rights));
     }
+    
+    @Given("^\"([^\"]*)\" shares (?:his|her) mailbox \"([^\"]*)\" with 
\"([^\"]*)\" with \"([^\"]*)\" rights$")
+    public void shareMailbox(String owner, String mailbox, String shareTo, 
String rights) throws Throwable {
+        mainStepdefs.jmapServer.getProbe(ACLProbeImpl.class)
+            .replaceRights(MailboxPath.forUser(owner, mailbox),
+                shareTo,
+                MailboxACL.Rfc4314Rights.fromSerializedRfc4314Rights(rights));
+    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/940b85f3/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/UserStepdefs.java
----------------------------------------------------------------------
diff --git 
a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/UserStepdefs.java
 
b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/UserStepdefs.java
index 2ef61e4..fa26e2f 100644
--- 
a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/UserStepdefs.java
+++ 
b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/UserStepdefs.java
@@ -110,7 +110,7 @@ public class UserStepdefs {
         createUser(username);
         connectUser(username);
     }
-    
+
     @Given("^\"([^\"]*)\" is connected$")
     public void connectUser(String username) throws Throwable {
         AccessToken accessToken = authenticate(username);

http://git-wip-us.apache.org/repos/asf/james-project/blob/940b85f3/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/DownloadEndpoint.feature
----------------------------------------------------------------------
diff --git 
a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/DownloadEndpoint.feature
 
b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/DownloadEndpoint.feature
index 979907d..ea41c5d 100644
--- 
a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/DownloadEndpoint.feature
+++ 
b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/DownloadEndpoint.feature
@@ -86,7 +86,7 @@ Feature: Download endpoint
     Then the user should receive a not found response
 
   Scenario: An authenticated user should have access to a shared attachment
-    Given "[email protected]" shares its mailbox "INBOX" with "[email protected]"
+    Given "[email protected]" shares his mailbox "INBOX" with 
"[email protected]" with "lr" rights
     And "[email protected]" is connected
     When "[email protected]" downloads "a1"
     Then the user should be authorized

http://git-wip-us.apache.org/repos/asf/james-project/blob/940b85f3/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/DownloadGet.feature
----------------------------------------------------------------------
diff --git 
a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/DownloadGet.feature
 
b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/DownloadGet.feature
index 662f3e9..9a69fa7 100644
--- 
a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/DownloadGet.feature
+++ 
b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/DownloadGet.feature
@@ -83,26 +83,26 @@ Feature: Download GET
 
   Scenario: User can download attachment of another user when shared mailbox
     Given "[email protected]" mailbox "sharedMailbox" contains a message "1" 
with an attachment "2"
-    And "[email protected]" shares its mailbox "sharedMailbox" with 
"[email protected]"
+    And "[email protected]" shares her mailbox "sharedMailbox" with 
"[email protected]" with "lr" rights
     When "[email protected]" downloads "2"
     Then he can read that blob
     And the blob size is 3071
 
   Scenario: User can download message blob of another user when shared mailbox
     Given "[email protected]" mailbox "sharedMailbox" contains a message "1" 
with an attachment "2"
-    And "[email protected]" shares its mailbox "sharedMailbox" with 
"[email protected]"
+    And "[email protected]" shares her mailbox "sharedMailbox" with 
"[email protected]" with "lr" rights
     When "[email protected]" downloads "1"
     Then he can read that blob
     And the blob size is 4963
 
   Scenario: Attachment read delegation should be user specific
     Given "[email protected]" mailbox "sharedMailbox" contains a message "1" 
with an attachment "2"
-    And "[email protected]" shares its mailbox "sharedMailbox" with 
"[email protected]"
+    And "[email protected]" shares her mailbox "sharedMailbox" with 
"[email protected]" with "lr" rights
     When "[email protected]" downloads "1"
     Then "[email protected]" should receive a not found response
 
   Scenario: Message download read delegation should be user specific
     Given "[email protected]" mailbox "sharedMailbox" contains a message "1" 
with an attachment "2"
-    And "[email protected]" shares its mailbox "sharedMailbox" with 
"[email protected]"
+    And "[email protected]" shares her mailbox "sharedMailbox" with 
"[email protected]" with "lr" rights
     When "[email protected]" downloads "2"
     Then "[email protected]" should receive a not found response
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/james-project/blob/940b85f3/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/GetMessages.feature
----------------------------------------------------------------------
diff --git 
a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/GetMessages.feature
 
b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/GetMessages.feature
index 23bc2a9..82d6459 100644
--- 
a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/GetMessages.feature
+++ 
b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/GetMessages.feature
@@ -39,7 +39,7 @@ Feature: GetMessages method
 
   Scenario: Retrieving a message in a mailbox delegated to me
     Given "[email protected]" has a mailbox "shared"
-    And "[email protected]" shares its mailbox "shared" with "[email protected]"
+    And "[email protected]" shares her mailbox "shared" with "[email protected]" 
with "lr" rights
     And "[email protected]" has a message "m1" in "shared" mailbox with subject 
"my test subject", content "testmail"
     When "[email protected]" ask for messages "m1"
     Then no error is returned
@@ -48,7 +48,7 @@ Feature: GetMessages method
 
   Scenario: Retrieving a message in a mailbox delegated to someone else
     Given "[email protected]" has a mailbox "shared"
-    And "[email protected]" shares its mailbox "shared" with "[email protected]"
+    And "[email protected]" shares her mailbox "shared" with "[email protected]" 
with "lr" rights
     And "[email protected]" has a message "m1" in "shared" mailbox with subject 
"my test subject", content "testmail"
     When "[email protected]" ask for messages "m1"
     Then no error is returned


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to