Skip to content

Commit

Permalink
[WFLY-15405] Don't hardcode the keystore location
Browse files Browse the repository at this point in the history
  • Loading branch information
kabir committed Nov 29, 2022
1 parent 8d1cf17 commit b8342b3
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 9 deletions.
Expand Up @@ -34,7 +34,7 @@
*/
public class ConfigureElytronSslContextSetupTask extends CLIServerSetupTask {
private final String CLIENT_KEYSTORE =
"src/test/resources/org/wildfly/test/integration/microprofile/reactive/messaging/kafka/client.truststore.p12";
"src/test/resources/org/wildfly/test/integration/microprofile/reactive/messaging/ssl/client.truststore.p12";
private final String KEYSTORE_PWD = "clientts";

@Override
Expand Down
Expand Up @@ -22,19 +22,23 @@

package org.wildfly.test.integration.microprofile.reactive;

import static java.util.concurrent.TimeUnit.SECONDS;
import static org.awaitility.Awaitility.await;

import java.net.URL;
import java.util.Set;

import org.apache.activemq.artemis.core.security.CheckType;
import org.apache.activemq.artemis.core.security.Role;
import org.apache.activemq.artemis.core.server.embedded.EmbeddedActiveMQ;
import org.apache.activemq.artemis.spi.core.security.ActiveMQSecurityManager;
import org.jboss.as.arquillian.api.ServerSetupTask;
import org.jboss.as.arquillian.container.ManagementClient;

import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;

import static java.util.concurrent.TimeUnit.SECONDS;
import static org.awaitility.Awaitility.await;

/**
* Setup task to start an embedded version of Artemis for AMQP support.
* I don't want to use the subsystem one because it means needing to run standalone-full.xml. Also, product does not
Expand Down Expand Up @@ -63,6 +67,7 @@ public void setup(ManagementClient managementClient, String containerId) throws
try {
server = new EmbeddedActiveMQ();
URL url = RunArtemisAmqpSetupTask.class.getResource(brokerXml);
url = getBrokerXmlAndAdjustIfNeeded();
String brokerXml = url.toExternalForm();
server.setConfigResourcePath(brokerXml);
server.setSecurityManager(new ActiveMQSecurityManager() {
Expand Down Expand Up @@ -95,6 +100,29 @@ public void tearDown(ManagementClient managementClient, String containerId) thro

}

private URL getBrokerXmlAndAdjustIfNeeded() throws Exception {
URL url = RunArtemisAmqpSetupTask.class.getResource(brokerXml);
List<String> lines = Files.readAllLines(Path.of(url.toURI()));
List<String> replacedLines = new LinkedList<>();

boolean replaced = false;
for (String line : lines) {
if (line.contains("$KEYSTORE$")) {
URL keystoreUrl = RunArtemisAmqpSetupTask.class.getResource("messaging/ssl/server.keystore.p12");
line = line.replace("$KEYSTORE$", Path.of(keystoreUrl.toURI()).toAbsolutePath().toString());
replaced = true;
}
replacedLines.add(line);
}

if (replaced) {
Path path = Files.createTempFile("broker", ".xml");
Files.write(path, replacedLines);
return path.toUri().toURL();
}
return url;
}

public static void main(String[] args) throws Exception{
RunArtemisAmqpSetupTask task = new RunArtemisAmqpSetupTask();
task.setup(null, null);
Expand Down
Expand Up @@ -35,7 +35,7 @@
*/
public class RunKafkaWithSslSetupTask extends RunKafkaSetupTask {
private final String SERVER_KEYSTORE =
"src/test/resources/org/wildfly/test/integration/microprofile/reactive/messaging/kafka/server.keystore.p12";
"src/test/resources/org/wildfly/test/integration/microprofile/reactive/messaging/ssl/server.keystore.p12";
private final String KEYSTORE_PWD = "serverks";

@Override
Expand Down
Expand Up @@ -37,7 +37,7 @@
<acceptor name="artemis">tcp://0.0.0.0:61616?tcpSendBufferSize=1048576;tcpReceiveBufferSize=1048576;protocols=CORE,AMQP;amqpCredits=1000;amqpLowCredits=300;amqpDuplicateDetection=true</acceptor>

<!-- AMQP Acceptor. Listens on default AMQP port for AMQP traffic - secured with SSL. -->
<acceptor name="amqp">tcp://0.0.0.0:5672?tcpSendBufferSize=1048576;tcpReceiveBufferSize=1048576;protocols=AMQP;amqpCredits=1000;amqpLowCredits=300;amqpDuplicateDetection=true;sslEnabled=true;keyStorePath=/Users/kabir/sourcecontrol/wildfly/wildfly/testsuite/integration/microprofile/src/test/resources/org/wildfly/test/integration/microprofile/reactive/messaging/kafka/server.keystore.p12;keyStorePassword=serverks</acceptor>
<acceptor name="amqp">tcp://0.0.0.0:5672?tcpSendBufferSize=1048576;tcpReceiveBufferSize=1048576;protocols=AMQP;amqpCredits=1000;amqpLowCredits=300;amqpDuplicateDetection=true;sslEnabled=true;keyStorePath=$KEYSTORE$;keyStorePassword=serverks</acceptor>
</acceptors>


Expand Down

0 comments on commit b8342b3

Please sign in to comment.