[java-idp-integration-tests] 02/02: Enable all modules

Tom Zeller tzeller at dragonacea.biz
Fri Jan 6 00:05:10 UTC 2023


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

tzeller pushed a commit to branch dev/plugin-tests
in repository java-idp-integration-tests.

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

commit 0d0ffacdac9daf2d9642b3dd685d5d0ff570f64a
Author: Tom Zeller <tzeller at dragonacea.biz>
AuthorDate: Thu Jan 5 18:04:58 2023 -0600

    Enable all modules
---
 .../idp/integration/tests/BaseIntegrationTest.java | 174 +++++++++++++++++++--
 .../idp/integration/tests/ModuleTest.java          |  83 +---------
 .../integration/tests/plugins/BasePluginTest.java  |  13 ++
 3 files changed, 176 insertions(+), 94 deletions(-)

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 75fcf13..ca1dc37 100644
--- a/src/test/java/net/shibboleth/idp/integration/tests/BaseIntegrationTest.java
+++ b/src/test/java/net/shibboleth/idp/integration/tests/BaseIntegrationTest.java
@@ -380,6 +380,12 @@ public abstract class BaseIntegrationTest {
     /** Jetty version determined from distribution name. **/
     @Nullable protected String jettyVersion;
 
+    /** Path to module.bat or module.sh */
+    @NonnullAfterInit protected Path pathToModuleCLI;
+
+    /** Module CLI, either module.sh or module.bat. **/
+    @NonnullAfterInit protected String moduleCLI;
+    
     /** Class logger. */
     @Nonnull private final Logger log = LoggerFactory.getLogger(BaseIntegrationTest.class);
 
@@ -460,21 +466,15 @@ public abstract class BaseIntegrationTest {
         final Process installerProcess = installerBuilder.start();
         logProcess(installerProcess, "install :");
 
-        // List and enable modules
-        if (isWindows()) {
-            final Path pathToModuleBat = pathToIdPHome.resolve(Paths.get("bin", "module.bat"));
-            Assert.assertTrue(pathToModuleBat.toFile().exists());
-            final String moduleBat = pathToModuleBat.toAbsolutePath().toString();
-            logProcess(Runtime.getRuntime().exec(moduleBat + " -l", null, idpHome), "module :");
-            logProcess(Runtime.getRuntime().exec(moduleBat + " -e idp.intercept.Consent", null, idpHome),"module :");
-            logProcess(Runtime.getRuntime().exec(moduleBat + " -e idp.profile.CAS", null, idpHome), "module :");
-            logProcess(Runtime.getRuntime().exec(moduleBat + " -l", null, idpHome), "module :");
-        } else {
-            logProcess(Runtime.getRuntime().exec("bin/module.sh -l", null, idpHome), "module :");
-            logProcess(Runtime.getRuntime().exec("bin/module.sh -e idp.intercept.Consent", null, idpHome),"module :");
-            logProcess(Runtime.getRuntime().exec("bin/module.sh -e idp.profile.CAS", null, idpHome), "module :");
-            logProcess(Runtime.getRuntime().exec("bin/module.sh -l", null, idpHome), "module :");
-        }
+        // Find path to module.bat or module.sh
+        pathToModuleCLI = pathToIdPHome.resolve(Paths.get("bin", isWindows() ? "module.bat" : "module.sh"));
+        Assert.assertTrue(pathToModuleCLI.toFile().exists());
+        moduleCLI = pathToModuleCLI.toAbsolutePath().toString();
+
+        enableModule("idp.intercept.Consent");
+        enableModule("idp.profile.CAS");
+        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();
@@ -2364,4 +2364,148 @@ public abstract class BaseIntegrationTest {
         }
     }
 
+    /**
+     * Parse output of `module.sh|.bat --list` and return list of disabled modules.
+     * 
+     * @param process
+     *            module CLI
+     * @return list of disabled modules
+     * @throws IOException
+     *             If an I/O error occurs
+     */
+    public @Nonnull List<String> disabledModules() throws IOException {
+
+        final List<String> disabledModules = new ArrayList<>();
+
+        final Process process = Runtime.getRuntime().exec(moduleCLI + " -l", null, pathToIdPHome.toFile());
+
+        final BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
+        String line = "";
+        while ((line = reader.readLine()) != null) {
+            // line should be something like :
+            // Module: idp.authn.Duo [ENABLED]
+            // or
+            // Module: idp.authn.External [DISABLED]
+            //
+            // Remove terminal codes since --ansi is the default.
+            line = line.replaceAll("\u001B\\[\\d+m", "");
+            // Split line, for example :
+            // strings[0] = Module:
+            // strings[1] = idp.authn.Duo
+            // strings[1] = [ENABLED]
+            final String[] strings = line.split(" ");
+            // If module is disabled, add to list to enable
+            if (strings.length == 3 && strings[2].matches(".*DISABLED.*")) {
+                // Do not enable the Attended Restart feature as it requires some configuration
+                if (strings[1].equals("idp.admin.UnlockKeys")) {
+                    continue;
+                }
+                disabledModules.add(strings[1]);
+            }
+        }
+        return disabledModules;
+    }
+
+    /**
+     * Enable IdP module.
+     * 
+     * @param module
+     *            module to be enabled
+     * @throws IOException
+     *             if an error occurs
+     */
+    public void enableModule(@Nonnull final String module) throws IOException {
+
+        final String[] commands = new String[] {
+                moduleCLI,
+                "-e",
+                module };
+
+        final Process process = Runtime.getRuntime().exec(commands, null, pathToIdPHome.toFile());
+
+        logProcess(process, "module :");
+    }
+
+    /**
+     * Enable IdP modules.
+     * 
+     * @param modules
+     *            modules to be enabled
+     * @throws IOException
+     *             if an error occurs
+     */
+    public void enableModules(@Nonnull final String... modules) throws IOException {
+        for (final String module : modules) {
+            enableModule(module);
+        }
+    }
+
+    /**
+     * Parse output of `module.sh|.bat --list` and return list of enabled modules.
+     * 
+     * @param process
+     *            module CLI
+     * @return list of enabled modules
+     * @throws IOException
+     *             If an I/O error occurs
+     */
+    public @Nonnull List<String> enabledModules() throws IOException {
+
+        final List<String> enabledModules = new ArrayList<>();
+
+        final Process process = Runtime.getRuntime().exec(moduleCLI + " -l", null, pathToIdPHome.toFile());
+
+        final BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
+        String line = "";
+        while ((line = reader.readLine()) != null) {
+            // line should be something like :
+            // Module: idp.authn.Duo [ENABLED]
+            // or
+            // Module: idp.authn.External [DISABLED]
+            //
+            // Remove terminal codes since --ansi is the default.
+            line = line.replaceAll("\u001B\\[\\d+m", "");
+            // Split line, for example :
+            // strings[0] = Module:
+            // strings[1] = idp.authn.Duo
+            // strings[1] = [ENABLED]
+            final String[] strings = line.split(" ");
+            // If module is disabled, add to list to enable
+            if (strings.length == 3 && strings[2].matches(".*ENABLED.*")) {
+                enabledModules.add(strings[1]);
+            }
+        }
+        return enabledModules;
+    }
+
+    /**
+     * Assert that modules are enabled.
+     * 
+     * @param modules
+     *            modules that should be enabled
+     * @throws IOException
+     *             if an error occurs
+     */
+    public void assertModulesAreEnabled(@Nonnull final String... modules) throws IOException {
+        final List<String> enabledModules = enabledModules();
+        for (final String module : modules) {
+            Assert.assertTrue(enabledModules.contains(module), "Module " + module + " should be enabled");
+        }
+    }
+
+    /**
+     * Assert that modules are listed on the status page.
+     * 
+     * @param modules
+     *            modules that should be listed on the status page
+     * @throws Exception
+     *             if an error occurs
+     */
+    public void assertModuleAreOnStatusPage(@Nonnull final String... modules) throws Exception {
+        final String statusPage = server.waitForStatusPage();
+        for (final String module : modules) {
+            Assert.assertTrue(statusPage.contains(module), "Status page should contain module " + module);
+        }
+    }
+
 }
