[java-idp-integration-tests] 01/03: Do not run from expanded webapp/ directory

Tom Zeller tzeller at dragonacea.biz
Sat Jan 7 16:24:52 UTC 2023


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

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

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

commit 3cb8f3bcfb0469c04613ddc87c12e7f6de521210
Author: Tom Zeller <tzeller at dragonacea.biz>
AuthorDate: Fri Jan 6 15:17:03 2023 -0600

    Do not run from expanded webapp/ directory
    
    Instead, extract web.xml from idp.war to edit-webapp and use build CLI
    to rebuild WAR
---
 .../integration/tests/AbstractServerProcess.java   |   3 +
 .../idp/integration/tests/BaseIntegrationTest.java | 136 ++++++++++++---------
 .../tests/clientstorage/ClientStorageTest.java     |  51 +++++++-
 .../integration/tests/plugins/BasePluginTest.java  |  65 +---------
 4 files changed, 131 insertions(+), 124 deletions(-)

diff --git a/src/test/java/net/shibboleth/idp/integration/tests/AbstractServerProcess.java b/src/test/java/net/shibboleth/idp/integration/tests/AbstractServerProcess.java
index d5d0c9d..ef2c8dd 100644
--- a/src/test/java/net/shibboleth/idp/integration/tests/AbstractServerProcess.java
+++ b/src/test/java/net/shibboleth/idp/integration/tests/AbstractServerProcess.java
@@ -20,6 +20,7 @@ package net.shibboleth.idp.integration.tests;
 import java.io.IOException;
 import java.lang.ProcessBuilder.Redirect;
 import java.net.ConnectException;
