Search in sources :

Example 46 with SoapTransport

use of com.zimbra.common.soap.SoapTransport in project zm-mailbox by Zimbra.

the class TestDelegatedDL method distributionListActionAddRemoveOwners.

@Test
public void distributionListActionAddRemoveOwners() throws Exception {
    String GROUP_NAME = getAddress(genGroupNameLocalPart("group"));
    Group group = createGroupAndAddOwner(GROUP_NAME);
    Account owner1 = provUtil.createAccount(genAcctNameLocalPart("1"), domain);
    Account owner2 = provUtil.createAccount(genAcctNameLocalPart("2"), domain);
    SoapTransport transport = authUser(USER_OWNER);
    //
    // addOwners
    //
    DistributionListAction action = new DistributionListAction(Operation.addOwners);
    DistributionListActionRequest req = new DistributionListActionRequest(DistributionListSelector.fromName(GROUP_NAME), action);
    action.addOwner(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.usr, DistributionListGranteeBy.name, USER_OWNER));
    action.addOwner(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.usr, DistributionListGranteeBy.name, owner1.getName()));
    action.addOwner(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.usr, DistributionListGranteeBy.name, owner2.getName()));
    DistributionListActionResponse resp = invokeJaxb(transport, req);
    //
    // verify owners are added
    //
    GetDistributionListRequest getDLReq = new GetDistributionListRequest(DistributionListSelector.fromName(GROUP_NAME), Boolean.TRUE);
    GetDistributionListResponse getDLResp = invokeJaxb(transport, getDLReq);
    DistributionListInfo dlInfo = getDLResp.getDl();
    List<? extends DistributionListGranteeInfoInterface> owners = dlInfo.getOwners();
    Set<String> ownerNames = Sets.newHashSet();
    for (DistributionListGranteeInfoInterface owner : owners) {
        if (owner.getType() == com.zimbra.soap.type.GranteeType.usr) {
            ownerNames.add(owner.getName());
        }
    }
    assertEquals(3, owners.size());
    Verify.verifyEquals(Sets.newHashSet(USER_OWNER, owner1.getName(), owner2.getName()), ownerNames);
    //
    // removeOwners
    //
    action = new DistributionListAction(Operation.removeOwners);
    req = new DistributionListActionRequest(DistributionListSelector.fromName(GROUP_NAME), action);
    action.addOwner(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.usr, DistributionListGranteeBy.name, owner1.getName()));
    action.addOwner(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.usr, DistributionListGranteeBy.name, owner2.getName()));
    resp = invokeJaxb(transport, req);
    //
    // verify owners are removed
    //
    getDLReq = new GetDistributionListRequest(DistributionListSelector.fromName(GROUP_NAME), Boolean.TRUE);
    getDLResp = invokeJaxb(transport, getDLReq);
    dlInfo = getDLResp.getDl();
    owners = dlInfo.getOwners();
    ownerNames = Sets.newHashSet();
    for (DistributionListGranteeInfoInterface owner : owners) {
        if (owner.getType() == com.zimbra.soap.type.GranteeType.usr) {
            ownerNames.add(owner.getName());
        }
    }
    assertEquals(1, owners.size());
    Verify.verifyEquals(Sets.newHashSet(USER_OWNER), ownerNames);
}
Also used : GetDistributionListResponse(com.zimbra.soap.account.message.GetDistributionListResponse) Group(com.zimbra.cs.account.Group) Account(com.zimbra.cs.account.Account) DistributionListGranteeInfoInterface(com.zimbra.soap.base.DistributionListGranteeInfoInterface) DistributionListInfo(com.zimbra.soap.account.type.DistributionListInfo) DistributionListActionResponse(com.zimbra.soap.account.message.DistributionListActionResponse) GetDistributionListRequest(com.zimbra.soap.account.message.GetDistributionListRequest) DistributionListActionRequest(com.zimbra.soap.account.message.DistributionListActionRequest) DistributionListGranteeSelector(com.zimbra.soap.account.type.DistributionListGranteeSelector) DistributionListAction(com.zimbra.soap.account.type.DistributionListAction) SoapTransport(com.zimbra.common.soap.SoapTransport) Test(org.junit.Test)

Example 47 with SoapTransport

use of com.zimbra.common.soap.SoapTransport in project zm-mailbox by Zimbra.

the class TestDelegatedDL method noHomeServerZimbraAdmin.

