Search in sources :

Example 76 with Group

use of com.zimbra.cs.account.Group in project zm-mailbox by Zimbra.

the class TestDelegatedDL method hideInGal.

@Test
@Bug(bug = 66234)
public void hideInGal() throws Exception {
    // setup GAL sync account
    GalTestUtil.enableGalSyncAccount(prov, domain.getName());
    String GROUP_NAME = getAddress(genGroupNameLocalPart("group"));
    Multimap<String, String> attrs = ArrayListMultimap.create();
    attrs.put(Provisioning.A_zimbraHideInGal, ProvisioningConstants.TRUE);
    // create an owner account
    Account ownerAcct = provUtil.createAccount(genAcctNameLocalPart("owner"), domain);
    Group group = createGroupAndAddOwner(GROUP_NAME, attrs, ownerAcct.getName());
    // create member accounts and add it to the group
    Account memberAcct1 = provUtil.createAccount(genAcctNameLocalPart("member1"), domain);
    Account memberAcct2 = provUtil.createAccount(genAcctNameLocalPart("member2"), domain);
    Account memberAcct3 = provUtil.createAccount(genAcctNameLocalPart("member3"), domain);
    prov.addGroupMembers(group, new String[] { memberAcct3.getName(), memberAcct2.getName(), memberAcct1.getName() });
    // create a non-member account
    Account nonMemberAcct = provUtil.createAccount(genAcctNameLocalPart("non-member"), domain);
    /*
         * Owners should be able to see members even when the list is hideInGal
         */
    // auth as the owner
    SoapTransport transport = authUser(ownerAcct.getName());
    GetDistributionListMembersRequest req = new GetDistributionListMembersRequest(null, null, group.getName());
    GetDistributionListMembersResponse resp = invokeJaxb(transport, req);
    List<String> members = resp.getDlMembers();
    //make sure members are returned sorted
    Verify.verifyEquals(Lists.newArrayList(memberAcct1.getName(), memberAcct2.getName(), memberAcct3.getName()), members);
    // add another member, verify cache is updated
    Account memberAcct4 = provUtil.createAccount(genAcctNameLocalPart("member4"), domain);
    prov.addGroupMembers(group, new String[] { memberAcct4.getName() });
    resp = invokeJaxb(transport, req);
    members = resp.getDlMembers();
    Verify.verifyEquals(Lists.newArrayList(memberAcct1.getName(), memberAcct2.getName(), memberAcct3.getName(), memberAcct4.getName()), members);
    String errorCode = null;
    /*
         * non owner cannot see members when the list is hideInGal
         */
    transport = authUser(memberAcct1.getName());
    errorCode = null;
    try {
        invokeJaxb(transport, req);
    } catch (ServiceException e) {
        errorCode = e.getCode();
    }
    assertEquals(AccountServiceException.NO_SUCH_DISTRIBUTION_LIST, errorCode);
    /*
         * non owner cannot see members when the list is hideInGal
         */
    transport = authUser(nonMemberAcct.getName());
    errorCode = null;
    try {
        invokeJaxb(transport, req);
    } catch (ServiceException e) {
        errorCode = e.getCode();
    }
    assertEquals(AccountServiceException.NO_SUCH_DISTRIBUTION_LIST, errorCode);
    GalTestUtil.disableGalSyncAccount(prov, domain.getName());
    provUtil.deleteAccount(ownerAcct);
    provUtil.deleteAccount(memberAcct1);
    provUtil.deleteAccount(memberAcct2);
    provUtil.deleteAccount(memberAcct3);
    provUtil.deleteAccount(memberAcct4);
    provUtil.deleteAccount(nonMemberAcct);
    provUtil.deleteGroup(group);
}
Also used : Account(com.zimbra.cs.account.Account) Group(com.zimbra.cs.account.Group) GetDistributionListMembersResponse(com.zimbra.soap.account.message.GetDistributionListMembersResponse) AccountServiceException(com.zimbra.cs.account.AccountServiceException) ServiceException(com.zimbra.common.service.ServiceException) GetDistributionListMembersRequest(com.zimbra.soap.account.message.GetDistributionListMembersRequest) SoapTransport(com.zimbra.common.soap.SoapTransport) Test(org.junit.Test) Bug(com.zimbra.qa.QA.Bug)

Example 77 with Group

use of com.zimbra.cs.account.Group in project zm-mailbox by Zimbra.

the class TestDelegatedDL method init.

