Search in sources :

Example 26 with SoapTransport

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

the class TestSearchGalGroups method testSearchGroup.

/*
     * Verify isOwner and isMember flags are returned correctly.
     */
private void testSearchGroup(Account acct, Group group, Boolean needIsOwner, MemberOfSelector needIsMember, boolean actualIsOwner, boolean actualIsMember) throws Exception {
    SoapTransport transport = authUser(acct.getName());
    SearchGalRequest req = new SearchGalRequest();
    req.setName(group.getName());
    req.setNeedIsOwner(needIsOwner);
    req.setNeedIsMember(needIsMember);
    SearchGalResponse resp = invokeJaxb(transport, req);
    List<String> result = Lists.newArrayList();
    List<String> expected = Lists.newArrayList(Verify.makeResultStr(group.getName(), ContactConstants.TYPE_GROUP, needIsOwner == null ? null : actualIsOwner, needIsMember == null ? null : actualIsMember, ZAttrProvisioning.DistributionListSubscriptionPolicy.ACCEPT.name()));
    List<ContactInfo> entries = resp.getContacts();
    for (ContactInfo entry : entries) {
        List<ContactAttr> attrs = entry.getAttrs();
        String email = null;
        String type = null;
        String subsPolicy = null;
        for (ContactAttr attr : attrs) {
            String key = attr.getKey();
            if (ContactConstants.A_email.equals(key)) {
                email = attr.getValue();
            } else if (ContactConstants.A_type.equals(key)) {
                type = attr.getValue();
            } else if (Provisioning.A_zimbraDistributionListSubscriptionPolicy.equals(key)) {
                subsPolicy = attr.getValue();
            }
        }
        Boolean isOwner = entry.isOwner();
        Boolean isMember = entry.isMember();
        result.add(Verify.makeResultStr(email, type, isOwner, isMember, subsPolicy));
    }
    Verify.verifyEquals(expected, result);
}
Also used : ContactAttr(com.zimbra.soap.type.ContactAttr) SearchGalResponse(com.zimbra.soap.account.message.SearchGalResponse) SearchGalRequest(com.zimbra.soap.account.message.SearchGalRequest) ContactInfo(com.zimbra.soap.account.type.ContactInfo) SoapTransport(com.zimbra.common.soap.SoapTransport)

Example 27 with SoapTransport

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

the class TestAuth method accountStatusMaintenanceAfterAuth.

@Test
public void accountStatusMaintenanceAfterAuth() throws Exception {
    Account acct = provUtil.createAccount(genAcctNameLocalPart(), domain);
    SoapTransport transport = authUser(acct.getName());
    /*
         * change account status to maintenance
         */
    prov.modifyAccountStatus(acct, AccountStatus.maintenance.name());
    GetInfoRequest req = new GetInfoRequest();
    String errorCode = null;
    try {
        GetInfoResponse resp = invokeJaxb(transport, req);
    } catch (SoapFaultException e) {
        errorCode = e.getCode();
    }
    assertEquals(AccountServiceException.AUTH_EXPIRED, errorCode);
    provUtil.deleteAccount(acct);
}
Also used : Account(com.zimbra.cs.account.Account) GetInfoResponse(com.zimbra.soap.account.message.GetInfoResponse) GetInfoRequest(com.zimbra.soap.account.message.GetInfoRequest) SoapTransport(com.zimbra.common.soap.SoapTransport) SoapFaultException(com.zimbra.common.soap.SoapFaultException) Test(org.junit.Test)

Example 28 with SoapTransport

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

the class TestAuth method accountStatusMaintenance.

@Test
public void accountStatusMaintenance() throws Exception {
    Account acct = provUtil.createAccount(genAcctNameLocalPart(), domain, Collections.singletonMap(Provisioning.A_zimbraAccountStatus, (Object) AccountStatus.maintenance.name()));
    String errorCode = null;
    try {
        SoapTransport transport = authUser(acct.getName());
    } catch (SoapFaultException e) {
        errorCode = e.getCode();
    }
    assertEquals(AccountServiceException.MAINTENANCE_MODE, errorCode);
    provUtil.deleteAccount(acct);
}
Also used : Account(com.zimbra.cs.account.Account) SoapTransport(com.zimbra.common.soap.SoapTransport) SoapFaultException(com.zimbra.common.soap.SoapFaultException) Test(org.junit.Test)

Example 29 with SoapTransport

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

the class TestAuth method clearCookie.

