|
|
|
@ -1,5 +1,5 @@
|
|
|
|
|
/*
|
|
|
|
|
* Copyright 2012-2017 the original author or authors.
|
|
|
|
|
* Copyright 2012-2018 the original author or authors.
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
@ -18,8 +18,10 @@ package org.springframework.boot.autoconfigure.amqp;
|
|
|
|
|
|
|
|
|
|
import javax.net.SocketFactory;
|
|
|
|
|
import javax.net.ssl.SSLSocketFactory;
|
|
|
|
|
import javax.net.ssl.TrustManager;
|
|
|
|
|
|
|
|
|
|
import com.rabbitmq.client.Address;
|
|
|
|
|
import com.rabbitmq.client.NullTrustManager;
|
|
|
|
|
import org.aopalliance.aop.Advice;
|
|
|
|
|
import org.junit.After;
|
|
|
|
|
import org.junit.Rule;
|
|
|
|
@ -53,6 +55,7 @@ import org.springframework.retry.backoff.ExponentialBackOffPolicy;
|
|
|
|
|
import org.springframework.retry.interceptor.MethodInvocationRecoverer;
|
|
|
|
|
import org.springframework.retry.policy.SimpleRetryPolicy;
|
|
|
|
|
import org.springframework.retry.support.RetryTemplate;
|
|
|
|
|
import org.springframework.test.util.ReflectionTestUtils;
|
|
|
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
|
import static org.mockito.Mockito.mock;
|
|
|
|
@ -411,6 +414,8 @@ public class RabbitAutoConfigurationTests {
|
|
|
|
|
com.rabbitmq.client.ConnectionFactory rabbitConnectionFactory = getTargetConnectionFactory();
|
|
|
|
|
assertThat(rabbitConnectionFactory.getSocketFactory())
|
|
|
|
|
.as("SocketFactory must use SSL").isInstanceOf(SSLSocketFactory.class);
|
|
|
|
|
TrustManager trustManager = getTrustManager(rabbitConnectionFactory);
|
|
|
|
|
assertThat(trustManager).isNotInstanceOf(NullTrustManager.class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@ -422,7 +427,38 @@ public class RabbitAutoConfigurationTests {
|
|
|
|
|
"spring.rabbitmq.ssl.keyStore=foo",
|
|
|
|
|
"spring.rabbitmq.ssl.keyStorePassword=secret",
|
|
|
|
|
"spring.rabbitmq.ssl.trustStore=bar",
|
|
|
|
|
"spring.rabbitmq.ssl.trustStorePassword=secret");
|
|
|
|
|
"spring.rabbitmq.ssl.trustStorePassword=secret",
|
|
|
|
|
"spring.rabbitmq.ssl.validateServerCertificate=false");
|
|
|
|
|
getTargetConnectionFactory();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void enableSslWithValidateServerCertificateFalse() throws Exception {
|
|
|
|
|
load(TestConfiguration.class, "spring.rabbitmq.ssl.enabled:true",
|
|
|
|
|
"spring.rabbitmq.ssl.validateServerCertificate=false");
|
|
|
|
|
com.rabbitmq.client.ConnectionFactory rabbitConnectionFactory = getTargetConnectionFactory();
|
|
|
|
|
TrustManager trustManager = getTrustManager(rabbitConnectionFactory);
|
|
|
|
|
assertThat(trustManager).isInstanceOf(NullTrustManager.class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void enableSslWithValidateServerCertificateDefault() throws Exception {
|
|
|
|
|
load(TestConfiguration.class, "spring.rabbitmq.ssl.enabled:true");
|
|
|
|
|
com.rabbitmq.client.ConnectionFactory rabbitConnectionFactory = getTargetConnectionFactory();
|
|
|
|
|
TrustManager trustManager = getTrustManager(rabbitConnectionFactory);
|
|
|
|
|
assertThat(trustManager).isNotInstanceOf(NullTrustManager.class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private TrustManager getTrustManager(
|
|
|
|
|
com.rabbitmq.client.ConnectionFactory rabbitConnectionFactory) {
|
|
|
|
|
Object sslContext = ReflectionTestUtils.getField(rabbitConnectionFactory,
|
|
|
|
|
"sslContext");
|
|
|
|
|
Object spi = ReflectionTestUtils.getField(sslContext, "contextSpi");
|
|
|
|
|
Object trustManager = ReflectionTestUtils.getField(spi, "trustManager");
|
|
|
|
|
while (trustManager.getClass().getName().endsWith("Wrapper")) {
|
|
|
|
|
trustManager = ReflectionTestUtils.getField(trustManager, "tm");
|
|
|
|
|
}
|
|
|
|
|
return (TrustManager) trustManager;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private com.rabbitmq.client.ConnectionFactory getTargetConnectionFactory() {
|
|
|
|
|