@BeforeClass
public static void init() throws Exception {
    DOMAIN_NAME = baseDomainName();
    ADMIN = TestUtil.getAddress("admin", DOMAIN_NAME);
    USER_CREATOR = TestUtil.getAddress("creator", DOMAIN_NAME);
    USER_OWNER = TestUtil.getAddress("owner", DOMAIN_NAME);
    USER_NOT_OWNER = TestUtil.getAddress("not-owner", DOMAIN_NAME);
    DL_NAME = TestUtil.getAddress("dl", DOMAIN_NAME);
    provUtil = new SoapProvTestUtil();
    prov = provUtil.getProv();
    domain = provUtil.createDomain(DOMAIN_NAME, new HashMap<String, Object>());
    Account admin = provUtil.createGlobalAdmin(ADMIN);
    Account creator = provUtil.createAccount(USER_CREATOR, new HashMap<String, Object>());
    Account owner = provUtil.createAccount(USER_OWNER, new HashMap<String, Object>());
    Account notOwner = provUtil.createAccount(USER_NOT_OWNER, new HashMap<String, Object>());
    prov.grantRight(TargetType.domain.getCode(), TargetBy.name, domain.getName(), GranteeType.GT_USER.getCode(), GranteeBy.name, creator.getName(), null, User.R_createDistList.getName(), null);
    // create a DL for get/action tests
    Multimap<String, String> attrs = ArrayListMultimap.create();
    attrs.put(Provisioning.A_zimbraDistributionListSubscriptionPolicy, ZAttrProvisioning.DistributionListSubscriptionPolicy.ACCEPT.name());
    Group group = createGroupAndAddOwner(DL_NAME, attrs, USER_OWNER);
}
Also used : Account(com.zimbra.cs.account.Account) Group(com.zimbra.cs.account.Group) HashMap(java.util.HashMap) BeforeClass(org.junit.BeforeClass)

Example 78 with Group

use of com.zimbra.cs.account.Group in project zm-mailbox by Zimbra.

the class TestDelegatedDL method distributionListActionDelete.

@Test
public void distributionListActionDelete() throws Exception {
    // create a group for the delete test
    String NAME = getAddress(genGroupNameLocalPart());
    Group group = createGroupAndAddOwner(NAME);
    SoapTransport transport = authUser(USER_OWNER);
    DistributionListAction action = new DistributionListAction(Operation.delete);
    DistributionListActionRequest req = new DistributionListActionRequest(DistributionListSelector.fromName(NAME), action);
    DistributionListActionResponse resp;
    String errorCode = null;
    try {
        // only people with create right and owner right can delete
        resp = invokeJaxb(transport, req);
    } catch (ServiceException e) {
        errorCode = e.getCode();
    }
    assertEquals(ServiceException.PERM_DENIED, errorCode);
    /*
         * auth as creator and try again, should still fail
         */
    transport = authUser(USER_CREATOR);
    errorCode = null;
    try {
        resp = invokeJaxb(transport, req);
    } catch (ServiceException e) {
        errorCode = e.getCode();
    }
    assertEquals(ServiceException.PERM_DENIED, errorCode);
    // make the creator an owner
    transport = authUser(USER_OWNER);
    addOwner(transport, group.getName(), USER_CREATOR);
    // now try delete as the creator (also an owner now), should succeed
    transport = authUser(USER_CREATOR);
    resp = invokeJaxb(transport, req);
    group = prov.getGroup(Key.DistributionListBy.name, NAME);
    assertNull(null);
}
Also used : Group(com.zimbra.cs.account.Group) AccountServiceException(com.zimbra.cs.account.AccountServiceException) ServiceException(com.zimbra.common.service.ServiceException) DistributionListActionResponse(com.zimbra.soap.account.message.DistributionListActionResponse) DistributionListAction(com.zimbra.soap.account.type.DistributionListAction) SoapTransport(com.zimbra.common.soap.SoapTransport) DistributionListActionRequest(com.zimbra.soap.account.message.DistributionListActionRequest) Test(org.junit.Test)

Example 79 with Group

use of com.zimbra.cs.account.Group in project zm-mailbox by Zimbra.

the class TestDelegatedDL method getDistributionList.

