use of javax.servlet.FilterChain in project OpenAM by OpenRock.
the class XUIFilterTest method loginRedirectsToXUIWithCompositeAdvice.
@Test
public void loginRedirectsToXUIWithCompositeAdvice() throws Exception {
String pathInfo = "/UI/Login";
String query = "locale=fr&realm=%2F";
String compositeAdvice = "<Advices><AttributeValuePair><Attribute name=\"AuthLevelConditionAdvice\"/>" + "<Value>1</Value></AttributeValuePair></Advices>";
String xuiLoginPath = "/XUI/#login/";
HttpServletRequest request = mock(HttpServletRequest.class);
HttpServletResponse responseLogin = mock(HttpServletResponse.class);
FilterChain filterChain = mock(FilterChain.class);
when(request.getRequestURI()).thenReturn(pathInfo);
when(request.getQueryString()).thenReturn(query);
when((request.getParameterMap())).thenAnswer(new Answer<Map>() {
@Override
public Map answer(InvocationOnMock invocation) throws Throwable {
Map parameterMap = new LinkedHashMap<String, String[]>();
parameterMap.put("locale", new String[] { "fr" });
parameterMap.put("realm", new String[] { "/" });
return parameterMap;
}
});
when(request.getParameter(Constants.COMPOSITE_ADVICE)).thenReturn(compositeAdvice);
filter.doFilter(request, responseLogin, filterChain);
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
verify(responseLogin).sendRedirect(captor.capture());
query += "&authIndexType=composite_advice&authIndexValue=" + ESAPI.encoder().encodeForURL(compositeAdvice);
assertThat(captor.getValue()).isEqualTo(CONTEXT + xuiLoginPath + "&" + query);
}
use of javax.servlet.FilterChain in project OpenAM by OpenRock.
the class AMSetupFilterTest method filterShouldAllowCertainRequestsThroughIfNotConfiguredAndInConfigurationMode.
@Test(dataProvider = "allowedRequestsWhilstConfiguring")
public void filterShouldAllowCertainRequestsThroughIfNotConfiguredAndInConfigurationMode(String suffix) throws Exception {
//Previous request must have been redirected to setup page to set the pass-through flag
filterShouldRedirectRequestsToSetupPageIfNotConfigured();
//Given
HttpServletRequest request = mockRequest(suffix);
HttpServletResponse response = mock(HttpServletResponse.class);
FilterChain chain = mock(FilterChain.class);
//When
setupFilter.doFilter(request, response, chain);
//Then
verify(chain).doFilter(request, response);
}
use of javax.servlet.FilterChain in project OpenAM by OpenRock.
the class AMSetupFilterTest method filterShouldAllowRequestsThroughIfConfigured.
@Test
public void filterShouldAllowRequestsThroughIfConfigured() throws Exception {
//Given
initializeFilter();
HttpServletRequest request = mockRequest("REQUEST_URI");
HttpServletResponse response = mock(HttpServletResponse.class);
FilterChain chain = mock(FilterChain.class);
systemIsConfigured();
//When
setupFilter.doFilter(request, response, chain);
//Then
verify(chain).doFilter(request, response);
}
use of javax.servlet.FilterChain in project OpenAM by OpenRock.
the class AMSetupFilterTest method filterShouldThrowConfigurationExceptionIfUpgradeInProgressAndConfigStoreIsDownButNoRedirectUriSet.
@Test
public void filterShouldThrowConfigurationExceptionIfUpgradeInProgressAndConfigStoreIsDownButNoRedirectUriSet() throws Exception {
//Given
initializeFilter();
HttpServletRequest request = mockRequest("REQUEST_URI");
HttpServletResponse response = mock(HttpServletResponse.class);
FilterChain chain = mock(FilterChain.class);
systemIsBeingUpgraded();
configStoreIsDown(null);
//When
try {
setupFilter.doFilter(request, response, chain);
fail("Expected ServletException with ConfigurationException is cause");
} catch (ServletException e) {
//Then
assertThat(e.getCause()).isInstanceOf(ConfigurationException.class);
verifyZeroInteractions(response, chain);
}
}
use of javax.servlet.FilterChain in project OpenAM by OpenRock.
the class AMSetupFilterTest method filterShouldRedirectRequestsIfUpgradeInProgressButConfigStoreIsDown.
@Test
public void filterShouldRedirectRequestsIfUpgradeInProgressButConfigStoreIsDown() throws Exception {
//Given
initializeFilter();
HttpServletRequest request = mockRequest("REQUEST_URI");
HttpServletResponse response = mock(HttpServletResponse.class);
FilterChain chain = mock(FilterChain.class);
systemIsBeingUpgraded();
configStoreIsDown("CONFIG_STORE_DOWN_REDIRECT_URI");
//When
setupFilter.doFilter(request, response, chain);
//Then
verify(response).sendRedirect("CONFIG_STORE_DOWN_REDIRECT_URI");
verifyZeroInteractions(chain);
}
Aggregations