public Stream<MailboxACL.Entry> addedEntries() { return newACL.getEntries() .entrySet() .stream() .filter(entry -> !oldACL.getEntries().containsKey(entry.getKey())) .map(entry -> new MailboxACL.Entry(entry.getKey(), entry.getValue())); }
public Stream<MailboxACL.Entry> removedEntries() { return oldACL.getEntries() .entrySet() .stream() .filter(entry -> !newACL.getEntries().containsKey(entry.getKey())) .map(entry -> new MailboxACL.Entry(entry.getKey(), entry.getValue())); }
public Stream<MailboxACL.Entry> changedEntries() { Map<MailboxACL.EntryKey, MailboxACL.Rfc4314Rights> oldEntries = oldACL.getEntries(); return newACL.getEntries() .entrySet() .stream() .filter(entry -> hasKeyWithDifferentValue(oldEntries, entry)) .map(entry -> new MailboxACL.Entry(entry.getKey(), entry.getValue())); }
@Test public void changedEntriesShouldReturnEntryWhenChangedEntry() throws Exception { PositiveUserACLDiff positiveUserAclDiff = PositiveUserACLDiff.computeDiff( MailboxACL.EMPTY.apply( MailboxACL.command() .key(USER_ENTRY_KEY) .rights(Right.Administer) .asAddition()), MailboxACL.EMPTY.apply( MailboxACL.command() .key(USER_ENTRY_KEY) .rights(Right.Lookup) .asAddition())); assertThat(positiveUserAclDiff.changedEntries()) .containsOnly(new Entry(USER_ENTRY_KEY, new Rfc4314Rights(MailboxACL.Right.Lookup))); }
@Test public void changedEntriesShouldReturnEntryWhenChangedEntry() throws Exception { ACLDiff aclDiff = ACLDiff.computeDiff( MailboxACL.EMPTY.apply( MailboxACL.command() .key(ENTRY_KEY) .rights(MailboxACL.Right.Administer) .asAddition()), MailboxACL.EMPTY.apply( MailboxACL.command() .key(ENTRY_KEY) .rights(MailboxACL.Right.Lookup) .asAddition())); assertThat(aclDiff.changedEntries()) .containsOnly(new MailboxACL.Entry(ENTRY_KEY, new MailboxACL.Rfc4314Rights(MailboxACL.Right.Lookup))); }
public MailboxACL union(EntryKey key, Rfc4314Rights mailboxACLRights) throws UnsupportedRightException { return union(new MailboxACL(new Entry(key, mailboxACLRights))); }
public MailboxACL except(EntryKey key, Rfc4314Rights mailboxACLRights) throws UnsupportedRightException { return except(new MailboxACL(new Entry(key, mailboxACLRights))); }
@Test void deleteShouldDeleteWhenExisting() { testee.update(MAILBOX_ID, ACLDiff.computeDiff( MailboxACL.EMPTY, new MailboxACL(new Entry(ENTRY_KEY, RIGHTS)))) .join(); testee.update(MAILBOX_ID, ACLDiff.computeDiff( new MailboxACL(new Entry(ENTRY_KEY, RIGHTS)), MailboxACL.EMPTY)) .join(); assertThat(testee.retrieve(USER_NAME, MAILBOX_ID).join()) .isEmpty(); } }
@Test void saveOnSecondShouldOverwrite() { testee.update(MAILBOX_ID, ACLDiff.computeDiff( MailboxACL.EMPTY, new MailboxACL(new Entry(ENTRY_KEY, RIGHTS)))) .join(); testee.update(MAILBOX_ID, ACLDiff.computeDiff( new MailboxACL(new Entry(ENTRY_KEY, RIGHTS)), new MailboxACL(new Entry(ENTRY_KEY, OTHER_RIGHTS)))) .join(); assertThat(testee.retrieve(USER_NAME, MAILBOX_ID).join()) .contains(OTHER_RIGHTS); }
@Test public void toMailboxAclShouldReturnAclConversion() throws Exception { String user1 = "user1"; String user2 = "user2"; Rights rights = Rights.builder() .delegateTo(new Rights.Username(user1), Right.Administer, Right.DeleteMessages) .delegateTo(new Rights.Username(user2), Right.Expunge, Right.Lookup) .build(); assertThat(rights.toMailboxAcl()) .isEqualTo(new MailboxACL( new Entry(user1, MailboxACL.Right.Administer, MailboxACL.Right.DeleteMessages), new Entry(user2, MailboxACL.Right.PerformExpunge, MailboxACL.Right.Lookup))); }
@Test void saveShouldInsertNewEntry() { testee.update(MAILBOX_ID, ACLDiff.computeDiff( MailboxACL.EMPTY, new MailboxACL(new Entry(ENTRY_KEY, RIGHTS)))) .join(); assertThat(testee.retrieve(USER_NAME, MAILBOX_ID).join()) .contains(RIGHTS); }
@Test public void eventShouldUpdateNewParentWhenRenameMailboxWhichContainLookupRight() throws Exception { Mailbox childMailbox = mailboxMapper.getMailboxMapper(mailboxSession).findMailboxById(childMailboxId); mailboxMapper.getMailboxMapper(mailboxSession).setACL(childMailbox, new MailboxACL( new Entry(SHARED_USER_KEY, new Rfc4314Rights(Right.Write, Right.Lookup)))); storeMailboxManager.renameMailbox(CHILD_MAILBOX, MailboxPath.forUser(OWNER_USER, "shared1.sub1New"), mailboxSession); MailboxACL actualACL = storeMailboxManager.getMailbox(parentMailboxId1, mailboxSession) .getMetaData(RESET_RECENT, mailboxSession, MessageManager.MetaData.FetchGroup.NO_COUNT) .getACL(); assertThat(actualACL.getEntries()) .contains(lookupEntry); }
@Test public void addedEntriesShouldReturnNewEntryWhenAddedEntry() throws Exception { ACLDiff aclDiff = ACLDiff.computeDiff( MailboxACL.EMPTY, MailboxACL.EMPTY.apply( MailboxACL.command() .key(ENTRY_KEY) .rights(RIGHTS) .asAddition())); assertThat(aclDiff.addedEntries()) .containsOnly(new MailboxACL.Entry(ENTRY_KEY, RIGHTS)); }
@Test public void removedEntriesShouldReturnEntryWhenRemovedEntry() throws Exception { PositiveUserACLDiff positiveUserAclDiff = PositiveUserACLDiff.computeDiff( MailboxACL.EMPTY.apply( MailboxACL.command() .key(USER_ENTRY_KEY) .rights(RIGHTS) .asAddition()), MailboxACL.EMPTY); assertThat(positiveUserAclDiff.removedEntries()) .containsOnly(new Entry(USER_ENTRY_KEY, RIGHTS)); }
@Test public void testExceptACLFull() throws UnsupportedRightException { Map<EntryKey, Rfc4314Rights> expectedEntries = new HashMap<>(u1u2g1g2ACL.getEntries()); expectedEntries.remove(EntryKey.deserialize(USER_1)); MailboxACL toRemove = new MailboxACL(new Entry(USER_1, MailboxACL.FULL_RIGHTS.serialize())); MailboxACL result = u1u2g1g2ACL.except(toRemove); Map<EntryKey, Rfc4314Rights> foundEntries = result.getEntries(); assertThat(foundEntries).isEqualTo(expectedEntries); }
@Test public void removedEntriesShouldReturnEntryWhenRemovedEntry() throws Exception { ACLDiff aclDiff = ACLDiff.computeDiff( MailboxACL.EMPTY.apply( MailboxACL.command() .key(ENTRY_KEY) .rights(RIGHTS) .asAddition()), MailboxACL.EMPTY); assertThat(aclDiff.removedEntries()) .containsOnly(new MailboxACL.Entry(ENTRY_KEY, RIGHTS)); }
@Test public void addedEntriesShouldReturnNewEntryWhenAddedEntry() throws Exception { PositiveUserACLDiff positiveUserAclDiff = PositiveUserACLDiff.computeDiff( MailboxACL.EMPTY, MailboxACL.EMPTY.apply( MailboxACL.command() .key(USER_ENTRY_KEY) .rights(RIGHTS) .asAddition())); assertThat(positiveUserAclDiff.addedEntries()) .containsOnly(new Entry(USER_ENTRY_KEY, RIGHTS)); }
@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 eventShouldNotUpdateNewParentWhenRenameMailboxWhichDoesContainLookupRight() throws Exception { Mailbox childMailbox = mailboxMapper.getMailboxMapper(mailboxSession).findMailboxById(childMailboxId); mailboxMapper.getMailboxMapper(mailboxSession).setACL(childMailbox, new MailboxACL( new Entry(SHARED_USER_KEY, new Rfc4314Rights(Right.Write)))); storeMailboxManager.renameMailbox(CHILD_MAILBOX, MailboxPath.forUser(OWNER_USER, "shared1.sub1New"), mailboxSession); MailboxACL actualACL = storeMailboxManager.getMailbox(parentMailboxId1, mailboxSession) .getMetaData(RESET_RECENT, mailboxSession, MessageManager.MetaData.FetchGroup.NO_COUNT) .getACL(); assertThat(actualACL.getEntries()) .doesNotContainKeys(SHARED_USER_KEY); }