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);
}
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);
}
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"));
}
Aggregations