Search in sources :

Example 21 with SoapTransport

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

the class TestDelegatedDL method getDistributionListMembersWithGSA.

/*
     * If GAL sync account is enabled, newly created groups are not synced in the GSA yet.
     * If a GetDistributionListMembersRequest is issued before it's synced, will get
     * NO_SUCH_DISTRIBUTION_LIST exception.
     */
@Test
@Bug(bug = { 72482, 73460 })
public void getDistributionListMembersWithGSA() throws Exception {
    // setup GAL sync account
    GalTestUtil.enableGalSyncAccount(prov, domain.getName(), "galsync1");
    String GROUP_NAME = getAddress(genGroupNameLocalPart());
    // create an owner account
    Account ownerAcct = provUtil.createAccount(genAcctNameLocalPart("owner"), domain);
    Group group = createGroupAndAddOwner(GROUP_NAME, 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);
    Account memberAcct4 = provUtil.createAccount(genAcctNameLocalPart("member4"), 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 not in GSA yet
         */
    // 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);
    /*
         * members should be able to see members even when the list is not in GSA yet
         */
    // auth as a member
    transport = authUser(memberAcct1.getName());
    resp = invokeJaxb(transport, req);
    members = resp.getDlMembers();
    // make sure members are returned sorted
    Verify.verifyEquals(Lists.newArrayList(memberAcct1.getName(), memberAcct2.getName(), memberAcct3.getName()), members);
    /*
         * non-owner, non-member cannot see members when the list is not in GSA yet
         */
    transport = authUser(nonMemberAcct.getName());
    String errorCode = null;
    try {
        invokeJaxb(transport, req);
    } catch (ServiceException e) {
        errorCode = e.getCode();
    }
    assertEquals(AccountServiceException.NO_SUCH_DISTRIBUTION_LIST, errorCode);
    /*
         * re-sync the GSA, so now non-owner/non member can also see the group.
         * Too much trouble re-sync the GSA, just disable and enable again.
         */
    GalTestUtil.disableGalSyncAccount(prov, domain.getName());
    GalTestUtil.enableGalSyncAccount(prov, domain.getName(), "galsync2");
    // now non-owner/non-member can also see the group
    transport = authUser(nonMemberAcct.getName());
    resp = invokeJaxb(transport, req);
    members = resp.getDlMembers();
    // make sure members are returned sorted
    Verify.verifyEquals(Lists.newArrayList(memberAcct1.getName(), memberAcct2.getName(), memberAcct3.getName()), members);
    // add a member
    prov.addGroupMembers(group, new String[] { memberAcct4.getName() });
    // owner can see the new member
    transport = authUser(ownerAcct.getName());
    resp = invokeJaxb(transport, req);
    members = resp.getDlMembers();
    Verify.verifyEquals(Lists.newArrayList(memberAcct1.getName(), memberAcct2.getName(), memberAcct3.getName(), memberAcct4.getName()), members);
    // member can see the new member
    transport = authUser(memberAcct1.getName());
    resp = invokeJaxb(transport, req);
    members = resp.getDlMembers();
    Verify.verifyEquals(Lists.newArrayList(memberAcct1.getName(), memberAcct2.getName(), memberAcct3.getName(), memberAcct4.getName()), members);
    // non-owner, non-member cannot see the new member yet, becasuse the change has not
    // yet synced to the GSA.
    transport = authUser(nonMemberAcct.getName());
    resp = invokeJaxb(transport, req);
    members = resp.getDlMembers();
    // make sure members are returned sorted
    Verify.verifyEquals(Lists.newArrayList(memberAcct1.getName(), memberAcct2.getName(), memberAcct3.getName()), members);
    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 22 with SoapTransport

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

the class TestDelegatedDL method getDistributionListRights.

/*
     * verify rights are returned
     */
@Test
public void getDistributionListRights() throws Exception {
    String GROUP_NAME = getAddress(genGroupNameLocalPart("group"));
    Group group = createGroupAndAddOwner(GROUP_NAME);
    String right1 = Right.RT_sendToDistList;
    String right2 = Right.RT_viewDistList;
    Account grantee1 = provUtil.createAccount(genAcctNameLocalPart("1"), domain);
    Account grantee2 = provUtil.createAccount(genAcctNameLocalPart("2"), domain);
    SoapTransport transport = authUser(USER_OWNER);
    // 
    // grantRights
    // 
    DistributionListAction action = new DistributionListAction(Operation.grantRights);
    DistributionListActionRequest req = new DistributionListActionRequest(DistributionListSelector.fromName(GROUP_NAME), action);
    DistributionListRightSpec dlRight1 = new DistributionListRightSpec(right1);
    dlRight1.addGrantee(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.usr, DistributionListGranteeBy.name, grantee1.getName()));
    dlRight1.addGrantee(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.usr, DistributionListGranteeBy.name, grantee2.getName()));
    DistributionListRightSpec dlRight2 = new DistributionListRightSpec(right2);
    dlRight2.addGrantee(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.all, null, null));
    action.addRight(dlRight1);
    action.addRight(dlRight2);
    DistributionListActionResponse resp = invokeJaxb(transport, req);
    /*
         * verify rights are returned
         */
    GetDistributionListRequest getDLReq = new GetDistributionListRequest(DistributionListSelector.fromName(GROUP_NAME), Boolean.FALSE, right1 + "," + right2);
    GetDistributionListResponse getDLResp = invokeJaxb(transport, getDLReq);
    DistributionListInfo dlInfo = getDLResp.getDl();
    List<? extends DistributionListRightInfo> rights = dlInfo.getRights();
    Set<String> right1GranteeNames = Sets.newHashSet();
    Set<String> right2GranteeNames = Sets.newHashSet();
    for (DistributionListRightInfo rightInfo : rights) {
        String right = rightInfo.getRight();
        List<DistributionListGranteeInfo> grantees = rightInfo.getGrantees();
        if (right1.equals(right)) {
            for (DistributionListGranteeInfo grantee : grantees) {
                right1GranteeNames.add(Verify.makeResultStr(grantee.getType().name(), grantee.getName()));
            }
        } else if (right2.equals(right)) {
            for (DistributionListGranteeInfo grantee : grantees) {
                right2GranteeNames.add(Verify.makeResultStr(grantee.getType().name(), grantee.getName()));
            }
        }
    }
    Verify.verifyEquals(Sets.newHashSet(Verify.makeResultStr(GranteeType.GT_USER.getCode(), grantee1.getName()), Verify.makeResultStr(GranteeType.GT_USER.getCode(), grantee2.getName())), right1GranteeNames);
    Verify.verifyEquals(Sets.newHashSet(Verify.makeResultStr(GranteeType.GT_AUTHUSER.getCode(), "null")), right2GranteeNames);
}
Also used : GetDistributionListResponse(com.zimbra.soap.account.message.GetDistributionListResponse) Group(com.zimbra.cs.account.Group) Account(com.zimbra.cs.account.Account) DistributionListInfo(com.zimbra.soap.account.type.DistributionListInfo) DistributionListGranteeInfo(com.zimbra.soap.account.type.DistributionListGranteeInfo) DistributionListActionResponse(com.zimbra.soap.account.message.DistributionListActionResponse) GetDistributionListRequest(com.zimbra.soap.account.message.GetDistributionListRequest) DistributionListRightInfo(com.zimbra.soap.account.type.DistributionListRightInfo) DistributionListActionRequest(com.zimbra.soap.account.message.DistributionListActionRequest) DistributionListGranteeSelector(com.zimbra.soap.account.type.DistributionListGranteeSelector) DistributionListAction(com.zimbra.soap.account.type.DistributionListAction) DistributionListRightSpec(com.zimbra.soap.account.type.DistributionListRightSpec) SoapTransport(com.zimbra.common.soap.SoapTransport) Test(org.junit.Test)

