Merge pull request #43771 from hezean

* gh-43771:
  Polish "Add support for empty password in bitnami/postgresql"
  Add support for empty password in bitnami/postgresql

Closes gh-43771
This commit is contained in:
Andy Wilkinson 2025-01-15 11:47:07 +00:00
commit 6c476a2b92
4 changed files with 12 additions and 3 deletions

View File

@ -35,6 +35,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Andy Wilkinson
* @author Phillip Webb
* @author Scott Frederick
* @author He Zean
*/
class PostgresJdbcDockerComposeConnectionDetailsFactoryIntegrationTests {

View File

@ -37,6 +37,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Andy Wilkinson
* @author Phillip Webb
* @author Scott Frederick
* @author He Zean
*/
class PostgresR2dbcDockerComposeConnectionDetailsFactoryIntegrationTests {

View File

@ -67,8 +67,9 @@ class PostgresEnvironment {
return null;
}
String password = env.getOrDefault("POSTGRES_PASSWORD", env.get("POSTGRESQL_PASSWORD"));
Assert.state(StringUtils.hasLength(password), "PostgreSQL password must be provided");
return password;
boolean allowEmpty = env.containsKey("ALLOW_EMPTY_PASSWORD");
Assert.state(allowEmpty || StringUtils.hasLength(password), "No PostgreSQL password found");
return (password != null) ? password : "";
}
private boolean isUsingTrustHostAuthMethod(Map<String, String> env) {

View File

@ -39,7 +39,7 @@ class PostgresEnvironmentTests {
@Test
void createWhenNoPostgresPasswordThrowsException() {
assertThatIllegalStateException().isThrownBy(() -> new PostgresEnvironment(Collections.emptyMap()))
.withMessage("PostgreSQL password must be provided");
.withMessage("No PostgreSQL password found");
}
@Test
@ -93,6 +93,12 @@ class PostgresEnvironmentTests {
assertThat(environment.getPassword()).isNull();
}
@Test
void getPasswordWhenHasNoPasswordAndAllowEmptyPassword() {
PostgresEnvironment environment = new PostgresEnvironment(Map.of("ALLOW_EMPTY_PASSWORD", "yes"));
assertThat(environment.getPassword()).isEmpty();
}
@Test
void getDatabaseWhenNoPostgresDbOrPostgresUser() {
PostgresEnvironment environment = new PostgresEnvironment(Map.of("POSTGRES_PASSWORD", "secret"));