Author: markt Date: Fri Feb 2 21:42:05 2018 New Revision: 1823007 URL: http://svn.apache.org/viewvc?rev=1823007&view=rev Log: Switch tests to using per connection control of redirects rather than changing the default which may fail when testing with concurrent threads.
Modified: tomcat/trunk/test/org/apache/catalina/mapper/TestMapperWebapps.java tomcat/trunk/test/org/apache/catalina/valves/rewrite/TestRewriteValve.java Modified: tomcat/trunk/test/org/apache/catalina/mapper/TestMapperWebapps.java URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/mapper/TestMapperWebapps.java?rev=1823007&r1=1823006&r2=1823007&view=diff ============================================================================== --- tomcat/trunk/test/org/apache/catalina/mapper/TestMapperWebapps.java (original) +++ tomcat/trunk/test/org/apache/catalina/mapper/TestMapperWebapps.java Fri Feb 2 21:42:05 2018 @@ -18,7 +18,6 @@ package org.apache.catalina.mapper; import java.io.File; import java.io.IOException; -import java.net.HttpURLConnection; import java.util.HashMap; import java.util.List; @@ -231,61 +230,54 @@ public class TestMapperWebapps extends T @Test public void testRedirect() throws Exception { - // Disable the following of redirects for this test only - boolean originalValue = HttpURLConnection.getFollowRedirects(); - HttpURLConnection.setFollowRedirects(false); - try { - Tomcat tomcat = getTomcatInstance(); - - // Use standard test webapp as ROOT - File rootDir = new File("test/webapp"); - org.apache.catalina.Context root = - tomcat.addWebapp(null, "", rootDir.getAbsolutePath()); - - // Add a security constraint - SecurityConstraint constraint = new SecurityConstraint(); - SecurityCollection collection = new SecurityCollection(); - collection.addPatternDecoded("/welcome-files/*"); - collection.addPatternDecoded("/welcome-files"); - constraint.addCollection(collection); - constraint.addAuthRole("foo"); - root.addConstraint(constraint); - - // Also make examples available - File examplesDir = new File(getBuildDirectory(), "webapps/examples"); - org.apache.catalina.Context examples = tomcat.addWebapp( - null, "/examples", examplesDir.getAbsolutePath()); - examples.setMapperContextRootRedirectEnabled(false); - // Then block access to the examples to test redirection - RemoteAddrValve rav = new RemoteAddrValve(); - rav.setDeny(".*"); - rav.setDenyStatus(404); - examples.getPipeline().addValve(rav); - - tomcat.start(); - - // Redirects within a web application - doRedirectTest("/welcome-files", 401); - doRedirectTest("/welcome-files/", 401); - - doRedirectTest("/jsp", 302); - doRedirectTest("/jsp/", 404); - - doRedirectTest("/WEB-INF", 404); - doRedirectTest("/WEB-INF/", 404); - - // Redirects between web applications - doRedirectTest("/examples", 404); - doRedirectTest("/examples/", 404); - } finally { - HttpURLConnection.setFollowRedirects(originalValue); - } + Tomcat tomcat = getTomcatInstance(); + + // Use standard test webapp as ROOT + File rootDir = new File("test/webapp"); + org.apache.catalina.Context root = + tomcat.addWebapp(null, "", rootDir.getAbsolutePath()); + + // Add a security constraint + SecurityConstraint constraint = new SecurityConstraint(); + SecurityCollection collection = new SecurityCollection(); + collection.addPatternDecoded("/welcome-files/*"); + collection.addPatternDecoded("/welcome-files"); + constraint.addCollection(collection); + constraint.addAuthRole("foo"); + root.addConstraint(constraint); + + // Also make examples available + File examplesDir = new File(getBuildDirectory(), "webapps/examples"); + org.apache.catalina.Context examples = tomcat.addWebapp( + null, "/examples", examplesDir.getAbsolutePath()); + examples.setMapperContextRootRedirectEnabled(false); + // Then block access to the examples to test redirection + RemoteAddrValve rav = new RemoteAddrValve(); + rav.setDeny(".*"); + rav.setDenyStatus(404); + examples.getPipeline().addValve(rav); + + tomcat.start(); + + // Redirects within a web application + doRedirectTest("/welcome-files", 401); + doRedirectTest("/welcome-files/", 401); + + doRedirectTest("/jsp", 302); + doRedirectTest("/jsp/", 404); + + doRedirectTest("/WEB-INF", 404); + doRedirectTest("/WEB-INF/", 404); + + // Redirects between web applications + doRedirectTest("/examples", 404); + doRedirectTest("/examples/", 404); } private void doRedirectTest(String path, int expected) throws IOException { ByteChunk bc = new ByteChunk(); - int rc = getUrl("http://localhost:" + getPort() + path, bc, null); + int rc = getUrl("http://localhost:" + getPort() + path, bc, false); Assert.assertEquals(expected, rc); } Modified: tomcat/trunk/test/org/apache/catalina/valves/rewrite/TestRewriteValve.java URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/valves/rewrite/TestRewriteValve.java?rev=1823007&r1=1823006&r2=1823007&view=diff ============================================================================== --- tomcat/trunk/test/org/apache/catalina/valves/rewrite/TestRewriteValve.java (original) +++ tomcat/trunk/test/org/apache/catalina/valves/rewrite/TestRewriteValve.java Fri Feb 2 21:42:05 2018 @@ -486,29 +486,15 @@ public class TestRewriteValve extends To @Test public void testDefaultRedirect() throws Exception { - // Disable the following of redirects for this test only - boolean originalValue = HttpURLConnection.getFollowRedirects(); - HttpURLConnection.setFollowRedirects(false); - try { - doTestRedirect("RewriteRule ^/from/a$ /to/b [R]", "/redirect/from/a", "/redirect/to/b", + doTestRedirect("RewriteRule ^/from/a$ /to/b [R]", "/redirect/from/a", "/redirect/to/b", 302); - } finally { - HttpURLConnection.setFollowRedirects(originalValue); - } } @Test public void testTempRedirect() throws Exception { - // Disable the following of redirects for this test only - boolean originalValue = HttpURLConnection.getFollowRedirects(); - HttpURLConnection.setFollowRedirects(false); - try { - doTestRedirect("RewriteRule ^/from/a$ /to/b [R=temp]", "/redirect/from/a", "/redirect/to/b", + doTestRedirect("RewriteRule ^/from/a$ /to/b [R=temp]", "/redirect/from/a", "/redirect/to/b", 302); - } finally { - HttpURLConnection.setFollowRedirects(originalValue); - } } @@ -645,7 +631,8 @@ public class TestRewriteValve extends To ByteChunk res = new ByteChunk(); Map<String, List<String>> resHead = new HashMap<>(); - int rc = getUrl("http://localhost:" + getPort() + request, res, null, resHead); + int rc = methodUrl("http://localhost:" + getPort() + request, res, + DEFAULT_CLIENT_TIMEOUT_MS, null, resHead, "GET", false); res.setCharset(StandardCharsets.UTF_8); if (expectedURI == null) { --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org