Skip to content

Commit

Permalink
JAMES-2195 Allow fine grained right delegation with Cucumber
Browse files Browse the repository at this point in the history
  • Loading branch information
chibenwa authored and aduprat committed Oct 26, 2017
1 parent f9ab357 commit 940b85f
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public static Rfc4314Rights fromSerializedRfc4314Rights(String serializedRfc4314
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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
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;
Expand All @@ -43,18 +44,18 @@ public void createMailbox(String username, String mailbox) throws Throwable {
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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public void createConnectedUser(String username) throws Throwable {
createUser(username);
connectUser(username);
}

@Given("^\"([^\"]*)\" is connected$")
public void connectUser(String username) throws Throwable {
AccessToken accessToken = authenticate(username);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 "usera@domain.tld" shares its mailbox "INBOX" with "userb@domain.tld"
Given "usera@domain.tld" shares his mailbox "INBOX" with "userb@domain.tld" with "lr" rights
And "userb@domain.tld" is connected
When "userb@domain.tld" downloads "a1"
Then the user should be authorized
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,26 +83,26 @@ Feature: Download GET

Scenario: User can download attachment of another user when shared mailbox
Given "alice@domain.tld" mailbox "sharedMailbox" contains a message "1" with an attachment "2"
And "alice@domain.tld" shares its mailbox "sharedMailbox" with "bob@domain.tld"
And "alice@domain.tld" shares her mailbox "sharedMailbox" with "bob@domain.tld" with "lr" rights
When "bob@domain.tld" 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 "alice@domain.tld" mailbox "sharedMailbox" contains a message "1" with an attachment "2"
And "alice@domain.tld" shares its mailbox "sharedMailbox" with "bob@domain.tld"
And "alice@domain.tld" shares her mailbox "sharedMailbox" with "bob@domain.tld" with "lr" rights
When "bob@domain.tld" downloads "1"
Then he can read that blob
And the blob size is 4963

Scenario: Attachment read delegation should be user specific
Given "alice@domain.tld" mailbox "sharedMailbox" contains a message "1" with an attachment "2"
And "alice@domain.tld" shares its mailbox "sharedMailbox" with "bob@domain.tld"
And "alice@domain.tld" shares her mailbox "sharedMailbox" with "bob@domain.tld" with "lr" rights
When "cedric@domain.tld" downloads "1"
Then "cedric@domain.tld" should receive a not found response

Scenario: Message download read delegation should be user specific
Given "alice@domain.tld" mailbox "sharedMailbox" contains a message "1" with an attachment "2"
And "alice@domain.tld" shares its mailbox "sharedMailbox" with "bob@domain.tld"
And "alice@domain.tld" shares her mailbox "sharedMailbox" with "bob@domain.tld" with "lr" rights
When "cedric@domain.tld" downloads "2"
Then "cedric@domain.tld" should receive a not found response
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Feature: GetMessages method

Scenario: Retrieving a message in a mailbox delegated to me
Given "alice@domain.tld" has a mailbox "shared"
And "alice@domain.tld" shares its mailbox "shared" with "bob@domain.tld"
And "alice@domain.tld" shares her mailbox "shared" with "bob@domain.tld" with "lr" rights
And "alice@domain.tld" has a message "m1" in "shared" mailbox with subject "my test subject", content "testmail"
When "bob@domain.tld" ask for messages "m1"
Then no error is returned
Expand All @@ -48,7 +48,7 @@ Feature: GetMessages method

Scenario: Retrieving a message in a mailbox delegated to someone else
Given "alice@domain.tld" has a mailbox "shared"
And "alice@domain.tld" shares its mailbox "shared" with "bob@domain.tld"
And "alice@domain.tld" shares her mailbox "shared" with "bob@domain.tld" with "lr" rights
And "alice@domain.tld" has a message "m1" in "shared" mailbox with subject "my test subject", content "testmail"
When "cedric@domain.tld" ask for messages "m1"
Then no error is returned
Expand Down

0 comments on commit 940b85f

Please sign in to comment.