Skip to content

Commit

Permalink
More updates to Standalone clients/auditlog tests
Browse files Browse the repository at this point in the history
  • Loading branch information
michalxo committed Oct 4, 2023
1 parent 7788ca4 commit ce4cf4c
Show file tree
Hide file tree
Showing 16 changed files with 345 additions and 275 deletions.
7 changes: 5 additions & 2 deletions common/src/main/java/io/brokerqe/claire/ArtemisConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ public interface ArtemisConstants {
int DEFAULT_STOMP_PORT = 61613;
int DEFAULT_WEB_CONSOLE_PORT = 8161;


// Security
String SASL_ANON = "ANONYMOUS";
String SASL_PLAIN = "PLAIN";
String SASL_EXTERNAL = "EXTERNAL";

// Logging
String DEFAULT_LOG_LEVEL = "INFO";
Expand Down Expand Up @@ -168,7 +171,7 @@ public interface ArtemisConstants {
String LOG_AUDIT_AUTHENTICATION_FAIL_PRODUCE_PATTERN = ".* AMQ601264: User %s\\(%s\\)@.* gets security check failure, reason = AMQ229032: User: %s does not have permission='SEND' on address %s.*";
String LOG_AUDIT_AUTHENTICATION_FAIL_CONSUME_PATTERN = ".* AMQ601264: User %s\\(%s\\)@.* gets security check failure, reason = AMQ229213: User: %s does not have permission='CONSUME' for queue %s on address %s.*";

String LOG_AUDIT_CREATE_ADDRESS_PATTERN = ".* AMQ601262: User %s\\(%s\\)@.* is creating address on target resource: .* with parameters: \\[%s::%s.*";
String LOG_AUDIT_CREATE_ADDRESS_PATTERN_CORE = ".* AMQ601262: User %s\\(%s\\)@.* is creating address on target resource: .* with parameters: \\[%s::%s.*";
String LOG_AUDIT_CREATE_ADDRESS_PATTERN_AMQP = ".* AMQ601262: User %s\\(%s\\)@.* is creating address on target resource: .* with parameters: .*name=%s.*";
String LOG_AUDIT_CREATE_QUEUE_PATTERN = ".* AMQ601065: User %s\\(%s\\)@.* is creating a queue on target resource: .* with parameters: \\[.* name=%s, address=%s.*";
String LOG_AUDIT_SENT_MESSAGE_PATTERN = ".* AMQ601500: User %s\\(%s\\)@.* sent a message .* address=%s::%s.*";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public int sendMessages() {
String cmdOutput;
String[] command = constructClientCommand(MessagingClient.SENDER, senderOptions);
cmdOutput = (String) deployableClient.getExecutor().executeCommand(Constants.DURATION_3_MINUTES, command);
LOGGER.debug("[{}] [TX] \n{}", deployableClient.getContainerName(), cmdOutput);
LOGGER.debug("[{}][TX] \n{}", deployableClient.getContainerName(), cmdOutput);
this.sentMessages = parseMessages(cmdOutput);
return sentMessages.size();
}
Expand Down Expand Up @@ -168,7 +168,7 @@ public int receiveMessages() {
String cmdOutput;
String[] command = constructClientCommand(MessagingClient.RECEIVER, receiverOptions);
cmdOutput = (String) deployableClient.getExecutor().executeCommand(Constants.DURATION_3_MINUTES, command);
LOGGER.debug("[{}] [RX] \n{}", deployableClient.getContainerName(), cmdOutput);
LOGGER.debug("[{}][RX] \n{}", deployableClient.getContainerName(), cmdOutput);
this.receivedMessages = parseMessages(cmdOutput);
return receivedMessages.size();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public int sendMessages() {
String cmdOutput;
String[] command = constructClientCommand(MessagingClient.SENDER, senderOptions);
cmdOutput = (String) deployableClient.getExecutor().executeCommand(Constants.DURATION_3_MINUTES, command);
LOGGER.debug("[{}] [TX] \n{}", deployableClient.getContainerName(), cmdOutput);
LOGGER.debug("[{}][TX] \n{}", deployableClient.getContainerName(), cmdOutput);
this.sentMessages = parseMessages(cmdOutput);
return sentMessages.size();
}
Expand Down Expand Up @@ -164,7 +164,7 @@ public int receiveMessages() {
String cmdOutput;
String[] command = constructClientCommand(MessagingClient.RECEIVER, receiverOptions);
cmdOutput = (String) deployableClient.getExecutor().executeCommand(Constants.DURATION_3_MINUTES, command);
LOGGER.debug("[{}] [RX] \n{}", deployableClient.getContainerName(), cmdOutput);
LOGGER.debug("[{}][RX] \n{}", deployableClient.getContainerName(), cmdOutput);
this.receivedMessages = parseMessages(cmdOutput);
return receivedMessages.size();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public int sendMessages() {
String cmdOutput;
String[] command = constructClientCommand(MessagingClient.SENDER, senderOptions);
cmdOutput = (String) deployableClient.getExecutor().executeCommand(Constants.DURATION_3_MINUTES, command);
LOGGER.debug("[{}] [TX] \n{}", deployableClient.getContainerName(), cmdOutput);
LOGGER.debug("[{}][TX] \n{}", deployableClient.getContainerName(), cmdOutput);
this.sentMessages = parseMessages(cmdOutput);
return sentMessages.size();
}
Expand Down Expand Up @@ -166,7 +166,7 @@ public int receiveMessages() {
String cmdOutput;
String[] command = constructClientCommand(MessagingClient.RECEIVER, receiverOptions);
cmdOutput = (String) deployableClient.getExecutor().executeCommand(Constants.DURATION_3_MINUTES, command);
LOGGER.debug("[{}] [RX] \n{}", deployableClient.getContainerName(), cmdOutput);
LOGGER.debug("[{}][RX] \n{}", deployableClient.getContainerName(), cmdOutput);
this.receivedMessages = parseMessages(cmdOutput);
return receivedMessages.size();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public int sendMessages() {
String cmdOutput;
String[] command = constructClientCommand(MessagingClient.SENDER, senderOptions);
cmdOutput = (String) deployableClient.getExecutor().executeCommand(Constants.DURATION_3_MINUTES, command);
LOGGER.debug("[{}] [TX] \n{}", deployableClient.getContainerName(), cmdOutput);
LOGGER.debug("[{}][TX] \n{}", deployableClient.getContainerName(), cmdOutput);
this.sentMessages = parseMessages(cmdOutput);
return sentMessages.size();
}
Expand Down Expand Up @@ -164,7 +164,7 @@ public int receiveMessages() {
String cmdOutput;
String[] command = constructClientCommand(MessagingClient.RECEIVER, receiverOptions);
cmdOutput = (String) deployableClient.getExecutor().executeCommand(Constants.DURATION_3_MINUTES, command);
LOGGER.debug("[{}] [RX] \n{}", deployableClient.getContainerName(), cmdOutput);
LOGGER.debug("[{}][RX] \n{}", deployableClient.getContainerName(), cmdOutput);
this.receivedMessages = parseMessages(cmdOutput);
return receivedMessages.size();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io.brokerqe.claire.clients.DeployableClient;
import io.brokerqe.claire.clients.MessagingClient;
import io.brokerqe.claire.clients.MessagingClientException;
import io.brokerqe.claire.exception.ClaireRuntimeException;
import io.brokerqe.claire.executor.Executor;
import org.json.JSONException;
import org.json.JSONObject;
Expand All @@ -22,9 +23,6 @@
public abstract class BaseJMSClient extends SystemtestClient {

private static final Logger LOGGER = LoggerFactory.getLogger(BaseJMSClient.class);
public static final String SASL_ANON = "ANONYMOUS";
public static final String SASL_PLAIN = "PLAIN";
public static final String SASL_EXTERNAL = "EXTERNAL";
private String keystorePassword;
private String trustStore;
private String trustStorePassword;
Expand Down Expand Up @@ -93,10 +91,14 @@ public BaseJMSClient(DeployableClient deployableClient, String brokerUri, Map<St
public int sendMessages() {
String cmdOutput;
String[] command = constructClientCommand(MessagingClient.SENDER);
cmdOutput = (String) deployableClient.getExecutor().executeCommand(Constants.DURATION_3_MINUTES, command);
LOGGER.debug("[{}][TX] \n{}", deployableClient.getContainerName(), cmdOutput);
this.sentMessages = parseMessages(cmdOutput);
return sentMessages.size();
try {
cmdOutput = (String) deployableClient.getExecutor().executeCommand(Constants.DURATION_3_MINUTES, command);
LOGGER.debug("[{}][TX] \n{}", deployableClient.getContainerName(), cmdOutput);
this.sentMessages = parseMessages(cmdOutput);
return sentMessages.size();
} catch (ClaireRuntimeException e) {
throw new MessagingClientException(e.getMessage(), e);
}
}

@Override
Expand All @@ -108,10 +110,14 @@ public int receiveMessages() {
// executed client on foreground
String cmdOutput;
String[] command = constructClientCommand(MessagingClient.RECEIVER);
cmdOutput = (String) deployableClient.getExecutor().executeCommand(Constants.DURATION_3_MINUTES, command);
LOGGER.debug("[{}] [RX] \n{}", deployableClient.getContainerName(), cmdOutput);
this.receivedMessages = parseMessages(cmdOutput);
return receivedMessages.size();
try {
cmdOutput = (String) deployableClient.getExecutor().executeCommand(Constants.DURATION_3_MINUTES, command);
LOGGER.debug("[{}][RX] \n{}", deployableClient.getContainerName(), cmdOutput);
this.receivedMessages = parseMessages(cmdOutput);
return receivedMessages.size();
} catch (ClaireRuntimeException e) {
throw new MessagingClientException(e.getMessage(), e);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import io.brokerqe.claire.ArtemisVersion;
import io.brokerqe.claire.Constants;
import io.brokerqe.claire.ResourceManager;
import io.brokerqe.claire.clients.container.AmqpQpidClient;
import io.brokerqe.claire.clients.MessagingClient;
import io.brokerqe.claire.clients.MessagingClientException;
import io.brokerqe.claire.junit.TestValidSince;
Expand Down Expand Up @@ -58,7 +57,7 @@ public abstract class TLSAuthorizationTests extends AbstractSystemTests {
String expiredAfterSecretName = "expired-after-tls-secret";
String expiredSecretName = "expired-tls-secret";
int msgsExpected = 2;
String saslMechanism = AmqpQpidClient.SASL_EXTERNAL;
String saslMechanism = ArtemisConstants.SASL_EXTERNAL;
ActiveMQArtemis broker;
ActiveMQArtemisSecurity artemisSecurity;
Acceptors amqpAcceptors;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ public String executeCommand(long maxExecMs, String... command) {
Container.ExecResult execResult = container.execInContainer(command);
int cmdReturnCode = execResult.getExitCode();
if (cmdReturnCode != 0) {
String errMsg = String.format("Error on executing command '%s' in container %s, return code: %s ",
String.join(" ", command), container.getContainerName(), cmdReturnCode);
LOGGER.error("[ExecutorStandalone] {} {} ", errMsg, execResult.getStderr());
throw new ClaireRuntimeException(errMsg);
String errMsg = String.format("Error on executing command '%s' in container %s, return code: %s\n%s",
String.join(" ", command), container.getContainerName(), cmdReturnCode, execResult.getStderr());
LOGGER.error("[ExecutorStandalone] {}", errMsg);
throw new ClaireRuntimeException(execResult.getStderr(), new Throwable(errMsg));
}
return execResult.getStdout();
} catch (IOException | InterruptedException e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* Copyright Broker QE authors.
* License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html).
*/
package io.brokerqe.claire.logging.audit;

import io.brokerqe.claire.ArtemisConstants;
import io.brokerqe.claire.clients.MessagingClient;
import io.brokerqe.claire.clients.MessagingClientException;
import io.brokerqe.claire.clients.bundled.BundledClientOptions;
import io.brokerqe.claire.clients.bundled.BundledCoreMessagingClient;
import org.hamcrest.MatcherAssert;
import org.junit.jupiter.api.Test;

import java.util.List;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.jupiter.api.Assertions.assertThrows;

public class AuditCoreLogTests extends AuditLogTests {
@Test
void checkBundledCoreAuditLogsTest() {
int msgsExpected = 5;
LOGGER.info("Test Bundled Core Messaging. Starting test for {} user.", ArtemisConstants.ADMIN_NAME);
BundledClientOptions options = new BundledClientOptions()
.withDeployableClient(artemisDeployableClient)
.withDestinationAddress(address)
.withDestinationPort(DEFAULT_ALL_PORT)
.withMessageCount(msgsExpected)
.withPassword(ArtemisConstants.ADMIN_NAME)
.withUsername(ArtemisConstants.ADMIN_PASS)
.withDestinationQueue(queue)
.withDestinationUrl(artemis.getName());
MessagingClient bundledClient = new BundledCoreMessagingClient(options);
int sent = bundledClient.sendMessages();
int received = bundledClient.receiveMessages();
MatcherAssert.assertThat(sent, equalTo(msgsExpected));
MatcherAssert.assertThat(received, equalTo(msgsExpected));
checkAuditLogs(List.of(adminFormattedAuth, adminFormattedAddressCore, adminFormattedQueue, adminFormattedSent, adminFormattedRecv));

LOGGER.info("Starting test for senders/receivers user: {}", ArtemisConstants.CHARLIE_NAME);
options = new BundledClientOptions()
.withDeployableClient(artemisDeployableClient)
.withDestinationAddress(address)
.withDestinationPort(DEFAULT_ALL_PORT)
.withMessageCount(msgsExpected)
.withPassword(ArtemisConstants.CHARLIE_NAME)
.withUsername(ArtemisConstants.CHARLIE_PASS)
.withDestinationQueue(queue)
.withDestinationUrl(artemis.getName());
bundledClient = new BundledCoreMessagingClient(options);
sent = bundledClient.sendMessages();
received = bundledClient.receiveMessages();
MatcherAssert.assertThat(sent, equalTo(msgsExpected));
MatcherAssert.assertThat(received, equalTo(msgsExpected));
checkAuditLogs(List.of(charlieFormattedAuth, charlieFormattedSent, charlieFormattedRecv));

LOGGER.info("Starting test for senders user: {}", ArtemisConstants.ALICE_NAME);
options = new BundledClientOptions()
.withDeployableClient(artemisDeployableClient)
.withDestinationAddress(address)
.withDestinationPort(DEFAULT_ALL_PORT)
.withMessageCount(msgsExpected)
.withPassword(ArtemisConstants.ALICE_NAME)
.withUsername(ArtemisConstants.ALICE_PASS)
.withDestinationQueue(queue)
.withDestinationUrl(artemis.getName());
BundledCoreMessagingClient bundledClientAlice = new BundledCoreMessagingClient(options);
int sentAlice = bundledClientAlice.sendMessages();
assertThrows(MessagingClientException.class, bundledClientAlice::receiveMessages);
checkAuditLogs(List.of(aliceFormattedAuth, aliceFormattedSent, aliceFormattedRecv));

LOGGER.info("Starting test for receivers user: {}", ArtemisConstants.BOB_NAME);
options = new BundledClientOptions()
.withDeployableClient(artemisDeployableClient)
.withDestinationAddress(address)
.withDestinationPort(DEFAULT_ALL_PORT)
.withMessageCount(msgsExpected)
.withPassword(ArtemisConstants.BOB_NAME)
.withUsername(ArtemisConstants.BOB_PASS)
.withDestinationQueue(queue)
.withDestinationUrl(artemis.getName());
BundledCoreMessagingClient bundledClientBob = new BundledCoreMessagingClient(options);

assertThrows(MessagingClientException.class, bundledClientBob::sendMessages);
int receivedBob = bundledClientBob.receiveMessages();
MatcherAssert.assertThat(sentAlice, equalTo(msgsExpected));
MatcherAssert.assertThat(receivedBob, equalTo(msgsExpected));
checkAuditLogs(List.of(bobFormattedAuth, bobFormattedSent, bobFormattedRecv));

deleteQueue(artemisDeployableClient, queue);
deleteAddress(artemisDeployableClient, address);
}
}
Loading

0 comments on commit ce4cf4c

Please sign in to comment.