Search in sources :

Example 11 with SoapTransport

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

the class TestGetInfo method discoverRights.

@Test
public void discoverRights() throws Exception {
    Account acct = provUtil.createAccount(genAcctNameLocalPart(), domain);
    Group group = provUtil.createGroup(genGroupNameLocalPart(), domain, false);
    prov.grantRight(TargetType.domain.getCode(), TargetBy.name, domain.getName(), GranteeType.GT_USER.getCode(), GranteeBy.name, acct.getName(), null, User.R_createDistList.getName(), null);
    prov.grantRight(TargetType.dl.getCode(), TargetBy.name, group.getName(), GranteeType.GT_USER.getCode(), GranteeBy.name, acct.getName(), null, User.R_sendToDistList.getName(), null);
    SoapTransport transport = authUser(acct.getName());
    GetInfoRequest req = new GetInfoRequest();
    req.addRight(User.R_createDistList.getName());
    req.addRight(User.R_sendToDistList.getName());
    GetInfoResponse resp = invokeJaxb(transport, req);
    List<DiscoverRightsInfo> rightsInfo = resp.getDiscoveredRights();
    Set<String> result = Sets.newHashSet();
    for (DiscoverRightsInfo rightInfo : rightsInfo) {
        String right = rightInfo.getRight();
        List<DiscoverRightsTarget> targets = rightInfo.getTargets();
        for (DiscoverRightsTarget target : targets) {
            String id = target.getId();
            String name = target.getName();
            String type = target.getType().toString();
            result.add(Verify.makeResultStr(right, id, name, type));
        }
    }
    Verify.verifyEquals(Sets.newHashSet(Verify.makeResultStr(User.R_createDistList.getName(), domain.getId(), domain.getName(), TargetType.domain.getCode()), Verify.makeResultStr(User.R_sendToDistList.getName(), group.getId(), group.getName(), TargetType.dl.getCode())), result);
}
Also used : Account(com.zimbra.cs.account.Account) Group(com.zimbra.cs.account.Group) GetInfoResponse(com.zimbra.soap.account.message.GetInfoResponse) DiscoverRightsInfo(com.zimbra.soap.account.type.DiscoverRightsInfo) DiscoverRightsTarget(com.zimbra.soap.account.type.DiscoverRightsTarget) GetInfoRequest(com.zimbra.soap.account.message.GetInfoRequest) SoapTransport(com.zimbra.common.soap.SoapTransport) Test(org.junit.Test)

Example 12 with SoapTransport

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

the class TestSearchCalendarResources method searchByFilter.

