logstash-output-elasticsearch 5.4.1-java → 6.0.0-java

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,12 +4,7 @@ require "logstash/outputs/elasticsearch"
4
4
  require 'manticore/client'
5
5
 
6
6
  describe "Proxy option" do
7
- let(:settings) {
8
- {
9
- "hosts" => "node01",
10
- "proxy" => proxy
11
- }
12
- }
7
+ let(:settings) { { "hosts" => "node01" } }
13
8
  subject {
14
9
  LogStash::Outputs::ElasticSearch.new(settings)
15
10
  }
@@ -23,30 +18,46 @@ describe "Proxy option" do
23
18
  subject.register
24
19
  end
25
20
 
26
- context "when specified as a string" do
27
- let(:proxy) { "http://127.0.0.1:1234" }
28
-
29
- it "should set the proxy to the exact value" do
30
- expect(::Manticore::Client).to have_received(:new) do |options|
31
- expect(options[:proxy]).to eql(proxy)
21
+ context "when specified as a URI" do
22
+ shared_examples("hash conversion") do |hash|
23
+ let(:settings) { super.merge("proxy" => proxy)}
24
+
25
+ it "should set the proxy to the correct hash value" do
26
+ expect(::Manticore::Client).to have_received(:new) do |options|
27
+ expect(options[:proxy]).to eq(hash)
28
+ end
32
29
  end
33
30
  end
34
- end
31
+
32
+ describe "simple proxy" do
33
+ let(:proxy) { LogStash::Util::SafeURI.new("http://127.0.0.1:1234") }
35
34
 
36
- context "when specified as a hash" do
37
- let(:proxy) { {"hosts" => "127.0.0.1", "protocol" => "http"} }
35
+ include_examples("hash conversion",
36
+ {
37
+ :host => "127.0.0.1",
38
+ :scheme => "http",
39
+ :port => 1234
40
+ }
41
+ )
42
+ end
43
+
44
+
45
+ describe "a secure authed proxy" do
46
+ let(:proxy) { LogStash::Util::SafeURI.new("https://myuser:mypass@127.0.0.1:1234") }
38
47
 
39
- it "should pass through the proxy values as symbols" do
40
- expected = {:hosts => proxy["hosts"], :protocol => proxy["protocol"]}
41
- expect(::Manticore::Client).to have_received(:new) do |options|
42
- expect(options[:proxy]).to eql(expected)
43
- end
48
+ include_examples("hash conversion",
49
+ {
50
+ :host => "127.0.0.1",
51
+ :scheme => "https",
52
+ :user => "myuser",
53
+ :password => "mypass",
54
+ :port => 1234
55
+ }
56
+ )
44
57
  end
45
58
  end
46
59
 
47
60
  context "when not specified" do
48
- let(:proxy) { nil }
49
-
50
61
  it "should not send the proxy option to manticore" do
51
62
  expect(::Manticore::Client).to have_received(:new) do |options|
52
63
  expect(options).not_to include(:proxy)
@@ -54,15 +65,4 @@ describe "Proxy option" do
54
65
  end
55
66
  end
56
67
  end
57
-
58
- describe "invalid configs" do
59
- let(:proxy) { ["bad", "stuff"] }
60
-
61
- it "should have raised an exception" do
62
- expect {
63
- subject.register
64
- }.to raise_error(LogStash::ConfigurationError)
65
- end
66
- end
67
-
68
68
  end
@@ -8,23 +8,34 @@ describe "outputs/elasticsearch" do
8
8
  {
9
9
  "index" => "my-index",
10
10
  "hosts" => ["localhost","localhost:9202"],
11
- "path" => "some-path"
11
+ "path" => "some-path",
12
+ "manage_template" => false
12
13
  }
13
14
  }
14
-
15
- let(:eso) {LogStash::Outputs::ElasticSearch.new(options)}
15
+
16
+ let(:eso) { LogStash::Outputs::ElasticSearch.new(options) }
16
17
 
17
18
  let(:manticore_urls) { eso.client.pool.urls }
18
19
  let(:manticore_url) { manticore_urls.first }
19
20
 
20
21
  let(:do_register) { true }
21
22
 
22
- around(:each) do |block|
23
- eso.register if do_register
24
- block.call()
25
- eso.close if do_register
23
+ before(:each) do
24
+ if do_register
25
+ eso.register
26
+
27
+ # Rspec mocks can't handle background threads, so... we can't use any
28
+ allow(eso.client.pool).to receive(:start_resurrectionist)
29
+ allow(eso.client.pool).to receive(:start_sniffer)
30
+ allow(eso.client.pool).to receive(:healthcheck!)
31
+ eso.client.pool.adapter.manticore.respond_with(:body => "{}")
32
+ end
26
33
  end
