From 860c61d165e4f966234ca369b3fd68e315d1690b Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Thu, 28 Dec 2023 13:36:27 +0100 Subject: [PATCH] Return non-null password publisher if no password is provided. [#622] Signed-off-by: Mark Paluch --- .../PostgresqlConnectionConfiguration.java | 19 ++++++++----------- ...resqlConnectionConfigurationUnitTests.java | 10 ++++++++++ 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/main/java/io/r2dbc/postgresql/PostgresqlConnectionConfiguration.java b/src/main/java/io/r2dbc/postgresql/PostgresqlConnectionConfiguration.java index aa323787..6e5720aa 100644 --- a/src/main/java/io/r2dbc/postgresql/PostgresqlConnectionConfiguration.java +++ b/src/main/java/io/r2dbc/postgresql/PostgresqlConnectionConfiguration.java @@ -105,6 +105,7 @@ public final class PostgresqlConnectionConfiguration { private final Map options; + @Nullable private final Publisher password; private final boolean preferAttachedBuffers; @@ -127,16 +128,12 @@ public final class PostgresqlConnectionConfiguration { private final Publisher username; - private PostgresqlConnectionConfiguration(String applicationName, boolean autodetectExtensions, @Nullable boolean compatibilityMode, @Nullable Duration connectTimeout, @Nullable String database, - LogLevel errorResponseLogLevel, - List extensions, ToIntFunction fetchSize, boolean forceBinary, @Nullable Duration lockWaitTimeout, - @Nullable LoopResources loopResources, - @Nullable MultiHostConfiguration multiHostConfiguration, - LogLevel noticeLogLevel, @Nullable Map options, Publisher password, boolean preferAttachedBuffers, - int preparedStatementCacheQueries, @Nullable String schema, - @Nullable SingleHostConfiguration singleHostConfiguration, SSLConfig sslConfig, @Nullable Duration statementTimeout, - boolean tcpKeepAlive, boolean tcpNoDelay, TimeZone timeZone, - Publisher username) { + private PostgresqlConnectionConfiguration(String applicationName, boolean autodetectExtensions, @Nullable boolean compatibilityMode, @Nullable Duration connectTimeout, @Nullable String database + , LogLevel errorResponseLogLevel, List extensions, ToIntFunction fetchSize, boolean forceBinary, @Nullable Duration lockWaitTimeout, + @Nullable LoopResources loopResources, @Nullable MultiHostConfiguration multiHostConfiguration, LogLevel noticeLogLevel, + @Nullable Map options, @Nullable Publisher password, boolean preferAttachedBuffers, int preparedStatementCacheQueries, + @Nullable String schema, @Nullable SingleHostConfiguration singleHostConfiguration, SSLConfig sslConfig, @Nullable Duration statementTimeout, + boolean tcpKeepAlive, boolean tcpNoDelay, TimeZone timeZone, Publisher username) { this.applicationName = Assert.requireNonNull(applicationName, "applicationName must not be null"); this.autodetectExtensions = autodetectExtensions; this.compatibilityMode = compatibilityMode; @@ -264,7 +261,7 @@ Map getOptions() { } Publisher getPassword() { - return this.password; + return this.password == null ? Mono.empty() : this.password; } boolean isPreferAttachedBuffers() { diff --git a/src/test/java/io/r2dbc/postgresql/PostgresqlConnectionConfigurationUnitTests.java b/src/test/java/io/r2dbc/postgresql/PostgresqlConnectionConfigurationUnitTests.java index f6c346f3..9e5aa265 100644 --- a/src/test/java/io/r2dbc/postgresql/PostgresqlConnectionConfigurationUnitTests.java +++ b/src/test/java/io/r2dbc/postgresql/PostgresqlConnectionConfigurationUnitTests.java @@ -176,6 +176,16 @@ void constructorNoUsername() { .withMessage("username must not be null"); } + @Test + void constructorNoPassword() { + PostgresqlConnectionConfiguration configuration = PostgresqlConnectionConfiguration.builder() + .host("test-host") + .username("foo") + .build(); + + assertThat(configuration.getPassword()).isNotNull(); + } + @Test void constructorInvalidOptions() { assertThatIllegalArgumentException().isThrownBy(() -> PostgresqlConnectionConfiguration.builder()