private void searchByFilter(boolean ldap, String domainName) throws Exception {
    SoapTransport transport = authUser(TestUtil.getAddress(AUTHED_USER, domainName));
    Element request = Element.create(transport.getRequestProtocol(), AccountConstants.SEARCH_CALENDAR_RESOURCES_REQUEST);
    request.addAttribute(MailConstants.A_QUERY_OFFSET, 1);
    request.addAttribute(MailConstants.A_QUERY_LIMIT, 1);
    Element eSearchFilter = request.addElement(AccountConstants.E_ENTRY_SEARCH_FILTER);
    Element eConds = eSearchFilter.addElement(AccountConstants.E_ENTRY_SEARCH_FILTER_MULTICOND);
    Element eCondResType = eConds.addElement(AccountConstants.E_ENTRY_SEARCH_FILTER_SINGLECOND);
    eCondResType.addAttribute(AccountConstants.A_ENTRY_SEARCH_FILTER_ATTR, "zimbraCalResType");
    eCondResType.addAttribute(AccountConstants.A_ENTRY_SEARCH_FILTER_OP, Operator.eq.name());
    eCondResType.addAttribute(AccountConstants.A_ENTRY_SEARCH_FILTER_VALUE, "Location");
    Element eCondResCapacity = eConds.addElement(AccountConstants.E_ENTRY_SEARCH_FILTER_SINGLECOND);
    eCondResCapacity.addAttribute(AccountConstants.A_ENTRY_SEARCH_FILTER_ATTR, "zimbraCalResCapacity");
    eCondResCapacity.addAttribute(AccountConstants.A_ENTRY_SEARCH_FILTER_OP, Operator.ge.name());
    eCondResCapacity.addAttribute(AccountConstants.A_ENTRY_SEARCH_FILTER_VALUE, "15");
    Element eCondResSite = eConds.addElement(AccountConstants.E_ENTRY_SEARCH_FILTER_SINGLECOND);
    eCondResSite.addAttribute(AccountConstants.A_ENTRY_SEARCH_FILTER_ATTR, "zimbraCalResSite");
    eCondResSite.addAttribute(AccountConstants.A_ENTRY_SEARCH_FILTER_OP, Operator.has.name());
    eCondResSite.addAttribute(AccountConstants.A_ENTRY_SEARCH_FILTER_VALUE, SITE_WORD_1);
    Element response = transport.invoke(request);
    boolean paginationSupported = response.getAttributeBool(AccountConstants.A_PAGINATION_SUPPORTED);
    boolean found1 = false;
    boolean found2 = false;
    boolean found3 = false;
    List<CalendarResource> resources = new ArrayList<CalendarResource>();
    for (Element eResource : response.listElements(AccountConstants.E_CALENDAR_RESOURCE)) {
        CalendarResource resource = new MockCalendarResource(eResource);
        resources.add(resource);
        if (resource.getName().equals(TestUtil.getAddress(ROOM_1, domainName))) {
            found1 = true;
        }
        if (resource.getName().equals(TestUtil.getAddress(ROOM_2, domainName))) {
            found2 = true;
        }
        if (resource.getName().equals(TestUtil.getAddress(ROOM_3, domainName))) {
            found3 = true;
        }
    }
    if (ldap) {
        // pagination is not supported
        Assert.assertFalse(paginationSupported);
        // offset and limit are not honored
        Assert.assertEquals(2, resources.size());
        // not matching capacity requirement
        Assert.assertTrue(!found1);
        Assert.assertTrue(found2);
        Assert.assertTrue(found3);
    } else {
        // pagination is supported
        Assert.assertTrue(paginationSupported);
        // offset and limit are honored
        Assert.assertEquals(1, resources.size());
        // not matching capacity requirement
        Assert.assertTrue(!found1);
        Assert.assertTrue(!found2);
        // not within specified offset, at offset 0
        Assert.assertTrue(found3);
    // (gal sync acount mailbox search is by dateDesc order)
    }
}
Also used : Element(com.zimbra.common.soap.Element) ArrayList(java.util.ArrayList) CalendarResource(com.zimbra.cs.account.CalendarResource) SoapTransport(com.zimbra.common.soap.SoapTransport)

Example 13 with SoapTransport

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

the class TestSearchCalendarResources method chineseChar.

@Test
public void chineseChar() throws Exception {
    Map<String, Object> attrs = Maps.newHashMap();
    attrs.put(Provisioning.A_displayName, "\u4e2d\u6587");
    attrs.put(Provisioning.A_zimbraCalResType, Provisioning.CalResType.Location.name());
    attrs.put(Provisioning.A_zimbraCalResSite, "\u4e2d\u6587");
    CalendarResource cr = provUtil.createCalendarResource("chineseChar", domain, attrs);
    String crName = cr.getName();
    /*
         * 
         filter="(&(&(&(|(displayName=*\E4\B8\AD\E6\96\87*)(cn=*\E4\B8\AD\E6\96\87*)(sn=*\E4\B8\AD\E6\96\87*)(givenName=*\E4\B8\AD\E6\96\87*)(?mail=*\E4\B8\AD\E6\96\87*)(?zimbraMailDeliveryAddress=*\E4\B8\AD\E6\96\87*)(?zimbraMailAlias=*\E4\B8\AD\E6\96\87*))(objectClass=zimbraCalendarResource)(zimbraAccountStatus=active))(!(zimbraHideInGal=TRUE))(!(zimbraIsSystemResource=TRUE)))(&(zimbraCalResType=location)(zimbraCalResSite=*\E4\B8\AD\E6\96\87*)))"
         */
    SoapTransport transport = authUser("user1@phoebe.mbp");
    SearchCalendarResourcesRequest req = new SearchCalendarResourcesRequest("\u4e2d\u6587");
    EntrySearchFilterMultiCond conds = new EntrySearchFilterMultiCond();
    EntrySearchFilterSingleCond cond;
    cond = new EntrySearchFilterSingleCond();
    cond.setAttr(Provisioning.A_zimbraCalResType);
    cond.setOp("eq");
    cond.setValue("Location");
    conds.addCondition(cond);
    cond = new EntrySearchFilterSingleCond();
    cond.setAttr(Provisioning.A_zimbraCalResSite);
    cond.setOp("has");
    cond.setValue("\u4e2d\u6587");
    conds.addCondition(cond);
    EntrySearchFilterInfo filter = new EntrySearchFilterInfo();
    filter.setCondition(conds);
    req.setSearchFilter(filter);
    SearchCalendarResourcesResponse resp = invokeJaxb(transport, req);
    List<CalendarResourceInfo> crInfo = resp.getCalendarResources();
    assertEquals(1, crInfo.size());
    assertEquals(crName, crInfo.get(0).getName());
}
Also used : SearchCalendarResourcesResponse(com.zimbra.soap.account.message.SearchCalendarResourcesResponse) CalendarResourceInfo(com.zimbra.soap.account.type.CalendarResourceInfo) EntrySearchFilterMultiCond(com.zimbra.soap.account.type.EntrySearchFilterMultiCond) SearchCalendarResourcesRequest(com.zimbra.soap.account.message.SearchCalendarResourcesRequest) CalendarResource(com.zimbra.cs.account.CalendarResource) EntrySearchFilterInfo(com.zimbra.soap.account.type.EntrySearchFilterInfo) SoapTransport(com.zimbra.common.soap.SoapTransport) EntrySearchFilterSingleCond(com.zimbra.soap.account.type.EntrySearchFilterSingleCond) Test(org.junit.Test)