+import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.time.Duration;
@@ -284,6 +285,8 @@ public class AbstractServerProcess extends AbstractInitializableComponent implem
         try {
             processBuilder.command(buildCommands());
             log.debug("Will start server using command '{}'", processBuilder.command());
+            log.debug("Writing command to start server to '{}'", pathToContainerBase.resolve("start.sh"));
+            Files.write(pathToContainerBase.resolve("start.sh"), String.join(" ", processBuilder.command()).getBytes());
             final Stopwatch stopwatch = Stopwatch.createStarted();
             // Workaround Maven Surefire Plugin freeze if Jetty 10 writes to stdout or stderr
             processBuilder.redirectOutput(Redirect.INHERIT);
diff --git a/src/test/java/net/shibboleth/idp/integration/tests/BaseIntegrationTest.java b/src/test/java/net/shibboleth/idp/integration/tests/BaseIntegrationTest.java
index ca1dc37..88f6b8f 100644
--- a/src/test/java/net/shibboleth/idp/integration/tests/BaseIntegrationTest.java
+++ b/src/test/java/net/shibboleth/idp/integration/tests/BaseIntegrationTest.java
@@ -302,6 +302,12 @@ public abstract class BaseIntegrationTest {
     /** Path to idp.home. */
     @NonnullAfterInit protected Path pathToIdPHome;
 
+    /** Directory to be used as idp.home **/
+    @NonnullAfterInit protected File idpHome;
+
+    /** Path to idp.war. */
+    @NonnullAfterInit protected Path pathToIdPWAR;
+
     /** Path to idp distribution. */
     @NonnullAfterInit protected Path pathToIdPDist;
 
@@ -380,12 +386,24 @@ public abstract class BaseIntegrationTest {
     /** Jetty version determined from distribution name. **/
     @Nullable protected String jettyVersion;
 
-    /** Path to module.bat or module.sh */
+    /** Path to build.sh or build.bat. */
+    @NonnullAfterInit protected Path pathToBuildCLI;
+    
+    /** Build CLI, either build.sh or build.bat. **/
+    @NonnullAfterInit protected String buildCLI;
+
+    /** Path to module.sh or module.bat. */
     @NonnullAfterInit protected Path pathToModuleCLI;
 
     /** Module CLI, either module.sh or module.bat. **/
     @NonnullAfterInit protected String moduleCLI;
     
+    /** Path to plugin.sh or plugin.bat. */
+    @NonnullAfterInit protected Path pathToPluginCLI;
+    
+    /** Plugin CLI, either plugin.sh or plugin.bat. **/
+    @NonnullAfterInit protected String pluginCLI;
+
     /** Class logger. */
     @Nonnull private final Logger log = LoggerFactory.getLogger(BaseIntegrationTest.class);
 
@@ -434,7 +452,7 @@ public abstract class BaseIntegrationTest {
         log.debug("Per-test directory '{}'", pathToPerTestDirectory);
         pathToIdPHome = pathToPerTestDirectory.resolve("shibboleth-idp");
         log.debug("Path to idp.home '{}'", pathToIdPHome.toAbsolutePath());
-        final File idpHome = pathToIdPHome.toAbsolutePath().toFile();
+        idpHome = pathToIdPHome.toAbsolutePath().toFile();
         Assert.assertFalse(idpHome.exists(), "Path to idp.home already exists");
         // Create empty idp.home directory
         Files.createDirectories(pathToIdPHome.toAbsolutePath());
@@ -466,35 +484,30 @@ public abstract class BaseIntegrationTest {
         final Process installerProcess = installerBuilder.start();
         logProcess(installerProcess, "install :");
 
-        // Find path to module.bat or module.sh
+        pathToBuildCLI = pathToIdPHome.resolve(Paths.get("bin", isWindows() ? "build.bat" : "build.sh"));
+        Assert.assertTrue(pathToBuildCLI.toFile().exists());
+        buildCLI = pathToBuildCLI.toAbsolutePath().toString();
+
         pathToModuleCLI = pathToIdPHome.resolve(Paths.get("bin", isWindows() ? "module.bat" : "module.sh"));
         Assert.assertTrue(pathToModuleCLI.toFile().exists());
         moduleCLI = pathToModuleCLI.toAbsolutePath().toString();
 
+        pathToPluginCLI = pathToIdPHome.resolve(Paths.get("bin", isWindows() ? "plugin.bat" : "plugin.sh"));
+        Assert.assertTrue(pathToPluginCLI.toFile().exists());
+        pluginCLI = pathToPluginCLI.toAbsolutePath().toString();
+
+        listModules();
         enableModule("idp.intercept.Consent");
         enableModule("idp.profile.CAS");
+        listModules();
         assertModulesAreEnabled("idp.intercept.Consent");
         assertModulesAreEnabled("idp.profile.CAS");
 
-        // Expand idp.war to webapp/ directory (so web.xml can be modified later if need be)
-        final Path pathToWebappDir = pathToIdPHome.resolve("webapp").toAbsolutePath();
-        log.debug("Path to webapp dir '{}'", pathToWebappDir);
-        Files.createDirectory(pathToWebappDir);
-        Assert.assertTrue(pathToWebappDir.toFile().exists());
-        if (isWindows()) {
-            logProcess(Runtime.getRuntime().exec("jar -xvf ..\\war\\idp.war", null, pathToWebappDir.toFile()), "jar :");
-        } else {
-            logProcess(Runtime.getRuntime().exec("jar -xvf ../war/idp.war", null, pathToWebappDir.toFile()), "jar :");
-        }
-
         // Copy directories from idp distribution to idp home
         copyFromIdPDistToIdPHome("metadata");
         copyFromIdPDistToIdPHome("credentials");
         copyFromIdPDistToIdPHome("testbed-war");
 
-        // Set idp.home system property, replace '\' with '/' for Windows
-        System.setProperty("idp.home", pathToIdPHome.toAbsolutePath().toString().replace('\\', '/'));
-
         // 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");
@@ -502,11 +515,18 @@ public abstract class BaseIntegrationTest {
         // Path to conf/ldap.properties
         pathToLDAPProperties = Paths.get(pathToIdPHome.toAbsolutePath().toString(), "conf", "ldap.properties");
         Assert.assertTrue(pathToLDAPProperties.toFile().exists(), "Path to conf/ldap.properties not found");
-        
+
         // Classpath messages.properties
         messagesPropertiesResource = new ClassPathResource("/net/shibboleth/idp/messages/messages.properties");
         Assert.assertTrue(messagesPropertiesResource.exists(), "Classpath resource messages.properties not found");
         log.debug("Path to message properties '{}'", messagesPropertiesResource);
+
+        pathToIdPWAR = pathToIdPHome.resolve("war").resolve("idp.war").toAbsolutePath();
+        log.debug("Path to idp.war '{}'", pathToIdPWAR);
+        Assert.assertTrue(pathToIdPWAR.toFile().exists());
+
+        // Set idp.home system property, replace '\' with '/' for Windows
+        System.setProperty("idp.home", pathToIdPHome.toAbsolutePath().toString().replace('\\', '/'));
     }
     
     /**
@@ -648,8 +668,10 @@ public abstract class BaseIntegrationTest {
             
             // set idp.home system property
             serverCommands.add(0, "-Didp.home=" + System.getProperty("idp.home"));
-            // set idp.war.path system property to webapp directory
-            serverCommands.add("-Didp.war.path=" + pathToIdPHome.resolve("webapp").toAbsolutePath());
+
+            // set idp.war.path system property to per-test directory
+            serverCommands.add("-Didp.war.path=" + pathToIdPWAR);
+
             // set tmp directory system property
             serverCommands.add("-Djava.io.tmpdir=" + pathToJettyBase.resolve("tmp").toAbsolutePath());
         } else {
@@ -919,8 +941,8 @@ public abstract class BaseIntegrationTest {
         replaceFile(pathToIdpIni, "\\z", System.lineSeparator() + "jetty.http.port=" + port);
 
         // Set secure container session cookie to false
-        final Path pathToIdPWebXML = Paths.get("webapp", "WEB-INF", "web.xml");
-        replaceIdPHomeFile(pathToIdPWebXML, "<secure>true</secure>", "<secure>false</secure>");
+        // TODO final Path pathToIdPWebXML = Paths.get("webapp", "WEB-INF", "web.xml");
+        // TODO replaceIdPHomeFile(pathToIdPWebXML, "<secure>true</secure>", "<secure>false</secure>");
 
         // Set secure cookies to false
         replaceIdPProperty("idp.cookie.secure", "false");
@@ -978,40 +1000,6 @@ public abstract class BaseIntegrationTest {
         replaceIdPHomeFile(pathToMetadataProvidersXML, oldText, newText);
     }
 
-    /**
-     * Add StorageServlet to IdP webapp.
-     * 
-     * @throws Exception if something bad happens
-     */
-    @BeforeClass(enabled = true, dependsOnMethods = {"setUpIdPPaths"})
-    public void setUpStorageServlet() throws Exception {
-
-        final Path pathToIdPWebXML = pathToIdPHome.resolve(Paths.get("webapp", "WEB-INF", "web.xml"));
-        Assert.assertTrue(pathToIdPWebXML.toAbsolutePath().toFile().exists(), "Path to IdP web.xml not found");
-
-        final String oldText = "</web-app>";
-
-        final StringBuilder builder = new StringBuilder();
-        builder.append("\n");
-        builder.append("<!-- The /storage app space. Interact with storage services via HTTP. -->\n");
-        builder.append("<servlet>\n");
-        builder.append("    <servlet-name>storage</servlet-name>\n");
-        builder.append("    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>\n");
-        builder.append("    <init-param>\n");
-        builder.append("        <param-name>contextConfigLocation</param-name>\n");
-        builder.append("        <param-value>classpath:/system/conf/storage-context.xml</param-value>\n");
-        builder.append("     </init-param>\n");
-        builder.append("     <load-on-startup>1</load-on-startup>\n");
-        builder.append("</servlet>\n");
-        builder.append("<servlet-mapping>\n");
-        builder.append("    <servlet-name>storage</servlet-name>\n");
-        builder.append("    <url-pattern>/storage/*</url-pattern>\n");
-        builder.append("</servlet-mapping>\n");
-        builder.append("</web-app>\n");
-
-        replaceFile(pathToIdPWebXML, oldText, builder.toString());
-    }
-
     @BeforeClass(enabled = true, dependsOnMethods = {"setUpIdPPaths", "setUpJettyPaths"})
     public void setUpIdPWebApp() throws Exception {
         if (Boolean.getBoolean("tomcat")) {
@@ -2364,6 +2352,25 @@ public abstract class BaseIntegrationTest {
         }
     }
 
+    /**
+     * Build IdP WAR.
+     * 
+     * @throws IOException
+     *             if an error occurs
+     */
+    public void buildWAR() throws IOException {
+
+        final String[] commands = new String[] {
+                buildCLI,
+                "-Didp.target.dir=" + idpHome };
+
+        final String logPrefix = "Build WAR :";
+
+        final Process process = Runtime.getRuntime().exec(commands, null, idpHome);
+
+        logProcess(process, logPrefix);
+    }
+
     /**
      * Parse output of `module.sh|.bat --list` and return list of disabled modules.
      * 
@@ -2377,7 +2384,7 @@ public abstract class BaseIntegrationTest {
 
         final List<String> disabledModules = new ArrayList<>();
 
-        final Process process = Runtime.getRuntime().exec(moduleCLI + " -l", null, pathToIdPHome.toFile());
+        final Process process = Runtime.getRuntime().exec(moduleCLI + " -l", null, idpHome);
 
         final BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
         String line = "";
@@ -2421,7 +2428,7 @@ public abstract class BaseIntegrationTest {
                 "-e",
                 module };
 
-        final Process process = Runtime.getRuntime().exec(commands, null, pathToIdPHome.toFile());
+        final Process process = Runtime.getRuntime().exec(commands, null, idpHome);
 
         logProcess(process, "module :");
     }
@@ -2453,7 +2460,7 @@ public abstract class BaseIntegrationTest {
 
         final List<String> enabledModules = new ArrayList<>();
 
-        final Process process = Runtime.getRuntime().exec(moduleCLI + " -l", null, pathToIdPHome.toFile());
+        final Process process = Runtime.getRuntime().exec(moduleCLI + " -l", null, idpHome);
 
         final BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
         String line = "";
@@ -2508,4 +2515,15 @@ public abstract class BaseIntegrationTest {
         }
     }
 
+    /**
+     * List IdP modules.
+     * 
+     * @throws IOException
+     *             if an error occurs
+     */
+    public void listModules() throws IOException {
+        final Process process = Runtime.getRuntime().exec(moduleCLI + " -l", null, idpHome);
+        logProcess(process, "modules :");
+    }
+
 }
diff --git a/src/test/java/net/shibboleth/idp/integration/tests/clientstorage/ClientStorageTest.java b/src/test/java/net/shibboleth/idp/integration/tests/clientstorage/ClientStorageTest.java
index 0f0eb5a..64f739e 100644
--- a/src/test/java/net/shibboleth/idp/integration/tests/clientstorage/ClientStorageTest.java
+++ b/src/test/java/net/shibboleth/idp/integration/tests/clientstorage/ClientStorageTest.java
@@ -17,6 +17,7 @@
 
 package net.shibboleth.idp.integration.tests.clientstorage;
 
+import java.nio.file.Path;
 import java.time.Duration;
 
 import javax.annotation.Nonnull;
@@ -41,8 +42,6 @@ import storage.SimpleStorageRecordSerializer;
 
 /**
  * Client storage tests.
- * 
- * TODO WIP
  */
 public class ClientStorageTest extends BaseIntegrationTest {
 
@@ -69,6 +68,54 @@ public class ClientStorageTest extends BaseIntegrationTest {
         serializer = new SimpleStorageRecordSerializer();
     }
 
+    /**
+     * Add testbed storage servlet to IdP.
+     * 
+     * @throws Exception if an error occurs
+     */
+    @BeforeClass(enabled = true, dependsOnMethods = {"setUpIdPPaths"})
+    public void setUpStorageServlet() throws Exception {
+
+        final Path pathToEditWebapp = pathToIdPHome.resolve("edit-webapp").toAbsolutePath();
+        log.debug("Path to edit-webapp '{}'", pathToEditWebapp);
+        Assert.assertTrue(pathToEditWebapp.toFile().exists(), "Path to edit-webapp " + pathToEditWebapp + " should exist");
+
+        // Extract web.xml from idp.war
+        if (isWindows()) {
+            logProcess(Runtime.getRuntime().exec("jar -xvf ..\\war\\idp.war WEB-INF\\web.xml", null, pathToEditWebapp.toFile()), "jar :");
+        } else {
+            logProcess(Runtime.getRuntime().exec("jar -xvf ../war/idp.war WEB-INF/web.xml", null, pathToEditWebapp.toFile()), "jar :");
+        }
+
+        final Path pathToCustomWebXML = pathToEditWebapp.resolve("WEB-INF").resolve("web.xml");
+        log.debug("Path to custom web.xml '{}'", pathToCustomWebXML);
+        Assert.assertTrue(pathToCustomWebXML.toFile().exists(), "Path to web.xml " + pathToCustomWebXML + " should exist");
+
+        final String oldText = "</web-app>";
+
+        final StringBuilder newText = new StringBuilder();
+        newText.append("\n");
+        newText.append("<!-- The /storage app space. Interact with storage services via HTTP. -->\n");
+        newText.append("<servlet>\n");
+        newText.append("    <servlet-name>storage</servlet-name>\n");
+        newText.append("    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>\n");
+        newText.append("    <init-param>\n");
+        newText.append("        <param-name>contextConfigLocation</param-name>\n");
+        newText.append("        <param-value>classpath:/system/conf/storage-context.xml</param-value>\n");
+        newText.append("     </init-param>\n");
+        newText.append("     <load-on-startup>1</load-on-startup>\n");
+        newText.append("</servlet>\n");
+        newText.append("<servlet-mapping>\n");
+        newText.append("    <servlet-name>storage</servlet-name>\n");
+        newText.append("    <url-pattern>/storage/*</url-pattern>\n");
+        newText.append("</servlet-mapping>\n");
+        newText.append("</web-app>\n");
+
+        replaceFile(pathToCustomWebXML, oldText, newText.toString());
+
+        buildWAR();
+    }
+
     /**
      * Initialize client storage by executing the test client-storage/read flow.
      */
diff --git a/src/test/java/net/shibboleth/idp/integration/tests/plugins/BasePluginTest.java b/src/test/java/net/shibboleth/idp/integration/tests/plugins/BasePluginTest.java
index 1d29c2f..fa01763 100644
--- a/src/test/java/net/shibboleth/idp/integration/tests/plugins/BasePluginTest.java
+++ b/src/test/java/net/shibboleth/idp/integration/tests/plugins/BasePluginTest.java
@@ -22,7 +22,6 @@ import java.io.File;
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.nio.file.Path;
-import java.nio.file.Paths;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -45,18 +44,6 @@ public abstract class BasePluginTest extends BaseIntegrationTest {
     @Nonnull
     protected final Logger log = LoggerFactory.getLogger(BasePluginTest.class);
 
-    /** IdP home directory */
-    @Nonnull
-    protected File idpHome;
-
-    /** Build CLI, either build.sh or build.bat */
-    @Nonnull
-    protected String buildCLI;
-
-    /** Plugin CLI, either plugin.sh or plugin.bat */
-    @Nonnull
-    protected String pluginCLI;
-
     /** Path to truststores directory */
     @Nonnull
     protected Path pathToTruststores;
@@ -66,41 +53,12 @@ public abstract class BasePluginTest extends BaseIntegrationTest {
     final public String truststoresResource = "/net/shibboleth/idp/integration/tests/truststores/";
 
     /**
-     * Set up paths to :
-     * <ul>
-     * <li>truststores directory</li>
-     * <li>IdP home directory</li>
-     * <li>plugin CLI</li>
-     * <li>build CLI</li>
-     * </ul>
-     * 
-     * @throws Exception
-     *             if an error occurs
+     * Set up path to truststores directory.
      */
     @BeforeClass
-    public void setUpPaths() throws Exception {
-
+    public void setUpPaths() {
         pathToTruststores = new File(getClass().getResource(truststoresResource).getFile()).toPath();
         Assert.assertTrue(pathToTruststores.toAbsolutePath().toFile().exists());
-
-        idpHome = pathToIdPHome.toAbsolutePath().toFile();
-        Assert.assertTrue(idpHome.exists(), "Path to idp.home not found");
-
-        final Path pathToPluginCLI = pathToIdPHome.resolve(Paths.get("bin", isWindows() ? "plugin.bat" : "plugin.sh"));
-        Assert.assertTrue(pathToPluginCLI.toFile().exists());
-        pluginCLI = pathToPluginCLI.toAbsolutePath().toString();
-
-        final Path pathToBuildCLI = pathToIdPHome.resolve(Paths.get("bin", isWindows() ? "build.bat" : "build.sh"));
-        Assert.assertTrue(pathToBuildCLI.toFile().exists());
-        buildCLI = pathToBuildCLI.toAbsolutePath().toString();
-
-        // Run IdP from WAR, not webapp/ directory
-        for (final String serverCommand : serverCommands) {
-            if (serverCommand.startsWith("-Didp.war.path=")) {
-                serverCommands.remove(serverCommand);
-            }
-        }
-        serverCommands.add("-Didp.war.path=" + pathToIdPHome.resolve("war").resolve("idp.war").toAbsolutePath());
     }
 
     /**
@@ -226,25 +184,6 @@ public abstract class BasePluginTest extends BaseIntegrationTest {
         return availablePlugins;
     }
 
-    /**
-     * Build IdP WAR.
-     * 
-     * @throws IOException
-     *             if an error occurs
-     */
-    public void buildWAR() throws IOException {
-
-        final String[] commands = new String[] {
-                buildCLI,
-                "-Didp.target.dir=" + idpHome };
-
-        final String logPrefix = "Build WAR :";
-
-        final Process process = Runtime.getRuntime().exec(commands, null, idpHome);
-
-        logProcess(process, logPrefix);
-    }
-
     /**
      * Install plugin.
      * 

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


More information about the commits mailing list