Search in sources :

Example 86 with Header

use of org.apache.commons.httpclient.Header in project sling by apache.

the class SelectorRedirectOnLoginErrorTest method testRedirectToSelectorLoginFormAfterLoginError.

/**
     * Test SLING-2165.  Login Error should redirect back to the referrer
     * login page.
     *
     * @throws Exception
     */
public void testRedirectToSelectorLoginFormAfterLoginError() throws Exception {
    //login failure
    List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new NameValuePair("j_username", "___bogus___"));
    params.add(new NameValuePair("j_password", "not_a_real_user"));
    final String loginPageUrl = String.format("%s/system/sling/selector/login", HTTP_BASE_URL);
    PostMethod post = (PostMethod) assertPostStatus(HTTP_BASE_URL + "/j_security_check", HttpServletResponse.SC_MOVED_TEMPORARILY, params, null, loginPageUrl);
    final Header locationHeader = post.getResponseHeader("Location");
    String location = locationHeader.getValue();
    int queryStrStart = location.indexOf('?');
    if (queryStrStart != -1) {
        location = location.substring(0, queryStrStart);
    }
    assertEquals("Expected to remain on the selector/login page", loginPageUrl, location);
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair) Header(org.apache.commons.httpclient.Header) PostMethod(org.apache.commons.httpclient.methods.PostMethod) ArrayList(java.util.ArrayList)

Example 87 with Header

use of org.apache.commons.httpclient.Header in project sling by apache.

the class SelectorRedirectOnLoginErrorTest method testRedirectToOpenIDLoginFormAfterLoginError.

/**
     * Test SLING-2165.  Login Error should redirect back to the referrer
     * login page.
     *
     * @throws Exception
     */
public void testRedirectToOpenIDLoginFormAfterLoginError() throws Exception {
    //login failure
    List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new NameValuePair("openid_identifier", "___bogus___"));
    final String loginPageUrl = String.format("%s/system/sling/openid/login", HTTP_BASE_URL);
    PostMethod post = (PostMethod) assertPostStatus(HTTP_BASE_URL + "/j_security_check", HttpServletResponse.SC_MOVED_TEMPORARILY, params, null, loginPageUrl);
    final Header locationHeader = post.getResponseHeader("Location");
    String location = locationHeader.getValue();
    int queryStrStart = location.indexOf('?');
    if (queryStrStart != -1) {
        location = location.substring(0, queryStrStart);
    }
    assertEquals("Expected to remain on the openid/login page", loginPageUrl, location);
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair) Header(org.apache.commons.httpclient.Header) PostMethod(org.apache.commons.httpclient.methods.PostMethod) ArrayList(java.util.ArrayList)

Example 88 with Header

use of org.apache.commons.httpclient.Header in project sling by apache.

the class SelectorAuthenticationResponseCodeTest method testWithAcceptHeaderIncorrectCredentials.

// this method assumes the use of the selector auth bundle
@Test
public void testWithAcceptHeaderIncorrectCredentials() throws Exception {
    List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new NameValuePair("j_username", "garbage"));
    params.add(new NameValuePair("j_password", "garbage"));
    // simulate a browser request
    List<Header> headers = new ArrayList<Header>();
    headers.add(new Header("User-Agent", "Mozilla/5.0 Sling Integration Test"));
    HttpMethod post = assertPostStatus(HttpTest.HTTP_BASE_URL + "/j_security_check", HttpServletResponse.SC_MOVED_TEMPORARILY, params, headers, null);
    final String location = post.getResponseHeader("Location").getValue();
    assertNotNull(location);
    assertTrue(location.startsWith(HttpTest.HTTP_BASE_URL + "/system/sling/selector/login?"));
    assertTrue(location.contains("resource=%2F"));
    assertTrue(location.contains("j_reason=INVALID_CREDENTIALS"));
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair) Header(org.apache.commons.httpclient.Header) ArrayList(java.util.ArrayList) HttpMethod(org.apache.commons.httpclient.HttpMethod) HttpTest(org.apache.sling.commons.testing.integration.HttpTest) Test(org.junit.Test)

Aggregations

Header (org.apache.commons.httpclient.Header)88 GetMethod (org.apache.commons.httpclient.methods.GetMethod)22 Test (org.junit.Test)22 IOException (java.io.IOException)20 HttpClient (org.apache.commons.httpclient.HttpClient)19 PostMethod (org.apache.commons.httpclient.methods.PostMethod)19 HttpMethod (org.apache.commons.httpclient.HttpMethod)17 NameValuePair (org.apache.commons.httpclient.NameValuePair)16 ArrayList (java.util.ArrayList)15 InputStream (java.io.InputStream)13 HttpException (org.apache.commons.httpclient.HttpException)13 PutMethod (org.apache.commons.httpclient.methods.PutMethod)10 Account (com.zimbra.cs.account.Account)9 ServiceException (com.zimbra.common.service.ServiceException)6 UsernamePasswordCredentials (org.apache.commons.httpclient.UsernamePasswordCredentials)6 HttpTest (org.apache.sling.commons.testing.integration.HttpTest)6 Pair (com.zimbra.common.util.Pair)5 ByteArrayInputStream (java.io.ByteArrayInputStream)5 HashMap (java.util.HashMap)5 DefaultHttpMethodRetryHandler (org.apache.commons.httpclient.DefaultHttpMethodRetryHandler)5