|
4 | 4 | require "logstash/filters/elasticsearch" |
5 | 5 | require "logstash/json" |
6 | 6 | require "cabin" |
7 | | -require "manticore" |
8 | 7 | require "webrick" |
9 | 8 | require "uri" |
10 | 9 |
|
@@ -326,25 +325,30 @@ def wait_receive_request |
326 | 325 |
|
327 | 326 | context "with ssl" do |
328 | 327 | 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') } |
330 | 329 |
|
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'] |
335 | 335 |
|
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 |
339 | 339 |
|
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 |
344 | 346 |
|
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)) |
347 | 350 | end |
| 351 | + it_behaves_like "a plugin that sets the ApiKey authorization header" |
348 | 352 | end |
349 | 353 |
|
350 | 354 | context 'user also set' do |
|
0 commit comments