use of com.zimbra.cs.account.NamedEntry in project zm-mailbox by Zimbra.
the class TestDistListACL method doCheckSentToDistListUserRight.
private void doCheckSentToDistListUserRight(DistributionList targetDl, String email, String user, boolean expected) throws ServiceException {
ZimbraLog.test.info("DL name %s ID %s", targetDl.getName(), targetDl.getId());
Group group = prov.getGroupBasic(Key.DistributionListBy.name, listAddress);
Assert.assertNotNull("Unable to find Group object for DL by name", group);
AccessManager.ViaGrant via = new AccessManager.ViaGrant();
// More permissive that GT_USER - want to test called functions
NamedEntry ne = GranteeType.lookupGrantee(prov, GranteeType.GT_EMAIL, GranteeBy.name, email);
MailTarget grantee = null;
if (ne instanceof MailTarget) {
grantee = (MailTarget) ne;
}
boolean result = RightCommand.checkRight(prov, "dl", /* targetType */
TargetBy.name, listAddress, grantee, RightConsts.RT_sendToDistList, null, /* attrs */
via);
if (expected) {
Assert.assertTrue(String.format("%s should be able to send to DL (as user %s)", email, user), accessMgr.canDo(email, group, User.R_sendToDistList, false));
Assert.assertTrue(String.format("%s should have right to send to DL (as user %s)", email, user), result);
ZimbraLog.test.info("Test for %s against dom %s Via=%s", email, user, via);
} else {
Assert.assertFalse(String.format("%s should NOT be able to send to DL (because not user %s)", email, user), accessMgr.canDo(email, group, User.R_sendToDistList, false));
Assert.assertFalse(String.format("%s should NOT have right to send to DL (because not user %s)", email, user), result);
}
}
use of com.zimbra.cs.account.NamedEntry in project zm-mailbox by Zimbra.
the class TestDistListACL method doCheckSentToDistListEmailRight.
private void doCheckSentToDistListEmailRight(DistributionList targetDl, String email, String grantEmail, boolean expected) throws ServiceException {
ZimbraLog.test.info("DL name %s ID %s", targetDl.getName(), targetDl.getId());
Group group = prov.getGroupBasic(Key.DistributionListBy.name, listAddress);
Assert.assertNotNull("Unable to find Group object for DL by name", group);
AccessManager.ViaGrant via = new AccessManager.ViaGrant();
NamedEntry ne = GranteeType.lookupGrantee(prov, GranteeType.GT_EMAIL, GranteeBy.name, email);
MailTarget grantee = null;
if (ne instanceof MailTarget) {
grantee = (MailTarget) ne;
}
boolean result = RightCommand.checkRight(prov, "dl", /* targetType */
TargetBy.name, listAddress, grantee, RightConsts.RT_sendToDistList, null, /* attrs */
via);
if (expected) {
Assert.assertTrue(String.format("%s should be able to send to DL (using email %s)", email, grantEmail), accessMgr.canDo(email, group, User.R_sendToDistList, false));
Assert.assertTrue(String.format("%s should have right to send to DL (using email %s)", email, grantEmail), result);
ZimbraLog.test.info("Test for %s against dom %s Via=%s", email, grantEmail, via);
} else {
Assert.assertFalse(String.format("%s should NOT be able to send to DL (because not email %s)", email, grantEmail), accessMgr.canDo(email, group, User.R_sendToDistList, false));
Assert.assertFalse(String.format("%s should NOT have right to send to DL (because not email %s)", email, grantEmail), result);
}
}
use of com.zimbra.cs.account.NamedEntry in project zm-mailbox by Zimbra.
the class Verify method verifyEquals.
public static void verifyEquals(List<? extends NamedEntry> expected, List<? extends NamedEntry> actual, boolean orderMatters) {
try {
if (expected == null) {
expected = new ArrayList<NamedEntry>();
}
int size = expected.size();
assertEquals(expected.size(), actual.size());
List<String> expectedIds = Lists.newArrayList();
List<String> expectedNames = Lists.newArrayList();
for (NamedEntry entry : expected) {
expectedIds.add(entry.getId());
expectedNames.add(entry.getName());
}
List<String> actualIds = Lists.newArrayList();
List<String> actualNames = Lists.newArrayList();
for (NamedEntry entry : actual) {
actualIds.add(entry.getId());
actualNames.add(entry.getName());
}
for (int i = 0; i < size; i++) {
if (orderMatters) {
assertEquals(expectedIds.get(i), actualIds.get(i));
assertEquals(expectedNames.get(i), actualNames.get(i));
} else {
assertTrue(actualIds.contains(expectedIds.get(i)));
assertTrue(actualNames.contains(expectedNames.get(i)));
}
}
} catch (AssertionError e) {
System.out.println();
System.out.println("===== verifyEquals failed =====");
System.out.println("Message: " + e.getMessage());
System.out.println();
System.out.println(String.format("expected (size=%d)", expected.size()));
for (NamedEntry entry : expected) {
System.out.println(" " + entry.getName() + " (" + entry.getId() + ")");
}
System.out.println();
System.out.println(String.format("actual (size=%d)", actual.size()));
for (NamedEntry entry : actual) {
System.out.println(" " + entry.getName() + " (" + entry.getId() + ")");
}
System.out.println();
throw e;
}
}
use of com.zimbra.cs.account.NamedEntry in project zm-mailbox by Zimbra.
the class Verify method verifyEntriesByName.
// verify list of NamedEntry contains all the names
// if checkCount == true, verify the count matches too
public static void verifyEntriesByName(List<NamedEntry> list, String[] names, boolean checkCount) throws Exception {
Set<String> namesInList = new HashSet<String>();
for (NamedEntry entry : list) namesInList.add(entry.getName());
verifyEntries(namesInList, names, checkCount);
}
use of com.zimbra.cs.account.NamedEntry in project zm-mailbox by Zimbra.
the class Verify method verifyEntriesById.
// verify list of NamedEntry contains all the ids
// if checkCount == true, verify the count matches too
public static void verifyEntriesById(List<NamedEntry> list, String[] names, boolean checkCount) throws Exception {
Set<String> idsInList = new HashSet<String>();
for (NamedEntry entry : list) idsInList.add(entry.getId());
verifyEntries(idsInList, names, checkCount);
}
Aggregations