Author: markt Date: Tue Feb 6 16:20:56 2018 New Revision: 1823359 URL: http://svn.apache.org/viewvc?rev=1823359&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/tc7.0.x/trunk/test/org/apache/tomcat/util/http/mapper/TestMapperWebapps.java Modified: tomcat/tc7.0.x/trunk/test/org/apache/tomcat/util/http/mapper/TestMapperWebapps.java URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/test/org/apache/tomcat/util/http/mapper/TestMapperWebapps.java?rev=1823359&r1=1823358&r2=1823359&view=diff ============================================================================== --- tomcat/tc7.0.x/trunk/test/org/apache/tomcat/util/http/mapper/TestMapperWebapps.java (original) +++ tomcat/tc7.0.x/trunk/test/org/apache/tomcat/util/http/mapper/TestMapperWebapps.java Tue Feb 6 16:20:56 2018 @@ -18,7 +18,6 @@ package org.apache.tomcat.util.http.mapp import java.io.File; import java.io.IOException; -import java.net.HttpURLConnection; import java.util.HashMap; import java.util.List; @@ -229,61 +228,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-3.0"); - org.apache.catalina.Context root = - tomcat.addWebapp(null, "", rootDir.getAbsolutePath()); - - // Add a security constraint - SecurityConstraint constraint = new SecurityConstraint(); - SecurityCollection collection = new SecurityCollection(); - collection.addPattern("/welcome-files/*"); - collection.addPattern("/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-3.0"); + org.apache.catalina.Context root = + tomcat.addWebapp(null, "", rootDir.getAbsolutePath()); + + // Add a security constraint + SecurityConstraint constraint = new SecurityConstraint(); + SecurityCollection collection = new SecurityCollection(); + collection.addPattern("/welcome-files/*"); + collection.addPattern("/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); } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org