27
-
34
+
35
+ after(:each) do
36
+ eso.close
37
+ end
38
+
28
39
  describe "getting a document type" do
29
40
  it "should default to 'logs'" do
30
41
  expect(eso.send(:get_event_type, LogStash::Event.new)).to eql("logs")
@@ -59,13 +70,43 @@ describe "outputs/elasticsearch" do
59
70
  end
60
71
  end
61
72
  end
73
+
74
+ describe "with auth" do
75
+ let(:user) { "myuser" }
76
+ let(:password) { ::LogStash::Util::Password.new("mypassword") }
77
+
78
+ shared_examples "an authenticated config" do
79
+ it "should set the URL auth correctly" do
80
+ expect(manticore_url.user).to eq user
81
+ end
82
+ end
83
+
84
+ context "as part of a URL" do
85
+ let(:options) {
86
+ super.merge("hosts" => ["http://#{user}:#{password.value}@localhost:9200"])
87
+ }
88
+
89
+ include_examples("an authenticated config")
90
+ end
91
+
92
+ context "as a hash option" do
93
+ let(:options) {
94
+ super.merge!(
95
+ "user" => user,
96
+ "password" => password
97
+ )
98
+ }
99
+
100
+ include_examples("an authenticated config")
101
+ end
102
+ end
62
103
 
63
104
  describe "with path" do
64
105
  it "should properly create a URI with the path" do
65
106
  expect(eso.path).to eql(options["path"])
66
107
  end
67
108
 
68
- it "should properly set the path on the HTTP client adding slashes" do
109
+ it "should properly set the path on the HTTP client adding slashes" do
69
110
  expect(manticore_url.path).to eql("/" + options["path"] + "/")
70
111
  end
71
112
 
@@ -185,6 +226,7 @@ describe "outputs/elasticsearch" do
185
226
  end
186
227
 
187
228
  it "should fail after the timeout" do
229
+ #pending("This is tricky now that we do healthchecks on instantiation")
188
230
  Thread.new { eso.multi_receive([LogStash::Event.new]) }
189
231
 
190
232
  # Allow the timeout to occur
@@ -214,19 +256,35 @@ describe "outputs/elasticsearch" do
214
256
  end
215
257
 
216
258
  describe "SSL end to end" do
217
- shared_examples("an encrypted client connection") do
218
- it "should enable SSL in manticore" do
219
- expect(eso.client.pool.urls.map(&:scheme).uniq).to eql(['https'])
220
- end
259
+ let(:manticore_double) do
260
+ double("manticoreX#{self.inspect}")
221
261
  end
222
-
262
+
223
263
  let(:eso) {LogStash::Outputs::ElasticSearch.new(options)}
224
- subject(:manticore) { eso.client.pool.adapter.client}
225
264
 
226
- before do
265
+ before(:each) do
266
+ response_double = double("manticore response").as_null_object
267
+ # Allow healtchecks
268
+ allow(manticore_double).to receive(:head).with(any_args).and_return(response_double)
269
+ allow(manticore_double).to receive(:get).with(any_args).and_return(response_double)
270
+ allow(manticore_double).to receive(:close)
271
+
272
+ allow(::Manticore::Client).to receive(:new).and_return(manticore_double)
227
273
  eso.register
228
274
  end
275
+
276
+ after(:each) do
277
+ eso.close
278
+ end
279
+
280
+
281
+ shared_examples("an encrypted client connection") do
282
+ it "should enable SSL in manticore" do
283
+ expect(eso.client.pool.urls.map(&:scheme).uniq).to eql(['https'])
284
+ end
285
+ end
229
286
 
287
+
230
288
  context "With the 'ssl' option" do
231
289
  let(:options) { {"ssl" => true}}
232
290
 
@@ -3,6 +3,18 @@ require 'stud/temporary'
3
3
  require "logstash/outputs/elasticsearch"
4
4
 
5
5
  describe "SSL option" do
6
+ let(:manticore_double) { double("manticoreSSL #{self.inspect}") }
7
+ before do
8
+ allow(manticore_double).to receive(:close)
9
+
10
+ response_double = double("manticore response").as_null_object
11
+ # Allow healtchecks
12
+ allow(manticore_double).to receive(:head).with(any_args).and_return(response_double)
13
+ allow(manticore_double).to receive(:get).with(any_args).and_return(response_double)
14
+
15
+ allow(::Manticore::Client).to receive(:new).and_return(manticore_double)
16
+ end
17
+
6
18
  context "when using ssl without cert verification" do
7
19
  subject do
8
20
  require "logstash/outputs/elasticsearch"
@@ -13,13 +25,18 @@ describe "SSL option" do
13
25
  "pool_max" => 1,
14
26
  "pool_max_per_route" => 1
15
27
  }
