Skip to content

Commit

Permalink
Merge pull request #43790 from hezean
Browse files Browse the repository at this point in the history
* gh-43790:
  Make handling of ALLOW_EMPTY_PASSWORD consistent

Closes gh-43790
  • Loading branch information
wilkinsona committed Jan 15, 2025
2 parents f2906a0 + ab8d2eb commit 54819bc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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 : "";
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -50,10 +50,9 @@ void getPasswordWhenHasNoPasswordAndAllowEmptyPassword() {
}

@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
Expand Down

0 comments on commit 54819bc

Please sign in to comment.