[java-idp-integration-tests] branch master updated: IDP-843 - First steps toward testing Tomcat

Tom Zeller tzeller at dragonacea.biz
Tue Jul 12 20:17:33 EDT 2016


This is an automated email from the git hooks/post-receive script.

tzeller pushed a commit to branch master
in repository java-idp-integration-tests.

View the commit online:
http://git.shibboleth.net/view/?p=java-idp-integration-tests.git;a=commit;h=180658e8bf3009f5c8414e1b7d2540fcea68bff3

The following commit(s) were added to refs/heads/master by this push:
       new  180658e   IDP-843 - First steps toward testing Tomcat
180658e is described below

commit 180658e8bf3009f5c8414e1b7d2540fcea68bff3
Author: Tom Zeller <tzeller at dragonacea.biz>
AuthorDate: Tue Jul 12 19:16:38 2016 -0500

    IDP-843 - First steps toward testing Tomcat
    
    Set "tomcat" system property to true to run Tomcat instead of Jetty.
---
 pom.xml                                            |  72 ++++++++++++-
 .../shibboleth/idp/test/BaseIntegrationTest.java   | 113 +++++++++++++++++++--
 .../java/net/shibboleth/idp/test/StatusTest.java   |   2 +-
 .../shibboleth/idp/test/TomcatServerProcess.java   |  48 +++++++++
 .../idp/test/cas/CASIntegrationTest.java           |   4 +-
 .../idp/test/clientstorage/ClientStorageTest.java  |   4 +-
 .../test/saml1/AbstractSAML1IntegrationTest.java   |   2 +-
 .../test/saml2/AbstractSAML2IntegrationTest.java   |  18 ++--
 8 files changed, 235 insertions(+), 28 deletions(-)

diff --git a/pom.xml b/pom.xml
index 58e4262..adbff56 100644
--- a/pom.xml
+++ b/pom.xml
@@ -21,10 +21,12 @@
         <opensaml.version>3.3.0-SNAPSHOT</opensaml.version>
         <idp.version>3.3.0-SNAPSHOT</idp.version>
         <idp-jetty-base.version>9.2.0-SNAPSHOT</idp-jetty-base.version>
+        <idp-tomcat-base.version>8.0.0-SNAPSHOT</idp-tomcat-base.version>
         <selenium.version>2.53.1</selenium.version>
         <testbed.version>0.5.0-SNAPSHOT</testbed.version>
         <testbed.classifier>classes</testbed.classifier>
         <test-distributions.directory>${project.basedir}/test-distributions</test-distributions.directory>
+        <tomcat.version>8.0.36</tomcat.version>
         <svn.relative.location>java-idp-integration-tests</svn.relative.location>
         <xalan.groupId>xalan</xalan.groupId>
         <xalan.version>2.7.1</xalan.version>
@@ -121,6 +123,13 @@
             <classifier>${testbed.classifier}</classifier>
         </dependency>
         <dependency>
+            <groupId>net.shibboleth.idp</groupId>
+            <artifactId>idp-tomcat-base</artifactId>
+            <version>${idp-tomcat-base.version}</version>
+            <scope>test</scope>
+            <type>tar.gz</type>
+        </dependency>
+        <dependency>
             <groupId>org.opensaml</groupId>
             <artifactId>opensaml-saml-impl</artifactId>
             <version>${opensaml.version}</version>
@@ -339,6 +348,25 @@
                             <outputDirectory>${test-distributions.directory}/shibboleth-identity-provider-${idp.version}</outputDirectory>
                         </configuration>
                     </execution>
+                    <!-- Unpack idp-tomcat-base. -->
+                    <execution>
+                        <id>unpack-idp-tomcat-base</id>
+                        <phase>compile</phase>
+                        <goals>
+                            <goal>unpack</goal>
+                        </goals>
+                        <configuration>
+                            <artifactItems>
+                                <artifactItem>
+                                    <groupId>net.shibboleth.idp</groupId>
+                                    <artifactId>idp-tomcat-base</artifactId>
+                                    <version>${idp-tomcat-base.version}</version>
+                                    <type>tar.gz</type>
+                                </artifactItem>
+                            </artifactItems>
+                            <outputDirectory>${test-distributions.directory}/shibboleth-identity-provider-${idp.version}</outputDirectory>
+                        </configuration>
+                    </execution>
                     <!-- Unpack jetty-distribution to test-distributions directory. -->
                     <execution>
                         <id>unpack-jetty-distribution</id>
