use of com.zimbra.cs.account.Provisioning.GroupMembership in project zm-mailbox by Zimbra.
the class TestGroups method doGetGroupMembershipWithRights.
private GroupMembership doGetGroupMembershipWithRights(Account acct, Set<Right> rights, int expected, int adminOnlyExpected) throws ServiceException {
String rightsDesc;
if (rights == null) {
rightsDesc = "rights={ALL(null)}";
} else if (rights.isEmpty()) {
rightsDesc = "rights={ALL(empty)}";
} else {
StringBuilder sb = new StringBuilder("rights=");
for (Right right : rights) {
if (sb.length() > 7) {
sb.append(',');
}
sb.append(right.getName());
}
rightsDesc = sb.toString();
}
long before = System.currentTimeMillis();
GroupMembership membership = ldapProv.getGroupMembershipWithRights(acct, rights, false);
long after = System.currentTimeMillis();
String groupNames = groupInfo(membership.groupIds());
ZimbraLog.test.info("YYY getGroupMembershipWithRights %s ms=%s acct=%s size=%s\n%s\ngroupNames=%s", rightsDesc, after - before, acct.getName(), membership.groupIds().size(), membership, groupNames);
before = System.currentTimeMillis();
GroupMembership adminOnlyMembership = ldapProv.getGroupMembershipWithRights(acct, rights, true);
after = System.currentTimeMillis();
String adminOnlyGroupNames = groupInfo(membership.groupIds());
ZimbraLog.test.info("YYY getGroupMembershipWithRights [adminOnly] %s ms=%s acct=%s size=%s\n%s\ngroupNames=%s", rightsDesc, after - before, acct.getName(), adminOnlyMembership.groupIds().size(), adminOnlyMembership, adminOnlyGroupNames);
assertEquals(String.format("Number of groups with %s which contain %s groups=%s", rightsDesc, acct.getName(), groupNames), expected, membership.groupIds().size());
assertEquals(String.format("Number of adminOnly groups with %s which contain %s groups=%s", rightsDesc, acct.getName(), adminOnlyGroupNames), adminOnlyExpected, adminOnlyMembership.groupIds().size());
return membership;
}
use of com.zimbra.cs.account.Provisioning.GroupMembership in project zm-mailbox by Zimbra.
the class TestGroups method testDLupdateGroupMembershipWithViaWithAliases.
public void testDLupdateGroupMembershipWithViaWithAliases() throws Exception {
Account acct = ldapProv.getAccountByName(acctWithAlias);
GroupMembership membership = new GroupMembership();
Map<String, String> via = Maps.newHashMap();
long start = System.currentTimeMillis();
DistributionList.updateGroupMembership(ldapProv, (ZLdapContext) null, membership, acct, via, false, /* adminGroupsOnly */
false);
ZimbraLog.test.info("testDLupdateGroupMembershipWithVia %s size=%d via size=%d via=%s", ZimbraLog.elapsedTime(start, System.currentTimeMillis()), membership.groupIds().size(), via.size(), via);
for (int cnt = 1; cnt <= NUM_NORMAL_DL; cnt++) {
String nam = String.format(normalDLPatt, cnt);
DistributionList dl = ldapProv.get(DistributionListBy.name, nam);
Assert.assertTrue(String.format("DL %s (id=%s) in membership", nam, dl.getId()), membership.groupIds().contains(dl.getId()));
}
DistributionList dl = ldapProv.get(DistributionListBy.name, dlWithAlias);
Assert.assertTrue(String.format("DL %s (id=%s) in membership", dl.getId(), dl.getId()), membership.groupIds().contains(dl.getId()));
dl = ldapProv.get(DistributionListBy.name, dlWithAlias2);
Assert.assertTrue(String.format("DL %s (id=%s) in membership", dl.getId(), dl.getId()), membership.groupIds().contains(dl.getId()));
Assert.assertEquals(String.format("Number of DLs User %s is a member of", acctWithAlias), NUM_NORMAL_DL + 2, membership.memberOf().size());
Assert.assertEquals(String.format("Number of vias for User %s", acctWithAlias), 1, via.size());
acct = ldapProv.getAccountByName(acctWithAlias2);
membership = new GroupMembership();
Maps.newHashMap();
start = System.currentTimeMillis();
DistributionList.updateGroupMembership(ldapProv, (ZLdapContext) null, membership, acct, via, false, /* adminGroupsOnly */
false);
ZimbraLog.test.info("testDLupdateGroupMembershipWithVia %s size=%d via size=%d via=%s", ZimbraLog.elapsedTime(start, System.currentTimeMillis()), membership.groupIds().size(), via.size(), via);
dl = ldapProv.get(DistributionListBy.name, dlWithAlias);
Assert.assertTrue(String.format("DL %s (id=%s) in membership", dl.getName(), dl.getId()), membership.groupIds().contains(dl.getId()));
dl = ldapProv.get(DistributionListBy.name, dlWithAlias2);
Assert.assertTrue(String.format("DL %s (id=%s) in membership", dl.getName(), dl.getId()), membership.groupIds().contains(dl.getId()));
Assert.assertEquals(String.format("Number of DLs User %s is a member of", acctWithAlias2), 2, membership.memberOf().size());
Assert.assertEquals(String.format("Number of vias for User %s", acctWithAlias2), 1, via.size());
}
use of com.zimbra.cs.account.Provisioning.GroupMembership in project zm-mailbox by Zimbra.
the class TestLdapProvDynamicGroup method renameAccount.
/*
* renaming an account should not affect its membership in a dynamic group
*/
@Test
public void renameAccount() throws Exception {
Group group = createDynamicGroup(genGroupNameLocalPart());
String groupId = group.getId();
Account acct = provUtil.createAccount(genAcctNameLocalPart("1"), domain);
String newAddr = TestUtil.getAddress(genAcctNameLocalPart("2"), domain.getName());
prov.addGroupMembers(group, new String[] { acct.getName(), newAddr });
String[] members = prov.getGroupMembers(group);
// ensure groups contains the account
Verify.verifyEquals(Sets.newHashSet(acct.getName(), newAddr), members);
GroupMembership membership = prov.getGroupMembership(acct, false);
List<String> groupIdList = membership.groupIds();
// ensure the account is a member of the group
assertTrue(groupIdList.contains(groupId));
//
// rename the account, then make sure the account is still in the group
//
prov.renameAccount(acct.getId(), newAddr);
group = prov.getGroupBasic(DistributionListBy.id, groupId);
members = prov.getGroupMembers(group);
// ensure groups contains the account
Verify.verifyEquals(Sets.newHashSet(newAddr), members);
membership = prov.getGroupMembership(acct, false);
groupIdList = membership.groupIds();
// ensure the account is a member of the group
assertTrue(groupIdList.contains(groupId));
}
Aggregations