Skip to content

Commit 7ed7821

Browse files
authored
Merge pull request #1128 from smallrye/backport-#1124-to-3.x
[3.x] Backport Fix MQTT Client when the keystore/truststore password is missing
2 parents 123d38c + 112f237 commit 7ed7821

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

smallrye-reactive-messaging-mqtt/src/main/java/io/smallrye/reactive/messaging/mqtt/MqttHelpers.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,9 @@ private static KeyCertOptions getKeyCertOptions(MqttConnectorCommonConfiguration
7171
.setPath(keyStoreLocation)
7272
.setPassword(keyStorePassword);
7373
} else {
74-
new IllegalArgumentException("The attribute `ssl.keystore.password` on connector 'smallrye-mqtt' (channel: "
75-
+ config.getChannel() + ") must be set for `ssl.keystore.type`" + sslKeystoreType);
74+
throw new IllegalArgumentException(
75+
"The attribute `ssl.keystore.password` on connector 'smallrye-mqtt' (channel: "
76+
+ config.getChannel() + ") must be set for `ssl.keystore.type`" + sslKeystoreType);
7677
}
7778
}
7879
return null;
@@ -108,8 +109,9 @@ private static TrustOptions getTrustOptions(MqttConnectorCommonConfiguration con
108109
.setPath(truststoreLocation)
109110
.setPassword(truststorePassword);
110111
} else {
111-
new IllegalArgumentException("The attribute `ssl.keystore.password` on connector 'smallrye-mqtt' (channel: "
112-
+ config.getChannel() + ") must be set for `ssl.keystore.type`" + truststoreType);
112+
throw new IllegalArgumentException(
113+
"The attribute `ssl.keystore.password` on connector 'smallrye-mqtt' (channel: "
114+
+ config.getChannel() + ") must be set for `ssl.keystore.type`" + truststoreType);
113115
}
114116
}
115117
return null;

smallrye-reactive-messaging-mqtt/src/test/java/io/smallrye/reactive/messaging/mqtt/MutualTlsMqttSourceTest.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import static org.assertj.core.api.Assertions.assertThat;
44
import static org.awaitility.Awaitility.await;
5+
import static org.junit.Assert.assertThrows;
56

67
import java.util.*;
78
import java.util.concurrent.TimeUnit;
@@ -75,4 +76,26 @@ void pause() {
7576
}
7677
}
7778

79+
@Test
80+
public void testMutualTLSMissingPassword() {
81+
assertThrows(IllegalArgumentException.class, () -> {
82+
String topic = UUID.randomUUID().toString();
83+
Map<String, Object> config = new HashMap<>();
84+
config.put("topic", topic);
85+
config.put("host", address);
86+
config.put("port", port);
87+
config.put("username", "user");
88+
config.put("password", "foo");
89+
config.put("channel-name", topic);
90+
config.put("ssl", true);
91+
config.put("ssl.keystore.type", "jks");
92+
config.put("ssl.keystore.location", "mosquitto-tls/client/client.ks");
93+
config.put("ssl.truststore.type", "jks");
94+
config.put("ssl.truststore.location", "mosquitto-tls/client/client.ts");
95+
96+
new MqttSource(vertx, new MqttConnectorIncomingConfiguration(new MapBasedConfig(config)));
97+
});
98+
99+
}
100+
78101
}

0 commit comments

Comments
 (0)