@Test public void testNegativeGroup() throws UnsupportedRightException { assertThat(EntryKey.deserialize(String.valueOf(MailboxACL.DEFAULT_NEGATIVE_MARKER) + MailboxACL.DEFAULT_GROUP_MARKER + GROUP_1)) .isEqualTo(new EntryKey(GROUP_1, NameType.group, true)); }
@Test public void testSerializeNegativeGroup() throws UnsupportedRightException { assertThat(new EntryKey(GROUP_1, NameType.group, true).serialize()) .isEqualTo(String.valueOf(MailboxACL.DEFAULT_NEGATIVE_MARKER) + MailboxACL.DEFAULT_GROUP_MARKER + GROUP_1); }
@Test public void testSerializeUser() throws UnsupportedRightException { assertThat(new EntryKey(USER_1, NameType.user, false).serialize()) .isEqualTo(USER_1); }
@Test void twoConcurrentUpdatesWhenNoACEStoredShouldReturnACEWithTwoEntries(CassandraCluster cassandra) throws Exception { CountDownLatch countDownLatch = new CountDownLatch(2); MailboxACL.EntryKey keyBob = new MailboxACL.EntryKey("bob", MailboxACL.NameType.user, false); MailboxACL.Rfc4314Rights rights = new MailboxACL.Rfc4314Rights(MailboxACL.Right.Read); MailboxACL.EntryKey keyAlice = new MailboxACL.EntryKey("alice", MailboxACL.NameType.user, false); Future<Boolean> future1 = performACLUpdateInExecutor(cassandra, executor, keyBob, rights, countDownLatch::countDown); Future<Boolean> future2 = performACLUpdateInExecutor(cassandra, executor, keyAlice, rights, countDownLatch::countDown); awaitAll(future1, future2); assertThat(cassandraACLMapper.getACL(MAILBOX_ID).join()) .isEqualTo(new MailboxACL().union(keyBob, rights).union(keyAlice, rights)); }
@Test void modifyACLWhenStoredShouldReturnUpdatedACL() throws MailboxException { MailboxACL.EntryKey keyBob = new MailboxACL.EntryKey("bob", MailboxACL.NameType.user, false); MailboxACL.Rfc4314Rights rights = new MailboxACL.Rfc4314Rights(MailboxACL.Right.Read); cassandraACLMapper.updateACL(MAILBOX_ID, MailboxACL.command().key(keyBob).rights(rights).asAddition()); MailboxACL.EntryKey keyAlice = new MailboxACL.EntryKey("alice", MailboxACL.NameType.user, false); cassandraACLMapper.updateACL(MAILBOX_ID, MailboxACL.command().key(keyAlice).rights(rights).asAddition()); assertThat(cassandraACLMapper.getACL(MAILBOX_ID).join()) .isEqualTo(new MailboxACL().union(keyBob, rights).union(keyAlice, rights)); }
@Test public void testSerializeNegativeAuthenticated() throws UnsupportedRightException { assertThat(new EntryKey(SpecialName.authenticated.toString(), NameType.special, true).serialize()) .isEqualTo(MailboxACL.DEFAULT_NEGATIVE_MARKER + SpecialName.authenticated.toString()); } }
@Test public void testSerializeAuthenticated() throws UnsupportedRightException { assertThat(new EntryKey(SpecialName.authenticated.toString(), NameType.special, false).serialize()) .isEqualTo(SpecialName.authenticated.toString()); }
@Test public void testSerializeNegativeUser() throws UnsupportedRightException { assertThat(new EntryKey(USER_1, NameType.user, true).serialize()) .isEqualTo(MailboxACL.DEFAULT_NEGATIVE_MARKER + USER_1); }
@Test public void testNegativeAuthenticated() throws UnsupportedRightException { assertThat(EntryKey.deserialize(MailboxACL.DEFAULT_NEGATIVE_MARKER + SpecialName.authenticated.toString())) .isEqualTo(new EntryKey(SpecialName.authenticated.toString(), NameType.special, true)); }
@Test public void testAnybody() throws UnsupportedRightException { assertThat(EntryKey.deserialize(SpecialName.anybody.toString())) .isEqualTo(new EntryKey(SpecialName.anybody.toString(), NameType.special, false)); }
@Test public void testOwner() throws UnsupportedRightException { assertThat(EntryKey.deserialize(SpecialName.owner.toString())) .isEqualTo(new EntryKey(SpecialName.owner.toString(), NameType.special, false)); }
@Test public void testUser() throws UnsupportedRightException { assertThat(EntryKey.deserialize(USER_1)) .isEqualTo(new EntryKey(USER_1, NameType.user, false)); }
@Test public void testSerializeAnybody() throws UnsupportedRightException { assertThat(new EntryKey(SpecialName.anybody.toString(), NameType.special, false).serialize()) .isEqualTo(SpecialName.anybody.toString()); }
@Test public void testSerializeNegativeOwner() throws UnsupportedRightException { assertThat(new EntryKey(SpecialName.owner.toString(), NameType.special, true).serialize()) .isEqualTo(MailboxACL.DEFAULT_NEGATIVE_MARKER + SpecialName.owner.toString()); }
@Override public Rfc4314Rights resolveRights(String requestUser, GroupMembershipResolver groupMembershipResolver, MailboxACL resourceACL, String resourceOwner, boolean resourceOwnerIsGroup) throws UnsupportedRightException { Rfc4314Rights[] positiveNegativePair = { MailboxACL.NO_RIGHTS, MailboxACL.NO_RIGHTS }; final EntryKey queryKey = requestUser == null ? null : new EntryKey(requestUser, NameType.user, false); MailboxACL userACL = resourceOwnerIsGroup ? groupGlobalACL : userGlobalACL; resolveRights(queryKey, groupMembershipResolver, userACL.getEntries(), resourceOwner, resourceOwnerIsGroup, positiveNegativePair); if (resourceACL != null) { resolveRights(queryKey, groupMembershipResolver, resourceACL.getEntries(), resourceOwner, resourceOwnerIsGroup, positiveNegativePair); } return positiveNegativePair[POSITIVE_INDEX].except(positiveNegativePair[NEGATIVE_INDEX]); }
@Test void replaceWhenNotStoredShouldUpdateACLEntry() throws MailboxException { MailboxACL.EntryKey key = new MailboxACL.EntryKey("bob", MailboxACL.NameType.user, false); MailboxACL.Rfc4314Rights rights = new MailboxACL.Rfc4314Rights(MailboxACL.Right.Read); cassandraACLMapper.updateACL(MAILBOX_ID, MailboxACL.command().key(key).rights(rights).asReplacement()); assertThat(cassandraACLMapper.getACL(MAILBOX_ID).join()).isEqualTo(new MailboxACL().union(key, rights)); }
@Test void updateInvalidACLShouldBeBasedOnEmptyACL(CassandraCluster cassandra) throws Exception { cassandra.getConf().execute( insertInto(CassandraACLTable.TABLE_NAME) .value(CassandraACLTable.ID, MAILBOX_ID.asUuid()) .value(CassandraACLTable.ACL, "{\"entries\":{\"bob\":invalid}}") .value(CassandraACLTable.VERSION, 1)); MailboxACL.EntryKey key = new MailboxACL.EntryKey("bob", MailboxACL.NameType.user, false); MailboxACL.Rfc4314Rights rights = new MailboxACL.Rfc4314Rights(MailboxACL.Right.Read); cassandraACLMapper.updateACL(MAILBOX_ID, MailboxACL.command().key(key).rights(rights).asAddition()); assertThat(cassandraACLMapper.getACL(MAILBOX_ID).join()).isEqualTo(new MailboxACL().union(key, rights)); }
@Test public void testAuthenticated() throws UnsupportedRightException { assertThat(EntryKey.deserialize(SpecialName.authenticated.toString())) .isEqualTo(new EntryKey(SpecialName.authenticated.toString(), NameType.special, false)); }
@Test public void testGroup() throws UnsupportedRightException { assertThat(EntryKey.deserialize(MailboxACL.DEFAULT_GROUP_MARKER + GROUP_1)) .isEqualTo(new EntryKey(GROUP_1, NameType.group, false)); }
@Test public void testNegativeUser() throws UnsupportedRightException { assertThat(EntryKey.deserialize(MailboxACL.DEFAULT_NEGATIVE_MARKER + USER_1)) .isEqualTo(new EntryKey(USER_1, NameType.user, true)); }