Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
* @author Andy Wilkinson
* @author Phillip Webb
* @author Scott Frederick
* @author Sidmar Theodoro
*/
class PostgresEnvironment {

Expand All @@ -44,11 +45,19 @@ class PostgresEnvironment {
}

private String extractPassword(Map<String, String> env) {
if (hasTrustAuthMethod(env)) {
return null;
}
String password = env.getOrDefault("POSTGRES_PASSWORD", env.get("POSTGRESQL_PASSWORD"));
Assert.state(StringUtils.hasLength(password), "PostgreSQL password must be provided");
return password;
}

private Boolean hasTrustAuthMethod(Map<String, String> env) {
String hostAuthMethod = env.get("POSTGRES_HOST_AUTH_METHOD");
return "trust".equals(hostAuthMethod);
}

String getUsername() {
return this.username;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ void getPasswordWhenHasPostgresqlPassword() {
assertThat(environment.getPassword()).isEqualTo("secret");
}

@Test
void getPasswordWhenHasTrustHostAuthMethod() {
PostgresEnvironment environment = new PostgresEnvironment(Map.of("POSTGRES_HOST_AUTH_METHOD", "trust"));
assertThat(environment.getPassword()).isNull();
}

@Test
void getDatabaseWhenNoPostgresDbOrPostgresUser() {
PostgresEnvironment environment = new PostgresEnvironment(Map.of("POSTGRES_PASSWORD", "secret"));
Expand Down