Skip to content

Commit

Permalink
Return non-null password publisher if no password is provided.
Browse files Browse the repository at this point in the history
[#622]

Signed-off-by: Mark Paluch <mpaluch@paluch.biz>
  • Loading branch information
mp911de committed Dec 28, 2023
1 parent afd0058 commit 29fd8dd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ public final class PostgresqlConnectionConfiguration {

private final Map<String, String> options;

@Nullable
private final Publisher<CharSequence> password;

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

private final Publisher<String> username;

private PostgresqlConnectionConfiguration(String applicationName, boolean autodetectExtensions, @Nullable boolean compatibilityMode, @Nullable Duration connectTimeout, @Nullable String database,
LogLevel errorResponseLogLevel,
List<Extension> extensions, ToIntFunction<String> fetchSize, boolean forceBinary, @Nullable Duration lockWaitTimeout,
@Nullable LoopResources loopResources,
@Nullable MultiHostConfiguration multiHostConfiguration,
LogLevel noticeLogLevel, @Nullable Map<String, String> options, Publisher<CharSequence> password, boolean preferAttachedBuffers,
int preparedStatementCacheQueries, @Nullable String schema,
@Nullable SingleHostConfiguration singleHostConfiguration, SSLConfig sslConfig, @Nullable Duration statementTimeout,
boolean tcpKeepAlive, boolean tcpNoDelay, TimeZone timeZone,
Publisher<String> username) {
private PostgresqlConnectionConfiguration(String applicationName, boolean autodetectExtensions, @Nullable boolean compatibilityMode, @Nullable Duration connectTimeout, @Nullable String database
, LogLevel errorResponseLogLevel, List<Extension> extensions, ToIntFunction<String> fetchSize, boolean forceBinary, @Nullable Duration lockWaitTimeout,
@Nullable LoopResources loopResources, @Nullable MultiHostConfiguration multiHostConfiguration, LogLevel noticeLogLevel,
@Nullable Map<String, String> options, @Nullable Publisher<CharSequence> password, boolean preferAttachedBuffers, int preparedStatementCacheQueries,
@Nullable String schema, @Nullable SingleHostConfiguration singleHostConfiguration, SSLConfig sslConfig, @Nullable Duration statementTimeout,
boolean tcpKeepAlive, boolean tcpNoDelay, TimeZone timeZone, Publisher<String> username) {
this.applicationName = Assert.requireNonNull(applicationName, "applicationName must not be null");
this.autodetectExtensions = autodetectExtensions;
this.compatibilityMode = compatibilityMode;
Expand Down Expand Up @@ -264,7 +261,7 @@ Map<String, String> getOptions() {
}

Publisher<CharSequence> getPassword() {
return this.password;
return this.password == null ? Mono.empty() : this.password;
}

boolean isPreferAttachedBuffers() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 29fd8dd

Please sign in to comment.