@Test public void testPlainTextNoInjection() throws IOException { respWrapper.getWriter().write(NON_HTML_TEST_CASE_A); assertThat(printerResult.toString(), equalTo(NON_HTML_TEST_CASE_A)); }
@Test public void testHeadInjection() throws IOException { respWrapper.getWriter().write(HTML_TEST_CASE_A); assertThat(printerResult.toString(), equalTo(HTML_TEST_CASE_A_REFERENCE)); }
@Test public void testInvalidMarkupNoInjection() throws IOException { respWrapper.getWriter().write(NON_HTML_TEST_CASE_B); assertThat(printerResult.toString(), equalTo(NON_HTML_TEST_CASE_B)); }
@Test public void testBodyInjection() throws IOException { respWrapper.getWriter().write(HTML_TEST_CASE_B); assertThat(printerResult.toString(), equalTo(HTML_TEST_CASE_B_REFERENCE)); }
@Test public void testPreventCookieOverwriting() throws IOException { hook = new EUMInstrumentationHook(linker, tracer, dataHandler, config, agentBuilder); String sessionId = "234587"; when(dummyRequest.getCookies()).thenReturn(new Cookie[] { new Cookie(JSAgentBuilder.SESSION_ID_COOKIE_NAME, sessionId) }); Object[] params = new Object[] { dummyRequest, dummyResponse }; boolean intercepted = null != hook.beforeBody(METHOD_ID, dummyServlet, params, ssc); respWrapper.getWriter(); assertThat(intercepted, equalTo(false)); verify(dummyResponse, never()).addCookie(any(Cookie.class)); }
@Test public void testCookieGeneration() throws IOException { hook = new EUMInstrumentationHook(linker, tracer, dataHandler, config, agentBuilder); Object[] params = new Object[] { dummyRequest, dummyResponse }; boolean intercepted = null != hook.beforeBody(METHOD_ID, dummyServlet, params, ssc); respWrapper.getWriter(); assertThat(intercepted, equalTo(false)); verify(dummyResponse, times(1)).addCookie(any(Cookie.class)); }
@Test public void testTraceCorrelationInfoSet() throws IOException { when(tagPrinter.clone()).thenReturn(tagPrinter); SpanContextImpl context = mock(SpanContextImpl.class); when(context.getTraceId()).thenReturn(1234L); String traceID = ConversionUtils.toHexString(1234L); when(tracer.getCurrentContext()).thenReturn(context); ArgumentCaptor<String> traceIdJSSetting = ArgumentCaptor.forClass(String.class); ArgumentCaptor<Cookie> cookieCapture = ArgumentCaptor.forClass(Cookie.class); respWrapper.getWriter(); verify(tagPrinter).setSetting(eq(JSAgentBuilder.TRACEID_CORRELATION_SETTING), traceIdJSSetting.capture()); verify(dummyResponse, atLeast(1)).addCookie(cookieCapture.capture()); boolean cookieFound = false; for (Cookie cookie : cookieCapture.getAllValues()) { if (cookie.getName().equals(JSAgentBuilder.TRACEID_CORRELATION_COOKIE_PREFIX + traceID)) { cookieFound = true; } } assertThat("Trace Correlation cookie not set", cookieFound); assertThat(traceIdJSSetting.getValue(), equalTo("\"" + traceID + "\"")); }