Search in sources :

Example 31 with SoapTransport

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

the class TestCheckRights method grantRight.

private void grantRight(Account target, GranteeType granteeType, NamedEntry grantee, String right) throws Exception {
    SoapTransport transport = authUser(target.getName());
    GrantRightsRequest req = new GrantRightsRequest();
    AccountACEInfo ace = new AccountACEInfo(granteeType, right);
    ace.setZimbraId(grantee.getId());
    req.addAce(ace);
    GrantRightsResponse resp = invokeJaxb(transport, req);
}
Also used : AccountACEInfo(com.zimbra.soap.account.type.AccountACEInfo) GrantRightsRequest(com.zimbra.soap.account.message.GrantRightsRequest) GrantRightsResponse(com.zimbra.soap.account.message.GrantRightsResponse) SoapTransport(com.zimbra.common.soap.SoapTransport)

Example 32 with SoapTransport

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

the class TestCsrfRequest method getCreateSigWithCsrfFeatureDisbaledAndAuthTokenIsCsrfEnabled.

@Test
public void getCreateSigWithCsrfFeatureDisbaledAndAuthTokenIsCsrfEnabled() throws Exception {
    Map<String, Object> attrs = new HashMap<String, Object>();
    attrs.put(Provisioning.A_zimbraCsrfTokenCheckEnabled, "FALSE");
    prov.modifyAttrs(prov.getConfig(), attrs, true);
    Account acct = provUtil.createAccount(genAcctNameLocalPart(), domain);
    boolean csrfEnabled = Boolean.TRUE;
    SoapTransport transport = authUser(acct.getName(), csrfEnabled, Boolean.FALSE);
    String sigContent = "xss&lt;script&gt;alert(\"XSS\")&lt;/script&gt;&lt;a href=javascript:alert(\"XSS\")&gt;&lt;";
    Signature sig = new Signature(null, "testSig", sigContent, "text/html");
    CreateSignatureRequest req = new CreateSignatureRequest(sig);
    SoapProtocol proto = SoapProtocol.Soap12;
    Element sigReq = JaxbUtil.jaxbToElement(req, proto.getFactory());
    try {
        Element element = transport.invoke(sigReq, false, false, null);
        String sigt = element.getElement("signature").getAttribute("id");
        assertNotNull(sigt);
    } catch (SoapFaultException e) {
        e.printStackTrace();
        assertNull(e);
    }
}
Also used : Account(com.zimbra.cs.account.Account) CreateSignatureRequest(com.zimbra.soap.account.message.CreateSignatureRequest) HashMap(java.util.HashMap) Signature(com.zimbra.soap.account.type.Signature) Element(com.zimbra.common.soap.Element) SoapProtocol(com.zimbra.common.soap.SoapProtocol) SoapTransport(com.zimbra.common.soap.SoapTransport) SoapFaultException(com.zimbra.common.soap.SoapFaultException) Test(org.junit.Test)

Example 33 with SoapTransport

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

the class TestDiscoverRights method displayName.

/*
     * verify display name is returned in DiscoverRights and discovered targets
     * are sorted by displayName
     */
@Test
@Bug(bug = 68225)
public void displayName() throws Exception {
    Account acct = provUtil.createAccount(genAcctNameLocalPart(), domain);
    String GROUP_1_NAME = getAddress(genGroupNameLocalPart("1"));
    String GROUP_1_DISPLAY_NAME = "third";
    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";
    Group group1 = provUtil.createGroup(GROUP_1_NAME, Collections.singletonMap(Provisioning.A_displayName, (Object) GROUP_1_DISPLAY_NAME), false);
    Group group2 = provUtil.createGroup(GROUP_2_NAME, Collections.singletonMap(Provisioning.A_displayName, (Object) GROUP_2_DISPLAY_NAME), false);
    Group group3 = provUtil.createGroup(GROUP_3_NAME, Collections.singletonMap(Provisioning.A_displayName, (Object) GROUP_3_DISPLAY_NAME), false);
    String RIGHT_NAME = User.R_ownDistList.getName();
    prov.grantRight(TargetType.dl.getCode(), TargetBy.name, group1.getName(), GranteeType.GT_USER.getCode(), GranteeBy.name, acct.getName(), null, RIGHT_NAME, null);
    prov.grantRight(TargetType.dl.getCode(), TargetBy.name, group2.getName(), GranteeType.GT_USER.getCode(), GranteeBy.name, acct.getName(), null, RIGHT_NAME, null);
    prov.grantRight(TargetType.dl.getCode(), TargetBy.name, group3.getName(), GranteeType.GT_USER.getCode(), GranteeBy.name, acct.getName(), null, RIGHT_NAME, null);
    SoapTransport transport = authUser(acct.getName());
    DiscoverRightsRequest req = new DiscoverRightsRequest(Collections.singletonList(RIGHT_NAME));
    DiscoverRightsResponse resp = invokeJaxb(transport, req);
    List<DiscoverRightsInfo> rightsInfo = resp.getDiscoveredRights();
    assertEquals(1, rightsInfo.size());
    List<String> result = Lists.newArrayList();
    for (DiscoverRightsInfo rightInfo : rightsInfo) {
        List<DiscoverRightsTarget> targets = rightInfo.getTargets();
        for (DiscoverRightsTarget target : targets) {
            String id = target.getId();
            String name = target.getName();
            String displayName = target.getDisplayName();
            result.add(Verify.makeResultStr(id, name, displayName));
        }
    }
    // 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()), Verify.makeResultStr(group3.getId(), group3.getName(), group3.getDisplayName()), Verify.makeResultStr(group1.getId(), group1.getName(), group1.getDisplayName())), result);
}
Also used : Account(com.zimbra.cs.account.Account) Group(com.zimbra.cs.account.Group) DiscoverRightsRequest(com.zimbra.soap.account.message.DiscoverRightsRequest) DiscoverRightsInfo(com.zimbra.soap.account.type.DiscoverRightsInfo) DiscoverRightsResponse(com.zimbra.soap.account.message.DiscoverRightsResponse) DiscoverRightsTarget(com.zimbra.soap.account.type.DiscoverRightsTarget) SoapTransport(com.zimbra.common.soap.SoapTransport) Test(org.junit.Test) Bug(com.zimbra.qa.QA.Bug)

