|
17 | 17 | allow_any_instance_of(LogStash::Outputs::ElasticSearch::HttpClient::Pool).to receive(:start) |
18 | 18 | end |
19 | 19 |
|
| 20 | + let(:spy_http_client_builder!) do |
| 21 | + allow(described_class::HttpClientBuilder).to receive(:build).with(any_args).and_call_original |
| 22 | + end |
| 23 | + |
20 | 24 | let(:after_successful_connection_thread_mock) do |
21 | 25 | double('after_successful_connection_thread', value: true) |
22 | 26 | end |
23 | 27 |
|
24 | 28 | before(:each) do |
25 | 29 | if do_register |
| 30 | + spy_http_client_builder! |
26 | 31 | stub_http_client_pool! |
27 | 32 |
|
28 | 33 | allow(subject).to receive(:finish_register) # stub-out thread completion (to avoid error log entries) |
|
1003 | 1008 | let(:api_key) { "some_id:some_api_key" } |
1004 | 1009 | let(:base64_api_key) { "ApiKey c29tZV9pZDpzb21lX2FwaV9rZXk=" } |
1005 | 1010 |
|
1006 | | - context "when set without ssl" do |
| 1011 | + shared_examples 'secure api-key authenticated client' do |
| 1012 | + let(:do_register) { true } |
| 1013 | + |
| 1014 | + it 'adds the appropriate Authorization header to the manticore client' do |
| 1015 | + expect(manticore_options[:headers]).to eq({ "Authorization" => base64_api_key }) |
| 1016 | + end |
| 1017 | + it 'is provides ssl=>true to the http client builder' do; aggregate_failures do |
| 1018 | + expect(described_class::HttpClientBuilder).to have_received(:build).with(anything, anything, hash_including('ssl'=>true)) |
| 1019 | + end; end |
| 1020 | + end |
| 1021 | + |
| 1022 | + context "when set without ssl => true" do |
1007 | 1023 | let(:do_register) { false } # this is what we want to test, so we disable the before(:each) call |
1008 | 1024 | let(:options) { { "api_key" => api_key } } |
1009 | 1025 |
|
1010 | 1026 | it "should raise a configuration error" do |
1011 | 1027 | expect { subject.register }.to raise_error LogStash::ConfigurationError, /requires SSL\/TLS/ |
1012 | 1028 | end |
| 1029 | + |
| 1030 | + context 'with cloud_id' do |
| 1031 | + let(:sample_cloud_id) { 'sample:dXMtY2VudHJhbDEuZ2NwLmNsb3VkLmVzLmlvJGFjMzFlYmI5MDI0MTc3MzE1NzA0M2MzNGZkMjZmZDQ2OjkyNDMkYTRjMDYyMzBlNDhjOGZjZTdiZTg4YTA3NGEzYmIzZTA6OTI0NA==' } |
| 1032 | + let(:options) { super().merge('cloud_id' => sample_cloud_id) } |
| 1033 | + |
| 1034 | + it_behaves_like 'secure api-key authenticated client' |
| 1035 | + end |
1013 | 1036 | end |
1014 | 1037 |
|
1015 | | - context "when set without ssl but with a https host" do |
| 1038 | + context "when set without ssl specified but with an https host" do |
1016 | 1039 | let(:do_register) { false } # this is what we want to test, so we disable the before(:each) call |
1017 | 1040 | let(:options) { { "hosts" => ["https://some.host.com"], "api_key" => api_key } } |
1018 | 1041 |
|
| 1042 | + it_behaves_like 'secure api-key authenticated client' |
| 1043 | + end |
| 1044 | + |
| 1045 | + context "when set without ssl specified but with an http host`" do |
| 1046 | + let(:do_register) { false } # this is what we want to test, so we disable the before(:each) call |
| 1047 | + let(:options) { { "hosts" => ["http://some.host.com"], "api_key" => api_key } } |
| 1048 | + |
| 1049 | + it "should raise a configuration error" do |
| 1050 | + expect { subject.register }.to raise_error LogStash::ConfigurationError, /requires SSL\/TLS/ |
| 1051 | + end |
| 1052 | + end |
| 1053 | + |
| 1054 | + context "when set with `ssl => false`" do |
| 1055 | + let(:do_register) { false } # this is what we want to test, so we disable the before(:each) call |
| 1056 | + let(:options) { { "ssl" => "false", "api_key" => api_key } } |
| 1057 | + |
1019 | 1058 | it "should raise a configuration error" do |
1020 | 1059 | expect { subject.register }.to raise_error LogStash::ConfigurationError, /requires SSL\/TLS/ |
1021 | 1060 | end |
1022 | 1061 | end |
1023 | 1062 |
|
1024 | 1063 | context "when set" do |
1025 | | - let(:options) { { "ssl" => true, "api_key" => ::LogStash::Util::Password.new(api_key) } } |
| 1064 | + let(:options) { { "api_key" => ::LogStash::Util::Password.new(api_key) } } |
1026 | 1065 |
|
1027 | | - it "should use the custom headers in the adapter options" do |
1028 | | - expect(manticore_options[:headers]).to eq({ "Authorization" => base64_api_key }) |
| 1066 | + context "with ssl => true" do |
| 1067 | + let(:options) { super().merge("ssl" => true) } |
| 1068 | + it_behaves_like 'secure api-key authenticated client' |
| 1069 | + end |
| 1070 | + |
| 1071 | + context "with ssl => false" do |
| 1072 | + let(:options) { super().merge("ssl" => "false") } |
| 1073 | + |
| 1074 | + let(:do_register) { false } # this is what we want to test, so we disable the before(:each) call |
| 1075 | + it "should raise a configuration error" do |
| 1076 | + expect { subject.register }.to raise_error LogStash::ConfigurationError, /requires SSL\/TLS/ |
| 1077 | + end |
| 1078 | + end |
| 1079 | + |
| 1080 | + context "without ssl specified" do |
| 1081 | + context "with an https host" do |
| 1082 | + let(:options) { super().merge("hosts" => ["https://some.host.com"]) } |
| 1083 | + it_behaves_like 'secure api-key authenticated client' |
| 1084 | + end |
| 1085 | + context "with an http host`" do |
| 1086 | + let(:do_register) { false } # this is what we want to test, so we disable the before(:each) call |
| 1087 | + let(:options) { { "hosts" => ["http://some.host.com"], "api_key" => api_key } } |
| 1088 | + |
| 1089 | + it "should raise a configuration error" do |
| 1090 | + expect { subject.register }.to raise_error LogStash::ConfigurationError, /requires SSL\/TLS/ |
| 1091 | + end |
| 1092 | + end |
1029 | 1093 | end |
1030 | 1094 | end |
1031 | 1095 |
|
|
0 commit comments