Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix: Test command does not load credentials from defaults #330

Merged
5 commits merged into from
Jan 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ tab_width = 4
ij_continuation_indent_size = 8
ij_formatter_off_tag = @formatter:off
ij_formatter_on_tag = @formatter:on
ij_formatter_tags_enabled = false
ij_formatter_tags_enabled = true
ij_smart_tabs = false
ij_visual_guides = none
ij_wrap_on_typing = false
Expand Down
2 changes: 2 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ val systemTest by tasks.registering(Test::class) {
languageVersion.set(JavaLanguageVersion.of(11))
})
dependsOn(tasks.shadowJar)
systemProperties["junit.jupiter.testinstance.lifecycle.default"] = "per_class"
systemProperties["cliExec"] = javaLauncher.get().executablePath.asFile.absolutePath + " -jar " +
tasks.shadowJar.map { it.outputs.files.singleFile }.get()
systemProperties["java"] = javaLauncher.get().executablePath.asFile.absolutePath
Expand All @@ -316,6 +317,7 @@ val systemTestNative by tasks.registering(Test::class) {
languageVersion.set(JavaLanguageVersion.of(11))
})
dependsOn(tasks.nativeCompile)
systemProperties["junit.jupiter.testinstance.lifecycle.default"] = "per_class"
systemProperties["cliExec"] =
tasks.nativeCompile.map { it.outputs.files.singleFile }.get().resolve(project.name).absolutePath
systemProperties["java"] = javaLauncher.get().executablePath.asFile.absolutePath
Expand Down
40 changes: 25 additions & 15 deletions src/main/java/com/hivemq/cli/commands/cli/TestBrokerCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ public TestBrokerCommand(final @NotNull DefaultCLIProperties defaultCLIPropertie
port = defaultCLIProperties.getPort();
}

authenticationOptions.setDefaultOptions();

try {
sslConfig = sslOptions.buildSslConfig();
} catch (final Exception e) {
Expand All @@ -134,21 +136,27 @@ public TestBrokerCommand(final @NotNull DefaultCLIProperties defaultCLIPropertie
return 1;
}

int mqtt3ExitCode = 0;
int mqtt5ExitCode = 0;
if (version != null) {
if (version == MqttVersion.MQTT_3_1_1) {
testMqtt3Features();
mqtt3ExitCode = testMqtt3Features();
} else if (version == MqttVersion.MQTT_5_0) {
testMqtt5Features();
mqtt5ExitCode = testMqtt5Features();
}
} else {
testMqtt3Features();
testMqtt5Features();
mqtt3ExitCode = testMqtt3Features();
mqtt5ExitCode = testMqtt5Features();
}

return 0;
if (mqtt3ExitCode != 0 || mqtt5ExitCode != 0) {
return 1;
} else {
return 0;
}
}

