@ -23,6 +23,7 @@ import com.mongodb.ConnectionString;
@@ -23,6 +23,7 @@ import com.mongodb.ConnectionString;
import com.mongodb.MongoClientSettings ;
import com.mongodb.ReadPreference ;
import com.mongodb.connection.AsynchronousSocketChannelStreamFactoryFactory ;
import com.mongodb.connection.SslSettings ;
import com.mongodb.connection.StreamFactory ;
import com.mongodb.connection.StreamFactoryFactory ;
import com.mongodb.connection.netty.NettyStreamFactoryFactory ;
@ -32,6 +33,7 @@ import io.netty.channel.EventLoopGroup;
@@ -32,6 +33,7 @@ import io.netty.channel.EventLoopGroup;
import org.junit.jupiter.api.Test ;
import org.springframework.boot.autoconfigure.AutoConfigurations ;
import org.springframework.boot.autoconfigure.ssl.SslAutoConfiguration ;
import org.springframework.boot.test.context.runner.ApplicationContextRunner ;
import org.springframework.context.ApplicationContext ;
import org.springframework.context.annotation.Bean ;
@ -52,7 +54,7 @@ import static org.mockito.Mockito.mock;
@@ -52,7 +54,7 @@ import static org.mockito.Mockito.mock;
class MongoReactiveAutoConfigurationTests {
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner ( )
. withConfiguration ( AutoConfigurations . of ( MongoReactiveAutoConfiguration . class ) ) ;
. withConfiguration ( AutoConfigurations . of ( MongoReactiveAutoConfiguration . class , SslAutoConfiguration . class ) ) ;
@Test
void clientExists ( ) {
@ -86,6 +88,39 @@ class MongoReactiveAutoConfigurationTests {
@@ -86,6 +88,39 @@ class MongoReactiveAutoConfigurationTests {
} ) ;
}
@Test
void configuresSslWhenEnabled ( ) {
this . contextRunner . withPropertyValues ( "spring.data.mongodb.ssl.enabled=true" ) . run ( ( context ) - > {
SslSettings sslSettings = getSettings ( context ) . getSslSettings ( ) ;
assertThat ( sslSettings . isEnabled ( ) ) . isTrue ( ) ;
assertThat ( sslSettings . getContext ( ) ) . isNull ( ) ;
} ) ;
}
@Test
void configuresSslWithBundle ( ) {
this . contextRunner
. withPropertyValues ( "spring.data.mongodb.ssl.bundle=test-bundle" ,
"spring.ssl.bundle.jks.test-bundle.keystore.location=classpath:test.jks" ,
"spring.ssl.bundle.jks.test-bundle.keystore.password=secret" ,
"spring.ssl.bundle.jks.test-bundle.key.password=password" )
. run ( ( context ) - > {
SslSettings sslSettings = getSettings ( context ) . getSslSettings ( ) ;
assertThat ( sslSettings . isEnabled ( ) ) . isTrue ( ) ;
assertThat ( sslSettings . getContext ( ) ) . isNotNull ( ) ;
} ) ;
}
@Test
void configuresWithoutSslWhenDisabledWithBundle ( ) {
this . contextRunner
. withPropertyValues ( "spring.data.mongodb.ssl.enabled=false" , "spring.data.mongodb.ssl.bundle=test-bundle" )
. run ( ( context ) - > {
SslSettings sslSettings = getSettings ( context ) . getSslSettings ( ) ;
assertThat ( sslSettings . isEnabled ( ) ) . isFalse ( ) ;
} ) ;
}
@Test
void nettyStreamFactoryFactoryIsConfiguredAutomatically ( ) {
AtomicReference < EventLoopGroup > eventLoopGroupReference = new AtomicReference < > ( ) ;