Search in sources :

Example 21 with SoapHttpTransport

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

the class TestCookieReuse method testLoginClearAuthTokensException.

/**
     * Verify that when an expired authtoken has been removed from LDAP, login still succeeds
     * @throws Exception
     */
@Test
public void testLoginClearAuthTokensException() throws Exception {
    Account a = TestUtil.getAccount(USER_NAME);
    ZimbraAuthToken at1 = new ZimbraAuthToken(a, System.currentTimeMillis() + 1000);
    Assert.assertFalse("token should not be expired yet", at1.isExpired());
    Thread.sleep(2000);
    Assert.assertTrue("token should have expired by now", at1.isExpired());
    //explicitely clean up expired auth tokens
    a.purgeAuthTokens();
    //verify that AuthRequest still works
    SoapHttpTransport transport = new SoapHttpTransport(TestUtil.getSoapUrl());
    AccountSelector acctSel = new AccountSelector(com.zimbra.soap.type.AccountBy.name, a.getName());
    AuthRequest req = new AuthRequest(acctSel, "test123");
    Element resp = transport.invoke(JaxbUtil.jaxbToElement(req, SoapProtocol.SoapJS.getFactory()));
    AuthResponse authResp = JaxbUtil.elementToJaxb(resp);
    String newAuthToken = authResp.getAuthToken();
    Assert.assertNotNull("should have received a new authtoken", newAuthToken);
    AuthToken at = ZimbraAuthToken.getAuthToken(newAuthToken);
    Assert.assertTrue("new auth token should be registered", at.isRegistered());
    Assert.assertFalse("new auth token should not be expired yet", at.isExpired());
}
Also used : Account(com.zimbra.cs.account.Account) AuthRequest(com.zimbra.soap.account.message.AuthRequest) ZimbraAuthToken(com.zimbra.cs.account.ZimbraAuthToken) Element(com.zimbra.common.soap.Element) XMLElement(com.zimbra.common.soap.Element.XMLElement) JSONElement(com.zimbra.common.soap.Element.JSONElement) AccountSelector(com.zimbra.soap.type.AccountSelector) AuthToken(com.zimbra.cs.account.AuthToken) ZAuthToken(com.zimbra.common.auth.ZAuthToken) ZimbraAuthToken(com.zimbra.cs.account.ZimbraAuthToken) SoapHttpTransport(com.zimbra.common.soap.SoapHttpTransport) AuthResponse(com.zimbra.soap.account.message.AuthResponse) Test(org.junit.Test)

Example 22 with SoapHttpTransport

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

the class TestDeployZimlet method testBadZimletName.

@Test
public void testBadZimletName() throws Exception {
    SoapHttpTransport transport = new SoapHttpTransport(TestUtil.getAdminSoapUrl());
    com.zimbra.soap.admin.message.AuthRequest authReq = new com.zimbra.soap.admin.message.AuthRequest(LC.zimbra_ldap_user.value(), LC.zimbra_ldap_password.value());
    authReq.setCsrfSupported(false);
    Element response = transport.invoke(JaxbUtil.jaxbToElement(authReq, SoapProtocol.SoapJS.getFactory()));
    com.zimbra.soap.admin.message.AuthResponse authResp = JaxbUtil.elementToJaxb(response);
    String authToken = authResp.getAuthToken();
    String aid = adminUpload(authToken, "attack.zip", "/opt/zimbra/unittest/zimlets/attack.zip");
    assertNotNull("Attachment ID should not be null", aid);
    AttachmentIdAttrib att = new AttachmentIdAttrib(aid);
    transport.setAdmin(true);
    transport.setAuthToken(authToken);
    DeployZimletRequest deployReq = new DeployZimletRequest(AdminConstants.A_DEPLOYLOCAL, false, true, att);
    Element req = JaxbUtil.jaxbToElement(deployReq);
    try {
        Element res = transport.invoke(req);
        JaxbUtil.elementToJaxb(res);
        fail("Should throw SoapFaultException");
    } catch (SoapFaultException e) {
    //expected
    }
}
Also used : Element(com.zimbra.common.soap.Element) SoapFaultException(com.zimbra.common.soap.SoapFaultException) DeployZimletRequest(com.zimbra.soap.admin.message.DeployZimletRequest) SoapHttpTransport(com.zimbra.common.soap.SoapHttpTransport) AttachmentIdAttrib(com.zimbra.soap.admin.type.AttachmentIdAttrib) Test(org.junit.Test)

