Search in sources :

Example 36 with NamedEntry

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);
    }
}
Also used : AccessManager(com.zimbra.cs.account.AccessManager) Group(com.zimbra.cs.account.Group) NamedEntry(com.zimbra.cs.account.NamedEntry) MailTarget(com.zimbra.cs.account.MailTarget)

Example 37 with NamedEntry

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);
    }
}
Also used : AccessManager(com.zimbra.cs.account.AccessManager) Group(com.zimbra.cs.account.Group) NamedEntry(com.zimbra.cs.account.NamedEntry) MailTarget(com.zimbra.cs.account.MailTarget)

Example 38 with NamedEntry

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;
    }
}
Also used : NamedEntry(com.zimbra.cs.account.NamedEntry)

Example 39 with NamedEntry

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);
}
Also used : NamedEntry(com.zimbra.cs.account.NamedEntry) HashSet(java.util.HashSet)

Example 40 with NamedEntry

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);
}
Also used : NamedEntry(com.zimbra.cs.account.NamedEntry) HashSet(java.util.HashSet)

Aggregations

NamedEntry (com.zimbra.cs.account.NamedEntry)109 Account (com.zimbra.cs.account.Account)51 ServiceException (com.zimbra.common.service.ServiceException)24 Domain (com.zimbra.cs.account.Domain)24 Provisioning (com.zimbra.cs.account.Provisioning)23 DistributionList (com.zimbra.cs.account.DistributionList)19 SearchDirectoryOptions (com.zimbra.cs.account.SearchDirectoryOptions)19 ProvTest (com.zimbra.qa.unittest.prov.ProvTest)19 AccountServiceException (com.zimbra.cs.account.AccountServiceException)18 HashSet (java.util.HashSet)17 Entry (com.zimbra.cs.account.Entry)15 HashMap (java.util.HashMap)15 Element (com.zimbra.common.soap.Element)14 Group (com.zimbra.cs.account.Group)14 SearchAccountsOptions (com.zimbra.cs.account.SearchAccountsOptions)12 GuestAccount (com.zimbra.cs.account.GuestAccount)9 MailTarget (com.zimbra.cs.account.MailTarget)8 LdapDomain (com.zimbra.cs.account.ldap.entry.LdapDomain)8 ArrayList (java.util.ArrayList)8 AccessManager (com.zimbra.cs.account.AccessManager)7