Skip to content

Commit 6c476a2

Browse files
committed
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
2 parents 21161bc + b601282 commit 6c476a2

File tree

4 files changed

+12
-3
lines changed

4 files changed

+12
-3
lines changed

spring-boot-project/spring-boot-docker-compose/src/dockerTest/java/org/springframework/boot/docker/compose/service/connection/postgres/PostgresJdbcDockerComposeConnectionDetailsFactoryIntegrationTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
* @author Andy Wilkinson
3636
* @author Phillip Webb
3737
* @author Scott Frederick
38+
* @author He Zean
3839
*/
3940
class PostgresJdbcDockerComposeConnectionDetailsFactoryIntegrationTests {
4041

spring-boot-project/spring-boot-docker-compose/src/dockerTest/java/org/springframework/boot/docker/compose/service/connection/postgres/PostgresR2dbcDockerComposeConnectionDetailsFactoryIntegrationTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
* @author Andy Wilkinson
3838
* @author Phillip Webb
3939
* @author Scott Frederick
40+
* @author He Zean
4041
*/
4142
class PostgresR2dbcDockerComposeConnectionDetailsFactoryIntegrationTests {
4243

spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/postgres/PostgresEnvironment.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,9 @@ private String extractPassword(Map<String, String> env) {
6767
return null;
6868
}
6969
String password = env.getOrDefault("POSTGRES_PASSWORD", env.get("POSTGRESQL_PASSWORD"));
70-
Assert.state(StringUtils.hasLength(password), "PostgreSQL password must be provided");
71-
return password;
70+
boolean allowEmpty = env.containsKey("ALLOW_EMPTY_PASSWORD");
71+
Assert.state(allowEmpty || StringUtils.hasLength(password), "No PostgreSQL password found");
72+
return (password != null) ? password : "";
7273
}
7374

7475
private boolean isUsingTrustHostAuthMethod(Map<String, String> env) {

spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/postgres/PostgresEnvironmentTests.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class PostgresEnvironmentTests {
3939
@Test
4040
void createWhenNoPostgresPasswordThrowsException() {
4141
assertThatIllegalStateException().isThrownBy(() -> new PostgresEnvironment(Collections.emptyMap()))
42-
.withMessage("PostgreSQL password must be provided");
42+
.withMessage("No PostgreSQL password found");
4343
}
4444

4545
@Test
@@ -93,6 +93,12 @@ void getPasswordWhenHasTrustHostAuthMethod() {
9393
assertThat(environment.getPassword()).isNull();
9494
}
9595

96+
@Test
97+
void getPasswordWhenHasNoPasswordAndAllowEmptyPassword() {
98+
PostgresEnvironment environment = new PostgresEnvironment(Map.of("ALLOW_EMPTY_PASSWORD", "yes"));
99+
assertThat(environment.getPassword()).isEmpty();
100+
}
101+
96102
@Test
97103
void getDatabaseWhenNoPostgresDbOrPostgresUser() {
98104
PostgresEnvironment environment = new PostgresEnvironment(Map.of("POSTGRES_PASSWORD", "secret"));

0 commit comments

Comments
 (0)