From 7b00a2b9b35d71d5d72bb04f31d16e7e24b9813f Mon Sep 17 00:00:00 2001 From: govi20 Date: Sat, 23 Oct 2021 13:30:01 +0530 Subject: [PATCH] Consider disabled SSL flag in `ConnectionFactoryOptions` [resolves #453][#460] --- .../PostgresqlConnectionFactoryProvider.java | 7 ++++++- ...resqlConnectionFactoryProviderUnitTests.java | 17 ++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/r2dbc/postgresql/PostgresqlConnectionFactoryProvider.java b/src/main/java/io/r2dbc/postgresql/PostgresqlConnectionFactoryProvider.java index 8f0dba82..44f0e7c7 100644 --- a/src/main/java/io/r2dbc/postgresql/PostgresqlConnectionFactoryProvider.java +++ b/src/main/java/io/r2dbc/postgresql/PostgresqlConnectionFactoryProvider.java @@ -287,7 +287,12 @@ private static PostgresqlConnectionConfiguration.Builder fromConnectionFactoryOp private static void setupSsl(PostgresqlConnectionConfiguration.Builder builder, OptionMapper mapper) { - mapper.from(SSL).to(builder::enableSsl); + mapper.from(SSL).map(OptionMapper::toBoolean).to(enableSsl -> { + if(enableSsl) { + builder.enableSsl(); + } + }); + mapper.from(SSL_MODE).map(it -> { if (it instanceof String) { diff --git a/src/test/java/io/r2dbc/postgresql/PostgresqlConnectionFactoryProviderUnitTests.java b/src/test/java/io/r2dbc/postgresql/PostgresqlConnectionFactoryProviderUnitTests.java index a5e0ec03..0e35becd 100644 --- a/src/test/java/io/r2dbc/postgresql/PostgresqlConnectionFactoryProviderUnitTests.java +++ b/src/test/java/io/r2dbc/postgresql/PostgresqlConnectionFactoryProviderUnitTests.java @@ -149,7 +149,22 @@ void supportsWithoutUser() { } @Test - void supportsSsl() { + void disableSsl() { + PostgresqlConnectionFactory factory = this.provider.create(builder() + .option(DRIVER, POSTGRESQL_DRIVER) + .option(HOST, "test-host") + .option(PASSWORD, "test-password") + .option(USER, "test-user") + .option(SSL, false) + .build()); + + SSLConfig sslConfig = factory.getConfiguration().getSslConfig(); + + assertThat(sslConfig.getSslMode()).isEqualTo(SSLMode.DISABLE); + } + + @Test + void enableSsl() { PostgresqlConnectionFactory factory = this.provider.create(builder() .option(DRIVER, POSTGRESQL_DRIVER) .option(HOST, "test-host")