use of javax.servlet.ServletRequest in project ddf by codice.
the class LoginFilterTest method testBadSubject.
/**
* Test with a bad subject - shouldn't call the filter chain, just returns.
*
* @throws IOException
* @throws ServletException
*/
@Test
public void testBadSubject() throws IOException, ServletException {
FilterConfig filterConfig = mock(FilterConfig.class);
LoginFilter loginFilter = new LoginFilter();
loginFilter.setSessionFactory(sessionFactory);
try {
loginFilter.init(filterConfig);
} catch (ServletException e) {
fail(e.getMessage());
}
HttpServletRequest servletRequest = new TestHttpServletRequest();
servletRequest.setAttribute("ddf.security.securityToken", mock(SecurityToken.class));
HttpServletResponse servletResponse = mock(HttpServletResponse.class);
FilterChain filterChain = new FilterChain() {
@Override
public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException {
fail("Should not have continued down the filter chain without a valid Subject");
}
};
loginFilter.doFilter(servletRequest, servletResponse, filterChain);
}
use of javax.servlet.ServletRequest in project sling by apache.
the class LogTracerTest method checkTracing.
@Test
public void checkTracing() throws Exception {
HttpServletRequest request = mock(SlingHttpServletRequest.class);
HttpServletResponse response = mock(HttpServletResponse.class);
when(request.getParameter(LogTracer.PARAM_TRACER_CONFIG)).thenReturn("a.b.c;level=trace,a.b;level=debug");
activateTracer();
Level oldLevel = rootLogger().getLevel();
rootLogger().setLevel(Level.INFO);
FilterChain chain = new FilterChain() {
@Override
public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException {
TurboFilter turboFilter = context.getService(TurboFilter.class);
assertNotNull(turboFilter);
getLogContext().addTurboFilter(turboFilter);
getLogger("a").info("a-info");
getLogger("a").debug("a-debug");
getLogger("a.b").info("a.b-info");
getLogger("a.b").debug("a.b-debug");
getLogger("a.b").trace("a.b-trace");
getLogger("a.b.c").debug("a.b.c-debug");
getLogger("a.b.c").trace("a.b.c-trace");
getLogger("a.b.c.d").trace("a.b.c.d-trace");
if (getLogger("a.b.c").isTraceEnabled()) {
getLogger("a.b.c").trace("a.b.c-trace2");
}
}
};
Filter filter = getFilter(true);
filter.doFilter(request, response, chain);
assertNull(context.getService(TurboFilter.class));
List<String> logs = logCollector.getLogs();
assertThat(logs, hasItem("a-info"));
assertThat(logs, not(hasItem("a-debug")));
assertThat(logs, hasItem("a.b-info"));
assertThat(logs, hasItem("a.b-debug"));
assertThat(logs, not(hasItem("a.b-trace")));
assertThat(logs, hasItem("a.b.c-debug"));
assertThat(logs, hasItem("a.b.c-trace"));
assertThat(logs, hasItem("a.b.c-trace2"));
assertThat(logs, hasItem("a.b.c.d-trace"));
rootLogger().setLevel(oldLevel);
}
use of javax.servlet.ServletRequest in project sling by apache.
the class LogTracerTest method turboFilterRegisteredWhenTracingRequested.
@Test
public void turboFilterRegisteredWhenTracingRequested() throws Exception {
HttpServletRequest request = mock(HttpServletRequest.class);
HttpServletResponse response = mock(HttpServletResponse.class);
when(request.getHeader(LogTracer.HEADER_TRACER_CONFIG)).thenReturn("foo.bar");
activateTracer();
FilterChain chain = new FilterChain() {
@Override
public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException {
assertNotNull(context.getService(TurboFilter.class));
}
};
Filter filter = getFilter(false);
filter.doFilter(request, response, chain);
assertNull("TurboFilter should get removed once request is done", context.getService(TurboFilter.class));
}
use of javax.servlet.ServletRequest in project sling by apache.
the class LogTracerTest method recordingWithoutTracing.
@Test
public void recordingWithoutTracing() throws Exception {
activateTracerAndServlet();
MockSlingHttpServletRequest request = new MockSlingHttpServletRequest(context.bundleContext()) {
@Override
public RequestProgressTracker getRequestProgressTracker() {
return createTracker("x", "y");
}
@Override
public String getRequestURI() {
return "foo";
}
};
request.setHeader(TracerLogServlet.HEADER_TRACER_RECORDING, "true");
HttpServletResponse response = mock(HttpServletResponse.class);
FilterChain chain = new FilterChain() {
@Override
public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException {
//No TurboFilter should be registered if tracing is not requested
assertNull(context.getService(TurboFilter.class));
}
};
prepareChain(chain).doFilter(request, response);
String requestId = getRequestId(response);
assertNotNull(requestId);
Recording r = ((TracerLogServlet) context.getService(Servlet.class)).getRecording(requestId);
assertTrue(r instanceof JSONRecording);
JSONRecording jr = (JSONRecording) r;
StringWriter sw = new StringWriter();
jr.render(sw);
JsonObject json = Json.createReader(new StringReader(sw.toString())).readObject();
assertEquals(2, json.getJsonArray("requestProgressLogs").size());
}
use of javax.servlet.ServletRequest in project sling by apache.
the class LogTracerTest method turboFilterRegisteredWhenTracingRequested_Sling.
@Test
public void turboFilterRegisteredWhenTracingRequested_Sling() throws Exception {
HttpServletRequest request = mock(SlingHttpServletRequest.class);
HttpServletResponse response = mock(HttpServletResponse.class);
when(request.getParameter(LogTracer.PARAM_TRACER_CONFIG)).thenReturn("foo.bar");
activateTracer();
FilterChain chain = new FilterChain() {
@Override
public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException {
assertNotNull(context.getService(TurboFilter.class));
}
};
Filter filter = getFilter(true);
filter.doFilter(request, response, chain);
assertNull("TurboFilter should get removed once request is done", context.getService(TurboFilter.class));
}
Aggregations