Search in sources :

Example 21 with FilterChain

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);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) InvocationOnMock(org.mockito.invocation.InvocationOnMock) FilterChain(javax.servlet.FilterChain) HttpServletResponse(javax.servlet.http.HttpServletResponse) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Test(org.testng.annotations.Test)

Example 22 with FilterChain

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);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) FilterChain(javax.servlet.FilterChain) HttpServletResponse(javax.servlet.http.HttpServletResponse) Test(org.testng.annotations.Test)

Example 23 with FilterChain

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);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) FilterChain(javax.servlet.FilterChain) HttpServletResponse(javax.servlet.http.HttpServletResponse) Test(org.testng.annotations.Test)

Example 24 with FilterChain

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);
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletException(javax.servlet.ServletException) ConfigurationException(com.sun.identity.common.configuration.ConfigurationException) FilterChain(javax.servlet.FilterChain) HttpServletResponse(javax.servlet.http.HttpServletResponse) Test(org.testng.annotations.Test)

Example 25 with FilterChain

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);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) FilterChain(javax.servlet.FilterChain) HttpServletResponse(javax.servlet.http.HttpServletResponse) Test(org.testng.annotations.Test)

Aggregations

FilterChain (javax.servlet.FilterChain)418 HttpServletRequest (javax.servlet.http.HttpServletRequest)317 HttpServletResponse (javax.servlet.http.HttpServletResponse)269 Test (org.junit.Test)246 ServletResponse (javax.servlet.ServletResponse)135 ServletRequest (javax.servlet.ServletRequest)118 FilterConfig (javax.servlet.FilterConfig)80 Filter (javax.servlet.Filter)68 ServletException (javax.servlet.ServletException)54 IOException (java.io.IOException)48 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)46 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)46 Injector (com.google.inject.Injector)32 ServletTestUtils.newFakeHttpServletRequest (com.google.inject.servlet.ServletTestUtils.newFakeHttpServletRequest)25 ServletContext (javax.servlet.ServletContext)25 Test (org.testng.annotations.Test)25 HttpSession (javax.servlet.http.HttpSession)24 MockFilterChain (org.springframework.mock.web.MockFilterChain)24 InvocationOnMock (org.mockito.invocation.InvocationOnMock)22 Properties (java.util.Properties)19