/*
     * Verify groups without a home server will get executed for zimbraAdmin
     * SOAP calls.
     */
@Test
@Bug(bug = 66412)
public void noHomeServerZimbraAdmin() throws Exception {
    String groupName = TestUtil.getAddress(genGroupNameLocalPart(), DOMAIN_NAME);
    Group group = provUtil.createGroup(groupName, DYNAMIC);
    String groupId = group.getId();
    // remove zimbraMailHost
    Map<String, Object> attrs = Maps.newHashMap();
    attrs.put(Provisioning.A_zimbraMailHost, null);
    prov.modifyAttrs(group, attrs);
    SoapTransport transport = authAdmin(ADMIN);
    Object req;
    com.zimbra.soap.admin.type.DistributionListInfo dlInfo;
    /*
         * GetDistributionList
         */
    req = new com.zimbra.soap.admin.message.GetDistributionListRequest(com.zimbra.soap.admin.type.DistributionListSelector.fromName(groupName));
    com.zimbra.soap.admin.message.GetDistributionListResponse getDLResp = invokeJaxb(transport, req);
    dlInfo = getDLResp.getDl();
    assertEquals(groupId, dlInfo.getId());
    /*
         * ModifyDistributionList
         */
    req = new ModifyDistributionListRequest(groupId);
    ModifyDistributionListResponse modifyDLResp = invokeJaxb(transport, req);
    dlInfo = modifyDLResp.getDl();
    assertEquals(groupId, dlInfo.getId());
    /*
         * AddDistributionAlias
         */
    req = new AddDistributionListAliasRequest(groupId, TestUtil.getAddress(genGroupNameLocalPart("alias"), DOMAIN_NAME));
    AddDistributionListAliasResponse addDLAliasResp = invokeJaxb(transport, req);
    /*
         * RemoveDistributionAlias
         */
    req = new RemoveDistributionListAliasRequest(groupId, TestUtil.getAddress(genGroupNameLocalPart("alias"), DOMAIN_NAME));
    RemoveDistributionListAliasResponse removeDLAliasResp = invokeJaxb(transport, req);
    /*
         * AddDistributionListMember
         */
    req = new AddDistributionListMemberRequest(groupId, Collections.singleton(TestUtil.getAddress(genAcctNameLocalPart("member"), DOMAIN_NAME)));
    AddDistributionListMemberResponse addDLMemberResp = invokeJaxb(transport, req);
    /*
         * RemoveDistributionListMember
         */
    req = new RemoveDistributionListMemberRequest(groupId, Collections.singleton(TestUtil.getAddress(genAcctNameLocalPart("member"), DOMAIN_NAME)));
    RemoveDistributionListMemberResponse removeDLMemberResp = invokeJaxb(transport, req);
    /*
         * DeleteDistributionList
         */
    req = new DeleteDistributionListRequest(groupId);
    DeleteDistributionListResponse deleteDLResp = invokeJaxb(transport, req);
}
Also used : Group(com.zimbra.cs.account.Group) RemoveDistributionListAliasRequest(com.zimbra.soap.admin.message.RemoveDistributionListAliasRequest) AddDistributionListMemberRequest(com.zimbra.soap.admin.message.AddDistributionListMemberRequest) AddDistributionListAliasRequest(com.zimbra.soap.admin.message.AddDistributionListAliasRequest) RemoveDistributionListMemberResponse(com.zimbra.soap.admin.message.RemoveDistributionListMemberResponse) RemoveDistributionListAliasResponse(com.zimbra.soap.admin.message.RemoveDistributionListAliasResponse) RemoveDistributionListMemberRequest(com.zimbra.soap.admin.message.RemoveDistributionListMemberRequest) AddDistributionListMemberResponse(com.zimbra.soap.admin.message.AddDistributionListMemberResponse) ModifyDistributionListRequest(com.zimbra.soap.admin.message.ModifyDistributionListRequest) DeleteDistributionListRequest(com.zimbra.soap.admin.message.DeleteDistributionListRequest) DeleteDistributionListResponse(com.zimbra.soap.admin.message.DeleteDistributionListResponse) AddDistributionListAliasResponse(com.zimbra.soap.admin.message.AddDistributionListAliasResponse) SoapTransport(com.zimbra.common.soap.SoapTransport) ModifyDistributionListResponse(com.zimbra.soap.admin.message.ModifyDistributionListResponse) Test(org.junit.Test) Bug(com.zimbra.qa.QA.Bug)

