|
26 | 26 | end
|
27 | 27 | end
|
28 | 28 |
|
| 29 | + describe "auth setup with api-key" do |
| 30 | + let(:klass) { LogStash::Outputs::ElasticSearch::HttpClientBuilder } |
| 31 | + |
| 32 | + context "when api-key is not encoded (id:api-key)" do |
| 33 | + let(:api_key) { "id:api-key" } |
| 34 | + let(:api_key_secured) do |
| 35 | + secured = double("api_key") |
| 36 | + allow(secured).to receive(:value).and_return(api_key) |
| 37 | + secured |
| 38 | + end |
| 39 | + let(:options) { { "api_key" => api_key_secured } } |
| 40 | + let(:logger) { double("logger") } |
| 41 | + let(:api_key_header) { klass.setup_api_key(logger, options) } |
| 42 | + |
| 43 | + it "returns the correct encoded api-key header" do |
| 44 | + expected = "ApiKey #{Base64.strict_encode64(api_key)}" |
| 45 | + expect(api_key_header["Authorization"]).to eql(expected) |
| 46 | + end |
| 47 | + end |
| 48 | + |
| 49 | + context "when api-key is already encoded" do |
| 50 | + let(:api_key) { Base64.strict_encode64("id:api-key") } |
| 51 | + let(:api_key_secured) do |
| 52 | + secured = double("api_key") |
| 53 | + allow(secured).to receive(:value).and_return(api_key) |
| 54 | + secured |
| 55 | + end |
| 56 | + let(:options) { { "api_key" => api_key_secured } } |
| 57 | + let(:logger) { double("logger") } |
| 58 | + let(:api_key_header) { klass.setup_api_key(logger, options) } |
| 59 | + |
| 60 | + it "returns the api-key header as is" do |
| 61 | + expected = "ApiKey #{api_key}" |
| 62 | + expect(api_key_header["Authorization"]).to eql(expected) |
| 63 | + end |
| 64 | + end |
| 65 | + end |
| 66 | + |
29 | 67 | describe "customizing action paths" do
|
30 | 68 | let(:hosts) { [ ::LogStash::Util::SafeURI.new("http://localhost:9200") ] }
|
31 | 69 | let(:options) { {"hosts" => hosts } }
|
|
0 commit comments