@Test
public void clearCookie() throws Exception {
    // 2 seconds
    int authTokenLifetimeMSecs = 2000;
    int waitMSecs = authTokenLifetimeMSecs + 1000;
    Account acct = provUtil.createGlobalAdmin(genAcctNameLocalPart(), domain);
    // set the account's auth token lifetime to a short period
    acct.setAdminAuthTokenLifetime(String.valueOf(authTokenLifetimeMSecs) + "ms");
    // String authToken = getAuthToken(acct.getName(), true);
    SoapTransport transport = authAdmin(acct.getName());
    // wait till the auto token expire
    Thread.sleep(waitMSecs);
    // make sure the auth token is indeed expired
    boolean caughtAuthExpired = false;
    try {
        NoOpRequest noOpReq = new NoOpRequest();
        NoOpResponse noOpResp = invokeJaxb(transport, noOpReq);
    } catch (ServiceException e) {
        if (AccountServiceException.AUTH_EXPIRED.equals(e.getCode())) {
            caughtAuthExpired = true;
        }
    }
    assertTrue(caughtAuthExpired);
    List<CookieSpec> cookiesToClear = Lists.newArrayList(new CookieSpec(ZimbraCookie.COOKIE_ZM_ADMIN_AUTH_TOKEN));
    ClearCookieRequest req = new ClearCookieRequest(cookiesToClear);
    /*
         * test the regular path when auto token control is not set
         * (auth token in soap header)
         */
    caughtAuthExpired = false;
    try {
        invokeJaxb(transport, req);
    } catch (ServiceException e) {
        if (AccountServiceException.AUTH_EXPIRED.equals(e.getCode())) {
            caughtAuthExpired = true;
        }
    }
    assertTrue(caughtAuthExpired);
    /*
         * test the regular path when auto token control is not set
         * (auth token in cookie)
         */
    String authToken = transport.getAuthToken().getValue();
    SoapTransport authTokenInCookieTransport = new AuthTokenInCookieTransport(authToken, true);
    caughtAuthExpired = false;
    try {
        invokeJaxb(authTokenInCookieTransport, req);
    } catch (ServiceException e) {
        if (AccountServiceException.AUTH_EXPIRED.equals(e.getCode())) {
            caughtAuthExpired = true;
        }
    }
    assertTrue(caughtAuthExpired);
    /*
         * test the path when auth token control voidOnExpired is true
         */
    // debug listener to verify the cookie is cleared
    SoapDebugListener verifyCookieClearedListener = new SoapDebugListener(Level.ALL) {

        @Override
        public void receiveSoapMessage(HttpPost postMethod, Element envelope) {
            super.receiveSoapMessage(postMethod, envelope);
            // verify cookies are cleared
            Header[] headers = postMethod.getAllHeaders();
            boolean cookieCleared = false;
            for (Header header : headers) {
                if (header.toString().trim().equals("Set-Cookie: ZM_ADMIN_AUTH_TOKEN=;Path=/;Expires=Thu, 01-Jan-1970 00:00:00 GMT")) {
                    cookieCleared = true;
                }
            // System.out.println(header.toString().trim()); // trim the ending crlf
            }
            assertTrue(cookieCleared);
        }
    };
    authTokenInCookieTransport = new AuthTokenInCookieTransport(authToken, true, true, verifyCookieClearedListener);
    // should NOT get AUTH_EXPIRED
    ClearCookieResponse resp = invokeJaxb(authTokenInCookieTransport, req);
    provUtil.deleteAccount(acct);
}
Also used : Account(com.zimbra.cs.account.Account) HttpPost(org.apache.http.client.methods.HttpPost) NoOpRequest(com.zimbra.soap.admin.message.NoOpRequest) Element(com.zimbra.common.soap.Element) AccountServiceException(com.zimbra.cs.account.AccountServiceException) ServiceException(com.zimbra.common.service.ServiceException) Header(org.apache.http.Header) HttpHeader(org.eclipse.jetty.http.HttpHeader) NoOpResponse(com.zimbra.soap.admin.message.NoOpResponse) ClearCookieRequest(com.zimbra.soap.admin.message.ClearCookieRequest) ClearCookieResponse(com.zimbra.soap.admin.message.ClearCookieResponse) CookieSpec(com.zimbra.soap.admin.type.CookieSpec) SoapTransport(com.zimbra.common.soap.SoapTransport) Test(org.junit.Test)

Example 30 with SoapTransport

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

the class TestAuth method soapByCookieAdmin.

@Test
public void soapByCookieAdmin() throws Exception {
    boolean isAdmin = true;
    String USER_NAME = TestUtil.getAddress("admin");
    String authToken = getAuthToken(USER_NAME, isAdmin);
    Element req = Element.create(SoapProtocol.Soap12, AdminConstants.GET_CONFIG_REQUEST);
    req.addElement(AdminConstants.E_A).addAttribute(AdminConstants.A_N, Provisioning.A_cn);
    SoapTransport transport = new AuthTokenInCookieTransport(authToken, isAdmin);
    Element resp = transport.invoke(req);
    Element eA = resp.getElement(AdminConstants.E_A);
    String value = eA.getText();
    assertEquals("config", value);
}
Also used : Element(com.zimbra.common.soap.Element) 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