From 2f5d7e9f14d01b702eaf7aeeb03e10dc1e5b6214 Mon Sep 17 00:00:00 2001 From: Emmanuel Hugonnet Date: Tue, 27 Feb 2024 13:40:16 +0100 Subject: [PATCH 1/3] [WFCORE-6679]: ManagementReadXmlTestCase inputs are too fragile. * Generating the servers configuration through scripts to make them less fragile. Jira: https://issues.redhat.com/browse/WFCORE-6679 Signed-off-by: Emmanuel Hugonnet --- .../suites/ManagementReadXmlTestCase.java | 90 +++++++- .../src/test/resources/base-server-config.xml | 71 ++++++ .../src/test/resources/expected-main-one.xml | 207 ------------------ .../test/resources/expected-main-three.xml | 207 ------------------ 4 files changed, 158 insertions(+), 417 deletions(-) create mode 100644 testsuite/domain/src/test/resources/base-server-config.xml delete mode 100644 testsuite/domain/src/test/resources/expected-main-one.xml delete mode 100644 testsuite/domain/src/test/resources/expected-main-three.xml diff --git a/testsuite/domain/src/test/java/org/jboss/as/test/integration/domain/suites/ManagementReadXmlTestCase.java b/testsuite/domain/src/test/java/org/jboss/as/test/integration/domain/suites/ManagementReadXmlTestCase.java index 8bb8004bb93..62d4980a3e0 100644 --- a/testsuite/domain/src/test/java/org/jboss/as/test/integration/domain/suites/ManagementReadXmlTestCase.java +++ b/testsuite/domain/src/test/java/org/jboss/as/test/integration/domain/suites/ManagementReadXmlTestCase.java @@ -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; @@ -41,6 +43,7 @@ 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.junit.AfterClass; import org.junit.Assert; @@ -58,11 +61,92 @@ public class ManagementReadXmlTestCase { 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"); + 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)) { + 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 @@ -148,8 +232,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)); @@ -160,7 +244,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(); diff --git a/testsuite/domain/src/test/resources/base-server-config.xml b/testsuite/domain/src/test/resources/base-server-config.xml new file mode 100644 index 00000000000..144bec65579 --- /dev/null +++ b/testsuite/domain/src/test/resources/base-server-config.xml @@ -0,0 +1,71 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/testsuite/domain/src/test/resources/expected-main-one.xml b/testsuite/domain/src/test/resources/expected-main-one.xml deleted file mode 100644 index 230827bcb73..00000000000 --- a/testsuite/domain/src/test/resources/expected-main-one.xml +++ /dev/null @@ -1,207 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/testsuite/domain/src/test/resources/expected-main-three.xml b/testsuite/domain/src/test/resources/expected-main-three.xml deleted file mode 100644 index b77618bed9f..00000000000 --- a/testsuite/domain/src/test/resources/expected-main-three.xml +++ /dev/null @@ -1,207 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file From 97a90b77f2684308158e3167cc1dc896d9314ee5 Mon Sep 17 00:00:00 2001 From: Emmanuel Hugonnet Date: Tue, 27 Feb 2024 17:04:59 +0100 Subject: [PATCH 2/3] [WFCORE-6679]: Adding traces Signed-off-by: Emmanuel Hugonnet --- .../management/cli/BasicOpsTestCase.java | 86 ++++++++++--------- .../suites/ManagementReadXmlTestCase.java | 3 + 2 files changed, 48 insertions(+), 41 deletions(-) diff --git a/testsuite/domain/src/test/java/org/jboss/as/test/integration/domain/management/cli/BasicOpsTestCase.java b/testsuite/domain/src/test/java/org/jboss/as/test/integration/domain/management/cli/BasicOpsTestCase.java index 07e7f638d3d..d0633fdfddd 100644 --- a/testsuite/domain/src/test/java/org/jboss/as/test/integration/domain/management/cli/BasicOpsTestCase.java +++ b/testsuite/domain/src/test/java/org/jboss/as/test/integration/domain/management/cli/BasicOpsTestCase.java @@ -16,6 +16,7 @@ import org.junit.Test; import java.util.List; + /** * * @author Dominik Pospisil @@ -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"); @@ -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; } diff --git a/testsuite/domain/src/test/java/org/jboss/as/test/integration/domain/suites/ManagementReadXmlTestCase.java b/testsuite/domain/src/test/java/org/jboss/as/test/integration/domain/suites/ManagementReadXmlTestCase.java index 62d4980a3e0..07b2add41bd 100644 --- a/testsuite/domain/src/test/java/org/jboss/as/test/integration/domain/suites/ManagementReadXmlTestCase.java +++ b/testsuite/domain/src/test/java/org/jboss/as/test/integration/domain/suites/ManagementReadXmlTestCase.java @@ -45,6 +45,7 @@ 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; @@ -56,6 +57,7 @@ * @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; @@ -69,6 +71,7 @@ private static void prepareExpectedServerConfiguration(String server, boolean pr 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()"); From 76f2a910685f23bd30e58c24a1743dc0d34a8d14 Mon Sep 17 00:00:00 2001 From: Emmanuel Hugonnet Date: Wed, 28 Feb 2024 11:09:04 +0100 Subject: [PATCH 3/3] [WFCORE-6679]: Trying to fix the maven repo issue Signed-off-by: Emmanuel Hugonnet --- testsuite/domain/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testsuite/domain/pom.xml b/testsuite/domain/pom.xml index e896a54b200..09f7eba5851 100644 --- a/testsuite/domain/pom.xml +++ b/testsuite/domain/pom.xml @@ -188,7 +188,7 @@ false - ${jvm.args.ip.client} ${jvm.args.timeouts} ${surefire.system.args} -Djava.util.logging.manager=org.jboss.logmanager.LogManager + ${jvm.args.ip.client} ${jvm.args.timeouts} ${surefire.system.args} -Dmaven.repo.local=${settings.localRepository} -Djava.util.logging.manager=org.jboss.logmanager.LogManager -ea