Skip to content

Commit ecaf1fd

Browse files
authored
Cover the warn password policy usage of ValidatedPassword setting (#18203)
1 parent ad20032 commit ecaf1fd

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

logstash-core/spec/logstash/settings_spec.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,25 @@
299299
expect(LogStash::Setting::ValidatedPassword.new("test.validated.password", password, password_policies)).to_not be_nil
300300
end
301301
end
302+
303+
context "containing a mode WARN policy" do
304+
before :each do
305+
# Needs to mock the logger method at LogStash::Settings instead of LogStash::Setting::ValidatedPassword
306+
# else the LOGGABLE_PROXY hide the mock itself.
307+
allow(LogStash::Settings).to receive(:logger).at_least(:once).and_return(mock_logger)
308+
allow(mock_logger).to receive(:warn)
309+
end
310+
let(:mock_logger) { double("logger") }
311+
let(:password_policies) { super().merge({ "mode": "WARN" }) }
312+
313+
it "logs a warning on validation failure" do
314+
password = LogStash::Util::Password.new("Password!")
315+
expect {
316+
LogStash::Setting::ValidatedPassword.new("test.validated.password", password, password_policies)
317+
}.not_to raise_error
318+
expect(mock_logger).to have_received(:warn).with(a_string_including("Password must contain at least one digit between 0 and 9."))
319+
end
320+
end
302321
end
303322

304323
context "placeholders in nested logstash.yml" do

0 commit comments

Comments
 (0)