[java-idp-integration-tests] branch main updated: Test starting the IdP with all modules enabled.
Tom Zeller
tzeller at dragonacea.biz
Tue Jan 3 22:28:30 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=0c40c9597d85b8271677a54ec02d0bb2060c2cc0
The following commit(s) were added to refs/heads/main by this push:
new 0c40c95 Test starting the IdP with all modules enabled.
0c40c95 is described below
commit 0c40c9597d85b8271677a54ec02d0bb2060c2cc0
Author: Tom Zeller <tzeller at dragonacea.biz>
AuthorDate: Tue Jan 3 16:28:05 2023 -0600
Test starting the IdP with all modules enabled.
---
.../idp/integration/tests/ModuleTest.java | 126 +++++++++++++++++++++
1 file changed, 126 insertions(+)
diff --git a/src/test/java/net/shibboleth/idp/integration/tests/ModuleTest.java b/src/test/java/net/shibboleth/idp/integration/tests/ModuleTest.java
new file mode 100644
index 0000000..209edfd
--- /dev/null
+++ b/src/test/java/net/shibboleth/idp/integration/tests/ModuleTest.java
@@ -0,0 +1,126 @@
+/*
+ * 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.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;
+
+/**
+ * Test IdP modules.
+ */
+public class ModuleTest extends BaseIntegrationTest {
+
+ /**
+ * Test starting the IdP with all modules enabled.
+ *
+ * @param browserData
+ * the platform+browser+version triplet
+ * @throws Exception
+ * if an error occurs
+ */
+ @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();
+
+ // Get modules to enable by listing all modules and selecting disabled modules
+ final List<String> modulesToEnable = modulesToEnable(
+ Runtime.getRuntime().exec(moduleCmd + " -l", null, idpHome));
+
+ // 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 :");
+
+ 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;
+ }
+
+}
\ No newline at end of file
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list