Example 48 with SoapTransport

use of com.zimbra.common.soap.SoapTransport in project zm-mailbox by Zimbra.

the class TestDelegatedDL method distributionListActionModify.

@Test
public void distributionListActionModify() throws Exception {
    String ATTR = Provisioning.A_description;
    String VALUE = "test description";
    SoapTransport transport = authUser(USER_OWNER);
    DistributionListAction action = new DistributionListAction(Operation.modify);
    List<KeyValuePair> attrs = Lists.newArrayList(new KeyValuePair(ATTR, VALUE));
    action.setKeyValuePairs(attrs);
    DistributionListActionRequest req = new DistributionListActionRequest(DistributionListSelector.fromName(DL_NAME), action);
    DistributionListActionResponse resp = invokeJaxb(transport, req);
    Group group = prov.getGroup(Key.DistributionListBy.name, DL_NAME);
    assertEquals(VALUE, group.getAttr(ATTR));
}
Also used : Group(com.zimbra.cs.account.Group) KeyValuePair(com.zimbra.soap.type.KeyValuePair) 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 49 with SoapTransport

use of com.zimbra.common.soap.SoapTransport in project zm-mailbox by Zimbra.

the class TestDelegatedDL method noHomeServerZimbraAccount.

/*
     * Verify groups without a home server will get PROXY_ERROR for zimbraAccount
     * SOAP calls.
     */
@Test
@Bug(bug = 66412)
public void noHomeServerZimbraAccount() throws Exception {
    String groupName = TestUtil.getAddress(genGroupNameLocalPart(), DOMAIN_NAME);
    Group group = provUtil.createGroup(groupName, DYNAMIC);
    // remove zimbraMailHost
    Map<String, Object> attrs = Maps.newHashMap();
    attrs.put(Provisioning.A_zimbraMailHost, null);
    prov.modifyAttrs(group, attrs);
    SoapTransport transport = authUser(USER_OWNER);
    /*
         * GetDistributionList
         */
    GetDistributionListRequest getDLreq = new GetDistributionListRequest(DistributionListSelector.fromName(groupName), Boolean.TRUE);
    verifyCaughtProxyError(transport, getDLreq);
    /*
         * DistributionListAction
         */
    DistributionListActionRequest DLActionReq = new DistributionListActionRequest(DistributionListSelector.fromName(groupName), new DistributionListAction(Operation.addMembers));
    verifyCaughtProxyError(transport, DLActionReq);
    /*
         * SubscribeDistributionList
         */
    SubscribeDistributionListRequest subsDLReq = new SubscribeDistributionListRequest(DistributionListSelector.fromName(groupName), DistributionListSubscribeOp.subscribe);
    verifyCaughtProxyError(transport, subsDLReq);
    provUtil.deleteGroup(group);
}
Also used : Group(com.zimbra.cs.account.Group) SubscribeDistributionListRequest(com.zimbra.soap.account.message.SubscribeDistributionListRequest) DistributionListAction(com.zimbra.soap.account.type.DistributionListAction) GetDistributionListRequest(com.zimbra.soap.account.message.GetDistributionListRequest) SoapTransport(com.zimbra.common.soap.SoapTransport) DistributionListActionRequest(com.zimbra.soap.account.message.DistributionListActionRequest) Test(org.junit.Test) Bug(com.zimbra.qa.QA.Bug)

Example 50 with SoapTransport

use of com.zimbra.common.soap.SoapTransport in project zm-mailbox by Zimbra.

the class TestDelegatedDL method getAccountDistributionLists.

