|
12 | 12 | let(:connection) { double("connection") }
|
13 | 13 | let(:certificate) { BeatsInputTest.certificate }
|
14 | 14 | let(:port) { BeatsInputTest.random_port }
|
| 15 | + let(:client_inactivity_timeout) { 400 } |
| 16 | + let(:threads) { 1 + rand(9) } |
15 | 17 | let(:queue) { Queue.new }
|
16 | 18 | let(:config) do
|
17 | 19 | {
|
18 |
| - "port" => 0, |
| 20 | + "port" => port, |
19 | 21 | "ssl_certificate" => certificate.ssl_cert,
|
20 | 22 | "ssl_key" => certificate.ssl_key,
|
| 23 | + "client_inactivity_timeout" => client_inactivity_timeout, |
| 24 | + "executor_threads" => threads, |
21 | 25 | "type" => "example",
|
22 | 26 | "tags" => "beats"
|
23 | 27 | }
|
24 | 28 | end
|
25 | 29 |
|
| 30 | + subject(:plugin) { LogStash::Inputs::Beats.new(config) } |
| 31 | + |
26 | 32 | context "#register" do
|
27 | 33 | context "host related configuration" do
|
28 |
| - let(:config) { super().merge("host" => host, "port" => port, "client_inactivity_timeout" => client_inactivity_timeout, "executor_threads" => threads) } |
| 34 | + let(:config) { super().merge("host" => host, "port" => port) } |
29 | 35 | let(:host) { "192.168.1.20" }
|
30 |
| - let(:port) { 9000 } |
31 |
| - let(:client_inactivity_timeout) { 400 } |
32 |
| - let(:threads) { 10 } |
33 |
| - |
34 |
| - subject(:plugin) { LogStash::Inputs::Beats.new(config) } |
| 36 | + let(:port) { 9001 } |
35 | 37 |
|
36 | 38 | it "sends the required options to the server" do
|
37 | 39 | expect(org.logstash.beats.Server).to receive(:new).with(host, port, client_inactivity_timeout, threads)
|
|
158 | 160 |
|
159 | 161 | it "raise a ConfigurationError when multiline codec is set" do
|
160 | 162 | plugin = LogStash::Inputs::Beats.new(config)
|
161 |
| - expect {plugin.register}.to raise_error(LogStash::ConfigurationError, "Multiline codec with beats input is not supported. Please refer to the beats documentation for how to best manage multiline data. See https://www.elastic.co/guide/en/beats/filebeat/current/multiline-examples.html") |
| 163 | + expect { plugin.register }.to raise_error(LogStash::ConfigurationError, "Multiline codec with beats input is not supported. Please refer to the beats documentation for how to best manage multiline data. See https://www.elastic.co/guide/en/beats/filebeat/current/multiline-examples.html") |
| 164 | + end |
| 165 | + end |
| 166 | + end |
| 167 | + |
| 168 | + context "tls meta-data" do |
| 169 | + let(:config) { super().merge("host" => host, "ssl_peer_metadata" => true, "ssl_certificate_authorities" => [ certificate.ssl_cert ]) } |
| 170 | + let(:host) { "192.168.1.20" } |
| 171 | + let(:port) { 9002 } |
| 172 | + |
| 173 | + let(:queue) { Queue.new } |
| 174 | + let(:event) { LogStash::Event.new } |
| 175 | + |
| 176 | + subject(:plugin) { LogStash::Inputs::Beats.new(config) } |
| 177 | + |
| 178 | + before do |
| 179 | + @server = org.logstash.beats.Server.new(host, port, client_inactivity_timeout, threads) |
| 180 | + expect( org.logstash.beats.Server ).to receive(:new).with(host, port, client_inactivity_timeout, threads).and_return @server |
| 181 | + expect( @server ).to receive(:listen) |
| 182 | + |
| 183 | + subject.register |
| 184 | + subject.run(queue) # listen does nothing |
| 185 | + @message_listener = @server.getMessageListener |
| 186 | + |
| 187 | + allow( ssl_engine = double('ssl_engine') ).to receive(:getSession).and_return ssl_session |
| 188 | + allow( ssl_handler = double('ssl-handler') ).to receive(:engine).and_return ssl_engine |
| 189 | + allow( pipeline = double('pipeline') ).to receive(:get).and_return ssl_handler |
| 190 | + allow( @channel = double('channel') ).to receive(:pipeline).and_return pipeline |
| 191 | + end |
| 192 | + |
| 193 | + let(:ctx) do |
| 194 | + Java::io.netty.channel.ChannelHandlerContext.impl do |method, *args| |
| 195 | + fail("unexpected #{method}( #{args} )") unless method.eql?(:channel) |
| 196 | + @channel |
162 | 197 | end
|
163 | 198 | end
|
| 199 | + |
| 200 | + let(:ssl_session) do |
| 201 | + Java::javax.net.ssl.SSLSession.impl do |method, *args| |
| 202 | + case method |
| 203 | + when :getPeerCertificates |
| 204 | + [].to_java(java.security.cert.Certificate) |
| 205 | + when :getProtocol |
| 206 | + 'TLS-Mock' |
| 207 | + when :getCipherSuite |
| 208 | + 'SSL_NULL_WITH_TEST_SPEC' |
| 209 | + when :getPeerPrincipal |
| 210 | + javax.security.auth.x500.X500Principal.new('CN=TEST, OU=RSpec, O=Logstash, C=NL', {}) |
| 211 | + else |
| 212 | + fail("unexpected #{method}( #{args} )") |
| 213 | + end |
| 214 | + end |
| 215 | + end |
| 216 | + |
| 217 | + let(:ssl_session_peer_principal) do |
| 218 | + javax.security.auth.x500.X500Principal |
| 219 | + end |
| 220 | + |
| 221 | + let(:message) do |
| 222 | + org.logstash.beats.Message.new(0, java.util.HashMap.new('foo' => 'bar')) |
| 223 | + end |
| 224 | + |
| 225 | + it 'sets tls fields' do |
| 226 | + @message_listener.onNewMessage(ctx, message) |
| 227 | + |
| 228 | + expect( queue.size ).to be 1 |
| 229 | + expect( event = queue.pop ).to be_a LogStash::Event |
| 230 | + |
| 231 | + expect( event.get('[@metadata][tls_peer][status]') ).to eql 'verified' |
| 232 | + |
| 233 | + expect( event.get('[@metadata][tls_peer][protocol]') ).to eql 'TLS-Mock' |
| 234 | + expect( event.get('[@metadata][tls_peer][cipher_suite]') ).to eql 'SSL_NULL_WITH_TEST_SPEC' |
| 235 | + expect( event.get('[@metadata][tls_peer][subject]') ).to eql 'CN=TEST,OU=RSpec,O=Logstash,C=NL' |
| 236 | + end |
164 | 237 | end
|
165 | 238 |
|
166 | 239 | context "when interrupting the plugin" do
|
|
0 commit comments