Example 23 with SoapHttpTransport

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

the class TestDeployZimlet method testNoAid.

@Test
public void testNoAid() throws Exception {
    SoapHttpTransport transport = new SoapHttpTransport(TestUtil.getAdminSoapUrl());
    com.zimbra.soap.admin.message.AuthRequest authReq = new com.zimbra.soap.admin.message.AuthRequest(LC.zimbra_ldap_user.value(), LC.zimbra_ldap_password.value());
    authReq.setCsrfSupported(false);
    Element response = transport.invoke(JaxbUtil.jaxbToElement(authReq, SoapProtocol.SoapJS.getFactory()));
    com.zimbra.soap.admin.message.AuthResponse authResp = JaxbUtil.elementToJaxb(response);
    String authToken = authResp.getAuthToken();
    transport.setAdmin(true);
    transport.setAuthToken(authToken);
    DeployZimletRequest deployReq = new DeployZimletRequest(AdminConstants.A_DEPLOYLOCAL, false, true, null);
    Element req = JaxbUtil.jaxbToElement(deployReq);
    try {
        Element res = transport.invoke(req);
        JaxbUtil.elementToJaxb(res);
        fail("Should throw SoapFaultException");
    } catch (SoapFaultException e) {
    //expected
    }
}
Also used : Element(com.zimbra.common.soap.Element) SoapFaultException(com.zimbra.common.soap.SoapFaultException) DeployZimletRequest(com.zimbra.soap.admin.message.DeployZimletRequest) SoapHttpTransport(com.zimbra.common.soap.SoapHttpTransport) Test(org.junit.Test)

Example 24 with SoapHttpTransport

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

the class TestDeployZimlet method testZipWithTraversal.

@Test
public void testZipWithTraversal() throws Exception {
    SoapHttpTransport transport = new SoapHttpTransport(TestUtil.getAdminSoapUrl());
    com.zimbra.soap.admin.message.AuthRequest authReq = new com.zimbra.soap.admin.message.AuthRequest(LC.zimbra_ldap_user.value(), LC.zimbra_ldap_password.value());
    authReq.setCsrfSupported(false);
    Element response = transport.invoke(JaxbUtil.jaxbToElement(authReq, SoapProtocol.SoapJS.getFactory()));
    com.zimbra.soap.admin.message.AuthResponse authResp = JaxbUtil.elementToJaxb(response);
    String authToken = authResp.getAuthToken();
    String aid = adminUpload(authToken, "attack.zip", "/opt/zimbra/unittest/zimlets/com_zimbra_url.zip");
    assertNotNull("Attachment ID should not be null", aid);
    AttachmentIdAttrib att = new AttachmentIdAttrib(aid);
    transport.setAdmin(true);
    transport.setAuthToken(authToken);
    DeployZimletRequest deployReq = new DeployZimletRequest(AdminConstants.A_DEPLOYLOCAL, false, true, att);
    Element req = JaxbUtil.jaxbToElement(deployReq);
    try {
        Element res = transport.invoke(req);
        JaxbUtil.elementToJaxb(res);
        fail("Should throw SoapFaultException");
    } catch (SoapFaultException e) {
    //expected
    }
}
Also used : Element(com.zimbra.common.soap.Element) SoapFaultException(com.zimbra.common.soap.SoapFaultException) DeployZimletRequest(com.zimbra.soap.admin.message.DeployZimletRequest) SoapHttpTransport(com.zimbra.common.soap.SoapHttpTransport) AttachmentIdAttrib(com.zimbra.soap.admin.type.AttachmentIdAttrib) Test(org.junit.Test)

Example 25 with SoapHttpTransport

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

the class TestDeployZimlet method testValidZimlet.