Example 23 with SoapTransport

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

the class TestDelegatedDL method getDistributionListAdmin.

/*
     * Test the owners element in zimbraAdmin:GetDistributionList
     */
@Test
public void getDistributionListAdmin() throws Exception {
    SoapTransport transport = authAdmin(ADMIN);
    com.zimbra.soap.admin.message.GetDistributionListRequest req = new com.zimbra.soap.admin.message.GetDistributionListRequest(com.zimbra.soap.admin.type.DistributionListSelector.fromName(DL_NAME));
    com.zimbra.soap.admin.message.GetDistributionListResponse resp = invokeJaxb(transport, req);
    com.zimbra.soap.admin.type.DistributionListInfo dlInfo = resp.getDl();
    String dlId = dlInfo.getId();
    Group group = prov.getGroup(Key.DistributionListBy.name, DL_NAME);
    assertNotNull(group);
    assertEquals(group.getId(), dlId);
    /*
        System.out.println("\nAttrs:");
        List<com.zimbra.soap.admin.type.Attr> attrs = dlInfo.getAttrList();
        for (com.zimbra.soap.admin.type.Attr attr : attrs) {
            System.out.println(attr.getN() + ", " + attr.getValue());
        }
        */
    List<GranteeInfo> dlOwners = dlInfo.getOwners();
    assertEquals(1, dlOwners.size());
    for (GranteeInfo 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 : Group(com.zimbra.cs.account.Group) GranteeInfo(com.zimbra.soap.admin.type.GranteeInfo) DistributionListGranteeInfo(com.zimbra.soap.account.type.DistributionListGranteeInfo) GetDistributionListRequest(com.zimbra.soap.account.message.GetDistributionListRequest) SoapTransport(com.zimbra.common.soap.SoapTransport) Test(org.junit.Test)

Example 24 with SoapTransport

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

the class TestDelegatedDL method ownerIsGroup.

/*
     * owner of a group is a group
     */
@Test
public void ownerIsGroup() throws Exception {
    Group ownedGroup = provUtil.createGroup(genGroupNameLocalPart("owned"), domain, DYNAMIC);
    Group owningGroup = provUtil.createGroup(genGroupNameLocalPart("owning"), domain, DYNAMIC);
    /*
         * add members to owning group
         */
    Account acctInOwningGroup = provUtil.createAccount("acctInOwningGroup", domain);
    prov.addGroupMembers(owningGroup, new String[] { acctInOwningGroup.getName() });
    /*
         * grant ownDistList right to owningGroup on ownedGroup
         */
    prov.grantRight(TargetType.dl.getCode(), TargetBy.name, ownedGroup.getName(), GranteeType.GT_GROUP.getCode(), GranteeBy.name, owningGroup.getName(), null, Group.GroupOwner.GROUP_OWNER_RIGHT.getName(), null);
    /*
         * auth as acctInOwningGroup
         */
    SoapTransport transport = authUser(acctInOwningGroup.getName());
    /*
         * try to add member in ownedGroup
         */
    // addMembers
    DistributionListAction action = new DistributionListAction(Operation.addMembers);
    DistributionListActionRequest req = new DistributionListActionRequest(DistributionListSelector.fromName(ownedGroup.getName()), action);
    String MEMBER1 = "member1@test.com";
    String MEMBER2 = "member2@test.com";
    action.addMember(MEMBER1);
    action.addMember(MEMBER2);
    DistributionListActionResponse resp = invokeJaxb(transport, req);
    Group group = prov.getGroup(Key.DistributionListBy.name, ownedGroup.getName());
    Set<String> members = group.getAllMembersSet();
    assertEquals(2, members.size());
    assertTrue(members.contains(MEMBER1));
    assertTrue(members.contains(MEMBER2));
    provUtil.deleteAccount(acctInOwningGroup);
    provUtil.deleteGroup(owningGroup);
    provUtil.deleteGroup(ownedGroup);
}
Also used : Group(com.zimbra.cs.account.Group) Account(com.zimbra.cs.account.Account) 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 25 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)

Aggregations

SoapTransport (com.zimbra.common.soap.SoapTransport)89 Test (org.junit.Test)69 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)18 SoapFaultException (com.zimbra.common.soap.SoapFaultException)16 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 SoapTest (com.zimbra.qa.unittest.prov.soap.SoapTest)10 ArrayList (java.util.ArrayList)10 SoapProtocol (com.zimbra.common.soap.SoapProtocol)9 Bug (com.zimbra.qa.QA.Bug)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