Search in sources :

Example 1 with DistributionListGranteeInfoInterface

use of com.zimbra.soap.base.DistributionListGranteeInfoInterface in project zm-mailbox by Zimbra.

the class TestDelegatedDL method distributionListActionSetBadOwners.

@Test
@Bug(bug = 72791)
public void distributionListActionSetBadOwners() throws Exception {
    String GROUP_NAME = getAddress(genGroupNameLocalPart());
    Group group = createGroupAndAddOwner(GROUP_NAME);
    Account owner1 = provUtil.createAccount(genAcctNameLocalPart("1"), domain);
    Account owner2 = provUtil.createAccount(genAcctNameLocalPart("2"), domain);
    Account owner3 = provUtil.createAccount(genAcctNameLocalPart("3"), domain);
    SoapTransport transport = authUser(USER_OWNER);
    //
    // setOwners: some good owners an a bogus owner (not a user)
    //
    DistributionListAction action = new DistributionListAction(Operation.setOwners);
    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()));
    action.addOwner(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.usr, DistributionListGranteeBy.name, owner3.getName()));
    action.addOwner(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.usr, DistributionListGranteeBy.name, "bogus@bogus.com"));
    String errorCode = null;
    try {
        DistributionListActionResponse resp = invokeJaxb(transport, req);
    } catch (ServiceException e) {
        errorCode = e.getCode();
    }
    assertEquals(AccountServiceException.NO_SUCH_ACCOUNT, errorCode);
    //
    // verify owners are NOT replaced
    //
    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(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) AccountServiceException(com.zimbra.cs.account.AccountServiceException) ServiceException(com.zimbra.common.service.ServiceException) DistributionListAction(com.zimbra.soap.account.type.DistributionListAction) SoapTransport(com.zimbra.common.soap.SoapTransport) Test(org.junit.Test) Bug(com.zimbra.qa.QA.Bug)

Example 2 with DistributionListGranteeInfoInterface

use of com.zimbra.soap.base.DistributionListGranteeInfoInterface in project zm-mailbox by Zimbra.

the class TestDelegatedDL method distributionListActionSetOwners.

@Test
public void distributionListActionSetOwners() 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);
    Account owner3 = provUtil.createAccount(genAcctNameLocalPart("3"), domain);
    SoapTransport transport = authUser(USER_OWNER);
    //
    // setOwners
    //
    DistributionListAction action = new DistributionListAction(Operation.setOwners);
    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()));
    action.addOwner(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.email, DistributionListGranteeBy.name, owner3.getName()));
    DistributionListActionResponse resp = invokeJaxb(transport, req);
    //
    // verify owners are replaced
    //
    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(4, owners.size());
    Verify.verifyEquals(Sets.newHashSet(USER_OWNER, owner1.getName(), owner2.getName(), owner3.getName()), ownerNames);
    /*
         * test invalid grantee type for owner
         */
    action = new DistributionListAction(Operation.setOwners);
    req = new DistributionListActionRequest(DistributionListSelector.fromName(GROUP_NAME), action);
    action.addOwner(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.email, DistributionListGranteeBy.name, "user@external.com"));
    String errCode = null;
    try {
        resp = invokeJaxb(transport, req);
    } catch (ServiceException e) {
        errCode = e.getCode();
    }
    assertEquals(ServiceException.INVALID_REQUEST, errCode);
    // remove all owners
    action = new DistributionListAction(Operation.setOwners);
    req = new DistributionListActionRequest(DistributionListSelector.fromName(GROUP_NAME), action);
    resp = invokeJaxb(transport, req);
    getDLReq = new GetDistributionListRequest(DistributionListSelector.fromName(GROUP_NAME), Boolean.TRUE);
    getDLResp = invokeJaxb(transport, getDLReq);
    dlInfo = getDLResp.getDl();
    owners = dlInfo.getOwners();
    assertEquals(0, owners.size());
}
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) AccountServiceException(com.zimbra.cs.account.AccountServiceException) ServiceException(com.zimbra.common.service.ServiceException) DistributionListAction(com.zimbra.soap.account.type.DistributionListAction) SoapTransport(com.zimbra.common.soap.SoapTransport) Test(org.junit.Test)

Example 3 with DistributionListGranteeInfoInterface

use of com.zimbra.soap.base.DistributionListGranteeInfoInterface 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 4 with DistributionListGranteeInfoInterface

use of com.zimbra.soap.base.DistributionListGranteeInfoInterface 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)

Aggregations

SoapTransport (com.zimbra.common.soap.SoapTransport)4 Group (com.zimbra.cs.account.Group)4 GetDistributionListRequest (com.zimbra.soap.account.message.GetDistributionListRequest)4 GetDistributionListResponse (com.zimbra.soap.account.message.GetDistributionListResponse)4 DistributionListInfo (com.zimbra.soap.account.type.DistributionListInfo)4 DistributionListGranteeInfoInterface (com.zimbra.soap.base.DistributionListGranteeInfoInterface)4 Test (org.junit.Test)4 Account (com.zimbra.cs.account.Account)3 DistributionListActionRequest (com.zimbra.soap.account.message.DistributionListActionRequest)3 DistributionListActionResponse (com.zimbra.soap.account.message.DistributionListActionResponse)3 DistributionListAction (com.zimbra.soap.account.type.DistributionListAction)3 DistributionListGranteeSelector (com.zimbra.soap.account.type.DistributionListGranteeSelector)3 ServiceException (com.zimbra.common.service.ServiceException)2 AccountServiceException (com.zimbra.cs.account.AccountServiceException)2 Bug (com.zimbra.qa.QA.Bug)1 KeyValuePair (com.zimbra.soap.type.KeyValuePair)1