Skip to content

Commit 08439f8

Browse files
fix logstash-keystore to accept spaces in values when added via stdin (#17039) (#17040)
This commit preserves spaces in values, ensuring that multi-word strings are stored as intended. Prior to this change, `logstash-keystore` incorrectly handled values containing spaces, causing only the first word to be stored. (cherry picked from commit 5573b5a) Co-authored-by: kaisecheng <[email protected]>
1 parent d37150e commit 08439f8

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

logstash-core/src/main/java/org/logstash/secret/cli/Terminal.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public char[] readSecret() {
8181
if (useConsole) {
8282
return System.console().readPassword();
8383
} else {
84-
return scanner.next().toCharArray();
84+
return scanner.nextLine().toCharArray();
8585
}
8686
}
8787

qa/integration/specs/secret_store_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,20 @@
8787
expect(logstash.stderr_and_stdout).to match(/\\"\$\{tag1\}\\"/)
8888
end
8989

90+
it "add value that contains a space" do
91+
# add two key value pairs to keystore
92+
# hello => hello world
93+
# bye => bye
94+
key = "hello"
95+
value = "hello world"
96+
@logstash.run_cmd(["bash", "-c", "echo -e '#{value}\\nbye' | LOGSTASH_KEYSTORE_PASS=#{logstash_keystore_passowrd} #{@logstash.logstash_home}/bin/logstash-keystore --path.settings #{settings_dir} add #{key} bye"])
97+
98+
test_env["LOGSTASH_KEYSTORE_PASS"] = logstash_keystore_passowrd
99+
logstash = @logstash.run_cmd(["bin/logstash", "-e", "input{ generator{ count => 1 tags => ['${#{key}}', '${bye}'] }}", "--path.settings", settings_dir], true, test_env)
100+
expect(logstash.stderr_and_stdout).to match(/#{value}/)
101+
expect(logstash.stderr_and_stdout).to match(/bye/)
102+
end
103+
90104
context "won't start" do
91105
it "with the wrong password when variables are in settings" do
92106
test_env["LOGSTASH_KEYSTORE_PASS"] = "WRONG_PASSWRD"

0 commit comments

Comments
 (0)