Skip to content

Commit

Permalink
[WFCORE-6679]: ManagementReadXmlTestCase inputs are too fragile.
Browse files Browse the repository at this point in the history
 * Generating the servers configuration through scripts to make them
   less fragile.

Jira: https://issues.redhat.com/browse/WFCORE-6679

Signed-off-by: Emmanuel Hugonnet <[email protected]>
  • Loading branch information
ehsavoie committed Jan 30, 2024
1 parent 3134974 commit 5380d85
Show file tree
Hide file tree
Showing 4 changed files with 158 additions and 418 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
* Copyright The WildFly Authors
* SPDX-License-Identifier: Apache-2.0
*/

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

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 @@ -42,11 +42,13 @@
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.domain.suites.DomainTestSuite;
import org.jboss.as.test.integration.management.util.CLIWrapper;
import org.jboss.dmr.ModelNode;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.wildfly.security.manager.WildFlySecurityManager;

/**
* Test of various read-config-as-xml against the domain controller.
Expand All @@ -59,8 +61,89 @@ 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(WildFlySecurityManager.getPropertyPrivileged("jboss.home", "toto")).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().toString());
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 {
prepareExpectedServerConfiguration("one", true, 0);
prepareExpectedServerConfiguration("three", false, 350);
testSupport = DomainTestSuite.createSupport(ManagementReadXmlTestCase.class.getSimpleName());
domainPrimaryLifecycleUtil = testSupport.getDomainPrimaryLifecycleUtil();
domainSecondaryLifecycleUtil = testSupport.getDomainSecondaryLifecycleUtil();
Expand Down Expand Up @@ -149,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));
Expand All @@ -161,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();
Expand Down
71 changes: 71 additions & 0 deletions testsuite/domain/src/test/resources/base-server-config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?xml version="1.0" encoding="UTF-8"?>

<server xmlns="urn:jboss:domain:20.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:jboss:domain:20.0 wildfly-config_20_0.xsd">
<extensions>
<extension module="org.jboss.as.jmx"/>
<extension module="org.jboss.as.logging"/>
<extension module="org.jboss.as.remoting"/>
<extension module="org.wildfly.extension.core-management"/>
<extension module="org.wildfly.extension.elytron"/>
<extension module="org.wildfly.extension.io"/>
<extension module="org.wildfly.extension.request-controller"/>
<extension module="org.wildfly.extension.security.manager"/>
</extensions>
<system-properties>
<property name="jboss.domain.test.property.one" value="ONE"/>
<property name="jboss.domain.test.property.two" value="${jboss.domain.test.property.one}"/>
</system-properties>
<paths>
<path name="domainTestPath" path="main-one" relative-to="jboss.server.temp.dir"/>
</paths>
<management>
<audit-log>
<formatters>
<json-formatter name="json-formatter"/>
</formatters>
<handlers>
<file-handler name="host-file" formatter="json-formatter" path="audit-log.log" relative-to="jboss.domain.data.dir"/>
<file-handler name="server-file" formatter="json-formatter" path="audit-log.log" relative-to="jboss.server.data.dir"/>
</handlers>
<logger log-boot="true" log-read-only="true" enabled="false">
<handlers>
<handler name="server-file"/>
</handlers>
</logger>
</audit-log>
<access-control provider="simple">
<role-mapping>
<role name="SuperUser">
<include>
<user name="$local"/>
</include>
</role>
</role-mapping>
</access-control>
</management>
<profile>
</profile>
<interfaces>
<interface name="management">
<inet-address value="${jboss.test.host.primary.address}"/>
</interface>
<interface name="public">
<inet-address value="${jboss.test.host.primary.address}"/>
</interface>
</interfaces>
<socket-binding-group name="standard-sockets" default-interface="public" port-offset="0">
<socket-binding name="ajp" port="8009"/>
<socket-binding name="http" port="8080"/>
<socket-binding name="https" port="8443"/>
<socket-binding name="jmx-connector-registry" interface="management" port="1090"/>
<socket-binding name="jmx-connector-server" interface="management" port="1091"/>
<socket-binding name="messaging" port="5445"/>
<socket-binding name="messaging-throughput" port="5455"/>
<socket-binding name="remoting" port="4447"/>
<socket-binding name="txn-recovery-environment" port="4712"/>
<socket-binding name="txn-status-manager" port="4713"/>
<outbound-socket-binding name="mail-smtp">
<remote-destination host="localhost" port="25"/>
</outbound-socket-binding>
</socket-binding-group>
</server>
Loading

0 comments on commit 5380d85

Please sign in to comment.