16
- next LogStash::Outputs::ElasticSearch.new(settings)
28
+ LogStash::Outputs::ElasticSearch.new(settings)
17
29
  end
18
-
30
+
31
+ after do
32
+ subject.close
33
+ end
34
+
19
35
  it "should pass the flag to the ES client" do
20
- expect(::Manticore::Client).to receive(:new).and_call_original do |args|
36
+ expect(::Manticore::Client).to receive(:new) do |args|
21
37
  expect(args[:ssl]).to eq(:enabled => true, :verify => false)
22
- end
38
+ end.and_return(manticore_double)
39
+
23
40
  subject.register
24
41
  end
25
42
 
@@ -27,7 +44,9 @@ describe "SSL option" do
27
44
  disabled_matcher = /You have enabled encryption but DISABLED certificate verification/
28
45
  expect(subject.logger).to receive(:warn).with(disabled_matcher).at_least(:once)
29
46
  allow(subject.logger).to receive(:warn).with(any_args)
47
+
30
48
  subject.register
49
+ allow(LogStash::Outputs::ElasticSearch::HttpClient::Pool).to receive(:start)
31
50
  end
32
51
  end
33
52
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-output-elasticsearch
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.4.1
4
+ version: 6.0.0
5
5
  platform: java
6
6
  authors:
7
7
  - Elastic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-14 00:00:00.000000000 Z
11
+ date: 2016-12-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -189,7 +189,6 @@ files:
189
189
  - lib/logstash/outputs/elasticsearch/http_client/manticore_adapter.rb
190
190
  - lib/logstash/outputs/elasticsearch/http_client/pool.rb
191
191
  - lib/logstash/outputs/elasticsearch/http_client_builder.rb
192
- - lib/logstash/outputs/elasticsearch/safe_url.rb
193
192
  - lib/logstash/outputs/elasticsearch/template_manager.rb
194
193
  - logstash-output-elasticsearch.gemspec
195
194
  - spec/es_spec_helper.rb
@@ -216,7 +215,6 @@ files:
216
215
  - spec/unit/outputs/elasticsearch_spec.rb
217
216
  - spec/unit/outputs/elasticsearch_ssl_spec.rb
218
217
  - spec/unit/outputs/error_whitelist_spec.rb
219
- - spec/unit/safe_url_spec.rb
220
218
  homepage: http://logstash.net/
221
219
  licenses:
222
220
  - apache-2.0
@@ -268,4 +266,3 @@ test_files:
268
266
  - spec/unit/outputs/elasticsearch_spec.rb
269
267
  - spec/unit/outputs/elasticsearch_ssl_spec.rb
270
268
  - spec/unit/outputs/error_whitelist_spec.rb
271
- - spec/unit/safe_url_spec.rb
@@ -1,16 +0,0 @@
1
- module LogStash; module Outputs; class ElasticSearch;
2
- module SafeURL
3
- PLACEHOLDER = "~hidden~".freeze
4
-
5
- module_function
6
-
7
- # Takes a URI object and returns a copy of it with any user or password
8
- # information replaced with a placeholder `~hidden~`.
9
- def without_credentials(url)
10
- url.dup.tap do |u|
11
- u.user = PLACEHOLDER if u.user
12
- u.password = PLACEHOLDER if u.password
13
- end
14
- end
15
- end
16
- end end end
@@ -1,46 +0,0 @@
1
- require "logstash/outputs/elasticsearch/safe_url"
2
- require "uri"
3
-
4
- describe ::LogStash::Outputs::ElasticSearch::SafeURL do
5
- let(:placeholder) { ::LogStash::Outputs::ElasticSearch::SafeURL::PLACEHOLDER }
6
-
7
- context "#without_credentials" do
8
- subject { described_class.without_credentials(url) }
9
-
10
- shared_examples_for "returning a new object" do
11
- it "should return a new url object" do
12
- expect(subject.object_id).not_to be == url.object_id
13
- end
14
- end
15
-
16
- context "when given a url without credentials" do
17
- let(:url) { URI.parse("https://example.com/") }
18
-
19
- it_behaves_like "returning a new object"
20
-
21
- it "should return the same url" do
22
- expect(subject).to be == url
23
- end
24
- end
25
-
26
- context "when url contains credentials" do
27
- let(:url) { URI.parse("https://user:pass@example.com/") }
28
-
29
- it_behaves_like "returning a new object"
30
-
31
- it "should hide the user" do
32
- expect(subject.user).to be == placeholder
33
- end
34
-
35
- it "should hide the password" do
36
- expect(subject.user).to be == placeholder
37
- end
38
-
39
- context "#to_s" do
40
- it "should not contain credentials" do
41
- expect(subject.to_s).to be == "https://#{placeholder}:#{placeholder}@example.com/"
42
- end
43
- end
44
- end
45
- end
46
- end