use of javax.servlet.FilterConfig in project hbase by apache.
the class TestStaticUserWebFilter method testFilter.
@Test
public void testFilter() throws Exception {
FilterConfig config = mockConfig("myuser");
StaticUserFilter suf = new StaticUserFilter();
suf.init(config);
ArgumentCaptor<HttpServletRequestWrapper> wrapperArg = ArgumentCaptor.forClass(HttpServletRequestWrapper.class);
FilterChain chain = mock(FilterChain.class);
suf.doFilter(mock(HttpServletRequest.class), mock(ServletResponse.class), chain);
Mockito.verify(chain).doFilter(wrapperArg.capture(), Mockito.<ServletResponse>anyObject());
HttpServletRequestWrapper wrapper = wrapperArg.getValue();
assertEquals("myuser", wrapper.getUserPrincipal().getName());
assertEquals("myuser", wrapper.getRemoteUser());
suf.destroy();
}
use of javax.servlet.FilterConfig in project jetty.project by eclipse.
the class ProxyServletTest method testResponseHeadersAreNotRemoved.
@Test
public void testResponseHeadersAreNotRemoved() throws Exception {
startServer(new EmptyHttpServlet());
startProxy();
proxyContext.stop();
final String headerName = "X-Test";
final String headerValue = "test-value";
proxyContext.addFilter(new FilterHolder(new Filter() {
@Override
public void init(FilterConfig filterConfig) throws ServletException {
}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
((HttpServletResponse) response).addHeader(headerName, headerValue);
chain.doFilter(request, response);
}
@Override
public void destroy() {
}
}), "/*", EnumSet.of(DispatcherType.REQUEST));
proxyContext.start();
startClient();
ContentResponse response = client.newRequest("localhost", serverConnector.getLocalPort()).timeout(5, TimeUnit.SECONDS).send();
Assert.assertEquals(200, response.getStatus());
Assert.assertEquals(headerValue, response.getHeaders().get(headerName));
}
use of javax.servlet.FilterConfig in project sonarqube by SonarSource.
the class MasterServletFilterTest method should_init_and_destroy_filters.
@Test
public void should_init_and_destroy_filters() throws Exception {
ServletFilter filter = mock(ServletFilter.class);
FilterConfig config = mock(FilterConfig.class);
MasterServletFilter master = new MasterServletFilter();
master.init(config, singletonList(filter));
assertThat(master.getFilters()).containsOnly(filter);
verify(filter).init(config);
master.destroy();
verify(filter).destroy();
}
use of javax.servlet.FilterConfig in project sonarqube by SonarSource.
the class MasterServletFilterTest method should_propagate_initialization_failure.
@Test
public void should_propagate_initialization_failure() throws Exception {
expectedException.expect(IllegalStateException.class);
expectedException.expectMessage("foo");
ServletFilter filter = mock(ServletFilter.class);
doThrow(new IllegalStateException("foo")).when(filter).init(any(FilterConfig.class));
FilterConfig config = mock(FilterConfig.class);
MasterServletFilter filters = new MasterServletFilter();
filters.init(config, singletonList(filter));
}
use of javax.servlet.FilterConfig in project sonarqube by SonarSource.
the class MasterServletFilterTest method filters_should_be_optional.
@Test
public void filters_should_be_optional() throws Exception {
FilterConfig config = mock(FilterConfig.class);
MasterServletFilter filters = new MasterServletFilter();
filters.init(config, Collections.emptyList());
ServletRequest request = mock(HttpServletRequest.class);
ServletResponse response = mock(HttpServletResponse.class);
FilterChain chain = mock(FilterChain.class);
filters.doFilter(request, response, chain);
verify(chain).doFilter(request, response);
}
Aggregations