Browse Source

Make handling of ALLOW_EMPTY_PASSWORD consistent

See gh-43790

Signed-off-by: He Zean <realhezean@gmail.com>
pull/43863/head
He Zean 11 months ago committed by Andy Wilkinson
parent
commit
ab8d2ebc8a
  1. 4
      spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/clickhouse/ClickHouseEnvironment.java
  2. 9
      spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/clickhouse/ClickHouseEnvironmentTests.java

4
spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/clickhouse/ClickHouseEnvironment.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2012-2024 the original author or authors.
* Copyright 2012-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -41,7 +41,7 @@ class ClickHouseEnvironment { @@ -41,7 +41,7 @@ class ClickHouseEnvironment {
}
private String extractPassword(Map<String, String> env) {
boolean allowEmpty = Boolean.parseBoolean(env.getOrDefault("ALLOW_EMPTY_PASSWORD", Boolean.FALSE.toString()));
boolean allowEmpty = env.containsKey("ALLOW_EMPTY_PASSWORD");
String password = env.get("CLICKHOUSE_PASSWORD");
Assert.state(StringUtils.hasLength(password) || allowEmpty, "No ClickHouse password found");
return (password != null) ? password : "";

9
spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/clickhouse/ClickHouseEnvironmentTests.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2012-2024 the original author or authors.
* Copyright 2012-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -50,10 +50,9 @@ class ClickHouseEnvironmentTests { @@ -50,10 +50,9 @@ class ClickHouseEnvironmentTests {
}
@Test
void getPasswordWhenHasNoPasswordAndAllowEmptyPasswordIsFalse() {
assertThatIllegalStateException()
.isThrownBy(() -> new ClickHouseEnvironment(Map.of("ALLOW_EMPTY_PASSWORD", "false")))
.withMessage("No ClickHouse password found");
void getPasswordWhenHasNoPasswordAndAllowEmptyPasswordIsYes() {
ClickHouseEnvironment environment = new ClickHouseEnvironment(Map.of("ALLOW_EMPTY_PASSWORD", "yes"));
assertThat(environment.getPassword()).isEmpty();
}
@Test

Loading…
Cancel
Save