From d48fe23399a21a39ef71f47f3e509f338505df28 Mon Sep 17 00:00:00 2001 From: xjusko Date: Thu, 5 Oct 2023 09:20:08 +0200 Subject: [PATCH] [WFCORE-6532] Add security manager to script tests --- .../scripts/test/DomainScriptTestCase.java | 27 ++++++++++++++++++- .../test/StandaloneScriptTestCase.java | 10 ++++++- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/testsuite/scripts/src/test/java/org/wildfly/scripts/test/DomainScriptTestCase.java b/testsuite/scripts/src/test/java/org/wildfly/scripts/test/DomainScriptTestCase.java index e23f9d2ca67..330cdcdc7d2 100644 --- a/testsuite/scripts/src/test/java/org/wildfly/scripts/test/DomainScriptTestCase.java +++ b/testsuite/scripts/src/test/java/org/wildfly/scripts/test/DomainScriptTestCase.java @@ -6,6 +6,11 @@ package org.wildfly.scripts.test; import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.Map; import java.util.concurrent.Callable; import java.util.concurrent.TimeoutException; import java.util.function.Function; @@ -15,22 +20,42 @@ import org.jboss.as.test.shared.TestSuiteEnvironment; import org.jboss.dmr.ModelNode; import org.junit.Assert; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; import org.wildfly.common.test.ServerHelper; /** * @author James R. Perkins */ +@RunWith(Parameterized.class) public class DomainScriptTestCase extends ScriptTestCase { private static final Function HOST_CONTROLLER_CHECK = ServerHelper::isDomainRunning; + @Parameterized.Parameter + public Map env; public DomainScriptTestCase() { super("domain"); } + @Parameterized.Parameters + public static Collection data() { + final Collection result = new ArrayList<>(2); + result.add(Collections.emptyMap()); + result.add(Collections.singletonMap("SECMGR", "true")); + return result; + } + @Override void testScript(final ScriptProcess script) throws InterruptedException, TimeoutException, IOException { - script.start(HOST_CONTROLLER_CHECK, ServerHelper.DEFAULT_SERVER_JAVA_OPTS); + boolean isSecurityManagerEnabled = Boolean.parseBoolean(System.getProperty("security.manager")); + + String[] modifiedJavaOpts = Arrays.copyOf(ServerHelper.DEFAULT_SERVER_JAVA_OPTS, ServerHelper.DEFAULT_SERVER_JAVA_OPTS.length + 1); + modifiedJavaOpts[modifiedJavaOpts.length - 1] = "-secmgr"; + + String[] javaOptsToUse = isSecurityManagerEnabled ? modifiedJavaOpts : ServerHelper.DEFAULT_SERVER_JAVA_OPTS; + + script.start(HOST_CONTROLLER_CHECK, env, javaOptsToUse); Assert.assertNotNull("The process is null and may have failed to start.", script); Assert.assertTrue("The process is not running and should be", script.isAlive()); diff --git a/testsuite/scripts/src/test/java/org/wildfly/scripts/test/StandaloneScriptTestCase.java b/testsuite/scripts/src/test/java/org/wildfly/scripts/test/StandaloneScriptTestCase.java index 65376bdf4f3..bd70c756388 100644 --- a/testsuite/scripts/src/test/java/org/wildfly/scripts/test/StandaloneScriptTestCase.java +++ b/testsuite/scripts/src/test/java/org/wildfly/scripts/test/StandaloneScriptTestCase.java @@ -9,6 +9,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.List; @@ -56,6 +57,7 @@ public static Collection data() { result.add(Collections.emptyMap()); result.add(Collections.singletonMap("GC_LOG", "true")); result.add(Collections.singletonMap("MODULE_OPTS", "-javaagent:logging-agent-tests.jar=" + LoggingAgent.DEBUG_ARG)); + result.add(Collections.singletonMap("SECMGR", "true")); return result; } @@ -89,7 +91,13 @@ void testScript(final ScriptProcess script) throws InterruptedException, Timeout // seem to work when a directory has a space. An error indicating the trailing quote cannot be found. Removing // the `\ parts and just keeping quotes ends in the error shown in JDK-8215398. Assume.assumeFalse(TestSuiteEnvironment.isWindows() && env.containsKey("GC_LOG") && script.getScript().toString().contains(" ")); - script.start(STANDALONE_CHECK, env, ServerHelper.DEFAULT_SERVER_JAVA_OPTS); + + boolean isSecurityManagerEnabled = Boolean.parseBoolean(System.getProperty("security.manager")); + String[] modifiedJavaOpts = Arrays.copyOf(ServerHelper.DEFAULT_SERVER_JAVA_OPTS, ServerHelper.DEFAULT_SERVER_JAVA_OPTS.length + 1); + modifiedJavaOpts[modifiedJavaOpts.length - 1] = "-secmgr"; + String[] javaOptsToUse = isSecurityManagerEnabled ? modifiedJavaOpts : ServerHelper.DEFAULT_SERVER_JAVA_OPTS; + script.start(STANDALONE_CHECK, env, javaOptsToUse); + Assert.assertNotNull("The process is null and may have failed to start.", script); Assert.assertTrue("The process is not running and should be", script.isAlive());