Example 14 with SoapTransport

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

the class TestSearchCalendarResources method reservedChar.

@Test
@Bug(bug = 67045)
public void reservedChar() throws Exception {
    Map<String, Object> attrs = Maps.newHashMap();
    attrs.put(Provisioning.A_displayName, "name()");
    attrs.put(Provisioning.A_zimbraCalResType, Provisioning.CalResType.Location.name());
    attrs.put(Provisioning.A_zimbraCalResSite, "Site()");
    attrs.put(Provisioning.A_zimbraCalResCapacity, "10");
    attrs.put(Provisioning.A_zimbraCalResBuilding, "Building()");
    attrs.put(Provisioning.A_zimbraNotes, "Notes()");
    attrs.put(Provisioning.A_zimbraCalResFloor, "()");
    CalendarResource cr = provUtil.createCalendarResource("reservedChar", domain, attrs);
    String crName = cr.getName();
    /*
        <SearchCalendarResourcesRequest xmlns="urn:zimbraAccount" 
            attrs="fullName,email,zimbraCalResLocationDisplayName,zimbraCalResContactEmail,notes,zimbraCalResType">
            <name>()</name>
            <searchFilter>
                <conds>
                  <cond op="eq" value="Location" attr="zimbraCalResType"/>
                  <cond op="has" value="()" attr="zimbraCalResSite"/>
                  <cond op="ge" value="9" attr="zimbraCalResCapacity"/>
                  <cond op="has" value="()" attr="zimbraCalResBuilding"/>
                  <cond op="has" value="()" attr="zimbraNotes"/>
                  <cond op="eq" value="()" attr="zimbraCalResFloor"/>
                </conds>
            </searchFilter>
        </SearchCalendarResourcesRequest>
        
        Expected filer:
        filter="(&(&(&(|(displayName=*\28\29*)(cn=*\28\29*)(sn=*\28\29*)(givenName=*\28\29*)(mail=*\28\29*)(zimbraMailDeliveryAddress=*\28\29*)(zimbraMailAlias=*\28\29*))(objectClass=zimbraCalendarResource)(zimbraAccountStatus=active))(!(zimbraHideInGal=TRUE))(!(zimbraIsSystemResource=TRUE)))(&(zimbraCalResType=location)(zimbraCalResSite=*\28\29*)(zimbraCalResCapacity>=9)(zimbraCalResBuilding=*\28\29*)(zimbraNotes=*\28\29*)(zimbraCalResFloor=\28\29)))"
        */
    SoapTransport transport = authUser("user1@phoebe.mbp");
    SearchCalendarResourcesRequest req = new SearchCalendarResourcesRequest("()");
    EntrySearchFilterMultiCond conds = new EntrySearchFilterMultiCond();
    EntrySearchFilterSingleCond cond;
    cond = new EntrySearchFilterSingleCond();
    cond.setAttr(Provisioning.A_zimbraCalResType);
    cond.setOp("eq");
    cond.setValue("Location");
    conds.addCondition(cond);
    cond = new EntrySearchFilterSingleCond();
    cond.setAttr(Provisioning.A_zimbraCalResSite);
    cond.setOp("has");
    cond.setValue("()");
    conds.addCondition(cond);
    cond = new EntrySearchFilterSingleCond();
    cond.setAttr(Provisioning.A_zimbraCalResCapacity);
    cond.setOp("ge");
    cond.setValue("9");
    conds.addCondition(cond);
    cond = new EntrySearchFilterSingleCond();
    cond.setAttr(Provisioning.A_zimbraCalResBuilding);
    cond.setOp("has");
    cond.setValue("()");
    conds.addCondition(cond);
    cond = new EntrySearchFilterSingleCond();
    cond.setAttr(Provisioning.A_zimbraNotes);
    cond.setOp("has");
    cond.setValue("()");
    conds.addCondition(cond);
    cond = new EntrySearchFilterSingleCond();
    cond.setAttr(Provisioning.A_zimbraCalResFloor);
    cond.setOp("eq");
    cond.setValue("()");
    conds.addCondition(cond);
    EntrySearchFilterInfo filter = new EntrySearchFilterInfo();
    filter.setCondition(conds);
    req.setSearchFilter(filter);
    SearchCalendarResourcesResponse resp = invokeJaxb(transport, req);
    List<CalendarResourceInfo> crInfo = resp.getCalendarResources();
    assertEquals(1, crInfo.size());
    assertEquals(crName, crInfo.get(0).getName());
}
Also used : SearchCalendarResourcesResponse(com.zimbra.soap.account.message.SearchCalendarResourcesResponse) CalendarResourceInfo(com.zimbra.soap.account.type.CalendarResourceInfo) EntrySearchFilterMultiCond(com.zimbra.soap.account.type.EntrySearchFilterMultiCond) SearchCalendarResourcesRequest(com.zimbra.soap.account.message.SearchCalendarResourcesRequest) CalendarResource(com.zimbra.cs.account.CalendarResource) EntrySearchFilterInfo(com.zimbra.soap.account.type.EntrySearchFilterInfo) SoapTransport(com.zimbra.common.soap.SoapTransport) EntrySearchFilterSingleCond(com.zimbra.soap.account.type.EntrySearchFilterSingleCond) Test(org.junit.Test) Bug(com.zimbra.qa.QA.Bug)