diff --git a/src/test/java/net/shibboleth/idp/integration/tests/ModuleTest.java b/src/test/java/net/shibboleth/idp/integration/tests/ModuleTest.java
index 209edfd..d154de2 100644
--- a/src/test/java/net/shibboleth/idp/integration/tests/ModuleTest.java
+++ b/src/test/java/net/shibboleth/idp/integration/tests/ModuleTest.java
@@ -17,19 +17,8 @@
 
 package net.shibboleth.idp.integration.tests;
 
-import java.io.BufferedReader;
-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;
-
-import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 
-import org.testng.Assert;
 import org.testng.annotations.Test;
 
 /**
@@ -48,79 +37,15 @@ public class ModuleTest extends BaseIntegrationTest {
     @Test(dataProvider = "sauceOnDemandBrowserDataProvider")
     public void testStartingServerWithAllModulesEnabled(@Nullable final BrowserData browserData) throws Exception {
 
-        startSeleniumClient(browserData);
-
-        // Find IdP home directory
-        final File idpHome = pathToIdPHome.toAbsolutePath().toFile();
-        Assert.assertTrue(idpHome.exists(), "Path to idp.home not found");
-
-        // Find path to module.bat or module.sh
-        final Path pathToModuleCmd = pathToIdPHome.resolve(Paths.get("bin", isWindows() ? "module.bat" : "module.sh"));
-        Assert.assertTrue(pathToModuleCmd.toFile().exists());
-        final String moduleCmd = pathToModuleCmd.toAbsolutePath().toString();
+        final String[] modulesToEnable = disabledModules().toArray(String[]::new);
 
-        // Get modules to enable by listing all modules and selecting disabled modules
-        final List<String> modulesToEnable = modulesToEnable(
-                Runtime.getRuntime().exec(moduleCmd + " -l", null, idpHome));
+        enableModules(modulesToEnable);
 
-        // Enable each disabled module
-        for (String moduleToEnable : modulesToEnable) {
-            logProcess(Runtime.getRuntime().exec(moduleCmd + " -e " + moduleToEnable, null, idpHome), " enable: ");
-        }
-
-        // List modules
-        logProcess(Runtime.getRuntime().exec(moduleCmd + " -l", null, idpHome), "module :");
+        assertModulesAreEnabled(modulesToEnable);
 
         startServer();
 
-        // Get status page
-        driver.get(getBaseURL() + StatusTest.statusPath);
-        final String statusPage = getPageSource();
-
-        Assert.assertTrue(statusPage.startsWith(StatusTest.STARTS_WITH));
-
-        // Assert that the status page contains the modules which were enabled
-        for (final String moduleToEnable : modulesToEnable) {
-            Assert.assertTrue(statusPage.contains(moduleToEnable), "Status page contains module " + moduleToEnable);
-        }
-    }
-
-    /**
-     * Parse output of `module.sh|.bat --list` and return list of disabled modules.
-     * 
-     * @param process
-     *            module CLI
-     * @return list of modules to enable
-     * @throws IOException
-     *             If an I/O error occurs
-     */
-    public @Nonnull List<String> modulesToEnable(@Nonnull final Process process) throws IOException {
-        final List<String> modulesToEnable = new ArrayList<>();
-        final BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
-        String line = "";
-        while ((line = reader.readLine()) != null) {
-            // line should be something like :
-            // Module: idp.authn.Duo [ENABLED]
-            // or
-            // Module: idp.authn.External [DISABLED]
-            //
-            // Remove terminal codes since --ansi is the default.
-            line = line.replaceAll("\u001B\\[\\d+m", "");
-            // Split line, for example :
-            // strings[0] = Module:
-            // strings[1] = idp.authn.Duo
-            // strings[1] = [ENABLED]
-            final String[] strings = line.split(" ");
-            // If module is disabled, add to list to enable
-            if (strings.length == 3 && strings[2].matches(".*DISABLED.*")) {
-                // Do not enable the Attended Restart feature as it requires some configuration
-                if (strings[1].equals("idp.admin.UnlockKeys")) {
-                    continue;
-                }
-                modulesToEnable.add(strings[1]);
-            }
-        }
-        return modulesToEnable;
+        assertModuleAreOnStatusPage(modulesToEnable);
     }
 
 }
\ No newline at end of file
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 19779f1..1d29c2f 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
@@ -103,6 +103,19 @@ public abstract class BasePluginTest extends BaseIntegrationTest {
         serverCommands.add("-Didp.war.path=" + pathToIdPHome.resolve("war").resolve("idp.war").toAbsolutePath());
     }
 
+    /**
+     * Enable all IdP modules.
+     * 
+     * @throws Exception
+     *             if an error occurs
+     */
+    @BeforeClass
+    public void enableAllModules() throws Exception {
+        final String[] modulesToEnable = disabledModules().toArray(String[]::new);
+        enableModules(modulesToEnable);
+        assertModulesAreEnabled(modulesToEnable);
+    }
+
     /**
      * Assert that plugins are available to be installed.
      * 

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


More information about the commits mailing list