@Test
public void getDistributionList() throws Exception {
    SoapTransport transport = authUser(USER_OWNER);
    GetDistributionListRequest req = new GetDistributionListRequest(DistributionListSelector.fromName(DL_NAME), Boolean.TRUE);
    GetDistributionListResponse resp = invokeJaxb(transport, req);
    DistributionListInfo dlInfo = resp.getDl();
    assertTrue(dlInfo.isOwner());
    assertFalse(dlInfo.isMember());
    String dlId = dlInfo.getId();
    Group group = prov.getGroup(Key.DistributionListBy.name, DL_NAME);
    assertNotNull(group);
    assertEquals(group.getId(), dlId);
    boolean seenMail = false;
    boolean seenSubsPolicy = false;
    boolean seenUnsubsPolicy = false;
    List<? extends KeyValuePair> attrs = dlInfo.getAttrList();
    for (KeyValuePair attr : attrs) {
        String name = attr.getKey();
        String value = attr.getValue();
        if (Provisioning.A_mail.equals(name)) {
            assertEquals(group.getName(), value);
            seenMail = true;
        }
        if (Provisioning.A_zimbraDistributionListSubscriptionPolicy.equals(name)) {
            assertEquals(ZAttrProvisioning.DistributionListSubscriptionPolicy.ACCEPT.name(), value);
            seenSubsPolicy = true;
        }
        // zimbraAccount:GetDistributionListResponse should return the default value, instead of empty.
        if (Provisioning.A_zimbraDistributionListUnsubscriptionPolicy.equals(name)) {
            assertEquals(ZAttrProvisioning.DistributionListUnsubscriptionPolicy.REJECT.name(), value);
            seenUnsubsPolicy = true;
        }
    }
    assertTrue(seenMail);
    assertTrue(seenSubsPolicy);
    assertTrue(seenUnsubsPolicy);
    List<? extends DistributionListGranteeInfoInterface> dlOwners = dlInfo.getOwners();
    assertEquals(1, dlOwners.size());
    for (DistributionListGranteeInfoInterface owner : dlOwners) {
        com.zimbra.soap.type.GranteeType type = owner.getType();
        String id = owner.getId();
        String name = owner.getName();
        assertEquals(com.zimbra.soap.type.GranteeType.usr, type);
        assertEquals(USER_OWNER, name);
    }
}
Also used : GetDistributionListResponse(com.zimbra.soap.account.message.GetDistributionListResponse) Group(com.zimbra.cs.account.Group) DistributionListGranteeInfoInterface(com.zimbra.soap.base.DistributionListGranteeInfoInterface) DistributionListInfo(com.zimbra.soap.account.type.DistributionListInfo) KeyValuePair(com.zimbra.soap.type.KeyValuePair) GetDistributionListRequest(com.zimbra.soap.account.message.GetDistributionListRequest) SoapTransport(com.zimbra.common.soap.SoapTransport) Test(org.junit.Test)

Example 80 with Group

use of com.zimbra.cs.account.Group in project zm-mailbox by Zimbra.

the class TestDelegatedDL method InvalidOwnerEmail.

@Test
@Bug(bug = 72791)
public void InvalidOwnerEmail() throws Exception {
    String GROUP_NAME = getAddress(genGroupNameLocalPart());
    String errorCode = null;
    try {
        Group group = createGroupAndAddOwner(GROUP_NAME, "bogus@bogus.com");
    } catch (ServiceException e) {
        errorCode = e.getCode();
    }
    assertEquals(AccountServiceException.NO_SUCH_ACCOUNT, errorCode);
}
Also used : Group(com.zimbra.cs.account.Group) AccountServiceException(com.zimbra.cs.account.AccountServiceException) ServiceException(com.zimbra.common.service.ServiceException) Test(org.junit.Test) Bug(com.zimbra.qa.QA.Bug)

Aggregations

Group (com.zimbra.cs.account.Group)110 Account (com.zimbra.cs.account.Account)53 Test (org.junit.Test)42 DynamicGroup (com.zimbra.cs.account.DynamicGroup)27 ServiceException (com.zimbra.common.service.ServiceException)23 SoapTransport (com.zimbra.common.soap.SoapTransport)23 Provisioning (com.zimbra.cs.account.Provisioning)23 LdapDynamicGroup (com.zimbra.cs.account.ldap.entry.LdapDynamicGroup)21 Domain (com.zimbra.cs.account.Domain)17 GuestAccount (com.zimbra.cs.account.GuestAccount)17 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)17 Element (com.zimbra.common.soap.Element)16 AccountServiceException (com.zimbra.cs.account.AccountServiceException)15 NamedEntry (com.zimbra.cs.account.NamedEntry)14 LdapAccount (com.zimbra.cs.account.ldap.entry.LdapAccount)12 DistributionListActionRequest (com.zimbra.soap.account.message.DistributionListActionRequest)12 DistributionListAction (com.zimbra.soap.account.type.DistributionListAction)12 DistributionListActionResponse (com.zimbra.soap.account.message.DistributionListActionResponse)11 DistributionList (com.zimbra.cs.account.DistributionList)9 Entry (com.zimbra.cs.account.Entry)9