Skip to content

Commit 29fd8dd

Browse files
committed
Return non-null password publisher if no password is provided.
[#622] Signed-off-by: Mark Paluch <[email protected]>
1 parent afd0058 commit 29fd8dd

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

src/main/java/io/r2dbc/postgresql/PostgresqlConnectionConfiguration.java

+8-11
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ public final class PostgresqlConnectionConfiguration {
105105

106106
private final Map<String, String> options;
107107

108+
@Nullable
108109
private final Publisher<CharSequence> password;
109110

110111
private final boolean preferAttachedBuffers;
@@ -127,16 +128,12 @@ public final class PostgresqlConnectionConfiguration {
127128

128129
private final Publisher<String> username;
129130

130-
private PostgresqlConnectionConfiguration(String applicationName, boolean autodetectExtensions, @Nullable boolean compatibilityMode, @Nullable Duration connectTimeout, @Nullable String database,
131-
LogLevel errorResponseLogLevel,
132-
List<Extension> extensions, ToIntFunction<String> fetchSize, boolean forceBinary, @Nullable Duration lockWaitTimeout,
133-
@Nullable LoopResources loopResources,
134-
@Nullable MultiHostConfiguration multiHostConfiguration,
135-
LogLevel noticeLogLevel, @Nullable Map<String, String> options, Publisher<CharSequence> password, boolean preferAttachedBuffers,
136-
int preparedStatementCacheQueries, @Nullable String schema,
137-
@Nullable SingleHostConfiguration singleHostConfiguration, SSLConfig sslConfig, @Nullable Duration statementTimeout,
138-
boolean tcpKeepAlive, boolean tcpNoDelay, TimeZone timeZone,
139-
Publisher<String> username) {
131+
private PostgresqlConnectionConfiguration(String applicationName, boolean autodetectExtensions, @Nullable boolean compatibilityMode, @Nullable Duration connectTimeout, @Nullable String database
132+
, LogLevel errorResponseLogLevel, List<Extension> extensions, ToIntFunction<String> fetchSize, boolean forceBinary, @Nullable Duration lockWaitTimeout,
133+
@Nullable LoopResources loopResources, @Nullable MultiHostConfiguration multiHostConfiguration, LogLevel noticeLogLevel,
134+
@Nullable Map<String, String> options, @Nullable Publisher<CharSequence> password, boolean preferAttachedBuffers, int preparedStatementCacheQueries,
135+
@Nullable String schema, @Nullable SingleHostConfiguration singleHostConfiguration, SSLConfig sslConfig, @Nullable Duration statementTimeout,
136+
boolean tcpKeepAlive, boolean tcpNoDelay, TimeZone timeZone, Publisher<String> username) {
140137
this.applicationName = Assert.requireNonNull(applicationName, "applicationName must not be null");
141138
this.autodetectExtensions = autodetectExtensions;
142139
this.compatibilityMode = compatibilityMode;
@@ -264,7 +261,7 @@ Map<String, String> getOptions() {
264261
}
265262

266263
Publisher<CharSequence> getPassword() {
267-
return this.password;
264+
return this.password == null ? Mono.empty() : this.password;
268265
}
269266

270267
boolean isPreferAttachedBuffers() {

src/test/java/io/r2dbc/postgresql/PostgresqlConnectionConfigurationUnitTests.java

+10
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,16 @@ void constructorNoUsername() {
176176
.withMessage("username must not be null");
177177
}
178178

179+
@Test
180+
void constructorNoPassword() {
181+
PostgresqlConnectionConfiguration configuration = PostgresqlConnectionConfiguration.builder()
182+
.host("test-host")
183+
.username("foo")
184+
.build();
185+
186+
assertThat(configuration.getPassword()).isNotNull();
187+
}
188+
179189
@Test
180190
void constructorInvalidOptions() {
181191
assertThatIllegalArgumentException().isThrownBy(() -> PostgresqlConnectionConfiguration.builder()

0 commit comments

Comments
 (0)