@Test
public void getAccountDistributionLists() throws Exception {
    String GROUP_1_NAME = getAddress(genGroupNameLocalPart("1"));
    String GROUP_1_DISPLAY_NAME = "last";
    String GROUP_2_NAME = getAddress(genGroupNameLocalPart("2"));
    String GROUP_2_DISPLAY_NAME = "first";
    String GROUP_3_NAME = getAddress(genGroupNameLocalPart("3"));
    String GROUP_3_DISPLAY_NAME = "first";
    String GROUP_4_NAME = getAddress(genGroupNameLocalPart("4"));
    String GROUP_4_DISPLAY_NAME = "first";
    Group group1 = provUtil.createGroup(GROUP_1_NAME, Collections.singletonMap(Provisioning.A_displayName, (Object) GROUP_1_DISPLAY_NAME), DYNAMIC);
    Group group2 = provUtil.createGroup(GROUP_2_NAME, Collections.singletonMap(Provisioning.A_displayName, (Object) GROUP_2_DISPLAY_NAME), DYNAMIC);
    Group group3 = provUtil.createGroup(GROUP_3_NAME, Collections.singletonMap(Provisioning.A_displayName, (Object) GROUP_3_DISPLAY_NAME), DYNAMIC);
    Group group4 = provUtil.createGroup(GROUP_4_NAME, Collections.singletonMap(Provisioning.A_displayName, (Object) GROUP_4_DISPLAY_NAME), DYNAMIC);
    // create an account
    String ACCT_NAME = getAddress(genAcctNameLocalPart());
    Account acct = provUtil.createAccount(ACCT_NAME);
    // add the account in groups
    prov.addGroupMembers(group1, new String[] { ACCT_NAME });
    prov.addGroupMembers(group2, new String[] { ACCT_NAME });
    prov.addGroupMembers(group3, new String[] { ACCT_NAME });
    // make the account owner of groups
    prov.grantRight(TargetType.dl.getCode(), TargetBy.name, group1.getName(), GranteeType.GT_USER.getCode(), GranteeBy.name, acct.getName(), null, Group.GroupOwner.GROUP_OWNER_RIGHT.getName(), null);
    prov.grantRight(TargetType.dl.getCode(), TargetBy.name, group4.getName(), GranteeType.GT_USER.getCode(), GranteeBy.name, acct.getName(), null, Group.GroupOwner.GROUP_OWNER_RIGHT.getName(), null);
    SoapTransport transport = authUser(ACCT_NAME);
    GetAccountDistributionListsRequest req = new GetAccountDistributionListsRequest(Boolean.TRUE, MemberOfSelector.all, Sets.newHashSet(Provisioning.A_zimbraMailStatus, Provisioning.A_zimbraDistributionListSubscriptionPolicy, Provisioning.A_zimbraDistributionListUnsubscriptionPolicy));
    GetAccountDistributionListsResponse resp = invokeJaxb(transport, req);
    List<String> result = Lists.newArrayList();
    List<DLInfo> groups = resp.getDlList();
    for (DLInfo dlInfo : groups) {
        String id = dlInfo.getId();
        String name = dlInfo.getName();
        String displayName = dlInfo.getDisplayName();
        Boolean isOwner = dlInfo.isOwner();
        Boolean isMember = dlInfo.isMember();
        List<? extends KeyValuePair> attrs = dlInfo.getAttrList();
        List<String> attrValues = Lists.newArrayList();
        for (KeyValuePair attr : attrs) {
            String key = attr.getKey();
            String value = attr.getValue();
            attrValues.add(Verify.makeResultStr(key, value));
        }
        Collections.sort(attrValues);
        result.add(Verify.makeResultStr(id, name, displayName, isOwner, isMember, attrValues));
    }
    List<String> expectedAttrValuesOwner = Lists.newArrayList();
    expectedAttrValuesOwner.add(Verify.makeResultStr(Provisioning.A_zimbraDistributionListSubscriptionPolicy, ZAttrProvisioning.DistributionListSubscriptionPolicy.REJECT.name()));
    expectedAttrValuesOwner.add(Verify.makeResultStr(Provisioning.A_zimbraDistributionListUnsubscriptionPolicy, ZAttrProvisioning.DistributionListUnsubscriptionPolicy.REJECT.name()));
    expectedAttrValuesOwner.add(Verify.makeResultStr(Provisioning.A_zimbraMailStatus, ZAttrProvisioning.MailStatus.enabled.name()));
    List<String> expectedAttrValuesNonOwner = Lists.newArrayList();
    expectedAttrValuesNonOwner.add(Verify.makeResultStr(Provisioning.A_zimbraDistributionListSubscriptionPolicy, ZAttrProvisioning.DistributionListSubscriptionPolicy.REJECT.name()));
    expectedAttrValuesNonOwner.add(Verify.makeResultStr(Provisioning.A_zimbraDistributionListUnsubscriptionPolicy, ZAttrProvisioning.DistributionListUnsubscriptionPolicy.REJECT.name()));
    // result should be sorted by displayName.
    // If displayName are the same, sorted by entry.getLabel()
    Verify.verifyEquals(Lists.newArrayList(Verify.makeResultStr(group2.getId(), group2.getName(), group2.getDisplayName(), Boolean.FALSE, Boolean.TRUE, expectedAttrValuesNonOwner), Verify.makeResultStr(group3.getId(), group3.getName(), group3.getDisplayName(), Boolean.FALSE, Boolean.TRUE, expectedAttrValuesNonOwner), Verify.makeResultStr(group4.getId(), group4.getName(), group4.getDisplayName(), Boolean.TRUE, Boolean.FALSE, expectedAttrValuesOwner), Verify.makeResultStr(group1.getId(), group1.getName(), group1.getDisplayName(), Boolean.TRUE, Boolean.TRUE, expectedAttrValuesOwner)), result);
    // rename group
    String GROUP_NEW_NAME = getAddress(genGroupNameLocalPart("new"));
    prov.renameGroup(group1.getId(), GROUP_NEW_NAME);
    // get membership again, should show the new name
    result.clear();
    groups = resp.getDlList();
    for (DLInfo dlInfo : groups) {
        String id = dlInfo.getId();
        String name = dlInfo.getName();
        String displayName = dlInfo.getDisplayName();
        Boolean isOwner = dlInfo.isOwner();
        Boolean isMember = dlInfo.isMember();
        List<? extends KeyValuePair> attrs = dlInfo.getAttrList();
        List<String> attrValues = Lists.newArrayList();
        for (KeyValuePair attr : attrs) {
            String key = attr.getKey();
            String value = attr.getValue();
            attrValues.add(Verify.makeResultStr(key, value));
        }
        Collections.sort(attrValues);
        result.add(Verify.makeResultStr(id, name, displayName, isOwner, isMember, attrValues));
    }
    // result should be sorted by displayName
    Verify.verifyEquals(Lists.newArrayList(Verify.makeResultStr(group2.getId(), group2.getName(), group2.getDisplayName(), Boolean.FALSE, Boolean.TRUE, expectedAttrValuesNonOwner), Verify.makeResultStr(group3.getId(), group3.getName(), group3.getDisplayName(), Boolean.FALSE, Boolean.TRUE, expectedAttrValuesNonOwner), Verify.makeResultStr(group4.getId(), group4.getName(), group4.getDisplayName(), Boolean.TRUE, Boolean.FALSE, expectedAttrValuesOwner), Verify.makeResultStr(group1.getId(), group1.getName(), group1.getDisplayName(), Boolean.TRUE, Boolean.TRUE, expectedAttrValuesOwner)), result);
}
Also used : Group(com.zimbra.cs.account.Group) Account(com.zimbra.cs.account.Account) KeyValuePair(com.zimbra.soap.type.KeyValuePair) GetAccountDistributionListsResponse(com.zimbra.soap.account.message.GetAccountDistributionListsResponse) GetAccountDistributionListsRequest(com.zimbra.soap.account.message.GetAccountDistributionListsRequest) DLInfo(com.zimbra.soap.account.type.DLInfo) SoapTransport(com.zimbra.common.soap.SoapTransport) Test(org.junit.Test)

