-
Notifications
You must be signed in to change notification settings - Fork 307
/
Copy pathhttp_client_builder_spec.rb
228 lines (199 loc) · 8.01 KB
/
http_client_builder_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
require "logstash/devutils/rspec/spec_helper"
require "logstash/outputs/elasticsearch"
require "logstash/outputs/elasticsearch/http_client"
require "logstash/outputs/elasticsearch/http_client_builder"
describe LogStash::Outputs::ElasticSearch::HttpClientBuilder do
describe "auth setup with url encodable passwords" do
let(:klass) { LogStash::Outputs::ElasticSearch::HttpClientBuilder }
let(:user) { "foo@bar"}
let(:password) {"baz@blah" }
let(:password_secured) do
secured = double("password")
allow(secured).to receive(:value).and_return(password)
secured
end
let(:basic_auth_eager) { true }
let(:options) { {"user" => user, "password" => password} }
let(:logger) { mock("logger") }
let(:auth_setup) { klass.setup_basic_auth(double("logger"), {"user" => user, "password" => password_secured, "basic_auth_eager" => basic_auth_eager}) }
it "should return the user escaped" do
expect(auth_setup[:user]).to eql(CGI.escape(user))
end
it "should return the password escaped" do
expect(auth_setup[:password]).to eql(CGI.escape(password))
end
end
describe "auth without eager basic auth" do
let(:hosts) { [ ::LogStash::Util::SafeURI.new("http://localhost:9200") ] }
let(:options) { {
"basic_auth_eager" => false,
"hosts" => hosts,
} }
let(:logger) { double("logger") }
before :each do
[:debug, :debug?, :info?, :info, :warn].each do |level|
allow(logger).to receive(level)
end
end
it "Attempt to connect without auth, fake the response requesting credentials, check that your code then retries with the auth" do
end
context "with cookies" do
let(:options) { super.merge("cookies" => true) }
it "should use cookies when configured" do
expect(described_class).to receive(:create_http_client) do |options|
expect(options[:client_settings][:cookies]).to eq(true)
end
described_class.build(logger, hosts, options)
end
it "Attempt to connect with basic auth, fake the response setting a cookie, check that your code saves the cookie" do
end
context "already saved" do
it "Attempt to connect when the cookie is saved in memory, check that the request will actually send the cookie with the request" do
end
end
context "expired" do
it "Attempt to connect when an expired cookie is saved in memory, fake the response requesting credentials, check that your code retries with the auth" do
end
end
end
end
describe "customizing action paths" do
let(:hosts) { [ ::LogStash::Util::SafeURI.new("http://localhost:9200") ] }
let(:options) { {"hosts" => hosts } }
let(:logger) { double("logger") }
before :each do
[:debug, :debug?, :info?, :info, :warn].each do |level|
allow(logger).to receive(level)
end
end
describe "healthcheck_path" do
context "when setting bulk_path" do
let(:bulk_path) { "/meh" }
let(:options) { super.merge("bulk_path" => bulk_path) }
context "when using path" do
let(:options) { super.merge("path" => "/path") }
it "ignores the path setting" do
expect(described_class).to receive(:create_http_client) do |options|
expect(options[:bulk_path]).to eq(bulk_path)
end
described_class.build(logger, hosts, options)
end
end
context "when not using path" do
it "uses the bulk_path setting" do
expect(described_class).to receive(:create_http_client) do |options|
expect(options[:bulk_path]).to eq(bulk_path)
end
described_class.build(logger, hosts, options)
end
end
end
context "when not setting bulk_path" do
context "when using path" do
let(:path) { "/meh" }
let(:options) { super.merge("path" => path) }
it "sets bulk_path to path+_bulk" do
expect(described_class).to receive(:create_http_client) do |options|
expect(options[:bulk_path]).to eq("#{path}/_bulk")
end
described_class.build(logger, hosts, options)
end
end
context "when not using path" do
it "sets the bulk_path to _bulk" do
expect(described_class).to receive(:create_http_client) do |options|
expect(options[:bulk_path]).to eq("/_bulk")
end
described_class.build(logger, hosts, options)
end
end
end
end
describe "healthcheck_path" do
context "when setting healthcheck_path" do
let(:healthcheck_path) { "/meh" }
let(:options) { super.merge("healthcheck_path" => healthcheck_path) }
context "when using path" do
let(:options) { super.merge("path" => "/path") }
it "ignores the path setting" do
expect(described_class).to receive(:create_http_client) do |options|
expect(options[:healthcheck_path]).to eq(healthcheck_path)
end
described_class.build(logger, hosts, options)
end
end
context "when not using path" do
it "uses the healthcheck_path setting" do
expect(described_class).to receive(:create_http_client) do |options|
expect(options[:healthcheck_path]).to eq(healthcheck_path)
end
described_class.build(logger, hosts, options)
end
end
end
context "when not setting healthcheck_path" do
context "when using path" do
let(:path) { "/meh" }
let(:options) { super.merge("path" => path) }
it "sets healthcheck_path to path" do
expect(described_class).to receive(:create_http_client) do |options|
expect(options[:healthcheck_path]).to eq(path)
end
described_class.build(logger, hosts, options)
end
end
context "when not using path" do
it "sets the healthcheck_path to root" do
expect(described_class).to receive(:create_http_client) do |options|
expect(options[:healthcheck_path]).to eq("/")
end
described_class.build(logger, hosts, options)
end
end
end
end
describe "sniffing_path" do
context "when setting sniffing_path" do
let(:sniffing_path) { "/meh" }
let(:options) { super.merge("sniffing_path" => sniffing_path) }
context "when using path" do
let(:options) { super.merge("path" => "/path") }
it "ignores the path setting" do
expect(described_class).to receive(:create_http_client) do |options|
expect(options[:sniffing_path]).to eq(sniffing_path)
end
described_class.build(logger, hosts, options)
end
end
context "when not using path" do
it "uses the sniffing_path setting" do
expect(described_class).to receive(:create_http_client) do |options|
expect(options[:sniffing_path]).to eq(sniffing_path)
end
described_class.build(logger, hosts, options)
end
end
end
context "when not setting sniffing_path" do
context "when using path" do
let(:path) { "/meh" }
let(:options) { super.merge("path" => path) }
it "sets sniffing_path to path+_nodes/http" do
expect(described_class).to receive(:create_http_client) do |options|
expect(options[:sniffing_path]).to eq("#{path}/_nodes/http")
end
described_class.build(logger, hosts, options)
end
end
context "when not using path" do
it "sets the sniffing_path to _nodes/http" do
expect(described_class).to receive(:create_http_client) do |options|
expect(options[:sniffing_path]).to eq("/_nodes/http")
end
described_class.build(logger, hosts, options)
end
end
end
end
end
end