Skip to content

Commit

Permalink
[WFCORE-6532] Add security manager to script tests
Browse files Browse the repository at this point in the history
  • Loading branch information
xjusko committed Oct 10, 2023
1 parent fec6a97 commit d48fe23
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 <a href="mailto:[email protected]">James R. Perkins</a>
*/
@RunWith(Parameterized.class)
public class DomainScriptTestCase extends ScriptTestCase {

private static final Function<ModelControllerClient, Boolean> HOST_CONTROLLER_CHECK = ServerHelper::isDomainRunning;

@Parameterized.Parameter
public Map<String, String> env;
public DomainScriptTestCase() {
super("domain");
}

@Parameterized.Parameters
public static Collection<Object> data() {
final Collection<Object> 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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -56,6 +57,7 @@ public static Collection<Object> 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;
}

Expand Down Expand Up @@ -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());

Expand Down

0 comments on commit d48fe23

Please sign in to comment.