From: markt Date: Thu, 22 Jul 2010 12:18:59 +0000 (+0000) Subject: Run all unit tests will all connectors X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=83366b107755e6851641ccf77f0f554c00f2e31e;p=tomcat7.0 Run all unit tests will all connectors git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@966613 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/build.xml b/build.xml index bece78b0e..f5d794b08 100644 --- a/build.xml +++ b/build.xml @@ -928,39 +928,72 @@ - - - - - - - + depends="test-bio,test-nio,test-apr" > + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - + + + - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/org/apache/catalina/startup/TestTomcatSSL.java b/test/org/apache/catalina/startup/TestTomcatSSL.java index 55491e540..5b1d8164c 100644 --- a/test/org/apache/catalina/startup/TestTomcatSSL.java +++ b/test/org/apache/catalina/startup/TestTomcatSSL.java @@ -30,7 +30,6 @@ import javax.net.ssl.SSLSocketFactory; import javax.net.ssl.TrustManager; import javax.net.ssl.X509TrustManager; -import org.apache.catalina.connector.Connector; import org.apache.tomcat.util.buf.ByteChunk; /** @@ -56,15 +55,7 @@ public class TestTomcatSSL extends TomcatBaseTest { } }; - private void initSsl(Tomcat tomcat, boolean nio) { - if (nio) { - Connector connector = - new Connector("org.apache.coyote.http11.Http11NioProtocol"); - connector.setPort(getPort()); - tomcat.getService().addConnector(connector); - tomcat.setConnector(connector); - tomcat.getConnector().setProperty("sslProtocol", "tls"); - } + private void initSsl(Tomcat tomcat) { String protocol = tomcat.getConnector().getProtocolHandlerClassName(); if (protocol.indexOf("Apr") == -1) { tomcat.getConnector().setProperty("sslProtocol", "tls"); @@ -88,14 +79,6 @@ public class TestTomcatSSL extends TomcatBaseTest { } public void testSimpleSsl() throws Exception { - simpleSsl(false); - } - - public void testSimpleSslNio() throws Exception { - simpleSsl(true); - } - - public void simpleSsl(boolean nio) throws Exception { // Install the all-trusting trust manager so https:// works // with unsigned certs. @@ -113,7 +96,7 @@ public class TestTomcatSSL extends TomcatBaseTest { File appDir = new File(getBuildDirectory(), "webapps/examples"); tomcat.addWebapp(null, "/examples", appDir.getAbsolutePath()); - initSsl(tomcat, nio); + initSsl(tomcat); tomcat.start(); ByteChunk res = getUrl("https://localhost:" + getPort() + @@ -124,19 +107,16 @@ public class TestTomcatSSL extends TomcatBaseTest { boolean handshakeDone = false; public void testRenegotiateFail() throws Exception { - renegotiateFail(false); - } - - public void renegotiateFail(boolean nio) throws Exception { Tomcat tomcat = getTomcatInstance(); File appDir = new File(getBuildDirectory(), "webapps/examples"); // app dir is relative to server home tomcat.addWebapp(null, "/examples", appDir.getAbsolutePath()); - initSsl(tomcat, nio); - // Default - MITM not enabled + initSsl(tomcat); + // Default - MITM attack prevented + tomcat.start(); SSLContext sslCtx = SSLContext.getInstance("TLS"); sslCtx.init(null, trustAllCerts, new java.security.SecureRandom()); @@ -191,36 +171,22 @@ public class TestTomcatSSL extends TomcatBaseTest { } public void testRenegotiateWorks() throws Exception { - renegotiateWorks(false); - } - - - // Re-negotiation not implemented in NIO - // public void testRenegotiateWorksNio() throws Exception { - // renegotiateWorks(true); - // } - - public void testRenegotiateFailNio() throws Exception { - renegotiateFail(true); - } - - - public void renegotiateWorks(boolean nio) throws Exception { Tomcat tomcat = getTomcatInstance(); File appDir = new File(getBuildDirectory(), "webapps/examples"); // app dir is relative to server home tomcat.addWebapp(null, "/examples", appDir.getAbsolutePath()); - initSsl(tomcat, nio); + initSsl(tomcat); + // Enable MITM attack tomcat.getConnector().setAttribute("allowUnsafeLegacyRenegotiation", "true"); tomcat.start(); String protocol = tomcat.getConnector().getProtocolHandlerClassName(); - if (protocol.indexOf("Apr") != -1) { - return; // Not supported yet (10/05/25) + if (protocol.indexOf("Nio") != -1) { + return; // Not supported yet (2010-07-22) } SSLContext sslCtx = SSLContext.getInstance("TLS"); @@ -265,4 +231,11 @@ public class TestTomcatSSL extends TomcatBaseTest { } } + + @Override + public void setUp() throws Exception { + // Make sure SSL renegotiation is not disabled in the JVM + System.setProperty("sun.security.ssl.allowUnsafeRenegotiation", "true"); + super.setUp(); + } } diff --git a/test/org/apache/catalina/startup/TomcatBaseTest.java b/test/org/apache/catalina/startup/TomcatBaseTest.java index 131562789..53e17a7e2 100644 --- a/test/org/apache/catalina/startup/TomcatBaseTest.java +++ b/test/org/apache/catalina/startup/TomcatBaseTest.java @@ -32,6 +32,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.catalina.LifecycleState; +import org.apache.catalina.connector.Connector; import org.apache.catalina.core.StandardServer; import org.apache.catalina.core.AprLifecycleListener; @@ -109,17 +110,30 @@ public abstract class TomcatBaseTest extends TestCase { tomcat = new Tomcat(); - // Add AprLifecycleListener - StandardServer server = (StandardServer) tomcat.getServer(); - AprLifecycleListener listener = new AprLifecycleListener(); - server.addLifecycleListener(listener); + // Has a protocol been specified + String protocol = System.getProperty("tomcat.test.protocol"); - tomcat.setBaseDir(tempDir.getAbsolutePath()); - tomcat.getHost().setAppBase(appBase.getAbsolutePath()); - + // Use BIO by default + if (protocol == null) { + protocol = "org.apache.coyote.http11.Http11Protocol"; + } + + Connector connector = new Connector(protocol); // If each test is running on same port - they // may interfere with each other (on unix at least) - tomcat.setPort(getNextPort()); + connector.setPort(getNextPort()); + tomcat.getService().addConnector(connector); + tomcat.setConnector(connector); + + // Add AprLifecycleListener if we are using the Apr connector + if (protocol.contains("Apr")) { + StandardServer server = (StandardServer) tomcat.getServer(); + AprLifecycleListener listener = new AprLifecycleListener(); + server.addLifecycleListener(listener); + } + + tomcat.setBaseDir(tempDir.getAbsolutePath()); + tomcat.getHost().setAppBase(appBase.getAbsolutePath()); } @Override diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index 728af3ca2..582c88ef0 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -285,6 +285,10 @@ installer, making it clear that the service will be installed. Patch provided by sebb. (markt) + + Re-factor unit tests to enable them to be run once with each of the HTTP + connector implementations (BIO, NIO and APR/native). (markt) +