@@ -358,6 +386,25 @@
                             <outputDirectory>${test-distributions.directory}</outputDirectory>
                         </configuration>
                     </execution>
+                    <!-- Unpack Tomcat to test-distributions directory. -->
+                    <execution>
+                        <id>unpack-tomcat-distribution</id>
+                        <phase>compile</phase>
+                        <goals>
+                            <goal>unpack</goal>
+                        </goals>
+                        <configuration>
+                            <artifactItems>
+                                <artifactItem>
+                                    <groupId>org.apache.tomcat</groupId>
+                                    <artifactId>tomcat</artifactId>
+                                    <version>${tomcat.version}</version>
+                                    <type>tar.gz</type>
+                                </artifactItem>
+                            </artifactItems>
+                            <outputDirectory>${test-distributions.directory}</outputDirectory>
+                        </configuration>
+                    </execution>
                     <!-- Copy testbed war to IdP distribution directory. -->
                     <execution>
                         <id>copy-testbed-war</id>
@@ -398,9 +445,9 @@
                             <outputDirectory>${test-distributions.directory}/shibboleth-identity-provider-${idp.version}/webapp/WEB-INF/lib/</outputDirectory>
                         </configuration>
                     </execution>
-                    <!-- Copy testbed deployment descriptor from testbed jar. -->
+                    <!-- Copy testbed deployment descriptor from testbed jar to Jetty. -->
                     <execution>
-                        <id>copy-testbed-deployment-descriptor</id>
+                        <id>copy-testbed-deployment-descriptor-jetty</id>
                         <phase>compile</phase>
                         <goals>
                             <goal>unpack</goal>
@@ -419,6 +466,27 @@
                             <outputDirectory>${test-distributions.directory}/shibboleth-identity-provider-${idp.version}/jetty-base/</outputDirectory>
                         </configuration>
                     </execution>
+                    <!-- Copy testbed context descriptor from testbed jar to Tomcat. -->
+                    <execution>
+                        <id>copy-testbed-context-descriptor-tomcat</id>
+                        <phase>compile</phase>
+                        <goals>
+                            <goal>unpack</goal>
+                        </goals>
+                        <configuration>
+                            <artifactItems>
+                                <artifactItem>
+                                   <groupId>net.shibboleth.idp</groupId>
+                                    <artifactId>idp-testbed</artifactId>
+                                    <version>${testbed.version}</version>
+                                    <type>jar</type>
+                                    <classifier>${testbed.classifier}</classifier>
+                                    <includes>conf/Catalina/localhost/ROOT.xml</includes>
+                                </artifactItem>
+                            </artifactItems>
+                            <outputDirectory>${test-distributions.directory}/shibboleth-identity-provider-${idp.version}/tomcat-base/</outputDirectory>
+                        </configuration>
+                    </execution>
                 </executions>
             </plugin>
             <!-- Also delete the test-distributions directory during clean. -->
diff --git a/src/test/java/net/shibboleth/idp/test/BaseIntegrationTest.java b/src/test/java/net/shibboleth/idp/test/BaseIntegrationTest.java
index 769ce5a..802756f 100644
--- a/src/test/java/net/shibboleth/idp/test/BaseIntegrationTest.java
+++ b/src/test/java/net/shibboleth/idp/test/BaseIntegrationTest.java
@@ -259,9 +259,12 @@ public abstract class BaseIntegrationTest
 
     /** Path to jetty.home. */
     @NonnullAfterInit protected Path pathToJettyHome;
+    
+    /** Path to tomcat.base. */
+    @NonnullAfterInit protected Path pathToTomcatBase;
 
