From d0be3760b2f686c98f2888af2b8d0ce873a86baa Mon Sep 17 00:00:00 2001 From: Emmanuel Hugonnet Date: Mon, 12 Feb 2024 17:31:02 +0100 Subject: [PATCH] [(nobranch,rebasingWFCORE-6679)]: [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