Example 34 with SoapTransport

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

the class TestGetSignature method getSignature.

@Test
public void getSignature() throws Exception {
    Account acct = provUtil.createAccount(genAcctNameLocalPart(), domain);
    boolean csrfEnabled = Boolean.FALSE;
    SoapTransport transport = authUser(acct.getName(), csrfEnabled, Boolean.FALSE);
    String sigContent = "xss&lt;script&gt;alert(\"XSS\")&lt;/script&gt;&lt;a href=javascript:alert(\"XSS\")&gt;&lt;";
    Signature sig = new Signature(null, "testSig", sigContent, "text/html");
    CreateSignatureRequest req = new CreateSignatureRequest(sig);
    SoapProtocol proto = SoapProtocol.Soap12;
    Element sigReq = JaxbUtil.jaxbToElement(req, proto.getFactory());
    try {
        Element element = transport.invoke(sigReq, false, false, null);
        String sigt = element.getElement("signature").getAttribute("id");
        assertNotNull(sigt);
    } catch (SoapFaultException e) {
        e.printStackTrace();
        assertNull(e);
    }
    GetSignaturesRequest getSigReq = new GetSignaturesRequest();
    sigReq = JaxbUtil.jaxbToElement(getSigReq, proto.getFactory());
    try {
        Element element = transport.invoke(sigReq, false, false, null);
        String sigtContent = element.getElement("signature").getElement("content").getText();
        assertNotNull(sigContent);
        int index = sigtContent.indexOf("alert(\"XSS\")");
        Assert.assertEquals(-1, index);
    } catch (SoapFaultException e) {
        e.printStackTrace();
        assertNull(e);
    }
}
Also used : Account(com.zimbra.cs.account.Account) CreateSignatureRequest(com.zimbra.soap.account.message.CreateSignatureRequest) GetSignaturesRequest(com.zimbra.soap.account.message.GetSignaturesRequest) Signature(com.zimbra.soap.account.type.Signature) Element(com.zimbra.common.soap.Element) SoapProtocol(com.zimbra.common.soap.SoapProtocol) SoapTransport(com.zimbra.common.soap.SoapTransport) SoapFaultException(com.zimbra.common.soap.SoapFaultException) Test(org.junit.Test)

Example 35 with SoapTransport

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

the class TestSearchGal method searchWithOffsetLimit.

private void searchWithOffsetLimit(boolean ldap, String domainName) throws Exception {
    SoapTransport transport = authUser(TestUtil.getAddress(AUTHED_USER, domainName));
    Element request = Element.create(transport.getRequestProtocol(), AccountConstants.SEARCH_GAL_REQUEST);
    request.addElement(AccountConstants.E_NAME).setText(".");
    int offset = 5;
    int limit = 3;
    request.addAttribute(MailConstants.A_QUERY_OFFSET, offset);
    request.addAttribute(MailConstants.A_QUERY_LIMIT, limit);
    request.addAttribute(MailConstants.A_SORTBY, "nameAsc");
    Element response = transport.invoke(request);
    boolean paginationSupported = response.getAttributeBool(AccountConstants.A_PAGINATION_SUPPORTED);
    List<GalContact> result = new ArrayList<GalContact>();
    for (Element e : response.listElements(AdminConstants.E_CN)) {
        result.add(new GalContact(AdminConstants.A_ID, SoapProvisioning.getAttrs(e)));
    }
    if (ldap) {
        // pagination is not supported
        assertFalse(paginationSupported);
        // limit is ignored, ldap search is limited by zimbraGalMaxResults
        // should find all objects, plus the authed user
        assertEquals(NUM_ALL_OBJECTS + 1, result.size());
    } else {
        // pagination is supported
        assertTrue(paginationSupported);
        assertEquals(limit, result.size());
        for (int i = 0; i < limit; i++) {
            assertEquals(getAcctEmail(offset + i, domainName), result.get(i).getSingleAttr(ContactConstants.A_email));
        }
    }
}
Also used : GalContact(com.zimbra.cs.account.GalContact) Element(com.zimbra.common.soap.Element) ArrayList(java.util.ArrayList) SoapTransport(com.zimbra.common.soap.SoapTransport)

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