From c3ea7693dfc566888e539136736ab3928c9ad29d Mon Sep 17 00:00:00 2001 From: Paul Tuckey Date: Thu, 2 Mar 2023 20:25:47 +1300 Subject: [PATCH 01/19] example 2 --- container-test2/example-webapp/pom.xml | 77 +++ .../MockRewriteMatch.java | 70 +++ .../urlrewriteviacontainer/TestRunObj.java | 248 +++++++++ .../webapp/WEB-INF/urlrewrite-decode-none.xml | 28 + .../webapp/WEB-INF/urlrewrite-decode-utf8.xml | 16 + .../src/main/webapp/WEB-INF/urlrewrite.xml | 501 ++++++++++++++++++ .../src/main/webapp/WEB-INF/web.xml | 65 +++ .../example-webapp/src/main/webapp/echo.jsp | 1 + .../src/main/webapp/gzip-me.jsp | 1 + .../src/main/webapp/mod/index.jsp | 1 + .../main/webapp/no-decode-test-D%25%2cD.jsp | 1 + .../src/main/webapp/products.jsp | 1 + .../src/main/webapp/settest.jsp | 1 + .../src/main/webapp/test/filterRedirector.jsp | 0 .../src/main/webapp/test/test.jsp | 7 + 15 files changed, 1018 insertions(+) create mode 100644 container-test2/example-webapp/pom.xml create mode 100644 container-test2/example-webapp/src/main/java/org/tuckey/web/filters/urlrewriteviacontainer/MockRewriteMatch.java create mode 100644 container-test2/example-webapp/src/main/java/org/tuckey/web/filters/urlrewriteviacontainer/TestRunObj.java create mode 100644 container-test2/example-webapp/src/main/webapp/WEB-INF/urlrewrite-decode-none.xml create mode 100644 container-test2/example-webapp/src/main/webapp/WEB-INF/urlrewrite-decode-utf8.xml create mode 100644 container-test2/example-webapp/src/main/webapp/WEB-INF/urlrewrite.xml create mode 100644 container-test2/example-webapp/src/main/webapp/WEB-INF/web.xml create mode 100644 container-test2/example-webapp/src/main/webapp/echo.jsp create mode 100644 container-test2/example-webapp/src/main/webapp/gzip-me.jsp create mode 100644 container-test2/example-webapp/src/main/webapp/mod/index.jsp create mode 100644 container-test2/example-webapp/src/main/webapp/no-decode-test-D%25%2cD.jsp create mode 100644 container-test2/example-webapp/src/main/webapp/products.jsp create mode 100644 container-test2/example-webapp/src/main/webapp/settest.jsp create mode 100644 container-test2/example-webapp/src/main/webapp/test/filterRedirector.jsp create mode 100644 container-test2/example-webapp/src/main/webapp/test/test.jsp diff --git a/container-test2/example-webapp/pom.xml b/container-test2/example-webapp/pom.xml new file mode 100644 index 00000000..98720da0 --- /dev/null +++ b/container-test2/example-webapp/pom.xml @@ -0,0 +1,77 @@ + + + 4.0.0 + org.tuckey + example-webapp + war + 5.0.0 + Example Webapp + http://www.tuckey.org/urlrewrite/ + 2001 + Example webapp for Integration tests for UrlRewriteFilter + + Paul Tuckey + + + + + BSD + http://www.opensource.org/licenses/bsd-license.php + repo + + + + + + Paul Tuckey + + + + + webapp + + + maven-compiler-plugin + 3.5.1 + + + org.apache.maven.plugins + maven-war-plugin + 3.3.1 + + + + WEB-INF + target + + urlrewrite-generated.xml + + + + + + + + + + + org.tuckey + urlrewritefilter + 5.0.0-SNAPSHOT + + + javax.servlet + javax.servlet-api + 3.1.0 + provided + + + + + UTF-8 + UTF-8 + 11 + 11 + + + \ No newline at end of file diff --git a/container-test2/example-webapp/src/main/java/org/tuckey/web/filters/urlrewriteviacontainer/MockRewriteMatch.java b/container-test2/example-webapp/src/main/java/org/tuckey/web/filters/urlrewriteviacontainer/MockRewriteMatch.java new file mode 100644 index 00000000..5f821cf3 --- /dev/null +++ b/container-test2/example-webapp/src/main/java/org/tuckey/web/filters/urlrewriteviacontainer/MockRewriteMatch.java @@ -0,0 +1,70 @@ +/** + * Copyright (c) 2005-2007, Paul Tuckey + * All rights reserved. + * ==================================================================== + * Licensed under the BSD License. Text as follows. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * - Neither the name tuckey.org nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + */ +package org.tuckey.web.filters.urlrewriteviacontainer; + +import org.tuckey.web.filters.urlrewrite.extend.RewriteMatch; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + + +/** + * Mock RewriteMatch that can be used for testing. Included here and not in test folder as it needs to be deployed with + * the main library. + * + * @author Paul Tuckey + * @version $Revision: 33 $ $Date: 2006-09-12 16:41:56 +1200 (Tue, 12 Sep 2006) $ + */ +public class MockRewriteMatch extends RewriteMatch { + + private static long calledTime = 0; + + public boolean execute(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + calledTime = System.currentTimeMillis(); + try { + Thread.sleep(10); + } catch (InterruptedException e) { + // don't worry + } + return true; + } + + public static long getCalledTime() { + return calledTime; + } +} diff --git a/container-test2/example-webapp/src/main/java/org/tuckey/web/filters/urlrewriteviacontainer/TestRunObj.java b/container-test2/example-webapp/src/main/java/org/tuckey/web/filters/urlrewriteviacontainer/TestRunObj.java new file mode 100644 index 00000000..67b99605 --- /dev/null +++ b/container-test2/example-webapp/src/main/java/org/tuckey/web/filters/urlrewriteviacontainer/TestRunObj.java @@ -0,0 +1,248 @@ +/** + * Copyright (c) 2005-2007, Paul Tuckey + * All rights reserved. + * ==================================================================== + * Licensed under the BSD License. Text as follows. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * - Neither the name tuckey.org nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + */ +package org.tuckey.web.filters.urlrewriteviacontainer; + +import org.tuckey.web.filters.urlrewrite.extend.RewriteMatch; + +import javax.servlet.FilterChain; +import javax.servlet.ServletConfig; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.io.PrintWriter; + +/** + * RunObject that can be used for testing. Included here and not in test folder as it needs to be deployed with the + * main library. + * + * @author Paul Tuckey + * @version $Revision: 33 $ $Date: 2006-09-12 16:41:56 +1200 (Tue, 12 Sep 2006) $ + */ +public class TestRunObj { + private static boolean runCalled; + private static boolean destroyCalled; + private static boolean initCalled; + private static boolean nonDefaultRunCalled; + private static ServletConfig servletConfig; + + private static int createdCount = 0; + private static String paramStr = null; + private static long runWithChainParamAfterDoFilter = 0; + + public TestRunObj() { + createdCount++; + } + + public void run(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) + throws ServletException, IOException { + runCalled = true; + + PrintWriter sos = httpServletResponse.getWriter(); + if (sos == null) return; + sos.print("this is " + TestRunObj.class.getName()); + sos.close(); + } + + + public MockRewriteMatch runWithReturnedObj(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) + throws ServletException, IOException { + return new MockRewriteMatch(); + } + + public void nonDefaultRun(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) + throws ServletException, IOException { + nonDefaultRunCalled = true; + } + + public String runThatReturns(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) + throws ServletException, IOException { + return "aaabbb"; + } + + public String runWithParam(int i) + throws ServletException, IOException { + paramStr = "" + i; + return paramStr; + } + + public String runWithNoParams() + throws ServletException, IOException { + paramStr = "[no params]"; + return paramStr; + } + + public String runWithChainParam(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, FilterChain c) + throws ServletException, IOException { + paramStr = "" + c; + c.doFilter(httpServletRequest, httpServletResponse); + try { + Thread.sleep(10); + } catch (InterruptedException e) { + // + } + runWithChainParamAfterDoFilter = System.currentTimeMillis(); + return paramStr; + } + + public static long getRunWithChainParamAfterDoFilter() { + return runWithChainParamAfterDoFilter; + } + + public String runWithPrimitiveParam(int i, char c, double d, float f, short s, byte b, boolean b2, String s2) + throws ServletException, IOException { + paramStr = i + "," + c + "," + d + "," + f + "," + s + "," + b + "," + b2 + "," + s2; + return paramStr; + } + + public String runWithObjParam(Integer i, Character c, Double d, Float f, Short s, Byte b, Boolean b2, String s2) + throws ServletException, IOException { + paramStr = i + "," + c + "," + d + "," + f + "," + s + "," + b + "," + b2 + "," + s2; + return paramStr; + } + + public static String getParamStr() { + return paramStr; + } + + public void runNullPointerException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) + throws ServletException, IOException { + exceptionGenerator.doNullPointer(); + } + + public void runRuntiumeException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) + throws ServletException, IOException { + exceptionGenerator.doRuntime(); + } + + public void runServletException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) + throws ServletException, IOException { + exceptionGenerator.doServlet(); + } + + public void runIOException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) + throws ServletException, IOException { + exceptionGenerator.doIO(); + } + + public void runCustomException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) + throws TestExceptionGenerator.CustomException { + exceptionGenerator.doCustom(); + } + + TestExceptionGenerator exceptionGenerator = new TestExceptionGenerator(); + + private class TestExceptionGenerator { + public void doNullPointer() { + String aaa = null; + // YES we WANT a null pointer here + aaa.toLowerCase(); + } + + public void doRuntime() { + throw new RuntimeException("shit!"); + } + + public void doServlet() throws ServletException { + throw new ServletException("serv"); + } + + public void doIO() throws IOException { + throw new IOException("me i.o. has gone crazy"); + } + + public void doCustom() throws CustomException { + throw new CustomException(); + } + + public class CustomException extends Exception { + + } + } + + public RewriteMatch trialException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, + ClassNotFoundException e) { + return new MockRewriteMatch(); + } + + /** + * Do not delete! used in RunTest. + */ + private void privateRun(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) { + // do nothing + } + + public void destroy() { + destroyCalled = true; + } + + public void init(ServletConfig config) throws ServletException { + servletConfig = config; + initCalled = true; + } + + public static boolean isRunCalled() { + return runCalled; + } + + public static int getCreatedCount() { + return createdCount; + } + + public static void resetTestFlags() { + createdCount = 0; + runCalled = false; + destroyCalled = false; + initCalled = false; + nonDefaultRunCalled = false; + servletConfig = null; + } + + public static ServletConfig getTestServletConfig() { + return servletConfig; + } + + public static boolean isDestroyCalled() { + return destroyCalled; + } + + public static boolean isInitCalled() { + return initCalled; + } + + public static boolean isNonDefaultRunCalled() { + return nonDefaultRunCalled; + } +} diff --git a/container-test2/example-webapp/src/main/webapp/WEB-INF/urlrewrite-decode-none.xml b/container-test2/example-webapp/src/main/webapp/WEB-INF/urlrewrite-decode-none.xml new file mode 100644 index 00000000..48c5793a --- /dev/null +++ b/container-test2/example-webapp/src/main/webapp/WEB-INF/urlrewrite-decode-none.xml @@ -0,0 +1,28 @@ + + + + + + + + + + utf test + /utf/(m%C4%81ori)/ + %{context-path}/utf-redir/done/$1/ + + + + Proxy + ^/no-decode-test/(.*)$ + /no-decode-test-$1.jsp + + + + ^/query-string-no-decode/(.*)$ + http://query-string-no-decode-result.com/?q=$1&another=${unescape:$1} + + + \ No newline at end of file diff --git a/container-test2/example-webapp/src/main/webapp/WEB-INF/urlrewrite-decode-utf8.xml b/container-test2/example-webapp/src/main/webapp/WEB-INF/urlrewrite-decode-utf8.xml new file mode 100644 index 00000000..d0fc098c --- /dev/null +++ b/container-test2/example-webapp/src/main/webapp/WEB-INF/urlrewrite-decode-utf8.xml @@ -0,0 +1,16 @@ + + + + + + + + + utf test + ^/utf/māori/$ + %{context-path}/utf-redir/done/ + + + \ No newline at end of file diff --git a/container-test2/example-webapp/src/main/webapp/WEB-INF/urlrewrite.xml b/container-test2/example-webapp/src/main/webapp/WEB-INF/urlrewrite.xml new file mode 100644 index 00000000..dfcff1da --- /dev/null +++ b/container-test2/example-webapp/src/main/webapp/WEB-INF/urlrewrite.xml @@ -0,0 +1,501 @@ + + + + + + + + + The rule means that requests to /test/status/ will be redirected to /rewrite-status + the url will be rewritten. + + /test/status/ + %{context-path}/rewrite-status + + + + /spelling/([a-z]+) + /spelling/index.jsp?spell=$1 + + + + gEt + /get/ + /getty/lotsofgetty/ + + + + /products/([0-9]+) + /products.jsp?product_id=$1 + + + + /multiple/products/([0-9]+) + /multiple/products.jsp?product_id=$1 + + + + /multiple/(.*) + /$1 + + + + ^/settest/([0-9]+)$ + hello! + none-fool + $1 + DELETE + /settest.jsp + + + + + http method test + + PROPFIND + PUT + /.* + /go-away-nasty-methods.html + + + + 1970 + 2020 + /time/year/current + /echo.jsp?echo=yearisbetween1970and3000 + + + + ^/services/(.*) + %{context-path}/axis/services/$1 + + + + ^/weblog/([0-9]+)/([0-9]+)/$ + /weblog/index.jsp?year=$1&month=$2 + + + + Domain Name Check + www.example.com + /eriktest(.*) + http://www.example.com/context$1 + + + + 403 null Check + ^/hideme/.*$ + 403 + null + + + + encode test + /went to bahamas/ + %{context-path}/bahamas/ + + + + Bad referers test + + + Prevent vermin from appearing in your logs by denying nasty referers + + + ^http://www\.badguys\.com/.*$ + /(.*) + 403 + null + + + + + admin + bigboss + ^/admin/(.*)$ + /go-away-please.html + + + + + Simple Run Test + ^/run/test/(.*)$ + + null + + + + + + + + + + + + + Canonical URLs + + On some webservers there are more than one URL for a resource. Usually there are canonical URLs (which + should be actually used and distributed) and those which are just shortcuts, internal ones, etc. Independent + of which URL the user supplied with the request he should finally see the canonical one only. + + We do an external HTTP redirect for all non-canonical URLs to fix them in the location view of the Browser + and for all subsequent requests. In the example ruleset below we replace /~user by the canonical /u/user and + fix a missing trailing slash for /u/user. + + RewriteRule ^/~([^/]+)/?(.*) /u/$1/$2 [R] + RewriteRule ^/([uge])/([^/]+)$ /$1/$2/ [R] + + ^/~([^/]+)/?(.*) + /u/$1/$2 + + + ^/([uge])/([^/]+)$ + /$1/$2/ + + + + + Canonical Hostnames + + The goal of this rule is to force the use of a particular hostname, in preference to other hostnames which + may be used to reach the same site. For example, if you wish to force the use of www.example.com instead of + example.com, you might use a variant of the following recipe. + + RewriteCond %{HTTP_HOST} !^fully\.qualified\.domain\.name [NC] + RewriteCond %{HTTP_HOST} !^$ + RewriteRule ^/(.*) http://fully.qualified.domain.name/$1 [L,R] + + !^fully\.qualified\.domain\.name + ^$ + ^/(.*) + http://fully.qualified.domain.name/$1 + + + + + Moved DocumentRoot + + Usually the DocumentRoot of the webserver directly relates to the URL "/". But often this data is not + really of top-level priority, it is perhaps just one entity of a lot of data pools. For instance at our + Intranet sites there are /e/www/ (the homepage for WWW), /e/sww/ (the homepage for the Intranet) etc. Now + because the data of the DocumentRoot stays at /e/www/ we had to make sure that all inlined images and other + stuff inside this data pool work for subsequent requests. + + We just redirect the URL / to /e/www/. While is seems trivial it is actually trivial with mod_rewrite, only. + Because the typical old mechanisms of URL Aliases (as provides by mod_alias and friends) only used prefix + matching. With this you cannot do such a redirection because the DocumentRoot is a prefix of all URLs. + With mod_rewrite it is really trivial: + + RewriteRule ^/$ /e/www/ [R] + + ^/$ + /e/www/ + + + + + Trailing Slash Problem + + Every webmaster can sing a song about the problem of the trailing slash on URLs referencing directories. + If they are missing, the server dumps an error, because if you say /~quux/foo instead of /~quux/foo/ then + the server searches for a file named foo. And because this file is a directory it complains. Actually it + tries to fix it itself in most of the cases, but sometimes this mechanism need to be emulated by you. For + instance after you have done a lot of complicated URL rewritings to CGI scripts etc. + + The solution to this subtle problem is to let the server add the trailing slash automatically. To do this + correctly we have to use an external redirect, so the browser correctly requests subsequent images etc. If + we only did a internal rewrite, this would only work for the directory page, but would go wrong when any + images are included into this page with relative URLs, because the browser would request an in-lined object. + For instance, a request for image.gif in /~quux/foo/index.html would become /~quux/image.gif without the + external redirect! + + ^/~quux/foo$ + /~quux/foo/ + + + + + Move Homedirs to Different Webserver + + Many webmasters have asked for a solution to the following situation: They wanted to redirect just all + homedirs on a webserver to another webserver. They usually need such things when establishing a newer + webserver which will replace the old one over time. + + The solution is trivial with mod_rewrite (and urlrewrite filter). On the old webserver we just redirect all + /~user/anypath URLs to http://newserver/~user/anypath. + + RewriteRule ^/~(.+) http://newserver/~$1 [R,L] + + ^/~(.+) + http://newserver/~$1 + + + + + Structured Homedirs + + Some sites with thousands of users usually use a structured homedir layout, i.e. each homedir is in a + subdirectory which begins for instance with the first character of the username. So, /~foo/anypath is + /home/f/foo/.www/anypath while /~bar/anypath is /home/b/bar/.www/anypath. + + We use the following ruleset to expand the tilde URLs into exactly the above layout. + + RewriteRule ^/~(([a-z])[a-z0-9]+)(.*) /home/$2/$1/.www$3 + + ^/~(([a-z])[a-z0-9]+)(.*) + /home/$2/$1/.www$3 + + + + + Redirect Homedirs For Foreigners + + We want to redirect homedir URLs to another webserver www.somewhere.com when the requesting user does not + stay in the local domain ourdomain.com. This is sometimes used in virtual host contexts. + + Just a rewrite condition: + + RewriteCond %{REMOTE_HOST} !^.+\.ourdomain\.com$ + RewriteRule ^(/~.+) http://www.somewhere.com/$1 [R,L] + + !^.+\.ourdomain\.com$ + ^(/~.+) + http://www.somewhere.com/$1 + + + + + Time-Dependent Rewriting + + When tricks like time-dependent content should happen a lot of webmasters still use CGI scripts which do for + instance redirects to specialized pages. How can it be done via mod_rewrite? + + There are a lot of types in conjunction with operators we can do time-dependent redirects: + + RewriteCond %{TIME_HOUR}%{TIME_MIN} >0700 + RewriteCond %{TIME_HOUR}%{TIME_MIN} <1900 + RewriteRule ^foo\.html$ foo.day.html + RewriteRule ^foo\.html$ foo.night.html + + 7 + 19 + ^foo\.html$ + foo.day.html + + + ^foo\.html$ + foo.night.html + + + + + + + Assume we have recently renamed the page foo.html to bar.html and now want to provide the old URL for + backward compatibility. Actually we want that users of the old URL even not recognize that the pages was + renamed. + + We rewrite the old URL to the new one internally via the following rule: + + RewriteBase /~quux/ + RewriteRule ^foo\.html$ bar.html + + ^/~quux/foo\.html$ + /~quux/bar.html + + + + + From Old to New (extern) + + Assume again that we have recently renamed the page foo.html to bar.html and now want to provide the old URL + for backward compatibility. But this time we want that the users of the old URL get hinted to the new one, + i.e. their browsers Location field should change, too. + + We force a HTTP redirect to the new URL which leads to a change of the browsers and thus the users view: + + RewriteBase /~quux/ + RewriteRule ^foo\.html$ bar.html [R] + + ^/~quux/foo\.html$ + /~quux/bar.html + + + + + Browser Dependent Content + + At least for important top-level pages it is sometimes necessary to provide the optimum of browser dependent + content, i.e. one has to provide a maximum version for the latest Netscape variants, a minimum version for + the Lynx browsers and a average feature version for all others. + + We cannot use content negotiation because the browsers do not provide their type in that form. Instead we + have to act on the HTTP header "User-Agent". The following condig does the following: If the HTTP header + "User-Agent" begins with "Mozilla/3", the page foo.html is rewritten to foo.NS.html and and the rewriting + stops. If the browser is "Lynx" or "Mozilla" of version 1 or 2 the URL becomes foo.20.html. All other + browsers receive page foo.32.html. This is done by the following ruleset: + + RewriteCond %{HTTP_USER_AGENT} ^Mozilla/3.* + RewriteRule ^foo\.html$ foo.NS.html [L] + + RewriteCond %{HTTP_USER_AGENT} ^Lynx/.* [OR] + RewriteCond %{HTTP_USER_AGENT} ^Mozilla/[12].* + RewriteRule ^foo\.html$ foo.20.html [L] + + RewriteRule ^foo\.html$ foo.32.html [L] + + ^Mozilla/3.* + ^foo\.html$ + foo.NS.html + + + ^Lynx/.* + ^Mozilla/[12].* + ^foo\.html$ + foo.20.html + + + ^foo\.html$ + foo.32.html + + + + + From Static to Dynamic + + How can we transform a static page foo.html into a dynamic variant foo.cgi in a seamless way, i.e. without + notice by the browser/user. + + We just rewrite the URL to the jsp/servlet and force the correct MIME-type so it gets really run as + a CGI-script. This way a request to /~quux/foo.html internally leads to the invocation of /~quux/foo.jsp. + + RewriteBase /~quux/ + RewriteRule ^foo\.html$ foo.cgi [T=application/x-httpd-cgi] + + ^/~quux/foo\.html$ + /~quux/foo.jsp + + + + Blocking of Robots + + How can we block a really annoying robot from retrieving pages of a specific webarea? A /robots.txt file + containing entries of the "Robot Exclusion Protocol" is typically not enough to get rid of such a robot. + + We use a ruleset which forbids the URLs of the webarea /~quux/foo/arc/ (perhaps a very deep directory + indexed area where the robot traversal would create big server load). We have to make sure that we forbid + access only to the particular robot, i.e. just forbidding the host where the robot runs is not enough. + This would block users from this host, too. We accomplish this by also matching the User-Agent HTTP header + information. + + RewriteCond %{HTTP_USER_AGENT} ^NameOfBadRobot.* + RewriteCond %{REMOTE_ADDR} ^123\.45\.67\.[8-9]$ + RewriteRule ^/~quux/foo/arc/.+ - [F] + + ^NameOfBadRobot.* + ^123\.45\.67\.[8-9]$ + ^/~quux/foo/arc/.+ + 403 + null + + + + + Blocked Inline-Images + + Assume we have under http://www.quux-corp.de/~quux/ some pages with inlined GIF graphics. These graphics are + nice, so others directly incorporate them via hyperlinks to their pages. We don't like this practice because + it adds useless traffic to our server. + + While we cannot 100% protect the images from inclusion, we can at least restrict the cases where the browser + sends a HTTP Referer header. + + RewriteCond %{HTTP_REFERER} !^$ + RewriteCond %{HTTP_REFERER} !^http://www.quux-corp.de/~quux/.*$ [NC] + RewriteRule .*\.gif$ - [F] + + ^$ + ^http://www.quux-corp.de/~quux/.*$ + .*\.gif$ + 403 + null + + + Blocked Inline-Images example 2 + + RewriteCond %{HTTP_REFERER} !^$ + RewriteCond %{HTTP_REFERER} !.*/foo-with-gif\.html$ + RewriteRule ^inlined-in-foo\.gif$ - [F] + + ^$ + .*/foo-with-gif\.html$ + ^inlined-in-foo\.gif$ + 403 + + + + + /bahamas/ + /jamaica/ + + + + ^/query-string-escape/(.*)$ + http://query-string-escape-result.com/?q=${escape:$1}&another=$1 + + + + ^/gzip-me.jsp$ + + + + + diff --git a/container-test2/example-webapp/src/main/webapp/WEB-INF/web.xml b/container-test2/example-webapp/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 00000000..aae9f7ee --- /dev/null +++ b/container-test2/example-webapp/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,65 @@ + + + + + + + test + test context + + + UrlRewriteFilter + org.tuckey.web.filters.urlrewrite.UrlRewriteFilter + + logLevel + debug + + + allowConfSwapViaHttp + true + + + + + UrlRewriteFilter-mod + org.tuckey.web.filters.urlrewrite.UrlRewriteFilter + + logLevel + debug + + + statusPath + /mod/rewrite-status + + + modRewriteConfText + + + + + + + UrlRewriteFilter-mod + /mod/* + + + + UrlRewriteFilter + /* + + + + + + + + + + diff --git a/container-test2/example-webapp/src/main/webapp/echo.jsp b/container-test2/example-webapp/src/main/webapp/echo.jsp new file mode 100644 index 00000000..c78b4773 --- /dev/null +++ b/container-test2/example-webapp/src/main/webapp/echo.jsp @@ -0,0 +1 @@ +echo <%= request.getParameter("echo") %> \ No newline at end of file diff --git a/container-test2/example-webapp/src/main/webapp/gzip-me.jsp b/container-test2/example-webapp/src/main/webapp/gzip-me.jsp new file mode 100644 index 00000000..2496d27b --- /dev/null +++ b/container-test2/example-webapp/src/main/webapp/gzip-me.jsp @@ -0,0 +1 @@ +hello world hello world hello world \ No newline at end of file diff --git a/container-test2/example-webapp/src/main/webapp/mod/index.jsp b/container-test2/example-webapp/src/main/webapp/mod/index.jsp new file mode 100644 index 00000000..7727d0fc --- /dev/null +++ b/container-test2/example-webapp/src/main/webapp/mod/index.jsp @@ -0,0 +1 @@ +this is index.jsp \ No newline at end of file diff --git a/container-test2/example-webapp/src/main/webapp/no-decode-test-D%25%2cD.jsp b/container-test2/example-webapp/src/main/webapp/no-decode-test-D%25%2cD.jsp new file mode 100644 index 00000000..277e1123 --- /dev/null +++ b/container-test2/example-webapp/src/main/webapp/no-decode-test-D%25%2cD.jsp @@ -0,0 +1 @@ +this is no-decode-test target jsp \ No newline at end of file diff --git a/container-test2/example-webapp/src/main/webapp/products.jsp b/container-test2/example-webapp/src/main/webapp/products.jsp new file mode 100644 index 00000000..d457064f --- /dev/null +++ b/container-test2/example-webapp/src/main/webapp/products.jsp @@ -0,0 +1 @@ +product <%= request.getParameter("product_id") %> \ No newline at end of file diff --git a/container-test2/example-webapp/src/main/webapp/settest.jsp b/container-test2/example-webapp/src/main/webapp/settest.jsp new file mode 100644 index 00000000..507e0fcf --- /dev/null +++ b/container-test2/example-webapp/src/main/webapp/settest.jsp @@ -0,0 +1 @@ +testsession: <%= session.getAttribute("testsession") %>, param.settest1: <%= request.getParameter("settest1") %>, method: <%= request.getMethod() %> \ No newline at end of file diff --git a/container-test2/example-webapp/src/main/webapp/test/filterRedirector.jsp b/container-test2/example-webapp/src/main/webapp/test/filterRedirector.jsp new file mode 100644 index 00000000..e69de29b diff --git a/container-test2/example-webapp/src/main/webapp/test/test.jsp b/container-test2/example-webapp/src/main/webapp/test/test.jsp new file mode 100644 index 00000000..e9e935c6 --- /dev/null +++ b/container-test2/example-webapp/src/main/webapp/test/test.jsp @@ -0,0 +1,7 @@ +<%-- Test JSP used by the TestServletTestCase test class to test --%> +<%-- RequestDispatcher call. --%> + + + Hello ! + + \ No newline at end of file From 9e707cc2339ae76ba57dface5398ad2d303bf876 Mon Sep 17 00:00:00 2001 From: Paul Tuckey Date: Thu, 2 Mar 2023 20:26:18 +1300 Subject: [PATCH 02/19] example 2 --- container-test2/pom.xml | 60 +++++++++++++++++++ .../urlrewriteviacontainer/ExampleTest.java | 35 +++++++++++ 2 files changed, 95 insertions(+) create mode 100644 container-test2/pom.xml create mode 100644 container-test2/src/intTest/java/org/tuckey/web/filters/urlrewriteviacontainer/ExampleTest.java diff --git a/container-test2/pom.xml b/container-test2/pom.xml new file mode 100644 index 00000000..fb799124 --- /dev/null +++ b/container-test2/pom.xml @@ -0,0 +1,60 @@ + + + 4.0.0 + org.tuckey + urlrewritefilter-container-test2 + war + + 13 + 13 + + 6.0.0 + UrlRewriteFilter Container Tests2 + http://www.tuckey.org/urlrewrite/ + 2001 + Integration tests for UrlRewriteFilter + + Paul Tuckey + + + + + BSD + http://www.opensource.org/licenses/bsd-license.php + repo + + + + + + Paul Tuckey + + + + + + org.tuckey + urlrewritefilter + 5.0.0-SNAPSHOT + + + org.junit.jupiter + junit-jupiter + 5.8.1 + test + + + org.testcontainers + testcontainers + 1.17.6 + test + + + org.testcontainers + junit-jupiter + 1.17.6 + test + + + + \ No newline at end of file diff --git a/container-test2/src/intTest/java/org/tuckey/web/filters/urlrewriteviacontainer/ExampleTest.java b/container-test2/src/intTest/java/org/tuckey/web/filters/urlrewriteviacontainer/ExampleTest.java new file mode 100644 index 00000000..eabf0eab --- /dev/null +++ b/container-test2/src/intTest/java/org/tuckey/web/filters/urlrewriteviacontainer/ExampleTest.java @@ -0,0 +1,35 @@ +package org.tuckey.web.filters.urlrewriteviacontainer; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.testcontainers.containers.GenericContainer; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; +import org.testcontainers.utility.DockerImageName; + +import static org.hamcrest.MatcherAssert.assertThat; + +@Testcontainers +public class ExampleTest { + + //private RedisBackedCache underTest; + + @Container + public GenericContainer webContainer = new GenericContainer(DockerImageName.parse("jboss/wildfly:9.0.1.Final")) + .withExposedPorts(8086); + + @BeforeEach + public void setUp() { + // Assume that we have Redis running locally? + //underTest = new RedisBackedCache("localhost", 6379); + } + + @Test + public void testSimplePutAndGet() { + System.out.println(webContainer.getContainerId()); + //underTest.put("test", "example"); + + //String retrieved = underTest.get("test"); + //assertThat("123").isEqualTo("example"); + } +} \ No newline at end of file From 91525836ebddfcbfdb633613c64ca9e8e7314dbd Mon Sep 17 00:00:00 2001 From: Paul Tuckey Date: Wed, 5 Apr 2023 10:47:32 +1200 Subject: [PATCH 03/19] upgrade maven plugins, use jakarta --- .../annotation/SampleMatchAction.java | 8 +-- .../MockRewriteMatch.java | 6 +-- .../urlrewriteviacontainer/TestRunObj.java | 10 ++-- .../WebappDecodeNoneIT.java | 2 +- .../WebappDecodeUtf8IT.java | 2 +- .../urlrewriteviacontainer/WebappHttpIT.java | 2 +- .../WebappModStyleHttpIT.java | 2 +- container-test2/example-webapp/pom.xml | 2 +- .../MockRewriteMatch.java | 6 +-- .../urlrewriteviacontainer/TestRunObj.java | 10 ++-- .../urlrewriteviacontainer/ExampleTest.java | 35 ------------- .../{ => test-with-testcontainters}/pom.xml | 19 +++++-- .../urlrewriteviacontainer/ExampleTest.java | 48 ++++++++++++++++++ pom.xml | 49 +++++-------------- .../web/filters/urlrewrite/CatchElem.java | 8 +-- .../web/filters/urlrewrite/ClassRule.java | 12 ++--- .../web/filters/urlrewrite/Condition.java | 6 +-- .../tuckey/web/filters/urlrewrite/Conf.java | 2 +- .../urlrewrite/NormalRewrittenUrl.java | 12 ++--- .../web/filters/urlrewrite/NormalRule.java | 8 +-- .../web/filters/urlrewrite/OutboundRule.java | 8 +-- .../web/filters/urlrewrite/RequestProxy.java | 4 +- .../web/filters/urlrewrite/RewrittenUrl.java | 8 +-- .../filters/urlrewrite/RewrittenUrlClass.java | 8 +-- .../tuckey/web/filters/urlrewrite/Rule.java | 8 +-- .../web/filters/urlrewrite/RuleBase.java | 8 +-- .../web/filters/urlrewrite/RuleChain.java | 12 ++--- .../urlrewrite/RuleExecutionOutput.java | 2 +- .../tuckey/web/filters/urlrewrite/Run.java | 18 +++---- .../web/filters/urlrewrite/RunConfig.java | 6 +-- .../web/filters/urlrewrite/SetAttribute.java | 8 +-- .../tuckey/web/filters/urlrewrite/Status.java | 6 +-- .../filters/urlrewrite/UrlRewriteFilter.java | 18 +++---- .../filters/urlrewrite/UrlRewriteServlet.java | 22 ++++----- .../urlrewrite/UrlRewriteWrappedRequest.java | 4 +- .../urlrewrite/UrlRewriteWrappedResponse.java | 10 ++-- .../web/filters/urlrewrite/UrlRewriter.java | 8 +-- .../urlrewrite/extend/RewriteMatch.java | 6 +-- .../urlrewrite/extend/RewriteRule.java | 6 +-- .../gzip/FilterServletOutputStream.java | 16 +++++- .../gzip/GenericResponseWrapper.java | 8 +-- .../filters/urlrewrite/gzip/GzipFilter.java | 8 +-- .../filters/urlrewrite/gzip/ResponseUtil.java | 4 +- .../urlrewrite/json/JsonRewriteMatch.java | 6 +-- .../sample/SampleMultiUrlRewriteFilter.java | 10 ++-- .../urlrewrite/sample/SampleRewriteMatch.java | 8 +-- .../urlrewrite/sample/SampleRewriteRule.java | 4 +- .../ChainedSubstitutionFilters.java | 2 +- .../substitution/SubstitutionContext.java | 2 +- .../substitution/VariableReplacer.java | 8 +-- .../web/filters/urlrewrite/utils/Log.java | 4 +- .../filters/urlrewrite/utils/TypeUtils.java | 24 ++++----- .../web/filters/urlrewrite/ConditionTest.java | 2 +- .../filters/urlrewrite/PerformanceTest.java | 2 +- .../filters/urlrewrite/RequestProxyTest.java | 2 +- .../filters/urlrewrite/RewrittenUrlTest.java | 4 +- .../web/filters/urlrewrite/RuleTest.java | 2 +- .../web/filters/urlrewrite/RunTest.java | 2 +- .../filters/urlrewrite/SetAttributeTest.java | 2 +- .../filters/urlrewrite/TestRewriteMatch.java | 6 +-- .../web/filters/urlrewrite/TestRuleObj.java | 4 +- .../web/filters/urlrewrite/TestServlet.java | 10 ++-- .../urlrewrite/UrlRewriteFilterTest.java | 2 +- .../filters/urlrewrite/UrlRewriterTest.java | 2 +- .../urlrewrite/VariableReplacerTest.java | 2 +- .../urlrewrite/json/JsonRewriteMatchTest.java | 2 +- .../test/MockRequestParserTest.java | 2 +- .../urlrewrite/test/MockRewriteMatch.java | 6 +-- .../filters/urlrewrite/test/TestRunObj.java | 10 ++-- .../urlrewrite/test/UrlRewriteTestCase.java | 16 +++--- .../utils/FunctionReplacerTest.java | 2 +- .../web/testhelper/MockFilterChain.java | 8 +-- .../web/testhelper/MockFilterConfig.java | 4 +- .../tuckey/web/testhelper/MockRequest.java | 10 ++-- .../web/testhelper/MockRequestDispatcher.java | 8 +-- .../tuckey/web/testhelper/MockResponse.java | 6 +-- .../web/testhelper/MockServletContext.java | 8 +-- .../tuckey/web/testhelper/MockSession.java | 6 +-- 78 files changed, 332 insertions(+), 321 deletions(-) delete mode 100644 container-test2/src/intTest/java/org/tuckey/web/filters/urlrewriteviacontainer/ExampleTest.java rename container-test2/{ => test-with-testcontainters}/pom.xml (75%) create mode 100644 container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/ExampleTest.java diff --git a/annotation/src/test/java/org/tuckey/web/filters/urlrewrite/annotation/SampleMatchAction.java b/annotation/src/test/java/org/tuckey/web/filters/urlrewrite/annotation/SampleMatchAction.java index 74255187..d25f00c9 100644 --- a/annotation/src/test/java/org/tuckey/web/filters/urlrewrite/annotation/SampleMatchAction.java +++ b/annotation/src/test/java/org/tuckey/web/filters/urlrewrite/annotation/SampleMatchAction.java @@ -34,10 +34,10 @@ */ package org.tuckey.web.filters.urlrewrite.annotation; -import javax.servlet.FilterChain; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.FilterChain; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; import java.sql.SQLException; diff --git a/container-test/src/main/java/org/tuckey/web/filters/urlrewriteviacontainer/MockRewriteMatch.java b/container-test/src/main/java/org/tuckey/web/filters/urlrewriteviacontainer/MockRewriteMatch.java index 91ad8d0b..6bf52551 100644 --- a/container-test/src/main/java/org/tuckey/web/filters/urlrewriteviacontainer/MockRewriteMatch.java +++ b/container-test/src/main/java/org/tuckey/web/filters/urlrewriteviacontainer/MockRewriteMatch.java @@ -36,9 +36,9 @@ import org.tuckey.web.filters.urlrewrite.extend.RewriteMatch; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; diff --git a/container-test/src/main/java/org/tuckey/web/filters/urlrewriteviacontainer/TestRunObj.java b/container-test/src/main/java/org/tuckey/web/filters/urlrewriteviacontainer/TestRunObj.java index 0aa2ffb8..9085af9e 100644 --- a/container-test/src/main/java/org/tuckey/web/filters/urlrewriteviacontainer/TestRunObj.java +++ b/container-test/src/main/java/org/tuckey/web/filters/urlrewriteviacontainer/TestRunObj.java @@ -36,11 +36,11 @@ import org.tuckey.web.filters.urlrewrite.extend.RewriteMatch; -import javax.servlet.FilterChain; -import javax.servlet.ServletConfig; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.FilterChain; +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.PrintWriter; diff --git a/container-test/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeNoneIT.java b/container-test/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeNoneIT.java index 08dac55b..1e21e10e 100644 --- a/container-test/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeNoneIT.java +++ b/container-test/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeNoneIT.java @@ -3,7 +3,7 @@ import org.apache.commons.httpclient.methods.GetMethod; -import javax.servlet.ServletException; +import jakarta.servlet.ServletException; import java.io.IOException; import java.net.URLEncoder; diff --git a/container-test/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeUtf8IT.java b/container-test/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeUtf8IT.java index 4ffe999e..acf56ffd 100644 --- a/container-test/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeUtf8IT.java +++ b/container-test/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeUtf8IT.java @@ -3,7 +3,7 @@ import org.apache.commons.httpclient.methods.GetMethod; -import javax.servlet.ServletException; +import jakarta.servlet.ServletException; import java.io.IOException; import java.net.URLEncoder; diff --git a/container-test/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappHttpIT.java b/container-test/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappHttpIT.java index 8906b5f7..668c7092 100644 --- a/container-test/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappHttpIT.java +++ b/container-test/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappHttpIT.java @@ -39,7 +39,7 @@ import org.tuckey.web.filters.urlrewrite.utils.StringUtils; import org.xml.sax.SAXException; -import javax.servlet.ServletException; +import jakarta.servlet.ServletException; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; diff --git a/container-test/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappModStyleHttpIT.java b/container-test/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappModStyleHttpIT.java index 595ae30a..4f6401af 100644 --- a/container-test/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappModStyleHttpIT.java +++ b/container-test/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappModStyleHttpIT.java @@ -37,7 +37,7 @@ import org.apache.commons.httpclient.methods.GetMethod; import org.xml.sax.SAXException; -import javax.servlet.ServletException; +import jakarta.servlet.ServletException; import java.io.IOException; diff --git a/container-test2/example-webapp/pom.xml b/container-test2/example-webapp/pom.xml index 98720da0..54ecf6b4 100644 --- a/container-test2/example-webapp/pom.xml +++ b/container-test2/example-webapp/pom.xml @@ -57,7 +57,7 @@ org.tuckey urlrewritefilter - 5.0.0-SNAPSHOT + 4.0.4 javax.servlet diff --git a/container-test2/example-webapp/src/main/java/org/tuckey/web/filters/urlrewriteviacontainer/MockRewriteMatch.java b/container-test2/example-webapp/src/main/java/org/tuckey/web/filters/urlrewriteviacontainer/MockRewriteMatch.java index 5f821cf3..59ae3b6e 100644 --- a/container-test2/example-webapp/src/main/java/org/tuckey/web/filters/urlrewriteviacontainer/MockRewriteMatch.java +++ b/container-test2/example-webapp/src/main/java/org/tuckey/web/filters/urlrewriteviacontainer/MockRewriteMatch.java @@ -36,9 +36,9 @@ import org.tuckey.web.filters.urlrewrite.extend.RewriteMatch; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; diff --git a/container-test2/example-webapp/src/main/java/org/tuckey/web/filters/urlrewriteviacontainer/TestRunObj.java b/container-test2/example-webapp/src/main/java/org/tuckey/web/filters/urlrewriteviacontainer/TestRunObj.java index 67b99605..ffbecebc 100644 --- a/container-test2/example-webapp/src/main/java/org/tuckey/web/filters/urlrewriteviacontainer/TestRunObj.java +++ b/container-test2/example-webapp/src/main/java/org/tuckey/web/filters/urlrewriteviacontainer/TestRunObj.java @@ -36,11 +36,11 @@ import org.tuckey.web.filters.urlrewrite.extend.RewriteMatch; -import javax.servlet.FilterChain; -import javax.servlet.ServletConfig; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.FilterChain; +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.PrintWriter; diff --git a/container-test2/src/intTest/java/org/tuckey/web/filters/urlrewriteviacontainer/ExampleTest.java b/container-test2/src/intTest/java/org/tuckey/web/filters/urlrewriteviacontainer/ExampleTest.java deleted file mode 100644 index eabf0eab..00000000 --- a/container-test2/src/intTest/java/org/tuckey/web/filters/urlrewriteviacontainer/ExampleTest.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.tuckey.web.filters.urlrewriteviacontainer; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.testcontainers.containers.GenericContainer; -import org.testcontainers.junit.jupiter.Container; -import org.testcontainers.junit.jupiter.Testcontainers; -import org.testcontainers.utility.DockerImageName; - -import static org.hamcrest.MatcherAssert.assertThat; - -@Testcontainers -public class ExampleTest { - - //private RedisBackedCache underTest; - - @Container - public GenericContainer webContainer = new GenericContainer(DockerImageName.parse("jboss/wildfly:9.0.1.Final")) - .withExposedPorts(8086); - - @BeforeEach - public void setUp() { - // Assume that we have Redis running locally? - //underTest = new RedisBackedCache("localhost", 6379); - } - - @Test - public void testSimplePutAndGet() { - System.out.println(webContainer.getContainerId()); - //underTest.put("test", "example"); - - //String retrieved = underTest.get("test"); - //assertThat("123").isEqualTo("example"); - } -} \ No newline at end of file diff --git a/container-test2/pom.xml b/container-test2/test-with-testcontainters/pom.xml similarity index 75% rename from container-test2/pom.xml rename to container-test2/test-with-testcontainters/pom.xml index fb799124..fe1b7dd2 100644 --- a/container-test2/pom.xml +++ b/container-test2/test-with-testcontainters/pom.xml @@ -3,10 +3,10 @@ 4.0.0 org.tuckey urlrewritefilter-container-test2 - war + jar - 13 - 13 + 17 + 17 6.0.0 UrlRewriteFilter Container Tests2 @@ -35,7 +35,7 @@ org.tuckey urlrewritefilter - 5.0.0-SNAPSHOT + 4.0.4 org.junit.jupiter @@ -55,6 +55,17 @@ 1.17.6 test + + org.slf4j + slf4j-api + 1.7.5 + + + org.slf4j + slf4j-simple + 1.7.5 + + \ No newline at end of file diff --git a/container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/ExampleTest.java b/container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/ExampleTest.java new file mode 100644 index 00000000..5e499b72 --- /dev/null +++ b/container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/ExampleTest.java @@ -0,0 +1,48 @@ +package org.tuckey.web.filters.urlrewriteviacontainer; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.testcontainers.containers.GenericContainer; +import org.testcontainers.containers.wait.strategy.Wait; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; +import org.testcontainers.utility.DockerImageName; +import org.testcontainers.utility.MountableFile; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.testcontainers.shaded.org.apache.commons.lang3.BooleanUtils.isTrue; + +@Testcontainers +public class ExampleTest { + + private final MountableFile warFile = MountableFile.forHostPath("/Users/paul/co/urlrewritefilter/container-test2/example-webapp/target/webapp.war"); + + @Container + public GenericContainer container = new GenericContainer(DockerImageName.parse("payara/micro")) + .withExposedPorts(8087) + .withCopyFileToContainer(warFile, "/opt/payara/deployments/webapp.war") + .withCommand("--noCluster --deploy /opt/payara/deployments/webapp.war --contextRoot /") + .waitingFor(Wait.forHttp("/get").forStatusCode(200)); + + @BeforeEach + public void setUp() { + // Assume that we have Redis running locally? + //underTest = new RedisBackedCache("localhost", 6379); + } + + @Test + public void checkContainerIsRunning(){ + assert(isTrue(container.isRunning())); + } + + @Test + public void testSimplePutAndGet() { + //System.out.println(webContainer.getContainerId()); + //underTest.put("test", "example"); + + //String retrieved = underTest.get("test"); + //assertThat("123").isEqualTo("example"); + + + } +} \ No newline at end of file diff --git a/pom.xml b/pom.xml index 0235878a..8bc8e35d 100644 --- a/pom.xml +++ b/pom.xml @@ -67,8 +67,9 @@ + org.apache.maven.plugins maven-compiler-plugin - 2.5.1 + 3.11.0 1.7 1.7 @@ -93,6 +94,7 @@ + org.apache.maven.plugins maven-release-plugin 2.1 @@ -100,6 +102,7 @@ + org.apache.maven.plugins maven-surefire-plugin 2.12 @@ -113,6 +116,7 @@ + org.apache.maven.plugins maven-jar-plugin 2.4 @@ -128,6 +132,7 @@ + org.apache.maven.plugins maven-source-plugin 2.1.2 @@ -153,36 +158,6 @@ - - org.apache.maven.plugins - maven-shade-plugin - 3.2.2 - - - jakarta - package - - shade - - - jakarta - true - false - - - ${project.groupId}:${project.artifactId} - - - - - javax.servlet - jakarta.servlet - - - - - - @@ -190,13 +165,13 @@ junit junit - 4.13.1 + 4.13.2 test - javax.servlet - servlet-api - 2.4 + jakarta.servlet + jakarta.servlet-api + 6.0.0 provided @@ -209,14 +184,14 @@ ant ant - 1.5 + 1.7.0 provided true org.slf4j slf4j-api - 1.5.2 + 2.0.5 true diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/CatchElem.java b/src/main/java/org/tuckey/web/filters/urlrewrite/CatchElem.java index 1f5a5e6d..02be4f21 100644 --- a/src/main/java/org/tuckey/web/filters/urlrewrite/CatchElem.java +++ b/src/main/java/org/tuckey/web/filters/urlrewrite/CatchElem.java @@ -37,10 +37,10 @@ import org.tuckey.web.filters.urlrewrite.utils.Log; import org.tuckey.web.filters.urlrewrite.extend.RewriteMatch; -import javax.servlet.ServletContext; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import java.util.ArrayList; import java.util.List; import java.io.IOException; diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/ClassRule.java b/src/main/java/org/tuckey/web/filters/urlrewrite/ClassRule.java index c189135e..6e295610 100644 --- a/src/main/java/org/tuckey/web/filters/urlrewrite/ClassRule.java +++ b/src/main/java/org/tuckey/web/filters/urlrewrite/ClassRule.java @@ -39,12 +39,12 @@ import org.tuckey.web.filters.urlrewrite.utils.Log; import org.tuckey.web.filters.urlrewrite.utils.StringUtils; -import javax.servlet.ServletContext; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/Condition.java b/src/main/java/org/tuckey/web/filters/urlrewrite/Condition.java index c1c625d3..2c6cf4b8 100644 --- a/src/main/java/org/tuckey/web/filters/urlrewrite/Condition.java +++ b/src/main/java/org/tuckey/web/filters/urlrewrite/Condition.java @@ -43,9 +43,9 @@ import org.tuckey.web.filters.urlrewrite.utils.StringUtils; import org.tuckey.web.filters.urlrewrite.utils.WildcardPattern; -import javax.servlet.http.Cookie; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpSession; +import jakarta.servlet.http.Cookie; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpSession; import java.io.File; import java.util.Calendar; diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/Conf.java b/src/main/java/org/tuckey/web/filters/urlrewrite/Conf.java index f23cfaf4..0b8a4ba2 100644 --- a/src/main/java/org/tuckey/web/filters/urlrewrite/Conf.java +++ b/src/main/java/org/tuckey/web/filters/urlrewrite/Conf.java @@ -46,7 +46,7 @@ import org.w3c.dom.Text; import org.xml.sax.SAXParseException; -import javax.servlet.ServletContext; +import jakarta.servlet.ServletContext; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/NormalRewrittenUrl.java b/src/main/java/org/tuckey/web/filters/urlrewrite/NormalRewrittenUrl.java index 60250eef..e3257019 100644 --- a/src/main/java/org/tuckey/web/filters/urlrewrite/NormalRewrittenUrl.java +++ b/src/main/java/org/tuckey/web/filters/urlrewrite/NormalRewrittenUrl.java @@ -37,12 +37,12 @@ import org.tuckey.web.filters.urlrewrite.extend.RewriteMatch; import org.tuckey.web.filters.urlrewrite.utils.Log; -import javax.servlet.FilterChain; -import javax.servlet.RequestDispatcher; -import javax.servlet.ServletContext; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.FilterChain; +import jakarta.servlet.RequestDispatcher; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/NormalRule.java b/src/main/java/org/tuckey/web/filters/urlrewrite/NormalRule.java index 0252ca4f..9570c831 100644 --- a/src/main/java/org/tuckey/web/filters/urlrewrite/NormalRule.java +++ b/src/main/java/org/tuckey/web/filters/urlrewrite/NormalRule.java @@ -37,10 +37,10 @@ import org.tuckey.web.filters.urlrewrite.utils.Log; import org.tuckey.web.filters.urlrewrite.utils.StringUtils; -import javax.servlet.ServletContext; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; import java.lang.reflect.InvocationTargetException; diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/OutboundRule.java b/src/main/java/org/tuckey/web/filters/urlrewrite/OutboundRule.java index 7354ef46..d2c257ea 100644 --- a/src/main/java/org/tuckey/web/filters/urlrewrite/OutboundRule.java +++ b/src/main/java/org/tuckey/web/filters/urlrewrite/OutboundRule.java @@ -36,10 +36,10 @@ import org.tuckey.web.filters.urlrewrite.utils.Log; -import javax.servlet.ServletContext; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; import java.lang.reflect.InvocationTargetException; diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/RequestProxy.java b/src/main/java/org/tuckey/web/filters/urlrewrite/RequestProxy.java index 1f839119..663c5408 100644 --- a/src/main/java/org/tuckey/web/filters/urlrewrite/RequestProxy.java +++ b/src/main/java/org/tuckey/web/filters/urlrewrite/RequestProxy.java @@ -44,8 +44,8 @@ import org.tuckey.web.filters.urlrewrite.utils.Log; import org.tuckey.web.filters.urlrewrite.utils.StringUtils; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/RewrittenUrl.java b/src/main/java/org/tuckey/web/filters/urlrewrite/RewrittenUrl.java index 590c1129..b0de9b0f 100644 --- a/src/main/java/org/tuckey/web/filters/urlrewrite/RewrittenUrl.java +++ b/src/main/java/org/tuckey/web/filters/urlrewrite/RewrittenUrl.java @@ -34,10 +34,10 @@ */ package org.tuckey.web.filters.urlrewrite; -import javax.servlet.FilterChain; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.FilterChain; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; /** diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/RewrittenUrlClass.java b/src/main/java/org/tuckey/web/filters/urlrewrite/RewrittenUrlClass.java index 440fde83..4a65366f 100644 --- a/src/main/java/org/tuckey/web/filters/urlrewrite/RewrittenUrlClass.java +++ b/src/main/java/org/tuckey/web/filters/urlrewrite/RewrittenUrlClass.java @@ -36,10 +36,10 @@ import org.tuckey.web.filters.urlrewrite.extend.RewriteMatch; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.FilterChain; -import javax.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.servlet.FilterChain; +import jakarta.servlet.ServletException; import java.io.IOException; /** diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/Rule.java b/src/main/java/org/tuckey/web/filters/urlrewrite/Rule.java index 43138aa7..b52709f5 100644 --- a/src/main/java/org/tuckey/web/filters/urlrewrite/Rule.java +++ b/src/main/java/org/tuckey/web/filters/urlrewrite/Rule.java @@ -34,10 +34,10 @@ */ package org.tuckey.web.filters.urlrewrite; -import javax.servlet.ServletContext; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.List; import java.lang.reflect.InvocationTargetException; diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/RuleBase.java b/src/main/java/org/tuckey/web/filters/urlrewrite/RuleBase.java index 816c7a06..7bfb42d1 100644 --- a/src/main/java/org/tuckey/web/filters/urlrewrite/RuleBase.java +++ b/src/main/java/org/tuckey/web/filters/urlrewrite/RuleBase.java @@ -49,10 +49,10 @@ import org.tuckey.web.filters.urlrewrite.utils.StringUtils; import org.tuckey.web.filters.urlrewrite.utils.WildcardPattern; -import javax.servlet.ServletContext; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/RuleChain.java b/src/main/java/org/tuckey/web/filters/urlrewrite/RuleChain.java index 1044b366..ee8be776 100644 --- a/src/main/java/org/tuckey/web/filters/urlrewrite/RuleChain.java +++ b/src/main/java/org/tuckey/web/filters/urlrewrite/RuleChain.java @@ -36,12 +36,12 @@ import org.tuckey.web.filters.urlrewrite.utils.Log; -import javax.servlet.FilterChain; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.FilterChain; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.util.List; diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/RuleExecutionOutput.java b/src/main/java/org/tuckey/web/filters/urlrewrite/RuleExecutionOutput.java index 11e2061e..ee2e9ae7 100644 --- a/src/main/java/org/tuckey/web/filters/urlrewrite/RuleExecutionOutput.java +++ b/src/main/java/org/tuckey/web/filters/urlrewrite/RuleExecutionOutput.java @@ -34,7 +34,7 @@ */ package org.tuckey.web.filters.urlrewrite; -import javax.servlet.ServletContext; +import jakarta.servlet.ServletContext; import org.tuckey.web.filters.urlrewrite.extend.RewriteMatch; import org.tuckey.web.filters.urlrewrite.utils.Log; diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/Run.java b/src/main/java/org/tuckey/web/filters/urlrewrite/Run.java index eba8af51..b8b020db 100644 --- a/src/main/java/org/tuckey/web/filters/urlrewrite/Run.java +++ b/src/main/java/org/tuckey/web/filters/urlrewrite/Run.java @@ -41,15 +41,15 @@ import org.tuckey.web.filters.urlrewrite.utils.TypeUtils; import org.tuckey.web.filters.urlrewrite.json.JsonRewriteMatch; -import javax.servlet.FilterChain; -import javax.servlet.FilterConfig; -import javax.servlet.ServletConfig; -import javax.servlet.ServletContext; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.FilterChain; +import jakarta.servlet.FilterConfig; +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/RunConfig.java b/src/main/java/org/tuckey/web/filters/urlrewrite/RunConfig.java index 30c4f7fb..ccb6a93f 100644 --- a/src/main/java/org/tuckey/web/filters/urlrewrite/RunConfig.java +++ b/src/main/java/org/tuckey/web/filters/urlrewrite/RunConfig.java @@ -34,9 +34,9 @@ */ package org.tuckey.web.filters.urlrewrite; -import javax.servlet.ServletConfig; -import javax.servlet.ServletContext; -import javax.servlet.FilterConfig; +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletContext; +import jakarta.servlet.FilterConfig; import java.util.Enumeration; import java.util.Hashtable; diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/SetAttribute.java b/src/main/java/org/tuckey/web/filters/urlrewrite/SetAttribute.java index 212d28db..ba447c73 100644 --- a/src/main/java/org/tuckey/web/filters/urlrewrite/SetAttribute.java +++ b/src/main/java/org/tuckey/web/filters/urlrewrite/SetAttribute.java @@ -45,10 +45,10 @@ import org.tuckey.web.filters.urlrewrite.utils.StringMatchingMatcher; import org.tuckey.web.filters.urlrewrite.utils.StringUtils; -import javax.servlet.http.Cookie; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpSession; +import jakarta.servlet.http.Cookie; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpSession; import java.util.Locale; import java.util.regex.Matcher; diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/Status.java b/src/main/java/org/tuckey/web/filters/urlrewrite/Status.java index dcac0e10..522649cf 100644 --- a/src/main/java/org/tuckey/web/filters/urlrewrite/Status.java +++ b/src/main/java/org/tuckey/web/filters/urlrewrite/Status.java @@ -37,9 +37,9 @@ import org.tuckey.web.filters.urlrewrite.utils.Log; import org.tuckey.web.filters.urlrewrite.utils.StringUtils; -import javax.servlet.http.Cookie; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpSession; +import jakarta.servlet.http.Cookie; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpSession; import java.io.IOException; import java.io.InputStream; import java.text.SimpleDateFormat; diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/UrlRewriteFilter.java b/src/main/java/org/tuckey/web/filters/urlrewrite/UrlRewriteFilter.java index f1291672..f78afc71 100644 --- a/src/main/java/org/tuckey/web/filters/urlrewrite/UrlRewriteFilter.java +++ b/src/main/java/org/tuckey/web/filters/urlrewrite/UrlRewriteFilter.java @@ -40,15 +40,15 @@ import org.tuckey.web.filters.urlrewrite.utils.ServerNameMatcher; import org.tuckey.web.filters.urlrewrite.utils.StringUtils; -import javax.servlet.Filter; -import javax.servlet.FilterChain; -import javax.servlet.FilterConfig; -import javax.servlet.ServletContext; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.Filter; +import jakarta.servlet.FilterChain; +import jakarta.servlet.FilterConfig; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/UrlRewriteServlet.java b/src/main/java/org/tuckey/web/filters/urlrewrite/UrlRewriteServlet.java index 1afea98c..8241120f 100644 --- a/src/main/java/org/tuckey/web/filters/urlrewrite/UrlRewriteServlet.java +++ b/src/main/java/org/tuckey/web/filters/urlrewrite/UrlRewriteServlet.java @@ -34,17 +34,17 @@ */ package org.tuckey.web.filters.urlrewrite; -import javax.servlet.FilterChain; -import javax.servlet.FilterConfig; -import javax.servlet.ServletConfig; -import javax.servlet.ServletContext; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; -import javax.servlet.UnavailableException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.FilterChain; +import jakarta.servlet.FilterConfig; +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; +import jakarta.servlet.UnavailableException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.Enumeration; diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/UrlRewriteWrappedRequest.java b/src/main/java/org/tuckey/web/filters/urlrewrite/UrlRewriteWrappedRequest.java index bebc6d0e..02a89c66 100644 --- a/src/main/java/org/tuckey/web/filters/urlrewrite/UrlRewriteWrappedRequest.java +++ b/src/main/java/org/tuckey/web/filters/urlrewrite/UrlRewriteWrappedRequest.java @@ -34,8 +34,8 @@ */ package org.tuckey.web.filters.urlrewrite; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletRequestWrapper; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletRequestWrapper; import java.util.Collections; import java.util.Enumeration; import java.util.HashMap; diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/UrlRewriteWrappedResponse.java b/src/main/java/org/tuckey/web/filters/urlrewrite/UrlRewriteWrappedResponse.java index 2e879310..4717d9e5 100644 --- a/src/main/java/org/tuckey/web/filters/urlrewrite/UrlRewriteWrappedResponse.java +++ b/src/main/java/org/tuckey/web/filters/urlrewrite/UrlRewriteWrappedResponse.java @@ -34,9 +34,9 @@ */ package org.tuckey.web.filters.urlrewrite; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpServletResponseWrapper; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpServletResponseWrapper; import java.util.HashMap; /** @@ -91,7 +91,7 @@ public String encodeUrl(String s) { return super.encodeURL(s); } if (rou.isEncode()) { - rou.setTarget(super.encodeUrl(rou.getTarget())); + rou.setTarget(super.encodeURL(rou.getTarget())); } return processPostEncodeURL(rou.getTarget()).getTarget(); } @@ -102,7 +102,7 @@ public String encodeRedirectUrl(String s) { return super.encodeURL(s); } if (rou.isEncode()) { - rou.setTarget(super.encodeRedirectUrl(rou.getTarget())); + rou.setTarget(super.encodeRedirectURL(rou.getTarget())); } return processPostEncodeURL(rou.getTarget()).getTarget(); } diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/UrlRewriter.java b/src/main/java/org/tuckey/web/filters/urlrewrite/UrlRewriter.java index d707b832..a421263c 100644 --- a/src/main/java/org/tuckey/web/filters/urlrewrite/UrlRewriter.java +++ b/src/main/java/org/tuckey/web/filters/urlrewrite/UrlRewriter.java @@ -38,10 +38,10 @@ import org.tuckey.web.filters.urlrewrite.utils.StringUtils; import org.tuckey.web.filters.urlrewrite.utils.URLDecoder; -import javax.servlet.FilterChain; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.FilterChain; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.net.URISyntaxException; diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/extend/RewriteMatch.java b/src/main/java/org/tuckey/web/filters/urlrewrite/extend/RewriteMatch.java index a38b4213..94946a1f 100644 --- a/src/main/java/org/tuckey/web/filters/urlrewrite/extend/RewriteMatch.java +++ b/src/main/java/org/tuckey/web/filters/urlrewrite/extend/RewriteMatch.java @@ -34,9 +34,9 @@ */ package org.tuckey.web.filters.urlrewrite.extend; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.servlet.ServletException; import java.io.IOException; /** diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/extend/RewriteRule.java b/src/main/java/org/tuckey/web/filters/urlrewrite/extend/RewriteRule.java index 56c70ea3..b4a0a02a 100644 --- a/src/main/java/org/tuckey/web/filters/urlrewrite/extend/RewriteRule.java +++ b/src/main/java/org/tuckey/web/filters/urlrewrite/extend/RewriteRule.java @@ -34,9 +34,9 @@ */ package org.tuckey.web.filters.urlrewrite.extend; -import javax.servlet.ServletContext; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.ServletContext; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; /** * A RewriteRule is basically the class that will figure out the answer to "Can we service this http request?". If we diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/gzip/FilterServletOutputStream.java b/src/main/java/org/tuckey/web/filters/urlrewrite/gzip/FilterServletOutputStream.java index 4a9219a5..a7bcfa75 100644 --- a/src/main/java/org/tuckey/web/filters/urlrewrite/gzip/FilterServletOutputStream.java +++ b/src/main/java/org/tuckey/web/filters/urlrewrite/gzip/FilterServletOutputStream.java @@ -20,12 +20,14 @@ * limitations under the License. */ -import javax.servlet.ServletOutputStream; +import jakarta.servlet.ServletOutputStream; +import jakarta.servlet.WriteListener; + import java.io.IOException; import java.io.OutputStream; /** - * A custom {@link javax.servlet.ServletOutputStream} for use by our filters + * A custom {@link jakarta.servlet.ServletOutputStream} for use by our filters * * @version $Id: FilterServletOutputStream.java 744 2008-08-16 20:10:49Z gregluck $ * @author Greg Luck @@ -61,5 +63,15 @@ public void write(final byte[] b) throws IOException { public void write(final byte[] b, final int off, final int len) throws IOException { stream.write(b, off, len); } + + @Override + public boolean isReady() { + return true; + } + + @Override + public void setWriteListener(WriteListener writeListener) { + // + } } diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/gzip/GenericResponseWrapper.java b/src/main/java/org/tuckey/web/filters/urlrewrite/gzip/GenericResponseWrapper.java index e6c82303..9cb11ccc 100644 --- a/src/main/java/org/tuckey/web/filters/urlrewrite/gzip/GenericResponseWrapper.java +++ b/src/main/java/org/tuckey/web/filters/urlrewrite/gzip/GenericResponseWrapper.java @@ -20,7 +20,7 @@ * limitations under the License. */ -import javax.servlet.http.HttpServletResponseWrapper; +import jakarta.servlet.http.HttpServletResponseWrapper; import java.io.IOException; import java.io.OutputStream; @@ -33,9 +33,9 @@ import java.util.Map; import java.util.TreeMap; -import javax.servlet.ServletOutputStream; -import javax.servlet.http.Cookie; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.ServletOutputStream; +import jakarta.servlet.http.Cookie; +import jakarta.servlet.http.HttpServletResponse; import org.tuckey.web.filters.urlrewrite.utils.Log; diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/gzip/GzipFilter.java b/src/main/java/org/tuckey/web/filters/urlrewrite/gzip/GzipFilter.java index bf128b27..3ead9fc0 100644 --- a/src/main/java/org/tuckey/web/filters/urlrewrite/gzip/GzipFilter.java +++ b/src/main/java/org/tuckey/web/filters/urlrewrite/gzip/GzipFilter.java @@ -24,9 +24,9 @@ import java.util.Enumeration; import java.util.zip.GZIPOutputStream; -import javax.servlet.*; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.*; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import org.tuckey.web.filters.urlrewrite.utils.Log; @@ -41,7 +41,7 @@ * @author Adam Murdoch * @version $Id: GzipFilter.java 744 2008-08-16 20:10:49Z gregluck $ */ -public class GzipFilter implements javax.servlet.Filter { +public class GzipFilter implements jakarta.servlet.Filter { private static final Log LOG = Log.getLog(GzipFilter.class); diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/gzip/ResponseUtil.java b/src/main/java/org/tuckey/web/filters/urlrewrite/gzip/ResponseUtil.java index 6f166046..a128e241 100644 --- a/src/main/java/org/tuckey/web/filters/urlrewrite/gzip/ResponseUtil.java +++ b/src/main/java/org/tuckey/web/filters/urlrewrite/gzip/ResponseUtil.java @@ -22,8 +22,8 @@ import org.tuckey.web.filters.urlrewrite.utils.Log; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; /** * A collection of response processing utilities, which are shared between 2 or more filters diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/json/JsonRewriteMatch.java b/src/main/java/org/tuckey/web/filters/urlrewrite/json/JsonRewriteMatch.java index 15ad905a..7f89da5d 100644 --- a/src/main/java/org/tuckey/web/filters/urlrewrite/json/JsonRewriteMatch.java +++ b/src/main/java/org/tuckey/web/filters/urlrewrite/json/JsonRewriteMatch.java @@ -36,9 +36,9 @@ import org.tuckey.web.filters.urlrewrite.extend.RewriteMatch; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; public class JsonRewriteMatch extends RewriteMatch { diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/sample/SampleMultiUrlRewriteFilter.java b/src/main/java/org/tuckey/web/filters/urlrewrite/sample/SampleMultiUrlRewriteFilter.java index 52cb364b..c3b18bd7 100644 --- a/src/main/java/org/tuckey/web/filters/urlrewrite/sample/SampleMultiUrlRewriteFilter.java +++ b/src/main/java/org/tuckey/web/filters/urlrewrite/sample/SampleMultiUrlRewriteFilter.java @@ -4,11 +4,11 @@ import org.tuckey.web.filters.urlrewrite.UrlRewriteFilter; import org.tuckey.web.filters.urlrewrite.UrlRewriter; -import javax.servlet.FilterChain; -import javax.servlet.FilterConfig; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; +import jakarta.servlet.FilterChain; +import jakarta.servlet.FilterConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; import java.io.FileInputStream; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/sample/SampleRewriteMatch.java b/src/main/java/org/tuckey/web/filters/urlrewrite/sample/SampleRewriteMatch.java index 54ed1a0f..36a35ce1 100644 --- a/src/main/java/org/tuckey/web/filters/urlrewrite/sample/SampleRewriteMatch.java +++ b/src/main/java/org/tuckey/web/filters/urlrewrite/sample/SampleRewriteMatch.java @@ -36,10 +36,10 @@ import org.tuckey.web.filters.urlrewrite.extend.RewriteMatch; -import javax.servlet.RequestDispatcher; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.RequestDispatcher; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/sample/SampleRewriteRule.java b/src/main/java/org/tuckey/web/filters/urlrewrite/sample/SampleRewriteRule.java index 09c289f4..49c6fad2 100644 --- a/src/main/java/org/tuckey/web/filters/urlrewrite/sample/SampleRewriteRule.java +++ b/src/main/java/org/tuckey/web/filters/urlrewrite/sample/SampleRewriteRule.java @@ -37,8 +37,8 @@ import org.tuckey.web.filters.urlrewrite.extend.RewriteRule; import org.tuckey.web.filters.urlrewrite.extend.RewriteMatch; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; /** * A sample of how you might write a custom rule. diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/substitution/ChainedSubstitutionFilters.java b/src/main/java/org/tuckey/web/filters/urlrewrite/substitution/ChainedSubstitutionFilters.java index de0e095a..a48085a3 100644 --- a/src/main/java/org/tuckey/web/filters/urlrewrite/substitution/ChainedSubstitutionFilters.java +++ b/src/main/java/org/tuckey/web/filters/urlrewrite/substitution/ChainedSubstitutionFilters.java @@ -1,6 +1,6 @@ package org.tuckey.web.filters.urlrewrite.substitution; -import javax.servlet.ServletContext; +import jakarta.servlet.ServletContext; import java.util.ArrayList; import java.util.LinkedList; import java.util.List; diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/substitution/SubstitutionContext.java b/src/main/java/org/tuckey/web/filters/urlrewrite/substitution/SubstitutionContext.java index b864d933..7d53e9d4 100644 --- a/src/main/java/org/tuckey/web/filters/urlrewrite/substitution/SubstitutionContext.java +++ b/src/main/java/org/tuckey/web/filters/urlrewrite/substitution/SubstitutionContext.java @@ -3,7 +3,7 @@ import org.tuckey.web.filters.urlrewrite.ConditionMatch; import org.tuckey.web.filters.urlrewrite.utils.StringMatchingMatcher; -import javax.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletRequest; public class SubstitutionContext { diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/substitution/VariableReplacer.java b/src/main/java/org/tuckey/web/filters/urlrewrite/substitution/VariableReplacer.java index a3a9a138..5d4bad3d 100644 --- a/src/main/java/org/tuckey/web/filters/urlrewrite/substitution/VariableReplacer.java +++ b/src/main/java/org/tuckey/web/filters/urlrewrite/substitution/VariableReplacer.java @@ -38,10 +38,10 @@ import org.tuckey.web.filters.urlrewrite.utils.Log; import org.tuckey.web.filters.urlrewrite.utils.StringUtils; -import javax.servlet.ServletContext; -import javax.servlet.http.Cookie; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpSession; +import jakarta.servlet.ServletContext; +import jakarta.servlet.http.Cookie; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpSession; import java.util.Calendar; import java.util.Collections; import java.util.regex.Matcher; diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/utils/Log.java b/src/main/java/org/tuckey/web/filters/urlrewrite/utils/Log.java index 0e291a52..2502e12d 100644 --- a/src/main/java/org/tuckey/web/filters/urlrewrite/utils/Log.java +++ b/src/main/java/org/tuckey/web/filters/urlrewrite/utils/Log.java @@ -34,8 +34,8 @@ */ package org.tuckey.web.filters.urlrewrite.utils; -import javax.servlet.FilterConfig; -import javax.servlet.ServletContext; +import jakarta.servlet.FilterConfig; +import jakarta.servlet.ServletContext; /** diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/utils/TypeUtils.java b/src/main/java/org/tuckey/web/filters/urlrewrite/utils/TypeUtils.java index c01e88a0..67f2d3f4 100644 --- a/src/main/java/org/tuckey/web/filters/urlrewrite/utils/TypeUtils.java +++ b/src/main/java/org/tuckey/web/filters/urlrewrite/utils/TypeUtils.java @@ -1,9 +1,9 @@ package org.tuckey.web.filters.urlrewrite.utils; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; public class TypeUtils { @@ -52,19 +52,19 @@ public static Object getConvertedParam(Class runMethodParam, Object matchObj) { if (matchObj == null) { if (runMethodParam.isPrimitive()) { if (runMethodParam.equals(boolean.class)) param = Boolean.FALSE; - else if (runMethodParam.equals(char.class)) param = new Character('\u0000'); - else if (runMethodParam.equals(byte.class)) param = new Byte((byte) 0); - else if (runMethodParam.equals(short.class)) param = new Short((short) 0); - else if (runMethodParam.equals(int.class)) param = new Integer(0); - else if (runMethodParam.equals(long.class)) param = new Long(0L); - else if (runMethodParam.equals(float.class)) param = new Float(0f); - else if (runMethodParam.equals(double.class)) param = new Double(0d); + else if (runMethodParam.equals(char.class)) param = Character.valueOf('\u0000'); + else if (runMethodParam.equals(byte.class)) param = Byte.valueOf((byte) 0); + else if (runMethodParam.equals(short.class)) param = Short.valueOf((short) 0); + else if (runMethodParam.equals(int.class)) param = Integer.valueOf(0); + else if (runMethodParam.equals(long.class)) param = Long.valueOf(0L); + else if (runMethodParam.equals(float.class)) param = Float.valueOf(0f); + else if (runMethodParam.equals(double.class)) param = Double.valueOf(0d); } } else { if (runMethodParam.equals(Boolean.class) || runMethodParam.equals(boolean.class)) param = Boolean.valueOf((String) matchObj); else if (runMethodParam.equals(Character.class) || runMethodParam.equals(char.class)) - param = new Character(((String) matchObj).charAt(0)); + param = Character.valueOf(((String) matchObj).charAt(0)); else if (runMethodParam.equals(Byte.class) || runMethodParam.equals(byte.class)) param = Byte.valueOf((String) matchObj); else if (runMethodParam.equals(Short.class) || runMethodParam.equals(short.class)) diff --git a/src/test/java/org/tuckey/web/filters/urlrewrite/ConditionTest.java b/src/test/java/org/tuckey/web/filters/urlrewrite/ConditionTest.java index 78829fac..ee414d03 100644 --- a/src/test/java/org/tuckey/web/filters/urlrewrite/ConditionTest.java +++ b/src/test/java/org/tuckey/web/filters/urlrewrite/ConditionTest.java @@ -38,7 +38,7 @@ import org.tuckey.web.testhelper.MockRequest; import org.tuckey.web.filters.urlrewrite.utils.Log; -import javax.servlet.http.Cookie; +import jakarta.servlet.http.Cookie; import java.io.UnsupportedEncodingException; import java.util.Calendar; diff --git a/src/test/java/org/tuckey/web/filters/urlrewrite/PerformanceTest.java b/src/test/java/org/tuckey/web/filters/urlrewrite/PerformanceTest.java index a23e8ef3..8ac84f3a 100644 --- a/src/test/java/org/tuckey/web/filters/urlrewrite/PerformanceTest.java +++ b/src/test/java/org/tuckey/web/filters/urlrewrite/PerformanceTest.java @@ -5,7 +5,7 @@ import org.tuckey.web.filters.urlrewrite.utils.Log; import org.tuckey.web.testhelper.*; -import javax.servlet.ServletException; +import jakarta.servlet.ServletException; import java.io.IOException; import java.lang.reflect.InvocationTargetException; diff --git a/src/test/java/org/tuckey/web/filters/urlrewrite/RequestProxyTest.java b/src/test/java/org/tuckey/web/filters/urlrewrite/RequestProxyTest.java index 44e28d61..951568c2 100644 --- a/src/test/java/org/tuckey/web/filters/urlrewrite/RequestProxyTest.java +++ b/src/test/java/org/tuckey/web/filters/urlrewrite/RequestProxyTest.java @@ -2,7 +2,7 @@ import junit.framework.TestCase; -import javax.servlet.ServletException; +import jakarta.servlet.ServletException; import java.io.IOException; /** diff --git a/src/test/java/org/tuckey/web/filters/urlrewrite/RewrittenUrlTest.java b/src/test/java/org/tuckey/web/filters/urlrewrite/RewrittenUrlTest.java index bf677264..69d62316 100644 --- a/src/test/java/org/tuckey/web/filters/urlrewrite/RewrittenUrlTest.java +++ b/src/test/java/org/tuckey/web/filters/urlrewrite/RewrittenUrlTest.java @@ -41,8 +41,8 @@ import org.tuckey.web.testhelper.MockRequestDispatcher; import org.tuckey.web.testhelper.MockResponse; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; /** diff --git a/src/test/java/org/tuckey/web/filters/urlrewrite/RuleTest.java b/src/test/java/org/tuckey/web/filters/urlrewrite/RuleTest.java index fd079515..a4a01917 100644 --- a/src/test/java/org/tuckey/web/filters/urlrewrite/RuleTest.java +++ b/src/test/java/org/tuckey/web/filters/urlrewrite/RuleTest.java @@ -40,7 +40,7 @@ import org.tuckey.web.testhelper.MockResponse; import org.tuckey.web.testhelper.MockServletContext; -import javax.servlet.ServletException; +import jakarta.servlet.ServletException; import java.io.IOException; import java.lang.reflect.InvocationTargetException; diff --git a/src/test/java/org/tuckey/web/filters/urlrewrite/RunTest.java b/src/test/java/org/tuckey/web/filters/urlrewrite/RunTest.java index b7153795..c233a932 100644 --- a/src/test/java/org/tuckey/web/filters/urlrewrite/RunTest.java +++ b/src/test/java/org/tuckey/web/filters/urlrewrite/RunTest.java @@ -42,7 +42,7 @@ import org.tuckey.web.filters.urlrewrite.utils.Log; import org.tuckey.web.filters.urlrewrite.test.TestRunObj; -import javax.servlet.ServletException; +import jakarta.servlet.ServletException; import java.io.IOException; import java.lang.reflect.InvocationTargetException; diff --git a/src/test/java/org/tuckey/web/filters/urlrewrite/SetAttributeTest.java b/src/test/java/org/tuckey/web/filters/urlrewrite/SetAttributeTest.java index 72081168..43214e1f 100644 --- a/src/test/java/org/tuckey/web/filters/urlrewrite/SetAttributeTest.java +++ b/src/test/java/org/tuckey/web/filters/urlrewrite/SetAttributeTest.java @@ -41,7 +41,7 @@ import org.tuckey.web.testhelper.MockRequest; import org.tuckey.web.testhelper.MockResponse; -import javax.servlet.http.Cookie; +import jakarta.servlet.http.Cookie; import java.util.regex.Pattern; /** diff --git a/src/test/java/org/tuckey/web/filters/urlrewrite/TestRewriteMatch.java b/src/test/java/org/tuckey/web/filters/urlrewrite/TestRewriteMatch.java index 7cee9fce..f42e1735 100644 --- a/src/test/java/org/tuckey/web/filters/urlrewrite/TestRewriteMatch.java +++ b/src/test/java/org/tuckey/web/filters/urlrewrite/TestRewriteMatch.java @@ -36,9 +36,9 @@ import org.tuckey.web.filters.urlrewrite.extend.RewriteMatch; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.servlet.ServletException; import java.io.IOException; public class TestRewriteMatch extends RewriteMatch { diff --git a/src/test/java/org/tuckey/web/filters/urlrewrite/TestRuleObj.java b/src/test/java/org/tuckey/web/filters/urlrewrite/TestRuleObj.java index 12d86065..712d8911 100644 --- a/src/test/java/org/tuckey/web/filters/urlrewrite/TestRuleObj.java +++ b/src/test/java/org/tuckey/web/filters/urlrewrite/TestRuleObj.java @@ -37,8 +37,8 @@ import org.tuckey.web.filters.urlrewrite.extend.RewriteRule; import org.tuckey.web.filters.urlrewrite.extend.RewriteMatch; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; public class TestRuleObj extends RewriteRule { public RewriteMatch matches(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) { diff --git a/src/test/java/org/tuckey/web/filters/urlrewrite/TestServlet.java b/src/test/java/org/tuckey/web/filters/urlrewrite/TestServlet.java index 84bd1367..610f44b5 100644 --- a/src/test/java/org/tuckey/web/filters/urlrewrite/TestServlet.java +++ b/src/test/java/org/tuckey/web/filters/urlrewrite/TestServlet.java @@ -34,11 +34,11 @@ */ package org.tuckey.web.filters.urlrewrite; -import javax.servlet.ServletConfig; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.PrintWriter; diff --git a/src/test/java/org/tuckey/web/filters/urlrewrite/UrlRewriteFilterTest.java b/src/test/java/org/tuckey/web/filters/urlrewrite/UrlRewriteFilterTest.java index 27cdca07..087c622a 100644 --- a/src/test/java/org/tuckey/web/filters/urlrewrite/UrlRewriteFilterTest.java +++ b/src/test/java/org/tuckey/web/filters/urlrewrite/UrlRewriteFilterTest.java @@ -39,7 +39,7 @@ import org.tuckey.web.testhelper.MockServletContext; import org.tuckey.web.filters.urlrewrite.utils.Log; -import javax.servlet.ServletException; +import jakarta.servlet.ServletException; /** * @author Paul Tuckey diff --git a/src/test/java/org/tuckey/web/filters/urlrewrite/UrlRewriterTest.java b/src/test/java/org/tuckey/web/filters/urlrewrite/UrlRewriterTest.java index c06c53d8..3e92d344 100644 --- a/src/test/java/org/tuckey/web/filters/urlrewrite/UrlRewriterTest.java +++ b/src/test/java/org/tuckey/web/filters/urlrewrite/UrlRewriterTest.java @@ -43,7 +43,7 @@ import org.tuckey.web.testhelper.MockResponse; import org.tuckey.web.testhelper.MockServletContext; -import javax.servlet.ServletException; +import jakarta.servlet.ServletException; import java.io.IOException; import java.lang.reflect.InvocationTargetException; diff --git a/src/test/java/org/tuckey/web/filters/urlrewrite/VariableReplacerTest.java b/src/test/java/org/tuckey/web/filters/urlrewrite/VariableReplacerTest.java index 5b025fd7..26d38668 100644 --- a/src/test/java/org/tuckey/web/filters/urlrewrite/VariableReplacerTest.java +++ b/src/test/java/org/tuckey/web/filters/urlrewrite/VariableReplacerTest.java @@ -4,7 +4,7 @@ import org.tuckey.web.filters.urlrewrite.substitution.VariableReplacer; import org.tuckey.web.testhelper.MockRequest; -import javax.servlet.ServletContext; +import jakarta.servlet.ServletContext; /** * @author Tim Morrow diff --git a/src/test/java/org/tuckey/web/filters/urlrewrite/json/JsonRewriteMatchTest.java b/src/test/java/org/tuckey/web/filters/urlrewrite/json/JsonRewriteMatchTest.java index 53d72be2..2b319d52 100644 --- a/src/test/java/org/tuckey/web/filters/urlrewrite/json/JsonRewriteMatchTest.java +++ b/src/test/java/org/tuckey/web/filters/urlrewrite/json/JsonRewriteMatchTest.java @@ -39,7 +39,7 @@ import org.tuckey.web.testhelper.MockRequest; import org.tuckey.web.testhelper.MockResponse; -import javax.servlet.ServletException; +import jakarta.servlet.ServletException; import java.io.IOException; diff --git a/src/test/java/org/tuckey/web/filters/urlrewrite/test/MockRequestParserTest.java b/src/test/java/org/tuckey/web/filters/urlrewrite/test/MockRequestParserTest.java index e8d9d1f1..64188838 100644 --- a/src/test/java/org/tuckey/web/filters/urlrewrite/test/MockRequestParserTest.java +++ b/src/test/java/org/tuckey/web/filters/urlrewrite/test/MockRequestParserTest.java @@ -3,7 +3,7 @@ import junit.framework.TestCase; import org.tuckey.web.filters.urlrewrite.utils.Log; -import javax.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletRequest; public class MockRequestParserTest extends TestCase { diff --git a/src/test/java/org/tuckey/web/filters/urlrewrite/test/MockRewriteMatch.java b/src/test/java/org/tuckey/web/filters/urlrewrite/test/MockRewriteMatch.java index f4f329c2..c72babbe 100644 --- a/src/test/java/org/tuckey/web/filters/urlrewrite/test/MockRewriteMatch.java +++ b/src/test/java/org/tuckey/web/filters/urlrewrite/test/MockRewriteMatch.java @@ -36,9 +36,9 @@ import org.tuckey.web.filters.urlrewrite.extend.RewriteMatch; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; diff --git a/src/test/java/org/tuckey/web/filters/urlrewrite/test/TestRunObj.java b/src/test/java/org/tuckey/web/filters/urlrewrite/test/TestRunObj.java index 576e8f6d..d3879a71 100644 --- a/src/test/java/org/tuckey/web/filters/urlrewrite/test/TestRunObj.java +++ b/src/test/java/org/tuckey/web/filters/urlrewrite/test/TestRunObj.java @@ -36,11 +36,11 @@ import org.tuckey.web.filters.urlrewrite.extend.RewriteMatch; -import javax.servlet.FilterChain; -import javax.servlet.ServletConfig; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.FilterChain; +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.PrintWriter; diff --git a/src/test/java/org/tuckey/web/filters/urlrewrite/test/UrlRewriteTestCase.java b/src/test/java/org/tuckey/web/filters/urlrewrite/test/UrlRewriteTestCase.java index e4bb4ecc..69ce6e56 100644 --- a/src/test/java/org/tuckey/web/filters/urlrewrite/test/UrlRewriteTestCase.java +++ b/src/test/java/org/tuckey/web/filters/urlrewrite/test/UrlRewriteTestCase.java @@ -41,14 +41,14 @@ import org.tuckey.web.filters.urlrewrite.UrlRewriter; import org.tuckey.web.filters.urlrewrite.utils.Log; -import javax.servlet.RequestDispatcher; -import javax.servlet.ServletException; -import javax.servlet.ServletInputStream; -import javax.servlet.ServletOutputStream; -import javax.servlet.http.Cookie; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpSession; +import jakarta.servlet.RequestDispatcher; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletInputStream; +import jakarta.servlet.ServletOutputStream; +import jakarta.servlet.http.Cookie; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpSession; import java.io.BufferedReader; import java.io.IOException; import java.io.PrintWriter; diff --git a/src/test/java/org/tuckey/web/filters/urlrewrite/utils/FunctionReplacerTest.java b/src/test/java/org/tuckey/web/filters/urlrewrite/utils/FunctionReplacerTest.java index eeab0c76..93a8cebc 100644 --- a/src/test/java/org/tuckey/web/filters/urlrewrite/utils/FunctionReplacerTest.java +++ b/src/test/java/org/tuckey/web/filters/urlrewrite/utils/FunctionReplacerTest.java @@ -3,7 +3,7 @@ import junit.framework.TestCase; import org.tuckey.web.filters.urlrewrite.substitution.FunctionReplacer; -import javax.servlet.ServletException; +import jakarta.servlet.ServletException; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.lang.reflect.InvocationTargetException; diff --git a/src/test/java/org/tuckey/web/testhelper/MockFilterChain.java b/src/test/java/org/tuckey/web/testhelper/MockFilterChain.java index 7e8b99e7..37674fbc 100644 --- a/src/test/java/org/tuckey/web/testhelper/MockFilterChain.java +++ b/src/test/java/org/tuckey/web/testhelper/MockFilterChain.java @@ -34,10 +34,10 @@ */ package org.tuckey.web.testhelper; -import javax.servlet.FilterChain; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; +import jakarta.servlet.FilterChain; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; import java.io.IOException; /** diff --git a/src/test/java/org/tuckey/web/testhelper/MockFilterConfig.java b/src/test/java/org/tuckey/web/testhelper/MockFilterConfig.java index e2178475..5f0436aa 100644 --- a/src/test/java/org/tuckey/web/testhelper/MockFilterConfig.java +++ b/src/test/java/org/tuckey/web/testhelper/MockFilterConfig.java @@ -34,8 +34,8 @@ */ package org.tuckey.web.testhelper; -import javax.servlet.FilterConfig; -import javax.servlet.ServletContext; +import jakarta.servlet.FilterConfig; +import jakarta.servlet.ServletContext; import java.util.Enumeration; /** diff --git a/src/test/java/org/tuckey/web/testhelper/MockRequest.java b/src/test/java/org/tuckey/web/testhelper/MockRequest.java index 37889ad4..ccdeaca2 100644 --- a/src/test/java/org/tuckey/web/testhelper/MockRequest.java +++ b/src/test/java/org/tuckey/web/testhelper/MockRequest.java @@ -34,11 +34,11 @@ */ package org.tuckey.web.testhelper; -import javax.servlet.RequestDispatcher; -import javax.servlet.ServletInputStream; -import javax.servlet.http.Cookie; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpSession; +import jakarta.servlet.RequestDispatcher; +import jakarta.servlet.ServletInputStream; +import jakarta.servlet.http.Cookie; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpSession; import java.io.BufferedReader; import java.io.IOException; import java.io.UnsupportedEncodingException; diff --git a/src/test/java/org/tuckey/web/testhelper/MockRequestDispatcher.java b/src/test/java/org/tuckey/web/testhelper/MockRequestDispatcher.java index 7f1d0686..3001c1af 100644 --- a/src/test/java/org/tuckey/web/testhelper/MockRequestDispatcher.java +++ b/src/test/java/org/tuckey/web/testhelper/MockRequestDispatcher.java @@ -34,10 +34,10 @@ */ package org.tuckey.web.testhelper; -import javax.servlet.RequestDispatcher; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; +import jakarta.servlet.RequestDispatcher; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; import java.io.IOException; /** diff --git a/src/test/java/org/tuckey/web/testhelper/MockResponse.java b/src/test/java/org/tuckey/web/testhelper/MockResponse.java index 67c43ba0..3fbabe64 100644 --- a/src/test/java/org/tuckey/web/testhelper/MockResponse.java +++ b/src/test/java/org/tuckey/web/testhelper/MockResponse.java @@ -34,9 +34,9 @@ */ package org.tuckey.web.testhelper; -import javax.servlet.ServletOutputStream; -import javax.servlet.http.Cookie; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.ServletOutputStream; +import jakarta.servlet.http.Cookie; +import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.PrintWriter; import java.io.ByteArrayOutputStream; diff --git a/src/test/java/org/tuckey/web/testhelper/MockServletContext.java b/src/test/java/org/tuckey/web/testhelper/MockServletContext.java index 78239f53..9abd4863 100644 --- a/src/test/java/org/tuckey/web/testhelper/MockServletContext.java +++ b/src/test/java/org/tuckey/web/testhelper/MockServletContext.java @@ -37,10 +37,10 @@ import org.tuckey.web.filters.urlrewrite.UrlRewriteFilterTest; import org.tuckey.web.filters.urlrewrite.utils.Log; -import javax.servlet.RequestDispatcher; -import javax.servlet.Servlet; -import javax.servlet.ServletContext; -import javax.servlet.ServletException; +import jakarta.servlet.RequestDispatcher; +import jakarta.servlet.Servlet; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; import java.io.InputStream; import java.net.MalformedURLException; import java.net.URL; diff --git a/src/test/java/org/tuckey/web/testhelper/MockSession.java b/src/test/java/org/tuckey/web/testhelper/MockSession.java index 16304d03..f0fc1c7d 100644 --- a/src/test/java/org/tuckey/web/testhelper/MockSession.java +++ b/src/test/java/org/tuckey/web/testhelper/MockSession.java @@ -34,9 +34,9 @@ */ package org.tuckey.web.testhelper; -import javax.servlet.ServletContext; -import javax.servlet.http.HttpSession; -import javax.servlet.http.HttpSessionContext; +import jakarta.servlet.ServletContext; +import jakarta.servlet.http.HttpSession; +import jakarta.servlet.http.HttpSessionContext; import java.util.Enumeration; import java.util.Hashtable; From 47d2f1ef5a2f3d68edc9452ad17ee2b541a81873 Mon Sep 17 00:00:00 2001 From: Paul Tuckey Date: Thu, 8 Jun 2023 19:51:50 +1200 Subject: [PATCH 04/19] progress --- pom.xml | 6 +- .../urlrewrite/test/UrlRewriteTestCase.java | 1524 +++++++++-------- .../tuckey/web/testhelper/MockRequest.java | 1022 ++++++----- .../tuckey/web/testhelper/MockResponse.java | 522 +++--- .../web/testhelper/MockServletContext.java | 523 ++++-- .../tuckey/web/testhelper/MockSession.java | 279 ++- 6 files changed, 2148 insertions(+), 1728 deletions(-) diff --git a/pom.xml b/pom.xml index 8bc8e35d..e6f24e0f 100644 --- a/pom.xml +++ b/pom.xml @@ -71,8 +71,8 @@ maven-compiler-plugin 3.11.0 - 1.7 - 1.7 + 1.8 + 1.8 @@ -182,7 +182,7 @@ true - ant + org.apache.ant ant 1.7.0 provided diff --git a/src/test/java/org/tuckey/web/filters/urlrewrite/test/UrlRewriteTestCase.java b/src/test/java/org/tuckey/web/filters/urlrewrite/test/UrlRewriteTestCase.java index 69ce6e56..7fdef6ef 100644 --- a/src/test/java/org/tuckey/web/filters/urlrewrite/test/UrlRewriteTestCase.java +++ b/src/test/java/org/tuckey/web/filters/urlrewrite/test/UrlRewriteTestCase.java @@ -1,705 +1,819 @@ -/** - * Copyright (c) 2005-2007, Paul Tuckey - * All rights reserved. - * ==================================================================== - * Licensed under the BSD License. Text as follows. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * - Neither the name tuckey.org nor the names of its contributors - * may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * ==================================================================== - */ -package org.tuckey.web.filters.urlrewrite.test; - -import junit.framework.TestCase; -import org.tuckey.web.filters.urlrewrite.Conf; -import org.tuckey.web.filters.urlrewrite.NormalRewrittenUrl; -import org.tuckey.web.filters.urlrewrite.Rule; -import org.tuckey.web.filters.urlrewrite.UrlRewriter; -import org.tuckey.web.filters.urlrewrite.utils.Log; - -import jakarta.servlet.RequestDispatcher; -import jakarta.servlet.ServletException; -import jakarta.servlet.ServletInputStream; -import jakarta.servlet.ServletOutputStream; -import jakarta.servlet.http.Cookie; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; -import jakarta.servlet.http.HttpSession; -import java.io.BufferedReader; -import java.io.IOException; -import java.io.PrintWriter; -import java.io.UnsupportedEncodingException; -import java.lang.reflect.InvocationTargetException; -import java.net.URL; -import java.security.Principal; -import java.util.ArrayList; -import java.util.Enumeration; -import java.util.Hashtable; -import java.util.List; -import java.util.Locale; -import java.util.Map; - -/** - * The idea for UrlRewriteTestCase is that users can extend it to create their own - * simple unit tests instead of having to manually setup a mock request and the filter. - *

- * note, Ideally this would be in a separate urlrewrite-test.jar but that - * seems a little over the top for one class. - */ -public class UrlRewriteTestCase extends TestCase { - - Conf conf; - UrlRewriter urlRewriter; - - public void loadConf(URL confFileUrl) { - Log.setLevel("SYSOUT:DEBUG"); - conf = new Conf(confFileUrl); - assertTrue("Conf should load without errors", conf.isOk()); - urlRewriter = new UrlRewriter(conf); - } - - public Rule getRule(String ruleName) { - List rules = urlRewriter.getConf().getRules(); - Rule rule = null; - if (rules != null) { - for (int i = 0; i < rules.size(); i++) { - Rule loopRule = (Rule) rules.get(i); - if (ruleName.equalsIgnoreCase(loopRule.getName())) { - rule = loopRule; - } - } - } - if (rule == null) { - assertTrue("Rule by the name " + ruleName + " does not exist", false); - } - return rule; - } - - /** - * Checks to see if the specified rule name matches the url specified. - * - * @param ruleName - the name of the rule - * @param requestUrl - the url to check - */ - public void assertRuleMatches(String ruleName, String requestUrl) { - - Rule rule = getRule(ruleName); - - MockResponse response = new MockResponse(); - MockRequest request = new MockRequest(requestUrl); - NormalRewrittenUrl rewrittenUrl = null; - try { - rewrittenUrl = (NormalRewrittenUrl) rule.matches(request.getRequestURI(), request, response); - - } catch (IOException e) { - assertNull("IOException during rule matching " + e.toString(), e); - - } catch (ServletException e) { - assertNull("ServletException during rule matching " + e.toString(), e); - - } catch (InvocationTargetException e) { - assertNull("InvocationTargetException during rule matching " + e.toString(), e); - - } - assertNotNull("Rule " + ruleName + " does not match", rewrittenUrl); - } - - public void assertRuleDoesNotMatches(String ruleName, String requestUrl) { - Rule rule = getRule(ruleName); - - MockResponse response = new MockResponse(); - MockRequest request = new MockRequest(requestUrl); - NormalRewrittenUrl rewrittenUrl = null; - try { - rewrittenUrl = (NormalRewrittenUrl) rule.matches(request.getRequestURI(), request, response); - - } catch (IOException e) { - assertNull("IOException during rule matching " + e.toString(), e); - - } catch (ServletException e) { - assertNull("ServletException during rule matching " + e.toString(), e); - - } catch (InvocationTargetException e) { - assertNull("InvocationTargetException during rule matching " + e.toString(), e); - - } - assertNull("Rule " + ruleName + " match", rewrittenUrl); - } - - - /** - * An empty method so that Junit doesn't complain when running tests. - */ - public void testUrlRerwriteTestCase() { - // do nothing - } -} - - -class MockRequest implements HttpServletRequest { - - private String requestURI; - private int serverPort = 80; - private String queryString; - private String method = "GET"; - private Hashtable headers = new Hashtable(); - private Hashtable attrs = new Hashtable(); - private Hashtable parameters = new Hashtable(); - private String authType; - private int contentLength; - private String contentType; - private String contextPath = ""; - private Cookie[] cookies; - private int cookieCounter; - private String pathInfo; - private String pathTranslated; - private String protocol; - private String remoteAddr; - private String remoteHost; - private String remoteUser; - private String requestedSessionId; - private String requestUrl; - private String serverName; - private String servletPath; - private String scheme; - private int localPort = 0; - - public MockRequest() { - } - - public MockRequest(String requestURI) { - this.requestURI = contextPath + requestURI; - this.requestUrl = requestURI; - this.servletPath = requestURI; - } - - public void setRequestURI(String requestURI) { - this.requestURI = requestURI; - } - - public String getAuthType() { - return authType; - } - - public void setAuthType(String s) { - authType = s; - } - - - public Cookie[] getCookies() { - return cookies; - } - - public long getDateHeader(String s) { - return 0; - } - - public String getHeader(String s) { - if (s == null) { - return null; - } - return (String) headers.get(s); - } - - public Enumeration getHeaders(String s) { - return headers.elements(); - } - - public Enumeration getHeaderNames() { - return headers.keys(); - } - - public int getIntHeader(String s) { - return 0; - } - - public String getMethod() { - return method; - } - - public String getPathInfo() { - return pathInfo; - } - - public String getPathTranslated() { - return pathTranslated; - } - - public String getContextPath() { - return contextPath; - } - - public String getQueryString() { - return queryString; - } - - public String getRemoteUser() { - return remoteUser; - } - - private ArrayList roles = new ArrayList(); - - public boolean isUserInRole(String s) { - return roles.contains(s); - } - - public void addRole(String s) { - roles.add(s); - } - - public void removeRole(String s) { - roles.remove(s); - } - - - public Principal getUserPrincipal() { - return null; - } - - public String getRequestedSessionId() { - return requestedSessionId; - } - - public String getRequestURI() { - return requestURI; - } - - public StringBuffer getRequestURL() { - if (requestUrl == null) return null; - return new StringBuffer(requestUrl); - } - - public String getServletPath() { - return servletPath; - } - - public HttpSession getSession(boolean b) { - return null; - } - - public void setSessionNew(boolean b) { - } - - public HttpSession getSession() { - return null; - } - - public boolean isRequestedSessionIdValid() { - return false; - } - - public boolean isRequestedSessionIdFromCookie() { - return false; - } - - public boolean isRequestedSessionIdFromURL() { - return false; - } - - /** - * @deprecated - */ - public boolean isRequestedSessionIdFromUrl() { - return false; - } - - public Object getAttribute(String s) { - return attrs.get(s); - } - - public Enumeration getAttributeNames() { - return null; - } - - public String getCharacterEncoding() { - return characterEncoding; - } - - String characterEncoding; - - public void setCharacterEncoding(String s) throws UnsupportedEncodingException { - characterEncoding = s; - } - - public int getContentLength() { - return contentLength; - } - - public String getContentType() { - return contentType; - } - - public ServletInputStream getInputStream() throws IOException { - return null; - } - - public String getParameter(String s) { - return (String) parameters.get(s); - } - - public Enumeration getParameterNames() { - return null; - } - - public String[] getParameterValues(String s) { - return new String[0]; - } - - public Map getParameterMap() { - return null; - } - - public String getProtocol() { - return protocol; - } - - public String getScheme() { - return scheme; - } - - public String getServerName() { - return serverName; - } - - public int getServerPort() { - return serverPort; - } - - public BufferedReader getReader() throws IOException { - return null; - } - - public String getRemoteAddr() { - return remoteAddr; - } - - public String getRemoteHost() { - return remoteHost; - } - - public void setAttribute(String s, Object o) { - attrs.put(s, o); - } - - public void removeAttribute(String s) { - attrs.remove(s); - } - - public Locale getLocale() { - return null; - } - - public Enumeration getLocales() { - return null; - } - - public boolean isSecure() { - return false; - } - - public RequestDispatcher getRequestDispatcher(String s) { - return null; - } - - /** - * @deprecated - */ - public String getRealPath(String s) { - return null; - } - - public int getRemotePort() { - return 0; - } - - public String getLocalName() { - return null; - } - - public String getLocalAddr() { - return null; - } - - public int getLocalPort() { - return localPort; - } - - public void setServerPort(int i) { - serverPort = i; - } - - public void setQueryString(String s) { - queryString = s; - } - - public void setMethod(String s) { - method = s; - } - - public void setHeader(String name, String value) { - headers.put(name, value); - } - - public void setContentLength(int i) { - contentLength = i; - } - - public void setContentType(String s) { - contentType = s; - } - - public void setContextPath(String s) { - contextPath = s; - } - - public void addCookie(Cookie c) { - if (cookies == null) cookies = new Cookie[100]; - cookies[cookieCounter++] = c; - } - - public void addParameter(String s, String s1) { - parameters.put(s, s1); - } - - public void setPathInfo(String s) { - pathInfo = s; - } - - public void setPathTranslated(String s) { - pathTranslated = s; - } - - public void setProtocol(String s) { - protocol = s; - } - - public void setRemoteAddr(String s) { - remoteAddr = s; - } - - public void setRemoteHost(String s) { - remoteHost = s; - } - - public void setRemoteUser(String s) { - remoteUser = s; - } - - public void setRequestedSessionId(String s) { - requestedSessionId = s; - } - - public void setRequestURL(String s) { - requestUrl = s; - } - - public void setServerName(String s) { - serverName = s; - } - - public void setScheme(String s) { - scheme = s; - } - - public void addHeader(String s, String s1) { - headers.put(s, s1); - } - - public void setLocalPort(int localPort) { - this.localPort = localPort; - } - -} - - -class MockResponse implements HttpServletResponse { - - private Hashtable responseHeaders = new Hashtable(); - private int status = 200; - private String redirectedUrl; - private List cookies = new ArrayList(); - private Locale locale; - - public void addCookie(Cookie cookie) { - cookies.add(cookie); - } - - public boolean containsHeader(String s) { - return false; - } - - public String encodeURL(String s) { - if (s == null) return null; - if (s.indexOf("http:") == 0) return s; - if (s.contains("?")) { - return s.substring(0, s.indexOf("?")) + ";mockencoded=test" + s.substring(s.indexOf("?"), s.length()); - } else { - return s.concat(";mockencoded=test"); - } - } - - public String encodeRedirectURL(String s) { - return encodeURL(s); - } - - /** - * @deprecated - */ - public String encodeUrl(String s) { - return encodeURL(s); - } - - /** - * @deprecated - */ - public String encodeRedirectUrl(String s) { - return encodeURL(s); - } - - public void sendError(int i, String s) throws IOException { - - } - - public void sendError(int i) throws IOException { - - } - - public void sendRedirect(String s) throws IOException { - redirectedUrl = s; - } - - public void setDateHeader(String s, long l) { - responseHeaders.put(s, l + ""); - } - - public void addDateHeader(String s, long l) { - responseHeaders.put(s, l + ""); - } - - public void setHeader(String s, String s1) { - responseHeaders.put(s, s1); - } - - public void addHeader(String s, String s1) { - responseHeaders.put(s, s1); - } - - public void setIntHeader(String s, int i) { - responseHeaders.put(s, i + ""); - } - - public void addIntHeader(String s, int i) { - responseHeaders.put(s, i + ""); - } - - public void setStatus(int i) { - status = i; - } - - /** - * @deprecated - */ - public void setStatus(int i, String s) { - - } - - public String getCharacterEncoding() { - return null; - } - - public String getContentType() { - return null; - } - - public ServletOutputStream getOutputStream() throws IOException { - return null; - } - - public PrintWriter getWriter() throws IOException { - return null; - } - - public void setCharacterEncoding(String s) { - - } - - public void setContentLength(int i) { - - } - - public void setContentType(String s) { - - } - - public void setBufferSize(int i) { - - } - - public int getBufferSize() { - return 0; - } - - public void flushBuffer() throws IOException { - - } - - public void resetBuffer() { - - } - - public boolean isCommitted() { - return false; - } - - public void reset() { - - } - - public void setLocale(Locale l) { - locale = l; - } - - public Locale getLocale() { - return locale; - } - - public String getHeader(String s) { - return (String) responseHeaders.get(s); - } - - public int getStatus() { - return status; - } - - public String getRedirectedUrl() { - return redirectedUrl; - } - - public List getCookies() { - return cookies; - } -} +/** + * Copyright (c) 2005-2007, Paul Tuckey + * All rights reserved. + * ==================================================================== + * Licensed under the BSD License. Text as follows. + *

+ * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + *

+ * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * - Neither the name tuckey.org nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + *

+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + */ +package org.tuckey.web.filters.urlrewrite.test; + +import jakarta.servlet.AsyncContext; +import jakarta.servlet.DispatcherType; +import jakarta.servlet.RequestDispatcher; +import jakarta.servlet.ServletConnection; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletInputStream; +import jakarta.servlet.ServletOutputStream; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; +import jakarta.servlet.http.Cookie; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpSession; +import jakarta.servlet.http.HttpUpgradeHandler; +import jakarta.servlet.http.Part; +import junit.framework.TestCase; +import org.tuckey.web.filters.urlrewrite.Conf; +import org.tuckey.web.filters.urlrewrite.NormalRewrittenUrl; +import org.tuckey.web.filters.urlrewrite.Rule; +import org.tuckey.web.filters.urlrewrite.UrlRewriter; +import org.tuckey.web.filters.urlrewrite.utils.Log; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.PrintWriter; +import java.io.UnsupportedEncodingException; +import java.lang.reflect.InvocationTargetException; +import java.net.URL; +import java.security.Principal; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Enumeration; +import java.util.Hashtable; +import java.util.List; +import java.util.Locale; +import java.util.Map; + +/** + * The idea for UrlRewriteTestCase is that users can extend it to create their own + * simple unit tests instead of having to manually setup a mock request and the filter. + *

+ * note, Ideally this would be in a separate urlrewrite-test.jar but that + * seems a little over the top for one class. + */ +public class UrlRewriteTestCase extends TestCase { + + Conf conf; + UrlRewriter urlRewriter; + + public void loadConf(URL confFileUrl) { + Log.setLevel("SYSOUT:DEBUG"); + conf = new Conf(confFileUrl); + assertTrue("Conf should load without errors", conf.isOk()); + urlRewriter = new UrlRewriter(conf); + } + + public Rule getRule(String ruleName) { + List rules = urlRewriter.getConf().getRules(); + Rule rule = null; + if (rules != null) { + for (int i = 0; i < rules.size(); i++) { + Rule loopRule = (Rule) rules.get(i); + if (ruleName.equalsIgnoreCase(loopRule.getName())) { + rule = loopRule; + } + } + } + if (rule == null) { + assertTrue("Rule by the name " + ruleName + " does not exist", false); + } + return rule; + } + + /** + * Checks to see if the specified rule name matches the url specified. + * + * @param ruleName - the name of the rule + * @param requestUrl - the url to check + */ + public void assertRuleMatches(String ruleName, String requestUrl) { + + Rule rule = getRule(ruleName); + + MockResponse response = new MockResponse(); + MockRequest request = new MockRequest(requestUrl); + NormalRewrittenUrl rewrittenUrl = null; + try { + rewrittenUrl = (NormalRewrittenUrl) rule.matches(request.getRequestURI(), request, response); + + } catch (IOException e) { + assertNull("IOException during rule matching " + e.toString(), e); + + } catch (ServletException e) { + assertNull("ServletException during rule matching " + e.toString(), e); + + } catch (InvocationTargetException e) { + assertNull("InvocationTargetException during rule matching " + e.toString(), e); + + } + assertNotNull("Rule " + ruleName + " does not match", rewrittenUrl); + } + + public void assertRuleDoesNotMatches(String ruleName, String requestUrl) { + Rule rule = getRule(ruleName); + + MockResponse response = new MockResponse(); + MockRequest request = new MockRequest(requestUrl); + NormalRewrittenUrl rewrittenUrl = null; + try { + rewrittenUrl = (NormalRewrittenUrl) rule.matches(request.getRequestURI(), request, response); + + } catch (IOException e) { + assertNull("IOException during rule matching " + e.toString(), e); + + } catch (ServletException e) { + assertNull("ServletException during rule matching " + e.toString(), e); + + } catch (InvocationTargetException e) { + assertNull("InvocationTargetException during rule matching " + e.toString(), e); + + } + assertNull("Rule " + ruleName + " match", rewrittenUrl); + } + + + /** + * An empty method so that Junit doesn't complain when running tests. + */ + public void testUrlRerwriteTestCase() { + // do nothing + } +} + + +class MockRequest implements HttpServletRequest { + + private String requestURI; + private int serverPort = 80; + private String queryString; + private String method = "GET"; + private Hashtable headers = new Hashtable(); + private Hashtable attrs = new Hashtable(); + private Hashtable parameters = new Hashtable(); + private String authType; + private int contentLength; + private String contentType; + private String contextPath = ""; + private Cookie[] cookies; + private int cookieCounter; + private String pathInfo; + private String pathTranslated; + private String protocol; + private String remoteAddr; + private String remoteHost; + private String remoteUser; + private String requestedSessionId; + private String requestUrl; + private String serverName; + private String servletPath; + private String scheme; + private int localPort = 0; + + public MockRequest() { + } + + public MockRequest(String requestURI) { + this.requestURI = contextPath + requestURI; + this.requestUrl = requestURI; + this.servletPath = requestURI; + } + + public void setRequestURI(String requestURI) { + this.requestURI = requestURI; + } + + public String getAuthType() { + return authType; + } + + public void setAuthType(String s) { + authType = s; + } + + + public Cookie[] getCookies() { + return cookies; + } + + public long getDateHeader(String s) { + return 0; + } + + public String getHeader(String s) { + if (s == null) { + return null; + } + return (String) headers.get(s); + } + + public Enumeration getHeaders(String s) { + return headers.elements(); + } + + public Enumeration getHeaderNames() { + return headers.keys(); + } + + public int getIntHeader(String s) { + return 0; + } + + public String getMethod() { + return method; + } + + public String getPathInfo() { + return pathInfo; + } + + public String getPathTranslated() { + return pathTranslated; + } + + public String getContextPath() { + return contextPath; + } + + public String getQueryString() { + return queryString; + } + + public String getRemoteUser() { + return remoteUser; + } + + private ArrayList roles = new ArrayList(); + + public boolean isUserInRole(String s) { + return roles.contains(s); + } + + public void addRole(String s) { + roles.add(s); + } + + public void removeRole(String s) { + roles.remove(s); + } + + + public Principal getUserPrincipal() { + return null; + } + + public String getRequestedSessionId() { + return requestedSessionId; + } + + public String getRequestURI() { + return requestURI; + } + + public StringBuffer getRequestURL() { + if (requestUrl == null) return null; + return new StringBuffer(requestUrl); + } + + public String getServletPath() { + return servletPath; + } + + public HttpSession getSession(boolean b) { + return null; + } + + public void setSessionNew(boolean b) { + } + + public HttpSession getSession() { + return null; + } + + @Override + public String changeSessionId() { + return null; + } + + public boolean isRequestedSessionIdValid() { + return false; + } + + public boolean isRequestedSessionIdFromCookie() { + return false; + } + + public boolean isRequestedSessionIdFromURL() { + return false; + } + + @Override + public boolean authenticate(HttpServletResponse httpServletResponse) throws IOException, ServletException { + return false; + } + + @Override + public void login(String s, String s1) throws ServletException { + + } + + @Override + public void logout() throws ServletException { + + } + + @Override + public Collection getParts() throws IOException, ServletException { + return null; + } + + @Override + public Part getPart(String s) throws IOException, ServletException { + return null; + } + + @Override + public T upgrade(Class aClass) throws IOException, ServletException { + return null; + } + + /** + * @deprecated + */ + public boolean isRequestedSessionIdFromUrl() { + return false; + } + + public Object getAttribute(String s) { + return attrs.get(s); + } + + public Enumeration getAttributeNames() { + return null; + } + + public String getCharacterEncoding() { + return characterEncoding; + } + + String characterEncoding; + + public void setCharacterEncoding(String s) throws UnsupportedEncodingException { + characterEncoding = s; + } + + public int getContentLength() { + return contentLength; + } + + @Override + public long getContentLengthLong() { + return 0; + } + + public String getContentType() { + return contentType; + } + + public ServletInputStream getInputStream() throws IOException { + return null; + } + + public String getParameter(String s) { + return (String) parameters.get(s); + } + + public Enumeration getParameterNames() { + return null; + } + + public String[] getParameterValues(String s) { + return new String[0]; + } + + public Map getParameterMap() { + return null; + } + + public String getProtocol() { + return protocol; + } + + public String getScheme() { + return scheme; + } + + public String getServerName() { + return serverName; + } + + public int getServerPort() { + return serverPort; + } + + public BufferedReader getReader() throws IOException { + return null; + } + + public String getRemoteAddr() { + return remoteAddr; + } + + public String getRemoteHost() { + return remoteHost; + } + + public void setAttribute(String s, Object o) { + attrs.put(s, o); + } + + public void removeAttribute(String s) { + attrs.remove(s); + } + + public Locale getLocale() { + return null; + } + + public Enumeration getLocales() { + return null; + } + + public boolean isSecure() { + return false; + } + + public RequestDispatcher getRequestDispatcher(String s) { + return null; + } + + /** + * @deprecated + */ + public String getRealPath(String s) { + return null; + } + + public int getRemotePort() { + return 0; + } + + public String getLocalName() { + return null; + } + + public String getLocalAddr() { + return null; + } + + public int getLocalPort() { + return localPort; + } + + @Override + public ServletContext getServletContext() { + return null; + } + + @Override + public AsyncContext startAsync() throws IllegalStateException { + return null; + } + + @Override + public AsyncContext startAsync(ServletRequest servletRequest, ServletResponse servletResponse) throws IllegalStateException { + return null; + } + + @Override + public boolean isAsyncStarted() { + return false; + } + + @Override + public boolean isAsyncSupported() { + return false; + } + + @Override + public AsyncContext getAsyncContext() { + return null; + } + + @Override + public DispatcherType getDispatcherType() { + return null; + } + + @Override + public String getRequestId() { + return null; + } + + @Override + public String getProtocolRequestId() { + return null; + } + + @Override + public ServletConnection getServletConnection() { + return null; + } + + public void setServerPort(int i) { + serverPort = i; + } + + public void setQueryString(String s) { + queryString = s; + } + + public void setMethod(String s) { + method = s; + } + + public void setHeader(String name, String value) { + headers.put(name, value); + } + + public void setContentLength(int i) { + contentLength = i; + } + + public void setContentType(String s) { + contentType = s; + } + + public void setContextPath(String s) { + contextPath = s; + } + + public void addCookie(Cookie c) { + if (cookies == null) cookies = new Cookie[100]; + cookies[cookieCounter++] = c; + } + + public void addParameter(String s, String s1) { + parameters.put(s, s1); + } + + public void setPathInfo(String s) { + pathInfo = s; + } + + public void setPathTranslated(String s) { + pathTranslated = s; + } + + public void setProtocol(String s) { + protocol = s; + } + + public void setRemoteAddr(String s) { + remoteAddr = s; + } + + public void setRemoteHost(String s) { + remoteHost = s; + } + + public void setRemoteUser(String s) { + remoteUser = s; + } + + public void setRequestedSessionId(String s) { + requestedSessionId = s; + } + + public void setRequestURL(String s) { + requestUrl = s; + } + + public void setServerName(String s) { + serverName = s; + } + + public void setScheme(String s) { + scheme = s; + } + + public void addHeader(String s, String s1) { + headers.put(s, s1); + } + + public void setLocalPort(int localPort) { + this.localPort = localPort; + } + +} + + +class MockResponse implements HttpServletResponse { + + private Hashtable responseHeaders = new Hashtable(); + private int status = 200; + private String redirectedUrl; + private List cookies = new ArrayList(); + private Locale locale; + + public void addCookie(Cookie cookie) { + cookies.add(cookie); + } + + public boolean containsHeader(String s) { + return false; + } + + public String encodeURL(String s) { + if (s == null) return null; + if (s.indexOf("http:") == 0) return s; + if (s.contains("?")) { + return s.substring(0, s.indexOf("?")) + ";mockencoded=test" + s.substring(s.indexOf("?"), s.length()); + } else { + return s.concat(";mockencoded=test"); + } + } + + public String encodeRedirectURL(String s) { + return encodeURL(s); + } + + /** + * @deprecated + */ + public String encodeUrl(String s) { + return encodeURL(s); + } + + /** + * @deprecated + */ + public String encodeRedirectUrl(String s) { + return encodeURL(s); + } + + public void sendError(int i, String s) throws IOException { + + } + + public void sendError(int i) throws IOException { + + } + + public void sendRedirect(String s) throws IOException { + redirectedUrl = s; + } + + public void setDateHeader(String s, long l) { + responseHeaders.put(s, l + ""); + } + + public void addDateHeader(String s, long l) { + responseHeaders.put(s, l + ""); + } + + public void setHeader(String s, String s1) { + responseHeaders.put(s, s1); + } + + public void addHeader(String s, String s1) { + responseHeaders.put(s, s1); + } + + public void setIntHeader(String s, int i) { + responseHeaders.put(s, i + ""); + } + + public void addIntHeader(String s, int i) { + responseHeaders.put(s, i + ""); + } + + public void setStatus(int i) { + status = i; + } + + /** + * @deprecated + */ + public void setStatus(int i, String s) { + + } + + public String getCharacterEncoding() { + return null; + } + + public String getContentType() { + return null; + } + + public ServletOutputStream getOutputStream() throws IOException { + return null; + } + + public PrintWriter getWriter() throws IOException { + return null; + } + + public void setCharacterEncoding(String s) { + + } + + public void setContentLength(int i) { + + } + + @Override + public void setContentLengthLong(long l) { + + } + + public void setContentType(String s) { + + } + + public void setBufferSize(int i) { + + } + + public int getBufferSize() { + return 0; + } + + public void flushBuffer() throws IOException { + + } + + public void resetBuffer() { + + } + + public boolean isCommitted() { + return false; + } + + public void reset() { + + } + + public void setLocale(Locale l) { + locale = l; + } + + public Locale getLocale() { + return locale; + } + + public String getHeader(String s) { + return (String) responseHeaders.get(s); + } + + @Override + public Collection getHeaders(String s) { + return null; + } + + @Override + public Collection getHeaderNames() { + return null; + } + + public int getStatus() { + return status; + } + + public String getRedirectedUrl() { + return redirectedUrl; + } + + public List getCookies() { + return cookies; + } +} diff --git a/src/test/java/org/tuckey/web/testhelper/MockRequest.java b/src/test/java/org/tuckey/web/testhelper/MockRequest.java index ccdeaca2..e5490031 100644 --- a/src/test/java/org/tuckey/web/testhelper/MockRequest.java +++ b/src/test/java/org/tuckey/web/testhelper/MockRequest.java @@ -1,460 +1,562 @@ -/** - * Copyright (c) 2005-2007, Paul Tuckey - * All rights reserved. - * ==================================================================== - * Licensed under the BSD License. Text as follows. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * - Neither the name tuckey.org nor the names of its contributors - * may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * ==================================================================== - */ -package org.tuckey.web.testhelper; - -import jakarta.servlet.RequestDispatcher; -import jakarta.servlet.ServletInputStream; -import jakarta.servlet.http.Cookie; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpSession; -import java.io.BufferedReader; -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.io.CharArrayReader; -import java.security.Principal; -import java.util.ArrayList; -import java.util.Enumeration; -import java.util.Hashtable; -import java.util.Locale; -import java.util.Map; - -/** - * @author Paul Tuckey - * @version $Revision: 36 $ $Date: 2006-09-19 18:32:39 +1200 (Tue, 19 Sep 2006) $ - */ -public class MockRequest implements HttpServletRequest { - - private String requestURI; - private int serverPort = 80; - private String queryString; - private String method = "GET"; - private Hashtable headers = new Hashtable(); - private Hashtable attrs = new Hashtable(); - private Hashtable parameters = new Hashtable(); - private MockSession session = null; - private String authType; - private int contentLength; - private String contentType; - private String contextPath = ""; - private Cookie[] cookies; - private int cookieCounter; - private String pathInfo; - private String pathTranslated; - private String protocol; - private String remoteAddr; - private String remoteHost; - private String remoteUser; - private String requestedSessionId; - private boolean requestedSessionIdFromCookie = false; - private boolean requestedSessionIdFromURL = false; - private boolean requestedSessionIdValid = false; - private String requestUrl; - private String serverName; - private String servletPath; - private String scheme; - private int localPort = 0; - private String body; - - public MockRequest() { - } - - public MockRequest(String requestURI) { - this.requestURI = contextPath + requestURI; - this.servletPath = requestURI; - } - - public void setRequestURI(String requestURI) { - this.requestURI = requestURI; - } - - public String getAuthType() { - return authType; - } - - public void setAuthType(String s) { - authType = s; - } - - - public Cookie[] getCookies() { - return cookies; - } - - public long getDateHeader(String s) { - return 0; - } - - public String getHeader(String s) { - if (s == null) { - return null; - } - return (String) headers.get(s); - } - - public Enumeration getHeaders(String s) { - return headers.elements(); - } - - public Enumeration getHeaderNames() { - return headers.keys(); - } - - public int getIntHeader(String s) { - return 0; - } - - public String getMethod() { - return method; - } - - public String getPathInfo() { - return pathInfo; - } - - public String getPathTranslated() { - return pathTranslated; - } - - public String getContextPath() { - return contextPath; - } - - public String getQueryString() { - return queryString; - } - - public String getRemoteUser() { - return remoteUser; - } - - private ArrayList roles = new ArrayList(); - - public boolean isUserInRole(String s) { - return roles.contains(s); - } - - public void addRole(String s) { - roles.add(s); - } - - public void removeRole(String s) { - roles.remove(s); - } - - - public Principal getUserPrincipal() { - return null; - } - - public String getRequestedSessionId() { - return requestedSessionId; - } - - public String getRequestURI() { - return requestURI; - } - - public StringBuffer getRequestURL() { - if (requestUrl == null) return null; - return new StringBuffer(requestUrl); - } - - public String getServletPath() { - return servletPath; - } - - public HttpSession getSession(boolean b) { - if (b && session == null) session = new MockSession(); - return session; - } - - public void setSessionNew(boolean b) { - if (session == null) session = new MockSession(); - session.setNew(b); - } - - public HttpSession getSession() { - return session; - } - - public MockSession getMockSession() { - return session; - } - - public boolean isRequestedSessionIdValid() { - return requestedSessionIdValid; - } - - public boolean isRequestedSessionIdFromCookie() { - return requestedSessionIdFromCookie; - } - - public boolean isRequestedSessionIdFromURL() { - return requestedSessionIdFromURL; - } - - /** - * @deprecated - */ - public boolean isRequestedSessionIdFromUrl() { - return false; - } - - public Object getAttribute(String s) { - return attrs.get(s); - } - - public Enumeration getAttributeNames() { - return null; - } - - public String getCharacterEncoding() { - return characterEncoding; - } - - String characterEncoding; - - public void setCharacterEncoding(String s) throws UnsupportedEncodingException { - characterEncoding = s; - } - - public int getContentLength() { - return contentLength; - } - - public String getContentType() { - return contentType; - } - - public ServletInputStream getInputStream() throws IOException { - return null; - } - - public String getParameter(String s) { - return (String) parameters.get(s); - } - - public void setParameter(String s, String v) { - parameters.put(s, v); - } - - public Enumeration getParameterNames() { - return parameters.keys(); - } - - public String[] getParameterValues(String s) { - return new String[0]; - } - - public Map getParameterMap() { - return null; - } - - public String getProtocol() { - return protocol; - } - - public String getScheme() { - return scheme; - } - - public String getServerName() { - return serverName; - } - - public int getServerPort() { - return serverPort; - } - - public BufferedReader getReader() throws IOException { - return new BufferedReader(new CharArrayReader(body.toCharArray())); - } - - public String getRemoteAddr() { - return remoteAddr; - } - - public String getRemoteHost() { - return remoteHost; - } - - public void setAttribute(String s, Object o) { - attrs.put(s, o); - } - - public void removeAttribute(String s) { - attrs.remove(s); - } - - public Locale getLocale() { - return null; - } - - public Enumeration getLocales() { - return null; - } - - public boolean isSecure() { - return false; - } - - public RequestDispatcher getRequestDispatcher(String s) { - return new MockRequestDispatcher(s); - } - - /** - * @deprecated - */ - public String getRealPath(String s) { - return null; - } - - public int getRemotePort() { - return 0; - } - - public String getLocalName() { - return null; - } - - public String getLocalAddr() { - return null; - } - - public int getLocalPort() { - return localPort; - } - - public void setServerPort(int i) { - serverPort = i; - } - - public void setQueryString(String s) { - queryString = s; - } - - public void setMethod(String s) { - method = s; - } - - public void setHeader(String name, String value) { - headers.put(name, value); - } - - public void setContentLength(int i) { - contentLength = i; - } - - public void setContentType(String s) { - contentType = s; - } - - public void setContextPath(String s) { - contextPath = s; - } - - public void addCookie(Cookie c) { - if (cookies == null) cookies = new Cookie[100]; - cookies[cookieCounter++] = c; - } - - public void addParameter(String s, String s1) { - parameters.put(s, s1); - } - - public void setPathInfo(String s) { - pathInfo = s; - } - - public void setPathTranslated(String s) { - pathTranslated = s; - } - - public void setProtocol(String s) { - protocol = s; - } - - public void setRemoteAddr(String s) { - remoteAddr = s; - } - - public void setRemoteHost(String s) { - remoteHost = s; - } - - public void setRemoteUser(String s) { - remoteUser = s; - } - - public void setRequestedSessionId(String s) { - requestedSessionId = s; - } - - public void setRequestURL(String s) { - requestUrl = s; - } - - public void setServerName(String s) { - serverName = s; - } - - public void setScheme(String s) { - scheme = s; - } - - public void addHeader(String s, String s1) { - headers.put(s, s1); - } - - public void setLocalPort(int localPort) { - this.localPort = localPort; - } - - public void setBody(String s) { - body = s; - } - - public void setRequestedSessionIdFromCookie(boolean requestedSessionIdFromCookie) { - this.requestedSessionIdFromCookie = requestedSessionIdFromCookie; - } - - public void setRequestedSessionIdFromURL(boolean requestedSessionIdFromURL) { - this.requestedSessionIdFromURL = requestedSessionIdFromURL; - } - - public void setRequestedSessionIdValid(boolean requestedSessionIdValid) { - this.requestedSessionIdValid = requestedSessionIdValid; - } -} +/** + * Copyright (c) 2005-2007, Paul Tuckey + * All rights reserved. + * ==================================================================== + * Licensed under the BSD License. Text as follows. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * - Neither the name tuckey.org nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + */ +package org.tuckey.web.testhelper; + +import jakarta.servlet.AsyncContext; +import jakarta.servlet.DispatcherType; +import jakarta.servlet.RequestDispatcher; +import jakarta.servlet.ServletConnection; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletInputStream; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; +import jakarta.servlet.http.Cookie; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpSession; +import jakarta.servlet.http.HttpUpgradeHandler; +import jakarta.servlet.http.Part; + +import java.io.BufferedReader; +import java.io.CharArrayReader; +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.security.Principal; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Enumeration; +import java.util.Hashtable; +import java.util.Locale; +import java.util.Map; + +/** + * @author Paul Tuckey + * @version $Revision: 36 $ $Date: 2006-09-19 18:32:39 +1200 (Tue, 19 Sep 2006) $ + */ +public class MockRequest implements HttpServletRequest { + + private String requestURI; + private int serverPort = 80; + private String queryString; + private String method = "GET"; + private Hashtable headers = new Hashtable(); + private Hashtable attrs = new Hashtable(); + private Hashtable parameters = new Hashtable(); + private MockSession session = null; + private String authType; + private int contentLength; + private String contentType; + private String contextPath = ""; + private Cookie[] cookies; + private int cookieCounter; + private String pathInfo; + private String pathTranslated; + private String protocol; + private String remoteAddr; + private String remoteHost; + private String remoteUser; + private String requestedSessionId; + private boolean requestedSessionIdFromCookie = false; + private boolean requestedSessionIdFromURL = false; + private boolean requestedSessionIdValid = false; + private String requestUrl; + private String serverName; + private String servletPath; + private String scheme; + private int localPort = 0; + private String body; + + public MockRequest() { + } + + public MockRequest(String requestURI) { + this.requestURI = contextPath + requestURI; + this.servletPath = requestURI; + } + + public void setRequestURI(String requestURI) { + this.requestURI = requestURI; + } + + public String getAuthType() { + return authType; + } + + public void setAuthType(String s) { + authType = s; + } + + + public Cookie[] getCookies() { + return cookies; + } + + public long getDateHeader(String s) { + return 0; + } + + public String getHeader(String s) { + if (s == null) { + return null; + } + return (String) headers.get(s); + } + + public Enumeration getHeaders(String s) { + return headers.elements(); + } + + public Enumeration getHeaderNames() { + return headers.keys(); + } + + public int getIntHeader(String s) { + return 0; + } + + public String getMethod() { + return method; + } + + public String getPathInfo() { + return pathInfo; + } + + public String getPathTranslated() { + return pathTranslated; + } + + public String getContextPath() { + return contextPath; + } + + public String getQueryString() { + return queryString; + } + + public String getRemoteUser() { + return remoteUser; + } + + private ArrayList roles = new ArrayList(); + + public boolean isUserInRole(String s) { + return roles.contains(s); + } + + public void addRole(String s) { + roles.add(s); + } + + public void removeRole(String s) { + roles.remove(s); + } + + + public Principal getUserPrincipal() { + return null; + } + + public String getRequestedSessionId() { + return requestedSessionId; + } + + public String getRequestURI() { + return requestURI; + } + + public StringBuffer getRequestURL() { + if (requestUrl == null) return null; + return new StringBuffer(requestUrl); + } + + public String getServletPath() { + return servletPath; + } + + public HttpSession getSession(boolean b) { + if (b && session == null) session = new MockSession(); + return session; + } + + public void setSessionNew(boolean b) { + if (session == null) session = new MockSession(); + session.setNew(b); + } + + public HttpSession getSession() { + return session; + } + + @Override + public String changeSessionId() { + return null; + } + + public MockSession getMockSession() { + return session; + } + + public boolean isRequestedSessionIdValid() { + return requestedSessionIdValid; + } + + public boolean isRequestedSessionIdFromCookie() { + return requestedSessionIdFromCookie; + } + + public boolean isRequestedSessionIdFromURL() { + return requestedSessionIdFromURL; + } + + @Override + public boolean authenticate(HttpServletResponse httpServletResponse) throws IOException, ServletException { + return false; + } + + @Override + public void login(String s, String s1) throws ServletException { + + } + + @Override + public void logout() throws ServletException { + + } + + @Override + public Collection getParts() throws IOException, ServletException { + return null; + } + + @Override + public Part getPart(String s) throws IOException, ServletException { + return null; + } + + @Override + public T upgrade(Class aClass) throws IOException, ServletException { + return null; + } + + /** + * @deprecated + */ + public boolean isRequestedSessionIdFromUrl() { + return false; + } + + public Object getAttribute(String s) { + return attrs.get(s); + } + + public Enumeration getAttributeNames() { + return null; + } + + public String getCharacterEncoding() { + return characterEncoding; + } + + String characterEncoding; + + public void setCharacterEncoding(String s) throws UnsupportedEncodingException { + characterEncoding = s; + } + + public int getContentLength() { + return contentLength; + } + + @Override + public long getContentLengthLong() { + return 0; + } + + public String getContentType() { + return contentType; + } + + public ServletInputStream getInputStream() throws IOException { + return null; + } + + public String getParameter(String s) { + return (String) parameters.get(s); + } + + public void setParameter(String s, String v) { + parameters.put(s, v); + } + + public Enumeration getParameterNames() { + return parameters.keys(); + } + + public String[] getParameterValues(String s) { + return new String[0]; + } + + public Map getParameterMap() { + return null; + } + + public String getProtocol() { + return protocol; + } + + public String getScheme() { + return scheme; + } + + public String getServerName() { + return serverName; + } + + public int getServerPort() { + return serverPort; + } + + public BufferedReader getReader() throws IOException { + return new BufferedReader(new CharArrayReader(body.toCharArray())); + } + + public String getRemoteAddr() { + return remoteAddr; + } + + public String getRemoteHost() { + return remoteHost; + } + + public void setAttribute(String s, Object o) { + attrs.put(s, o); + } + + public void removeAttribute(String s) { + attrs.remove(s); + } + + public Locale getLocale() { + return null; + } + + public Enumeration getLocales() { + return null; + } + + public boolean isSecure() { + return false; + } + + public RequestDispatcher getRequestDispatcher(String s) { + return new MockRequestDispatcher(s); + } + + /** + * @deprecated + */ + public String getRealPath(String s) { + return null; + } + + public int getRemotePort() { + return 0; + } + + public String getLocalName() { + return null; + } + + public String getLocalAddr() { + return null; + } + + public int getLocalPort() { + return localPort; + } + + @Override + public ServletContext getServletContext() { + return null; + } + + @Override + public AsyncContext startAsync() throws IllegalStateException { + return null; + } + + @Override + public AsyncContext startAsync(ServletRequest servletRequest, ServletResponse servletResponse) throws IllegalStateException { + return null; + } + + @Override + public boolean isAsyncStarted() { + return false; + } + + @Override + public boolean isAsyncSupported() { + return false; + } + + @Override + public AsyncContext getAsyncContext() { + return null; + } + + @Override + public DispatcherType getDispatcherType() { + return null; + } + + @Override + public String getRequestId() { + return null; + } + + @Override + public String getProtocolRequestId() { + return null; + } + + @Override + public ServletConnection getServletConnection() { + return null; + } + + public void setServerPort(int i) { + serverPort = i; + } + + public void setQueryString(String s) { + queryString = s; + } + + public void setMethod(String s) { + method = s; + } + + public void setHeader(String name, String value) { + headers.put(name, value); + } + + public void setContentLength(int i) { + contentLength = i; + } + + public void setContentType(String s) { + contentType = s; + } + + public void setContextPath(String s) { + contextPath = s; + } + + public void addCookie(Cookie c) { + if (cookies == null) cookies = new Cookie[100]; + cookies[cookieCounter++] = c; + } + + public void addParameter(String s, String s1) { + parameters.put(s, s1); + } + + public void setPathInfo(String s) { + pathInfo = s; + } + + public void setPathTranslated(String s) { + pathTranslated = s; + } + + public void setProtocol(String s) { + protocol = s; + } + + public void setRemoteAddr(String s) { + remoteAddr = s; + } + + public void setRemoteHost(String s) { + remoteHost = s; + } + + public void setRemoteUser(String s) { + remoteUser = s; + } + + public void setRequestedSessionId(String s) { + requestedSessionId = s; + } + + public void setRequestURL(String s) { + requestUrl = s; + } + + public void setServerName(String s) { + serverName = s; + } + + public void setScheme(String s) { + scheme = s; + } + + public void addHeader(String s, String s1) { + headers.put(s, s1); + } + + public void setLocalPort(int localPort) { + this.localPort = localPort; + } + + public void setBody(String s) { + body = s; + } + + public void setRequestedSessionIdFromCookie(boolean requestedSessionIdFromCookie) { + this.requestedSessionIdFromCookie = requestedSessionIdFromCookie; + } + + public void setRequestedSessionIdFromURL(boolean requestedSessionIdFromURL) { + this.requestedSessionIdFromURL = requestedSessionIdFromURL; + } + + public void setRequestedSessionIdValid(boolean requestedSessionIdValid) { + this.requestedSessionIdValid = requestedSessionIdValid; + } +} diff --git a/src/test/java/org/tuckey/web/testhelper/MockResponse.java b/src/test/java/org/tuckey/web/testhelper/MockResponse.java index 3fbabe64..231d53dd 100644 --- a/src/test/java/org/tuckey/web/testhelper/MockResponse.java +++ b/src/test/java/org/tuckey/web/testhelper/MockResponse.java @@ -1,248 +1,276 @@ -/** - * Copyright (c) 2005-2007, Paul Tuckey - * All rights reserved. - * ==================================================================== - * Licensed under the BSD License. Text as follows. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * - Neither the name tuckey.org nor the names of its contributors - * may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * ==================================================================== - */ -package org.tuckey.web.testhelper; - -import jakarta.servlet.ServletOutputStream; -import jakarta.servlet.http.Cookie; -import jakarta.servlet.http.HttpServletResponse; -import java.io.IOException; -import java.io.PrintWriter; -import java.io.ByteArrayOutputStream; -import java.io.StringWriter; -import java.util.ArrayList; -import java.util.Hashtable; -import java.util.List; -import java.util.Locale; - -/** - * @author Paul Tuckey - * @version $Revision: 1 $ $Date: 2006-08-01 21:40:28 +1200 (Tue, 01 Aug 2006) $ - */ -public class MockResponse implements HttpServletResponse { - - private Hashtable responseHeaders = new Hashtable(); - private int status = 200; - private String redirectedUrl; - private List cookies = new ArrayList(); - private Locale locale; - MockSerlvetOutputStream mockSerlvetOutputStream = new MockSerlvetOutputStream(); - StringWriter stringWriter = new StringWriter(); - PrintWriter writer = new PrintWriter(stringWriter); - - public void addCookie(Cookie cookie) { - cookies.add(cookie); - } - - public boolean containsHeader(String s) { - return false; - } - - public String encodeURL(String s) { - if (s == null) return null; - if (s.indexOf("http:") == 0 ) return s; - if (s.indexOf("?") != -1) { - return s.substring(0, s.indexOf("?")) + ";mockencoded=test" + s.substring(s.indexOf("?"), s.length()); - } else { - return s.concat(";mockencoded=test"); - } - } - - public String encodeRedirectURL(String s) { - return encodeURL(s); - } - - /** - * @deprecated - */ - public String encodeUrl(String s) { - return encodeURL(s); - } - - /** - * @deprecated - */ - public String encodeRedirectUrl(String s) { - return encodeURL(s); - } - - public void sendError(int i, String s) throws IOException { - - } - - public void sendError(int i) throws IOException { - - } - - public void sendRedirect(String s) throws IOException { - redirectedUrl = s; - } - - public void setDateHeader(String s, long l) { - responseHeaders.put(s, l + ""); - } - - public void addDateHeader(String s, long l) { - responseHeaders.put(s, l + ""); - } - - public void setHeader(String s, String s1) { - responseHeaders.put(s, s1); - } - - public void addHeader(String s, String s1) { - responseHeaders.put(s, s1); - } - - public void setIntHeader(String s, int i) { - responseHeaders.put(s, i + ""); - } - - public void addIntHeader(String s, int i) { - responseHeaders.put(s, i + ""); - } - - public void setStatus(int i) { - status = i; - } - - /** - * @deprecated - */ - public void setStatus(int i, String s) { - - } - - public String getCharacterEncoding() { - return null; - } - - public String getContentType() { - return null; - } - - public ServletOutputStream getOutputStream() throws IOException { - return mockSerlvetOutputStream; - } - - public String getOutputStreamAsString() { - return mockSerlvetOutputStream.getAsString(); - } - - public PrintWriter getWriter() throws IOException { - return writer; - } - - public String getWriterAsString() { - writer.flush(); - return stringWriter.toString(); - } - - public void setCharacterEncoding(String s) { - - } - - public void setContentLength(int i) { - - } - - public void setContentType(String s) { - - } - - public void setBufferSize(int i) { - - } - - public int getBufferSize() { - return 0; - } - - public void flushBuffer() throws IOException { - - } - - public void resetBuffer() { - - } - - public boolean isCommitted() { - return false; - } - - public void reset() { - - } - - public void setLocale(Locale l) { - locale = l; - } - - public Locale getLocale() { - return locale; - } - - public String getHeader(String s) { - return (String) responseHeaders.get(s); - } - - public int getStatus() { - return status; - } - - public String getRedirectedUrl() { - return redirectedUrl; - } - - public List getCookies() { - return cookies; - } -} - -class MockSerlvetOutputStream extends ServletOutputStream { - - ByteArrayOutputStream baos; - - public MockSerlvetOutputStream() { - this.baos = new ByteArrayOutputStream(); - } - - public void write(int b) throws IOException { - baos.write(b); - } - - public String getAsString() { - return new String(baos.toByteArray()); - } +/** + * Copyright (c) 2005-2007, Paul Tuckey + * All rights reserved. + * ==================================================================== + * Licensed under the BSD License. Text as follows. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * - Neither the name tuckey.org nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + */ +package org.tuckey.web.testhelper; + +import jakarta.servlet.ServletOutputStream; +import jakarta.servlet.WriteListener; +import jakarta.servlet.http.Cookie; +import jakarta.servlet.http.HttpServletResponse; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Hashtable; +import java.util.List; +import java.util.Locale; + +/** + * @author Paul Tuckey + * @version $Revision: 1 $ $Date: 2006-08-01 21:40:28 +1200 (Tue, 01 Aug 2006) $ + */ +public class MockResponse implements HttpServletResponse { + + private Hashtable responseHeaders = new Hashtable(); + private int status = 200; + private String redirectedUrl; + private List cookies = new ArrayList(); + private Locale locale; + MockSerlvetOutputStream mockSerlvetOutputStream = new MockSerlvetOutputStream(); + StringWriter stringWriter = new StringWriter(); + PrintWriter writer = new PrintWriter(stringWriter); + + public void addCookie(Cookie cookie) { + cookies.add(cookie); + } + + public boolean containsHeader(String s) { + return false; + } + + public String encodeURL(String s) { + if (s == null) return null; + if (s.indexOf("http:") == 0 ) return s; + if (s.indexOf("?") != -1) { + return s.substring(0, s.indexOf("?")) + ";mockencoded=test" + s.substring(s.indexOf("?"), s.length()); + } else { + return s.concat(";mockencoded=test"); + } + } + + public String encodeRedirectURL(String s) { + return encodeURL(s); + } + + /** + * @deprecated + */ + public String encodeUrl(String s) { + return encodeURL(s); + } + + /** + * @deprecated + */ + public String encodeRedirectUrl(String s) { + return encodeURL(s); + } + + public void sendError(int i, String s) throws IOException { + + } + + public void sendError(int i) throws IOException { + + } + + public void sendRedirect(String s) throws IOException { + redirectedUrl = s; + } + + public void setDateHeader(String s, long l) { + responseHeaders.put(s, l + ""); + } + + public void addDateHeader(String s, long l) { + responseHeaders.put(s, l + ""); + } + + public void setHeader(String s, String s1) { + responseHeaders.put(s, s1); + } + + public void addHeader(String s, String s1) { + responseHeaders.put(s, s1); + } + + public void setIntHeader(String s, int i) { + responseHeaders.put(s, i + ""); + } + + public void addIntHeader(String s, int i) { + responseHeaders.put(s, i + ""); + } + + public void setStatus(int i) { + status = i; + } + + /** + * @deprecated + */ + public void setStatus(int i, String s) { + + } + + public String getCharacterEncoding() { + return null; + } + + public String getContentType() { + return null; + } + + public ServletOutputStream getOutputStream() throws IOException { + return mockSerlvetOutputStream; + } + + public String getOutputStreamAsString() { + return mockSerlvetOutputStream.getAsString(); + } + + public PrintWriter getWriter() throws IOException { + return writer; + } + + public String getWriterAsString() { + writer.flush(); + return stringWriter.toString(); + } + + public void setCharacterEncoding(String s) { + + } + + public void setContentLength(int i) { + + } + + @Override + public void setContentLengthLong(long l) { + + } + + public void setContentType(String s) { + + } + + public void setBufferSize(int i) { + + } + + public int getBufferSize() { + return 0; + } + + public void flushBuffer() throws IOException { + + } + + public void resetBuffer() { + + } + + public boolean isCommitted() { + return false; + } + + public void reset() { + + } + + public void setLocale(Locale l) { + locale = l; + } + + public Locale getLocale() { + return locale; + } + + public String getHeader(String s) { + return (String) responseHeaders.get(s); + } + + @Override + public Collection getHeaders(String s) { + return null; + } + + @Override + public Collection getHeaderNames() { + return null; + } + + public int getStatus() { + return status; + } + + public String getRedirectedUrl() { + return redirectedUrl; + } + + public List getCookies() { + return cookies; + } +} + +class MockSerlvetOutputStream extends ServletOutputStream { + + ByteArrayOutputStream baos; + + public MockSerlvetOutputStream() { + this.baos = new ByteArrayOutputStream(); + } + + @Override + public boolean isReady() { + return false; + } + + @Override + public void setWriteListener(WriteListener writeListener) { + + } + + public void write(int b) throws IOException { + baos.write(b); + } + + public String getAsString() { + return new String(baos.toByteArray()); + } } \ No newline at end of file diff --git a/src/test/java/org/tuckey/web/testhelper/MockServletContext.java b/src/test/java/org/tuckey/web/testhelper/MockServletContext.java index 9abd4863..5b310e76 100644 --- a/src/test/java/org/tuckey/web/testhelper/MockServletContext.java +++ b/src/test/java/org/tuckey/web/testhelper/MockServletContext.java @@ -1,170 +1,353 @@ -/** - * Copyright (c) 2005-2007, Paul Tuckey - * All rights reserved. - * ==================================================================== - * Licensed under the BSD License. Text as follows. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * - Neither the name tuckey.org nor the names of its contributors - * may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * ==================================================================== - */ -package org.tuckey.web.testhelper; - -import org.tuckey.web.filters.urlrewrite.UrlRewriteFilterTest; -import org.tuckey.web.filters.urlrewrite.utils.Log; - -import jakarta.servlet.RequestDispatcher; -import jakarta.servlet.Servlet; -import jakarta.servlet.ServletContext; -import jakarta.servlet.ServletException; -import java.io.InputStream; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.Enumeration; -import java.util.Hashtable; -import java.util.Set; - -/** - * @author Paul Tuckey - * @version $Revision: 1 $ $Date: 2006-08-01 21:40:28 +1200 (Tue, 01 Aug 2006) $ - */ -public class MockServletContext implements ServletContext { - - private static Log log = Log.getLog(MockServletContext.class); - private final Hashtable attributes = new Hashtable(); - - public ServletContext getContext(String s) { - return new MockServletContext(); - } - - public Object getAttribute(String name) { - return this.attributes.get(name); - } - - public int getMajorVersion() { - return 0; - } - - public int getMinorVersion() { - return 0; - } - - public String getMimeType(String s) { - return null; - } - - public Set getResourcePaths(String s) { - return null; - } - - public URL getResource(String s) throws MalformedURLException { - return null; - } - - public InputStream getResourceAsStream(String s) { - return null; - } - - public RequestDispatcher getRequestDispatcher(String s) { - return null; - } - - public RequestDispatcher getNamedDispatcher(String s) { - return null; - } - - public Servlet getServlet(String s) throws ServletException { - return null; - } - - public Enumeration getServlets() { - return null; - } - - public Enumeration getServletNames() { - return null; - } - - public void log(String s) { - - } - - public void log(Exception e, String s) { - - } - - public void log(String s, Throwable throwable) { - - } - - public String getRealPath(String s) { - URL url = UrlRewriteFilterTest.class.getResource("conf-test1.xml"); - if ( url == null ) { - log.error("could not get base path for comparison"); - return null; - } else { - String basePath = url.getFile(); - log.debug("TEST ONLY using base path of " + basePath); - if (basePath.endsWith("conf-test1.xml")) basePath = basePath.substring(0, basePath.length() - "conf-test1.xml".length()); - if (basePath.endsWith("/")) basePath = basePath.substring(0, basePath.length() - 1); - return basePath + (s == null ? "" : s); - } - } - - public String getServerInfo() { - return null; - } - - public String getInitParameter(String s) { - return null; - } - - public Enumeration getInitParameterNames() { - return null; - } - - public Enumeration getAttributeNames() { - return null; - } - - public void setAttribute(String name, Object value) { - if (value != null) { - this.attributes.put(name, value); - } - else { - this.attributes.remove(name); - } - } - - public void removeAttribute(String s) { - - } - - public String getServletContextName() { - return null; - } -} +/** + * Copyright (c) 2005-2007, Paul Tuckey + * All rights reserved. + * ==================================================================== + * Licensed under the BSD License. Text as follows. + *

+ * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + *

+ * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * - Neither the name tuckey.org nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + *

+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + */ +package org.tuckey.web.testhelper; + +import jakarta.servlet.Filter; +import jakarta.servlet.FilterRegistration; +import jakarta.servlet.RequestDispatcher; +import jakarta.servlet.Servlet; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRegistration; +import jakarta.servlet.SessionCookieConfig; +import jakarta.servlet.SessionTrackingMode; +import jakarta.servlet.descriptor.JspConfigDescriptor; +import org.tuckey.web.filters.urlrewrite.UrlRewriteFilterTest; +import org.tuckey.web.filters.urlrewrite.utils.Log; + +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.Enumeration; +import java.util.EventListener; +import java.util.Hashtable; +import java.util.Map; +import java.util.Set; + +/** + * @author Paul Tuckey + * @version $Revision: 1 $ $Date: 2006-08-01 21:40:28 +1200 (Tue, 01 Aug 2006) $ + */ +public class MockServletContext implements ServletContext { + + private static Log log = Log.getLog(MockServletContext.class); + private final Hashtable attributes = new Hashtable(); + + @Override + public String getContextPath() { + return null; + } + + public ServletContext getContext(String s) { + return new MockServletContext(); + } + + public Object getAttribute(String name) { + return this.attributes.get(name); + } + + public int getMajorVersion() { + return 0; + } + + public int getMinorVersion() { + return 0; + } + + @Override + public int getEffectiveMajorVersion() { + return 0; + } + + @Override + public int getEffectiveMinorVersion() { + return 0; + } + + public String getMimeType(String s) { + return null; + } + + public Set getResourcePaths(String s) { + return null; + } + + public URL getResource(String s) throws MalformedURLException { + return null; + } + + public InputStream getResourceAsStream(String s) { + return null; + } + + public RequestDispatcher getRequestDispatcher(String s) { + return null; + } + + public RequestDispatcher getNamedDispatcher(String s) { + return null; + } + + public Servlet getServlet(String s) throws ServletException { + return null; + } + + public Enumeration getServlets() { + return null; + } + + public Enumeration getServletNames() { + return null; + } + + public void log(String s) { + + } + + public void log(Exception e, String s) { + + } + + public void log(String s, Throwable throwable) { + + } + + public String getRealPath(String s) { + URL url = UrlRewriteFilterTest.class.getResource("conf-test1.xml"); + if (url == null) { + log.error("could not get base path for comparison"); + return null; + } else { + String basePath = url.getFile(); + log.debug("TEST ONLY using base path of " + basePath); + if (basePath.endsWith("conf-test1.xml")) + basePath = basePath.substring(0, basePath.length() - "conf-test1.xml".length()); + if (basePath.endsWith("/")) basePath = basePath.substring(0, basePath.length() - 1); + return basePath + (s == null ? "" : s); + } + } + + public String getServerInfo() { + return null; + } + + public String getInitParameter(String s) { + return null; + } + + public Enumeration getInitParameterNames() { + return null; + } + + @Override + public boolean setInitParameter(String s, String s1) { + return false; + } + + public Enumeration getAttributeNames() { + return null; + } + + public void setAttribute(String name, Object value) { + if (value != null) { + this.attributes.put(name, value); + } else { + this.attributes.remove(name); + } + } + + public void removeAttribute(String s) { + + } + + public String getServletContextName() { + return null; + } + + @Override + public ServletRegistration.Dynamic addServlet(String s, String s1) { + return null; + } + + @Override + public ServletRegistration.Dynamic addServlet(String s, Servlet servlet) { + return null; + } + + @Override + public ServletRegistration.Dynamic addServlet(String s, Class aClass) { + return null; + } + + @Override + public ServletRegistration.Dynamic addJspFile(String s, String s1) { + return null; + } + + @Override + public T createServlet(Class aClass) throws ServletException { + return null; + } + + @Override + public ServletRegistration getServletRegistration(String s) { + return null; + } + + @Override + public Map getServletRegistrations() { + return null; + } + + @Override + public FilterRegistration.Dynamic addFilter(String s, String s1) { + return null; + } + + @Override + public FilterRegistration.Dynamic addFilter(String s, Filter filter) { + return null; + } + + @Override + public FilterRegistration.Dynamic addFilter(String s, Class aClass) { + return null; + } + + @Override + public T createFilter(Class aClass) throws ServletException { + return null; + } + + @Override + public FilterRegistration getFilterRegistration(String s) { + return null; + } + + @Override + public Map getFilterRegistrations() { + return null; + } + + @Override + public SessionCookieConfig getSessionCookieConfig() { + return null; + } + + @Override + public void setSessionTrackingModes(Set set) { + + } + + @Override + public Set getDefaultSessionTrackingModes() { + return null; + } + + @Override + public Set getEffectiveSessionTrackingModes() { + return null; + } + + @Override + public void addListener(String s) { + + } + + @Override + public void addListener(T t) { + + } + + @Override + public void addListener(Class aClass) { + + } + + @Override + public T createListener(Class aClass) throws ServletException { + return null; + } + + @Override + public JspConfigDescriptor getJspConfigDescriptor() { + return null; + } + + @Override + public ClassLoader getClassLoader() { + return null; + } + + @Override + public void declareRoles(String... strings) { + + } + + @Override + public String getVirtualServerName() { + return null; + } + + @Override + public int getSessionTimeout() { + return 0; + } + + @Override + public void setSessionTimeout(int i) { + + } + + @Override + public String getRequestCharacterEncoding() { + return null; + } + + @Override + public void setRequestCharacterEncoding(String s) { + + } + + @Override + public String getResponseCharacterEncoding() { + return null; + } + + @Override + public void setResponseCharacterEncoding(String s) { + + } +} diff --git a/src/test/java/org/tuckey/web/testhelper/MockSession.java b/src/test/java/org/tuckey/web/testhelper/MockSession.java index f0fc1c7d..ce0f7a95 100644 --- a/src/test/java/org/tuckey/web/testhelper/MockSession.java +++ b/src/test/java/org/tuckey/web/testhelper/MockSession.java @@ -1,143 +1,136 @@ -/** - * Copyright (c) 2005-2007, Paul Tuckey - * All rights reserved. - * ==================================================================== - * Licensed under the BSD License. Text as follows. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * - Neither the name tuckey.org nor the names of its contributors - * may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * ==================================================================== - */ -package org.tuckey.web.testhelper; - -import jakarta.servlet.ServletContext; -import jakarta.servlet.http.HttpSession; -import jakarta.servlet.http.HttpSessionContext; -import java.util.Enumeration; -import java.util.Hashtable; - -/** - * @author Paul Tuckey - * @version $Revision: 1 $ $Date: 2006-08-01 21:40:28 +1200 (Tue, 01 Aug 2006) $ - */ -public class MockSession implements HttpSession { - - MockServletContext servletContext = new MockServletContext(); - Hashtable attrs = new Hashtable(); - private boolean sessionNew; - - public long getCreationTime() { - return 0; - } - - public String getId() { - return null; - } - - public long getLastAccessedTime() { - return 0; - } - - public void setServletContext(ServletContext sc) { - servletContext = (MockServletContext) sc; - } - - public ServletContext getServletContext() { - return servletContext; - } - - public void setMaxInactiveInterval(int i) { - - } - - public int getMaxInactiveInterval() { - return 0; - } - - /** - * @deprecated - */ - public HttpSessionContext getSessionContext() { - return null; - } - - public Object getAttribute(String s) { - return attrs.get(s); - } - - /** - * @deprecated - */ - public Object getValue(String s) { - return null; - } - - public Enumeration getAttributeNames() { - return null; - } - - /** - * @deprecated - */ - public String[] getValueNames() { - return new String[0]; - } - - public void setAttribute(String s, Object o) { - attrs.put(s, o); - } - - /** - * @deprecated - */ - public void putValue(String s, Object o) { - - } - - public void removeAttribute(String s) { - attrs.remove(s); - } - - /** - * @deprecated - */ - public void removeValue(String s) { - - } - - public void invalidate() { - - } - - public boolean isNew() { - return sessionNew; - } - - public void setNew(boolean sessionNew) { - this.sessionNew = sessionNew; - } -} +/** + * Copyright (c) 2005-2007, Paul Tuckey + * All rights reserved. + * ==================================================================== + * Licensed under the BSD License. Text as follows. + *

+ * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + *

+ * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * - Neither the name tuckey.org nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + *

+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + */ +package org.tuckey.web.testhelper; + +import jakarta.servlet.ServletContext; +import jakarta.servlet.http.HttpSession; + +import java.util.Enumeration; +import java.util.Hashtable; + +/** + * @author Paul Tuckey + * @version $Revision: 1 $ $Date: 2006-08-01 21:40:28 +1200 (Tue, 01 Aug 2006) $ + */ +public class MockSession implements HttpSession { + + MockServletContext servletContext = new MockServletContext(); + Hashtable attrs = new Hashtable(); + private boolean sessionNew; + + public long getCreationTime() { + return 0; + } + + public String getId() { + return null; + } + + public long getLastAccessedTime() { + return 0; + } + + public void setServletContext(ServletContext sc) { + servletContext = (MockServletContext) sc; + } + + public ServletContext getServletContext() { + return servletContext; + } + + public void setMaxInactiveInterval(int i) { + + } + + public int getMaxInactiveInterval() { + return 0; + } + + public Object getAttribute(String s) { + return attrs.get(s); + } + + /** + * @deprecated + */ + public Object getValue(String s) { + return null; + } + + public Enumeration getAttributeNames() { + return null; + } + + /** + * @deprecated + */ + public String[] getValueNames() { + return new String[0]; + } + + public void setAttribute(String s, Object o) { + attrs.put(s, o); + } + + /** + * @deprecated + */ + public void putValue(String s, Object o) { + + } + + public void removeAttribute(String s) { + attrs.remove(s); + } + + /** + * @deprecated + */ + public void removeValue(String s) { + + } + + public void invalidate() { + + } + + public boolean isNew() { + return sessionNew; + } + + public void setNew(boolean sessionNew) { + this.sessionNew = sessionNew; + } +} From 9a1d92fc084ba588ccd00690915cb7c3830f57f5 Mon Sep 17 00:00:00 2001 From: Paul Tuckey Date: Thu, 8 Jun 2023 22:48:18 +1200 Subject: [PATCH 05/19] progress --- container-test2/example-webapp/pom.xml | 11 ++-- .../test-with-testcontainters/pom.xml | 8 ++- .../urlrewriteviacontainer/ExampleTest.java | 52 +++++++++++-------- 3 files changed, 43 insertions(+), 28 deletions(-) diff --git a/container-test2/example-webapp/pom.xml b/container-test2/example-webapp/pom.xml index 54ecf6b4..20d500b3 100644 --- a/container-test2/example-webapp/pom.xml +++ b/container-test2/example-webapp/pom.xml @@ -28,7 +28,7 @@ - webapp + example-webapp maven-compiler-plugin @@ -55,14 +55,15 @@ + org.tuckey urlrewritefilter - 4.0.4 + 5.0.0-SNAPSHOT - javax.servlet - javax.servlet-api - 3.1.0 + jakarta.servlet + jakarta.servlet-api + 6.0.0 provided diff --git a/container-test2/test-with-testcontainters/pom.xml b/container-test2/test-with-testcontainters/pom.xml index fe1b7dd2..f17728ef 100644 --- a/container-test2/test-with-testcontainters/pom.xml +++ b/container-test2/test-with-testcontainters/pom.xml @@ -33,9 +33,15 @@ + org.tuckey urlrewritefilter - 4.0.4 + 5.0.0-SNAPSHOT + + + org.apache.httpcomponents.client5 + httpclient5 + 5.2.1 org.junit.jupiter diff --git a/container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/ExampleTest.java b/container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/ExampleTest.java index 5e499b72..c81325cf 100644 --- a/container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/ExampleTest.java +++ b/container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/ExampleTest.java @@ -1,48 +1,56 @@ package org.tuckey.web.filters.urlrewriteviacontainer; +import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; +import org.apache.hc.client5.http.impl.classic.HttpClients; +import org.apache.hc.core5.http.ClassicHttpRequest; +import org.apache.hc.core5.http.io.support.ClassicRequestBuilder; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.wait.strategy.Wait; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; -import org.testcontainers.utility.DockerImageName; -import org.testcontainers.utility.MountableFile; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.testcontainers.shaded.org.apache.commons.lang3.BooleanUtils.isTrue; + +import java.io.IOException; +import java.nio.file.Paths; + @Testcontainers public class ExampleTest { - private final MountableFile warFile = MountableFile.forHostPath("/Users/paul/co/urlrewritefilter/container-test2/example-webapp/target/webapp.war"); + String webappPath = Paths.get("..", "example-webapp", "target", "example-webapp.war") + .toAbsolutePath().toString(); @Container - public GenericContainer container = new GenericContainer(DockerImageName.parse("payara/micro")) - .withExposedPorts(8087) - .withCopyFileToContainer(warFile, "/opt/payara/deployments/webapp.war") - .withCommand("--noCluster --deploy /opt/payara/deployments/webapp.war --contextRoot /") - .waitingFor(Wait.forHttp("/get").forStatusCode(200)); + public GenericContainer container = new GenericContainer<>("tomcat:10.1.9") + .withReuse(true) + .withExposedPorts(8080) + .withFileSystemBind(webappPath, "/usr/local/tomcat/webapps/example-webapp.war") + .waitingFor(Wait.forHttp("/example-webapp/test/test.jsp").forStatusCode(200)); @BeforeEach public void setUp() { - // Assume that we have Redis running locally? - //underTest = new RedisBackedCache("localhost", 6379); + System.out.println("War: " + webappPath); } @Test - public void checkContainerIsRunning(){ - assert(isTrue(container.isRunning())); + public void checkContainerIsRunning() { + System.out.println(container.getContainerId()); + assert (container.isRunning()); } @Test - public void testSimplePutAndGet() { - //System.out.println(webContainer.getContainerId()); - //underTest.put("test", "example"); - - //String retrieved = underTest.get("test"); - //assertThat("123").isEqualTo("example"); - - + public void testSimplePutAndGet() throws IOException { + System.out.println("Container ID" + container.getContainerId()); + + try (CloseableHttpClient httpClient = HttpClients.createDefault()) { + ClassicHttpRequest httpGet = ClassicRequestBuilder.get("http://localhost:8080/example-webapp/test/test.jsp") + .build(); + httpClient.execute(httpGet, response -> { + System.out.println(response.getCode() + " " + response.getReasonPhrase()); + return null; + }); + } } } \ No newline at end of file From 2b10e16eb5485cd45cbd5596ccd7787f77530f16 Mon Sep 17 00:00:00 2001 From: Paul Tuckey Date: Fri, 9 Jun 2023 20:36:40 +1200 Subject: [PATCH 06/19] progress --- container-test2/example-webapp/pom.xml | 2 +- .../test-with-testcontainters/pom.xml | 20 +- .../ContainerTestBase.java | 127 +++++++++++++ .../urlrewriteviacontainer/ExampleTest.java | 56 ------ .../WebappDecodeNoneIT.java | 70 +++++++ .../WebappDecodeUtf8IT.java | 59 ++++++ .../urlrewriteviacontainer/WebappHttpIT.java | 172 ++++++++++++++++++ .../WebappModStyleHttpIT.java | 82 +++++++++ 8 files changed, 528 insertions(+), 60 deletions(-) create mode 100644 container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/ContainerTestBase.java delete mode 100644 container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/ExampleTest.java create mode 100644 container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeNoneIT.java create mode 100644 container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeUtf8IT.java create mode 100644 container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappHttpIT.java create mode 100644 container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappModStyleHttpIT.java diff --git a/container-test2/example-webapp/pom.xml b/container-test2/example-webapp/pom.xml index 20d500b3..2d9fc1e1 100644 --- a/container-test2/example-webapp/pom.xml +++ b/container-test2/example-webapp/pom.xml @@ -28,7 +28,7 @@ - example-webapp + webapp maven-compiler-plugin diff --git a/container-test2/test-with-testcontainters/pom.xml b/container-test2/test-with-testcontainters/pom.xml index f17728ef..e2afa6bf 100644 --- a/container-test2/test-with-testcontainters/pom.xml +++ b/container-test2/test-with-testcontainters/pom.xml @@ -39,9 +39,17 @@ 5.0.0-SNAPSHOT - org.apache.httpcomponents.client5 - httpclient5 - 5.2.1 + + org.tuckey + example-webapp + 5.0.0 + test + + + commons-httpclient + commons-httpclient + 3.1 + test org.junit.jupiter @@ -71,6 +79,12 @@ slf4j-simple 1.7.5 + + jakarta.servlet + jakarta.servlet-api + 6.0.0 + test + diff --git a/container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/ContainerTestBase.java b/container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/ContainerTestBase.java new file mode 100644 index 00000000..7ffdb3d1 --- /dev/null +++ b/container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/ContainerTestBase.java @@ -0,0 +1,127 @@ +/** + * Copyright (c) 2005-2007, Paul Tuckey + * All rights reserved. + * ==================================================================== + * Licensed under the BSD License. Text as follows. + *

+ * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + *

+ * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * - Neither the name tuckey.org nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + *

+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + */ +package org.tuckey.web.filters.urlrewriteviacontainer; + +import org.apache.commons.httpclient.HttpClient; +import org.apache.commons.httpclient.methods.GetMethod; +import org.junit.jupiter.api.BeforeEach; +import org.testcontainers.containers.GenericContainer; +import org.testcontainers.containers.wait.strategy.Wait; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; + +import java.io.File; +import java.io.IOException; +import java.io.PrintWriter; +import java.nio.file.Paths; + + +@Testcontainers +public abstract class ContainerTestBase { + + private int mappedPort = 0; + + protected HttpClient client = new HttpClient(); + private File systemPropBaseReportsDir = new File("container-test", "reports"); + private String containerId = "test"; + + String webappPath = Paths.get("..", "example-webapp", "target", "webapp.war") + .toAbsolutePath().toString(); + + @Container + public GenericContainer container = new GenericContainer<>("tomcat:10.1.9") + .withReuse(true) + .withExposedPorts(8080) + .withFileSystemBind(webappPath, "/usr/local/tomcat/webapps/webapp.war") + .waitingFor(Wait.forHttp("/webapp/test/test.jsp").forStatusCode(200)); + + //@BeforeEach + public void setUp() throws Exception { + container.start(); + System.out.println(container.getContainerId()); + System.out.println("PORT " + container.getFirstMappedPort()); + this.mappedPort = container.getFirstMappedPort(); + assert (container.isRunning()); + + String containerId = System.getProperty("test.container.id"); + if (containerId != null) { + this.containerId = containerId; + } +// String systemPropBaseUrl = System.getProperty("test.base.url"); +// if (systemPropBaseUrl != null) { +// baseUrl = systemPropBaseUrl; +// } + String systemPropBaseReports = System.getProperty("test.base.reports"); + if (systemPropBaseReports != null) { + systemPropBaseReportsDir = new File(systemPropBaseReports); + } + System.err.println("systemPropBaseReportsDir: " + systemPropBaseReportsDir); + + GetMethod method = new GetMethod(getBaseUrl() + "/rewrite-status/?conf=/WEB-INF/" + getConf()); + client.executeMethod(method); + } + + protected String getBaseUrl() { + return "http://localhost:" + this.mappedPort + "/" + getApp(); + } + + protected void recordRewriteStatus() throws IOException { + GetMethod method = new GetMethod(getBaseUrl() + "/" + getApp() + "/rewrite-status"); + method.setFollowRedirects(false); + client.executeMethod(method); + File statusFile = new File(containerId + "-" + getApp() + "-" + getConf() + "-rewrite-status.html"); + if (statusFile.exists() && !statusFile.delete()) { + System.out.println("could not remove status at " + statusFile.getAbsolutePath()); + } else + if (!statusFile.createNewFile()) { // some containers don't let us do this + System.out.println("could not create status at " + statusFile.getAbsolutePath()); + } else { + PrintWriter pw = new PrintWriter(statusFile); + pw.print(method.getResponseBodyAsString()); + pw.close(); + System.out.println("status saved to " + statusFile.getAbsolutePath()); + } + } + + abstract protected String getApp(); + + protected String getConf() { + return "urlrewrite.xml"; + } + + public String getContainerId() { + return containerId; + } +} diff --git a/container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/ExampleTest.java b/container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/ExampleTest.java deleted file mode 100644 index c81325cf..00000000 --- a/container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/ExampleTest.java +++ /dev/null @@ -1,56 +0,0 @@ -package org.tuckey.web.filters.urlrewriteviacontainer; - -import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; -import org.apache.hc.client5.http.impl.classic.HttpClients; -import org.apache.hc.core5.http.ClassicHttpRequest; -import org.apache.hc.core5.http.io.support.ClassicRequestBuilder; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.testcontainers.containers.GenericContainer; -import org.testcontainers.containers.wait.strategy.Wait; -import org.testcontainers.junit.jupiter.Container; -import org.testcontainers.junit.jupiter.Testcontainers; - - -import java.io.IOException; -import java.nio.file.Paths; - - -@Testcontainers -public class ExampleTest { - - String webappPath = Paths.get("..", "example-webapp", "target", "example-webapp.war") - .toAbsolutePath().toString(); - - @Container - public GenericContainer container = new GenericContainer<>("tomcat:10.1.9") - .withReuse(true) - .withExposedPorts(8080) - .withFileSystemBind(webappPath, "/usr/local/tomcat/webapps/example-webapp.war") - .waitingFor(Wait.forHttp("/example-webapp/test/test.jsp").forStatusCode(200)); - - @BeforeEach - public void setUp() { - System.out.println("War: " + webappPath); - } - - @Test - public void checkContainerIsRunning() { - System.out.println(container.getContainerId()); - assert (container.isRunning()); - } - - @Test - public void testSimplePutAndGet() throws IOException { - System.out.println("Container ID" + container.getContainerId()); - - try (CloseableHttpClient httpClient = HttpClients.createDefault()) { - ClassicHttpRequest httpGet = ClassicRequestBuilder.get("http://localhost:8080/example-webapp/test/test.jsp") - .build(); - httpClient.execute(httpGet, response -> { - System.out.println(response.getCode() + " " + response.getReasonPhrase()); - return null; - }); - } - } -} \ No newline at end of file diff --git a/container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeNoneIT.java b/container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeNoneIT.java new file mode 100644 index 00000000..e6652294 --- /dev/null +++ b/container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeNoneIT.java @@ -0,0 +1,70 @@ +package org.tuckey.web.filters.urlrewriteviacontainer; + + +import org.apache.commons.httpclient.methods.GetMethod; + +import jakarta.servlet.ServletException; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.BeforeEach; + + +import java.io.IOException; +import java.net.URLEncoder; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +/** + * + */ +public class WebappDecodeNoneIT extends ContainerTestBase { + + protected String getApp() { + return "webapp"; + } + + protected String getConf() { + return "urlrewrite-decode-none.xml"; + } + + @BeforeEach + public void testSetup() throws Exception { + super.setUp(); + super.recordRewriteStatus(); + } + + /** + * note, had trouble keeping true utf (multi byte) chars as cvs buggers them up! + */ + @Test + public void testTestUtf() throws ServletException, IOException { + if ( "orion2.0.5".equals(getContainerId())) return; // orion not supported + String encodedStr = URLEncoder.encode("m\u0101ori", "UTF8"); + GetMethod method = new GetMethod(getBaseUrl() + "/utf/" + encodedStr + "/"); + method.setRequestHeader("Accept-Encoding", "utf8"); + method.setFollowRedirects(false); + client.executeMethod(method); + assertNotNull("no location header", method.getResponseHeader("Location")); + assertEquals(getBaseUrl() + "/utf-redir/done/" + encodedStr + "/", method.getResponseHeader("Location").getValue()); + } + + public void testNoDecode() throws IOException { + if ( "orion2.0.5".equals(getContainerId())) return; // jsp's with % in path not supported + if ( "tomcat-4.1.31".equals(getContainerId())) return; // jsp's with % in path not supported + + GetMethod method = new GetMethod(getBaseUrl() + "/no-decode-test/D%25%2cD"); + client.executeMethod(method); + assertEquals("this is no-decode-test target jsp", method.getResponseBodyAsString()); + } + + public void testQueryStringNoDecode() throws IOException { + if ( "orion2.0.5".equals(getContainerId())) return; // orion cannot correctly encode & into %26 + + GetMethod method = new GetMethod(getBaseUrl() + "/query-string-no-decode/jack+%26+jones"); + method.setFollowRedirects(false); + client.executeMethod(method); + assertEquals("http://query-string-no-decode-result.com/?q=jack+%26+jones&another=jack & jones", method.getResponseHeader("Location").getValue()); + } + + +} \ No newline at end of file diff --git a/container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeUtf8IT.java b/container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeUtf8IT.java new file mode 100644 index 00000000..555d3d33 --- /dev/null +++ b/container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeUtf8IT.java @@ -0,0 +1,59 @@ +package org.tuckey.web.filters.urlrewriteviacontainer; + + +import org.apache.commons.httpclient.methods.GetMethod; + +import jakarta.servlet.ServletException; +import java.io.IOException; +import java.net.URLEncoder; + +import static org.junit.Assert.assertEquals; + +/** + * todo: need to do a few tests + *

+ * with eocode-using not set (ie, browser encoding used, step down to utf8) + * with eocode-using set to utf (force always with a specific decoding) + * with eocode-using not set to null (never decode) + * accept-encoding header? + *

+ *

+ * don't decode anything - null + * browser then utf then default - default browser,utf + * browser then don't decode - default browser,null + * always utf - utf + *

+ *

+ * options: browser (may fail), enc (unlikely fail) + */ +public class WebappDecodeUtf8IT extends ContainerTestBase { + + protected String getApp() { + return "webapp"; + } + + protected String getConf() { + return "urlrewrite-decode-utf8.xml"; + } + + public void testSetup() throws IOException { + super.recordRewriteStatus(); + } + + + /** + * + */ + public void testTestUtf() throws ServletException, IOException { + String utfSampleString = "m\u0101ori"; + GetMethod method = new GetMethod(getBaseUrl() + "/utf/" + URLEncoder.encode(utfSampleString, "UTF8") + "/"); + method.setRequestHeader("Accept-Encoding", "utf8"); + method.setFollowRedirects(false); + client.executeMethod(method); + assertEquals(getBaseUrl() + "/utf-redir/done/", method.getResponseHeader("Location").getValue()); + } + + + + +} diff --git a/container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappHttpIT.java b/container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappHttpIT.java new file mode 100644 index 00000000..58df2c30 --- /dev/null +++ b/container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappHttpIT.java @@ -0,0 +1,172 @@ +/** + * Copyright (c) 2005-2007, Paul Tuckey + * All rights reserved. + * ==================================================================== + * Licensed under the BSD License. Text as follows. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * - Neither the name tuckey.org nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + */ +package org.tuckey.web.filters.urlrewriteviacontainer; + +import org.apache.commons.httpclient.Header; +import org.apache.commons.httpclient.methods.GetMethod; +import org.tuckey.web.filters.urlrewrite.utils.StringUtils; +import org.xml.sax.SAXException; + +import jakarta.servlet.ServletException; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.zip.GZIPInputStream; + +import static org.junit.Assert.*; + + +/** + * @author Paul Tuckey + * @version $Revision: 33 $ $Date: 2006-09-12 16:41:56 +1200 (Tue, 12 Sep 2006) $ + */ +public class WebappHttpIT extends ContainerTestBase { + + protected String getApp() { + return "webapp"; + } + + public void testStatusRecord() throws IOException { + super.recordRewriteStatus(); + } + + public void testProduct() throws IOException, SAXException, InterruptedException { + GetMethod method = new GetMethod(getBaseUrl() + "/products/987"); + client.executeMethod(method); + assertEquals("product 987", method.getResponseBodyAsString()); + } + + + public void testSimpleDistEx() throws ServletException, IOException, SAXException { + GetMethod method = new GetMethod(getBaseUrl() + "/test/status/"); + method.setFollowRedirects(false); + client.executeMethod(method); + assertEquals(getBaseUrl() + "/rewrite-status", method.getResponseHeader("Location").getValue()); + } + + public void testBasicSets() throws ServletException, IOException, SAXException { + GetMethod method = new GetMethod(getBaseUrl() + "/settest/674"); + client.executeMethod(method); + assertNotNull(method.getResponseHeader("cache-control")); + assertEquals("testsession: hello!, " + + "param.settest1: 674, " + + "method: DELETE", method.getResponseBodyAsString()); + } + + public void testMultipleProduct() throws ServletException, IOException, SAXException { + GetMethod method = new GetMethod(getBaseUrl() + "/multiple/products/987"); + client.executeMethod(method); + assertEquals("product 987", method.getResponseBodyAsString()); + } + + public void testNullTo() throws ServletException, IOException { + GetMethod method = new GetMethod(getBaseUrl() + "/hideme/anb.jsp;dsaddd?asdasds#sdsfd"); + client.executeMethod(method); + assertEquals("should have status set", 403, method.getStatusCode()); + String CONTENT = "

some content

"; + assertFalse("should not output above content", CONTENT.equals(StringUtils.trim(method.getResponseBodyAsString()))); + } + + public void testYear() throws ServletException, IOException { + GetMethod method = new GetMethod(getBaseUrl() + "/time/year/current"); + client.executeMethod(method); + assertEquals("echo yearisbetween1970and3000", method.getResponseBodyAsString()); + } + + public void testTestAxis() throws ServletException, IOException { + GetMethod method = new GetMethod(getBaseUrl() + "/services/blah?qwerty"); + method.setFollowRedirects(false); + client.executeMethod(method); + assertEquals(getBaseUrl() + "/axis/services/blah", method.getResponseHeader("Location").getValue()); + } + + public void testTestErik() throws ServletException, IOException { + GetMethod method = new GetMethod(getBaseUrl() + "/eriktest/hi.ho"); + method.setFollowRedirects(false); + method.addRequestHeader(new Header("host", "blah.com")); + client.executeMethod(method); + assertEquals("http://www.example.com/context/hi.ho", method.getResponseHeader("Location").getValue()); + } + + public void testTestEncode() throws ServletException, IOException { + GetMethod method = new GetMethod(getBaseUrl() + "/went%20to%20bahamas/"); + method.setFollowRedirects(false); + client.executeMethod(method); + assertEquals(getBaseUrl() + "/jamaica/", method.getResponseHeader("Location").getValue()); + } + + public void testSimpleRun() throws ServletException, IOException { + GetMethod method = new GetMethod(getBaseUrl() + "/run/test/test1"); + client.executeMethod(method); + assertEquals("this is " + TestRunObj.class.getName(), method.getResponseBodyAsString()); + } + + public void testQueryStringEscape() throws IOException { + GetMethod method = new GetMethod(getBaseUrl() + "/query-string-escape/jack+%26+jones"); + method.setFollowRedirects(false); + client.executeMethod(method); + assertEquals("http://query-string-escape-result.com/?q=jack%2B%26%2Bjones&another=jack+&+jones", method.getResponseHeader("Location").getValue()); + } + + public void testGzip() throws IOException { + GetMethod method = new GetMethod(getBaseUrl() + "/gzip-me.jsp"); + method.addRequestHeader("accept-encoding", "gzip"); + client.executeMethod(method); + assertEquals("gzip", method.getResponseHeader("Content-Encoding").getValue()); + assertEquals("hello world hello world hello world", inflateGzipToString(method.getResponseBodyAsStream())); + } + + /** + * inflate a gzipped inputstream and return it as a string. + */ + private String inflateGzipToString(InputStream is) throws IOException { + GZIPInputStream gis = new GZIPInputStream(is); + ByteArrayOutputStream os = new ByteArrayOutputStream(); + byte[] buffer = new byte[1024]; + while (true) { + int bytesRead = gis.read(buffer); + if (bytesRead == -1) break; + os.write(buffer, 0, bytesRead); + } + return os.toString(); + } + + public void testSampleAnnotation() throws IOException { + GetMethod method = new GetMethod(getBaseUrl() + "/do-something/7"); + client.executeMethod(method); + assertEquals(method.getResponseBodyAsString(), "AnnotatedClassSample id=7"); + } + +} diff --git a/container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappModStyleHttpIT.java b/container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappModStyleHttpIT.java new file mode 100644 index 00000000..7d6ea9a3 --- /dev/null +++ b/container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappModStyleHttpIT.java @@ -0,0 +1,82 @@ +/** + * Copyright (c) 2005-2007, Paul Tuckey + * All rights reserved. + * ==================================================================== + * Licensed under the BSD License. Text as follows. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * - Neither the name tuckey.org nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + */ +package org.tuckey.web.filters.urlrewriteviacontainer; + +import org.apache.commons.httpclient.methods.GetMethod; +import org.xml.sax.SAXException; + +import jakarta.servlet.ServletException; +import java.io.IOException; + +import static org.junit.Assert.*; + + +/** + * @author Paul Tuckey + * @version $Revision: 33 $ $Date: 2006-09-12 16:41:56 +1200 (Tue, 12 Sep 2006) $ + */ +public class WebappModStyleHttpIT extends ContainerTestBase { + + protected String getApp() { + return "webapp/mod"; + } + + public void testStatusRecord() throws IOException { + super.recordRewriteStatus(); + } + + public void testSimpleTest() throws ServletException, IOException, SAXException { + GetMethod method = new GetMethod(getBaseUrl() + "/index.jsp"); + method.setFollowRedirects(false); + client.executeMethod(method); + assertEquals("this is index.jsp", method.getResponseBodyAsString()); + } + + public void testSimpleTestRewrite() throws ServletException, IOException, SAXException { + GetMethod method = new GetMethod(getBaseUrl() + "/simple/test"); + method.setFollowRedirects(false); + client.executeMethod(method); + assertEquals("this is index.jsp", method.getResponseBodyAsString()); + } + + public void testStatus1() throws ServletException, IOException, SAXException { + GetMethod method = new GetMethod(getBaseUrl() + "/rewrite-status"); + method.setFollowRedirects(false); + client.executeMethod(method); + assertTrue(method.getResponseBodyAsString().contains("Running Status")); + assertFalse(method.getResponseBodyAsString().contains("Error")); + } + +} From 7eabfb39d49b02f4cddef208d4442bf7c9669533 Mon Sep 17 00:00:00 2001 From: Paul Tuckey Date: Fri, 9 Jun 2023 20:56:12 +1200 Subject: [PATCH 07/19] progress --- .../ContainerTestBase.java | 4 +-- .../WebappDecodeNoneIT.java | 10 +++--- .../WebappDecodeUtf8IT.java | 12 +++++-- .../urlrewriteviacontainer/WebappHttpIT.java | 33 +++++++++++++++---- .../WebappModStyleHttpIT.java | 14 +++++--- 5 files changed, 52 insertions(+), 21 deletions(-) diff --git a/container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/ContainerTestBase.java b/container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/ContainerTestBase.java index 7ffdb3d1..fb382fb2 100644 --- a/container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/ContainerTestBase.java +++ b/container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/ContainerTestBase.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2005-2007, Paul Tuckey + * Copyright (c) 2005-2023, Paul Tuckey * All rights reserved. * ==================================================================== * Licensed under the BSD License. Text as follows. @@ -36,7 +36,6 @@ import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.methods.GetMethod; -import org.junit.jupiter.api.BeforeEach; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.wait.strategy.Wait; import org.testcontainers.junit.jupiter.Container; @@ -67,7 +66,6 @@ public abstract class ContainerTestBase { .withFileSystemBind(webappPath, "/usr/local/tomcat/webapps/webapp.war") .waitingFor(Wait.forHttp("/webapp/test/test.jsp").forStatusCode(200)); - //@BeforeEach public void setUp() throws Exception { container.start(); System.out.println(container.getContainerId()); diff --git a/container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeNoneIT.java b/container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeNoneIT.java index e6652294..93555907 100644 --- a/container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeNoneIT.java +++ b/container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeNoneIT.java @@ -11,8 +11,8 @@ import java.io.IOException; import java.net.URLEncoder; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; /** * @@ -28,7 +28,7 @@ protected String getConf() { } @BeforeEach - public void testSetup() throws Exception { + public void beforeEach() throws Exception { super.setUp(); super.recordRewriteStatus(); } @@ -44,10 +44,11 @@ public void testTestUtf() throws ServletException, IOException { method.setRequestHeader("Accept-Encoding", "utf8"); method.setFollowRedirects(false); client.executeMethod(method); - assertNotNull("no location header", method.getResponseHeader("Location")); + assertNotNull(method.getResponseHeader("Location"), "no location header"); assertEquals(getBaseUrl() + "/utf-redir/done/" + encodedStr + "/", method.getResponseHeader("Location").getValue()); } + @Test public void testNoDecode() throws IOException { if ( "orion2.0.5".equals(getContainerId())) return; // jsp's with % in path not supported if ( "tomcat-4.1.31".equals(getContainerId())) return; // jsp's with % in path not supported @@ -57,6 +58,7 @@ public void testNoDecode() throws IOException { assertEquals("this is no-decode-test target jsp", method.getResponseBodyAsString()); } + @Test public void testQueryStringNoDecode() throws IOException { if ( "orion2.0.5".equals(getContainerId())) return; // orion cannot correctly encode & into %26 diff --git a/container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeUtf8IT.java b/container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeUtf8IT.java index 555d3d33..5ed6e0c9 100644 --- a/container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeUtf8IT.java +++ b/container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeUtf8IT.java @@ -4,10 +4,14 @@ import org.apache.commons.httpclient.methods.GetMethod; import jakarta.servlet.ServletException; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + import java.io.IOException; import java.net.URLEncoder; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; + /** * todo: need to do a few tests @@ -36,14 +40,16 @@ protected String getConf() { return "urlrewrite-decode-utf8.xml"; } - public void testSetup() throws IOException { + @BeforeEach + public void beforeEach() throws Exception { + super.setUp(); super.recordRewriteStatus(); } - /** * */ + @Test public void testTestUtf() throws ServletException, IOException { String utfSampleString = "m\u0101ori"; GetMethod method = new GetMethod(getBaseUrl() + "/utf/" + URLEncoder.encode(utfSampleString, "UTF8") + "/"); diff --git a/container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappHttpIT.java b/container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappHttpIT.java index 58df2c30..0de900b0 100644 --- a/container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappHttpIT.java +++ b/container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappHttpIT.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2005-2007, Paul Tuckey + * Copyright (c) 2005-2023, Paul Tuckey * All rights reserved. * ==================================================================== * Licensed under the BSD License. Text as follows. @@ -34,18 +34,22 @@ */ package org.tuckey.web.filters.urlrewriteviacontainer; +import jakarta.servlet.ServletException; import org.apache.commons.httpclient.Header; import org.apache.commons.httpclient.methods.GetMethod; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.tuckey.web.filters.urlrewrite.utils.StringUtils; import org.xml.sax.SAXException; -import jakarta.servlet.ServletException; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.util.zip.GZIPInputStream; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertFalse; /** @@ -58,10 +62,13 @@ protected String getApp() { return "webapp"; } - public void testStatusRecord() throws IOException { + @BeforeEach + public void beforeEach() throws Exception { + super.setUp(); super.recordRewriteStatus(); } + @Test public void testProduct() throws IOException, SAXException, InterruptedException { GetMethod method = new GetMethod(getBaseUrl() + "/products/987"); client.executeMethod(method); @@ -69,6 +76,7 @@ public void testProduct() throws IOException, SAXException, InterruptedException } + @Test public void testSimpleDistEx() throws ServletException, IOException, SAXException { GetMethod method = new GetMethod(getBaseUrl() + "/test/status/"); method.setFollowRedirects(false); @@ -76,6 +84,7 @@ public void testSimpleDistEx() throws ServletException, IOException, SAXExceptio assertEquals(getBaseUrl() + "/rewrite-status", method.getResponseHeader("Location").getValue()); } + @Test public void testBasicSets() throws ServletException, IOException, SAXException { GetMethod method = new GetMethod(getBaseUrl() + "/settest/674"); client.executeMethod(method); @@ -85,33 +94,38 @@ public void testBasicSets() throws ServletException, IOException, SAXException { "method: DELETE", method.getResponseBodyAsString()); } + @Test public void testMultipleProduct() throws ServletException, IOException, SAXException { GetMethod method = new GetMethod(getBaseUrl() + "/multiple/products/987"); client.executeMethod(method); assertEquals("product 987", method.getResponseBodyAsString()); } + @Test public void testNullTo() throws ServletException, IOException { GetMethod method = new GetMethod(getBaseUrl() + "/hideme/anb.jsp;dsaddd?asdasds#sdsfd"); client.executeMethod(method); - assertEquals("should have status set", 403, method.getStatusCode()); + assertEquals(403, method.getStatusCode()); // "should have status set", String CONTENT = "

some content

"; - assertFalse("should not output above content", CONTENT.equals(StringUtils.trim(method.getResponseBodyAsString()))); + assertFalse(CONTENT.equals(StringUtils.trim(method.getResponseBodyAsString()))); // "should not output above content" } + @Test public void testYear() throws ServletException, IOException { GetMethod method = new GetMethod(getBaseUrl() + "/time/year/current"); client.executeMethod(method); assertEquals("echo yearisbetween1970and3000", method.getResponseBodyAsString()); } + @Test public void testTestAxis() throws ServletException, IOException { GetMethod method = new GetMethod(getBaseUrl() + "/services/blah?qwerty"); method.setFollowRedirects(false); client.executeMethod(method); - assertEquals(getBaseUrl() + "/axis/services/blah", method.getResponseHeader("Location").getValue()); + assertEquals("/" + getApp() + "/axis/services/blah", method.getResponseHeader("Location").getValue()); } + @Test public void testTestErik() throws ServletException, IOException { GetMethod method = new GetMethod(getBaseUrl() + "/eriktest/hi.ho"); method.setFollowRedirects(false); @@ -120,6 +134,7 @@ public void testTestErik() throws ServletException, IOException { assertEquals("http://www.example.com/context/hi.ho", method.getResponseHeader("Location").getValue()); } + @Test public void testTestEncode() throws ServletException, IOException { GetMethod method = new GetMethod(getBaseUrl() + "/went%20to%20bahamas/"); method.setFollowRedirects(false); @@ -127,12 +142,14 @@ public void testTestEncode() throws ServletException, IOException { assertEquals(getBaseUrl() + "/jamaica/", method.getResponseHeader("Location").getValue()); } + @Test public void testSimpleRun() throws ServletException, IOException { GetMethod method = new GetMethod(getBaseUrl() + "/run/test/test1"); client.executeMethod(method); assertEquals("this is " + TestRunObj.class.getName(), method.getResponseBodyAsString()); } + @Test public void testQueryStringEscape() throws IOException { GetMethod method = new GetMethod(getBaseUrl() + "/query-string-escape/jack+%26+jones"); method.setFollowRedirects(false); @@ -140,6 +157,7 @@ public void testQueryStringEscape() throws IOException { assertEquals("http://query-string-escape-result.com/?q=jack%2B%26%2Bjones&another=jack+&+jones", method.getResponseHeader("Location").getValue()); } + @Test public void testGzip() throws IOException { GetMethod method = new GetMethod(getBaseUrl() + "/gzip-me.jsp"); method.addRequestHeader("accept-encoding", "gzip"); @@ -163,6 +181,7 @@ private String inflateGzipToString(InputStream is) throws IOException { return os.toString(); } + @Test public void testSampleAnnotation() throws IOException { GetMethod method = new GetMethod(getBaseUrl() + "/do-something/7"); client.executeMethod(method); diff --git a/container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappModStyleHttpIT.java b/container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappModStyleHttpIT.java index 7d6ea9a3..03aec2b7 100644 --- a/container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappModStyleHttpIT.java +++ b/container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappModStyleHttpIT.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2005-2007, Paul Tuckey + * Copyright (c) 2005-2023, Paul Tuckey * All rights reserved. * ==================================================================== * Licensed under the BSD License. Text as follows. @@ -35,13 +35,14 @@ package org.tuckey.web.filters.urlrewriteviacontainer; import org.apache.commons.httpclient.methods.GetMethod; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.xml.sax.SAXException; import jakarta.servlet.ServletException; import java.io.IOException; -import static org.junit.Assert.*; - +import static org.junit.jupiter.api.Assertions.*; /** * @author Paul Tuckey @@ -53,10 +54,13 @@ protected String getApp() { return "webapp/mod"; } - public void testStatusRecord() throws IOException { + @BeforeEach + public void beforeEach() throws Exception { + super.setUp(); super.recordRewriteStatus(); } + @Test public void testSimpleTest() throws ServletException, IOException, SAXException { GetMethod method = new GetMethod(getBaseUrl() + "/index.jsp"); method.setFollowRedirects(false); @@ -64,6 +68,7 @@ public void testSimpleTest() throws ServletException, IOException, SAXException assertEquals("this is index.jsp", method.getResponseBodyAsString()); } + @Test public void testSimpleTestRewrite() throws ServletException, IOException, SAXException { GetMethod method = new GetMethod(getBaseUrl() + "/simple/test"); method.setFollowRedirects(false); @@ -71,6 +76,7 @@ public void testSimpleTestRewrite() throws ServletException, IOException, SAXExc assertEquals("this is index.jsp", method.getResponseBodyAsString()); } + @Test public void testStatus1() throws ServletException, IOException, SAXException { GetMethod method = new GetMethod(getBaseUrl() + "/rewrite-status"); method.setFollowRedirects(false); From acdeba00109360790675bae7a95887efacab5ecc Mon Sep 17 00:00:00 2001 From: Paul Tuckey Date: Fri, 9 Jun 2023 20:58:17 +1200 Subject: [PATCH 08/19] progress --- container-test/README.md | 13 - .../example-webapp/pom.xml | 0 .../MockRewriteMatch.java | 0 .../urlrewriteviacontainer/TestRunObj.java | 0 .../webapp/WEB-INF/urlrewrite-decode-none.xml | 0 .../webapp/WEB-INF/urlrewrite-decode-utf8.xml | 0 .../src/main/webapp/WEB-INF/urlrewrite.xml | 0 .../src/main/webapp/WEB-INF/web.xml | 0 .../src/main/webapp/echo.jsp | 0 .../src/main/webapp/gzip-me.jsp | 0 .../src/main/webapp/mod/index.jsp | 0 .../main/webapp/no-decode-test-D%25%2cD.jsp | 0 .../src/main/webapp/products.jsp | 0 .../src/main/webapp/settest.jsp | 0 .../src/main/webapp/test/filterRedirector.jsp | 0 .../src/main/webapp/test/test.jsp | 0 container-test/pom.xml | 151 ------ .../MockRewriteMatch.java | 70 --- .../urlrewriteviacontainer/TestRunObj.java | 248 --------- .../webapp/WEB-INF/urlrewrite-decode-none.xml | 28 - .../webapp/WEB-INF/urlrewrite-decode-utf8.xml | 16 - .../src/main/webapp/WEB-INF/web.xml | 65 --- container-test/src/main/webapp/test/test.jsp | 7 - .../ContainerTestBase.java | 100 ---- .../WebappDecodeNoneIT.java | 61 --- .../WebappDecodeUtf8IT.java | 57 -- .../urlrewriteviacontainer/WebappHttpIT.java | 170 ------ .../WebappModStyleHttpIT.java | 80 --- .../test-with-testcontainters/pom.xml | 4 +- .../ContainerTestBase.java | 0 .../WebappDecodeNoneIT.java | 0 .../WebappDecodeUtf8IT.java | 0 .../urlrewriteviacontainer/WebappHttpIT.java | 0 .../WebappModStyleHttpIT.java | 0 .../src/main/webapp/WEB-INF/urlrewrite.xml | 501 ------------------ .../example-webapp/src/main/webapp/echo.jsp | 1 - .../src/main/webapp/gzip-me.jsp | 1 - .../src/main/webapp/mod/index.jsp | 1 - .../main/webapp/no-decode-test-D%25%2cD.jsp | 1 - .../src/main/webapp/products.jsp | 1 - .../src/main/webapp/settest.jsp | 1 - .../src/main/webapp/test/filterRedirector.jsp | 0 42 files changed, 2 insertions(+), 1575 deletions(-) delete mode 100644 container-test/README.md rename {container-test2 => container-test}/example-webapp/pom.xml (100%) rename {container-test2 => container-test}/example-webapp/src/main/java/org/tuckey/web/filters/urlrewriteviacontainer/MockRewriteMatch.java (100%) rename {container-test2 => container-test}/example-webapp/src/main/java/org/tuckey/web/filters/urlrewriteviacontainer/TestRunObj.java (100%) rename {container-test2 => container-test}/example-webapp/src/main/webapp/WEB-INF/urlrewrite-decode-none.xml (100%) rename {container-test2 => container-test}/example-webapp/src/main/webapp/WEB-INF/urlrewrite-decode-utf8.xml (100%) rename container-test/{ => example-webapp}/src/main/webapp/WEB-INF/urlrewrite.xml (100%) rename {container-test2 => container-test}/example-webapp/src/main/webapp/WEB-INF/web.xml (100%) rename container-test/{ => example-webapp}/src/main/webapp/echo.jsp (100%) rename container-test/{ => example-webapp}/src/main/webapp/gzip-me.jsp (100%) rename container-test/{ => example-webapp}/src/main/webapp/mod/index.jsp (100%) rename container-test/{ => example-webapp}/src/main/webapp/no-decode-test-D%25%2cD.jsp (100%) rename container-test/{ => example-webapp}/src/main/webapp/products.jsp (100%) rename container-test/{ => example-webapp}/src/main/webapp/settest.jsp (100%) rename container-test/{ => example-webapp}/src/main/webapp/test/filterRedirector.jsp (100%) rename {container-test2 => container-test}/example-webapp/src/main/webapp/test/test.jsp (100%) delete mode 100644 container-test/pom.xml delete mode 100644 container-test/src/main/java/org/tuckey/web/filters/urlrewriteviacontainer/MockRewriteMatch.java delete mode 100644 container-test/src/main/java/org/tuckey/web/filters/urlrewriteviacontainer/TestRunObj.java delete mode 100644 container-test/src/main/webapp/WEB-INF/urlrewrite-decode-none.xml delete mode 100644 container-test/src/main/webapp/WEB-INF/urlrewrite-decode-utf8.xml delete mode 100644 container-test/src/main/webapp/WEB-INF/web.xml delete mode 100644 container-test/src/main/webapp/test/test.jsp delete mode 100644 container-test/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/ContainerTestBase.java delete mode 100644 container-test/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeNoneIT.java delete mode 100644 container-test/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeUtf8IT.java delete mode 100644 container-test/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappHttpIT.java delete mode 100644 container-test/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappModStyleHttpIT.java rename {container-test2 => container-test}/test-with-testcontainters/pom.xml (96%) rename {container-test2 => container-test}/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/ContainerTestBase.java (100%) rename {container-test2 => container-test}/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeNoneIT.java (100%) rename {container-test2 => container-test}/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeUtf8IT.java (100%) rename {container-test2 => container-test}/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappHttpIT.java (100%) rename {container-test2 => container-test}/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappModStyleHttpIT.java (100%) delete mode 100644 container-test2/example-webapp/src/main/webapp/WEB-INF/urlrewrite.xml delete mode 100644 container-test2/example-webapp/src/main/webapp/echo.jsp delete mode 100644 container-test2/example-webapp/src/main/webapp/gzip-me.jsp delete mode 100644 container-test2/example-webapp/src/main/webapp/mod/index.jsp delete mode 100644 container-test2/example-webapp/src/main/webapp/no-decode-test-D%25%2cD.jsp delete mode 100644 container-test2/example-webapp/src/main/webapp/products.jsp delete mode 100644 container-test2/example-webapp/src/main/webapp/settest.jsp delete mode 100644 container-test2/example-webapp/src/main/webapp/test/filterRedirector.jsp diff --git a/container-test/README.md b/container-test/README.md deleted file mode 100644 index 76c09e25..00000000 --- a/container-test/README.md +++ /dev/null @@ -1,13 +0,0 @@ -# Container Tests - - mvn clean verify org.codehaus.cargo:cargo-maven3-plugin:run - - mvn clean verify org.codehaus.cargo:cargo-maven3-plugin:run \ - -Dcargo.maven.containerId=tomcat9x \ - -Dcargo.maven.containerUrl=https://repo.maven.apache.org/maven2/org/apache/tomcat/tomcat/9.0.45/tomcat-9.0.45.zip - - - mvn clean verify org.codehaus.cargo:cargo-maven3-plugin:run - -Dcargo.maven.containerId=wildfly20x - -Dcargo.maven.containerUrl=https://download.jboss.org/wildfly/20.0.1.Final/wildfly-20.0.1.Final.zip - -Dcargo.servlet.port=9000 \ No newline at end of file diff --git a/container-test2/example-webapp/pom.xml b/container-test/example-webapp/pom.xml similarity index 100% rename from container-test2/example-webapp/pom.xml rename to container-test/example-webapp/pom.xml diff --git a/container-test2/example-webapp/src/main/java/org/tuckey/web/filters/urlrewriteviacontainer/MockRewriteMatch.java b/container-test/example-webapp/src/main/java/org/tuckey/web/filters/urlrewriteviacontainer/MockRewriteMatch.java similarity index 100% rename from container-test2/example-webapp/src/main/java/org/tuckey/web/filters/urlrewriteviacontainer/MockRewriteMatch.java rename to container-test/example-webapp/src/main/java/org/tuckey/web/filters/urlrewriteviacontainer/MockRewriteMatch.java diff --git a/container-test2/example-webapp/src/main/java/org/tuckey/web/filters/urlrewriteviacontainer/TestRunObj.java b/container-test/example-webapp/src/main/java/org/tuckey/web/filters/urlrewriteviacontainer/TestRunObj.java similarity index 100% rename from container-test2/example-webapp/src/main/java/org/tuckey/web/filters/urlrewriteviacontainer/TestRunObj.java rename to container-test/example-webapp/src/main/java/org/tuckey/web/filters/urlrewriteviacontainer/TestRunObj.java diff --git a/container-test2/example-webapp/src/main/webapp/WEB-INF/urlrewrite-decode-none.xml b/container-test/example-webapp/src/main/webapp/WEB-INF/urlrewrite-decode-none.xml similarity index 100% rename from container-test2/example-webapp/src/main/webapp/WEB-INF/urlrewrite-decode-none.xml rename to container-test/example-webapp/src/main/webapp/WEB-INF/urlrewrite-decode-none.xml diff --git a/container-test2/example-webapp/src/main/webapp/WEB-INF/urlrewrite-decode-utf8.xml b/container-test/example-webapp/src/main/webapp/WEB-INF/urlrewrite-decode-utf8.xml similarity index 100% rename from container-test2/example-webapp/src/main/webapp/WEB-INF/urlrewrite-decode-utf8.xml rename to container-test/example-webapp/src/main/webapp/WEB-INF/urlrewrite-decode-utf8.xml diff --git a/container-test/src/main/webapp/WEB-INF/urlrewrite.xml b/container-test/example-webapp/src/main/webapp/WEB-INF/urlrewrite.xml similarity index 100% rename from container-test/src/main/webapp/WEB-INF/urlrewrite.xml rename to container-test/example-webapp/src/main/webapp/WEB-INF/urlrewrite.xml diff --git a/container-test2/example-webapp/src/main/webapp/WEB-INF/web.xml b/container-test/example-webapp/src/main/webapp/WEB-INF/web.xml similarity index 100% rename from container-test2/example-webapp/src/main/webapp/WEB-INF/web.xml rename to container-test/example-webapp/src/main/webapp/WEB-INF/web.xml diff --git a/container-test/src/main/webapp/echo.jsp b/container-test/example-webapp/src/main/webapp/echo.jsp similarity index 100% rename from container-test/src/main/webapp/echo.jsp rename to container-test/example-webapp/src/main/webapp/echo.jsp diff --git a/container-test/src/main/webapp/gzip-me.jsp b/container-test/example-webapp/src/main/webapp/gzip-me.jsp similarity index 100% rename from container-test/src/main/webapp/gzip-me.jsp rename to container-test/example-webapp/src/main/webapp/gzip-me.jsp diff --git a/container-test/src/main/webapp/mod/index.jsp b/container-test/example-webapp/src/main/webapp/mod/index.jsp similarity index 100% rename from container-test/src/main/webapp/mod/index.jsp rename to container-test/example-webapp/src/main/webapp/mod/index.jsp diff --git a/container-test/src/main/webapp/no-decode-test-D%25%2cD.jsp b/container-test/example-webapp/src/main/webapp/no-decode-test-D%25%2cD.jsp similarity index 100% rename from container-test/src/main/webapp/no-decode-test-D%25%2cD.jsp rename to container-test/example-webapp/src/main/webapp/no-decode-test-D%25%2cD.jsp diff --git a/container-test/src/main/webapp/products.jsp b/container-test/example-webapp/src/main/webapp/products.jsp similarity index 100% rename from container-test/src/main/webapp/products.jsp rename to container-test/example-webapp/src/main/webapp/products.jsp diff --git a/container-test/src/main/webapp/settest.jsp b/container-test/example-webapp/src/main/webapp/settest.jsp similarity index 100% rename from container-test/src/main/webapp/settest.jsp rename to container-test/example-webapp/src/main/webapp/settest.jsp diff --git a/container-test/src/main/webapp/test/filterRedirector.jsp b/container-test/example-webapp/src/main/webapp/test/filterRedirector.jsp similarity index 100% rename from container-test/src/main/webapp/test/filterRedirector.jsp rename to container-test/example-webapp/src/main/webapp/test/filterRedirector.jsp diff --git a/container-test2/example-webapp/src/main/webapp/test/test.jsp b/container-test/example-webapp/src/main/webapp/test/test.jsp similarity index 100% rename from container-test2/example-webapp/src/main/webapp/test/test.jsp rename to container-test/example-webapp/src/main/webapp/test/test.jsp diff --git a/container-test/pom.xml b/container-test/pom.xml deleted file mode 100644 index da412149..00000000 --- a/container-test/pom.xml +++ /dev/null @@ -1,151 +0,0 @@ - - - 4.0.0 - org.tuckey - urlrewritefilter-container-test - war - 5.0.0 - UrlRewriteFilter Container Tests - http://www.tuckey.org/urlrewrite/ - 2001 - Integration tests for UrlRewriteFilter - - Paul Tuckey - - - - - BSD - http://www.opensource.org/licenses/bsd-license.php - repo - - - - - - Paul Tuckey - - - - - webapp - - - maven-compiler-plugin - 2.5.1 - - - org.apache.maven.plugins - maven-war-plugin - 3.3.1 - - - - WEB-INF - target - - urlrewrite-generated.xml - - - - - - - org.apache.maven.plugins - maven-failsafe-plugin - 2.12 - - - - integration-test - verify - - - - - - maven-surefire-plugin - 2.12 - - - org.codehaus.cargo - cargo-maven2-plugin - 1.6.5 - - - ${cargo.maven.containerId} - - ${cargo.maven.containerUrl} - - ${project.build.directory}/${cargo.maven.containerId}/out.log - - - ${project.build.directory}/${cargo.maven.containerId} - - - - - - start-container - pre-integration-test - - start - - - - stop-container - post-integration-test - - stop - - - - - - - - - - org.tuckey - urlrewritefilter - 4.0.4 - - - junit - junit - 4.13.2 - test - - - javax.servlet - servlet-api - 2.4 - provided - - - commons-httpclient - commons-httpclient - 3.1 - test - - - - - - - maven-surefire-report-plugin - 2.12 - - - - - - UTF-8 - UTF-8 - 1.7 - 1.7 - - - \ No newline at end of file diff --git a/container-test/src/main/java/org/tuckey/web/filters/urlrewriteviacontainer/MockRewriteMatch.java b/container-test/src/main/java/org/tuckey/web/filters/urlrewriteviacontainer/MockRewriteMatch.java deleted file mode 100644 index 6bf52551..00000000 --- a/container-test/src/main/java/org/tuckey/web/filters/urlrewriteviacontainer/MockRewriteMatch.java +++ /dev/null @@ -1,70 +0,0 @@ -/** - * Copyright (c) 2005-2007, Paul Tuckey - * All rights reserved. - * ==================================================================== - * Licensed under the BSD License. Text as follows. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * - Neither the name tuckey.org nor the names of its contributors - * may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * ==================================================================== - */ -package org.tuckey.web.filters.urlrewriteviacontainer; - -import org.tuckey.web.filters.urlrewrite.extend.RewriteMatch; - -import jakarta.servlet.ServletException; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; -import java.io.IOException; - - -/** - * Mock RewriteMatch that can be used for testing. Included here and not in test folder as it needs to be deployed with - * the main library. - * - * @author Paul Tuckey - * @version $Revision: 33 $ $Date: 2006-09-12 16:41:56 +1200 (Tue, 12 Sep 2006) $ - */ -public class MockRewriteMatch extends RewriteMatch { - - private static long calledTime = 0; - - public boolean execute(HttpServletRequest request, HttpServletResponse response) - throws ServletException, IOException { - calledTime = System.currentTimeMillis(); - try { - Thread.sleep(10); - } catch (InterruptedException e) { - // don't worry - } - return true; - } - - public static long getCalledTime() { - return calledTime; - } -} diff --git a/container-test/src/main/java/org/tuckey/web/filters/urlrewriteviacontainer/TestRunObj.java b/container-test/src/main/java/org/tuckey/web/filters/urlrewriteviacontainer/TestRunObj.java deleted file mode 100644 index 9085af9e..00000000 --- a/container-test/src/main/java/org/tuckey/web/filters/urlrewriteviacontainer/TestRunObj.java +++ /dev/null @@ -1,248 +0,0 @@ -/** - * Copyright (c) 2005-2007, Paul Tuckey - * All rights reserved. - * ==================================================================== - * Licensed under the BSD License. Text as follows. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * - Neither the name tuckey.org nor the names of its contributors - * may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * ==================================================================== - */ -package org.tuckey.web.filters.urlrewriteviacontainer; - -import org.tuckey.web.filters.urlrewrite.extend.RewriteMatch; - -import jakarta.servlet.FilterChain; -import jakarta.servlet.ServletConfig; -import jakarta.servlet.ServletException; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; -import java.io.IOException; -import java.io.PrintWriter; - -/** - * RunObject that can be used for testing. Included here and not in test folder as it needs to be deployed with the - * main library. - * - * @author Paul Tuckey - * @version $Revision: 33 $ $Date: 2006-09-12 16:41:56 +1200 (Tue, 12 Sep 2006) $ - */ -public class TestRunObj { - private static boolean runCalled; - private static boolean destroyCalled; - private static boolean initCalled; - private static boolean nonDefaultRunCalled; - private static ServletConfig servletConfig; - - private static int createdCount = 0; - private static String paramStr = null; - private static long runWithChainParamAfterDoFilter = 0; - - public TestRunObj() { - createdCount++; - } - - public void run(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) - throws ServletException, IOException { - runCalled = true; - - PrintWriter sos = httpServletResponse.getWriter(); - if (sos == null) return; - sos.print("this is " + TestRunObj.class.getName()); - sos.close(); - } - - - public MockRewriteMatch runWithReturnedObj(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) - throws ServletException, IOException { - return new MockRewriteMatch(); - } - - public void nonDefaultRun(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) - throws ServletException, IOException { - nonDefaultRunCalled = true; - } - - public String runThatReturns(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) - throws ServletException, IOException { - return "aaabbb"; - } - - public String runWithParam(int i) - throws ServletException, IOException { - paramStr = "" + i; - return paramStr; - } - - public String runWithNoParams() - throws ServletException, IOException { - paramStr = "[no params]"; - return paramStr; - } - - public String runWithChainParam(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, FilterChain c) - throws ServletException, IOException { - paramStr = "" + c; - c.doFilter(httpServletRequest, httpServletResponse); - try { - Thread.sleep(10); - } catch (InterruptedException e) { - // - } - runWithChainParamAfterDoFilter = System.currentTimeMillis(); - return paramStr; - } - - public static long getRunWithChainParamAfterDoFilter() { - return runWithChainParamAfterDoFilter; - } - - public String runWithPrimitiveParam(int i, char c, double d, float f, short s, byte b, boolean b2, String s2) - throws ServletException, IOException { - paramStr = i + "," + c + "," + d + "," + f + "," + s + "," + b + "," + b2 + "," + s2; - return paramStr; - } - - public String runWithObjParam(Integer i, Character c, Double d, Float f, Short s, Byte b, Boolean b2, String s2) - throws ServletException, IOException { - paramStr = i + "," + c + "," + d + "," + f + "," + s + "," + b + "," + b2 + "," + s2; - return paramStr; - } - - public static String getParamStr() { - return paramStr; - } - - public void runNullPointerException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) - throws ServletException, IOException { - exceptionGenerator.doNullPointer(); - } - - public void runRuntiumeException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) - throws ServletException, IOException { - exceptionGenerator.doRuntime(); - } - - public void runServletException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) - throws ServletException, IOException { - exceptionGenerator.doServlet(); - } - - public void runIOException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) - throws ServletException, IOException { - exceptionGenerator.doIO(); - } - - public void runCustomException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) - throws TestExceptionGenerator.CustomException { - exceptionGenerator.doCustom(); - } - - TestExceptionGenerator exceptionGenerator = new TestExceptionGenerator(); - - private class TestExceptionGenerator { - public void doNullPointer() { - String aaa = null; - // YES we WANT a null pointer here - aaa.toLowerCase(); - } - - public void doRuntime() { - throw new RuntimeException("shit!"); - } - - public void doServlet() throws ServletException { - throw new ServletException("serv"); - } - - public void doIO() throws IOException { - throw new IOException("me i.o. has gone crazy"); - } - - public void doCustom() throws CustomException { - throw new CustomException(); - } - - public class CustomException extends Exception { - - } - } - - public RewriteMatch trialException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, - ClassNotFoundException e) { - return new MockRewriteMatch(); - } - - /** - * Do not delete! used in RunTest. - */ - private void privateRun(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) { - // do nothing - } - - public void destroy() { - destroyCalled = true; - } - - public void init(ServletConfig config) throws ServletException { - servletConfig = config; - initCalled = true; - } - - public static boolean isRunCalled() { - return runCalled; - } - - public static int getCreatedCount() { - return createdCount; - } - - public static void resetTestFlags() { - createdCount = 0; - runCalled = false; - destroyCalled = false; - initCalled = false; - nonDefaultRunCalled = false; - servletConfig = null; - } - - public static ServletConfig getTestServletConfig() { - return servletConfig; - } - - public static boolean isDestroyCalled() { - return destroyCalled; - } - - public static boolean isInitCalled() { - return initCalled; - } - - public static boolean isNonDefaultRunCalled() { - return nonDefaultRunCalled; - } -} diff --git a/container-test/src/main/webapp/WEB-INF/urlrewrite-decode-none.xml b/container-test/src/main/webapp/WEB-INF/urlrewrite-decode-none.xml deleted file mode 100644 index 9bdfb77d..00000000 --- a/container-test/src/main/webapp/WEB-INF/urlrewrite-decode-none.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - utf test - /utf/(m%C4%81ori)/ - %{context-path}/utf-redir/done/$1/ - - - - Proxy - ^/no-decode-test/(.*)$ - /no-decode-test-$1.jsp - - - - ^/query-string-no-decode/(.*)$ - http://query-string-no-decode-result.com/?q=$1&another=${unescape:$1} - - - \ No newline at end of file diff --git a/container-test/src/main/webapp/WEB-INF/urlrewrite-decode-utf8.xml b/container-test/src/main/webapp/WEB-INF/urlrewrite-decode-utf8.xml deleted file mode 100644 index 3fa2bb82..00000000 --- a/container-test/src/main/webapp/WEB-INF/urlrewrite-decode-utf8.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - utf test - ^/utf/māori/$ - %{context-path}/utf-redir/done/ - - - \ No newline at end of file diff --git a/container-test/src/main/webapp/WEB-INF/web.xml b/container-test/src/main/webapp/WEB-INF/web.xml deleted file mode 100644 index 5d57210c..00000000 --- a/container-test/src/main/webapp/WEB-INF/web.xml +++ /dev/null @@ -1,65 +0,0 @@ - - - - - - - test - test context - - - UrlRewriteFilter - org.tuckey.web.filters.urlrewrite.UrlRewriteFilter - - logLevel - debug - - - allowConfSwapViaHttp - true - - - - - UrlRewriteFilter-mod - org.tuckey.web.filters.urlrewrite.UrlRewriteFilter - - logLevel - debug - - - statusPath - /mod/rewrite-status - - - modRewriteConfText - - - - - - - UrlRewriteFilter-mod - /mod/* - - - - UrlRewriteFilter - /* - - - - - - - - - - diff --git a/container-test/src/main/webapp/test/test.jsp b/container-test/src/main/webapp/test/test.jsp deleted file mode 100644 index 543a0b47..00000000 --- a/container-test/src/main/webapp/test/test.jsp +++ /dev/null @@ -1,7 +0,0 @@ -<%-- Test JSP used by the TestServletTestCase test class to test --%> -<%-- RequestDispatcher call. --%> - - - Hello ! - - \ No newline at end of file diff --git a/container-test/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/ContainerTestBase.java b/container-test/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/ContainerTestBase.java deleted file mode 100644 index 1ec6c14e..00000000 --- a/container-test/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/ContainerTestBase.java +++ /dev/null @@ -1,100 +0,0 @@ -/** - * Copyright (c) 2005-2007, Paul Tuckey - * All rights reserved. - * ==================================================================== - * Licensed under the BSD License. Text as follows. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * - Neither the name tuckey.org nor the names of its contributors - * may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * ==================================================================== - */ -package org.tuckey.web.filters.urlrewriteviacontainer; - -import junit.framework.TestCase; -import org.apache.commons.httpclient.HttpClient; -import org.apache.commons.httpclient.methods.GetMethod; - -import java.io.File; -import java.io.IOException; -import java.io.PrintWriter; - - -public abstract class ContainerTestBase extends TestCase { - - private String baseUrl = "http://127.0.0.1:8080"; - protected HttpClient client = new HttpClient(); - private File systemPropBaseReportsDir = new File("container-test", "reports"); - private String containerId = "test"; - - protected void setUp() throws Exception { - String containerId = System.getProperty("test.container.id"); - if (containerId != null) { - this.containerId = containerId; - } - String systemPropBaseUrl = System.getProperty("test.base.url"); - if (systemPropBaseUrl != null) { - baseUrl = systemPropBaseUrl; - } - String systemPropBaseReports = System.getProperty("test.base.reports"); - if (systemPropBaseReports != null) { - systemPropBaseReportsDir = new File(systemPropBaseReports); - } - System.err.println("systemPropBaseReportsDir: " + systemPropBaseReportsDir); - - GetMethod method = new GetMethod(getBaseUrl() + "/rewrite-status/?conf=/WEB-INF/" + getConf()); - client.executeMethod(method); - super.setUp(); - } - - protected String getBaseUrl() { - return baseUrl + "/" + getApp(); - } - - protected void recordRewriteStatus() throws IOException { - GetMethod method = new GetMethod(baseUrl + "/" + getApp() + "/rewrite-status"); - method.setFollowRedirects(false); - client.executeMethod(method); - File statusFile = new File(containerId + "-" + getApp() + "-" + getConf() + "-rewrite-status.html"); - //noinspection ResultOfMethodCallIgnored - if ( statusFile.canWrite() && statusFile.createNewFile() ) { // some containers don't let us do this - PrintWriter pw = new PrintWriter(statusFile); - pw.print(method.getResponseBodyAsString()); - pw.close(); - System.out.println("status saved to " + statusFile.getAbsolutePath()); - } - } - - abstract protected String getApp(); - - protected String getConf() { - return "urlrewrite.xml"; - } - - public String getContainerId() { - return containerId; - } -} diff --git a/container-test/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeNoneIT.java b/container-test/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeNoneIT.java deleted file mode 100644 index 1e21e10e..00000000 --- a/container-test/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeNoneIT.java +++ /dev/null @@ -1,61 +0,0 @@ -package org.tuckey.web.filters.urlrewriteviacontainer; - - -import org.apache.commons.httpclient.methods.GetMethod; - -import jakarta.servlet.ServletException; -import java.io.IOException; -import java.net.URLEncoder; - -/** - * - */ -public class WebappDecodeNoneIT extends ContainerTestBase { - - protected String getApp() { - return "webapp"; - } - - protected String getConf() { - return "urlrewrite-decode-none.xml"; - } - - public void testSetup() throws IOException { - super.recordRewriteStatus(); - } - - - /** - * note, had trouble keeping true utf (multi byte) chars as cvs buggers them up! - */ - public void testTestUtf() throws ServletException, IOException { - if ( "orion2.0.5".equals(getContainerId())) return; // orion not supported - String encodedStr = URLEncoder.encode("m\u0101ori", "UTF8"); - GetMethod method = new GetMethod(getBaseUrl() + "/utf/" + encodedStr + "/"); - method.setRequestHeader("Accept-Encoding", "utf8"); - method.setFollowRedirects(false); - client.executeMethod(method); - assertNotNull("no location header", method.getResponseHeader("Location")); - assertEquals(getBaseUrl() + "/utf-redir/done/" + encodedStr + "/", method.getResponseHeader("Location").getValue()); - } - - public void testNoDecode() throws IOException { - if ( "orion2.0.5".equals(getContainerId())) return; // jsp's with % in path not supported - if ( "tomcat-4.1.31".equals(getContainerId())) return; // jsp's with % in path not supported - - GetMethod method = new GetMethod(getBaseUrl() + "/no-decode-test/D%25%2cD"); - client.executeMethod(method); - assertEquals("this is no-decode-test target jsp", method.getResponseBodyAsString()); - } - - public void testQueryStringNoDecode() throws IOException { - if ( "orion2.0.5".equals(getContainerId())) return; // orion cannot correctly encode & into %26 - - GetMethod method = new GetMethod(getBaseUrl() + "/query-string-no-decode/jack+%26+jones"); - method.setFollowRedirects(false); - client.executeMethod(method); - assertEquals("http://query-string-no-decode-result.com/?q=jack+%26+jones&another=jack & jones", method.getResponseHeader("Location").getValue()); - } - - -} \ No newline at end of file diff --git a/container-test/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeUtf8IT.java b/container-test/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeUtf8IT.java deleted file mode 100644 index acf56ffd..00000000 --- a/container-test/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeUtf8IT.java +++ /dev/null @@ -1,57 +0,0 @@ -package org.tuckey.web.filters.urlrewriteviacontainer; - - -import org.apache.commons.httpclient.methods.GetMethod; - -import jakarta.servlet.ServletException; -import java.io.IOException; -import java.net.URLEncoder; - -/** - * todo: need to do a few tests - *

- * with eocode-using not set (ie, browser encoding used, step down to utf8) - * with eocode-using set to utf (force always with a specific decoding) - * with eocode-using not set to null (never decode) - * accept-encoding header? - *

- *

- * don't decode anything - null - * browser then utf then default - default browser,utf - * browser then don't decode - default browser,null - * always utf - utf - *

- *

- * options: browser (may fail), enc (unlikely fail) - */ -public class WebappDecodeUtf8IT extends ContainerTestBase { - - protected String getApp() { - return "webapp"; - } - - protected String getConf() { - return "urlrewrite-decode-utf8.xml"; - } - - public void testSetup() throws IOException { - super.recordRewriteStatus(); - } - - - /** - * - */ - public void testTestUtf() throws ServletException, IOException { - String utfSampleString = "m\u0101ori"; - GetMethod method = new GetMethod(getBaseUrl() + "/utf/" + URLEncoder.encode(utfSampleString, "UTF8") + "/"); - method.setRequestHeader("Accept-Encoding", "utf8"); - method.setFollowRedirects(false); - client.executeMethod(method); - assertEquals(getBaseUrl() + "/utf-redir/done/", method.getResponseHeader("Location").getValue()); - } - - - - -} diff --git a/container-test/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappHttpIT.java b/container-test/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappHttpIT.java deleted file mode 100644 index 668c7092..00000000 --- a/container-test/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappHttpIT.java +++ /dev/null @@ -1,170 +0,0 @@ -/** - * Copyright (c) 2005-2007, Paul Tuckey - * All rights reserved. - * ==================================================================== - * Licensed under the BSD License. Text as follows. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * - Neither the name tuckey.org nor the names of its contributors - * may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * ==================================================================== - */ -package org.tuckey.web.filters.urlrewriteviacontainer; - -import org.apache.commons.httpclient.Header; -import org.apache.commons.httpclient.methods.GetMethod; -import org.tuckey.web.filters.urlrewrite.utils.StringUtils; -import org.xml.sax.SAXException; - -import jakarta.servlet.ServletException; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.zip.GZIPInputStream; - - -/** - * @author Paul Tuckey - * @version $Revision: 33 $ $Date: 2006-09-12 16:41:56 +1200 (Tue, 12 Sep 2006) $ - */ -public class WebappHttpIT extends ContainerTestBase { - - protected String getApp() { - return "webapp"; - } - - public void testStatusRecord() throws IOException { - super.recordRewriteStatus(); - } - - public void testProduct() throws IOException, SAXException, InterruptedException { - GetMethod method = new GetMethod(getBaseUrl() + "/products/987"); - client.executeMethod(method); - assertEquals("product 987", method.getResponseBodyAsString()); - } - - - public void testSimpleDistEx() throws ServletException, IOException, SAXException { - GetMethod method = new GetMethod(getBaseUrl() + "/test/status/"); - method.setFollowRedirects(false); - client.executeMethod(method); - assertEquals(getBaseUrl() + "/rewrite-status", method.getResponseHeader("Location").getValue()); - } - - public void testBasicSets() throws ServletException, IOException, SAXException { - GetMethod method = new GetMethod(getBaseUrl() + "/settest/674"); - client.executeMethod(method); - assertNotNull(method.getResponseHeader("cache-control")); - assertEquals("testsession: hello!, " + - "param.settest1: 674, " + - "method: DELETE", method.getResponseBodyAsString()); - } - - public void testMultipleProduct() throws ServletException, IOException, SAXException { - GetMethod method = new GetMethod(getBaseUrl() + "/multiple/products/987"); - client.executeMethod(method); - assertEquals("product 987", method.getResponseBodyAsString()); - } - - public void testNullTo() throws ServletException, IOException { - GetMethod method = new GetMethod(getBaseUrl() + "/hideme/anb.jsp;dsaddd?asdasds#sdsfd"); - client.executeMethod(method); - assertEquals("should have status set", 403, method.getStatusCode()); - String CONTENT = "

some content

"; - assertFalse("should not output above content", CONTENT.equals(StringUtils.trim(method.getResponseBodyAsString()))); - } - - public void testYear() throws ServletException, IOException { - GetMethod method = new GetMethod(getBaseUrl() + "/time/year/current"); - client.executeMethod(method); - assertEquals("echo yearisbetween1970and3000", method.getResponseBodyAsString()); - } - - public void testTestAxis() throws ServletException, IOException { - GetMethod method = new GetMethod(getBaseUrl() + "/services/blah?qwerty"); - method.setFollowRedirects(false); - client.executeMethod(method); - assertEquals(getBaseUrl() + "/axis/services/blah", method.getResponseHeader("Location").getValue()); - } - - public void testTestErik() throws ServletException, IOException { - GetMethod method = new GetMethod(getBaseUrl() + "/eriktest/hi.ho"); - method.setFollowRedirects(false); - method.addRequestHeader(new Header("host", "blah.com")); - client.executeMethod(method); - assertEquals("http://www.example.com/context/hi.ho", method.getResponseHeader("Location").getValue()); - } - - public void testTestEncode() throws ServletException, IOException { - GetMethod method = new GetMethod(getBaseUrl() + "/went%20to%20bahamas/"); - method.setFollowRedirects(false); - client.executeMethod(method); - assertEquals(getBaseUrl() + "/jamaica/", method.getResponseHeader("Location").getValue()); - } - - public void testSimpleRun() throws ServletException, IOException { - GetMethod method = new GetMethod(getBaseUrl() + "/run/test/test1"); - client.executeMethod(method); - assertEquals("this is " + TestRunObj.class.getName(), method.getResponseBodyAsString()); - } - - public void testQueryStringEscape() throws IOException { - GetMethod method = new GetMethod(getBaseUrl() + "/query-string-escape/jack+%26+jones"); - method.setFollowRedirects(false); - client.executeMethod(method); - assertEquals("http://query-string-escape-result.com/?q=jack%2B%26%2Bjones&another=jack+&+jones", method.getResponseHeader("Location").getValue()); - } - - public void testGzip() throws IOException { - GetMethod method = new GetMethod(getBaseUrl() + "/gzip-me.jsp"); - method.addRequestHeader("accept-encoding", "gzip"); - client.executeMethod(method); - assertEquals("gzip", method.getResponseHeader("Content-Encoding").getValue()); - assertEquals("hello world hello world hello world", inflateGzipToString(method.getResponseBodyAsStream())); - } - - /** - * inflate a gzipped inputstream and return it as a string. - */ - private String inflateGzipToString(InputStream is) throws IOException { - GZIPInputStream gis = new GZIPInputStream(is); - ByteArrayOutputStream os = new ByteArrayOutputStream(); - byte[] buffer = new byte[1024]; - while (true) { - int bytesRead = gis.read(buffer); - if (bytesRead == -1) break; - os.write(buffer, 0, bytesRead); - } - return os.toString(); - } - - public void testSampleAnnotation() throws IOException { - GetMethod method = new GetMethod(getBaseUrl() + "/do-something/7"); - client.executeMethod(method); - assertEquals(method.getResponseBodyAsString(), "AnnotatedClassSample id=7"); - } - -} diff --git a/container-test/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappModStyleHttpIT.java b/container-test/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappModStyleHttpIT.java deleted file mode 100644 index 4f6401af..00000000 --- a/container-test/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappModStyleHttpIT.java +++ /dev/null @@ -1,80 +0,0 @@ -/** - * Copyright (c) 2005-2007, Paul Tuckey - * All rights reserved. - * ==================================================================== - * Licensed under the BSD License. Text as follows. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * - Neither the name tuckey.org nor the names of its contributors - * may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * ==================================================================== - */ -package org.tuckey.web.filters.urlrewriteviacontainer; - -import org.apache.commons.httpclient.methods.GetMethod; -import org.xml.sax.SAXException; - -import jakarta.servlet.ServletException; -import java.io.IOException; - - -/** - * @author Paul Tuckey - * @version $Revision: 33 $ $Date: 2006-09-12 16:41:56 +1200 (Tue, 12 Sep 2006) $ - */ -public class WebappModStyleHttpIT extends ContainerTestBase { - - protected String getApp() { - return "webapp/mod"; - } - - public void testStatusRecord() throws IOException { - super.recordRewriteStatus(); - } - - public void testSimpleTest() throws ServletException, IOException, SAXException { - GetMethod method = new GetMethod(getBaseUrl() + "/index.jsp"); - method.setFollowRedirects(false); - client.executeMethod(method); - assertEquals("this is index.jsp", method.getResponseBodyAsString()); - } - - public void testSimpleTestRewrite() throws ServletException, IOException, SAXException { - GetMethod method = new GetMethod(getBaseUrl() + "/simple/test"); - method.setFollowRedirects(false); - client.executeMethod(method); - assertEquals("this is index.jsp", method.getResponseBodyAsString()); - } - - public void testStatus1() throws ServletException, IOException, SAXException { - GetMethod method = new GetMethod(getBaseUrl() + "/rewrite-status"); - method.setFollowRedirects(false); - client.executeMethod(method); - assertTrue(method.getResponseBodyAsString().contains("Running Status")); - assertFalse(method.getResponseBodyAsString().contains("Error")); - } - -} diff --git a/container-test2/test-with-testcontainters/pom.xml b/container-test/test-with-testcontainters/pom.xml similarity index 96% rename from container-test2/test-with-testcontainters/pom.xml rename to container-test/test-with-testcontainters/pom.xml index e2afa6bf..0b39ec5b 100644 --- a/container-test2/test-with-testcontainters/pom.xml +++ b/container-test/test-with-testcontainters/pom.xml @@ -2,14 +2,14 @@ 4.0.0 org.tuckey - urlrewritefilter-container-test2 + urlrewritefilter-container-test jar 17 17 6.0.0 - UrlRewriteFilter Container Tests2 + UrlRewriteFilter Container Tests http://www.tuckey.org/urlrewrite/ 2001 Integration tests for UrlRewriteFilter diff --git a/container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/ContainerTestBase.java b/container-test/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/ContainerTestBase.java similarity index 100% rename from container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/ContainerTestBase.java rename to container-test/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/ContainerTestBase.java diff --git a/container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeNoneIT.java b/container-test/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeNoneIT.java similarity index 100% rename from container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeNoneIT.java rename to container-test/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeNoneIT.java diff --git a/container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeUtf8IT.java b/container-test/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeUtf8IT.java similarity index 100% rename from container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeUtf8IT.java rename to container-test/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeUtf8IT.java diff --git a/container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappHttpIT.java b/container-test/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappHttpIT.java similarity index 100% rename from container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappHttpIT.java rename to container-test/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappHttpIT.java diff --git a/container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappModStyleHttpIT.java b/container-test/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappModStyleHttpIT.java similarity index 100% rename from container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappModStyleHttpIT.java rename to container-test/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappModStyleHttpIT.java diff --git a/container-test2/example-webapp/src/main/webapp/WEB-INF/urlrewrite.xml b/container-test2/example-webapp/src/main/webapp/WEB-INF/urlrewrite.xml deleted file mode 100644 index dfcff1da..00000000 --- a/container-test2/example-webapp/src/main/webapp/WEB-INF/urlrewrite.xml +++ /dev/null @@ -1,501 +0,0 @@ - - - - - - - - - The rule means that requests to /test/status/ will be redirected to /rewrite-status - the url will be rewritten. - - /test/status/ - %{context-path}/rewrite-status - - - - /spelling/([a-z]+) - /spelling/index.jsp?spell=$1 - - - - gEt - /get/ - /getty/lotsofgetty/ - - - - /products/([0-9]+) - /products.jsp?product_id=$1 - - - - /multiple/products/([0-9]+) - /multiple/products.jsp?product_id=$1 - - - - /multiple/(.*) - /$1 - - - - ^/settest/([0-9]+)$ - hello! - none-fool - $1 - DELETE - /settest.jsp - - - - - http method test - - PROPFIND - PUT - /.* - /go-away-nasty-methods.html - - - - 1970 - 2020 - /time/year/current - /echo.jsp?echo=yearisbetween1970and3000 - - - - ^/services/(.*) - %{context-path}/axis/services/$1 - - - - ^/weblog/([0-9]+)/([0-9]+)/$ - /weblog/index.jsp?year=$1&month=$2 - - - - Domain Name Check - www.example.com - /eriktest(.*) - http://www.example.com/context$1 - - - - 403 null Check - ^/hideme/.*$ - 403 - null - - - - encode test - /went to bahamas/ - %{context-path}/bahamas/ - - - - Bad referers test - - - Prevent vermin from appearing in your logs by denying nasty referers - - - ^http://www\.badguys\.com/.*$ - /(.*) - 403 - null - - - - - admin - bigboss - ^/admin/(.*)$ - /go-away-please.html - - - - - Simple Run Test - ^/run/test/(.*)$ - - null - - - - - - - - - - - - - Canonical URLs - - On some webservers there are more than one URL for a resource. Usually there are canonical URLs (which - should be actually used and distributed) and those which are just shortcuts, internal ones, etc. Independent - of which URL the user supplied with the request he should finally see the canonical one only. - - We do an external HTTP redirect for all non-canonical URLs to fix them in the location view of the Browser - and for all subsequent requests. In the example ruleset below we replace /~user by the canonical /u/user and - fix a missing trailing slash for /u/user. - - RewriteRule ^/~([^/]+)/?(.*) /u/$1/$2 [R] - RewriteRule ^/([uge])/([^/]+)$ /$1/$2/ [R] - - ^/~([^/]+)/?(.*) - /u/$1/$2 - - - ^/([uge])/([^/]+)$ - /$1/$2/ - - - - - Canonical Hostnames - - The goal of this rule is to force the use of a particular hostname, in preference to other hostnames which - may be used to reach the same site. For example, if you wish to force the use of www.example.com instead of - example.com, you might use a variant of the following recipe. - - RewriteCond %{HTTP_HOST} !^fully\.qualified\.domain\.name [NC] - RewriteCond %{HTTP_HOST} !^$ - RewriteRule ^/(.*) http://fully.qualified.domain.name/$1 [L,R] - - !^fully\.qualified\.domain\.name - ^$ - ^/(.*) - http://fully.qualified.domain.name/$1 - - - - - Moved DocumentRoot - - Usually the DocumentRoot of the webserver directly relates to the URL "/". But often this data is not - really of top-level priority, it is perhaps just one entity of a lot of data pools. For instance at our - Intranet sites there are /e/www/ (the homepage for WWW), /e/sww/ (the homepage for the Intranet) etc. Now - because the data of the DocumentRoot stays at /e/www/ we had to make sure that all inlined images and other - stuff inside this data pool work for subsequent requests. - - We just redirect the URL / to /e/www/. While is seems trivial it is actually trivial with mod_rewrite, only. - Because the typical old mechanisms of URL Aliases (as provides by mod_alias and friends) only used prefix - matching. With this you cannot do such a redirection because the DocumentRoot is a prefix of all URLs. - With mod_rewrite it is really trivial: - - RewriteRule ^/$ /e/www/ [R] - - ^/$ - /e/www/ - - - - - Trailing Slash Problem - - Every webmaster can sing a song about the problem of the trailing slash on URLs referencing directories. - If they are missing, the server dumps an error, because if you say /~quux/foo instead of /~quux/foo/ then - the server searches for a file named foo. And because this file is a directory it complains. Actually it - tries to fix it itself in most of the cases, but sometimes this mechanism need to be emulated by you. For - instance after you have done a lot of complicated URL rewritings to CGI scripts etc. - - The solution to this subtle problem is to let the server add the trailing slash automatically. To do this - correctly we have to use an external redirect, so the browser correctly requests subsequent images etc. If - we only did a internal rewrite, this would only work for the directory page, but would go wrong when any - images are included into this page with relative URLs, because the browser would request an in-lined object. - For instance, a request for image.gif in /~quux/foo/index.html would become /~quux/image.gif without the - external redirect! - - ^/~quux/foo$ - /~quux/foo/ - - - - - Move Homedirs to Different Webserver - - Many webmasters have asked for a solution to the following situation: They wanted to redirect just all - homedirs on a webserver to another webserver. They usually need such things when establishing a newer - webserver which will replace the old one over time. - - The solution is trivial with mod_rewrite (and urlrewrite filter). On the old webserver we just redirect all - /~user/anypath URLs to http://newserver/~user/anypath. - - RewriteRule ^/~(.+) http://newserver/~$1 [R,L] - - ^/~(.+) - http://newserver/~$1 - - - - - Structured Homedirs - - Some sites with thousands of users usually use a structured homedir layout, i.e. each homedir is in a - subdirectory which begins for instance with the first character of the username. So, /~foo/anypath is - /home/f/foo/.www/anypath while /~bar/anypath is /home/b/bar/.www/anypath. - - We use the following ruleset to expand the tilde URLs into exactly the above layout. - - RewriteRule ^/~(([a-z])[a-z0-9]+)(.*) /home/$2/$1/.www$3 - - ^/~(([a-z])[a-z0-9]+)(.*) - /home/$2/$1/.www$3 - - - - - Redirect Homedirs For Foreigners - - We want to redirect homedir URLs to another webserver www.somewhere.com when the requesting user does not - stay in the local domain ourdomain.com. This is sometimes used in virtual host contexts. - - Just a rewrite condition: - - RewriteCond %{REMOTE_HOST} !^.+\.ourdomain\.com$ - RewriteRule ^(/~.+) http://www.somewhere.com/$1 [R,L] - - !^.+\.ourdomain\.com$ - ^(/~.+) - http://www.somewhere.com/$1 - - - - - Time-Dependent Rewriting - - When tricks like time-dependent content should happen a lot of webmasters still use CGI scripts which do for - instance redirects to specialized pages. How can it be done via mod_rewrite? - - There are a lot of types in conjunction with operators we can do time-dependent redirects: - - RewriteCond %{TIME_HOUR}%{TIME_MIN} >0700 - RewriteCond %{TIME_HOUR}%{TIME_MIN} <1900 - RewriteRule ^foo\.html$ foo.day.html - RewriteRule ^foo\.html$ foo.night.html - - 7 - 19 - ^foo\.html$ - foo.day.html - - - ^foo\.html$ - foo.night.html - - - - - - - Assume we have recently renamed the page foo.html to bar.html and now want to provide the old URL for - backward compatibility. Actually we want that users of the old URL even not recognize that the pages was - renamed. - - We rewrite the old URL to the new one internally via the following rule: - - RewriteBase /~quux/ - RewriteRule ^foo\.html$ bar.html - - ^/~quux/foo\.html$ - /~quux/bar.html - - - - - From Old to New (extern) - - Assume again that we have recently renamed the page foo.html to bar.html and now want to provide the old URL - for backward compatibility. But this time we want that the users of the old URL get hinted to the new one, - i.e. their browsers Location field should change, too. - - We force a HTTP redirect to the new URL which leads to a change of the browsers and thus the users view: - - RewriteBase /~quux/ - RewriteRule ^foo\.html$ bar.html [R] - - ^/~quux/foo\.html$ - /~quux/bar.html - - - - - Browser Dependent Content - - At least for important top-level pages it is sometimes necessary to provide the optimum of browser dependent - content, i.e. one has to provide a maximum version for the latest Netscape variants, a minimum version for - the Lynx browsers and a average feature version for all others. - - We cannot use content negotiation because the browsers do not provide their type in that form. Instead we - have to act on the HTTP header "User-Agent". The following condig does the following: If the HTTP header - "User-Agent" begins with "Mozilla/3", the page foo.html is rewritten to foo.NS.html and and the rewriting - stops. If the browser is "Lynx" or "Mozilla" of version 1 or 2 the URL becomes foo.20.html. All other - browsers receive page foo.32.html. This is done by the following ruleset: - - RewriteCond %{HTTP_USER_AGENT} ^Mozilla/3.* - RewriteRule ^foo\.html$ foo.NS.html [L] - - RewriteCond %{HTTP_USER_AGENT} ^Lynx/.* [OR] - RewriteCond %{HTTP_USER_AGENT} ^Mozilla/[12].* - RewriteRule ^foo\.html$ foo.20.html [L] - - RewriteRule ^foo\.html$ foo.32.html [L] - - ^Mozilla/3.* - ^foo\.html$ - foo.NS.html - - - ^Lynx/.* - ^Mozilla/[12].* - ^foo\.html$ - foo.20.html - - - ^foo\.html$ - foo.32.html - - - - - From Static to Dynamic - - How can we transform a static page foo.html into a dynamic variant foo.cgi in a seamless way, i.e. without - notice by the browser/user. - - We just rewrite the URL to the jsp/servlet and force the correct MIME-type so it gets really run as - a CGI-script. This way a request to /~quux/foo.html internally leads to the invocation of /~quux/foo.jsp. - - RewriteBase /~quux/ - RewriteRule ^foo\.html$ foo.cgi [T=application/x-httpd-cgi] - - ^/~quux/foo\.html$ - /~quux/foo.jsp - - - - Blocking of Robots - - How can we block a really annoying robot from retrieving pages of a specific webarea? A /robots.txt file - containing entries of the "Robot Exclusion Protocol" is typically not enough to get rid of such a robot. - - We use a ruleset which forbids the URLs of the webarea /~quux/foo/arc/ (perhaps a very deep directory - indexed area where the robot traversal would create big server load). We have to make sure that we forbid - access only to the particular robot, i.e. just forbidding the host where the robot runs is not enough. - This would block users from this host, too. We accomplish this by also matching the User-Agent HTTP header - information. - - RewriteCond %{HTTP_USER_AGENT} ^NameOfBadRobot.* - RewriteCond %{REMOTE_ADDR} ^123\.45\.67\.[8-9]$ - RewriteRule ^/~quux/foo/arc/.+ - [F] - - ^NameOfBadRobot.* - ^123\.45\.67\.[8-9]$ - ^/~quux/foo/arc/.+ - 403 - null - - - - - Blocked Inline-Images - - Assume we have under http://www.quux-corp.de/~quux/ some pages with inlined GIF graphics. These graphics are - nice, so others directly incorporate them via hyperlinks to their pages. We don't like this practice because - it adds useless traffic to our server. - - While we cannot 100% protect the images from inclusion, we can at least restrict the cases where the browser - sends a HTTP Referer header. - - RewriteCond %{HTTP_REFERER} !^$ - RewriteCond %{HTTP_REFERER} !^http://www.quux-corp.de/~quux/.*$ [NC] - RewriteRule .*\.gif$ - [F] - - ^$ - ^http://www.quux-corp.de/~quux/.*$ - .*\.gif$ - 403 - null - - - Blocked Inline-Images example 2 - - RewriteCond %{HTTP_REFERER} !^$ - RewriteCond %{HTTP_REFERER} !.*/foo-with-gif\.html$ - RewriteRule ^inlined-in-foo\.gif$ - [F] - - ^$ - .*/foo-with-gif\.html$ - ^inlined-in-foo\.gif$ - 403 - - - - - /bahamas/ - /jamaica/ - - - - ^/query-string-escape/(.*)$ - http://query-string-escape-result.com/?q=${escape:$1}&another=$1 - - - - ^/gzip-me.jsp$ - - - - - diff --git a/container-test2/example-webapp/src/main/webapp/echo.jsp b/container-test2/example-webapp/src/main/webapp/echo.jsp deleted file mode 100644 index c78b4773..00000000 --- a/container-test2/example-webapp/src/main/webapp/echo.jsp +++ /dev/null @@ -1 +0,0 @@ -echo <%= request.getParameter("echo") %> \ No newline at end of file diff --git a/container-test2/example-webapp/src/main/webapp/gzip-me.jsp b/container-test2/example-webapp/src/main/webapp/gzip-me.jsp deleted file mode 100644 index 2496d27b..00000000 --- a/container-test2/example-webapp/src/main/webapp/gzip-me.jsp +++ /dev/null @@ -1 +0,0 @@ -hello world hello world hello world \ No newline at end of file diff --git a/container-test2/example-webapp/src/main/webapp/mod/index.jsp b/container-test2/example-webapp/src/main/webapp/mod/index.jsp deleted file mode 100644 index 7727d0fc..00000000 --- a/container-test2/example-webapp/src/main/webapp/mod/index.jsp +++ /dev/null @@ -1 +0,0 @@ -this is index.jsp \ No newline at end of file diff --git a/container-test2/example-webapp/src/main/webapp/no-decode-test-D%25%2cD.jsp b/container-test2/example-webapp/src/main/webapp/no-decode-test-D%25%2cD.jsp deleted file mode 100644 index 277e1123..00000000 --- a/container-test2/example-webapp/src/main/webapp/no-decode-test-D%25%2cD.jsp +++ /dev/null @@ -1 +0,0 @@ -this is no-decode-test target jsp \ No newline at end of file diff --git a/container-test2/example-webapp/src/main/webapp/products.jsp b/container-test2/example-webapp/src/main/webapp/products.jsp deleted file mode 100644 index d457064f..00000000 --- a/container-test2/example-webapp/src/main/webapp/products.jsp +++ /dev/null @@ -1 +0,0 @@ -product <%= request.getParameter("product_id") %> \ No newline at end of file diff --git a/container-test2/example-webapp/src/main/webapp/settest.jsp b/container-test2/example-webapp/src/main/webapp/settest.jsp deleted file mode 100644 index 507e0fcf..00000000 --- a/container-test2/example-webapp/src/main/webapp/settest.jsp +++ /dev/null @@ -1 +0,0 @@ -testsession: <%= session.getAttribute("testsession") %>, param.settest1: <%= request.getParameter("settest1") %>, method: <%= request.getMethod() %> \ No newline at end of file diff --git a/container-test2/example-webapp/src/main/webapp/test/filterRedirector.jsp b/container-test2/example-webapp/src/main/webapp/test/filterRedirector.jsp deleted file mode 100644 index e69de29b..00000000 From 7b9a2705ea8ff82cbb8bd37f24af72bb3c0ec5f9 Mon Sep 17 00:00:00 2001 From: Paul Tuckey Date: Fri, 9 Jun 2023 21:00:43 +1200 Subject: [PATCH 09/19] progress --- .github/workflows/maven.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index f32b7d86..e3a47bce 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -23,6 +23,17 @@ jobs: - name: Build with Maven run: mvn --batch-mode --update-snapshots package + - name: Locally install filter + run: mvn install + + - name: Locally install example + working-directory: container-test/example-webapp + run: mvn install + + - name: Run container tests + working-directory: container-test/test-with-testcontainers + run: mvn test + # - uses: actions/upload-artifact@v3 # with: # name: Package From 0067f45c738545c8ffddd85f0a9482e4b98bbffa Mon Sep 17 00:00:00 2001 From: Paul Tuckey Date: Fri, 9 Jun 2023 21:06:20 +1200 Subject: [PATCH 10/19] progress --- .../pom.xml | 0 .../web/filters/urlrewriteviacontainer/ContainerTestBase.java | 0 .../web/filters/urlrewriteviacontainer/WebappDecodeNoneIT.java | 0 .../web/filters/urlrewriteviacontainer/WebappDecodeUtf8IT.java | 0 .../tuckey/web/filters/urlrewriteviacontainer/WebappHttpIT.java | 0 .../web/filters/urlrewriteviacontainer/WebappModStyleHttpIT.java | 0 6 files changed, 0 insertions(+), 0 deletions(-) rename container-test/{test-with-testcontainters => test-with-testcontainers}/pom.xml (100%) rename container-test/{test-with-testcontainters => test-with-testcontainers}/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/ContainerTestBase.java (100%) rename container-test/{test-with-testcontainters => test-with-testcontainers}/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeNoneIT.java (100%) rename container-test/{test-with-testcontainters => test-with-testcontainers}/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeUtf8IT.java (100%) rename container-test/{test-with-testcontainters => test-with-testcontainers}/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappHttpIT.java (100%) rename container-test/{test-with-testcontainters => test-with-testcontainers}/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappModStyleHttpIT.java (100%) diff --git a/container-test/test-with-testcontainters/pom.xml b/container-test/test-with-testcontainers/pom.xml similarity index 100% rename from container-test/test-with-testcontainters/pom.xml rename to container-test/test-with-testcontainers/pom.xml diff --git a/container-test/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/ContainerTestBase.java b/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/ContainerTestBase.java similarity index 100% rename from container-test/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/ContainerTestBase.java rename to container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/ContainerTestBase.java diff --git a/container-test/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeNoneIT.java b/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeNoneIT.java similarity index 100% rename from container-test/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeNoneIT.java rename to container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeNoneIT.java diff --git a/container-test/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeUtf8IT.java b/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeUtf8IT.java similarity index 100% rename from container-test/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeUtf8IT.java rename to container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeUtf8IT.java diff --git a/container-test/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappHttpIT.java b/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappHttpIT.java similarity index 100% rename from container-test/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappHttpIT.java rename to container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappHttpIT.java diff --git a/container-test/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappModStyleHttpIT.java b/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappModStyleHttpIT.java similarity index 100% rename from container-test/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappModStyleHttpIT.java rename to container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappModStyleHttpIT.java From d6480dcf43970d8f459d025bb9bbf4753f614232 Mon Sep 17 00:00:00 2001 From: Paul Tuckey Date: Fri, 9 Jun 2023 21:23:29 +1200 Subject: [PATCH 11/19] progress --- .github/workflows/maven.yml | 6 +++--- container-test/example-webapp/pom.xml | 4 ++-- container-test/test-with-testcontainers/pom.xml | 17 ++++++++++++++--- ...eNoneIT.java => WebappDecodeNoneITTest.java} | 2 +- ...eUtf8IT.java => WebappDecodeUtf8ITTest.java} | 2 +- ...{WebappHttpIT.java => WebappHttpITTest.java} | 2 +- ...ttpIT.java => WebappModStyleHttpITTest.java} | 2 +- 7 files changed, 23 insertions(+), 12 deletions(-) rename container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/{WebappDecodeNoneIT.java => WebappDecodeNoneITTest.java} (97%) rename container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/{WebappDecodeUtf8IT.java => WebappDecodeUtf8ITTest.java} (96%) rename container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/{WebappHttpIT.java => WebappHttpITTest.java} (99%) rename container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/{WebappModStyleHttpIT.java => WebappModStyleHttpITTest.java} (98%) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index e3a47bce..c63697b9 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -24,15 +24,15 @@ jobs: run: mvn --batch-mode --update-snapshots package - name: Locally install filter - run: mvn install + run: mvn install --batch-mode - name: Locally install example working-directory: container-test/example-webapp - run: mvn install + run: mvn install --batch-mode - name: Run container tests working-directory: container-test/test-with-testcontainers - run: mvn test + run: mvn test --batch-mode # - uses: actions/upload-artifact@v3 # with: diff --git a/container-test/example-webapp/pom.xml b/container-test/example-webapp/pom.xml index 2d9fc1e1..24455639 100644 --- a/container-test/example-webapp/pom.xml +++ b/container-test/example-webapp/pom.xml @@ -3,8 +3,8 @@ 4.0.0 org.tuckey example-webapp - war - 5.0.0 + jar + 5.0.0-SNAPSHOT Example Webapp http://www.tuckey.org/urlrewrite/ 2001 diff --git a/container-test/test-with-testcontainers/pom.xml b/container-test/test-with-testcontainers/pom.xml index 0b39ec5b..2303099c 100644 --- a/container-test/test-with-testcontainers/pom.xml +++ b/container-test/test-with-testcontainers/pom.xml @@ -8,7 +8,7 @@ 17 17 - 6.0.0 + 5.0.0-SNAPSHOT UrlRewriteFilter Container Tests http://www.tuckey.org/urlrewrite/ 2001 @@ -31,6 +31,16 @@ + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.22.2 + + + + @@ -42,7 +52,7 @@ org.tuckey example-webapp - 5.0.0 + 5.0.0-SNAPSHOT test @@ -54,7 +64,7 @@ org.junit.jupiter junit-jupiter - 5.8.1 + 5.8.2 test @@ -88,4 +98,5 @@ + \ No newline at end of file diff --git a/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeNoneIT.java b/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeNoneITTest.java similarity index 97% rename from container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeNoneIT.java rename to container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeNoneITTest.java index 93555907..496d1e01 100644 --- a/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeNoneIT.java +++ b/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeNoneITTest.java @@ -17,7 +17,7 @@ /** * */ -public class WebappDecodeNoneIT extends ContainerTestBase { +public class WebappDecodeNoneITTest extends ContainerTestBase { protected String getApp() { return "webapp"; diff --git a/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeUtf8IT.java b/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeUtf8ITTest.java similarity index 96% rename from container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeUtf8IT.java rename to container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeUtf8ITTest.java index 5ed6e0c9..f720c420 100644 --- a/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeUtf8IT.java +++ b/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeUtf8ITTest.java @@ -30,7 +30,7 @@ *

* options: browser (may fail), enc (unlikely fail) */ -public class WebappDecodeUtf8IT extends ContainerTestBase { +public class WebappDecodeUtf8ITTest extends ContainerTestBase { protected String getApp() { return "webapp"; diff --git a/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappHttpIT.java b/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappHttpITTest.java similarity index 99% rename from container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappHttpIT.java rename to container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappHttpITTest.java index 0de900b0..201c7dd1 100644 --- a/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappHttpIT.java +++ b/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappHttpITTest.java @@ -56,7 +56,7 @@ * @author Paul Tuckey * @version $Revision: 33 $ $Date: 2006-09-12 16:41:56 +1200 (Tue, 12 Sep 2006) $ */ -public class WebappHttpIT extends ContainerTestBase { +public class WebappHttpITTest extends ContainerTestBase { protected String getApp() { return "webapp"; diff --git a/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappModStyleHttpIT.java b/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappModStyleHttpITTest.java similarity index 98% rename from container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappModStyleHttpIT.java rename to container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappModStyleHttpITTest.java index 03aec2b7..1c44bb29 100644 --- a/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappModStyleHttpIT.java +++ b/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappModStyleHttpITTest.java @@ -48,7 +48,7 @@ * @author Paul Tuckey * @version $Revision: 33 $ $Date: 2006-09-12 16:41:56 +1200 (Tue, 12 Sep 2006) $ */ -public class WebappModStyleHttpIT extends ContainerTestBase { +public class WebappModStyleHttpITTest extends ContainerTestBase { protected String getApp() { return "webapp/mod"; From ad80f3f4efa3e402c7b7dcc9ffa7835db1d68d47 Mon Sep 17 00:00:00 2001 From: Paul Tuckey Date: Fri, 9 Jun 2023 21:45:53 +1200 Subject: [PATCH 12/19] progress --- .../filters/urlrewriteviacontainer/ContainerTestBase.java | 6 ++---- .../urlrewriteviacontainer/WebappDecodeNoneITTest.java | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/ContainerTestBase.java b/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/ContainerTestBase.java index fb382fb2..6d495e11 100644 --- a/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/ContainerTestBase.java +++ b/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/ContainerTestBase.java @@ -50,8 +50,6 @@ @Testcontainers public abstract class ContainerTestBase { - private int mappedPort = 0; - protected HttpClient client = new HttpClient(); private File systemPropBaseReportsDir = new File("container-test", "reports"); private String containerId = "test"; @@ -69,8 +67,8 @@ public abstract class ContainerTestBase { public void setUp() throws Exception { container.start(); System.out.println(container.getContainerId()); + System.out.println("HOST " + container.getHost()); System.out.println("PORT " + container.getFirstMappedPort()); - this.mappedPort = container.getFirstMappedPort(); assert (container.isRunning()); String containerId = System.getProperty("test.container.id"); @@ -92,7 +90,7 @@ public void setUp() throws Exception { } protected String getBaseUrl() { - return "http://localhost:" + this.mappedPort + "/" + getApp(); + return "http://" + container.getHost() + ":" + container.getFirstMappedPort() + "/" + getApp(); } protected void recordRewriteStatus() throws IOException { diff --git a/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeNoneITTest.java b/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeNoneITTest.java index 496d1e01..86bfbed8 100644 --- a/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeNoneITTest.java +++ b/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeNoneITTest.java @@ -45,7 +45,7 @@ public void testTestUtf() throws ServletException, IOException { method.setFollowRedirects(false); client.executeMethod(method); assertNotNull(method.getResponseHeader("Location"), "no location header"); - assertEquals(getBaseUrl() + "/utf-redir/done/" + encodedStr + "/", method.getResponseHeader("Location").getValue()); + assertEquals("/" + getApp() + "/utf-redir/done/" + encodedStr + "/", method.getResponseHeader("Location").getValue()); } @Test From bb6d4308aaaf31b1c3c639a61bf3521fac782e7d Mon Sep 17 00:00:00 2001 From: Paul Tuckey Date: Fri, 9 Jun 2023 21:58:49 +1200 Subject: [PATCH 13/19] progress --- .../filters/urlrewriteviacontainer/ContainerTestBase.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/ContainerTestBase.java b/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/ContainerTestBase.java index 6d495e11..b2f38d09 100644 --- a/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/ContainerTestBase.java +++ b/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/ContainerTestBase.java @@ -61,14 +61,15 @@ public abstract class ContainerTestBase { public GenericContainer container = new GenericContainer<>("tomcat:10.1.9") .withReuse(true) .withExposedPorts(8080) - .withFileSystemBind(webappPath, "/usr/local/tomcat/webapps/webapp.war") - .waitingFor(Wait.forHttp("/webapp/test/test.jsp").forStatusCode(200)); + .withFileSystemBind(webappPath, "/usr/local/tomcat/webapps/webapp.war"); + public void setUp() throws Exception { container.start(); System.out.println(container.getContainerId()); System.out.println("HOST " + container.getHost()); System.out.println("PORT " + container.getFirstMappedPort()); + Thread.sleep(2000); //no work //.waitingFor(Wait.forHttp("/webapp/test/test.jsp").forStatusCode(200)); assert (container.isRunning()); String containerId = System.getProperty("test.container.id"); From 326222c12f07be8f39b89e7fdf80b612850d8ae1 Mon Sep 17 00:00:00 2001 From: Paul Tuckey Date: Sat, 1 Jul 2023 15:45:35 +1200 Subject: [PATCH 14/19] progress --- .../web/filters/urlrewrite/ConditionTest.java | 1771 +++++++++-------- 1 file changed, 886 insertions(+), 885 deletions(-) diff --git a/src/test/java/org/tuckey/web/filters/urlrewrite/ConditionTest.java b/src/test/java/org/tuckey/web/filters/urlrewrite/ConditionTest.java index ee414d03..5814fd38 100644 --- a/src/test/java/org/tuckey/web/filters/urlrewrite/ConditionTest.java +++ b/src/test/java/org/tuckey/web/filters/urlrewrite/ConditionTest.java @@ -1,885 +1,886 @@ -/** - * Copyright (c) 2005-2007, Paul Tuckey - * All rights reserved. - * ==================================================================== - * Licensed under the BSD License. Text as follows. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * - Neither the name tuckey.org nor the names of its contributors - * may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * ==================================================================== - */ -package org.tuckey.web.filters.urlrewrite; - -import junit.framework.TestCase; -import org.tuckey.web.testhelper.MockRequest; -import org.tuckey.web.filters.urlrewrite.utils.Log; - -import jakarta.servlet.http.Cookie; -import java.io.UnsupportedEncodingException; -import java.util.Calendar; - -/** - * @author Paul Tuckey - * @version $Revision: 1 $ $Date: 2006-08-01 21:40:28 +1200 (Tue, 01 Aug 2006) $ - */ -public class ConditionTest extends TestCase { - - public void setUp() { - Log.setLevel("DEBUG"); - } - - - public void testValue() { - Condition condition = new Condition(); - condition.setValue("tEster"); - assertEquals("tEster", condition.getValue()); - } - - public void testName() { - Condition condition = new Condition(); - condition.setName("mename"); - assertEquals("mename", condition.getName()); - } - - public void testType() { - - typeSpecific("time"); - typeSpecific("year"); - typeSpecific("month"); - typeSpecific("dayofmonth"); - typeSpecific("dayofweek"); - - typeSpecific("ampm"); - typeSpecific("hourofday"); - typeSpecific("minute"); - typeSpecific("second"); - typeSpecific("millisecond"); - - typeSpecific("attribute"); - typeSpecific("auth-type"); - typeSpecific("character-encoding"); - typeSpecific("content-length"); - typeSpecific("content-type"); - - typeSpecific("context-path"); - typeSpecific("cookie"); - typeSpecific("header"); - typeSpecific("method"); - typeSpecific("parameter"); - - typeSpecific("path-info"); - typeSpecific("path-translated"); - typeSpecific("protocol"); - typeSpecific("query-string"); - typeSpecific("remote-addr"); - - typeSpecific("remote-host"); - typeSpecific("remote-user"); - typeSpecific("requested-session-id"); - typeSpecific("requested-session-id-from-cookie"); - typeSpecific("requested-session-id-from-url"); - typeSpecific("requested-session-id-valid"); - typeSpecific("request-uri"); - typeSpecific("request-url"); - - typeSpecific("session-attribute"); - typeSpecific("session-isnew"); - typeSpecific("port"); - typeSpecific("server-name"); - typeSpecific("scheme"); - - typeSpecific("user-in-role"); - } - - public void typeSpecific(String type) { - Condition condition = new Condition(); - condition.setType(type); - assertEquals(type, condition.getType()); - - // perform a weak test to check for null pointers etc - MockRequest request = new MockRequest(); - condition.initialise(); - condition.getConditionMatch(request); - } - - public void testCompileFailure() { - Condition condition = new Condition(); - condition.setValue("aaa["); - assertFalse("regex shouldn't compile", condition.initialise()); - } - - public void testOperator() { - Condition condition = new Condition(); - condition.setOperator(""); - assertEquals("equal", condition.getOperator()); - } - - public void testNext() { - Condition condition = new Condition(); - condition.setNext("and"); - assertEquals("and", condition.getNext()); - - Condition condition2 = new Condition(); - condition2.setNext("badand"); - assertFalse("must not init", condition.initialise()); - - Condition condition3 = new Condition(); - condition3.setNext("or"); - assertEquals("or", condition3.getNext()); - assertTrue(condition3.isProcessNextOr()); - } - - public void testUnItied() { - Condition condition = new Condition(); - assertNull(condition.getConditionMatch(new MockRequest())); - } - - public void testCaseSensitive() { - Condition condition = new Condition(); - condition.setType("header"); - condition.setName("a"); - condition.setValue("aaa"); - condition.setCaseSensitive(true); - condition.initialise(); - MockRequest request = new MockRequest(); - request.setHeader("a", "aAa"); - assertNull(condition.getConditionMatch(request)); - request.setHeader("a", "aaa"); - assertNotNull(condition.getConditionMatch(request)); - assertTrue(condition.isCaseSensitive()); - } - - public void testInvalid() { - Condition condition = new Condition(); - condition.setType("bogus"); - condition.initialise(); - assertNull(condition.getConditionMatch(new MockRequest())); - } - - public void testInstanceOf() { - Condition condition = new Condition(); - condition.setType("attribute"); - condition.setOperator("instanceof"); - condition.setName("obj"); - condition.setValue("org.tuckey.web.filters.urlrewrite.ConditionTest"); - condition.initialise(); - MockRequest req = new MockRequest(); - req.setAttribute("obj", this); - assertNotNull(condition.getConditionMatch(req)); - req.setAttribute("obj", new ConditionTestExtended()); - assertNotNull("subclasses should match", condition.getConditionMatch(req)); - } - - class ConditionTestExtended extends ConditionTest { - // nothing - } - - public void testId() { - Condition condition = new Condition(); - condition.setId(98); - assertTrue(condition.getId() == 98); - } - - public void testConditionOperator() { - MockRequest request = new MockRequest(); - request.setServerPort(10); - - Condition condition = new Condition(); - condition.setType("port"); - condition.setValue("9"); - condition.setOperator("greater"); - condition.initialise(); - assertNotNull("condition must match", condition.getConditionMatch(request)); - - Condition condition2 = new Condition(); - condition2.setType("port"); - condition2.setValue("11"); - condition2.setOperator("less"); - condition2.initialise(); - assertNotNull("condition must match", condition2.getConditionMatch(request)); - - Condition condition3 = new Condition(); - condition3.setType("port"); - condition3.setValue("10"); - condition3.setOperator("greaterorequal"); - condition3.initialise(); - assertNotNull("condition must match", condition3.getConditionMatch(request)); - - Condition condition4 = new Condition(); - condition4.setType("port"); - condition4.setValue("10"); - condition4.setOperator("lessorequal"); - condition4.initialise(); - assertNotNull("condition must match", condition4.getConditionMatch(request)); - - Condition condition5 = new Condition(); - condition5.setType("port"); - condition5.setValue("99"); - condition5.setOperator("notequal"); - condition5.initialise(); - assertNotNull("condition must match", condition5.getConditionMatch(request)); - - Condition condition6 = new Condition(); - condition6.setType("method"); - condition6.setValue("POST"); - condition6.setOperator("notequal"); - condition6.initialise(); - assertNotNull("condition must match", condition6.getConditionMatch(request)); - - Condition condition7 = new Condition(); - condition7.setType("method"); - condition7.setValue("POST"); - condition7.setOperator("somebadassop"); - - assertFalse("condition must not init", condition7.initialise()); - assertTrue("condition must have error", condition7.getError() != null); - - } - - public void testConditionTime() { - MockRequest request = new MockRequest(); - long field = System.currentTimeMillis(); - Condition condition = new Condition(); - condition.setType("time"); - condition.setValue("" + field); - condition.setOperator("greaterorequal"); - condition.initialise(); - assertNotNull("condition must match", condition.getConditionMatch(request)); - } - - public void testConditionYear() { - MockRequest request = new MockRequest(); - Calendar cal = Calendar.getInstance(); - int field = cal.get(Calendar.YEAR); - Condition condition = new Condition(); - condition.setType("year"); - condition.setValue("" + field); - condition.initialise(); - assertNotNull("condition must match", condition.getConditionMatch(request)); - } - - public void testConditionMonth() { - MockRequest request = new MockRequest(); - Calendar cal = Calendar.getInstance(); - int field = cal.get(Calendar.MONTH); - Condition condition = new Condition(); - condition.setType("month"); - condition.setValue("" + field); - condition.initialise(); - assertNotNull("condition must match", condition.getConditionMatch(request)); - } - - public void testConditionDayOfMonth() { - MockRequest request = new MockRequest(); - Calendar cal = Calendar.getInstance(); - int field = cal.get(Calendar.DAY_OF_MONTH); - Condition condition = new Condition(); - condition.setType("dayofmonth"); - condition.setValue("" + field); - condition.initialise(); - assertNotNull("condition must match", condition.getConditionMatch(request)); - } - - public void testConditionDayOfWeek() { - MockRequest request = new MockRequest(); - Calendar cal = Calendar.getInstance(); - int field = cal.get(Calendar.DAY_OF_WEEK); - Condition condition = new Condition(); - condition.setType("dayofweek"); - condition.setValue("" + field); - condition.initialise(); - assertNotNull("condition must match", condition.getConditionMatch(request)); - } - - - public void testConditionAmPm() { - MockRequest request = new MockRequest(); - Calendar cal = Calendar.getInstance(); - int field = cal.get(Calendar.AM_PM); - Condition condition = new Condition(); - condition.setType("ampm"); - condition.setValue("" + field); - condition.initialise(); - assertNotNull("condition must match", condition.getConditionMatch(request)); - } - - public void testConditionHourOfDay() { - MockRequest request = new MockRequest(); - Calendar cal = Calendar.getInstance(); - int field = cal.get(Calendar.HOUR_OF_DAY); - Condition condition = new Condition(); - condition.setType("hourofday"); - condition.setValue("" + field); - condition.initialise(); - assertNotNull("condition must match", condition.getConditionMatch(request)); - } - - public void testConditionMinute() { - MockRequest request = new MockRequest(); - Calendar cal = Calendar.getInstance(); - int field = cal.get(Calendar.MINUTE); - Condition condition = new Condition(); - condition.setType("minute"); - condition.setValue("" + field); - condition.initialise(); - assertNotNull("condition must match", condition.getConditionMatch(request)); - } - - public void testConditionSecond() { - MockRequest request = new MockRequest(); - Calendar cal = Calendar.getInstance(); - int field = cal.get(Calendar.SECOND); - Condition condition = new Condition(); - condition.setType("second"); - condition.setValue("" + field); - condition.initialise(); - assertNotNull("condition must match", condition.getConditionMatch(request)); - } - - public void testConditionMillisecond() { - MockRequest request = new MockRequest(); - Calendar cal = Calendar.getInstance(); - int field = cal.get(Calendar.MILLISECOND); - Condition condition = new Condition(); - condition.setType("millisecond"); - condition.setValue("" + field); - condition.setOperator("greaterorequal"); - condition.initialise(); - assertNotNull("condition must match", condition.getConditionMatch(request)); - } - - public void testConditionAttribute() { - MockRequest request = new MockRequest(); - Condition condition = new Condition(); - condition.setType("attribute"); - condition.setName("ray"); - condition.setValue("andchristian"); - condition.initialise(); - assertNull("condition must not match", condition.getConditionMatch(request)); - - request.setAttribute("ray", "andchristian"); - assertNotNull("condition must match", condition.getConditionMatch(request)); - - Condition condition2 = new Condition(); - condition2.setType("attribute"); - condition2.setName("ray"); - condition2.setValue("andbob"); - condition2.initialise(); - assertNull("condition must not match", condition2.getConditionMatch(request)); - - Condition condition3 = new Condition(); - condition3.setType("attribute"); - condition3.setValue("andbob"); - condition3.initialise(); - assertNull("condition must not initialise", condition3.getConditionMatch(request)); - } - - public void testConditionAuthType() { - MockRequest request = new MockRequest(); - request.setAuthType("pwdwithcrapasrot13"); - Condition condition = new Condition(); - condition.setType("auth-type"); - condition.setValue("pwd[a-z0-9]+"); - condition.initialise(); - assertNotNull("condition must match", condition.getConditionMatch(request)); - - Condition condition2 = new Condition(); - condition2.setType("auth-type"); - condition2.setValue("someotherpwdtype"); - condition2.initialise(); - assertNull("condition must not match", condition2.getConditionMatch(request)); - } - - public void testConditionCharacterEncoding() throws UnsupportedEncodingException { - MockRequest request = new MockRequest(); - Condition condition = new Condition(); - condition.setType("character-encoding"); - condition.setValue("utfcrazybig[0-9]+"); - condition.initialise(); - assertNull("condition must not match", condition.getConditionMatch(request)); - - request.setCharacterEncoding("utfcrazybig13"); - assertNotNull("condition must match", condition.getConditionMatch(request)); - } - - public void testConditionContentLength() throws UnsupportedEncodingException { - MockRequest request = new MockRequest(); - request.setContentLength(120); - Condition condition = new Condition(); - condition.setType("content-length"); - condition.setValue("100"); - condition.setOperator("greater"); - condition.initialise(); - assertNotNull("condition must match", condition.getConditionMatch(request)); - - request.setContentLength(10); - assertNull("condition must not match", condition.getConditionMatch(request)); - } - - public void testContentType() throws UnsupportedEncodingException { - MockRequest request = new MockRequest(); - request.setContentType("bottlesandcans"); - Condition condition = new Condition(); - condition.setType("content-type"); - condition.setValue("bott[a-z]+"); - condition.initialise(); - assertNotNull("condition must match", condition.getConditionMatch(request)); - - request.setContentType(null); - assertNull("condition must not match", condition.getConditionMatch(request)); - } - - public void testContextPath() throws UnsupportedEncodingException { - MockRequest request = new MockRequest(); - request.setContextPath("blah"); - Condition condition = new Condition(); - condition.setType("context-path"); - condition.setValue("[a-b]lah"); - condition.initialise(); - assertNotNull("condition must match", condition.getConditionMatch(request)); - - request.setContextPath("qlah"); - assertNull("condition must not match", condition.getConditionMatch(request)); - } - - public void testCookie() throws UnsupportedEncodingException { - MockRequest request = new MockRequest(); - Condition condition = new Condition(); - condition.setType("cookie"); - condition.setName("tracker"); - condition.setValue(".*bass.*"); - condition.initialise(); - assertNull("condition must not match", condition.getConditionMatch(request)); - - request.addCookie(new Cookie("otherokie", "allyourbassisbelongtous")); - assertNull("condition must not match", condition.getConditionMatch(request)); - - request.addCookie(new Cookie("tracker", "allyourbassisbelongtous")); - assertNotNull("condition must match", condition.getConditionMatch(request)); - } - - public void testLocalPort() throws UnsupportedEncodingException { - MockRequest request = new MockRequest(); - request.setLocalPort(4); - Condition condition = new Condition(); - condition.setType("local-port"); - condition.setValue("1004"); - condition.initialise(); - assertNull("condition must not match", condition.getConditionMatch(request)); - - request.setLocalPort(1004); - assertNotNull("condition must match", condition.getConditionMatch(request)); - } - - public void testParameter() throws UnsupportedEncodingException { - MockRequest request = new MockRequest(); - Condition condition = new Condition(); - condition.setType("parameter"); - condition.setName("reqparam"); - condition.setValue("[0-9]+"); - condition.initialise(); - assertNull("condition must not match", condition.getConditionMatch(request)); - - request.addParameter("reqparam", "1000245"); - assertNotNull("condition must match", condition.getConditionMatch(request)); - } - - // Condition: Equal, Pattern: Null, Value: Null, Result should be: Match. - public void testParameterNull1() throws UnsupportedEncodingException { - MockRequest request = new MockRequest(); - Condition condition = new Condition(); - condition.setType("parameter"); - condition.setName("reqparam"); - condition.setValue(""); - condition.setOperator("equal"); - condition.initialise(); - assertNull("condition must match", condition.getConditionMatch(request)); - } - - // Condition: Equal, Pattern: Null, Value: Not Null, Result should be: No match. - public void testParameterNull2() throws UnsupportedEncodingException { - MockRequest request = new MockRequest(); - Condition condition = new Condition(); - condition.setType("parameter"); - condition.setName("reqparam"); - condition.setValue(""); - condition.setOperator("equal"); - condition.initialise(); - request.addParameter("reqparam", "1000245"); - assertNotNull("condition must not match", condition.getConditionMatch(request)); - } - - // Condition: Not Equal, Pattern: Null, Value: Null, Result should be: No match. - public void testParameterNull3() throws UnsupportedEncodingException { - MockRequest request = new MockRequest(); - Condition condition = new Condition(); - condition.setType("parameter"); - condition.setName("reqparam"); - condition.setValue(""); - condition.setOperator("notequal"); - condition.initialise(); - assertNotNull("condition must not match", condition.getConditionMatch(request)); - request.addParameter("reqparam", "1000245"); - // Condition: Not Equal, Pattern: Null, Value: Not Null, Result should be: match. - assertNull("condition must match", condition.getConditionMatch(request)); - } - - // Condition: Not Equal, Pattern: Null, Value: Not Null, Result should be: match. - public void testParameterNull4() throws UnsupportedEncodingException { - MockRequest request = new MockRequest(); - Condition condition = new Condition(); - condition.setType("parameter"); - condition.setName("reqparam"); - condition.setValue(""); - condition.setOperator("notequal"); - condition.initialise(); - request.addParameter("reqparam", "1000245"); - assertNull("condition must match", condition.getConditionMatch(request)); - } - - public void testPathInfo() throws UnsupportedEncodingException { - MockRequest request = new MockRequest(); - Condition condition = new Condition(); - condition.setType("path-info"); - condition.setValue("afr[aeiou]ca"); - condition.initialise(); - assertNull("condition must not match", condition.getConditionMatch(request)); - - request.setPathInfo("africa"); - assertNotNull("condition must match", condition.getConditionMatch(request)); - } - - public void testPathTranslated() throws UnsupportedEncodingException { - MockRequest request = new MockRequest(); - Condition condition = new Condition(); - condition.setType("path-translated"); - condition.setValue("/!@&"); - condition.initialise(); - assertNull("condition must not match", condition.getConditionMatch(request)); - - request.setPathTranslated("/!@&"); - assertNotNull("condition must match", condition.getConditionMatch(request)); - } - - public void testProtocol() throws UnsupportedEncodingException { - MockRequest request = new MockRequest(); - Condition condition = new Condition(); - condition.setType("protocol"); - condition.setValue("HTTP/1\\.[1-2]"); - condition.initialise(); - request.setProtocol("HTTP/2.0"); - assertNull("condition must not match", condition.getConditionMatch(request)); - - request.setProtocol("HTTP/1.2"); - assertNotNull("condition must match", condition.getConditionMatch(request)); - } - - public void testQueryString() throws UnsupportedEncodingException { - MockRequest request = new MockRequest(); - Condition condition = new Condition(); - condition.setType("query-string"); - condition.setValue(".*¶m=[0-9]+.*"); - condition.initialise(); - assertNull("condition must not match", condition.getConditionMatch(request)); - - request.setQueryString("?aaa=dsdsd¶m=2333&asdsa=sdds"); - assertNotNull("condition must match", condition.getConditionMatch(request)); - } - - public void testRemoteAddr() throws UnsupportedEncodingException { - MockRequest request = new MockRequest(); - Condition condition = new Condition(); - condition.setType("remote-addr"); - condition.setValue("192.168.[0-9]+.[0-9]+"); - condition.initialise(); - assertNull("condition must not match", condition.getConditionMatch(request)); - - request.setRemoteAddr("192.168.184.23"); - assertNotNull("condition must match", condition.getConditionMatch(request)); - } - - public void testRemoteHost() throws UnsupportedEncodingException { - MockRequest request = new MockRequest(); - Condition condition = new Condition(); - condition.setType("remote-host"); - condition.setValue("\\w+\\.tuckey.org"); - condition.initialise(); - assertNull("condition must not match", condition.getConditionMatch(request)); - - request.setRemoteHost("toaster.tuckey.org"); - assertNotNull("condition must match", condition.getConditionMatch(request)); - } - - public void testRemoteUser() throws UnsupportedEncodingException { - MockRequest request = new MockRequest(); - Condition condition = new Condition(); - condition.setType("remote-user"); - condition.setValue("p.\\w+"); - condition.initialise(); - assertNull("condition must not match", condition.getConditionMatch(request)); - - request.setRemoteUser("p.smith"); - assertNotNull("condition must match", condition.getConditionMatch(request)); - } - - public void testRequestedSessionId() throws UnsupportedEncodingException { - MockRequest request = new MockRequest(); - Condition condition = new Condition(); - condition.setType("requested-session-id"); - condition.setValue("\\w+\\.sec[0-6]+"); - condition.initialise(); - assertNull("condition must not match", condition.getConditionMatch(request)); - - request.setRequestedSessionId("sdfjsdfhkjhk897fd.sec03"); - assertNotNull("condition must match", condition.getConditionMatch(request)); - } - - public void testRequestedSessionIdFromCookie() throws UnsupportedEncodingException { - MockRequest request = new MockRequest(); - Condition condition = new Condition(); - condition.setType("requested-session-id-from-cookie"); - condition.setValue("true"); - condition.initialise(); - assertNull("condition must not match", condition.getConditionMatch(request)); - - request.setRequestedSessionIdFromCookie(true); - assertNotNull("condition must match", condition.getConditionMatch(request)); - } - - public void testRequestedSessionIdFromURL() throws UnsupportedEncodingException { - MockRequest request = new MockRequest(); - Condition condition = new Condition(); - condition.setType("requested-session-id-from-url"); - condition.setValue("true"); - condition.initialise(); - assertNull("condition must not match", condition.getConditionMatch(request)); - - request.setRequestedSessionIdFromURL(true); - assertNotNull("condition must match", condition.getConditionMatch(request)); - } - - public void testRequestedSessionIdValid() throws UnsupportedEncodingException { - MockRequest request = new MockRequest(); - Condition condition = new Condition(); - condition.setType("requested-session-id-valid"); - condition.setValue("true"); - condition.initialise(); - assertNull("condition must not match", condition.getConditionMatch(request)); - - request.setRequestedSessionIdValid(true); - assertNotNull("condition must match", condition.getConditionMatch(request)); - } - - public void testRequestUri() throws UnsupportedEncodingException { - MockRequest request = new MockRequest(); - Condition condition = new Condition(); - condition.setType("request-uri"); - condition.setValue("\\d"); - condition.initialise(); - assertNull("condition must not match", condition.getConditionMatch(request)); - - request.setRequestURI("2"); - assertNotNull("condition must match", condition.getConditionMatch(request)); - } - - public void testRequestUrl() throws UnsupportedEncodingException { - MockRequest request = new MockRequest(); - Condition condition = new Condition(); - condition.setType("request-url"); - condition.setValue("\\d"); - condition.initialise(); - assertNull("condition must not match", condition.getConditionMatch(request)); - - request.setRequestURL("2"); - assertNotNull("condition must match", condition.getConditionMatch(request)); - } - - public void testSessionAttribute() throws UnsupportedEncodingException { - MockRequest request = new MockRequest(); - Condition condition = new Condition(); - condition.setType("session-attribute"); - condition.setValue("someval"); - condition.initialise(); - assertNull("condition must not match", condition.getConditionMatch(request)); - - Condition condition2 = new Condition(); - condition2.setType("session-attribute"); - condition2.setName("someatt"); - condition2.setValue("someval"); - condition2.initialise(); - assertNull("condition must not match", condition2.getConditionMatch(request)); - - request.getSession(true).setAttribute("someatt", "someval"); - - Condition condition3 = new Condition(); - condition3.setType("session-attribute"); - condition3.setName("someatt"); - condition3.setValue("someval"); - condition3.initialise(); - assertNotNull("condition must match", condition3.getConditionMatch(request)); - } - - public void testSessionIsNew() throws UnsupportedEncodingException { - MockRequest request = new MockRequest(); - Condition condition = new Condition(); - condition.setType("session-isnew"); - condition.setValue("yes"); - condition.setOperator("notequal"); - condition.initialise(); - assertNotNull("condition must match", condition.getConditionMatch(request)); - - request.setSessionNew(true); - assertNull("condition must not match", condition.getConditionMatch(request)); - } - - public void testServerName() throws UnsupportedEncodingException { - MockRequest request = new MockRequest(); - Condition condition = new Condition(); - condition.setType("server-name"); - condition.setValue("dev.*"); - condition.initialise(); - assertNull("condition must not match", condition.getConditionMatch(request)); - - request.setServerName("dev.googil.com"); - assertNotNull("condition must match", condition.getConditionMatch(request)); - } - - public void testScheme() throws UnsupportedEncodingException { - MockRequest request = new MockRequest(); - Condition condition = new Condition(); - condition.setType("scheme"); - condition.setValue("http"); - condition.initialise(); - assertNull("condition must not match", condition.getConditionMatch(request)); - - request.setScheme("http"); - assertNotNull("condition must match", condition.getConditionMatch(request)); - } - - - public void testConditionHeader() { - MockRequest request = new MockRequest(); - Condition condition = new Condition(); - condition.setName("some header"); - condition.setValue("tester"); - condition.initialise(); - assertNull("condition must not match", condition.getConditionMatch(request)); - - request.setHeader("some header", "tester"); - assertNotNull("condition must match", condition.getConditionMatch(request)); - - Condition condition2 = new Condition(); - condition2.setName(" "); - condition2.setValue("tester"); - assertFalse("condition must not initialise", condition2.initialise()); - assertNull("condition must not match", condition2.getConditionMatch(request)); - - Condition condition3 = new Condition(); - condition3.setName("bonus"); - assertTrue("condition must initialise and check for exists", condition3.initialise()); - assertNull("condition must not match", condition3.getConditionMatch(request)); - request.setHeader("bonus", "tester"); - assertNotNull("condition must match", condition3.getConditionMatch(request)); - - Condition condition4 = new Condition(); - condition4.setName("portashed"); - condition4.setOperator("notequal"); - - assertTrue("condition must initialise and check for exists", condition4.initialise()); - assertNotNull("condition must match", condition4.getConditionMatch(request)); - request.setHeader("portashed", "tester"); - assertNull("condition must not match", condition4.getConditionMatch(request)); - - } - - public void testConditionMethod() { - MockRequest request = new MockRequest(); - request.setMethod("HEAD"); - Condition condition = new Condition(); - condition.setType("method"); - condition.setValue("H[A-Z]AD"); - condition.initialise(); - assertNotNull("condition must match", condition.getConditionMatch(request)); - } - - - public void testConditionIsUserInRole() { - MockRequest request = new MockRequest(); - request.addRole("devil"); - Condition condition = new Condition(); - condition.setType("user-in-role"); - condition.setName("devil"); - condition.initialise(); - assertNotNull("user should be in this role", condition.getConditionMatch(request)); - - Condition condition2 = new Condition(); - condition2.setType("user-in-role"); - condition2.setName("angel"); - condition2.initialise(); - assertNull("bad user in role must not match", condition2.getConditionMatch(request)); - - Condition condition3 = new Condition(); - condition3.setType("user-in-role"); - condition3.setValue("devil"); - condition3.initialise(); - assertNotNull("value instead of name should match", condition3.getConditionMatch(request)); - - Condition condition4 = new Condition(); - condition4.setType("user-in-role"); - condition4.setValue("admin"); - condition4.setOperator("notequal"); - condition4.initialise(); - assertNotNull("value instead of name should match", condition4.getConditionMatch(request)); - } - - public void testConditionPort() { - MockRequest request = new MockRequest(); - request.setServerPort(9001); - Condition condition = new Condition(); - condition.setType("port"); - condition.setValue("9001"); - condition.initialise(); - assertNotNull("condition must match", condition.getConditionMatch(request)); - - Condition condition2 = new Condition(); - condition2.setType("port"); - condition2.setValue(" 9001"); - condition2.initialise(); - assertNotNull("condition must match", condition2.getConditionMatch(request)); - // check re-init - condition2.initialise(); - assertNotNull("condition must match", condition2.getConditionMatch(request)); - - Condition condition3 = new Condition(); - condition3.setType("port"); - condition3.setValue("aaa"); - condition3.initialise(); - assertNull("condition must not match", condition3.getConditionMatch(request)); - } - - -} +/** + * Copyright (c) 2005-2007, Paul Tuckey + * All rights reserved. + * ==================================================================== + * Licensed under the BSD License. Text as follows. + *

+ * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + *

+ * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * - Neither the name tuckey.org nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + *

+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + */ +package org.tuckey.web.filters.urlrewrite; + +import junit.framework.TestCase; +import org.tuckey.web.testhelper.MockRequest; +import org.tuckey.web.filters.urlrewrite.utils.Log; + +import jakarta.servlet.http.Cookie; + +import java.io.UnsupportedEncodingException; +import java.util.Calendar; + +/** + * @author Paul Tuckey + * @version $Revision: 1 $ $Date: 2006-08-01 21:40:28 +1200 (Tue, 01 Aug 2006) $ + */ +public class ConditionTest extends TestCase { + + public void setUp() { + Log.setLevel("DEBUG"); + } + + + public void testValue() { + Condition condition = new Condition(); + condition.setValue("tEster"); + assertEquals("tEster", condition.getValue()); + } + + public void testName() { + Condition condition = new Condition(); + condition.setName("mename"); + assertEquals("mename", condition.getName()); + } + + public void testType() { + + typeSpecific("time"); + typeSpecific("year"); + typeSpecific("month"); + typeSpecific("dayofmonth"); + typeSpecific("dayofweek"); + + typeSpecific("ampm"); + typeSpecific("hourofday"); + typeSpecific("minute"); + typeSpecific("second"); + typeSpecific("millisecond"); + + typeSpecific("attribute"); + typeSpecific("auth-type"); + typeSpecific("character-encoding"); + typeSpecific("content-length"); + typeSpecific("content-type"); + + typeSpecific("context-path"); + typeSpecific("cookie"); + typeSpecific("header"); + typeSpecific("method"); + typeSpecific("parameter"); + + typeSpecific("path-info"); + typeSpecific("path-translated"); + typeSpecific("protocol"); + typeSpecific("query-string"); + typeSpecific("remote-addr"); + + typeSpecific("remote-host"); + typeSpecific("remote-user"); + typeSpecific("requested-session-id"); + typeSpecific("requested-session-id-from-cookie"); + typeSpecific("requested-session-id-from-url"); + typeSpecific("requested-session-id-valid"); + typeSpecific("request-uri"); + typeSpecific("request-url"); + + typeSpecific("session-attribute"); + typeSpecific("session-isnew"); + typeSpecific("port"); + typeSpecific("server-name"); + typeSpecific("scheme"); + + typeSpecific("user-in-role"); + } + + public void typeSpecific(String type) { + Condition condition = new Condition(); + condition.setType(type); + assertEquals(type, condition.getType()); + + // perform a weak test to check for null pointers etc + MockRequest request = new MockRequest(); + condition.initialise(); + condition.getConditionMatch(request); + } + + public void testCompileFailure() { + Condition condition = new Condition(); + condition.setValue("aaa["); + assertFalse("regex shouldn't compile", condition.initialise()); + } + + public void testOperator() { + Condition condition = new Condition(); + condition.setOperator(""); + assertEquals("equal", condition.getOperator()); + } + + public void testNext() { + Condition condition = new Condition(); + condition.setNext("and"); + assertEquals("and", condition.getNext()); + + Condition condition2 = new Condition(); + condition2.setNext("badand"); + assertFalse("must not init", condition.initialise()); + + Condition condition3 = new Condition(); + condition3.setNext("or"); + assertEquals("or", condition3.getNext()); + assertTrue(condition3.isProcessNextOr()); + } + + public void testUnItied() { + Condition condition = new Condition(); + assertNull(condition.getConditionMatch(new MockRequest())); + } + + public void testCaseSensitive() { + Condition condition = new Condition(); + condition.setType("header"); + condition.setName("a"); + condition.setValue("aaa"); + condition.setCaseSensitive(true); + condition.initialise(); + MockRequest request = new MockRequest(); + request.setHeader("a", "aAa"); + assertNull(condition.getConditionMatch(request)); + request.setHeader("a", "aaa"); + assertNotNull(condition.getConditionMatch(request)); + assertTrue(condition.isCaseSensitive()); + } + + public void testInvalid() { + Condition condition = new Condition(); + condition.setType("bogus"); + condition.initialise(); + assertNull(condition.getConditionMatch(new MockRequest())); + } + + public void testInstanceOf() { + Condition condition = new Condition(); + condition.setType("attribute"); + condition.setOperator("instanceof"); + condition.setName("obj"); + condition.setValue("org.tuckey.web.filters.urlrewrite.ConditionTest"); + condition.initialise(); + MockRequest req = new MockRequest(); + req.setAttribute("obj", this); + assertNotNull(condition.getConditionMatch(req)); + req.setAttribute("obj", new ConditionTestExtended()); + assertNotNull("subclasses should match", condition.getConditionMatch(req)); + } + + class ConditionTestExtended extends ConditionTest { + // nothing + } + + public void testId() { + Condition condition = new Condition(); + condition.setId(98); + assertEquals(98, condition.getId()); + } + + public void testConditionOperator() { + MockRequest request = new MockRequest(); + request.setServerPort(10); + + Condition condition = new Condition(); + condition.setType("port"); + condition.setValue("9"); + condition.setOperator("greater"); + condition.initialise(); + assertNotNull("condition must match", condition.getConditionMatch(request)); + + Condition condition2 = new Condition(); + condition2.setType("port"); + condition2.setValue("11"); + condition2.setOperator("less"); + condition2.initialise(); + assertNotNull("condition must match", condition2.getConditionMatch(request)); + + Condition condition3 = new Condition(); + condition3.setType("port"); + condition3.setValue("10"); + condition3.setOperator("greaterorequal"); + condition3.initialise(); + assertNotNull("condition must match", condition3.getConditionMatch(request)); + + Condition condition4 = new Condition(); + condition4.setType("port"); + condition4.setValue("10"); + condition4.setOperator("lessorequal"); + condition4.initialise(); + assertNotNull("condition must match", condition4.getConditionMatch(request)); + + Condition condition5 = new Condition(); + condition5.setType("port"); + condition5.setValue("99"); + condition5.setOperator("notequal"); + condition5.initialise(); + assertNotNull("condition must match", condition5.getConditionMatch(request)); + + Condition condition6 = new Condition(); + condition6.setType("method"); + condition6.setValue("POST"); + condition6.setOperator("notequal"); + condition6.initialise(); + assertNotNull("condition must match", condition6.getConditionMatch(request)); + + Condition condition7 = new Condition(); + condition7.setType("method"); + condition7.setValue("POST"); + condition7.setOperator("somebadassop"); + + assertFalse("condition must not init", condition7.initialise()); + assertNotNull("condition must have error", condition7.getError()); + + } + + public void testConditionTime() { + MockRequest request = new MockRequest(); + long field = System.currentTimeMillis(); + Condition condition = new Condition(); + condition.setType("time"); + condition.setValue(String.valueOf(field)); + condition.setOperator("greaterorequal"); + condition.initialise(); + assertNotNull("condition must match", condition.getConditionMatch(request)); + } + + public void testConditionYear() { + MockRequest request = new MockRequest(); + Calendar cal = Calendar.getInstance(); + int field = cal.get(Calendar.YEAR); + Condition condition = new Condition(); + condition.setType("year"); + condition.setValue(String.valueOf(field)); + condition.initialise(); + assertNotNull("condition must match", condition.getConditionMatch(request)); + } + + public void testConditionMonth() { + MockRequest request = new MockRequest(); + Calendar cal = Calendar.getInstance(); + int field = cal.get(Calendar.MONTH); + Condition condition = new Condition(); + condition.setType("month"); + condition.setValue(String.valueOf(field)); + condition.initialise(); + assertNotNull("condition must match", condition.getConditionMatch(request)); + } + + public void testConditionDayOfMonth() { + MockRequest request = new MockRequest(); + Calendar cal = Calendar.getInstance(); + int field = cal.get(Calendar.DAY_OF_MONTH); + Condition condition = new Condition(); + condition.setType("dayofmonth"); + condition.setValue(String.valueOf(field)); + condition.initialise(); + assertNotNull("condition must match", condition.getConditionMatch(request)); + } + + public void testConditionDayOfWeek() { + MockRequest request = new MockRequest(); + Calendar cal = Calendar.getInstance(); + int field = cal.get(Calendar.DAY_OF_WEEK); + Condition condition = new Condition(); + condition.setType("dayofweek"); + condition.setValue(String.valueOf(field)); + condition.initialise(); + assertNotNull("condition must match", condition.getConditionMatch(request)); + } + + + public void testConditionAmPm() { + MockRequest request = new MockRequest(); + Calendar cal = Calendar.getInstance(); + int field = cal.get(Calendar.AM_PM); + Condition condition = new Condition(); + condition.setType("ampm"); + condition.setValue(String.valueOf(field)); + condition.initialise(); + assertNotNull("condition must match", condition.getConditionMatch(request)); + } + + public void testConditionHourOfDay() { + MockRequest request = new MockRequest(); + Calendar cal = Calendar.getInstance(); + int field = cal.get(Calendar.HOUR_OF_DAY); + Condition condition = new Condition(); + condition.setType("hourofday"); + condition.setValue(String.valueOf(field)); + condition.initialise(); + assertNotNull("condition must match", condition.getConditionMatch(request)); + } + + public void testConditionMinute() { + MockRequest request = new MockRequest(); + Calendar cal = Calendar.getInstance(); + int field = cal.get(Calendar.MINUTE); + Condition condition = new Condition(); + condition.setType("minute"); + condition.setValue(String.valueOf(field)); + condition.initialise(); + assertNotNull("condition must match", condition.getConditionMatch(request)); + } + + public void testConditionSecond() { + MockRequest request = new MockRequest(); + Calendar cal = Calendar.getInstance(); + int field = cal.get(Calendar.SECOND); + Condition condition = new Condition(); + condition.setType("second"); + condition.setValue(String.valueOf(field)); + condition.initialise(); + assertNotNull("condition must match", condition.getConditionMatch(request)); + } + + public void testConditionMillisecond() { + MockRequest request = new MockRequest(); + Calendar cal = Calendar.getInstance(); + int field = cal.get(Calendar.MILLISECOND); + Condition condition = new Condition(); + condition.setType("millisecond"); + condition.setValue(String.valueOf(field)); + condition.setOperator("greaterorequal"); + condition.initialise(); + assertNotNull("condition must match", condition.getConditionMatch(request)); + } + + public void testConditionAttribute() { + MockRequest request = new MockRequest(); + Condition condition = new Condition(); + condition.setType("attribute"); + condition.setName("ray"); + condition.setValue("andchristian"); + condition.initialise(); + assertNull("condition must not match", condition.getConditionMatch(request)); + + request.setAttribute("ray", "andchristian"); + assertNotNull("condition must match", condition.getConditionMatch(request)); + + Condition condition2 = new Condition(); + condition2.setType("attribute"); + condition2.setName("ray"); + condition2.setValue("andbob"); + condition2.initialise(); + assertNull("condition must not match", condition2.getConditionMatch(request)); + + Condition condition3 = new Condition(); + condition3.setType("attribute"); + condition3.setValue("andbob"); + condition3.initialise(); + assertNull("condition must not initialise", condition3.getConditionMatch(request)); + } + + public void testConditionAuthType() { + MockRequest request = new MockRequest(); + request.setAuthType("pwdwithcrapasrot13"); + Condition condition = new Condition(); + condition.setType("auth-type"); + condition.setValue("pwd[a-z0-9]+"); + condition.initialise(); + assertNotNull("condition must match", condition.getConditionMatch(request)); + + Condition condition2 = new Condition(); + condition2.setType("auth-type"); + condition2.setValue("someotherpwdtype"); + condition2.initialise(); + assertNull("condition must not match", condition2.getConditionMatch(request)); + } + + public void testConditionCharacterEncoding() throws UnsupportedEncodingException { + MockRequest request = new MockRequest(); + Condition condition = new Condition(); + condition.setType("character-encoding"); + condition.setValue("utfcrazybig[0-9]+"); + condition.initialise(); + assertNull("condition must not match", condition.getConditionMatch(request)); + + request.setCharacterEncoding("utfcrazybig13"); + assertNotNull("condition must match", condition.getConditionMatch(request)); + } + + public void testConditionContentLength() throws UnsupportedEncodingException { + MockRequest request = new MockRequest(); + request.setContentLength(120); + Condition condition = new Condition(); + condition.setType("content-length"); + condition.setValue("100"); + condition.setOperator("greater"); + condition.initialise(); + assertNotNull("condition must match", condition.getConditionMatch(request)); + + request.setContentLength(10); + assertNull("condition must not match", condition.getConditionMatch(request)); + } + + public void testContentType() throws UnsupportedEncodingException { + MockRequest request = new MockRequest(); + request.setContentType("bottlesandcans"); + Condition condition = new Condition(); + condition.setType("content-type"); + condition.setValue("bott[a-z]+"); + condition.initialise(); + assertNotNull("condition must match", condition.getConditionMatch(request)); + + request.setContentType(null); + assertNull("condition must not match", condition.getConditionMatch(request)); + } + + public void testContextPath() throws UnsupportedEncodingException { + MockRequest request = new MockRequest(); + request.setContextPath("blah"); + Condition condition = new Condition(); + condition.setType("context-path"); + condition.setValue("[a-b]lah"); + condition.initialise(); + assertNotNull("condition must match", condition.getConditionMatch(request)); + + request.setContextPath("qlah"); + assertNull("condition must not match", condition.getConditionMatch(request)); + } + + public void testCookie() throws UnsupportedEncodingException { + MockRequest request = new MockRequest(); + Condition condition = new Condition(); + condition.setType("cookie"); + condition.setName("tracker"); + condition.setValue(".*bass.*"); + condition.initialise(); + assertNull("condition must not match", condition.getConditionMatch(request)); + + request.addCookie(new Cookie("otherokie", "allyourbassisbelongtous")); + assertNull("condition must not match", condition.getConditionMatch(request)); + + request.addCookie(new Cookie("tracker", "allyourbassisbelongtous")); + assertNotNull("condition must match", condition.getConditionMatch(request)); + } + + public void testLocalPort() throws UnsupportedEncodingException { + MockRequest request = new MockRequest(); + request.setLocalPort(4); + Condition condition = new Condition(); + condition.setType("local-port"); + condition.setValue("1004"); + condition.initialise(); + assertNull("condition must not match", condition.getConditionMatch(request)); + + request.setLocalPort(1004); + assertNotNull("condition must match", condition.getConditionMatch(request)); + } + + public void testParameter() throws UnsupportedEncodingException { + MockRequest request = new MockRequest(); + Condition condition = new Condition(); + condition.setType("parameter"); + condition.setName("reqparam"); + condition.setValue("[0-9]+"); + condition.initialise(); + assertNull("condition must not match", condition.getConditionMatch(request)); + + request.addParameter("reqparam", "1000245"); + assertNotNull("condition must match", condition.getConditionMatch(request)); + } + + // Condition: Equal, Pattern: Null, Value: Null, Result should be: Match. + public void testParameterNull1() throws UnsupportedEncodingException { + MockRequest request = new MockRequest(); + Condition condition = new Condition(); + condition.setType("parameter"); + condition.setName("reqparam"); + condition.setValue(""); + condition.setOperator("equal"); + condition.initialise(); + assertNull("condition must match", condition.getConditionMatch(request)); + } + + // Condition: Equal, Pattern: Null, Value: Not Null, Result should be: No match. + public void testParameterNull2() throws UnsupportedEncodingException { + MockRequest request = new MockRequest(); + Condition condition = new Condition(); + condition.setType("parameter"); + condition.setName("reqparam"); + condition.setValue(""); + condition.setOperator("equal"); + condition.initialise(); + request.addParameter("reqparam", "1000245"); + assertNotNull("condition must not match", condition.getConditionMatch(request)); + } + + // Condition: Not Equal, Pattern: Null, Value: Null, Result should be: No match. + public void testParameterNull3() throws UnsupportedEncodingException { + MockRequest request = new MockRequest(); + Condition condition = new Condition(); + condition.setType("parameter"); + condition.setName("reqparam"); + condition.setValue(""); + condition.setOperator("notequal"); + condition.initialise(); + assertNotNull("condition must not match", condition.getConditionMatch(request)); + request.addParameter("reqparam", "1000245"); + // Condition: Not Equal, Pattern: Null, Value: Not Null, Result should be: match. + assertNull("condition must match", condition.getConditionMatch(request)); + } + + // Condition: Not Equal, Pattern: Null, Value: Not Null, Result should be: match. + public void testParameterNull4() throws UnsupportedEncodingException { + MockRequest request = new MockRequest(); + Condition condition = new Condition(); + condition.setType("parameter"); + condition.setName("reqparam"); + condition.setValue(""); + condition.setOperator("notequal"); + condition.initialise(); + request.addParameter("reqparam", "1000245"); + assertNull("condition must match", condition.getConditionMatch(request)); + } + + public void testPathInfo() throws UnsupportedEncodingException { + MockRequest request = new MockRequest(); + Condition condition = new Condition(); + condition.setType("path-info"); + condition.setValue("afr[aeiou]ca"); + condition.initialise(); + assertNull("condition must not match", condition.getConditionMatch(request)); + + request.setPathInfo("africa"); + assertNotNull("condition must match", condition.getConditionMatch(request)); + } + + public void testPathTranslated() throws UnsupportedEncodingException { + MockRequest request = new MockRequest(); + Condition condition = new Condition(); + condition.setType("path-translated"); + condition.setValue("/!@&"); + condition.initialise(); + assertNull("condition must not match", condition.getConditionMatch(request)); + + request.setPathTranslated("/!@&"); + assertNotNull("condition must match", condition.getConditionMatch(request)); + } + + public void testProtocol() throws UnsupportedEncodingException { + MockRequest request = new MockRequest(); + Condition condition = new Condition(); + condition.setType("protocol"); + condition.setValue("HTTP/1\\.[1-2]"); + condition.initialise(); + request.setProtocol("HTTP/2.0"); + assertNull("condition must not match", condition.getConditionMatch(request)); + + request.setProtocol("HTTP/1.2"); + assertNotNull("condition must match", condition.getConditionMatch(request)); + } + + public void testQueryString() throws UnsupportedEncodingException { + MockRequest request = new MockRequest(); + Condition condition = new Condition(); + condition.setType("query-string"); + condition.setValue(".*¶m=[0-9]+.*"); + condition.initialise(); + assertNull("condition must not match", condition.getConditionMatch(request)); + + request.setQueryString("?aaa=dsdsd¶m=2333&asdsa=sdds"); + assertNotNull("condition must match", condition.getConditionMatch(request)); + } + + public void testRemoteAddr() throws UnsupportedEncodingException { + MockRequest request = new MockRequest(); + Condition condition = new Condition(); + condition.setType("remote-addr"); + condition.setValue("192.168.[0-9]+.[0-9]+"); + condition.initialise(); + assertNull("condition must not match", condition.getConditionMatch(request)); + + request.setRemoteAddr("192.168.184.23"); + assertNotNull("condition must match", condition.getConditionMatch(request)); + } + + public void testRemoteHost() throws UnsupportedEncodingException { + MockRequest request = new MockRequest(); + Condition condition = new Condition(); + condition.setType("remote-host"); + condition.setValue("\\w+\\.tuckey.org"); + condition.initialise(); + assertNull("condition must not match", condition.getConditionMatch(request)); + + request.setRemoteHost("toaster.tuckey.org"); + assertNotNull("condition must match", condition.getConditionMatch(request)); + } + + public void testRemoteUser() throws UnsupportedEncodingException { + MockRequest request = new MockRequest(); + Condition condition = new Condition(); + condition.setType("remote-user"); + condition.setValue("p.\\w+"); + condition.initialise(); + assertNull("condition must not match", condition.getConditionMatch(request)); + + request.setRemoteUser("p.smith"); + assertNotNull("condition must match", condition.getConditionMatch(request)); + } + + public void testRequestedSessionId() throws UnsupportedEncodingException { + MockRequest request = new MockRequest(); + Condition condition = new Condition(); + condition.setType("requested-session-id"); + condition.setValue("\\w+\\.sec[0-6]+"); + condition.initialise(); + assertNull("condition must not match", condition.getConditionMatch(request)); + + request.setRequestedSessionId("sdfjsdfhkjhk897fd.sec03"); + assertNotNull("condition must match", condition.getConditionMatch(request)); + } + + public void testRequestedSessionIdFromCookie() throws UnsupportedEncodingException { + MockRequest request = new MockRequest(); + Condition condition = new Condition(); + condition.setType("requested-session-id-from-cookie"); + condition.setValue("true"); + condition.initialise(); + assertNull("condition must not match", condition.getConditionMatch(request)); + + request.setRequestedSessionIdFromCookie(true); + assertNotNull("condition must match", condition.getConditionMatch(request)); + } + + public void testRequestedSessionIdFromURL() throws UnsupportedEncodingException { + MockRequest request = new MockRequest(); + Condition condition = new Condition(); + condition.setType("requested-session-id-from-url"); + condition.setValue("true"); + condition.initialise(); + assertNull("condition must not match", condition.getConditionMatch(request)); + + request.setRequestedSessionIdFromURL(true); + assertNotNull("condition must match", condition.getConditionMatch(request)); + } + + public void testRequestedSessionIdValid() throws UnsupportedEncodingException { + MockRequest request = new MockRequest(); + Condition condition = new Condition(); + condition.setType("requested-session-id-valid"); + condition.setValue("true"); + condition.initialise(); + assertNull("condition must not match", condition.getConditionMatch(request)); + + request.setRequestedSessionIdValid(true); + assertNotNull("condition must match", condition.getConditionMatch(request)); + } + + public void testRequestUri() throws UnsupportedEncodingException { + MockRequest request = new MockRequest(); + Condition condition = new Condition(); + condition.setType("request-uri"); + condition.setValue("\\d"); + condition.initialise(); + assertNull("condition must not match", condition.getConditionMatch(request)); + + request.setRequestURI("2"); + assertNotNull("condition must match", condition.getConditionMatch(request)); + } + + public void testRequestUrl() throws UnsupportedEncodingException { + MockRequest request = new MockRequest(); + Condition condition = new Condition(); + condition.setType("request-url"); + condition.setValue("\\d"); + condition.initialise(); + assertNull("condition must not match", condition.getConditionMatch(request)); + + request.setRequestURL("2"); + assertNotNull("condition must match", condition.getConditionMatch(request)); + } + + public void testSessionAttribute() throws UnsupportedEncodingException { + MockRequest request = new MockRequest(); + Condition condition = new Condition(); + condition.setType("session-attribute"); + condition.setValue("someval"); + condition.initialise(); + assertNull("condition must not match", condition.getConditionMatch(request)); + + Condition condition2 = new Condition(); + condition2.setType("session-attribute"); + condition2.setName("someatt"); + condition2.setValue("someval"); + condition2.initialise(); + assertNull("condition must not match", condition2.getConditionMatch(request)); + + request.getSession(true).setAttribute("someatt", "someval"); + + Condition condition3 = new Condition(); + condition3.setType("session-attribute"); + condition3.setName("someatt"); + condition3.setValue("someval"); + condition3.initialise(); + assertNotNull("condition must match", condition3.getConditionMatch(request)); + } + + public void testSessionIsNew() throws UnsupportedEncodingException { + MockRequest request = new MockRequest(); + Condition condition = new Condition(); + condition.setType("session-isnew"); + condition.setValue("yes"); + condition.setOperator("notequal"); + condition.initialise(); + assertNotNull("condition must match", condition.getConditionMatch(request)); + + request.setSessionNew(true); + assertNull("condition must not match", condition.getConditionMatch(request)); + } + + public void testServerName() throws UnsupportedEncodingException { + MockRequest request = new MockRequest(); + Condition condition = new Condition(); + condition.setType("server-name"); + condition.setValue("dev.*"); + condition.initialise(); + assertNull("condition must not match", condition.getConditionMatch(request)); + + request.setServerName("dev.googil.com"); + assertNotNull("condition must match", condition.getConditionMatch(request)); + } + + public void testScheme() throws UnsupportedEncodingException { + MockRequest request = new MockRequest(); + Condition condition = new Condition(); + condition.setType("scheme"); + condition.setValue("http"); + condition.initialise(); + assertNull("condition must not match", condition.getConditionMatch(request)); + + request.setScheme("http"); + assertNotNull("condition must match", condition.getConditionMatch(request)); + } + + + public void testConditionHeader() { + MockRequest request = new MockRequest(); + Condition condition = new Condition(); + condition.setName("some header"); + condition.setValue("tester"); + condition.initialise(); + assertNull("condition must not match", condition.getConditionMatch(request)); + + request.setHeader("some header", "tester"); + assertNotNull("condition must match", condition.getConditionMatch(request)); + + Condition condition2 = new Condition(); + condition2.setName(" "); + condition2.setValue("tester"); + assertFalse("condition must not initialise", condition2.initialise()); + assertNull("condition must not match", condition2.getConditionMatch(request)); + + Condition condition3 = new Condition(); + condition3.setName("bonus"); + assertTrue("condition must initialise and check for exists", condition3.initialise()); + assertNull("condition must not match", condition3.getConditionMatch(request)); + request.setHeader("bonus", "tester"); + assertNotNull("condition must match", condition3.getConditionMatch(request)); + + Condition condition4 = new Condition(); + condition4.setName("portashed"); + condition4.setOperator("notequal"); + + assertTrue("condition must initialise and check for exists", condition4.initialise()); + assertNotNull("condition must match", condition4.getConditionMatch(request)); + request.setHeader("portashed", "tester"); + assertNull("condition must not match", condition4.getConditionMatch(request)); + + } + + public void testConditionMethod() { + MockRequest request = new MockRequest(); + request.setMethod("HEAD"); + Condition condition = new Condition(); + condition.setType("method"); + condition.setValue("H[A-Z]AD"); + condition.initialise(); + assertNotNull("condition must match", condition.getConditionMatch(request)); + } + + + public void testConditionIsUserInRole() { + MockRequest request = new MockRequest(); + request.addRole("devil"); + Condition condition = new Condition(); + condition.setType("user-in-role"); + condition.setName("devil"); + condition.initialise(); + assertNotNull("user should be in this role", condition.getConditionMatch(request)); + + Condition condition2 = new Condition(); + condition2.setType("user-in-role"); + condition2.setName("angel"); + condition2.initialise(); + assertNull("bad user in role must not match", condition2.getConditionMatch(request)); + + Condition condition3 = new Condition(); + condition3.setType("user-in-role"); + condition3.setValue("devil"); + condition3.initialise(); + assertNotNull("value instead of name should match", condition3.getConditionMatch(request)); + + Condition condition4 = new Condition(); + condition4.setType("user-in-role"); + condition4.setValue("admin"); + condition4.setOperator("notequal"); + condition4.initialise(); + assertNotNull("value instead of name should match", condition4.getConditionMatch(request)); + } + + public void testConditionPort() { + MockRequest request = new MockRequest(); + request.setServerPort(9001); + Condition condition = new Condition(); + condition.setType("port"); + condition.setValue("9001"); + condition.initialise(); + assertNotNull("condition must match", condition.getConditionMatch(request)); + + Condition condition2 = new Condition(); + condition2.setType("port"); + condition2.setValue(" 9001"); + condition2.initialise(); + assertNotNull("condition must match", condition2.getConditionMatch(request)); + // check re-init + condition2.initialise(); + assertNotNull("condition must match", condition2.getConditionMatch(request)); + + Condition condition3 = new Condition(); + condition3.setType("port"); + condition3.setValue("aaa"); + condition3.initialise(); + assertNull("condition must not match", condition3.getConditionMatch(request)); + } + + +} From 42eb4f8658e50a9de3d36d469cacdc2d6b0257b2 Mon Sep 17 00:00:00 2001 From: Paul Tuckey Date: Sat, 1 Jul 2023 16:34:54 +1200 Subject: [PATCH 15/19] progress --- container-test/example-webapp/pom.xml | 2 +- .../src/main/webapp/WEB-INF/urlrewrite.xml | 3 +- .../ContainerTestBase.java | 18 ++++++- .../WebappDecodeNoneITTest.java | 10 ---- .../WebappDecodeUtf8ITTest.java | 4 +- .../WebappHttpITTest.java | 47 +++++++++---------- .../WebappModStyleHttpITTest.java | 20 +++++--- 7 files changed, 54 insertions(+), 50 deletions(-) diff --git a/container-test/example-webapp/pom.xml b/container-test/example-webapp/pom.xml index 24455639..348233d9 100644 --- a/container-test/example-webapp/pom.xml +++ b/container-test/example-webapp/pom.xml @@ -3,7 +3,7 @@ 4.0.0 org.tuckey example-webapp - jar + war 5.0.0-SNAPSHOT Example Webapp http://www.tuckey.org/urlrewrite/ diff --git a/container-test/example-webapp/src/main/webapp/WEB-INF/urlrewrite.xml b/container-test/example-webapp/src/main/webapp/WEB-INF/urlrewrite.xml index dfcff1da..782e6fe3 100644 --- a/container-test/example-webapp/src/main/webapp/WEB-INF/urlrewrite.xml +++ b/container-test/example-webapp/src/main/webapp/WEB-INF/urlrewrite.xml @@ -46,7 +46,6 @@ hello! none-fool $1 - DELETE /settest.jsp @@ -62,7 +61,7 @@ 1970 - 2020 + 2045 /time/year/current /echo.jsp?echo=yearisbetween1970and3000 diff --git a/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/ContainerTestBase.java b/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/ContainerTestBase.java index b2f38d09..c0b7b688 100644 --- a/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/ContainerTestBase.java +++ b/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/ContainerTestBase.java @@ -37,7 +37,8 @@ import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.methods.GetMethod; import org.testcontainers.containers.GenericContainer; -import org.testcontainers.containers.wait.strategy.Wait; +import org.testcontainers.containers.output.OutputFrame; +import org.testcontainers.containers.output.ToStringConsumer; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; @@ -45,6 +46,7 @@ import java.io.IOException; import java.io.PrintWriter; import java.nio.file.Paths; +import java.time.Duration; @Testcontainers @@ -63,9 +65,14 @@ public abstract class ContainerTestBase { .withExposedPorts(8080) .withFileSystemBind(webappPath, "/usr/local/tomcat/webapps/webapp.war"); + ToStringConsumer toStringConsumer = new ToStringConsumer(); public void setUp() throws Exception { container.start(); + + container.followOutput(toStringConsumer, OutputFrame.OutputType.STDOUT); + container.followOutput(toStringConsumer, OutputFrame.OutputType.STDERR); + System.out.println(container.getContainerId()); System.out.println("HOST " + container.getHost()); System.out.println("PORT " + container.getFirstMappedPort()); @@ -90,12 +97,19 @@ public void setUp() throws Exception { client.executeMethod(method); } + public void tearDown() throws InterruptedException { + Thread.sleep(1); + // useful for debugging + //Thread.sleep(5 * 60 * 1000); + // go to tomcat container then files /usr/local/tomcat/logs + } + protected String getBaseUrl() { return "http://" + container.getHost() + ":" + container.getFirstMappedPort() + "/" + getApp(); } protected void recordRewriteStatus() throws IOException { - GetMethod method = new GetMethod(getBaseUrl() + "/" + getApp() + "/rewrite-status"); + GetMethod method = new GetMethod(getBaseUrl() + "/rewrite-status"); method.setFollowRedirects(false); client.executeMethod(method); File statusFile = new File(containerId + "-" + getApp() + "-" + getConf() + "-rewrite-status.html"); diff --git a/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeNoneITTest.java b/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeNoneITTest.java index 86bfbed8..dde69967 100644 --- a/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeNoneITTest.java +++ b/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeNoneITTest.java @@ -48,16 +48,6 @@ public void testTestUtf() throws ServletException, IOException { assertEquals("/" + getApp() + "/utf-redir/done/" + encodedStr + "/", method.getResponseHeader("Location").getValue()); } - @Test - public void testNoDecode() throws IOException { - if ( "orion2.0.5".equals(getContainerId())) return; // jsp's with % in path not supported - if ( "tomcat-4.1.31".equals(getContainerId())) return; // jsp's with % in path not supported - - GetMethod method = new GetMethod(getBaseUrl() + "/no-decode-test/D%25%2cD"); - client.executeMethod(method); - assertEquals("this is no-decode-test target jsp", method.getResponseBodyAsString()); - } - @Test public void testQueryStringNoDecode() throws IOException { if ( "orion2.0.5".equals(getContainerId())) return; // orion cannot correctly encode & into %26 diff --git a/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeUtf8ITTest.java b/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeUtf8ITTest.java index f720c420..601bb5ab 100644 --- a/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeUtf8ITTest.java +++ b/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeUtf8ITTest.java @@ -56,10 +56,8 @@ public void testTestUtf() throws ServletException, IOException { method.setRequestHeader("Accept-Encoding", "utf8"); method.setFollowRedirects(false); client.executeMethod(method); - assertEquals(getBaseUrl() + "/utf-redir/done/", method.getResponseHeader("Location").getValue()); + assertEquals("/" + getApp() + "/utf-redir/done/", method.getResponseHeader("Location").getValue()); } - - } diff --git a/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappHttpITTest.java b/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappHttpITTest.java index 201c7dd1..0e9cc12e 100644 --- a/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappHttpITTest.java +++ b/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappHttpITTest.java @@ -3,11 +3,11 @@ * All rights reserved. * ==================================================================== * Licensed under the BSD License. Text as follows. - * + *

* Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: - * + *

* - Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * - Redistributions in binary form must reproduce the above @@ -17,7 +17,7 @@ * - Neither the name tuckey.org nor the names of its contributors * may be used to endorse or promote products derived from this * software without specific prior written permission. - * + *

* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS @@ -34,13 +34,12 @@ */ package org.tuckey.web.filters.urlrewriteviacontainer; -import jakarta.servlet.ServletException; import org.apache.commons.httpclient.Header; import org.apache.commons.httpclient.methods.GetMethod; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.tuckey.web.filters.urlrewrite.utils.StringUtils; -import org.xml.sax.SAXException; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -68,8 +67,13 @@ public void beforeEach() throws Exception { super.recordRewriteStatus(); } + @AfterEach + public void afterEach() throws InterruptedException { + super.tearDown(); + } + @Test - public void testProduct() throws IOException, SAXException, InterruptedException { + public void testProduct() throws IOException { GetMethod method = new GetMethod(getBaseUrl() + "/products/987"); client.executeMethod(method); assertEquals("product 987", method.getResponseBodyAsString()); @@ -77,32 +81,32 @@ public void testProduct() throws IOException, SAXException, InterruptedException @Test - public void testSimpleDistEx() throws ServletException, IOException, SAXException { + public void testSimpleDistEx() throws IOException { GetMethod method = new GetMethod(getBaseUrl() + "/test/status/"); method.setFollowRedirects(false); client.executeMethod(method); - assertEquals(getBaseUrl() + "/rewrite-status", method.getResponseHeader("Location").getValue()); + assertEquals("/" + getApp() + "/rewrite-status", method.getResponseHeader("Location").getValue()); } @Test - public void testBasicSets() throws ServletException, IOException, SAXException { + public void testBasicSets() throws IOException { GetMethod method = new GetMethod(getBaseUrl() + "/settest/674"); client.executeMethod(method); assertNotNull(method.getResponseHeader("cache-control")); assertEquals("testsession: hello!, " + "param.settest1: 674, " + - "method: DELETE", method.getResponseBodyAsString()); + "method: GET", method.getResponseBodyAsString()); } @Test - public void testMultipleProduct() throws ServletException, IOException, SAXException { + public void testMultipleProduct() throws IOException { GetMethod method = new GetMethod(getBaseUrl() + "/multiple/products/987"); client.executeMethod(method); assertEquals("product 987", method.getResponseBodyAsString()); } @Test - public void testNullTo() throws ServletException, IOException { + public void testNullTo() throws IOException { GetMethod method = new GetMethod(getBaseUrl() + "/hideme/anb.jsp;dsaddd?asdasds#sdsfd"); client.executeMethod(method); assertEquals(403, method.getStatusCode()); // "should have status set", @@ -111,14 +115,14 @@ public void testNullTo() throws ServletException, IOException { } @Test - public void testYear() throws ServletException, IOException { + public void testYear() throws IOException { GetMethod method = new GetMethod(getBaseUrl() + "/time/year/current"); client.executeMethod(method); assertEquals("echo yearisbetween1970and3000", method.getResponseBodyAsString()); } @Test - public void testTestAxis() throws ServletException, IOException { + public void testTestAxis() throws IOException { GetMethod method = new GetMethod(getBaseUrl() + "/services/blah?qwerty"); method.setFollowRedirects(false); client.executeMethod(method); @@ -126,7 +130,7 @@ public void testTestAxis() throws ServletException, IOException { } @Test - public void testTestErik() throws ServletException, IOException { + public void testTestErik() throws IOException { GetMethod method = new GetMethod(getBaseUrl() + "/eriktest/hi.ho"); method.setFollowRedirects(false); method.addRequestHeader(new Header("host", "blah.com")); @@ -135,15 +139,15 @@ public void testTestErik() throws ServletException, IOException { } @Test - public void testTestEncode() throws ServletException, IOException { + public void testTestEncode() throws IOException { GetMethod method = new GetMethod(getBaseUrl() + "/went%20to%20bahamas/"); method.setFollowRedirects(false); client.executeMethod(method); - assertEquals(getBaseUrl() + "/jamaica/", method.getResponseHeader("Location").getValue()); + assertEquals("/" + getApp() + "/jamaica/", method.getResponseHeader("Location").getValue()); } @Test - public void testSimpleRun() throws ServletException, IOException { + public void testSimpleRun() throws IOException { GetMethod method = new GetMethod(getBaseUrl() + "/run/test/test1"); client.executeMethod(method); assertEquals("this is " + TestRunObj.class.getName(), method.getResponseBodyAsString()); @@ -181,11 +185,4 @@ private String inflateGzipToString(InputStream is) throws IOException { return os.toString(); } - @Test - public void testSampleAnnotation() throws IOException { - GetMethod method = new GetMethod(getBaseUrl() + "/do-something/7"); - client.executeMethod(method); - assertEquals(method.getResponseBodyAsString(), "AnnotatedClassSample id=7"); - } - } diff --git a/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappModStyleHttpITTest.java b/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappModStyleHttpITTest.java index 1c44bb29..c6a512aa 100644 --- a/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappModStyleHttpITTest.java +++ b/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappModStyleHttpITTest.java @@ -35,6 +35,7 @@ package org.tuckey.web.filters.urlrewriteviacontainer; import org.apache.commons.httpclient.methods.GetMethod; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.xml.sax.SAXException; @@ -51,7 +52,7 @@ public class WebappModStyleHttpITTest extends ContainerTestBase { protected String getApp() { - return "webapp/mod"; + return "webapp"; } @BeforeEach @@ -60,25 +61,30 @@ public void beforeEach() throws Exception { super.recordRewriteStatus(); } + @AfterEach + public void afterEach() throws InterruptedException { + super.tearDown(); + } + @Test - public void testSimpleTest() throws ServletException, IOException, SAXException { - GetMethod method = new GetMethod(getBaseUrl() + "/index.jsp"); + public void testSimpleTest() throws IOException { + GetMethod method = new GetMethod(getBaseUrl() + "/mod/index.jsp"); method.setFollowRedirects(false); client.executeMethod(method); assertEquals("this is index.jsp", method.getResponseBodyAsString()); } @Test - public void testSimpleTestRewrite() throws ServletException, IOException, SAXException { - GetMethod method = new GetMethod(getBaseUrl() + "/simple/test"); + public void testSimpleTestRewrite() throws IOException { + GetMethod method = new GetMethod(getBaseUrl() + "/mod/simple/test"); method.setFollowRedirects(false); client.executeMethod(method); assertEquals("this is index.jsp", method.getResponseBodyAsString()); } @Test - public void testStatus1() throws ServletException, IOException, SAXException { - GetMethod method = new GetMethod(getBaseUrl() + "/rewrite-status"); + public void testStatus1() throws IOException { + GetMethod method = new GetMethod(getBaseUrl() + "/mod/rewrite-status"); method.setFollowRedirects(false); client.executeMethod(method); assertTrue(method.getResponseBodyAsString().contains("Running Status")); From c486b81271f196c1e59ad4378be5a08e5986dbee Mon Sep 17 00:00:00 2001 From: Paul Tuckey Date: Sat, 1 Jul 2023 16:40:20 +1200 Subject: [PATCH 16/19] progress --- container-test/test-with-testcontainers/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/container-test/test-with-testcontainers/pom.xml b/container-test/test-with-testcontainers/pom.xml index 2303099c..af6db377 100644 --- a/container-test/test-with-testcontainers/pom.xml +++ b/container-test/test-with-testcontainers/pom.xml @@ -53,6 +53,7 @@ org.tuckey example-webapp 5.0.0-SNAPSHOT + war test From d2e8b31ef821ede3ba1d3370fea031a6bb4378ff Mon Sep 17 00:00:00 2001 From: Paul Tuckey Date: Sat, 1 Jul 2023 16:44:38 +1200 Subject: [PATCH 17/19] progress --- .../web/filters/urlrewriteviacontainer/WebappHttpITTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappHttpITTest.java b/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappHttpITTest.java index 0e9cc12e..b5f26ffb 100644 --- a/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappHttpITTest.java +++ b/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappHttpITTest.java @@ -150,7 +150,7 @@ public void testTestEncode() throws IOException { public void testSimpleRun() throws IOException { GetMethod method = new GetMethod(getBaseUrl() + "/run/test/test1"); client.executeMethod(method); - assertEquals("this is " + TestRunObj.class.getName(), method.getResponseBodyAsString()); + assertEquals("this is TestRunObj", method.getResponseBodyAsString()); } @Test From 3c2a51825518dbd85e1909c95b48315c58b65e3e Mon Sep 17 00:00:00 2001 From: Paul Tuckey Date: Sat, 1 Jul 2023 16:45:34 +1200 Subject: [PATCH 18/19] progress --- .../WebappHttpITTest.java | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappHttpITTest.java b/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappHttpITTest.java index b5f26ffb..cacbaab9 100644 --- a/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappHttpITTest.java +++ b/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappHttpITTest.java @@ -8,15 +8,15 @@ * modification, are permitted provided that the following conditions * are met: *

- * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * - Neither the name tuckey.org nor the names of its contributors - * may be used to endorse or promote products derived from this - * software without specific prior written permission. + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * - Neither the name tuckey.org nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. *

* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT @@ -47,8 +47,8 @@ import java.util.zip.GZIPInputStream; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertFalse; /** @@ -111,7 +111,7 @@ public void testNullTo() throws IOException { client.executeMethod(method); assertEquals(403, method.getStatusCode()); // "should have status set", String CONTENT = "

some content

"; - assertFalse(CONTENT.equals(StringUtils.trim(method.getResponseBodyAsString()))); // "should not output above content" + assertNotEquals(CONTENT, StringUtils.trim(method.getResponseBodyAsString())); // "should not output above content" } @Test From 0d45dfb72afac60a52c2ba4fe4db3a5c7983980d Mon Sep 17 00:00:00 2001 From: Paul Tuckey Date: Mon, 3 Jul 2023 09:05:45 +1200 Subject: [PATCH 19/19] progress --- .../web/filters/urlrewriteviacontainer/WebappHttpITTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappHttpITTest.java b/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappHttpITTest.java index cacbaab9..6135ac69 100644 --- a/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappHttpITTest.java +++ b/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappHttpITTest.java @@ -150,7 +150,7 @@ public void testTestEncode() throws IOException { public void testSimpleRun() throws IOException { GetMethod method = new GetMethod(getBaseUrl() + "/run/test/test1"); client.executeMethod(method); - assertEquals("this is TestRunObj", method.getResponseBodyAsString()); + assertEquals("this is org.tuckey.web.filters.urlrewriteviacontainer.TestRunObj", method.getResponseBodyAsString()); } @Test