-    /** Path to tmp directory. */
-    @NonnullAfterInit protected Path pathToTmpDir;
+    /** Path to tomcat.home. */
+    @NonnullAfterInit protected Path pathToTomcatHome;
 
     /** Pattern used when creating per test idp.home directory. Defaults to yyyyMMdd-HHmmssSS. **/
     @Nullable protected String idpHomePattern = "yyyyMMdd-HHmmssSS";
@@ -345,6 +348,19 @@ public abstract class BaseIntegrationTest
         log.debug("Path to jetty.home '{}'", pathToJettyHome.toAbsolutePath());
         Assert.assertNotNull(pathToJettyHome, "Path to jetty.home not found");
         Assert.assertTrue(pathToJettyHome.toAbsolutePath().toFile().exists(), "Path to jetty.home not found");
+        
+        // Path to Tomcat distribution
+        try (DirectoryStream<Path> stream = Files.newDirectoryStream(buildPath, "*apache-tomcat-*")) {
+            for (Path entry : stream) {
+                pathToTomcatHome = entry;
+                break;
+            }
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+        log.debug("Path to tomcat.home '{}'", pathToTomcatHome.toAbsolutePath());
+        Assert.assertNotNull(pathToTomcatHome, "Path to tomcat.home not found");
+        Assert.assertTrue(pathToTomcatHome.toAbsolutePath().toFile().exists(), "Path to tomcat.home not found");
 
         // Path to idp.home from distribution.
         Path pathToDistIdPHome = null;
@@ -381,6 +397,12 @@ public abstract class BaseIntegrationTest
         Assert.assertNotNull(pathToJettyBase, "Path to jetty.base not found");
         Assert.assertTrue(pathToJettyBase.toAbsolutePath().toFile().exists(), "Path to jetty.base not found");
 
+        // Path to tomcat.base
+        pathToTomcatBase = pathToIdPHome.resolve(Paths.get("tomcat-base"));
+        log.debug("Path to tomcat.base '{}'", pathToTomcatBase.toAbsolutePath());
+        Assert.assertNotNull(pathToTomcatBase, "Path to tomcat.base not found");
+        Assert.assertTrue(pathToTomcatBase.toAbsolutePath().toFile().exists(), "Path to tomcat.base not found");
+        
         // Path to conf/idp.properties
         pathToIdPProperties = Paths.get(pathToIdPHome.toAbsolutePath().toString(), "conf", "idp.properties");
         Assert.assertTrue(pathToIdPProperties.toFile().exists(), "Path to conf/idp.properties not found");
@@ -389,9 +411,9 @@ public abstract class BaseIntegrationTest
         pathToLDAPProperties = Paths.get(pathToIdPHome.toAbsolutePath().toString(), "conf", "ldap.properties");
         Assert.assertTrue(pathToLDAPProperties.toFile().exists(), "Path to conf/ldap.properties not found");
 
-        // Path to jetty.base/tmp
-        pathToTmpDir = pathToJettyBase.resolve("tmp");
-        Assert.assertTrue(pathToTmpDir.toFile().exists(), "Path to tmp/ not found");
+        // Make tmp directories exist
+        Assert.assertTrue(pathToJettyBase.resolve("tmp").toFile().exists(), "Path to jetty.base/tmp/ not found");
+        Assert.assertTrue(pathToTomcatBase.resolve("temp").toFile().exists(), "Path to tomcat.base/temp/ not found");
     }
 
     /**
@@ -505,6 +527,14 @@ public abstract class BaseIntegrationTest
         replaceProperty(pathToJettyIdPIni, "jetty.backchannel.port", Integer.toString(backchannelPort));
         replaceProperty(pathToJettyIdPIni, "jetty.nonhttps.host", privateAddress);
         replaceProperty(pathToJettyIdPIni, "jetty.nonhttps.port", Integer.toString(port));
+        
+        // Tomcat endpoints.
+        final Path pathToCatalinaProperties = pathToTomcatBase.resolve(Paths.get("conf", "catalina.properties"));
+        replaceFile(pathToCatalinaProperties, "tomcat.host=.*", "tomcat.host=" + privateSecureAddress);
+        replaceFile(pathToCatalinaProperties, "tomcat.https.port=.*", "tomcat.https.port=" + Integer.toString(securePort));
+        replaceFile(pathToCatalinaProperties, "tomcat.backchannel.port=.*", "tomcat.backchannel.port=" + Integer.toString(backchannelPort));
+        replaceFile(pathToCatalinaProperties, "tomcat.nonhttps.host=.*", "tomcat.nonhttps.host=" + privateAddress);
+        replaceFile(pathToCatalinaProperties, "tomcat.nonhttps.port=.*", "tomcat.nonhttps.port=" + Integer.toString(port));
 
         // Metadata.
         replaceIdPHomeFile(Paths.get("metadata", "example-metadata.xml"), "http://localhost:8080", baseURL);
@@ -582,13 +612,39 @@ public abstract class BaseIntegrationTest
     }
 
     /**
-     * Set default temp file path.
+     * Set per-test idp.home in setenv.sh. Use expanded IdP webapp.
      * 
-     * @throws Exception
+     * @throws IOException
      */
