Skip to content

Commit 4bc7fcd

Browse files
committed
Solved code style issues
1 parent 4a10ea5 commit 4bc7fcd

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed

lib/logstash/filters/elasticsearch/client.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,9 @@ def setup_api_key(api_key)
108108
end
109109

110110
def is_base64?(string)
111-
begin
112111
string == Base64.strict_encode64(Base64.strict_decode64(string))
113-
rescue ArgumentError
114-
false
115-
end
112+
rescue ArgumentError
113+
false
116114
end
117115

118116
def get_transport_client_class

spec/filters/elasticsearch_spec.rb

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
require "logstash/filters/elasticsearch"
55
require "logstash/json"
66
require "cabin"
7-
require "manticore"
87
require "webrick"
98
require "uri"
109

@@ -326,25 +325,30 @@ def wait_receive_request
326325

327326
context "with ssl" do
328327
let(:config) { super().merge("ssl_enabled" => true) }
329-
encoded_api_key = Base64.strict_encode64('foo:bar')
328+
let(:encoded_api_key) { Base64.strict_encode64('foo:bar') }
330329

331-
scenarios = {
332-
'with non-encoded api-key' => LogStash::Util::Password.new('foo:bar'),
333-
'with encoded api-key' => LogStash::Util::Password.new(encoded_api_key)
334-
}
330+
shared_examples "a plugin that sets the ApiKey authorization header" do
331+
it "correctly sets the Authorization header" do
332+
plugin.register
333+
client= plugin.send(:get_client).client
334+
auth_header = extract_transport(client).options[:transport_options][:headers]['Authorization']
335335

336-
scenarios.each do |description, api_key_value|
337-
context description do
338-
let(:config) { super().merge('api_key' => api_key_value) }
336+
expect(auth_header).to eql("ApiKey #{encoded_api_key}")
337+
end
338+
end
339339

340-
it "should set authorization" do
341-
plugin.register
342-
client= plugin.send(:get_client).client
343-
auth_header = extract_transport(client).options[:transport_options][:headers]['Authorization']
340+
context "with a non-encoded API key" do
341+
let(:config) do
342+
super().merge('api_key' => LogStash::Util::Password.new('foo:bar'))
343+
end
344+
it_behaves_like "a plugin that sets the ApiKey authorization header"
345+
end
344346

345-
expect(auth_header).to eql "ApiKey #{encoded_api_key}"
346-
end
347+
context "with an encoded API key" do
348+
let(:config) do
349+
super().merge('api_key' => LogStash::Util::Password.new(encoded_api_key))
347350
end
351+
it_behaves_like "a plugin that sets the ApiKey authorization header"
348352
end
349353

350354
context 'user also set' do

0 commit comments

Comments
 (0)