|
1 | 1 | require_relative "../../../spec/es_spec_helper"
|
| 2 | +require "base64" |
2 | 3 | require "flores/random"
|
3 | 4 | require "logstash/outputs/elasticsearch"
|
4 | 5 |
|
|
142 | 143 |
|
143 | 144 | include_examples("an authenticated config")
|
144 | 145 | end
|
| 146 | + |
| 147 | + context 'claud_auth also set' do |
| 148 | + let(:do_register) { false } # this is what we want to test, so we disable the before(:each) call |
| 149 | + let(:options) { { "user" => user, "password" => password, "cloud_auth" => "elastic:my-passwd-00" } } |
| 150 | + |
| 151 | + it "should fail" do |
| 152 | + expect { subject.register }.to raise_error LogStash::ConfigurationError, /Multiple authentication options are specified/ |
| 153 | + end |
| 154 | + end |
| 155 | + |
| 156 | + context 'api_key also set' do |
| 157 | + let(:do_register) { false } # this is what we want to test, so we disable the before(:each) call |
| 158 | + let(:options) { { "user" => user, "password" => password, "api_key" => "some_key" } } |
| 159 | + |
| 160 | + it "should fail" do |
| 161 | + expect { subject.register }.to raise_error LogStash::ConfigurationError, /Multiple authentication options are specified/ |
| 162 | + end |
| 163 | + end |
| 164 | + |
145 | 165 | end
|
146 | 166 |
|
147 | 167 | describe "with path" do
|
|
577 | 597 | let(:options) { { 'cloud_auth' => 'elastic:my-passwd-00', 'user' => 'another' } }
|
578 | 598 |
|
579 | 599 | it "should fail" do
|
580 |
| - expect { subject.register }.to raise_error LogStash::ConfigurationError, /cloud_auth and user/ |
| 600 | + expect { subject.register }.to raise_error LogStash::ConfigurationError, /Multiple authentication options are specified/ |
| 601 | + end |
| 602 | + end |
| 603 | + |
| 604 | + context 'api_key also set' do |
| 605 | + let(:options) { { 'cloud_auth' => 'elastic:my-passwd-00', 'api_key' => 'some_key' } } |
| 606 | + |
| 607 | + it "should fail" do |
| 608 | + expect { subject.register }.to raise_error LogStash::ConfigurationError, /Multiple authentication options are specified/ |
581 | 609 | end
|
582 | 610 | end
|
583 | 611 | end if LOGSTASH_VERSION > '6.0'
|
|
659 | 687 | end
|
660 | 688 | end
|
661 | 689 |
|
| 690 | + describe "API key" do |
| 691 | + let(:manticore_options) { subject.client.pool.adapter.manticore.instance_variable_get(:@options) } |
| 692 | + let(:api_key) { "some_id:some_api_key" } |
| 693 | + let(:base64_api_key) { "ApiKey c29tZV9pZDpzb21lX2FwaV9rZXk=" } |
| 694 | + |
| 695 | + context "when set without ssl" do |
| 696 | + let(:do_register) { false } # this is what we want to test, so we disable the before(:each) call |
| 697 | + let(:options) { { "api_key" => api_key } } |
| 698 | + |
| 699 | + it "should raise a configuration error" do |
| 700 | + expect { subject.register }.to raise_error LogStash::ConfigurationError, /requires SSL\/TLS/ |
| 701 | + end |
| 702 | + end |
| 703 | + |
| 704 | + context "when set without ssl but with a https host" do |
| 705 | + let(:do_register) { false } # this is what we want to test, so we disable the before(:each) call |
| 706 | + let(:options) { { "hosts" => ["https://some.host.com"], "api_key" => api_key } } |
| 707 | + |
| 708 | + it "should raise a configuration error" do |
| 709 | + expect { subject.register }.to raise_error LogStash::ConfigurationError, /requires SSL\/TLS/ |
| 710 | + end |
| 711 | + end |
| 712 | + |
| 713 | + context "when set" do |
| 714 | + let(:options) { { "ssl" => true, "api_key" => ::LogStash::Util::Password.new(api_key) } } |
| 715 | + |
| 716 | + it "should use the custom headers in the adapter options" do |
| 717 | + expect(manticore_options[:headers]).to eq({ "Authorization" => base64_api_key }) |
| 718 | + end |
| 719 | + end |
| 720 | + |
| 721 | + context "when not set" do |
| 722 | + it "should have no headers" do |
| 723 | + expect(manticore_options[:headers]).to be_empty |
| 724 | + end |
| 725 | + end |
| 726 | + |
| 727 | + context 'user also set' do |
| 728 | + let(:do_register) { false } # this is what we want to test, so we disable the before(:each) call |
| 729 | + let(:options) { { "ssl" => true, "api_key" => api_key, 'user' => 'another' } } |
| 730 | + |
| 731 | + it "should fail" do |
| 732 | + expect { subject.register }.to raise_error LogStash::ConfigurationError, /Multiple authentication options are specified/ |
| 733 | + end |
| 734 | + end |
| 735 | + |
| 736 | + context 'cloud_auth also set' do |
| 737 | + let(:do_register) { false } # this is what we want to test, so we disable the before(:each) call |
| 738 | + let(:options) { { "ssl" => true, "api_key" => api_key, 'cloud_auth' => 'foobar' } } |
| 739 | + |
| 740 | + it "should fail" do |
| 741 | + expect { subject.register }.to raise_error LogStash::ConfigurationError, /Multiple authentication options are specified/ |
| 742 | + end |
| 743 | + end |
| 744 | + end |
| 745 | + |
662 | 746 | @private
|
663 | 747 |
|
664 | 748 | def stub_manticore_client!(manticore_double = nil)
|
|
0 commit comments