manticore 0.4.2-java → 0.4.3-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/.travis.yml +2 -1
- data/CHANGELOG.md +15 -2
- data/Gemfile +1 -1
- data/LICENSE.txt +0 -0
- data/README.md +3 -3
- data/Rakefile +0 -0
- data/ext/manticore/org/manticore/Manticore.java +0 -0
- data/lib/faraday/adapter/manticore.rb +11 -1
- data/lib/manticore/client.rb +58 -26
- data/lib/manticore/stubbed_response.rb +9 -5
- data/lib/manticore/version.rb +1 -1
- data/manticore.gemspec +0 -0
- data/spec/manticore/client_proxy_spec.rb +22 -22
- data/spec/manticore/client_spec.rb +152 -148
- data/spec/manticore/cookie_spec.rb +9 -9
- data/spec/manticore/facade_spec.rb +8 -8
- data/spec/manticore/response_spec.rb +16 -16
- data/spec/manticore/stubbed_response_spec.rb +20 -15
- metadata +12 -12
- metadata.gz.sig +0 -0
@@ -8,44 +8,48 @@ describe Manticore::Client do
|
|
8
8
|
|
9
9
|
let(:client) { Manticore::Client.new }
|
10
10
|
|
11
|
-
it "
|
12
|
-
client.get(local_server).
|
11
|
+
it "fetches a URL and return a response" do
|
12
|
+
expect(client.get(local_server)).to be_a Manticore::Response
|
13
13
|
end
|
14
14
|
|
15
|
-
it "
|
15
|
+
it "resolves redirections" do
|
16
16
|
response = client.get(local_server, headers: {"X-Redirect" => "/foobar"})
|
17
|
-
response.code.
|
18
|
-
response.final_url.
|
17
|
+
expect(response.code).to eq 200
|
18
|
+
expect(response.final_url).to eq URI(local_server("/foobar"))
|
19
19
|
end
|
20
20
|
|
21
|
-
it "
|
21
|
+
it "accepts custom headers" do
|
22
22
|
response = client.get(local_server, headers: {"X-Custom-Header" => "Blaznotts"})
|
23
23
|
json = JSON.load(response.body)
|
24
|
-
json["headers"]["X-Custom-Header"].
|
24
|
+
expect(json["headers"]["X-Custom-Header"]).to eq "Blaznotts"
|
25
25
|
end
|
26
26
|
|
27
|
-
it "
|
27
|
+
it "enables compression" do
|
28
28
|
response = client.get(local_server)
|
29
29
|
json = JSON.load(response.body)
|
30
|
-
json["headers"].
|
31
|
-
json["headers"]["Accept-Encoding"].
|
30
|
+
expect(json["headers"]).to have_key "Accept-Encoding"
|
31
|
+
expect(json["headers"]["Accept-Encoding"]).to match "gzip"
|
32
32
|
end
|
33
33
|
|
34
|
-
it "
|
35
|
-
client.get(local_server("/auth")).code.
|
36
|
-
client.get(local_server("/auth"), auth: {user: "user", pass: "pass"}).code.
|
34
|
+
it "authenticates" do
|
35
|
+
expect(client.get(local_server("/auth")).code).to eq 401
|
36
|
+
expect(client.get(local_server("/auth"), auth: {user: "user", pass: "pass"}).code).to eq 200
|
37
37
|
end
|
38
38
|
|
39
|
-
it "
|
39
|
+
it "authenticates with eager auth" do
|
40
|
+
expect(client.get(local_server("/auth"), auth: {user: "user", pass: "pass", eager: true}).code).to eq 200
|
41
|
+
end
|
42
|
+
|
43
|
+
it "proxies" do
|
40
44
|
j = JSON.parse(client.get(local_server("/proxy"), proxy: "http://localhost:55442").body)
|
41
|
-
j["server_port"].
|
42
|
-
j["uri"]["port"].
|
45
|
+
expect(j["server_port"]).to eq 55442
|
46
|
+
expect(j["uri"]["port"]).to eq 55441
|
43
47
|
end
|
44
48
|
|
45
49
|
describe "with a custom user agent" do
|
46
50
|
let(:client) { Manticore::Client.new user_agent: "test-agent/1.0" }
|
47
51
|
|
48
|
-
it "
|
52
|
+
it "uses the specified UA" do
|
49
53
|
response = client.get(local_server("/"))
|
50
54
|
json = JSON.load(response.body)
|
51
55
|
expect(json["headers"]["User-Agent"]).to eq "test-agent/1.0"
|
@@ -56,7 +60,7 @@ describe Manticore::Client do
|
|
56
60
|
context "when on" do
|
57
61
|
let(:client) { Manticore::Client.new ssl: {verify: false} }
|
58
62
|
|
59
|
-
it "
|
63
|
+
it "does not break on SSL validation errors" do
|
60
64
|
expect { client.get("https://localhost:55444/").body }.to_not raise_exception
|
61
65
|
end
|
62
66
|
end
|
@@ -64,7 +68,7 @@ describe Manticore::Client do
|
|
64
68
|
context "when off" do
|
65
69
|
let(:client) { Manticore::Client.new ssl: {verify: true} }
|
66
70
|
|
67
|
-
it "
|
71
|
+
it "breaks on SSL validation errors" do
|
68
72
|
expect { client.get("https://localhost:55444/").call }.to raise_exception(Manticore::ClientProtocolException)
|
69
73
|
end
|
70
74
|
end
|
@@ -75,7 +79,7 @@ describe Manticore::Client do
|
|
75
79
|
context 'default' do
|
76
80
|
let(:client) { Manticore::Client.new }
|
77
81
|
|
78
|
-
it "
|
82
|
+
it "breaks on SSL validation errors" do
|
79
83
|
expect { client.get("https://localhost:55444/").call }.to raise_exception(Manticore::ClientProtocolException)
|
80
84
|
end
|
81
85
|
end
|
@@ -83,7 +87,7 @@ describe Manticore::Client do
|
|
83
87
|
context 'when on and no trust store is given' do
|
84
88
|
let(:client) { Manticore::Client.new :ssl => {:verify => :strict} }
|
85
89
|
|
86
|
-
it "
|
90
|
+
it "breaks on SSL validation errors" do
|
87
91
|
expect { client.get("https://localhost:55444/").call }.to raise_exception(Manticore::ClientProtocolException)
|
88
92
|
end
|
89
93
|
end
|
@@ -91,7 +95,7 @@ describe Manticore::Client do
|
|
91
95
|
context 'when on and custom trust store is given' do
|
92
96
|
let(:client) { Manticore::Client.new :ssl => {verify: :strict, truststore: File.expand_path("../../ssl/truststore.jks", __FILE__), truststore_password: "test123"} }
|
93
97
|
|
94
|
-
it "
|
98
|
+
it "verifies the request and succeed" do
|
95
99
|
expect { client.get("https://localhost:55444/").body }.to_not raise_exception
|
96
100
|
end
|
97
101
|
end
|
@@ -99,7 +103,7 @@ describe Manticore::Client do
|
|
99
103
|
context "when the client specifies a protocol list" do
|
100
104
|
let(:client) { Manticore::Client.new :ssl => {verify: :strict, truststore: File.expand_path("../../ssl/truststore.jks", __FILE__), truststore_password: "test123", protocols: ["TLSv1", "TLSv1.1", "TLSv1.2"]} }
|
101
105
|
|
102
|
-
it "
|
106
|
+
it "verifies the request and succeed" do
|
103
107
|
expect { client.get("https://localhost:55444/").body }.to_not raise_exception
|
104
108
|
end
|
105
109
|
end
|
@@ -107,7 +111,7 @@ describe Manticore::Client do
|
|
107
111
|
context 'when on and custom trust store is given with the wrong password' do
|
108
112
|
let(:client) { Manticore::Client.new :ssl => {verify: :strict, truststore: File.expand_path("../../ssl/truststore.jks", __FILE__), truststore_password: "wrongpass"} }
|
109
113
|
|
110
|
-
it "
|
114
|
+
it "fails to load the keystore" do
|
111
115
|
expect { client.get("https://localhost:55444/").body }.to raise_exception(Java::JavaIo::IOException)
|
112
116
|
end
|
113
117
|
end
|
@@ -115,7 +119,7 @@ describe Manticore::Client do
|
|
115
119
|
context 'when ca_file is given' do
|
116
120
|
let(:client) { Manticore::Client.new :ssl => {verify: :strict, ca_file: File.expand_path("../../ssl/root-ca.crt", __FILE__) } }
|
117
121
|
|
118
|
-
it "
|
122
|
+
it "verifies the request and succeed" do
|
119
123
|
expect { client.get("https://localhost:55444/").body }.to_not raise_exception
|
120
124
|
end
|
121
125
|
end
|
@@ -130,7 +134,7 @@ describe Manticore::Client do
|
|
130
134
|
})
|
131
135
|
}
|
132
136
|
|
133
|
-
it "
|
137
|
+
it "successfully auths requests" do
|
134
138
|
expect(client.get("https://localhost:55445/").body).to match("hello")
|
135
139
|
end
|
136
140
|
end
|
@@ -138,7 +142,7 @@ describe Manticore::Client do
|
|
138
142
|
context 'when off' do
|
139
143
|
let(:client) { Manticore::Client.new :ssl => {:verify => :none} }
|
140
144
|
|
141
|
-
it "
|
145
|
+
it "does not break on SSL validation errors" do
|
142
146
|
expect { client.get("https://localhost:55444/").body }.to_not raise_exception
|
143
147
|
end
|
144
148
|
end
|
@@ -156,7 +160,7 @@ describe Manticore::Client do
|
|
156
160
|
Manticore::Client.new :ssl => options
|
157
161
|
}
|
158
162
|
|
159
|
-
it "
|
163
|
+
it "successfully auths requests" do
|
160
164
|
expect(client.get("https://localhost:55445/").body).to match("hello")
|
161
165
|
end
|
162
166
|
end
|
@@ -171,7 +175,7 @@ describe Manticore::Client do
|
|
171
175
|
Manticore::Client.new :ssl => options
|
172
176
|
}
|
173
177
|
|
174
|
-
it "
|
178
|
+
it "fails the request" do
|
175
179
|
# oraclejdk7 throws a SocketException here, oraclejdk8/openjdk7 throw ClientProtocolException
|
176
180
|
expect { client.get("https://localhost:55445/").body }.to raise_exception(Manticore::ManticoreException)
|
177
181
|
end
|
@@ -189,17 +193,17 @@ describe Manticore::Client do
|
|
189
193
|
end
|
190
194
|
|
191
195
|
describe "lazy evaluation" do
|
192
|
-
it "
|
196
|
+
it "does not call synchronous requests by default" do
|
193
197
|
req = client.get(local_server)
|
194
|
-
req.
|
198
|
+
expect(req).to_not be_called
|
195
199
|
end
|
196
200
|
|
197
201
|
context "given a lazy request" do
|
198
202
|
subject { client.get(local_server) }
|
199
203
|
|
200
204
|
before do
|
201
|
-
subject.
|
202
|
-
subject.
|
205
|
+
expect(subject).to_not be_called
|
206
|
+
expect(subject).to receive(:call).once.and_call_original
|
203
207
|
end
|
204
208
|
|
205
209
|
specify { expect { subject.body }.to change { subject.called? } }
|
@@ -210,29 +214,29 @@ describe Manticore::Client do
|
|
210
214
|
specify { expect { subject.cookies }.to change { subject.called? } }
|
211
215
|
end
|
212
216
|
|
213
|
-
it "
|
217
|
+
it "automatically calls synchronous requests that pass a handler block" do
|
214
218
|
req = client.get(local_server) {|r| }
|
215
|
-
req.
|
219
|
+
expect(req).to be_called
|
216
220
|
end
|
217
221
|
|
218
|
-
it "
|
222
|
+
it "does not call asynchronous requests even if a block is passed" do
|
219
223
|
req = client.async.get(local_server) {|r| }
|
220
|
-
req.
|
224
|
+
expect(req).to_not be_called
|
221
225
|
end
|
222
226
|
|
223
|
-
it "
|
227
|
+
it "does not call asynchronous requests when on_success is passed" do
|
224
228
|
req = client.async.get(local_server).on_success {|r| }
|
225
|
-
req.
|
229
|
+
expect(req).to_not be_called
|
226
230
|
end
|
227
231
|
|
228
|
-
it "
|
232
|
+
it "calls async requests on client execution" do
|
229
233
|
req = client.async.get(local_server).on_success {|r| }
|
230
234
|
expect { client.execute! }.to change { req.called? }.from(false).to(true)
|
231
235
|
end
|
232
236
|
|
233
237
|
|
234
238
|
describe "with a bad port number" do
|
235
|
-
it "
|
239
|
+
it "returns a Manticore::InvalidArgumentException" do
|
236
240
|
failure = nil
|
237
241
|
client.async.get(local_server("/", 65536)).
|
238
242
|
on_failure {|f| failure = f }
|
@@ -242,7 +246,7 @@ describe Manticore::Client do
|
|
242
246
|
end
|
243
247
|
|
244
248
|
describe "mysterious failures" do
|
245
|
-
it "
|
249
|
+
it "still returns an error to on failure" do
|
246
250
|
failure = nil
|
247
251
|
# I'm not crazy about reaching into the client via instance_variable_get here, but it works.
|
248
252
|
expect(client.instance_variable_get("@client")).to receive(:execute).and_raise(StandardError.new("Uh oh"))
|
@@ -257,66 +261,66 @@ describe Manticore::Client do
|
|
257
261
|
context "when client-wide cookie management is disabled" do
|
258
262
|
let(:client) { Manticore::Client.new cookies: false }
|
259
263
|
|
260
|
-
it "
|
264
|
+
it "persists cookies across multiple redirects from a single request" do
|
261
265
|
response = client.get(local_server("/cookies/1/2"))
|
262
|
-
response.final_url.to_s.
|
263
|
-
response.cookies["x"].
|
264
|
-
response.headers["set-cookie"].
|
266
|
+
expect(response.final_url.to_s).to eq local_server("/cookies/2/2")
|
267
|
+
expect(response.cookies["x"]).to be_nil
|
268
|
+
expect(response.headers["set-cookie"]).to match(/1/)
|
265
269
|
end
|
266
270
|
|
267
|
-
it "
|
271
|
+
it "does not persist cookies between requests" do
|
268
272
|
response = client.get(local_server("/cookies/1/2"))
|
269
|
-
response.final_url.to_s.
|
270
|
-
response.cookies["x"].
|
271
|
-
response.headers["set-cookie"].
|
273
|
+
expect(response.final_url.to_s).to eq local_server("/cookies/2/2")
|
274
|
+
expect(response.cookies["x"]).to be_nil
|
275
|
+
expect(response.headers["set-cookie"]).to match(/1/)
|
272
276
|
|
273
277
|
response = client.get(local_server("/cookies/1/2"))
|
274
|
-
response.final_url.to_s.
|
275
|
-
response.cookies["x"].
|
276
|
-
response.headers["set-cookie"].
|
278
|
+
expect(response.final_url.to_s).to eq local_server("/cookies/2/2")
|
279
|
+
expect(response.cookies["x"]).to be_nil
|
280
|
+
expect(response.headers["set-cookie"]).to match(/1/)
|
277
281
|
end
|
278
282
|
end
|
279
283
|
|
280
284
|
context "when client-wide cookie management is set to per-request" do
|
281
285
|
let(:client) { Manticore::Client.new cookies: :per_request }
|
282
286
|
|
283
|
-
it "
|
287
|
+
it "persists cookies across multiple redirects from a single request" do
|
284
288
|
response = client.get(local_server("/cookies/1/2"))
|
285
|
-
response.final_url.to_s.
|
286
|
-
response.headers["set-cookie"].
|
287
|
-
response.cookies["x"].first.value.
|
289
|
+
expect(response.final_url.to_s).to eq local_server("/cookies/2/2")
|
290
|
+
expect(response.headers["set-cookie"]).to match(/2/)
|
291
|
+
expect(response.cookies["x"].first.value).to eq "2"
|
288
292
|
end
|
289
293
|
|
290
|
-
it "
|
294
|
+
it "does not persist cookies between requests" do
|
291
295
|
response = client.get(local_server("/cookies/1/2"))
|
292
|
-
response.final_url.to_s.
|
293
|
-
response.headers["set-cookie"].
|
294
|
-
response.cookies["x"].first.value.
|
296
|
+
expect(response.final_url.to_s).to eq local_server("/cookies/2/2")
|
297
|
+
expect(response.headers["set-cookie"]).to match(/2/)
|
298
|
+
expect(response.cookies["x"].first.value).to eq "2"
|
295
299
|
|
296
300
|
response = client.get(local_server("/cookies/1/2"))
|
297
|
-
response.final_url.to_s.
|
298
|
-
response.headers["set-cookie"].
|
299
|
-
response.cookies["x"].first.value.
|
301
|
+
expect(response.final_url.to_s).to eq local_server("/cookies/2/2")
|
302
|
+
expect(response.headers["set-cookie"]).to match(/2/)
|
303
|
+
expect(response.cookies["x"].first.value).to eq "2"
|
300
304
|
end
|
301
305
|
end
|
302
306
|
|
303
307
|
context "when client-wide cookie management is enabled" do
|
304
308
|
let(:client) { Manticore::Client.new cookies: true }
|
305
309
|
|
306
|
-
it "
|
310
|
+
it "persists cookies across multiple redirects from a single request" do
|
307
311
|
response = client.get(local_server("/cookies/1/2"))
|
308
|
-
response.final_url.to_s.
|
309
|
-
response.cookies["x"].first.value.
|
312
|
+
expect(response.final_url.to_s).to eq local_server("/cookies/2/2")
|
313
|
+
expect(response.cookies["x"].first.value).to eq "2"
|
310
314
|
end
|
311
315
|
|
312
|
-
it "
|
316
|
+
it "persists cookies between requests" do
|
313
317
|
response = client.get(local_server("/cookies/1/2"))
|
314
|
-
response.final_url.to_s.
|
315
|
-
response.cookies["x"].first.value.
|
318
|
+
expect(response.final_url.to_s).to eq local_server("/cookies/2/2")
|
319
|
+
expect(response.cookies["x"].first.value).to eq "2"
|
316
320
|
|
317
321
|
response = client.get(local_server("/cookies/1/2"))
|
318
|
-
response.final_url.to_s.
|
319
|
-
response.cookies["x"].first.value.
|
322
|
+
expect(response.final_url.to_s).to eq local_server("/cookies/2/2")
|
323
|
+
expect(response.cookies["x"].first.value).to eq "4"
|
320
324
|
end
|
321
325
|
end
|
322
326
|
|
@@ -327,138 +331,138 @@ describe Manticore::Client do
|
|
327
331
|
end
|
328
332
|
}
|
329
333
|
|
330
|
-
it "
|
334
|
+
it "disables compression" do
|
331
335
|
response = client.get(local_server)
|
332
336
|
json = JSON.load(response.body)
|
333
|
-
json["headers"]["Accept-Encoding"].
|
337
|
+
expect(json["headers"]["Accept-Encoding"]).to be_nil
|
334
338
|
end
|
335
339
|
end
|
336
340
|
|
337
341
|
context "when no response charset is specified" do
|
338
342
|
let(:content_type) { "text/plain" }
|
339
343
|
|
340
|
-
it "
|
341
|
-
client.get(local_server, headers: {"X-Content-Type" => content_type}).body.encoding.name.
|
344
|
+
it "decodes response bodies according to the content-type header" do
|
345
|
+
expect(client.get(local_server, headers: {"X-Content-Type" => content_type}).body.encoding.name).to eq "ISO-8859-1"
|
342
346
|
end
|
343
347
|
end
|
344
348
|
|
345
349
|
context "when an invalid response charset is specified" do
|
346
350
|
let(:content_type) { "text/plain; charset=bogus" }
|
347
351
|
|
348
|
-
it "
|
349
|
-
client.get(local_server, headers: {"X-Content-Type" => content_type}).body.encoding.name.
|
352
|
+
it "decodes the content as UTF-8" do
|
353
|
+
expect(client.get(local_server, headers: {"X-Content-Type" => content_type}).body.encoding.name).to eq "ISO-8859-1"
|
350
354
|
end
|
351
355
|
end
|
352
356
|
|
353
357
|
context "when the response charset is UTF-8" do
|
354
358
|
let(:content_type) { "text/plain; charset=utf-8" }
|
355
359
|
|
356
|
-
it "
|
357
|
-
client.get(local_server, headers: {"X-Content-Type" => content_type}).body.encoding.name.
|
360
|
+
it "decodes response bodies according to the content-type header" do
|
361
|
+
expect(client.get(local_server, headers: {"X-Content-Type" => content_type}).body.encoding.name).to eq "UTF-8"
|
358
362
|
end
|
359
363
|
end
|
360
364
|
|
361
365
|
describe "#get" do
|
362
|
-
it "
|
366
|
+
it "works" do
|
363
367
|
response = client.get(local_server)
|
364
|
-
JSON.load(response.body)["method"].
|
368
|
+
expect(JSON.load(response.body)["method"]).to eq "GET"
|
365
369
|
end
|
366
370
|
|
367
371
|
it "send a query" do
|
368
372
|
response = client.get local_server, query: {foo: "bar"}
|
369
|
-
CGI.parse(JSON.load(response.body)["uri"]["query"])["foo"].
|
373
|
+
expect(CGI.parse(JSON.load(response.body)["uri"]["query"])["foo"]).to eq ["bar"]
|
370
374
|
end
|
371
375
|
|
372
|
-
it "
|
376
|
+
it "sends a body" do
|
373
377
|
response = client.get(local_server, body: "This is a post body")
|
374
|
-
JSON.load(response.body)["body"].
|
378
|
+
expect(JSON.load(response.body)["body"]).to eq "This is a post body"
|
375
379
|
end
|
376
380
|
end
|
377
381
|
|
378
382
|
describe "#post" do
|
379
|
-
it "
|
383
|
+
it "works" do
|
380
384
|
response = client.post(local_server)
|
381
|
-
JSON.load(response.body)["method"].
|
385
|
+
expect(JSON.load(response.body)["method"]).to eq "POST"
|
382
386
|
end
|
383
387
|
|
384
|
-
it "
|
388
|
+
it "sends a body" do
|
385
389
|
response = client.post(local_server, body: "This is a post body")
|
386
|
-
JSON.load(response.body)["body"].
|
390
|
+
expect(JSON.load(response.body)["body"]).to eq "This is a post body"
|
387
391
|
end
|
388
392
|
|
389
|
-
it "
|
393
|
+
it "sends a UTF-8 body" do
|
390
394
|
response = client.post(local_server, body: "This is a post body ∑")
|
391
|
-
JSON.load(response.body)["body"].
|
395
|
+
expect(JSON.load(response.body)["body"]).to eq "This is a post body ∑"
|
392
396
|
end
|
393
397
|
|
394
|
-
it "
|
398
|
+
it "sends params" do
|
395
399
|
response = client.post(local_server, params: {key: "value"})
|
396
|
-
CGI.unescape(JSON.load(response.body)["body"]).
|
400
|
+
expect(CGI.unescape(JSON.load(response.body)["body"])).to eq "key=value"
|
397
401
|
end
|
398
402
|
|
399
|
-
it "
|
403
|
+
it "sends non-ASCII params" do
|
400
404
|
response = client.post(local_server, params: {"∑" => "√"})
|
401
|
-
CGI.unescape(JSON.load(response.body)["body"]).
|
405
|
+
expect(CGI.unescape(JSON.load(response.body)["body"])).to eq "∑=√"
|
402
406
|
end
|
403
407
|
|
404
|
-
it "
|
408
|
+
it "sends an arbitrary entity" do
|
405
409
|
f = open(__FILE__, "r").to_inputstream
|
406
410
|
multipart_entity = MultipartEntityBuilder.create.add_text_body("foo", "bar").add_binary_body("whatever", f , ContentType::TEXT_PLAIN, __FILE__)
|
407
411
|
response = client.post(local_server, entity: multipart_entity.build)
|
408
|
-
response.body.
|
412
|
+
expect(response.body).to match "sends an arbitrary entity"
|
409
413
|
end
|
410
414
|
end
|
411
415
|
|
412
416
|
describe "#put" do
|
413
|
-
it "
|
417
|
+
it "works" do
|
414
418
|
response = client.put(local_server)
|
415
|
-
JSON.load(response.body)["method"].
|
419
|
+
expect(JSON.load(response.body)["method"]).to eq "PUT"
|
416
420
|
end
|
417
421
|
|
418
|
-
it "
|
422
|
+
it "sends a body" do
|
419
423
|
response = client.put(local_server, body: "This is a put body")
|
420
|
-
JSON.load(response.body)["body"].
|
424
|
+
expect(JSON.load(response.body)["body"]).to eq "This is a put body"
|
421
425
|
end
|
422
426
|
|
423
|
-
it "
|
427
|
+
it "sends params" do
|
424
428
|
response = client.put(local_server, params: {key: "value"})
|
425
|
-
JSON.load(response.body)["body"].
|
429
|
+
expect(JSON.load(response.body)["body"]).to eq "key=value"
|
426
430
|
end
|
427
431
|
end
|
428
432
|
|
429
433
|
describe "#head" do
|
430
|
-
it "
|
434
|
+
it "works" do
|
431
435
|
response = client.head(local_server)
|
432
|
-
JSON.load(response.body).
|
436
|
+
expect(JSON.load(response.body)).to be_nil
|
433
437
|
end
|
434
438
|
end
|
435
439
|
|
436
440
|
describe "#options" do
|
437
|
-
it "
|
441
|
+
it "works" do
|
438
442
|
response = client.options(local_server)
|
439
|
-
JSON.load(response.body)["method"].
|
443
|
+
expect(JSON.load(response.body)["method"]).to eq "OPTIONS"
|
440
444
|
end
|
441
445
|
end
|
442
446
|
|
443
447
|
describe "#patch" do
|
444
|
-
it "
|
448
|
+
it "works" do
|
445
449
|
response = client.patch(local_server)
|
446
|
-
JSON.load(response.body)["method"].
|
450
|
+
expect(JSON.load(response.body)["method"]).to eq "PATCH"
|
447
451
|
end
|
448
452
|
|
449
|
-
it "
|
453
|
+
it "sends a body" do
|
450
454
|
response = client.patch(local_server, body: "This is a patch body")
|
451
|
-
JSON.load(response.body)["body"].
|
455
|
+
expect(JSON.load(response.body)["body"]).to eq "This is a patch body"
|
452
456
|
end
|
453
457
|
|
454
|
-
it "
|
458
|
+
it "sends params" do
|
455
459
|
response = client.patch(local_server, params: {key: "value"})
|
456
|
-
JSON.load(response.body)["body"].
|
460
|
+
expect(JSON.load(response.body)["body"]).to eq "key=value"
|
457
461
|
end
|
458
462
|
end
|
459
463
|
|
460
464
|
describe "#execute!" do
|
461
|
-
it "
|
465
|
+
it "performs multiple concurrent requests" do
|
462
466
|
futures = [55441, 55442].map do |port|
|
463
467
|
client.async.get("http://localhost:#{port}/?sleep=1").
|
464
468
|
on_success do |response|
|
@@ -468,72 +472,72 @@ describe Manticore::Client do
|
|
468
472
|
|
469
473
|
client.execute!
|
470
474
|
values = futures.map(&:callback_result)
|
471
|
-
(values[0] - values[1]).abs.
|
475
|
+
expect((values[0] - values[1]).abs).to be < 0.25
|
472
476
|
end
|
473
477
|
|
474
|
-
it "
|
478
|
+
it "returns the results of the handler blocks" do
|
475
479
|
[55441, 55442].each do |port|
|
476
480
|
client.async.get("http://localhost:#{port}/").
|
477
481
|
on_success {|response, request| "Result" }
|
478
482
|
end
|
479
483
|
|
480
|
-
client.execute!.map(&:callback_result).
|
484
|
+
expect(client.execute!.map(&:callback_result)).to eq ["Result", "Result"]
|
481
485
|
end
|
482
486
|
end
|
483
487
|
|
484
488
|
describe "#clear_pending" do
|
485
|
-
it "
|
489
|
+
it "removes pending requests" do
|
486
490
|
ran = false
|
487
491
|
client.async.get("http://google.com").on_success {|r| ran = true }
|
488
492
|
client.clear_pending
|
489
|
-
client.execute
|
490
|
-
ran.
|
493
|
+
expect(client.execute!).to be_empty
|
494
|
+
expect(ran).to be false
|
491
495
|
end
|
492
496
|
end
|
493
497
|
|
494
498
|
describe "#stub" do
|
495
|
-
it "
|
499
|
+
it "responds with a stubbed response until it is unstubbed" do
|
496
500
|
client.stub(local_server, body: "body", code: 200)
|
497
501
|
|
498
502
|
called = false
|
499
503
|
2.times {
|
500
504
|
client.get(local_server) do |response|
|
501
505
|
called = true
|
502
|
-
response.
|
503
|
-
response.body.
|
504
|
-
response.code.
|
506
|
+
expect(response).to be_a Manticore::StubbedResponse
|
507
|
+
expect(response.body).to eq "body"
|
508
|
+
expect(response.code).to eq 200
|
505
509
|
end
|
506
510
|
}
|
507
511
|
|
508
|
-
called.
|
512
|
+
expect(called).to be true
|
509
513
|
|
510
514
|
client.clear_stubs!
|
511
515
|
client.get(local_server) do |response|
|
512
|
-
response.
|
513
|
-
response.body.
|
514
|
-
response.code.
|
516
|
+
expect(response).to be_a Manticore::Response
|
517
|
+
expect(response.body).to match /Manticore/
|
518
|
+
expect(response.code).to eq 200
|
515
519
|
end
|
516
520
|
end
|
517
521
|
|
518
522
|
context 'stubbing' do
|
519
523
|
it "only the provided URLs" do
|
520
524
|
client.stub local_server, body: "body"
|
521
|
-
client.async.get(local_server).on_success {|r| r.
|
522
|
-
client.async.get(local_server("/other")).on_success {|r| r.
|
525
|
+
client.async.get(local_server).on_success {|r| expect(r).to be_a Manticore::StubbedResponse }
|
526
|
+
client.async.get(local_server("/other")).on_success {|r| expect(r).to_not be_a Manticore::StubbedResponse }
|
523
527
|
client.execute!
|
524
528
|
end
|
525
529
|
|
526
530
|
it "by regex matching" do
|
527
531
|
client.stub %r{#{local_server("/foo")}}, body: "body"
|
528
|
-
client.async.get(local_server("/foo")).on_success {|r| r.
|
529
|
-
client.async.get(local_server("/bar")).on_success {|r| r.
|
532
|
+
client.async.get(local_server("/foo")).on_success {|r| expect(r).to be_a Manticore::StubbedResponse }
|
533
|
+
client.async.get(local_server("/bar")).on_success {|r| expect(r).to_not be_a Manticore::StubbedResponse }
|
530
534
|
client.execute!
|
531
535
|
end
|
532
536
|
|
533
537
|
it "strictly matches string stubs" do
|
534
538
|
client.stub local_server("/foo"), body: "body"
|
535
|
-
client.async.get(local_server("/foo")).on_success {|r| r.
|
536
|
-
client.async.get(local_server("/other")).on_success {|r| r.
|
539
|
+
client.async.get(local_server("/foo")).on_success {|r| expect(r).to be_a Manticore::StubbedResponse }
|
540
|
+
client.async.get(local_server("/other")).on_success {|r| expect(r).to_not be_a Manticore::StubbedResponse }
|
537
541
|
client.execute!
|
538
542
|
end
|
539
543
|
|
@@ -559,17 +563,17 @@ describe Manticore::Client do
|
|
559
563
|
|
560
564
|
|
561
565
|
context "with keepalive" do
|
562
|
-
it "
|
566
|
+
it "adds the Connection: Keep-Alive header for http/1.0" do
|
563
567
|
expect( client.get(url).request["Connection"] ).to eq "Keep-Alive"
|
564
568
|
end
|
565
569
|
|
566
570
|
let(:client) { Manticore::Client.new keepalive: true, pool_max: 1 }
|
567
571
|
|
568
|
-
it "
|
572
|
+
it "keeps the connection open after a request" do
|
569
573
|
skip
|
570
574
|
response = client.get(url).call
|
571
575
|
get_connection(client, url) do |conn|
|
572
|
-
conn.is_open.
|
576
|
+
expect(conn.is_open).to be true
|
573
577
|
end
|
574
578
|
end
|
575
579
|
end
|
@@ -577,11 +581,11 @@ describe Manticore::Client do
|
|
577
581
|
context "without keepalive" do
|
578
582
|
let(:client) { Manticore::Client.new keepalive: false, pool_max: 1 }
|
579
583
|
|
580
|
-
it "
|
584
|
+
it "does not add the Connection: Keep-Alive header for http/1.0" do
|
581
585
|
expect( client.get(url).request["Connection"] ).to be_nil
|
582
586
|
end
|
583
587
|
|
584
|
-
it "
|
588
|
+
it "closes the connection after a request" do
|
585
589
|
skip
|
586
590
|
response = client.get(url).call
|
587
591
|
puts `netstat -apn`
|
@@ -613,7 +617,7 @@ describe Manticore::Client do
|
|
613
617
|
|
614
618
|
let(:client) { Manticore::Client.new keepalive: true, pool_max: 1 }
|
615
619
|
|
616
|
-
it "
|
620
|
+
it "retries 3 times by default" do
|
617
621
|
# The first time, reply with keepalive, then close the connection
|
618
622
|
# The second connection should succeed
|
619
623
|
|
@@ -622,14 +626,14 @@ describe Manticore::Client do
|
|
622
626
|
expect { request1.call }.to_not raise_exception
|
623
627
|
expect { request2.call }.to_not raise_exception
|
624
628
|
|
625
|
-
request1.times_retried.
|
626
|
-
request2.times_retried.
|
629
|
+
expect(request1.times_retried).to eq 0
|
630
|
+
expect(request2.times_retried).to eq 1
|
627
631
|
end
|
628
632
|
|
629
633
|
context "when the max retry is restrictive" do
|
630
634
|
let(:client) { Manticore::Client.new keepalive: true, pool_max: 1, automatic_retries: 0 }
|
631
635
|
|
632
|
-
it "
|
636
|
+
it "retries 0 times and fail on the second request" do
|
633
637
|
# The first time, reply with keepalive, then close the connection
|
634
638
|
# The second connection should succeed
|
635
639
|
expect { client.get("http://localhost:4567/").call }.to_not raise_exception
|
@@ -640,7 +644,7 @@ describe Manticore::Client do
|
|
640
644
|
context "when keepalive is off" do
|
641
645
|
let(:client) { Manticore::Client.new keepalive: false, pool_max: 1 }
|
642
646
|
|
643
|
-
it "
|
647
|
+
it "succeeds without any retries" do
|
644
648
|
# The first time, reply with keepalive, then close the connection
|
645
649
|
# The second connection should succeed
|
646
650
|
request1 = client.get("http://localhost:4567/")
|
@@ -648,8 +652,8 @@ describe Manticore::Client do
|
|
648
652
|
expect { request1.call }.to_not raise_exception
|
649
653
|
expect { request2.call }.to_not raise_exception
|
650
654
|
|
651
|
-
request1.times_retried.
|
652
|
-
request2.times_retried.
|
655
|
+
expect(request1.times_retried).to eq 0
|
656
|
+
expect(request2.times_retried).to eq 0
|
653
657
|
end
|
654
658
|
end
|
655
659
|
|
@@ -662,11 +666,11 @@ describe Manticore::Client do
|
|
662
666
|
describe "with connection timeouts" do
|
663
667
|
let(:client) { Manticore::Client.new request_timeout: 1, connect_timeout: 1, socket_timeout: 1 }
|
664
668
|
|
665
|
-
it "
|
669
|
+
it "times out" do
|
666
670
|
expect { client.get(local_server "/?sleep=2").body }.to raise_exception(Manticore::SocketTimeout)
|
667
671
|
end
|
668
672
|
|
669
|
-
it "
|
673
|
+
it "times out when custom request options are passed" do
|
670
674
|
expect { client.get(local_server("/?sleep=2"), max_redirects: 5).body }.to raise_exception(Manticore::SocketTimeout)
|
671
675
|
end
|
672
676
|
end
|