# encoding: utf-8 require_relative "../spec_helper" require "stud/temporary" require "logstash/inputs/beats" require "logstash/codecs/plain" require "logstash/codecs/json" require "logstash/codecs/multiline" require "logstash/event" describe LogStash::Inputs::Beats do let(:connection) { double("connection") } let(:certificate) { BeatsInputTest.certificate } let(:port) { BeatsInputTest.random_port } let(:queue) { Queue.new } let(:config) { { "port" => 0, "ssl_certificate" => certificate.ssl_cert, "ssl_key" => certificate.ssl_key, "type" => "example", "tags" => "beats"} } context "#register" do context "identity map" do subject(:plugin) { LogStash::Inputs::Beats.new(config) } before { plugin.register } context "when using the multiline codec" do let(:codec) { LogStash::Codecs::Multiline.new("pattern" => '^2015', "what" => "previous", "negate" => true) } let(:config) { super.merge({ "codec" => codec }) } it "wraps the codec with the identity_map" do expect(plugin.codec).to be_kind_of(LogStash::Codecs::IdentityMapCodec) end end context "when using non buffered codecs" do let(:config) { super.merge({ "codec" => "json" }) } it "doesnt wrap the codec with the identity map" do expect(plugin.codec).to be_kind_of(LogStash::Codecs::JSON) end end end it "raise no exception" do plugin = LogStash::Inputs::Beats.new(config) expect { plugin.register }.not_to raise_error end context "with ssl enabled" do context "without certificate configuration" do let(:config) {{ "port" => 0, "ssl" => true, "ssl_key" => certificate.ssl_key, "type" => "example", "tags" => "beats" }} it "should fail to register the plugin with ConfigurationError" do plugin = LogStash::Inputs::Beats.new(config) expect {plugin.register}.to raise_error(LogStash::ConfigurationError) end end context "without key configuration" do let(:config) { { "port" => 0, "ssl" => true, "ssl_certificate" => certificate.ssl_cert, "type" => "example", "tags" => "Beats"} } it "should fail to register the plugin with ConfigurationError" do plugin = LogStash::Inputs::Beats.new(config) expect {plugin.register}.to raise_error(LogStash::ConfigurationError) end end end context "with ssl disabled" do context "and certificate configuration" do let(:config) { { "port" => 0, "ssl" => false, "ssl_certificate" => certificate.ssl_cert, "type" => "example", "tags" => "Beats" } } it "should not fail" do plugin = LogStash::Inputs::Beats.new(config) expect {plugin.register}.not_to raise_error end end context "and certificate key configuration" do let(:config) {{ "port" => 0, "ssl" => false, "ssl_key" => certificate.ssl_key, "type" => "example", "tags" => "beats" }} it "should not fail" do plugin = LogStash::Inputs::Beats.new(config) expect {plugin.register}.not_to raise_error end end context "and no certificate or key configured" do let(:config) {{ "ssl" => false, "port" => 0, "type" => "example", "tags" => "beats" }} it "should work just fine" do plugin = LogStash::Inputs::Beats.new(config) expect {plugin.register}.not_to raise_error end end end end context "when interrupting the plugin" do it_behaves_like "an interruptible input plugin" end end