Search in sources :

Example 11 with FilterChain

use of javax.servlet.FilterChain in project neo4j by neo4j.

the class SecurityFilterTest method shouldPassThroughRequestToAnUnsecuredPath.

@Test
public void shouldPassThroughRequestToAnUnsecuredPath() throws Exception {
    // given
    SecurityRule rule = mock(SecurityRule.class);
    when(rule.forUriPath()).thenReturn("/some-path");
    FilterChain filterChain = mock(FilterChain.class);
    SecurityFilter securityFilter = new SecurityFilter(rule);
    HttpServletRequest request = mock(HttpServletRequest.class);
    when(request.getContextPath()).thenReturn("/some-other-path");
    // when
    securityFilter.doFilter(request, mock(HttpServletResponse.class), filterChain);
    // then
    verify(filterChain).doFilter(any(HttpServletRequest.class), any(HttpServletResponse.class));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) FilterChain(javax.servlet.FilterChain) HttpServletResponse(javax.servlet.http.HttpServletResponse) Test(org.junit.Test)

Example 12 with FilterChain

use of javax.servlet.FilterChain in project neo4j by neo4j.

the class SecurityFilterTest method shouldRemoveRules.

@Test
public void shouldRemoveRules() throws Exception {
    // given
    SecurityRule securityRule1 = mock(SecurityRule.class);
    when(securityRule1.forUriPath()).thenReturn("/securityRule1");
    SecurityRule securityRule2 = mock(SecurityRule.class);
    when(securityRule2.forUriPath()).thenReturn("/securityRule2");
    SecurityFilter securityFilter = new SecurityFilter(securityRule1, securityRule2);
    HttpServletRequest request = mock(HttpServletRequest.class);
    HttpServletResponse response = mock(HttpServletResponse.class);
    FilterChain filterChain = mock(FilterChain.class);
    // when
    securityFilter.destroy();
    securityFilter.doFilter(request, response, filterChain);
    // then
    verify(filterChain).doFilter(request, response);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) FilterChain(javax.servlet.FilterChain) HttpServletResponse(javax.servlet.http.HttpServletResponse) Test(org.junit.Test)

Example 13 with FilterChain

use of javax.servlet.FilterChain in project neo4j by neo4j.

the class SecurityFilterTest method shouldActivateRuleThatRejectsTheRequestForAMatchingPath.

@Test
public void shouldActivateRuleThatRejectsTheRequestForAMatchingPath() throws Exception {
    // given
    SecurityRule rule = mock(SecurityRule.class);
    when(rule.forUriPath()).thenReturn("/some-path");
    when(rule.isAuthorized(any(HttpServletRequest.class))).thenReturn(false);
    FilterChain filterChain = mock(FilterChain.class);
    SecurityFilter securityFilter = new SecurityFilter(rule);
    HttpServletRequest request = mock(HttpServletRequest.class);
    when(request.getContextPath()).thenReturn("/some-path");
    // when
    securityFilter.doFilter(request, mock(HttpServletResponse.class), filterChain);
    // then
    verify(filterChain, times(0)).doFilter(any(HttpServletRequest.class), any(HttpServletResponse.class));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) FilterChain(javax.servlet.FilterChain) HttpServletResponse(javax.servlet.http.HttpServletResponse) Test(org.junit.Test)

Example 14 with FilterChain

use of javax.servlet.FilterChain in project neo4j by neo4j.

the class NoCacheHtmlFilterTest method shouldPassThroughRequestsForNonHtmlResources.

@Test
public void shouldPassThroughRequestsForNonHtmlResources() throws Exception {
    // given
    HttpServletRequest request = mock(HttpServletRequest.class);
    when(request.getServletPath()).thenReturn("index.js");
    HttpServletResponse response = mock(HttpServletResponse.class);
    FilterChain filterChain = mock(FilterChain.class);
    // when
    new NoCacheHtmlFilter().doFilter(request, response, filterChain);
    // then
    verifyZeroInteractions(response);
    verify(filterChain).doFilter(request, response);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) FilterChain(javax.servlet.FilterChain) HttpServletResponse(javax.servlet.http.HttpServletResponse) Test(org.junit.Test)

Example 15 with FilterChain

use of javax.servlet.FilterChain in project neo4j by neo4j.

the class NoCacheHtmlFilterTest method shouldPassThroughRequestsWithNullServletPath.

@Test
public void shouldPassThroughRequestsWithNullServletPath() throws Exception {
    // given
    HttpServletRequest request = mock(HttpServletRequest.class);
    when(request.getServletPath()).thenReturn(null);
    HttpServletResponse response = mock(HttpServletResponse.class);
    FilterChain filterChain = mock(FilterChain.class);
    // when
    new NoCacheHtmlFilter().doFilter(request, response, filterChain);
    // then
    verifyZeroInteractions(response);
    verify(filterChain).doFilter(request, response);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) FilterChain(javax.servlet.FilterChain) HttpServletResponse(javax.servlet.http.HttpServletResponse) Test(org.junit.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