Aggregations

SoapTransport (com.zimbra.common.soap.SoapTransport)85 Test (org.junit.Test)66 Account (com.zimbra.cs.account.Account)38 Element (com.zimbra.common.soap.Element)24 Group (com.zimbra.cs.account.Group)23 ServiceException (com.zimbra.common.service.ServiceException)16 SoapFaultException (com.zimbra.common.soap.SoapFaultException)15 DistributionListActionRequest (com.zimbra.soap.account.message.DistributionListActionRequest)12 DistributionListAction (com.zimbra.soap.account.type.DistributionListAction)12 AccountServiceException (com.zimbra.cs.account.AccountServiceException)11 DistributionListActionResponse (com.zimbra.soap.account.message.DistributionListActionResponse)11 ArrayList (java.util.ArrayList)10 SoapProtocol (com.zimbra.common.soap.SoapProtocol)9 Bug (com.zimbra.qa.QA.Bug)9 SoapTest (com.zimbra.qa.unittest.prov.soap.SoapTest)9 CreateSignatureRequest (com.zimbra.soap.account.message.CreateSignatureRequest)9 Signature (com.zimbra.soap.account.type.Signature)9 Domain (com.zimbra.cs.account.Domain)8 GetDistributionListRequest (com.zimbra.soap.account.message.GetDistributionListRequest)8 GetDistributionListResponse (com.zimbra.soap.account.message.GetDistributionListResponse)6