Example 15 with SoapTransport

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

the class TestBatchRequest method batchReqWithoutCsrfToken.

@Test
public void batchReqWithoutCsrfToken() throws Exception {
    Account acct = provUtil.createAccount(genAcctNameLocalPart(), domain);
    boolean csrfEnabled = Boolean.TRUE;
    SoapTransport transport = authUser(acct.getName(), csrfEnabled, Boolean.FALSE);
    Element request = new Element.XMLElement(ZimbraNamespace.E_BATCH_REQUEST);
    String sigContent = "xss&lt;script&gt;alert(\"XSS\")&lt;/script&gt;&lt;a href=javascript:alert(\"XSS\")&gt;&lt;";
    Signature sig = new Signature("test_id", "testSig", sigContent, "text/html");
    CreateSignatureRequest req = new CreateSignatureRequest(sig);
    SoapProtocol proto = SoapProtocol.Soap12;
    Element sigReq = JaxbUtil.jaxbToElement(req, proto.getFactory());
    request.addElement(sigReq);
    try {
        transport.invoke(request, false, false, null);
    } catch (SoapFaultException e) {
        assertNotNull(e);
        Assert.assertEquals(true, e.getCode().contains("AUTH_REQUIRED"));
    }
}
Also used : Account(com.zimbra.cs.account.Account) CreateSignatureRequest(com.zimbra.soap.account.message.CreateSignatureRequest) Element(com.zimbra.common.soap.Element) Signature(com.zimbra.soap.account.type.Signature) SoapProtocol(com.zimbra.common.soap.SoapProtocol) SoapTransport(com.zimbra.common.soap.SoapTransport) SoapFaultException(com.zimbra.common.soap.SoapFaultException) 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