Plugin#params should not return obsolete params

Fixes #4011
This commit is contained in:
Pier-Hugues Pellerin 2015-10-13 11:46:48 -04:00 committed by Jordan Sissel
parent 62c42be8e2
commit dbb034ec45
2 changed files with 38 additions and 0 deletions

View file

@ -110,6 +110,16 @@ module LogStash::Config::Mixin
I18n.t("logstash.agent.configuration.invalid_plugin_settings")
end
# We remove any config options marked as obsolete,
# no code should be associated to them and their values should not bleed
# to the plugin context.
#
# This need to be done after fetching the options from the parents classed
params.reject! do |name, value|
opts = self.class.get_config[name]
opts.include?(:obsolete)
end
# set instance variables like '@foo' for each config value given.
params.each do |key, value|
next if key[0, 1] == "@"

View file

@ -115,6 +115,14 @@ describe LogStash::Config::Mixin do
end
end
context "when using an obsolete settings from the parent class" do
it "should cause a configuration error" do
expect {
plugin_class.new("debug" => true)
}.to raise_error(LogStash::ConfigurationError)
end
end
context "when not using an obsolete setting" do
it "should not cause a configuration error" do
expect {
@ -123,4 +131,24 @@ describe LogStash::Config::Mixin do
end
end
end
context "#params" do
let(:plugin_class) do
Class.new(LogStash::Filters::Base) do
config_name "fake"
config :password, :validate => :password
config :bad, :validate => :string, :default => "my default", :obsolete => "not here"
end
end
subject { plugin_class.new({ "password" => "secret" }) }
it "should not return the obsolete options" do
expect(subject.params).not_to include("bad")
end
it "should include any other params" do
expect(subject.params).to include("password")
end
end
end