Added keystore type and truststore type to rabbit properties
See gh-10251
This commit is contained in:
committed by
Stephane Nicoll
parent
f04fa32c27
commit
b70ac99bcb
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.springframework.boot.autoconfigure.amqp;
|
||||
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
import javax.net.SocketFactory;
|
||||
import javax.net.ssl.SSLSocketFactory;
|
||||
|
||||
@@ -540,21 +542,80 @@ public class RabbitAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
// Make sure that we at least attempt to load the store
|
||||
public void enableSslWithExtraConfig() {
|
||||
this.contextRunner.withUserConfiguration(TestConfiguration.class)
|
||||
public void enableSslWithNonexistingKeystoreShouldFail() {
|
||||
this.contextRunner
|
||||
.withUserConfiguration(TestConfiguration.class)
|
||||
.withPropertyValues("spring.rabbitmq.ssl.enabled:true",
|
||||
"spring.rabbitmq.ssl.keyStore=foo",
|
||||
"spring.rabbitmq.ssl.keyStorePassword=secret",
|
||||
"spring.rabbitmq.ssl.keyStorePassword=secret")
|
||||
.run(context -> {
|
||||
assertThat(context).hasFailed();
|
||||
assertThat(context).getFailure().hasMessageContaining("foo");
|
||||
assertThat(context).getFailure().hasMessageContaining("does not exist");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
// Make sure that we at least attempt to load the store
|
||||
public void enableSslWithNonexistingTruststoreShouldFail() {
|
||||
this.contextRunner
|
||||
.withUserConfiguration(TestConfiguration.class)
|
||||
.withPropertyValues(
|
||||
"spring.rabbitmq.ssl.enabled:true",
|
||||
"spring.rabbitmq.ssl.trustStore=bar",
|
||||
"spring.rabbitmq.ssl.trustStorePassword=secret")
|
||||
.run((context) -> {
|
||||
assertThat(context).hasFailed();
|
||||
assertThat(context).getFailure().hasMessageContaining("foo");
|
||||
assertThat(context).getFailure()
|
||||
.hasMessageContaining("does not exist");
|
||||
assertThat(context).getFailure().hasMessageContaining("bar");
|
||||
assertThat(context).getFailure().hasMessageContaining("does not exist");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void enableSslWithInvalidKeystoreTypeShouldFail() throws Exception {
|
||||
this.contextRunner
|
||||
.withUserConfiguration(TestConfiguration.class)
|
||||
.withPropertyValues(
|
||||
"spring.rabbitmq.ssl.enabled:true",
|
||||
"spring.rabbitmq.ssl.keyStore=foo",
|
||||
"spring.rabbitmq.ssl.keyStoreType=fooType")
|
||||
.run(context -> {
|
||||
assertThat(context).hasFailed();
|
||||
assertThat(context).getFailure().hasMessageContaining("fooType");
|
||||
assertThat(context).getFailure().hasRootCauseInstanceOf(NoSuchAlgorithmException.class);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void enableSslWithInvalidTruststoreTypeShouldFail() throws Exception {
|
||||
this.contextRunner
|
||||
.withUserConfiguration(TestConfiguration.class)
|
||||
.withPropertyValues(
|
||||
"spring.rabbitmq.ssl.enabled:true",
|
||||
"spring.rabbitmq.ssl.trustStore=bar",
|
||||
"spring.rabbitmq.ssl.trustStoreType=barType")
|
||||
.run(context -> {
|
||||
assertThat(context).hasFailed();
|
||||
assertThat(context).getFailure().hasMessageContaining("barType");
|
||||
assertThat(context).getFailure().hasRootCauseInstanceOf(NoSuchAlgorithmException.class);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void enableSslWithKeystoreTypeAndTrustStoreTypeShouldWork() throws Exception {
|
||||
this.contextRunner
|
||||
.withUserConfiguration(TestConfiguration.class)
|
||||
.withPropertyValues(
|
||||
"spring.rabbitmq.ssl.enabled:true",
|
||||
"spring.rabbitmq.ssl.keyStore=/org/springframework/boot/autoconfigure/amqp/test.jks",
|
||||
"spring.rabbitmq.ssl.keyStoreType=jks",
|
||||
"spring.rabbitmq.ssl.keyStorePassword=secret",
|
||||
"spring.rabbitmq.ssl.trustStore=/org/springframework/boot/autoconfigure/amqp/test.jks",
|
||||
"spring.rabbitmq.ssl.trustStoreType=jks",
|
||||
"spring.rabbitmq.ssl.trustStorePassword=secret")
|
||||
.run(context -> assertThat(context).hasNotFailed());
|
||||
}
|
||||
|
||||
private com.rabbitmq.client.ConnectionFactory getTargetConnectionFactory(
|
||||
AssertableApplicationContext context) {
|
||||
CachingConnectionFactory connectionFactory = context
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user