use of javax.servlet.http.HttpServletRequest in project hadoop by apache.
the class TestLdapAuthenticationHandler method testRequestWithAuthorization.
@Test(timeout = 60000)
public void testRequestWithAuthorization() throws Exception {
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
final Base64 base64 = new Base64(0);
String credentials = base64.encodeToString("bjones:p@ssw0rd".getBytes());
String authHeader = HttpConstants.BASIC + " " + credentials;
Mockito.when(request.getHeader(HttpConstants.AUTHORIZATION_HEADER)).thenReturn(authHeader);
AuthenticationToken token = handler.authenticate(request, response);
Assert.assertNotNull(token);
Mockito.verify(response).setStatus(HttpServletResponse.SC_OK);
Assert.assertEquals(TYPE, token.getType());
Assert.assertEquals("bjones", token.getUserName());
Assert.assertEquals("bjones", token.getName());
}
use of javax.servlet.http.HttpServletRequest in project hadoop by apache.
the class TestLdapAuthenticationHandler method testRequestWithWrongCredentials.
@Test(timeout = 60000)
public void testRequestWithWrongCredentials() throws Exception {
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
final Base64 base64 = new Base64(0);
String credentials = base64.encodeToString("bjones:foo123".getBytes());
String authHeader = HttpConstants.BASIC + " " + credentials;
Mockito.when(request.getHeader(HttpConstants.AUTHORIZATION_HEADER)).thenReturn(authHeader);
try {
handler.authenticate(request, response);
Assert.fail();
} catch (AuthenticationException ex) {
// Expected
} catch (Exception ex) {
Assert.fail();
}
}
use of javax.servlet.http.HttpServletRequest in project hadoop by apache.
the class TestLdapAuthenticationHandler method testRequestWithoutAuthorization.
@Test(timeout = 60000)
public void testRequestWithoutAuthorization() throws Exception {
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
Assert.assertNull(handler.authenticate(request, response));
Mockito.verify(response).setHeader(WWW_AUTHENTICATE, HttpConstants.BASIC);
Mockito.verify(response).setStatus(HttpServletResponse.SC_UNAUTHORIZED);
}
use of javax.servlet.http.HttpServletRequest in project hadoop by apache.
the class TestMultiSchemeAuthenticationHandler method testRequestWithInvalidKerberosAuthorization.
@Test(timeout = 60000)
public void testRequestWithInvalidKerberosAuthorization() throws Exception {
String token = new Base64(0).encodeToString(new byte[] { 0, 1, 2 });
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
Mockito.when(request.getHeader(AUTHORIZATION_HEADER)).thenReturn(NEGOTIATE + token);
try {
handler.authenticate(request, response);
Assert.fail();
} catch (AuthenticationException ex) {
// Expected
} catch (Exception ex) {
Assert.fail();
}
}
use of javax.servlet.http.HttpServletRequest in project hadoop by apache.
the class TestAuthenticationFilter method testGetRequestURL.
@Test
public void testGetRequestURL() throws Exception {
AuthenticationFilter filter = new AuthenticationFilter();
try {
FilterConfig config = Mockito.mock(FilterConfig.class);
Mockito.when(config.getInitParameter("management.operation.return")).thenReturn("true");
Mockito.when(config.getInitParameter(AuthenticationFilter.AUTH_TYPE)).thenReturn(DummyAuthenticationHandler.class.getName());
Mockito.when(config.getInitParameterNames()).thenReturn(new Vector<String>(Arrays.asList(AuthenticationFilter.AUTH_TYPE, "management.operation.return")).elements());
getMockedServletContextWithStringSigner(config);
filter.init(config);
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://foo:8080/bar"));
Mockito.when(request.getQueryString()).thenReturn("a=A&b=B");
Assert.assertEquals("http://foo:8080/bar?a=A&b=B", filter.getRequestURL(request));
} finally {
filter.destroy();
}
}
Aggregations