This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch 9.0.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/9.0.x by this push: new 9ad44a4cb5 Code clean-up. No functional change. 9ad44a4cb5 is described below commit 9ad44a4cb5e2a6e08d721da07bff896a0e053fc9 Author: Mark Thomas <ma...@apache.org> AuthorDate: Thu Mar 30 23:34:21 2023 +0100 Code clean-up. No functional change. --- .../catalina/valves/rewrite/TestResolverSSL.java | 5 +- .../catalina/valves/rewrite/TestRewriteValve.java | 220 +++++++++------------ .../catalina/valves/rewrite/TesterRewriteMapA.java | 2 +- 3 files changed, 98 insertions(+), 129 deletions(-) diff --git a/test/org/apache/catalina/valves/rewrite/TestResolverSSL.java b/test/org/apache/catalina/valves/rewrite/TestResolverSSL.java index 14198bd2bd..641b55eebf 100644 --- a/test/org/apache/catalina/valves/rewrite/TestResolverSSL.java +++ b/test/org/apache/catalina/valves/rewrite/TestResolverSSL.java @@ -53,6 +53,7 @@ public class TestResolverSSL extends TomcatBaseTest { Assert.assertTrue(res.toString().indexOf("OK") > 0); } + //@formatter:off // List from https://httpd.apache.org/docs/2.4/mod/mod_ssl.html#envvars private static final String[] keys = { "HTTPS", @@ -110,12 +111,12 @@ public class TestResolverSSL extends TomcatBaseTest { "SSL_SRP_USER", "SSL_SRP_USERINFO", "SSL_TLS_SNI" }; + //@formatter:on public static class ResolverTestValve extends ValveBase { @Override - public void invoke(Request request, Response response) - throws IOException, ServletException { + public void invoke(Request request, Response response) throws IOException, ServletException { PrintWriter writer = response.getWriter(); Resolver resolver = new ResolverImpl(request); for (String key : keys) { diff --git a/test/org/apache/catalina/valves/rewrite/TestRewriteValve.java b/test/org/apache/catalina/valves/rewrite/TestRewriteValve.java index e558394cec..6049d3e9fc 100644 --- a/test/org/apache/catalina/valves/rewrite/TestRewriteValve.java +++ b/test/org/apache/catalina/valves/rewrite/TestRewriteValve.java @@ -127,26 +127,22 @@ public class TestRewriteValve extends TomcatBaseTest { @Test public void testRewriteMap08() throws Exception { - doTestRewrite("RewriteMap lc int:tolower\n" + - "RewriteRule ^(.*) ${lc:$1}", "/C/AaA", "/c/aaa"); + doTestRewrite("RewriteMap lc int:tolower\n" + "RewriteRule ^(.*) ${lc:$1}", "/C/AaA", "/c/aaa"); } @Test public void testRewriteMap09() throws Exception { - doTestRewrite("RewriteMap lc int:toupper\n" + - "RewriteRule ^(.*) ${lc:$1}", "/w/aAa", "/W/AAA"); + doTestRewrite("RewriteMap lc int:toupper\n" + "RewriteRule ^(.*) ${lc:$1}", "/w/aAa", "/W/AAA"); } @Test public void testRewriteMap10() throws Exception { - doTestRewrite("RewriteMap lc int:escape\n" + - "RewriteRule ^(.*) ${lc:$1}", "/c/a%20aa", "/c/a%2520aa"); + doTestRewrite("RewriteMap lc int:escape\n" + "RewriteRule ^(.*) ${lc:$1}", "/c/a%20aa", "/c/a%2520aa"); } @Test public void testRewriteMap11() throws Exception { - doTestRewrite("RewriteMap lc int:unescape\n" + - "RewriteRule ^(.*) ${lc:$1}", "/c/a%2520aa", "/c/a%20aa"); + doTestRewrite("RewriteMap lc int:unescape\n" + "RewriteRule ^(.*) ${lc:$1}", "/c/a%2520aa", "/c/a%20aa"); } @@ -159,86 +155,86 @@ public class TestRewriteValve extends TomcatBaseTest { @Test public void testRewriteMap12() throws Exception { doTestRewrite("RewriteMap mapb txt:" + getTestConfDirectory() + "TesterRewriteMapB.txt\n" + - "RewriteRule /b/(.*).html$ /c/${mapb:$1}", "/b/a.html", "/c/aa"); + "RewriteRule /b/(.*).html$ /c/${mapb:$1}", "/b/a.html", "/c/aa"); } @Test public void testRewriteMap13() throws Exception { doTestRewrite("RewriteMap mapb txt:" + getTestConfDirectory() + "TesterRewriteMapB.txt\n" + - "RewriteRule /b/(.*).html$ /c/${mapb:$1|dd}", "/b/x.html", "/c/dd"); + "RewriteRule /b/(.*).html$ /c/${mapb:$1|dd}", "/b/x.html", "/c/dd"); } // BZ 62667 @Test public void testRewriteMap14() throws Exception { doTestRewrite("RewriteMap mapb txt:" + getTestConfDirectory() + "TesterRewriteMapB.txt\n" + - "RewriteRule /b/(.*).html$ /c/${mapb:$1|d$1d}", "/b/x.html", "/c/dxd"); + "RewriteRule /b/(.*).html$ /c/${mapb:$1|d$1d}", "/b/x.html", "/c/dxd"); } @Test public void testRewriteMap15() throws Exception { doTestRewrite("RewriteMap mapb txt:" + getTestConfDirectory() + "TesterRewriteMapB.txt\n" + - "RewriteRule /b/(.*).html$ /c/${mapb:a$1|dd}", "/b/a.html", "/c/aaaa"); + "RewriteRule /b/(.*).html$ /c/${mapb:a$1|dd}", "/b/a.html", "/c/aaaa"); } @Test public void testRewriteMap16() throws Exception { doTestRewrite("RewriteMap mapb txt:" + getTestConfDirectory() + "TesterRewriteMapB.txt\n" + - "RewriteRule /b/.* /c/${mapb:a}", "/b/a.html", "/c/aa"); + "RewriteRule /b/.* /c/${mapb:a}", "/b/a.html", "/c/aa"); } @Test public void testRewriteMap17() throws Exception { doTestRewrite("RewriteMap mapb txt:" + getTestConfDirectory() + "TesterRewriteMapB.txt\n" + - "RewriteRule /b/.* /c/${mapb:${mapb:a}}", "/b/a.html", "/c/aaaa"); + "RewriteRule /b/.* /c/${mapb:${mapb:a}}", "/b/a.html", "/c/aaaa"); } @Test public void testRewriteMap18() throws Exception { doTestRewrite("RewriteMap mapb txt:" + getTestConfDirectory() + "TesterRewriteMapB.txt\n" + - "RewriteRule /b/.* /c/${mapb:${mapb:a}}", "/b/a.html", "/c/aaaa"); + "RewriteRule /b/.* /c/${mapb:${mapb:a}}", "/b/a.html", "/c/aaaa"); } @Test(expected = IllegalArgumentException.class) public void testRewriteMap19() throws Exception { doTestRewrite("RewriteMap mapb txt:" + getTestConfDirectory() + "TesterRewriteMapB.txt first\n" + - "RewriteRule /b/(.*).html$ /c/${mapb:$1}", "/b/aa.html", "/c/aaaa"); + "RewriteRule /b/(.*).html$ /c/${mapb:$1}", "/b/aa.html", "/c/aaaa"); } @Test(expected = IllegalArgumentException.class) public void testRewriteMap20() throws Exception { doTestRewrite("RewriteMap mapb txt:" + getTestConfDirectory() + "TesterRewriteMapB.txt first second\n" + - "RewriteRule /b/(.*).html$ /c/${mapb:$1}", "/b/aa.html", "/c/aaaa"); + "RewriteRule /b/(.*).html$ /c/${mapb:$1}", "/b/aa.html", "/c/aaaa"); } @Test public void testRewriteMap21() throws Exception { doTestRewrite("RewriteMap mapb rnd:" + getTestConfDirectory() + "TesterRewriteMapC.txt\n" + - "RewriteRule /b/(.*).html$ /c/${mapb:$1}", "/b/a.html", "/c/aa"); + "RewriteRule /b/(.*).html$ /c/${mapb:$1}", "/b/a.html", "/c/aa"); } - //This test should succeed 50% of the runs as it depends on a random choice + // This test should succeed 50% of the runs as it depends on a random choice public void testRewriteMap22() throws Exception { doTestRewrite("RewriteMap mapb rnd:" + getTestConfDirectory() + "TesterRewriteMapC.txt\n" + - "RewriteRule /b/(.*).html$ /c/${mapb:$1}", "/b/b.html", "/c/bb"); + "RewriteRule /b/(.*).html$ /c/${mapb:$1}", "/b/b.html", "/c/bb"); } @Test public void testRewriteMap23() throws Exception { doTestRewrite("RewriteMap mapb rnd:" + getTestConfDirectory() + "TesterRewriteMapC.txt\n" + - "RewriteRule /b/(.*).html$ /c/${mapb:$1}", "/b/aa.html", "/c/aaaa"); + "RewriteRule /b/(.*).html$ /c/${mapb:$1}", "/b/aa.html", "/c/aaaa"); } @Test(expected = IllegalArgumentException.class) public void testRewriteMap24() throws Exception { doTestRewrite("RewriteMap mapb rnd:" + getTestConfDirectory() + "TesterRewriteMapC.txt first\n" + - "RewriteRule /b/(.*).html$ /c/${mapb:$1}", "/b/aa.html", "/c/aaaa"); + "RewriteRule /b/(.*).html$ /c/${mapb:$1}", "/b/aa.html", "/c/aaaa"); } @Test(expected = IllegalArgumentException.class) public void testRewriteMap25() throws Exception { doTestRewrite("RewriteMap mapb rnd:" + getTestConfDirectory() + "TesterRewriteMapC.txt first second\n" + - "RewriteRule /b/(.*).html$ /c/${mapb:$1}", "/b/aa.html", "/c/aaaa"); + "RewriteRule /b/(.*).html$ /c/${mapb:$1}", "/b/aa.html", "/c/aaaa"); } @Test @@ -249,15 +245,15 @@ public class TestRewriteValve extends TomcatBaseTest { @Test public void testRewriteEnvVarAndServerVar() throws Exception { System.setProperty("some_variable", "something"); - doTestRewrite("RewriteRule /b/(.*).html$ /c/%{ENV:some_variable}%{SERVLET_PATH}", - "/b/x.html", "/c/something/b/x.html"); + doTestRewrite("RewriteRule /b/(.*).html$ /c/%{ENV:some_variable}%{SERVLET_PATH}", "/b/x.html", + "/c/something/b/x.html"); } @Test public void testRewriteServerVarAndEnvVar() throws Exception { System.setProperty("some_variable", "something"); - doTestRewrite("RewriteRule /b/(.*).html$ /c%{SERVLET_PATH}/%{ENV:some_variable}", - "/b/x.html", "/c/b/x.html/something"); + doTestRewrite("RewriteRule /b/(.*).html$ /c%{SERVLET_PATH}/%{ENV:some_variable}", "/b/x.html", + "/c/b/x.html/something"); } @Test @@ -282,8 +278,8 @@ public class TestRewriteValve extends TomcatBaseTest { // https://bz.apache.org/bugzilla/show_bug.cgi?id=60013 public void testRewriteWithEncoding02() throws Exception { - doTestRewrite("RewriteRule ^/b/(.*)$ /c/?param=$1 [L]", - "/b/%E5%9C%A8%E7%BA%BF%E6%B5%8B%E8%AF%95", "/c/", "param=\u5728\u7EBF\u6D4B\u8BD5"); + doTestRewrite("RewriteRule ^/b/(.*)$ /c/?param=$1 [L]", "/b/%E5%9C%A8%E7%BA%BF%E6%B5%8B%E8%AF%95", "/c/", + "param=\u5728\u7EBF\u6D4B\u8BD5"); } @Test @@ -294,8 +290,7 @@ public class TestRewriteValve extends TomcatBaseTest { @Test public void testNonAsciiPathRedirect() throws Exception { - doTestRewrite("RewriteRule ^/b/(.*) /c/$1 [R]", - "/b/%E5%9C%A8%E7%BA%BF%E6%B5%8B%E8%AF%95", + doTestRewrite("RewriteRule ^/b/(.*) /c/$1 [R]", "/b/%E5%9C%A8%E7%BA%BF%E6%B5%8B%E8%AF%95", "/c/%E5%9C%A8%E7%BA%BF%E6%B5%8B%E8%AF%95"); } @@ -316,32 +311,28 @@ public class TestRewriteValve extends TomcatBaseTest { @Test public void testNonAsciiQueryString() throws Exception { - doTestRewrite("RewriteRule ^/b/(.*) /c?$1", - "/b/id=%E5%9C%A8%E7%BA%BF%E6%B5%8B%E8%AF%95", - "/c", "id=%E5%9C%A8%E7%BA%BF%E6%B5%8B%E8%AF%95"); + doTestRewrite("RewriteRule ^/b/(.*) /c?$1", "/b/id=%E5%9C%A8%E7%BA%BF%E6%B5%8B%E8%AF%95", "/c", + "id=%E5%9C%A8%E7%BA%BF%E6%B5%8B%E8%AF%95"); } @Test public void testNonAsciiQueryStringAndPath() throws Exception { - doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/$1?$2", - "/b/%E5%9C%A8%E7%BA%BF/id=%E6%B5%8B%E8%AF%95", + doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/$1?$2", "/b/%E5%9C%A8%E7%BA%BF/id=%E6%B5%8B%E8%AF%95", "/c/%E5%9C%A8%E7%BA%BF", "id=%E6%B5%8B%E8%AF%95"); } @Test public void testNonAsciiQueryStringAndRedirect() throws Exception { - doTestRewrite("RewriteRule ^/b/(.*) /c?$1 [R]", - "/b/id=%E5%9C%A8%E7%BA%BF%E6%B5%8B%E8%AF%95", - "/c", "id=%E5%9C%A8%E7%BA%BF%E6%B5%8B%E8%AF%95"); + doTestRewrite("RewriteRule ^/b/(.*) /c?$1 [R]", "/b/id=%E5%9C%A8%E7%BA%BF%E6%B5%8B%E8%AF%95", "/c", + "id=%E5%9C%A8%E7%BA%BF%E6%B5%8B%E8%AF%95"); } @Test public void testNonAsciiQueryStringAndPathAndRedirect() throws Exception { - doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/$1?$2 [R]", - "/b/%E5%9C%A8%E7%BA%BF/id=%E6%B5%8B%E8%AF%95", + doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/$1?$2 [R]", "/b/%E5%9C%A8%E7%BA%BF/id=%E6%B5%8B%E8%AF%95", "/c/%E5%9C%A8%E7%BA%BF", "id=%E6%B5%8B%E8%AF%95"); } @@ -358,8 +349,7 @@ public class TestRewriteValve extends TomcatBaseTest { public void testNonAsciiQueryStringAndPathAndRedirectWithB() throws Exception { // Note the double encoding of the result (httpd produces the same result) doTestRewrite("RewriteRule ^/b/(.*)/(.*)/id=(.*) /c/$1?filename=$2&id=$3 [B,R]", - "/b/%E5%9C%A8%E7%BA%BF/file01/id=%E6%B5%8B%E8%AF%95", - "/c/%25E5%259C%25A8%25E7%25BA%25BF", + "/b/%E5%9C%A8%E7%BA%BF/file01/id=%E6%B5%8B%E8%AF%95", "/c/%25E5%259C%25A8%25E7%25BA%25BF", "filename=file01&id=%25E6%25B5%258B%25E8%25AF%2595"); } @@ -367,32 +357,32 @@ public class TestRewriteValve extends TomcatBaseTest { @Test public void testUtf8WithBothQsFlagsNone() throws Exception { // Note %C2%A1 == \u00A1 - doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2", - "/b/%C2%A1/id=%C2%A1?di=%C2%AE", "/c/%C2%A1%C2%A1", "id=%C2%A1"); + doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2", "/b/%C2%A1/id=%C2%A1?di=%C2%AE", "/c/%C2%A1%C2%A1", + "id=%C2%A1"); } @Test public void testUtf8WithBothQsFlagsB() throws Exception { // Note %C2%A1 == \u00A1 - doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2 [B]", - "/b/%C2%A1/id=%C2%A1?di=%C2%AE", "/c/%C2%A1%25C2%25A1", "id=%25C2%25A1"); + doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2 [B]", "/b/%C2%A1/id=%C2%A1?di=%C2%AE", + "/c/%C2%A1%25C2%25A1", "id=%25C2%25A1"); } @Test public void testUtf8WithBothQsFlagsR() throws Exception { // Note %C2%A1 == \u00A1 - doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2 [R]", - "/b/%C2%A1/id=%C2%A1?di=%C2%AE", "/c/%C2%A1%C2%A1", "id=%C2%A1"); + doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2 [R]", "/b/%C2%A1/id=%C2%A1?di=%C2%AE", + "/c/%C2%A1%C2%A1", "id=%C2%A1"); } @Test public void testUtf8WithBothQsFlagsRB() throws Exception { // Note %C2%A1 == \u00A1 - doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2 [R,B]", - "/b/%C2%A1/id=%C2%A1?di=%C2%AE", "/c/%C2%A1%25C2%25A1", "id=%25C2%25A1"); + doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2 [R,B]", "/b/%C2%A1/id=%C2%A1?di=%C2%AE", + "/c/%C2%A1%25C2%25A1", "id=%25C2%25A1"); } @@ -401,8 +391,7 @@ public class TestRewriteValve extends TomcatBaseTest { // Note %C2%A1 == \u00A1 // Failing to escape the redirect means UTF-8 bytes in the Location // header which will be treated as if they are ISO-8859-1 - doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2 [R,NE]", - "/b/%C2%A1/id=%C2%A1?di=%C2%AE", null); + doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2 [R,NE]", "/b/%C2%A1/id=%C2%A1?di=%C2%AE", null); } @@ -411,35 +400,31 @@ public class TestRewriteValve extends TomcatBaseTest { // Note %C2%A1 == \u00A1 // Failing to escape the redirect means UTF-8 bytes in the Location // header which will be treated as if they are ISO-8859-1 - doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2 [R,B,NE]", - "/b/%C2%A1/id=%C2%A1?di=%C2%AE", null); + doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2 [R,B,NE]", "/b/%C2%A1/id=%C2%A1?di=%C2%AE", null); } @Test public void testUtf8WithBothQsFlagsBQSA() throws Exception { // Note %C2%A1 == \u00A1 - doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2 [B,QSA]", - "/b/%C2%A1/id=%C2%A1?di=%C2%AE", "/c/%C2%A1%25C2%25A1", - "id=%25C2%25A1&di=%C2%AE"); + doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2 [B,QSA]", "/b/%C2%A1/id=%C2%A1?di=%C2%AE", + "/c/%C2%A1%25C2%25A1", "id=%25C2%25A1&di=%C2%AE"); } @Test public void testUtf8WithBothQsFlagsRQSA() throws Exception { // Note %C2%A1 == \u00A1 - doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2 [R,QSA]", - "/b/%C2%A1/id=%C2%A1?di=%C2%AE", "/c/%C2%A1%C2%A1", - "id=%C2%A1&di=%C2%AE"); + doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2 [R,QSA]", "/b/%C2%A1/id=%C2%A1?di=%C2%AE", + "/c/%C2%A1%C2%A1", "id=%C2%A1&di=%C2%AE"); } @Test public void testUtf8WithBothQsFlagsRBQSA() throws Exception { // Note %C2%A1 == \u00A1 - doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2 [R,B,QSA]", - "/b/%C2%A1/id=%C2%A1?di=%C2%AE", "/c/%C2%A1%25C2%25A1", - "id=%25C2%25A1&di=%C2%AE"); + doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2 [R,B,QSA]", "/b/%C2%A1/id=%C2%A1?di=%C2%AE", + "/c/%C2%A1%25C2%25A1", "id=%25C2%25A1&di=%C2%AE"); } @@ -448,8 +433,7 @@ public class TestRewriteValve extends TomcatBaseTest { // Note %C2%A1 == \u00A1 // Failing to escape the redirect means UTF-8 bytes in the Location // header which will be treated as if they are ISO-8859-1 - doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2 [R,NE,QSA]", - "/b/%C2%A1/id=%C2%A1?di=%C2%AE", null); + doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2 [R,NE,QSA]", "/b/%C2%A1/id=%C2%A1?di=%C2%AE", null); } @@ -458,40 +442,37 @@ public class TestRewriteValve extends TomcatBaseTest { // Note %C2%A1 == \u00A1 // Failing to escape the redirect means UTF-8 bytes in the Location // header which will be treated as if they are ISO-8859-1 - doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2 [R,B,NE,QSA]", - "/b/%C2%A1/id=%C2%A1?di=%C2%AE", null); + doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2 [R,B,NE,QSA]", "/b/%C2%A1/id=%C2%A1?di=%C2%AE", null); } @Test public void testUtf8WithOriginalQsFlagsNone() throws Exception { // Note %C2%A1 == \u00A1 - doTestRewrite("RewriteRule ^/b/(.*) /c/\u00A1$1", - "/b/%C2%A1?id=%C2%A1", "/c/%C2%A1%C2%A1", "id=%C2%A1"); + doTestRewrite("RewriteRule ^/b/(.*) /c/\u00A1$1", "/b/%C2%A1?id=%C2%A1", "/c/%C2%A1%C2%A1", "id=%C2%A1"); } @Test public void testUtf8WithOriginalQsFlagsB() throws Exception { // Note %C2%A1 == \u00A1 - doTestRewrite("RewriteRule ^/b/(.*) /c/\u00A1$1 [B]", - "/b/%C2%A1?id=%C2%A1", "/c/%C2%A1%25C2%25A1", "id=%C2%A1"); + doTestRewrite("RewriteRule ^/b/(.*) /c/\u00A1$1 [B]", "/b/%C2%A1?id=%C2%A1", "/c/%C2%A1%25C2%25A1", + "id=%C2%A1"); } @Test public void testUtf8WithOriginalQsFlagsR() throws Exception { // Note %C2%A1 == \u00A1 - doTestRewrite("RewriteRule ^/b/(.*) /c/\u00A1$1 [R]", - "/b/%C2%A1?id=%C2%A1", "/c/%C2%A1%C2%A1", "id=%C2%A1"); + doTestRewrite("RewriteRule ^/b/(.*) /c/\u00A1$1 [R]", "/b/%C2%A1?id=%C2%A1", "/c/%C2%A1%C2%A1", "id=%C2%A1"); } @Test public void testUtf8WithOriginalQsFlagsRB() throws Exception { // Note %C2%A1 == \u00A1 - doTestRewrite("RewriteRule ^/b/(.*) /c/\u00A1$1 [R,B]", - "/b/%C2%A1?id=%C2%A1", "/c/%C2%A1%25C2%25A1", "id=%C2%A1"); + doTestRewrite("RewriteRule ^/b/(.*) /c/\u00A1$1 [R,B]", "/b/%C2%A1?id=%C2%A1", "/c/%C2%A1%25C2%25A1", + "id=%C2%A1"); } @@ -500,8 +481,7 @@ public class TestRewriteValve extends TomcatBaseTest { // Note %C2%A1 == \u00A1 // Failing to escape the redirect means UTF-8 bytes in the Location // header which will be treated as if they are ISO-8859-1 - doTestRewrite("RewriteRule ^/b/(.*) /c/\u00A1$1 [R,NE]", - "/b/%C2%A1?id=%C2%A1", null); + doTestRewrite("RewriteRule ^/b/(.*) /c/\u00A1$1 [R,NE]", "/b/%C2%A1?id=%C2%A1", null); } @@ -510,49 +490,47 @@ public class TestRewriteValve extends TomcatBaseTest { // Note %C2%A1 == \u00A1 // Failing to escape the redirect means UTF-8 bytes in the Location // header which will be treated as if they are ISO-8859-1 - doTestRewrite("RewriteRule ^/b/(.*) /c/\u00A1$1 [R,B,NE]", - "/b/%C2%A1?id=%C2%A1", null); + doTestRewrite("RewriteRule ^/b/(.*) /c/\u00A1$1 [R,B,NE]", "/b/%C2%A1?id=%C2%A1", null); } @Test public void testUtf8WithRewriteQsFlagsNone() throws Exception { // Note %C2%A1 == \u00A1 - doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2", - "/b/%C2%A1/id=%C2%A1", "/c/%C2%A1%C2%A1", "id=%C2%A1"); + doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2", "/b/%C2%A1/id=%C2%A1", "/c/%C2%A1%C2%A1", + "id=%C2%A1"); } @Test public void testUtf8WithRewriteQsFlagsB() throws Exception { // Note %C2%A1 == \u00A1 - doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2 [B]", - "/b/%C2%A1/id=%C2%A1", "/c/%C2%A1%25C2%25A1", "id=%25C2%25A1"); + doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2 [B]", "/b/%C2%A1/id=%C2%A1", "/c/%C2%A1%25C2%25A1", + "id=%25C2%25A1"); } @Test public void testUtf8WithRewriteQsFlagsR() throws Exception { // Note %C2%A1 == \u00A1 - doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2 [R]", - "/b/%C2%A1/id=%C2%A1", "/c/%C2%A1%C2%A1", "id=%C2%A1"); + doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2 [R]", "/b/%C2%A1/id=%C2%A1", "/c/%C2%A1%C2%A1", + "id=%C2%A1"); } @Test public void testUtf8WithBothQsFlagsQSA() throws Exception { // Note %C2%A1 == \u00A1 - doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2 [QSA]", - "/b/%C2%A1/id=%C2%A1?di=%C2%AE", "/c/%C2%A1%C2%A1", - "id=%C2%A1&di=%C2%AE"); + doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2 [QSA]", "/b/%C2%A1/id=%C2%A1?di=%C2%AE", + "/c/%C2%A1%C2%A1", "id=%C2%A1&di=%C2%AE"); } @Test public void testUtf8WithRewriteQsFlagsRB() throws Exception { // Note %C2%A1 == \u00A1 - doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2 [R,B]", - "/b/%C2%A1/id=%C2%A1", "/c/%C2%A1%25C2%25A1", "id=%25C2%25A1"); + doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2 [R,B]", "/b/%C2%A1/id=%C2%A1", "/c/%C2%A1%25C2%25A1", + "id=%25C2%25A1"); } @@ -561,8 +539,7 @@ public class TestRewriteValve extends TomcatBaseTest { // Note %C2%A1 == \u00A1 // Failing to escape the redirect means UTF-8 bytes in the Location // header which will be treated as if they are ISO-8859-1 - doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2 [R,NE]", - "/b/%C2%A1/id=%C2%A1", null); + doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2 [R,NE]", "/b/%C2%A1/id=%C2%A1", null); } @@ -571,16 +548,14 @@ public class TestRewriteValve extends TomcatBaseTest { // Note %C2%A1 == \u00A1 // Failing to escape the redirect means UTF-8 bytes in the Location // header which will be treated as if they are ISO-8859-1 - doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2 [R,B,NE]", - "/b/%C2%A1/id=%C2%A1", null); + doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2 [R,B,NE]", "/b/%C2%A1/id=%C2%A1", null); } @Test public void testUtf8WithRewriteQsFlagsQSA() throws Exception { // Note %C2%A1 == \u00A1 - doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2 [QSA]", - "/b/%C2%A1/id=%C2%A1", "/c/%C2%A1%C2%A1", + doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2 [QSA]", "/b/%C2%A1/id=%C2%A1", "/c/%C2%A1%C2%A1", "id=%C2%A1"); } @@ -634,9 +609,8 @@ public class TestRewriteValve extends TomcatBaseTest { @Test public void testFlagsNC() throws Exception { // https://bz.apache.org/bugzilla/show_bug.cgi?id=60116 - doTestRewrite("RewriteCond %{QUERY_STRING} a=([a-z]*) [NC]\n" - + "RewriteRule .* - [E=X-Test:%1]", - "/c?a=aAa", "/c", null, "aAa"); + doTestRewrite("RewriteCond %{QUERY_STRING} a=([a-z]*) [NC]\n" + "RewriteRule .* - [E=X-Test:%1]", "/c?a=aAa", + "/c", null, "aAa"); } @@ -644,33 +618,29 @@ public class TestRewriteValve extends TomcatBaseTest { public void testHostRewrite() throws Exception { // Based on report from users list that ':' was encoded and breaking // the redirect - doTestRewrite("RewriteRule ^/b(.*) http://%{HTTP_HOST}:%{SERVER_PORT}/a$1 [R]", - "/b/%255A", "/a/%255A"); + doTestRewrite("RewriteRule ^/b(.*) http://%{HTTP_HOST}:%{SERVER_PORT}/a$1 [R]", "/b/%255A", "/a/%255A"); } @Test public void testDefaultRedirect() throws Exception { - doTestRedirect("RewriteRule ^/from/a$ /to/b [R]", "/redirect/from/a", "/redirect/to/b", - 302); + doTestRedirect("RewriteRule ^/from/a$ /to/b [R]", "/redirect/from/a", "/redirect/to/b", 302); } @Test public void testTempRedirect() throws Exception { - doTestRedirect("RewriteRule ^/from/a$ /to/b [R=temp]", "/redirect/from/a", "/redirect/to/b", - 302); + doTestRedirect("RewriteRule ^/from/a$ /to/b [R=temp]", "/redirect/from/a", "/redirect/to/b", 302); } @Test public void testPermanentRedirect() throws Exception { - // Disable the following of redirects for this test only + // Disable the following of redirects for this test only boolean originalValue = HttpURLConnection.getFollowRedirects(); HttpURLConnection.setFollowRedirects(false); try { - doTestRedirect("RewriteRule ^/from/a$ /to/b [R=permanent]", "/redirect/from/a", "/redirect/to/b", - 301); + doTestRedirect("RewriteRule ^/from/a$ /to/b [R=permanent]", "/redirect/from/a", "/redirect/to/b", 301); } finally { HttpURLConnection.setFollowRedirects(originalValue); } @@ -679,12 +649,11 @@ public class TestRewriteValve extends TomcatBaseTest { @Test public void testSeeotherRedirect() throws Exception { - // Disable the following of redirects for this test only + // Disable the following of redirects for this test only boolean originalValue = HttpURLConnection.getFollowRedirects(); HttpURLConnection.setFollowRedirects(false); try { - doTestRedirect("RewriteRule ^/from/a$ /to/b [R=seeother]", "/redirect/from/a", "/redirect/to/b", - 303); + doTestRedirect("RewriteRule ^/from/a$ /to/b [R=seeother]", "/redirect/from/a", "/redirect/to/b", 303); } finally { HttpURLConnection.setFollowRedirects(originalValue); } @@ -693,12 +662,11 @@ public class TestRewriteValve extends TomcatBaseTest { @Test public void test307Redirect() throws Exception { - // Disable the following of redirects for this test only + // Disable the following of redirects for this test only boolean originalValue = HttpURLConnection.getFollowRedirects(); HttpURLConnection.setFollowRedirects(false); try { - doTestRedirect("RewriteRule ^/from/a$ /to/b [R=307]", "/redirect/from/a", "/redirect/to/b", - 307); + doTestRedirect("RewriteRule ^/from/a$ /to/b [R=307]", "/redirect/from/a", "/redirect/to/b", 307); } finally { HttpURLConnection.setFollowRedirects(originalValue); } @@ -755,14 +723,14 @@ public class TestRewriteValve extends TomcatBaseTest { } - private void doTestRewrite(String config, String request, String expectedURI, - String expectedQueryString) throws Exception { + private void doTestRewrite(String config, String request, String expectedURI, String expectedQueryString) + throws Exception { doTestRewrite(config, request, expectedURI, expectedQueryString, null); } - private void doTestRewrite(String config, String request, String expectedURI, - String expectedQueryString, String expectedAttributeValue) throws Exception { + private void doTestRewrite(String config, String request, String expectedURI, String expectedQueryString, + String expectedAttributeValue) throws Exception { Tomcat tomcat = getTomcatInstance(); @@ -809,8 +777,8 @@ public class TestRewriteValve extends TomcatBaseTest { } } - private void doTestRedirect(String config, String request, String expectedURI, - int expectedStatusCode) throws Exception { + private void doTestRedirect(String config, String request, String expectedURI, int expectedStatusCode) + throws Exception { Tomcat tomcat = getTomcatInstance(); @@ -830,8 +798,8 @@ public class TestRewriteValve extends TomcatBaseTest { ByteChunk res = new ByteChunk(); Map<String, List<String>> resHead = new HashMap<>(); - int rc = methodUrl("http://localhost:" + getPort() + request, res, - DEFAULT_CLIENT_TIMEOUT_MS, null, resHead, "GET", false); + int rc = methodUrl("http://localhost:" + getPort() + request, res, DEFAULT_CLIENT_TIMEOUT_MS, null, resHead, + "GET", false); res.setCharset(StandardCharsets.UTF_8); if (expectedURI == null) { @@ -872,10 +840,10 @@ public class TestRewriteValve extends TomcatBaseTest { Map<String, List<String>> reqHead = new HashMap<>(); reqHead.put("cookie", Arrays.asList("test=data")); ByteChunk res = new ByteChunk(); - int rc = methodUrl("http://localhost:" + getPort() + "/source/cookieTest", res, - DEFAULT_CLIENT_TIMEOUT_MS, reqHead, null, "GET", false); + int rc = methodUrl("http://localhost:" + getPort() + "/source/cookieTest", res, DEFAULT_CLIENT_TIMEOUT_MS, + reqHead, null, "GET", false); - Assert.assertEquals(HttpServletResponse.SC_OK , rc); + Assert.assertEquals(HttpServletResponse.SC_OK, rc); res.setCharset(StandardCharsets.UTF_8); Assert.assertEquals("PASS", res.toString()); diff --git a/test/org/apache/catalina/valves/rewrite/TesterRewriteMapA.java b/test/org/apache/catalina/valves/rewrite/TesterRewriteMapA.java index 0e0c5ccc53..434e3414d3 100644 --- a/test/org/apache/catalina/valves/rewrite/TesterRewriteMapA.java +++ b/test/org/apache/catalina/valves/rewrite/TesterRewriteMapA.java @@ -21,7 +21,7 @@ import java.util.Map; public class TesterRewriteMapA implements RewriteMap { - private static final Map<String,String> map = new HashMap<>(); + private static final Map<String, String> map = new HashMap<>(); static { map.put("a", "aa"); --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org