Add support for empty password in bitnami/postgresql
See gh-43771 Signed-off-by: He Zean <realhezean@gmail.com>
This commit is contained in:
parent
21161bc42e
commit
2f178188d1
|
|
@ -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 {
|
||||
|
||||
|
|
@ -60,6 +61,16 @@ class PostgresJdbcDockerComposeConnectionDetailsFactoryIntegrationTests {
|
|||
checkDatabaseAccess(connectionDetails);
|
||||
}
|
||||
|
||||
@DockerComposeTest(composeFile = "postgres-bitnami-empty-password-compose.yaml",
|
||||
image = TestImage.BITNAMI_POSTGRESQL)
|
||||
void runWithBitnamiImageCreatesConnectionDetailsWithAllowEmptyPassword(JdbcConnectionDetails connectionDetails)
|
||||
throws ClassNotFoundException {
|
||||
assertThat(connectionDetails.getUsername()).isEqualTo("myuser");
|
||||
assertThat(connectionDetails.getPassword()).isEmpty();
|
||||
assertThat(connectionDetails.getJdbcUrl()).startsWith("jdbc:postgresql://").endsWith("/mydatabase");
|
||||
checkDatabaseAccess(connectionDetails);
|
||||
}
|
||||
|
||||
@DockerComposeTest(composeFile = "postgres-application-name-compose.yaml", image = TestImage.POSTGRESQL)
|
||||
void runCreatesConnectionDetailsApplicationName(JdbcConnectionDetails connectionDetails)
|
||||
throws ClassNotFoundException {
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
||||
|
|
@ -63,6 +64,17 @@ class PostgresR2dbcDockerComposeConnectionDetailsFactoryIntegrationTests {
|
|||
checkDatabaseAccess(connectionDetails);
|
||||
}
|
||||
|
||||
@DockerComposeTest(composeFile = "postgres-bitnami-empty-password-compose.yaml",
|
||||
image = TestImage.BITNAMI_POSTGRESQL)
|
||||
void runWithBitnamiImageCreatesConnectionDetailsWithAllowEmptyPassword(R2dbcConnectionDetails connectionDetails) {
|
||||
ConnectionFactoryOptions connectionFactoryOptions = connectionDetails.getConnectionFactoryOptions();
|
||||
assertThat(connectionFactoryOptions.getRequiredValue(ConnectionFactoryOptions.USER)).isEqualTo("myuser");
|
||||
assertThat(connectionFactoryOptions.getValue(ConnectionFactoryOptions.PASSWORD)).isNull();
|
||||
assertThat(connectionFactoryOptions.getRequiredValue(ConnectionFactoryOptions.DATABASE))
|
||||
.isEqualTo("mydatabase");
|
||||
checkDatabaseAccess(connectionDetails);
|
||||
}
|
||||
|
||||
@DockerComposeTest(composeFile = "postgres-application-name-compose.yaml", image = TestImage.POSTGRESQL)
|
||||
void runCreatesConnectionDetailsApplicationName(R2dbcConnectionDetails connectionDetails) {
|
||||
assertConnectionDetails(connectionDetails);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
services:
|
||||
database:
|
||||
image: '{imageName}'
|
||||
ports:
|
||||
- '5432'
|
||||
environment:
|
||||
- 'POSTGRESQL_USERNAME=myuser'
|
||||
- 'POSTGRESQL_DATABASE=mydatabase'
|
||||
- 'ALLOW_EMPTY_PASSWORD=yes'
|
||||
|
|
@ -17,6 +17,7 @@
|
|||
package org.springframework.boot.docker.compose.service.connection.postgres;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
|
@ -67,8 +68,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), "PostgreSQL password must be provided");
|
||||
return Objects.requireNonNullElse(password, "");
|
||||
}
|
||||
|
||||
private boolean isUsingTrustHostAuthMethod(Map<String, String> env) {
|
||||
|
|
|
|||
|
|
@ -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"));
|
||||
|
|
|
|||
Loading…
Reference in New Issue