@Test
public void testValidZimlet() throws Exception {
    SoapHttpTransport transport = new SoapHttpTransport(TestUtil.getAdminSoapUrl());
    com.zimbra.soap.admin.message.AuthRequest authReq = new com.zimbra.soap.admin.message.AuthRequest(LC.zimbra_ldap_user.value(), LC.zimbra_ldap_password.value());
    authReq.setCsrfSupported(false);
    Element response = transport.invoke(JaxbUtil.jaxbToElement(authReq, SoapProtocol.SoapJS.getFactory()));
    com.zimbra.soap.admin.message.AuthResponse authResp = JaxbUtil.elementToJaxb(response);
    String authToken = authResp.getAuthToken();
    String aid = adminUpload(authToken, "com_zimbra_mailarchive.zip", "/opt/zimbra/zimlets/com_zimbra_mailarchive.zip");
    assertNotNull("Attachment ID should not be null", aid);
    AttachmentIdAttrib att = new AttachmentIdAttrib(aid);
    transport.setAdmin(true);
    transport.setAuthToken(authToken);
    DeployZimletRequest deployReq = new DeployZimletRequest(AdminConstants.A_DEPLOYLOCAL, false, true, att);
    Element req = JaxbUtil.jaxbToElement(deployReq);
    Element res = transport.invoke(req);
    DeployZimletResponse deployResp = JaxbUtil.elementToJaxb(res);
    assertNotNull(deployResp);
    String status = deployResp.getProgresses().get(0).getStatus();
    assertTrue("should be getting 'pending' or 'succeeded' status", status.equals(DeployZimlet.sPENDING) || status.equals(DeployZimlet.sSUCCEEDED));
    int waitMs = 10000;
    while (waitMs > 0) {
        DeployZimletRequest statusReq = new DeployZimletRequest(AdminConstants.A_STATUS, false, true, att);
        req = JaxbUtil.jaxbToElement(statusReq);
        res = transport.invoke(req);
        DeployZimletResponse statusResp = JaxbUtil.elementToJaxb(res);
        assertNotNull(statusResp);
        status = statusResp.getProgresses().get(0).getStatus();
        assertTrue("should be getting 'pending' or 'succeeded' status", status.equals(DeployZimlet.sPENDING) || status.equals(DeployZimlet.sSUCCEEDED));
        if (status.equals(DeployZimlet.sSUCCEEDED)) {
            break;
        }
        Thread.sleep(500);
        waitMs -= 500;
    }
    assertTrue("should be getting 'succeeded' status. Status is: " + status, status.equals(DeployZimlet.sSUCCEEDED));
}
Also used : Element(com.zimbra.common.soap.Element) DeployZimletResponse(com.zimbra.soap.admin.message.DeployZimletResponse) DeployZimletRequest(com.zimbra.soap.admin.message.DeployZimletRequest) SoapHttpTransport(com.zimbra.common.soap.SoapHttpTransport) AttachmentIdAttrib(com.zimbra.soap.admin.type.AttachmentIdAttrib) Test(org.junit.Test)

Aggregations

SoapHttpTransport (com.zimbra.common.soap.SoapHttpTransport)69 Element (com.zimbra.common.soap.Element)54 Test (org.junit.Test)32 SoapFaultException (com.zimbra.common.soap.SoapFaultException)16 ServiceException (com.zimbra.common.service.ServiceException)13 Account (com.zimbra.cs.account.Account)13 DeployZimletRequest (com.zimbra.soap.admin.message.DeployZimletRequest)13 AuthRequest (com.zimbra.soap.account.message.AuthRequest)12 AttachmentIdAttrib (com.zimbra.soap.admin.type.AttachmentIdAttrib)12 XMLElement (com.zimbra.common.soap.Element.XMLElement)11 AuthToken (com.zimbra.cs.account.AuthToken)10 ZAuthToken (com.zimbra.common.auth.ZAuthToken)8 AuthResponse (com.zimbra.soap.account.message.AuthResponse)8 IOException (java.io.IOException)8 ZMailbox (com.zimbra.client.ZMailbox)7 ZimbraAuthToken (com.zimbra.cs.account.ZimbraAuthToken)6 AccountSelector (com.zimbra.soap.type.AccountSelector)6 HashMap (java.util.HashMap)5 Domain (com.zimbra.cs.account.Domain)4 Server (com.zimbra.cs.account.Server)4