private static Map<EntryKey, Rfc4314Rights> toMap(Properties props) throws UnsupportedRightException { ImmutableMap.Builder<EntryKey, Rfc4314Rights> builder = ImmutableMap.builder(); if (props != null) { for (Map.Entry<?, ?> prop : props.entrySet()) { builder.put(EntryKey.deserialize((String) prop.getKey()), Rfc4314Rights.fromSerializedRfc4314Rights((String) prop.getValue())); } } return builder.build(); }
private String rightsAsString(String rights) throws UnsupportedRightException { return MailboxACL.Rfc4314Rights .fromSerializedRfc4314Rights(rights) .list() .stream() .map(MailboxACL.Right::asCharacter) .map(String::valueOf) .map(this::surroundWithDoubleQuotes) .collect(Collectors.joining(", ", "[ ", " ]")); }
@Test public void rfc4314RightsShouldThrowWhenUnknownFlag() throws UnsupportedRightException { assertThatThrownBy(() -> Rfc4314Rights.fromSerializedRfc4314Rights("z")) .isInstanceOf(UnsupportedRightException.class); }
@Test public void rightTShouldBeNeededToPerformCopyOfDeletedMessageUS() throws Exception { scriptedTestProtocol .withGrantRights(OTHER_USER_MAILBOX, USER, MailboxACL.Rfc4314Rights.fromSerializedRfc4314Rights("rispxwlake")) .withFilledMailbox(MY_INBOX) .run("aclIntegration/ACLIntegrationCopyWithoutT"); } }
@Test public void rightWShouldBeNeededToPerformCopyOfFlaggedMessageUS() throws Exception { scriptedTestProtocol .withGrantRights(OTHER_USER_MAILBOX, USER, MailboxACL.Rfc4314Rights.fromSerializedRfc4314Rights("rispxtcdlake")) .withFilledMailbox(MY_INBOX) .run("aclIntegration/ACLIntegrationCopyWithoutW"); }
@Test public void rightIWShouldBeSufficientToPerformAppendOfDeletedMessageUS() throws Exception { scriptedTestProtocol .withGrantRights(OTHER_USER_MAILBOX, USER, MailboxACL.Rfc4314Rights.fromSerializedRfc4314Rights("riw")) .run("aclIntegration/ACLIntegrationRightIW"); }
@Test public void rightIShouldBeSufficientToPerformAppendUS() throws Exception { scriptedTestProtocol .withGrantRights(OTHER_USER_MAILBOX, USER, MailboxACL.Rfc4314Rights.fromSerializedRfc4314Rights("ri")) .run("aclIntegration/ACLIntegrationRightI"); }
@Test public void rightKOnDestinationShouldBeSufficientToRenameAMailboxUS() throws Exception { MailboxPath newMailbox = MailboxPath.forUser(USER, "test"); scriptedTestProtocol .withMailbox(newMailbox) .withGrantRights(newMailbox, USER, MailboxACL.Rfc4314Rights.fromSerializedRfc4314Rights("x")) .withGrantRights(OTHER_USER_MAILBOX, USER, MailboxACL.Rfc4314Rights.fromSerializedRfc4314Rights("k")) .run("aclIntegration/ACLIntegrationRightK"); }
@Test public void rightXOnOriginShouldBeSufficientToRenameAMailboxUS() throws Exception { scriptedTestProtocol .withMailbox(MailboxPath.forUser("Boby","test")) .withGrantRights(MailboxPath.forUser(OTHER_USER_NAME, "test"), USER, MailboxACL.Rfc4314Rights.fromSerializedRfc4314Rights("x")) .run("aclIntegration/ACLIntegrationRightX"); }
@Test public void newInstanceShouldHaveNoRightsWhenEmptyString() throws UnsupportedRightException { Rfc4314Rights rights = Rfc4314Rights.fromSerializedRfc4314Rights(""); assertThat(rights.list()).isEmpty(); }
@Test public void testExceptACLExisting() throws UnsupportedRightException { Map<EntryKey, Rfc4314Rights> expectedEntries = new HashMap<>(u1u2g1g2ACL.getEntries()); expectedEntries.put(EntryKey.deserialize(USER_1), Rfc4314Rights.fromSerializedRfc4314Rights(ik)); MailboxACL toRemove = new MailboxACL(new Entry(USER_1, ae)); MailboxACL result = u1u2g1g2ACL.except(toRemove); Map<EntryKey, Rfc4314Rights> foundEntries = result.getEntries(); assertThat(foundEntries).isEqualTo(expectedEntries); }
@Test public void testUnionACLExisting() throws UnsupportedRightException { Map<EntryKey, Rfc4314Rights> expectedEntries = new HashMap<>(u1u2g1g2ACL.getEntries()); expectedEntries.put(EntryKey.deserialize(USER_1), Rfc4314Rights.fromSerializedRfc4314Rights(aeik + lprs)); MailboxACL toAdd = new MailboxACL(new Entry(USER_1, lprs)); MailboxACL result = u1u2g1g2ACL.union(toAdd); Map<EntryKey, Rfc4314Rights> foundEntries = result.getEntries(); assertThat(expectedEntries).isEqualTo(foundEntries); }
@Test public void testUnionEntryExisting() throws UnsupportedRightException { Map<EntryKey, Rfc4314Rights> expectedEntries = new HashMap<>(u1u2g1g2ACL.getEntries()); expectedEntries.put(EntryKey.deserialize(USER_1), Rfc4314Rights.fromSerializedRfc4314Rights(aeik + lprs)); MailboxACL result = u1u2g1g2ACL.union(EntryKey.deserialize(USER_1), Rfc4314Rights.fromSerializedRfc4314Rights(lprs)); Map<EntryKey, Rfc4314Rights> foundEntries = result.getEntries(); assertThat(foundEntries).isEqualTo(expectedEntries); }
@Test public void rightIShouldBeSufficientToPerformCopyUS() throws Exception { scriptedTestProtocol .withGrantRights(OTHER_USER_MAILBOX, USER, MailboxACL.Rfc4314Rights.fromSerializedRfc4314Rights("i")) .withFilledMailbox(MY_INBOX) .run("aclIntegration/ACLIntegrationCopyI"); }
@Test public void rightISShouldBeSufficientToPerformAppendOfSeenMessageUS() throws Exception { scriptedTestProtocol .withGrantRights(OTHER_USER_MAILBOX, USER, MailboxACL.Rfc4314Rights.fromSerializedRfc4314Rights("ris")) .run("aclIntegration/ACLIntegrationRightIS"); }
@Test public void rightREShouldBeSufficientToPerformExpungeUS() throws Exception { scriptedTestProtocol .withGrantRights(OTHER_USER_MAILBOX, USER, MailboxACL.Rfc4314Rights.fromSerializedRfc4314Rights("re")) .run("aclIntegration/ACLIntegrationRightRE"); }
@Test public void rightLShouldBeSufficientToPerformListUS() throws Exception { scriptedTestProtocol .withGrantRights(OTHER_USER_MAILBOX, USER, MailboxACL.Rfc4314Rights.fromSerializedRfc4314Rights("l")) .run("aclIntegration/ACLIntegrationRightL"); }
@Test public void rightRShouldBeNeededToPerformStatusSelectCloseExamineUS() throws Exception { scriptedTestProtocol .withGrantRights(OTHER_USER_MAILBOX, USER, MailboxACL.Rfc4314Rights.fromSerializedRfc4314Rights("lswipkxtecda")) .run("aclIntegration/ACLIntegrationWithoutRightR"); }
@Before public void setUp() throws Exception { aeik = Rfc4314Rights.fromSerializedRfc4314Rights("aeik"); lprs = Rfc4314Rights.fromSerializedRfc4314Rights("lprs"); twx = Rfc4314Rights.fromSerializedRfc4314Rights("twx"); full = MailboxACL.FULL_RIGHTS; none = MailboxACL.NO_RIGHTS; }
@Test public void testExceptEntryExisting() throws UnsupportedRightException { Map<EntryKey, Rfc4314Rights> expectedEntries = new HashMap<>(u1u2g1g2ACL.getEntries()); expectedEntries.put(EntryKey.deserialize(USER_1), Rfc4314Rights.fromSerializedRfc4314Rights(ik)); MailboxACL result = u1u2g1g2ACL.except(EntryKey.deserialize(USER_1), Rfc4314Rights.fromSerializedRfc4314Rights(ae)); Map<EntryKey, Rfc4314Rights> foundEntries = result.getEntries(); assertThat(foundEntries).isEqualTo(expectedEntries); }