-    @BeforeClass(enabled = true, dependsOnMethods = {"setUpPaths"})
-    public void setUpTmpDir() throws Exception {
-        serverCommands.add("-Djava.io.tmpdir=" + pathToTmpDir.toAbsolutePath().toFile());
+    @BeforeClass(dependsOnMethods = {"setUpAddresses", "setUpAvailablePorts"})
+    public void setUpTomcatIdPHome() throws IOException {
+        final Path pathToSetenvSh = pathToTomcatBase.resolve(Paths.get("bin", "setenv.sh"));
+        Assert.assertTrue(pathToSetenvSh.toAbsolutePath().toFile().exists(), "Path to setenv.sh not found");
+
+        final String oldTextSetenvSh = "-Didp.home=/opt/shibboleth-idp";
+        final String newTextSetenvSh = "-Didp.home=" + pathToIdPHome.toAbsolutePath().toString();
+        replaceFile(pathToSetenvSh, oldTextSetenvSh, newTextSetenvSh);
+
+        final Path pathToIdpXML = pathToTomcatBase.resolve(Paths.get("conf", "Catalina", "localhost", "idp.xml"));
+        Assert.assertTrue(pathToIdpXML.toAbsolutePath().toFile().exists(), "Path to idp.xml not found");
+
+        replaceFile(pathToIdpXML, "/war/idp.war\"", "/webapp/\"");
+    }
+
+    /**
+     * Append additional server commands to Tomcat setenv.sh.
+     * 
+     * @throws IOException
+     */
+    public void setUpTomcatServerCommands() throws IOException {
+        final Path pathToSetenvSh = pathToTomcatBase.resolve(Paths.get("bin", "setenv.sh"));
+        Assert.assertTrue(pathToSetenvSh.toAbsolutePath().toFile().exists(), "Path to setenv.sh not found");
+
+        for (final String serverCommand : serverCommands) {
+            if (serverCommand.startsWith("-D")) {
+                replaceFile(pathToSetenvSh, "\"$", " " + serverCommand + "\"");
+            }
+        }
     }
 
     /**
@@ -671,14 +727,30 @@ public abstract class BaseIntegrationTest
     }
 
     /**
-     * Start the Jetty server.
+     * Start the IdP server. Uses Jetty by default, and Tomcat if the system property 'tomcat' is true.
      * 
      * Note : this method must be called in each test to allow for customization of the IdP configuration before the
      * server is started.
      * 
+     * @throws ComponentInitializationException
+     */
+    public void startServer() throws ComponentInitializationException {
+        if (Boolean.valueOf(System.getProperty("tomcat"))) {
+            startTomcatServer();
+        } else {
+            startJettyServer();
+        }
+    }
+
+    /**
+     * Start the Jetty server.
+     * 
      * @throws ComponentInitializationException if the server cannot be initialized
      */
     public void startJettyServer() throws ComponentInitializationException {
+
+        serverCommands.add("-Djava.io.tmpdir=" + pathToJettyBase.resolve("tmp").toAbsolutePath());
+
         server = new JettyServerProcess();
         server.setServletContainerBasePath(pathToJettyBase);
         server.setServletContainerHomePath(pathToJettyHome);
@@ -689,6 +761,25 @@ public abstract class BaseIntegrationTest
     }
 
     /**
+     * Start the Tomcat server.
+     * 
+     * @throws ComponentInitializationException if the server cannot be initialized
+     */
+    public void startTomcatServer() throws ComponentInitializationException {
+        server = new TomcatServerProcess();
+        server.setServletContainerBasePath(pathToTomcatBase);
+        server.setServletContainerHomePath(pathToTomcatHome);
+        try {
+            setUpTomcatServerCommands();
+        } catch (IOException e) {
+            throw new ComponentInitializationException(e);
+        }
+        server.setStatusPageURL(getBaseURL() + StatusTest.statusPath);
+        server.initialize();
+        server.start();
+    }
+
+    /**
      * Stop the server.
      */
     @AfterMethod
diff --git a/src/test/java/net/shibboleth/idp/test/StatusTest.java b/src/test/java/net/shibboleth/idp/test/StatusTest.java
index eb3a85a..8f47169 100644
--- a/src/test/java/net/shibboleth/idp/test/StatusTest.java
+++ b/src/test/java/net/shibboleth/idp/test/StatusTest.java
@@ -38,7 +38,7 @@ public class StatusTest extends BaseIntegrationTest {
 
         startSeleniumClient(browserData);
 
-        startJettyServer();
+        startServer();
 
         driver.get(baseURL + statusPath);
 
diff --git a/src/test/java/net/shibboleth/idp/test/TomcatServerProcess.java b/src/test/java/net/shibboleth/idp/test/TomcatServerProcess.java
new file mode 100644
index 0000000..57d03cb
--- /dev/null
+++ b/src/test/java/net/shibboleth/idp/test/TomcatServerProcess.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the University Corporation for Advanced Internet Development, 
+ * Inc. (UCAID) under one or more contributor license agreements.  See the 
+ * NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The UCAID licenses this file to You under the Apache 
+ * License, Version 2.0 (the "License"); you may not use this file except in 
+ * compliance with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.shibboleth.idp.test;
+
+import javax.annotation.Nonnull;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
+
+/** Start Tomcat via 'catalina.sh run'. */
+public class TomcatServerProcess extends AbstractServerProcess {
+
+    /** Class logger. */
+    @Nonnull private final Logger log = LoggerFactory.getLogger(TomcatServerProcess.class);
+
+    /** {@inheritDoc} */
+    @Override
+    protected void doInitialize() throws ComponentInitializationException {
+        super.doInitialize();
+
+        // Add CATALINA_BASE to environment
+        getProcessBuilder().environment().put("CATALINA_BASE", getServletContainerBasePath().toAbsolutePath().toString());
+
+        // Start Tomcat in current window
+        getCommands().add(getServletContainerHomePath().toAbsolutePath().toString() + "/bin/catalina.sh");
+        getCommands().add("run");
+        
+        // TODO Windows file separator and .bat
+    }
+
+}
diff --git a/src/test/java/net/shibboleth/idp/test/cas/CASIntegrationTest.java b/src/test/java/net/shibboleth/idp/test/cas/CASIntegrationTest.java
index 32a83c3..1fc481c 100644
--- a/src/test/java/net/shibboleth/idp/test/cas/CASIntegrationTest.java
+++ b/src/test/java/net/shibboleth/idp/test/cas/CASIntegrationTest.java
@@ -101,7 +101,7 @@ public class CASIntegrationTest extends BaseIntegrationTest {
 
         enableLocalhostCASServiceDefinition();
 
-        startJettyServer();
+        startServer();
 
         startFlow();
 
@@ -133,7 +133,7 @@ public class CASIntegrationTest extends BaseIntegrationTest {
 
         enableLocalhostCASAttributes();
 
-        startJettyServer();
+        startServer();
 
         startFlow();
 
diff --git a/src/test/java/net/shibboleth/idp/test/clientstorage/ClientStorageTest.java b/src/test/java/net/shibboleth/idp/test/clientstorage/ClientStorageTest.java
index 70cdd5c..2dec8ea 100644
--- a/src/test/java/net/shibboleth/idp/test/clientstorage/ClientStorageTest.java
+++ b/src/test/java/net/shibboleth/idp/test/clientstorage/ClientStorageTest.java
@@ -132,7 +132,7 @@ public class ClientStorageTest extends BaseIntegrationTest {
 
         startSeleniumClient(browserData);
 
-        startJettyServer();
+        startServer();
 
         getAndWaitForTestbedPage();
 
@@ -148,7 +148,7 @@ public class ClientStorageTest extends BaseIntegrationTest {
 
         startSeleniumClient(browserData);
 
-        startJettyServer();
+        startServer();
 
         getAndWaitForTestbedPage();
 
diff --git a/src/test/java/net/shibboleth/idp/test/saml1/AbstractSAML1IntegrationTest.java b/src/test/java/net/shibboleth/idp/test/saml1/AbstractSAML1IntegrationTest.java
index 98f6310..50dc1e3 100644
--- a/src/test/java/net/shibboleth/idp/test/saml1/AbstractSAML1IntegrationTest.java
+++ b/src/test/java/net/shibboleth/idp/test/saml1/AbstractSAML1IntegrationTest.java
@@ -101,7 +101,7 @@ public class AbstractSAML1IntegrationTest extends BaseIntegrationTest {
 
         enableCustomRelyingPartyConfiguration();
 
-        startJettyServer();
+        startServer();
 
         startFlow();
 
diff --git a/src/test/java/net/shibboleth/idp/test/saml2/AbstractSAML2IntegrationTest.java b/src/test/java/net/shibboleth/idp/test/saml2/AbstractSAML2IntegrationTest.java
index 368521a..8bbc49a 100644
--- a/src/test/java/net/shibboleth/idp/test/saml2/AbstractSAML2IntegrationTest.java
+++ b/src/test/java/net/shibboleth/idp/test/saml2/AbstractSAML2IntegrationTest.java
@@ -214,7 +214,7 @@ public abstract class AbstractSAML2IntegrationTest extends BaseIntegrationTest {
 
         startSeleniumClient(browserData);
 
-        startJettyServer();
+        startServer();
 
         startFlow();
 
@@ -259,7 +259,7 @@ public abstract class AbstractSAML2IntegrationTest extends BaseIntegrationTest {
 
         enablePerAttributeConsent();
 
-        startJettyServer();
+        startServer();
 
         startFlow();
 
@@ -305,7 +305,7 @@ public abstract class AbstractSAML2IntegrationTest extends BaseIntegrationTest {
 
         startSeleniumClient(browserData);
 
-        startJettyServer();
+        startServer();
 
         startFlow();
 
@@ -358,7 +358,7 @@ public abstract class AbstractSAML2IntegrationTest extends BaseIntegrationTest {
 
         startSeleniumClient(browserData);
 
-        startJettyServer();
+        startServer();
 
         startFlow();
 
@@ -405,7 +405,7 @@ public abstract class AbstractSAML2IntegrationTest extends BaseIntegrationTest {
 
         enableCustomRelyingPartyConfiguration();
 
-        startJettyServer();
+        startServer();
 
         startFlow();
 
@@ -456,7 +456,7 @@ public abstract class AbstractSAML2IntegrationTest extends BaseIntegrationTest {
 
         startSeleniumClient(browserData);
 
-        startJettyServer();
+        startServer();
 
         startFlow();
 
@@ -503,7 +503,7 @@ public abstract class AbstractSAML2IntegrationTest extends BaseIntegrationTest {
 
         startSeleniumClient(browserData);
 
-        startJettyServer();
+        startServer();
 
         // start flow
         driver.get(getBaseURL() + isPassiveRequestURLPath);
@@ -529,7 +529,7 @@ public abstract class AbstractSAML2IntegrationTest extends BaseIntegrationTest {
 
         startSeleniumClient(browserData);
 
-        startJettyServer();
+        startServer();
 
         startFlow();
 
@@ -570,7 +570,7 @@ public abstract class AbstractSAML2IntegrationTest extends BaseIntegrationTest {
 
         enableLogout();
 
-        startJettyServer();
+        startServer();
 
         startFlow();
 

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list