Skip to content

Commit

Permalink
dont mutate SETTINGS object in keystore specs
Browse files Browse the repository at this point in the history
Fixes #11270
  • Loading branch information
jsvd committed Oct 25, 2019
1 parent a1930f2 commit e853377
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions logstash-core/spec/logstash/util/secretstore_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,32 @@
describe SecretStoreExt do

subject {SecretStoreExt}
let(:settings) { LogStash::SETTINGS.clone }

describe "with missing keystore" do
before :each do
LogStash::SETTINGS.set("keystore.file", File.join(File.dirname(__FILE__), "nothing_here"))
settings.set("keystore.file", File.join(File.dirname(__FILE__), "nothing_here"))
end

it "should be not exist" do
expect(subject.exists(LogStash::SETTINGS.get_setting("keystore.file").value, LogStash::SETTINGS.get_setting("keystore.classname").value)).to be_falsey
expect(subject.getIfExists(LogStash::SETTINGS.get_setting("keystore.file").value, LogStash::SETTINGS.get_setting("keystore.classname").value)).to be_nil
expect(subject.exists(settings.get_setting("keystore.file").value, settings.get_setting("keystore.classname").value)).to be_falsey
expect(subject.getIfExists(settings.get_setting("keystore.file").value, settings.get_setting("keystore.classname").value)).to be_nil
end
end

describe "with implicit password keystore" do
before :each do
LogStash::SETTINGS.set("keystore.file", File.join(File.dirname(__FILE__), "../../../src/test/resources/logstash.keystore.with.default.pass"))
settings.set("keystore.file", File.join(File.dirname(__FILE__), "../../../src/test/resources/logstash.keystore.with.default.pass"))
end

it "should be readable" do
expect(subject.getIfExists(LogStash::SETTINGS.get_setting("keystore.file").value, LogStash::SETTINGS.get_setting("keystore.classname").value).list).to include(subject.get_store_id("keystore.seed"))
expect(subject.getIfExists(settings.get_setting("keystore.file").value, settings.get_setting("keystore.classname").value).list).to include(subject.get_store_id("keystore.seed"))
end
end

describe "with explicit password keystore" do
before :each do
LogStash::SETTINGS.set("keystore.file", File.join(File.dirname(__FILE__), "../../../src/test/resources/logstash.keystore.with.defined.pass"))
settings.set("keystore.file", File.join(File.dirname(__FILE__), "../../../src/test/resources/logstash.keystore.with.defined.pass"))
end

describe "and correct password" do
Expand All @@ -42,7 +43,7 @@
end

it "should be readable" do
expect(subject.getIfExists(LogStash::SETTINGS.get_setting("keystore.file").value, LogStash::SETTINGS.get_setting("keystore.classname").value).list).to include(subject.get_store_id("keystore.seed"))
expect(subject.getIfExists(settings.get_setting("keystore.file").value, settings.get_setting("keystore.classname").value).list).to include(subject.get_store_id("keystore.seed"))
end
end

Expand All @@ -56,13 +57,13 @@
end

it "should be not readable" do
expect {subject.getIfExists(LogStash::SETTINGS.get_setting("keystore.file").value, LogStash::SETTINGS.get_setting("keystore.classname").value)}.to raise_error.with_message(/Can not access Logstash keystore/)
expect {subject.getIfExists(settings.get_setting("keystore.file").value, settings.get_setting("keystore.classname").value)}.to raise_error.with_message(/Can not access Logstash keystore/)
end
end

describe "and missing password" do
it "should be not readable" do
expect {subject.getIfExists(LogStash::SETTINGS.get_setting("keystore.file").value, LogStash::SETTINGS.get_setting("keystore.classname").value)}.to raise_error.with_message(/Could not determine keystore password/)
expect {subject.getIfExists(settings.get_setting("keystore.file").value, settings.get_setting("keystore.classname").value)}.to raise_error.with_message(/Could not determine keystore password/)
end
end
end
Expand Down

0 comments on commit e853377

Please sign in to comment.