Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WFCORE-6679]: ManagementReadXmlTestCase inputs are too fragile. #5851

Merged
merged 3 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion testsuite/domain/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@
<failIfNoTests>false</failIfNoTests>

<!-- System properties to forked surefire JVM which runs clients. -->
<argLine>${jvm.args.ip.client} ${jvm.args.timeouts} ${surefire.system.args} -Djava.util.logging.manager=org.jboss.logmanager.LogManager</argLine>
<argLine>${jvm.args.ip.client} ${jvm.args.timeouts} ${surefire.system.args} -Dmaven.repo.local=${settings.localRepository} -Djava.util.logging.manager=org.jboss.logmanager.LogManager</argLine>

<systemPropertyVariables>
<jboss.options>-ea</jboss.options>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.junit.Test;

import java.util.List;

/**
*
* @author Dominik Pospisil <[email protected]>
Expand All @@ -34,63 +35,62 @@ public static void afterClass() throws Exception {

@Test
public void testConnect() throws Exception {
CLIWrapper cli = new CLIWrapper(false, DomainTestSupport.primaryAddress);
assertFalse(cli.isConnected());
assertTrue(cli.sendConnect(DomainTestSupport.primaryAddress));
assertTrue(cli.isConnected());
cli.quit();
try (CLIWrapper cli = new CLIWrapper(false, DomainTestSupport.primaryAddress)) {
assertFalse(cli.isConnected());
assertTrue(cli.sendConnect(DomainTestSupport.primaryAddress));
assertTrue(cli.isConnected());
cli.quit();
}
}

@Test
public void testDomainSetup() throws Exception {
CLIWrapper cli = new CLIWrapper(false, DomainTestSupport.primaryAddress);
assertFalse(cli.isConnected());
try (CLIWrapper cli = new CLIWrapper(false, DomainTestSupport.primaryAddress)) {
assertFalse(cli.isConnected());

assertTrue(cli.sendConnect(DomainTestSupport.primaryAddress));
assertTrue(cli.isConnected());
assertTrue(cli.sendConnect(DomainTestSupport.primaryAddress));
assertTrue(cli.isConnected());

// check hosts
cli.sendLine(":read-children-names(child-type=host)");
CLIOpResult res = cli.readAllAsOpResult();
assertTrue(res.getResult() instanceof List);
List<?> hosts = (List<?>) res.getResult();
// check hosts
cli.sendLine(":read-children-names(child-type=host)");
CLIOpResult res = cli.readAllAsOpResult();
assertTrue(res.getResult() instanceof List);
List<?> hosts = (List<?>) res.getResult();

assertTrue(hosts.contains("primary"));
assertTrue(hosts.contains("secondary"));
assertTrue(hosts.contains("primary"));
assertTrue(hosts.contains("secondary"));

// check servers
assertTrue(checkHostServers(cli, "primary", new String[] {"main-one", "main-two", "other-one", "reload-one"}));
assertTrue(checkHostServers(cli, "secondary", new String[] {"main-three", "main-four", "other-two", "reload-two"}));
cli.quit();
// check servers
assertTrue(checkHostServers(cli, "primary", new String[]{"main-one", "main-two", "other-one", "reload-one"}));
assertTrue(checkHostServers(cli, "secondary", new String[]{"main-three", "main-four", "other-two", "reload-two"}));
cli.quit();
}

}

@Test
public void testWalkLocalHosts() throws Exception {

CLIWrapper cli = new CLIWrapper(true, DomainTestSupport.primaryAddress);
try {
try (CLIWrapper cli = new CLIWrapper(true, DomainTestSupport.primaryAddress)) {
cli.sendLine("cd /host=primary/server=main-one");
cli.sendLine("cd /host=primary");
cli.sendLine("cd server=main-one");
cli.sendLine("cd core-service=platform-mbean/type=garbage-collector");
boolean failed = false;
try {
cli.sendLine("cd nonexistent=path");
} catch (Throwable t) {
failed = true;
cli.sendLine("cd /host=primary");
cli.sendLine("cd server=main-one");
cli.sendLine("cd core-service=platform-mbean/type=garbage-collector");
boolean failed = false;
try {
cli.sendLine("cd nonexistent=path");
} catch (Throwable t) {
failed = true;
}
assertTrue("should have failed", failed);
cli.quit();
}
assertTrue("should have failed", failed);
} finally {
cli.quit();
}
}

@Test
public void testWalkRemoteHosts() throws Exception {

CLIWrapper cli = new CLIWrapper(true, DomainTestSupport.primaryAddress);
try {
try (CLIWrapper cli = new CLIWrapper(true, DomainTestSupport.primaryAddress)) {
cli.sendLine("cd /host=secondary/server=main-three");
cli.sendLine("cd /host=secondary");
cli.sendLine("cd server=main-three");
Expand All @@ -102,21 +102,25 @@ public void testWalkRemoteHosts() throws Exception {
failed = true;
}
assertTrue("should have failed", failed);
} finally {
cli.quit();
}


}

private boolean checkHostServers(CLIWrapper cli, String host, String[] serverList) throws Exception {
cli.sendLine("/host=" + host + ":read-children-names(child-type=server-config)");
CLIOpResult res = cli.readAllAsOpResult();
assertTrue(res.getResult() instanceof List);
List<?> servers = (List<?>) res.getResult();
List<?> servers = (List<?>) res.getResult();

if (servers.size() != serverList.length) return false;
for (String server : serverList) if (!servers.contains(server)) return false;
if (servers.size() != serverList.length) {
return false;
}
for (String server : serverList) {
if (!servers.contains(server)) {
return false;
}
}

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

package org.jboss.as.test.integration.domain.suites;


import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.HOST;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR;
Expand Down Expand Up @@ -41,7 +43,9 @@
import org.jboss.as.controller.client.helpers.domain.DomainClient;
import org.jboss.as.test.integration.domain.management.util.DomainLifecycleUtil;
import org.jboss.as.test.integration.domain.management.util.DomainTestSupport;
import org.jboss.as.test.integration.management.util.CLIWrapper;
import org.jboss.dmr.ModelNode;
import org.jboss.logging.Logger;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
Expand All @@ -53,16 +57,99 @@
* @author Emmanuel Hugonnet (c) 2022 Red Hat, Inc.
*/
public class ManagementReadXmlTestCase {
private static final Logger log = Logger.getLogger("org.jboss.as.test.integration.domain");

private static DomainTestSupport testSupport;
private static DomainLifecycleUtil domainPrimaryLifecycleUtil;
private static DomainLifecycleUtil domainSecondaryLifecycleUtil;

private static void prepareExpectedServerConfiguration(String server, boolean propertyOne, int offset) throws Exception {
String serverConfigFileName = "expected-main-" + server + ".xml";
Path serverHome = new File(domainPrimaryLifecycleUtil.getConfiguration().getJbossHome()).toPath();
Path configurationDir = serverHome.resolve("standalone").resolve("configuration");
ehsavoie marked this conversation as resolved.
Show resolved Hide resolved
Files.createDirectories(configurationDir);
Path referenceConfiguration = configurationDir.resolve(serverConfigFileName);
Files.copy(new File("target").toPath().resolve("test-classes").resolve("base-server-config.xml"), referenceConfiguration, REPLACE_EXISTING);
try (CLIWrapper cli = new CLIWrapper(false)) {
log.info("Executing the following command on cli: embed-server --admin-only --server-config=" + serverConfigFileName + " --jboss-home=" + serverHome.toAbsolutePath());
cli.sendLine("embed-server --admin-only --server-config=" + serverConfigFileName + " --jboss-home=" + serverHome.toAbsolutePath());
if(!propertyOne) {
cli.sendLine("/system-property=jboss.domain.test.property.one:remove()");
cli.sendLine("/system-property=jboss.domain.test.property.one:add(value=ONE)");
cli.sendLine("/path=domainTestPath:remove()");
cli.sendLine("/path=domainTestPath:add(path=\"/tmp\")");
}
cli.sendLine("/subsystem=logging:add()");
cli.sendLine("/subsystem=logging/console-handler=CONSOLE:add(level=INFO, formatter=\"%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n\")");
cli.sendLine("/subsystem=logging/periodic-rotating-file-handler=FILE:add(level=INFO, suffix=\".yyyy-MM-dd\", formatter=\"%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n\", file={relative-to=\"jboss.server.log.dir\", path=\"server.log\"})");
cli.sendLine("/subsystem=logging/logger=org.jboss.as.controller:add(category=\"org.jboss.as.controller\", level=TRACE)");
cli.sendLine("/subsystem=logging/root-logger=ROOT:add(handlers=[CONSOLE, FILE], level=INFO)");
cli.sendLine("/subsystem=core-management:add()");

cli.sendLine("batch");
cli.sendLine("/subsystem=elytron:add(disallowed-providers=[\"OracleUcrypto\"],final-providers=combined-providers)");
cli.sendLine("/subsystem=elytron/provider-loader=elytron:add(module=org.wildfly.security.elytron)");
cli.sendLine("/subsystem=elytron/provider-loader=openssl:add(module=org.wildfly.openssl)");
cli.sendLine("/subsystem=elytron/aggregate-providers=combined-providers:add(providers=[\"elytron\",\"openssl\"])");
cli.sendLine("/subsystem=elytron/identity-realm=local:add(identity=\"$local\")");
cli.sendLine("/subsystem=elytron/file-audit-log=local-audit:add(format=JSON,path=audit.log,relative-to=jboss.server.log.dir)");
cli.sendLine("/subsystem=elytron/constant-realm-mapper=local:add(realm-name=local)");
cli.sendLine("/subsystem=elytron/provider-http-server-mechanism-factory=global:add()");
cli.sendLine("/subsystem=elytron/simple-permission-mapper=default-permission-mapper:add(mapping-mode=first,"
+ "permission-mappings=[{\"principals\" => [\"anonymous\"],"
+ "\"permission-sets\" => [(\"permission-set\" => \"default-permissions\")]},{\"match-all\" => \"true\","
+ "\"permission-sets\" => [(\"permission-set\" => \"login-permission\"),(\"permission-set\" => \"default-permissions\")]}])");
cli.sendLine("/subsystem=elytron/simple-role-decoder=groups-to-roles:add(attribute=groups)");
cli.sendLine("/subsystem=elytron/provider-sasl-server-factory=global:add");
cli.sendLine("/subsystem=elytron/mechanism-provider-filtering-sasl-server-factory=elytron:add(filters=[{\"provider-name\" => \"WildFlyElytron\"}],sasl-server-factory=global)");
cli.sendLine("/subsystem=elytron/configurable-sasl-server-factory=configured:add(properties={\"wildfly.sasl.local-user.default-user\" => \"$local\"},sasl-server-factory=elytron)");
cli.sendLine("/subsystem=elytron/constant-role-mapper=super-user-mapper:add(roles=[\"SuperUser\"])");
cli.sendLine("/subsystem=elytron/permission-set=login-permission:add(permissions=[(\"class-name\" => \"org.wildfly.security.auth.permission.LoginPermission\")])");
cli.sendLine("/subsystem=elytron/permission-set=default-permissions:add(permissions=[])");
cli.sendLine("/subsystem=elytron/properties-realm=ApplicationRealm:add(users-properties={"
+ "\"path\" => \"application-users.properties\","
+ "\"relative-to\" => \"jboss.domain.config.dir\","
+ "\"digest-realm-name\" => \"ApplicationRealm\"})");
cli.sendLine("/subsystem=elytron/security-domain=ApplicationDomain:add(default-realm=ApplicationRealm,permission-mapper=default-permission-mapper,realms=[{\"realm\" => \"ApplicationRealm\",\"role-decoder\" => \"groups-to-roles\"},{\"realm\" => \"local\"}])");
cli.sendLine("/subsystem=elytron/sasl-authentication-factory=application-sasl-authentication:add(mechanism-configurations=[{\"mechanism-name\" => \"JBOSS-LOCAL-USER\",\"realm-mapper\" => \"local\"},{\"mechanism-name\" => \"DIGEST-MD5\",\"mechanism-realm-configurations\" => [{\"realm-name\" => \"ApplicationRealm\"}]}],sasl-server-factory=configured,security-domain=ApplicationDomain)");
cli.sendLine("/subsystem=elytron/key-store=applicationKS:add(credential-reference={\"clear-text\" => \"password\"},path=application.keystore,relative-to=jboss.domain.config.dir,type=JKS)");
cli.sendLine("/subsystem=elytron/key-manager=applicationKM:add(credential-reference={\"clear-text\" => \"password\"},generate-self-signed-certificate-host=localhost,key-store=applicationKS)");
cli.sendLine("/subsystem=elytron/server-ssl-context=applicationSSC:add(key-manager=applicationKM)");
cli.sendLine("run-batch");

cli.sendLine("/subsystem=io:add()");
cli.sendLine("/subsystem=io/worker=default:add()");
cli.sendLine("/subsystem=io/buffer-pool=default:add()");

cli.sendLine("/subsystem=jmx:add()");
cli.sendLine("/subsystem=jmx/expose-model=resolved:add()");
cli.sendLine("/subsystem=jmx/expose-model=expression:add()");
cli.sendLine("/subsystem=jmx/remoting-connector=jmx:add()");

cli.sendLine("/subsystem=remoting:add()");
cli.sendLine("/subsystem=remoting/connector=remoting-connector:add(socket-binding=remoting, sasl-authentication-factory=application-sasl-authentication)");

cli.sendLine("/subsystem=request-controller:add()");

cli.sendLine("/subsystem=security-manager:add()");
cli.sendLine("/subsystem=security-manager/deployment-permissions=default:add(maximum-permissions=[{class=java.security.AllPermission}]");
if(!propertyOne) {
cli.sendLine("/interface=management:write-attribute(name=inet-address,value=\"${jboss.test.host.secondary.address}\")");
cli.sendLine("/interface=public:write-attribute(name=inet-address,value=\"${jboss.test.host.secondary.address}\")");
}
cli.sendLine("/socket-binding-group=standard-sockets:write-attribute(name=port-offset, value=" + offset + ")");
cli.quit();
}
Files.move(referenceConfiguration, new File("target").toPath().toAbsolutePath().resolve("test-classes").resolve(referenceConfiguration.getFileName()), REPLACE_EXISTING);
}

@BeforeClass
public static void setupDomain() throws Exception {
testSupport = DomainTestSuite.createSupport(ManagementReadXmlTestCase.class.getSimpleName());
domainPrimaryLifecycleUtil = testSupport.getDomainPrimaryLifecycleUtil();
domainSecondaryLifecycleUtil = testSupport.getDomainSecondaryLifecycleUtil();
prepareExpectedServerConfiguration("one", true, 0);
prepareExpectedServerConfiguration("three", false, 350);
}

@AfterClass
Expand Down Expand Up @@ -148,8 +235,8 @@ public void testServerReadConfigAsXml() throws Exception {

OperationResponse opResponse = domainClient.executeOperation(Operation.Factory.create(request), OperationMessageHandler.DISCARD);
String xml = validateOperationResponse(opResponse);
Path expected = new File("target/test-classes", "expected-main-one.xml").toPath();
String expectedXml = readFileAsString(expected).replaceAll(System.lineSeparator(), "\n");
Path expected = new File("target").toPath().resolve("test-classes").resolve("expected-main-one.xml");
String expectedXml = readFileAsString(expected).replaceAll(System.lineSeparator(), "\n") + "\n";
Files.write(new File("target", "expected-main-one.xml").toPath(), Collections.singletonList(expectedXml));
Path result = new File("target", "result-main-one.xml").toPath();
Files.write(result, Collections.singletonList(xml));
Expand All @@ -160,7 +247,7 @@ public void testServerReadConfigAsXml() throws Exception {
request.get(OP_ADDR).setEmptyList().add(HOST, "secondary").add(SERVER, "main-three");
opResponse = domainClient.executeOperation(Operation.Factory.create(request), OperationMessageHandler.DISCARD);
xml = validateOperationResponse(opResponse);
expected = new File("target/test-classes", "expected-main-three.xml").toPath();
expected = new File("target").toPath().resolve("test-classes").resolve("expected-main-three.xml");
expectedXml = readFileAsString(expected).replaceAll(System.lineSeparator(), "\n");
Files.write(new File("target", "expected-main-three.xml").toPath(), Collections.singletonList(expectedXml));
result = new File("target", "result-main-three.xml").toPath();
Expand Down
Loading