@Test public void contextPathEmpty() throws Exception { this.request.addHeader(X_FORWARDED_PREFIX, ""); assertEquals("", filterAndGetContextPath()); }
private String filterAndGetContextPath() throws ServletException, IOException { return filterAndGetWrappedRequest().getContextPath(); }
@Test public void sendRedirectWithNoXForwardedAndAbsolutePath() throws Exception { String redirectedUrl = sendRedirect("/foo/bar"); assertEquals("/foo/bar", redirectedUrl); }
@Test public void shouldFilter() { testShouldFilter("Forwarded"); testShouldFilter(X_FORWARDED_HOST); testShouldFilter(X_FORWARDED_PORT); testShouldFilter(X_FORWARDED_PROTO); testShouldFilter(X_FORWARDED_SSL); }
@Test public void sendRedirectWithNoXForwardedAndDotDotPath() throws Exception { String redirectedUrl = sendRedirect("../foo/bar"); assertEquals("../foo/bar", redirectedUrl); }
@Test public void requestURLNewStringBuffer() throws Exception { this.request.addHeader(X_FORWARDED_PREFIX, "/prefix/"); this.request.setRequestURI("/mvc-showcase"); HttpServletRequest actual = filterAndGetWrappedRequest(); actual.getRequestURL().append("?key=value"); assertEquals("http://localhost/prefix/mvc-showcase", actual.getRequestURL().toString()); }
@Test public void contextPathWithTrailingSlash() throws Exception { this.request.addHeader(X_FORWARDED_PREFIX, "/foo/bar/"); assertEquals("/foo/bar", filterAndGetContextPath()); }
@Test public void sendRedirectWhenRequestOnlyAndNoXForwardedThenUsesRelativeRedirects() throws Exception { this.filter.setRelativeRedirects(true); String location = sendRedirect("/a"); assertEquals("/a", location); }
@Test public void requestUriWithForwardedPrefix() throws Exception { this.request.addHeader(X_FORWARDED_PREFIX, "/prefix"); this.request.setRequestURI("/mvc-showcase"); HttpServletRequest actual = filterAndGetWrappedRequest(); assertEquals("http://localhost/prefix/mvc-showcase", actual.getRequestURL().toString()); }
@Test public void contextPathWithTrailingSlashes() throws Exception { this.request.addHeader(X_FORWARDED_PREFIX, "/foo/bar/baz///"); assertEquals("/foo/bar/baz", filterAndGetContextPath()); }
@Test public void sendRedirectWithLocationHasScheme() throws Exception { this.request.addHeader(X_FORWARDED_PROTO, "https"); this.request.addHeader(X_FORWARDED_HOST, "example.com"); this.request.addHeader(X_FORWARDED_PORT, "443"); String location = "http://other.info/foo/bar"; String redirectedUrl = sendRedirect(location); assertEquals(location, redirectedUrl); }
@Test public void requestUriWithForwardedPrefixTrailingSlash() throws Exception { this.request.addHeader(X_FORWARDED_PREFIX, "/prefix/"); this.request.setRequestURI("/mvc-showcase"); HttpServletRequest actual = filterAndGetWrappedRequest(); assertEquals("http://localhost/prefix/mvc-showcase", actual.getRequestURL().toString()); }
@Test public void contextPathWithForwardedPrefixTrailingSlash() throws Exception { this.request.addHeader(X_FORWARDED_PREFIX, "/prefix/"); this.request.setContextPath("/mvc-showcase"); String actual = filterAndGetContextPath(); assertEquals("/prefix", actual); }
@Test public void sendRedirectWithLocationDotDotPath() throws Exception { this.request.addHeader(X_FORWARDED_PROTO, "https"); this.request.addHeader(X_FORWARDED_HOST, "example.com"); this.request.addHeader(X_FORWARDED_PORT, "443"); String redirectedUrl = sendRedirect("parent/../foo/bar"); assertEquals("https://example.com/foo/bar", redirectedUrl); }
@Test public void requestUriPreserveEncoding() throws Exception { this.request.setContextPath("/app"); this.request.setRequestURI("/app/path%20with%20spaces/"); HttpServletRequest actual = filterAndGetWrappedRequest(); assertEquals("/app", actual.getContextPath()); assertEquals("/app/path%20with%20spaces/", actual.getRequestURI()); assertEquals("http://localhost/app/path%20with%20spaces/", actual.getRequestURL().toString()); }
@Test public void contextPathWithForwardedPrefix() throws Exception { this.request.addHeader(X_FORWARDED_PREFIX, "/prefix"); this.request.setContextPath("/mvc-showcase"); String actual = filterAndGetContextPath(); assertEquals("/prefix", actual); }
@Test public void sendRedirectWithLocationSlashSlash() throws Exception { this.request.addHeader(X_FORWARDED_PROTO, "https"); this.request.addHeader(X_FORWARDED_HOST, "example.com"); this.request.addHeader(X_FORWARDED_PORT, "443"); String location = "//other.info/foo/bar"; String redirectedUrl = sendRedirect(location); assertEquals("https:" + location, redirectedUrl); }
@Test public void contextPathPreserveEncoding() throws Exception { this.request.setContextPath("/app%20"); this.request.setRequestURI("/app%20/path/"); HttpServletRequest actual = filterAndGetWrappedRequest(); assertEquals("/app%20", actual.getContextPath()); assertEquals("/app%20/path/", actual.getRequestURI()); assertEquals("http://localhost/app%20/path/", actual.getRequestURL().toString()); }
@Test public void sendRedirectWithLocationSlashSlashParentDotDot() throws Exception { this.request.addHeader(X_FORWARDED_PROTO, "https"); this.request.addHeader(X_FORWARDED_HOST, "example.com"); this.request.addHeader(X_FORWARDED_PORT, "443"); String location = "//other.info/parent/../foo/bar"; String redirectedUrl = sendRedirect(location); assertEquals("https:" + location, redirectedUrl); }
@Test public void requestUriPreserveSemicolonContent() throws Exception { this.request.setContextPath(""); this.request.setRequestURI("/path;a=b/with/semicolon"); HttpServletRequest actual = filterAndGetWrappedRequest(); assertEquals("", actual.getContextPath()); assertEquals("/path;a=b/with/semicolon", actual.getRequestURI()); assertEquals("http://localhost/path;a=b/with/semicolon", actual.getRequestURL().toString()); }