public void testMqtt5Features() {
public int testMqtt5Features() {
final Mqtt5FeatureTester mqtt5Tester = new Mqtt5FeatureTester(Objects.requireNonNull(host),
Objects.requireNonNull(port),
authenticationOptions.getUser(),
Expand All @@ -166,16 +174,16 @@ public void testMqtt5Features() {
connAck = mqtt5Tester.testConnect();
} catch (final Exception e) {
Logger.error(e, "Could not connect MQTT 5 client");
System.out.println("Could not connect MQTT 5 client - " + Throwables.getRootCause(e).getMessage());
return;
System.err.println("Could not connect MQTT 5 client - " + Throwables.getRootCause(e).getMessage());
return 1;
}

if (connAck == null) {
System.out.println("NO");
return;
return 1;
} else if (connAck.getReasonCode() != Mqtt5ConnAckReasonCode.SUCCESS) {
System.out.println(connAck.getReasonCode());
return;
return 1;
} else {
System.out.println("OK");
}
Expand Down Expand Up @@ -297,9 +305,10 @@ public void testMqtt5Features() {
}

Logger.info("Finished testing MQTT 5");
return 0;
}

public void testMqtt3Features() {
public int testMqtt3Features() {
final Mqtt3FeatureTester mqtt3Tester = new Mqtt3FeatureTester(Objects.requireNonNull(host),
Objects.requireNonNull(port),
authenticationOptions.getUser(),
Expand All @@ -317,15 +326,15 @@ public void testMqtt3Features() {
connAck = mqtt3Tester.testConnect();
} catch (final Exception e) {
Logger.error(e, "Could not connect MQTT 3 client");
System.out.println("Could not connect MQTT 3 client - " + Throwables.getRootCause(e).getMessage());
return;
System.err.println("Could not connect MQTT 3 client - " + Throwables.getRootCause(e).getMessage());
return 1;
}
if (connAck == null) {
System.out.println("NO");
return;
return 1;
} else if (connAck.getReturnCode() != Mqtt3ConnAckReturnCode.SUCCESS) {
System.out.println(connAck.getReturnCode());
return;
return 1;
} else {
System.out.println("OK");
}
Expand Down Expand Up @@ -405,6 +414,7 @@ public void testMqtt3Features() {
}

Logger.info("Finished testing MQTT 3");
return 0;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@
class PublishConnectST {

@RegisterExtension
private static final @NotNull HiveMQ HIVEMQ = HiveMQ.builder().build();
@SuppressWarnings("JUnitMalformedDeclaration")
private final @NotNull HiveMQ HIVEMQ = HiveMQ.builder().build();

@ParameterizedTest
@Timeout(value = 3, unit = TimeUnit.MINUTES)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
class PublishConnectTlsST {

@RegisterExtension
private static final @NotNull HiveMQ HIVEMQ = HiveMQ.builder().withTlsEnabled(true).build();
@SuppressWarnings("JUnitMalformedDeclaration")
private final @NotNull HiveMQ HIVEMQ = HiveMQ.builder().withTlsEnabled(true).build();

@RegisterExtension
private final @NotNull MqttCliAsync mqttCli = new MqttCliAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
class PublishConnectWebsocketsST {

@RegisterExtension
private static final @NotNull HiveMQ HIVEMQ = HiveMQ.builder().withWebsocketEnabled(true).build();
@SuppressWarnings("JUnitMalformedDeclaration")
private final @NotNull HiveMQ HIVEMQ = HiveMQ.builder().withWebsocketEnabled(true).build();

@ParameterizedTest
@Timeout(value = 3, unit = TimeUnit.MINUTES)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@
class PublishST {

@RegisterExtension
private static final @NotNull HiveMQ HIVEMQ = HiveMQ.builder().build();
@SuppressWarnings("JUnitMalformedDeclaration")
private final @NotNull HiveMQ HIVEMQ = HiveMQ.builder().build();

@ParameterizedTest
@Timeout(value = 3, unit = TimeUnit.MINUTES)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
class SubscribeConnectST {

@RegisterExtension
private static final @NotNull HiveMQ HIVEMQ = HiveMQ.builder().build();
@SuppressWarnings("JUnitMalformedDeclaration")
private final @NotNull HiveMQ HIVEMQ = HiveMQ.builder().build();

@RegisterExtension
private final @NotNull MqttCliAsync mqttCli = new MqttCliAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
class SubscribeConnectTlsST {

@RegisterExtension
private static final @NotNull HiveMQ HIVE_MQ = HiveMQ.builder().withTlsEnabled(true).build();
@SuppressWarnings("JUnitMalformedDeclaration")
private final @NotNull HiveMQ HIVEMQ = HiveMQ.builder().withTlsEnabled(true).build();

@RegisterExtension
private final @NotNull MqttCliAsync mqttCli = new MqttCliAsync();
Expand All @@ -56,9 +57,9 @@ void test_mutualTls(final char mqttVersion) throws Exception {
final List<String> subscribeCommand = List.of(
"sub",
"-h",
HIVE_MQ.getHost(),
HIVEMQ.getHost(),
"-p",
String.valueOf(HIVE_MQ.getMqttTlsPort()),
String.valueOf(HIVEMQ.getMqttTlsPort()),
"-V",
String.valueOf(mqttVersion),
"-i",
Expand All @@ -80,11 +81,11 @@ void test_mutualTls(final char mqttVersion) throws Exception {
executionResult.awaitStdOut("received SUBACK");

assertConnectPacket(
HIVE_MQ.getConnectPackets().get(0),
HIVEMQ.getConnectPackets().get(0),
connectAssertion -> connectAssertion.setMqttVersion(MqttVersionConverter.toExtensionSdkVersion(
mqttVersion)));

assertSubscribePacket(HIVE_MQ.getSubscribePackets().get(0), subscribeAssertion -> {
assertSubscribePacket(HIVEMQ.getSubscribePackets().get(0), subscribeAssertion -> {
final List<Subscription> expectedSubscriptions =
List.of(new SubscriptionImpl("topic", Qos.EXACTLY_ONCE, RetainHandling.SEND, false, false));
subscribeAssertion.setSubscriptions(expectedSubscriptions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
public class SubscribeConnectWebsocketsST {

@RegisterExtension
private static final @NotNull HiveMQ HIVE_MQ = HiveMQ.builder().withWebsocketEnabled(true).build();
@SuppressWarnings("JUnitMalformedDeclaration")
private final @NotNull HiveMQ HIVEMQ = HiveMQ.builder().withWebsocketEnabled(true).build();

@RegisterExtension
private final @NotNull MqttCliAsync mqttCli = new MqttCliAsync();
Expand All @@ -51,9 +52,9 @@ void test_websockets(final char mqttVersion) throws Exception {
final List<String> subscribeCommand = List.of(
"sub",
"-h",
HIVE_MQ.getHost(),
HIVEMQ.getHost(),
"-p",
String.valueOf(HIVE_MQ.getWebsocketsPort()),
String.valueOf(HIVEMQ.getWebsocketsPort()),
"-V",
String.valueOf(mqttVersion),
"-i",
Expand All @@ -62,19 +63,19 @@ void test_websockets(final char mqttVersion) throws Exception {
"topic",
"-ws",
"-ws:path",
HIVE_MQ.getWebsocketsPath(),
HIVEMQ.getWebsocketsPath(),
"-d");

final ExecutionResultAsync executionResult = mqttCli.executeAsync(subscribeCommand);
executionResult.awaitStdOut("received CONNACK");
executionResult.awaitStdOut("received SUBACK");

assertConnectPacket(
HIVE_MQ.getConnectPackets().get(0),
HIVEMQ.getConnectPackets().get(0),
connectAssertion -> connectAssertion.setMqttVersion(MqttVersionConverter.toExtensionSdkVersion(
mqttVersion)));

assertSubscribePacket(HIVE_MQ.getSubscribePackets().get(0), subscribeAssertion -> {
assertSubscribePacket(HIVEMQ.getSubscribePackets().get(0), subscribeAssertion -> {
final List<Subscription> expectedSubscriptions =
List.of(new SubscriptionImpl("topic", Qos.EXACTLY_ONCE, RetainHandling.SEND, false, false));
subscribeAssertion.setSubscriptions(expectedSubscriptions);
Expand Down
Loading