use of javax.servlet.FilterChain in project OpenAM by OpenRock.
the class AMSetupFilterTest method filterShouldRedirectRequestsToSetupPageIfNotConfigured.
@Test
public void filterShouldRedirectRequestsToSetupPageIfNotConfigured() throws Exception {
//Given
initializeFilter();
HttpServletRequest request = mockRequest("REQUEST_URI");
HttpServletResponse response = mock(HttpServletResponse.class);
FilterChain chain = mock(FilterChain.class);
systemIsNotConfigured();
withWritePermissionsOnBootstrapRootDirectory();
//When
setupFilter.doFilter(request, response, chain);
//Then
verify(response).sendRedirect("SCHEME://SERVER_NAME:8080/CONTEXT_PATH/config/options.htm");
verifyZeroInteractions(chain);
}
use of javax.servlet.FilterChain in project nhin-d by DirectProject.
the class BasicAuthFilter_doFilterTest method testDoFilter_sessionsNotAllowed.
@Test
public void testDoFilter_sessionsNotAllowed() throws Exception {
final HttpSession session = mock(HttpSession.class);
final BasicAuthFilter filter = buildFilter();
filter.setAllowSessions(false);
final HttpServletRequest request = mock(HttpServletRequest.class);
final HttpServletResponse response = mock(HttpServletResponse.class);
final FilterChain chain = mock(FilterChain.class);
when(request.getHeader("Authorization")).thenReturn(buildRawCredential("gm2552", "password"));
when(request.getSession(true)).thenReturn(session);
filter.doFilter(request, response, chain);
verify(chain, times(1)).doFilter((HttpServletRequest) any(), eq(response));
verify(session, never()).setAttribute(eq("NHINDAuthPrincipalAttr"), (Principal) any());
verify(response, never()).sendError(eq(HttpServletResponse.SC_UNAUTHORIZED));
}
use of javax.servlet.FilterChain in project nhin-d by DirectProject.
the class BasicAuthFilter_doFilterTest method testDoFilter_nonBasicAuthScheme_assertUnauthorized.
@Test
public void testDoFilter_nonBasicAuthScheme_assertUnauthorized() throws Exception {
final HttpSession session = mock(HttpSession.class);
final BasicAuthFilter filter = buildFilter();
final HttpServletRequest request = mock(HttpServletRequest.class);
final HttpServletResponse response = mock(HttpServletResponse.class);
final FilterChain chain = mock(FilterChain.class);
when(request.getHeader("Authorization")).thenReturn("OAuth 39843");
when(request.getSession(true)).thenReturn(session);
filter.doFilter(request, response, chain);
verify(chain, never()).doFilter((HttpServletRequest) any(), eq(response));
verify(request, times(1)).getHeader(eq("Authorization"));
verify(session, never()).setAttribute(eq("NHINDAuthPrincipalAttr"), (Principal) any());
verify(response, times(1)).sendError(eq(HttpServletResponse.SC_UNAUTHORIZED));
}
use of javax.servlet.FilterChain in project nhin-d by DirectProject.
the class BasicAuthFilter_doFilterTest method testDoFilter_nonSSLConnectionDisallowed_assertForbidden.
@Test
public void testDoFilter_nonSSLConnectionDisallowed_assertForbidden() throws Exception {
final HttpSession session = mock(HttpSession.class);
final BasicAuthFilter filter = buildFilter();
filter.setForceSSL(true);
final HttpServletRequest request = mock(HttpServletRequest.class);
final HttpServletResponse response = mock(HttpServletResponse.class);
final FilterChain chain = mock(FilterChain.class);
filter.doFilter(request, response, chain);
verify(chain, never()).doFilter((HttpServletRequest) any(), eq(response));
verify(session, never()).setAttribute(eq("NHINDAuthPrincipalAttr"), (Principal) any());
verify(response, times(1)).sendError(eq(HttpServletResponse.SC_FORBIDDEN));
verify(request, never()).getHeader(eq("Authorization"));
}
use of javax.servlet.FilterChain in project nhin-d by DirectProject.
the class BasicAuthFilter_doFilterTest method testDoFilter_exsitingPrincipal.
@Test
public void testDoFilter_exsitingPrincipal() throws Exception {
final HttpSession session = mock(HttpSession.class);
final BasicAuthFilter filter = buildFilter();
final HttpServletRequest request = mock(HttpServletRequest.class);
final HttpServletResponse response = mock(HttpServletResponse.class);
final FilterChain chain = mock(FilterChain.class);
when(request.getUserPrincipal()).thenReturn(new NHINDPrincipal("gm2552", "admin"));
filter.doFilter(request, response, chain);
verify(chain, times(1)).doFilter((HttpServletRequest) any(), eq(response));
verify(request, never()).getSession(eq(true));
verify(session, never()).setAttribute(eq("NHINDAuthPrincipalAttr"), (Principal) any());
verify(response, never()).sendError(eq(HttpServletResponse.SC_UNAUTHORIZED));
verify(request, never()).getHeader(eq("Authorization"));
}
Aggregations