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));
}
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);
}
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));
}
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);
}
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);
}
Aggregations