public void testSimple() throws Exception { HttpServletRequest req = request("GET", "/foo/bar", "12.34.56.78", null, null); filter.doFilter(req, response(), chain); RequestData data = dao.getLast(); assertEquals("GET", data.getHttpMethod()); assertEquals("/foo/bar", data.getPath()); assertEquals("12.34.56.78", data.getRemoteAddr()); assertNull(data.getHttpReferer()); }
public void testReferer() throws Exception { HttpServletRequest req = request("GET", "/foo/bar", "12.34.56.78", null, "http://testhost/testpath"); filter.doFilter(req, response(), chain); RequestData data = dao.getLast(); assertEquals("GET", data.getHttpMethod()); assertEquals("/foo/bar", data.getPath()); assertEquals("12.34.56.78", data.getRemoteAddr()); assertEquals("http://testhost/testpath", data.getHttpReferer()); } public void testReferrer() throws Exception {
public void testReferrer() throws Exception { // "Referrer" was misspelled in the HTTP spec, check if it works with the "correct" // spelling. MockHttpServletRequest req = request("POST", "/bar/foo", "78.56.34.12", null, null); ((MockHttpServletRequest)req).setHeader("Referrer", "http://testhost/testpath"); filter.doFilter(req, response(), chain); RequestData data = dao.getLast(); assertEquals("POST", data.getHttpMethod()); assertEquals("/bar/foo", data.getPath()); assertEquals("78.56.34.12", data.getRemoteAddr()); assertEquals("http://testhost/testpath", data.getHttpReferer()); }
@Test public void testSimple() throws Exception { HttpServletRequest req = request("GET", "/foo/bar", "12.34.56.78", null, null); filter.doFilter(req, response(), chain); RequestData data = dao.getLast(); assertEquals("GET", data.getHttpMethod()); assertEquals("/foo/bar", data.getPath()); assertEquals("12.34.56.78", data.getRemoteAddr()); assertNull(data.getHttpReferer()); }
@Test public void testReferer() throws Exception { HttpServletRequest req = request("GET", "/foo/bar", "12.34.56.78", null, "http://testhost/testpath"); filter.doFilter(req, response(), chain); RequestData data = dao.getLast(); assertEquals("GET", data.getHttpMethod()); assertEquals("/foo/bar", data.getPath()); assertEquals("12.34.56.78", data.getRemoteAddr()); assertEquals("http://testhost/testpath", data.getHttpReferer()); }
public void testWithBody() throws Exception { chain.setServlet(new HttpServlet() { @Override public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException { req.getInputStream().read(new byte[LONG_BODY_SIZE]); res.getOutputStream().write("hello".getBytes()); } }); HttpServletRequest req = request("POST", "/bar/foo", "78.56.34.12", "baz", null); filter.doFilter(req, response(), chain); RequestData data = dao.getLast(); assertEquals("POST", data.getHttpMethod()); assertEquals("/bar/foo", data.getPath()); assertEquals("78.56.34.12", data.getRemoteAddr()); assertNull(data.getHttpReferer()); assertEquals(new String(data.getBody()), "baz"); assertEquals(3, data.getBodyContentLength()); assertEquals(5, data.getResponseLength()); } public void testWithLongBody() throws Exception {
@Test public void testWithBody() throws Exception { chain = new MockFilterChain( new HttpServlet() { @Override public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException { req.getInputStream().read(new byte[LONG_BODY_SIZE]); res.getOutputStream().write("hello".getBytes()); } }); HttpServletRequest req = request("POST", "/bar/foo", "78.56.34.12", "baz", null); filter.doFilter(req, response(), chain); RequestData data = dao.getLast(); assertEquals("POST", data.getHttpMethod()); assertEquals("/bar/foo", data.getPath()); assertEquals("78.56.34.12", data.getRemoteAddr()); assertNull(data.getHttpReferer()); assertEquals(new String(data.getBody()), "baz"); assertEquals(3, data.getBodyContentLength()); assertEquals(5, data.getResponseLength()); }
@Test public void testReferrer() throws Exception { // "Referrer" was misspelled in the HTTP spec, check if it works with the "correct" // spelling. MockHttpServletRequest req = request("POST", "/bar/foo", "78.56.34.12", null, null); ((MockHttpServletRequest) req).addHeader("Referrer", "http://testhost/testpath"); filter.doFilter(req, response(), chain); RequestData data = dao.getLast(); assertEquals("POST", data.getHttpMethod()); assertEquals("/bar/foo", data.getPath()); assertEquals("78.56.34.12", data.getRemoteAddr()); assertEquals("http://testhost/testpath", data.getHttpReferer()); assertNull(data.getCacheResult()); assertNull(data.getMissReason()); }