use of org.codice.ddf.platform.filter.SecurityFilterChain in project ddf by codice.
the class PKIHandlerTest method testErrorHandling.
/**
* Tests Error Handling
*/
@Test
public void testErrorHandling() throws Exception {
PKIHandler handler = getPKIHandlerWithMockedCrl(true);
HttpServletResponse httpResponse = mock(HttpServletResponse.class);
HttpServletRequest httpRequest = mock(HttpServletRequest.class);
SecurityFilterChain filterChain = mock(SecurityFilterChain.class);
HandlerResult result = handler.handleError(httpRequest, httpResponse, filterChain);
assertThat(result.getStatus(), equalTo(HandlerResult.Status.NO_ACTION));
}
use of org.codice.ddf.platform.filter.SecurityFilterChain in project ddf by codice.
the class PKIHandlerTest method testGetNormalizedTokenSuccessNoCrlPki.
/**
* This test ensures the proper functionality of PKIHandler's method, getNormalizedToken(), when
* given a valid HTTPServletRequest.
*/
@Test
public void testGetNormalizedTokenSuccessNoCrlPki() throws Exception {
PKIHandler handler = getPKIHandlerWithMockedCrl(true);
HttpServletRequest request = mock(HttpServletRequest.class);
HttpServletResponse response = mock(HttpServletResponse.class);
SecurityFilterChain chain = mock(SecurityFilterChain.class);
when(request.getAttribute(("javax.servlet.request.X509Certificate"))).thenReturn(getTestCerts());
// Note that the getNormalizedToken() method for PKI handlers do not use the resolve tag.
HandlerResult result;
result = handler.getNormalizedToken(request, response, chain, true);
assertThat(result, is(notNullValue()));
assertThat(result.getStatus(), equalTo(HandlerResult.Status.COMPLETED));
verify(handler.crlChecker).passesCrlCheck(getTestCerts());
}
use of org.codice.ddf.platform.filter.SecurityFilterChain in project ddf by codice.
the class PKIHandlerTest method testNoActionWhenHttpResponseIsNull.
/**
* Tests that the certificate gets through when CRL checking is enabled but the cert is not listed
* in the CRL
*/
@Test
public void testNoActionWhenHttpResponseIsNull() throws Exception {
PKIHandler handler = getPKIHandlerWithMockedCrl(true);
HttpServletRequest httpRequest = mock(HttpServletRequest.class);
SecurityFilterChain chain = mock(SecurityFilterChain.class);
when(httpRequest.getAttribute(("javax.servlet.request.X509Certificate"))).thenReturn(getTestCerts());
HandlerResult result = handler.getNormalizedToken(httpRequest, null, chain, true);
assertThat(result.getStatus(), equalTo(HandlerResult.Status.NO_ACTION));
verify(handler.crlChecker, never()).passesCrlCheck(getTestCerts());
}
use of org.codice.ddf.platform.filter.SecurityFilterChain in project ddf by codice.
the class PKIHandlerTest method testGetNormalizedTokenFailureNoCerts.
/**
* This test ensures the proper functionality of PKIHandler's method, getNormalizedToken(), when
* given an invalid HTTPServletRequest.
*/
@Test
public void testGetNormalizedTokenFailureNoCerts() throws Exception {
PKIHandler handler = getPKIHandlerWithMockedCrl(false);
HttpServletRequest request = mock(HttpServletRequest.class);
HttpServletResponse response = mock(HttpServletResponse.class);
SecurityFilterChain chain = mock(SecurityFilterChain.class);
when(request.getAttribute(("javax.servlet.request.X509Certificate"))).thenReturn(null);
// Note that the getNormalizedToken() method for PKI handlers do not use the resolve tag.
HandlerResult result = null;
result = handler.getNormalizedToken(request, response, chain, true);
assertThat(result, is(notNullValue()));
assertThat(result.getStatus(), equalTo(HandlerResult.Status.NO_ACTION));
verify(handler.crlChecker, never()).passesCrlCheck(getTestCerts());
}
use of org.codice.ddf.platform.filter.SecurityFilterChain in project ddf by codice.
the class WebSSOFilterTest method testDoFilterWhiteListed.
@Test
public void testDoFilterWhiteListed() throws IOException, AuthenticationException {
ContextPolicy testPolicy = mock(ContextPolicy.class);
ContextPolicyManager policyManager = mock(ContextPolicyManager.class);
when(policyManager.getContextPolicy(anyString())).thenReturn(testPolicy);
when(policyManager.isWhiteListed(anyString())).thenReturn(true);
when(policyManager.getSessionAccess()).thenReturn(false);
WebSSOFilter filter = new WebSSOFilter();
// set handlers
AuthenticationHandler handler1 = mock(AuthenticationHandler.class);
HandlerResult noActionResult = mock(HandlerResult.class);
when(noActionResult.getStatus()).thenReturn(Status.NO_ACTION);
HandlerResult completedResult = mock(HandlerResult.class);
when(completedResult.getStatus()).thenReturn(Status.COMPLETED);
when(completedResult.getToken()).thenReturn(null);
when(handler1.getNormalizedToken(any(ServletRequest.class), any(ServletResponse.class), any(SecurityFilterChain.class), eq(true))).thenReturn(completedResult);
when(handler1.getNormalizedToken(any(ServletRequest.class), any(ServletResponse.class), any(SecurityFilterChain.class), eq(false))).thenReturn(noActionResult);
filter.setHandlerList(Collections.singletonList(handler1));
filter.setContextPolicyManager(policyManager);
SecurityFilterChain filterChain = mock(SecurityFilterChain.class);
HttpServletRequest request = mock(HttpServletRequest.class);
when(request.getRequestURI()).thenReturn(MOCK_CONTEXT);
HttpServletResponse response = mock(HttpServletResponse.class);
filter.doFilter(request, response, filterChain);
verify(request, times(1)).setAttribute(ContextPolicy.NO_AUTH_POLICY, true);
verify(filterChain).doFilter(request, response);
verify(handler1, never()).getNormalizedToken(any(HttpServletRequest.class), any(HttpServletResponse.class), any(SecurityFilterChain.class), anyBoolean());
}
Aggregations