|
20 | 20 | import java.util.List;
|
21 | 21 | import java.util.concurrent.atomic.AtomicInteger;
|
22 | 22 |
|
23 |
| -import javax.net.ssl.SSLContext; |
24 | 23 | import javax.net.ssl.SSLSocketFactory;
|
25 |
| -import javax.net.ssl.TrustManager; |
26 | 24 |
|
27 | 25 | import com.rabbitmq.client.Address;
|
28 | 26 | import com.rabbitmq.client.Connection;
|
29 | 27 | import com.rabbitmq.client.JDKSaslConfig;
|
30 |
| -import com.rabbitmq.client.SslContextFactory; |
31 |
| -import com.rabbitmq.client.TrustEverythingTrustManager; |
32 | 28 | import com.rabbitmq.client.impl.CredentialsProvider;
|
33 | 29 | import com.rabbitmq.client.impl.CredentialsRefreshService;
|
34 | 30 | import com.rabbitmq.client.impl.DefaultCredentialsProvider;
|
35 | 31 | import org.aopalliance.aop.Advice;
|
36 | 32 | import org.junit.jupiter.api.Test;
|
| 33 | +import org.junit.jupiter.api.extension.ExtendWith; |
37 | 34 | import org.mockito.InOrder;
|
38 | 35 |
|
39 | 36 | import org.springframework.amqp.core.AcknowledgeMode;
|
|
59 | 56 | import org.springframework.boot.autoconfigure.AutoConfigurations;
|
60 | 57 | import org.springframework.boot.test.context.assertj.AssertableApplicationContext;
|
61 | 58 | import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
| 59 | +import org.springframework.boot.test.system.CapturedOutput; |
| 60 | +import org.springframework.boot.test.system.OutputCaptureExtension; |
62 | 61 | import org.springframework.context.annotation.Bean;
|
63 | 62 | import org.springframework.context.annotation.Configuration;
|
64 | 63 | import org.springframework.context.annotation.Primary;
|
|
92 | 91 | * @author HaiTao Zhang
|
93 | 92 | * @author Franjo Zilic
|
94 | 93 | */
|
| 94 | +@ExtendWith(OutputCaptureExtension.class) |
95 | 95 | class RabbitAutoConfigurationTests {
|
96 | 96 |
|
97 | 97 | private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
@@ -722,24 +722,24 @@ void enableSslWithKeystoreTypeAndTrustStoreTypeShouldWork() {
|
722 | 722 | }
|
723 | 723 |
|
724 | 724 | @Test
|
725 |
| - void enableSslWithValidateServerCertificateFalse() { |
| 725 | + void enableSslWithValidateServerCertificateFalse(CapturedOutput output) { |
726 | 726 | this.contextRunner.withUserConfiguration(TestConfiguration.class)
|
727 | 727 | .withPropertyValues("spring.rabbitmq.ssl.enabled:true",
|
728 | 728 | "spring.rabbitmq.ssl.validateServerCertificate=false")
|
729 | 729 | .run((context) -> {
|
730 | 730 | com.rabbitmq.client.ConnectionFactory rabbitConnectionFactory = getTargetConnectionFactory(context);
|
731 |
| - TrustManager trustManager = getTrustManager(rabbitConnectionFactory); |
732 |
| - assertThat(trustManager).isInstanceOf(TrustEverythingTrustManager.class); |
| 731 | + assertThat(rabbitConnectionFactory.isSSL()).isTrue(); |
| 732 | + assertThat(output).contains("TrustEverythingTrustManager", "SECURITY ALERT"); |
733 | 733 | });
|
734 | 734 | }
|
735 | 735 |
|
736 | 736 | @Test
|
737 |
| - void enableSslWithValidateServerCertificateDefault() { |
| 737 | + void enableSslWithValidateServerCertificateDefault(CapturedOutput output) { |
738 | 738 | this.contextRunner.withUserConfiguration(TestConfiguration.class)
|
739 | 739 | .withPropertyValues("spring.rabbitmq.ssl.enabled:true").run((context) -> {
|
740 | 740 | com.rabbitmq.client.ConnectionFactory rabbitConnectionFactory = getTargetConnectionFactory(context);
|
741 |
| - TrustManager trustManager = getTrustManager(rabbitConnectionFactory); |
742 |
| - assertThat(trustManager).isNotInstanceOf(TrustEverythingTrustManager.class); |
| 741 | + assertThat(rabbitConnectionFactory.isSSL()).isTrue(); |
| 742 | + assertThat(output).doesNotContain("TrustEverythingTrustManager", "SECURITY ALERT"); |
743 | 743 | });
|
744 | 744 | }
|
745 | 745 |
|
@@ -849,18 +849,6 @@ void whenMultipleConnectionFactoryCustomizersAreDefinedThenTheyAreCalledInOrder(
|
849 | 849 | });
|
850 | 850 | }
|
851 | 851 |
|
852 |
| - private TrustManager getTrustManager(com.rabbitmq.client.ConnectionFactory rabbitConnectionFactory) { |
853 |
| - SslContextFactory sslContextFactory = (SslContextFactory) ReflectionTestUtils.getField(rabbitConnectionFactory, |
854 |
| - "sslContextFactory"); |
855 |
| - SSLContext sslContext = sslContextFactory.create("connection"); |
856 |
| - Object spi = ReflectionTestUtils.getField(sslContext, "contextSpi"); |
857 |
| - Object trustManager = ReflectionTestUtils.getField(spi, "trustManager"); |
858 |
| - while (trustManager.getClass().getName().endsWith("Wrapper")) { |
859 |
| - trustManager = ReflectionTestUtils.getField(trustManager, "tm"); |
860 |
| - } |
861 |
| - return (TrustManager) trustManager; |
862 |
| - } |
863 |
| - |
864 | 852 | private com.rabbitmq.client.ConnectionFactory getTargetConnectionFactory(AssertableApplicationContext context) {
|
865 | 853 | CachingConnectionFactory connectionFactory = context.getBean(CachingConnectionFactory.class);
|
866 | 854 | return connectionFactory.getRabbitConnectionFactory();
|
|
0 commit comments