httparty 0.13.7 → 0.21.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.editorconfig +18 -0
- data/.github/workflows/ci.yml +26 -0
- data/.gitignore +3 -0
- data/.rubocop_todo.yml +1 -1
- data/{History → Changelog.md} +226 -59
- data/Gemfile +10 -3
- data/Guardfile +3 -2
- data/README.md +8 -7
- data/bin/httparty +3 -1
- data/docs/README.md +191 -0
- data/examples/README.md +34 -12
- data/examples/aaws.rb +7 -3
- data/examples/body_stream.rb +14 -0
- data/examples/crack.rb +1 -1
- data/examples/custom_parsers.rb +5 -1
- data/examples/delicious.rb +4 -4
- data/examples/headers_and_user_agents.rb +7 -3
- data/examples/idn.rb +10 -0
- data/examples/logging.rb +4 -4
- data/examples/microsoft_graph.rb +52 -0
- data/examples/multipart.rb +22 -0
- data/examples/peer_cert.rb +9 -0
- data/examples/stackexchange.rb +1 -1
- data/examples/stream_download.rb +26 -0
- data/examples/tripit_sign_in.rb +17 -6
- data/examples/twitter.rb +2 -2
- data/examples/whoismyrep.rb +1 -1
- data/httparty.gemspec +7 -5
- data/lib/httparty/connection_adapter.rb +86 -20
- data/lib/httparty/cookie_hash.rb +10 -8
- data/lib/httparty/decompressor.rb +102 -0
- data/lib/httparty/exceptions.rb +8 -2
- data/lib/httparty/hash_conversions.rb +30 -8
- data/lib/httparty/headers_processor.rb +32 -0
- data/lib/httparty/logger/apache_formatter.rb +31 -6
- data/lib/httparty/logger/curl_formatter.rb +68 -23
- data/lib/httparty/logger/logger.rb +5 -1
- data/lib/httparty/logger/logstash_formatter.rb +61 -0
- data/lib/httparty/module_inheritable_attributes.rb +6 -4
- data/lib/httparty/net_digest_auth.rb +23 -21
- data/lib/httparty/parser.rb +25 -14
- data/lib/httparty/request/body.rb +105 -0
- data/lib/httparty/request/multipart_boundary.rb +13 -0
- data/lib/httparty/request.rb +160 -106
- data/lib/httparty/response/headers.rb +23 -19
- data/lib/httparty/response.rb +92 -13
- data/lib/httparty/response_fragment.rb +21 -0
- data/lib/httparty/text_encoder.rb +72 -0
- data/lib/httparty/utils.rb +13 -0
- data/lib/httparty/version.rb +3 -1
- data/lib/httparty.rb +98 -35
- data/website/css/common.css +1 -1
- metadata +34 -114
- data/.simplecov +0 -1
- data/.travis.yml +0 -7
- data/features/basic_authentication.feature +0 -20
- data/features/command_line.feature +0 -95
- data/features/deals_with_http_error_codes.feature +0 -26
- data/features/digest_authentication.feature +0 -30
- data/features/handles_compressed_responses.feature +0 -27
- data/features/handles_multiple_formats.feature +0 -57
- data/features/steps/env.rb +0 -27
- data/features/steps/httparty_response_steps.rb +0 -52
- data/features/steps/httparty_steps.rb +0 -43
- data/features/steps/mongrel_helper.rb +0 -127
- data/features/steps/remote_service_steps.rb +0 -90
- data/features/supports_read_timeout_option.feature +0 -13
- data/features/supports_redirection.feature +0 -22
- data/features/supports_timeout_option.feature +0 -13
- data/spec/fixtures/delicious.xml +0 -23
- data/spec/fixtures/empty.xml +0 -0
- data/spec/fixtures/google.html +0 -3
- data/spec/fixtures/ssl/generate.sh +0 -29
- data/spec/fixtures/ssl/generated/1fe462c2.0 +0 -16
- data/spec/fixtures/ssl/generated/bogushost.crt +0 -13
- data/spec/fixtures/ssl/generated/ca.crt +0 -16
- data/spec/fixtures/ssl/generated/ca.key +0 -15
- data/spec/fixtures/ssl/generated/selfsigned.crt +0 -14
- data/spec/fixtures/ssl/generated/server.crt +0 -13
- data/spec/fixtures/ssl/generated/server.key +0 -15
- data/spec/fixtures/ssl/openssl-exts.cnf +0 -9
- data/spec/fixtures/twitter.csv +0 -2
- data/spec/fixtures/twitter.json +0 -1
- data/spec/fixtures/twitter.xml +0 -403
- data/spec/fixtures/undefined_method_add_node_for_nil.xml +0 -2
- data/spec/httparty/connection_adapter_spec.rb +0 -468
- data/spec/httparty/cookie_hash_spec.rb +0 -83
- data/spec/httparty/exception_spec.rb +0 -38
- data/spec/httparty/hash_conversions_spec.rb +0 -41
- data/spec/httparty/logger/apache_formatter_spec.rb +0 -41
- data/spec/httparty/logger/curl_formatter_spec.rb +0 -18
- data/spec/httparty/logger/logger_spec.rb +0 -38
- data/spec/httparty/net_digest_auth_spec.rb +0 -230
- data/spec/httparty/parser_spec.rb +0 -173
- data/spec/httparty/request_spec.rb +0 -1073
- data/spec/httparty/response_spec.rb +0 -241
- data/spec/httparty/ssl_spec.rb +0 -74
- data/spec/httparty_spec.rb +0 -850
- data/spec/spec_helper.rb +0 -59
- data/spec/support/ssl_test_helper.rb +0 -47
- data/spec/support/ssl_test_server.rb +0 -80
- data/spec/support/stub_response.rb +0 -49
@@ -1,468 +0,0 @@
|
|
1
|
-
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
2
|
-
|
3
|
-
RSpec.describe HTTParty::ConnectionAdapter do
|
4
|
-
describe "initialization" do
|
5
|
-
let(:uri) { URI 'http://www.google.com' }
|
6
|
-
it "takes a URI as input" do
|
7
|
-
HTTParty::ConnectionAdapter.new(uri)
|
8
|
-
end
|
9
|
-
|
10
|
-
it "raises an ArgumentError if the uri is nil" do
|
11
|
-
expect { HTTParty::ConnectionAdapter.new(nil) }.to raise_error ArgumentError
|
12
|
-
end
|
13
|
-
|
14
|
-
it "raises an ArgumentError if the uri is a String" do
|
15
|
-
expect { HTTParty::ConnectionAdapter.new('http://www.google.com') }.to raise_error ArgumentError
|
16
|
-
end
|
17
|
-
|
18
|
-
it "sets the uri" do
|
19
|
-
adapter = HTTParty::ConnectionAdapter.new(uri)
|
20
|
-
expect(adapter.uri).to be uri
|
21
|
-
end
|
22
|
-
|
23
|
-
it "also accepts an optional options hash" do
|
24
|
-
HTTParty::ConnectionAdapter.new(uri, {})
|
25
|
-
end
|
26
|
-
|
27
|
-
it "sets the options" do
|
28
|
-
options = {foo: :bar}
|
29
|
-
adapter = HTTParty::ConnectionAdapter.new(uri, options)
|
30
|
-
expect(adapter.options).to be options
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
describe ".call" do
|
35
|
-
it "generates an HTTParty::ConnectionAdapter instance with the given uri and options" do
|
36
|
-
expect(HTTParty::ConnectionAdapter).to receive(:new).with(@uri, @options).and_return(double(connection: nil))
|
37
|
-
HTTParty::ConnectionAdapter.call(@uri, @options)
|
38
|
-
end
|
39
|
-
|
40
|
-
it "calls #connection on the connection adapter" do
|
41
|
-
adapter = double('Adapter')
|
42
|
-
connection = double('Connection')
|
43
|
-
expect(adapter).to receive(:connection).and_return(connection)
|
44
|
-
allow(HTTParty::ConnectionAdapter).to receive_messages(new: adapter)
|
45
|
-
expect(HTTParty::ConnectionAdapter.call(@uri, @options)).to be connection
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
describe '#connection' do
|
50
|
-
let(:uri) { URI 'http://www.google.com' }
|
51
|
-
let(:options) { Hash.new }
|
52
|
-
let(:adapter) { HTTParty::ConnectionAdapter.new(uri, options) }
|
53
|
-
|
54
|
-
describe "the resulting connection" do
|
55
|
-
subject { adapter.connection }
|
56
|
-
it { is_expected.to be_an_instance_of Net::HTTP }
|
57
|
-
|
58
|
-
context "using port 80" do
|
59
|
-
let(:uri) { URI 'http://foobar.com' }
|
60
|
-
it { is_expected.not_to use_ssl }
|
61
|
-
end
|
62
|
-
|
63
|
-
context "when dealing with ssl" do
|
64
|
-
let(:uri) { URI 'https://foobar.com' }
|
65
|
-
|
66
|
-
context "uses the system cert_store, by default" do
|
67
|
-
let!(:system_cert_store) do
|
68
|
-
system_cert_store = double('default_cert_store')
|
69
|
-
expect(system_cert_store).to receive(:set_default_paths)
|
70
|
-
expect(OpenSSL::X509::Store).to receive(:new).and_return(system_cert_store)
|
71
|
-
system_cert_store
|
72
|
-
end
|
73
|
-
it { is_expected.to use_cert_store(system_cert_store) }
|
74
|
-
end
|
75
|
-
|
76
|
-
context "should use the specified cert store, when one is given" do
|
77
|
-
let(:custom_cert_store) { double('custom_cert_store') }
|
78
|
-
let(:options) { {cert_store: custom_cert_store} }
|
79
|
-
it { is_expected.to use_cert_store(custom_cert_store) }
|
80
|
-
end
|
81
|
-
|
82
|
-
context "using port 443 for ssl" do
|
83
|
-
let(:uri) { URI 'https://api.foo.com/v1:443' }
|
84
|
-
it { is_expected.to use_ssl }
|
85
|
-
end
|
86
|
-
|
87
|
-
context "https scheme with default port" do
|
88
|
-
it { is_expected.to use_ssl }
|
89
|
-
end
|
90
|
-
|
91
|
-
context "https scheme with non-standard port" do
|
92
|
-
let(:uri) { URI 'https://foobar.com:123456' }
|
93
|
-
it { is_expected.to use_ssl }
|
94
|
-
end
|
95
|
-
|
96
|
-
context "when ssl version is set" do
|
97
|
-
let(:options) { {ssl_version: :TLSv1} }
|
98
|
-
|
99
|
-
it "sets ssl version" do
|
100
|
-
expect(subject.ssl_version).to eq(:TLSv1)
|
101
|
-
end
|
102
|
-
end if RUBY_VERSION > '1.9'
|
103
|
-
end
|
104
|
-
|
105
|
-
context "when dealing with IPv6" do
|
106
|
-
let(:uri) { URI 'http://[fd00::1]' }
|
107
|
-
|
108
|
-
it "strips brackets from the address" do
|
109
|
-
expect(subject.address).to eq('fd00::1')
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
context "specifying ciphers" do
|
114
|
-
let(:options) { {ciphers: 'RC4-SHA' } }
|
115
|
-
|
116
|
-
it "should set the ciphers on the connection" do
|
117
|
-
expect(subject.ciphers).to eq('RC4-SHA')
|
118
|
-
end
|
119
|
-
end if RUBY_VERSION > '1.9'
|
120
|
-
|
121
|
-
context "when timeout is not set" do
|
122
|
-
it "doesn't set the timeout" do
|
123
|
-
http = double(
|
124
|
-
"http",
|
125
|
-
:null_object => true,
|
126
|
-
:use_ssl= => false,
|
127
|
-
:use_ssl? => false
|
128
|
-
)
|
129
|
-
expect(http).not_to receive(:open_timeout=)
|
130
|
-
expect(http).not_to receive(:read_timeout=)
|
131
|
-
allow(Net::HTTP).to receive_messages(new: http)
|
132
|
-
|
133
|
-
adapter.connection
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
context "when setting timeout" do
|
138
|
-
context "to 5 seconds" do
|
139
|
-
let(:options) { {timeout: 5} }
|
140
|
-
|
141
|
-
describe '#open_timeout' do
|
142
|
-
subject { super().open_timeout }
|
143
|
-
it { is_expected.to eq(5) }
|
144
|
-
end
|
145
|
-
|
146
|
-
describe '#read_timeout' do
|
147
|
-
subject { super().read_timeout }
|
148
|
-
it { is_expected.to eq(5) }
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
context "and timeout is a string" do
|
153
|
-
let(:options) { {timeout: "five seconds"} }
|
154
|
-
|
155
|
-
it "doesn't set the timeout" do
|
156
|
-
http = double(
|
157
|
-
"http",
|
158
|
-
:null_object => true,
|
159
|
-
:use_ssl= => false,
|
160
|
-
:use_ssl? => false
|
161
|
-
)
|
162
|
-
expect(http).not_to receive(:open_timeout=)
|
163
|
-
expect(http).not_to receive(:read_timeout=)
|
164
|
-
allow(Net::HTTP).to receive_messages(new: http)
|
165
|
-
|
166
|
-
adapter.connection
|
167
|
-
end
|
168
|
-
end
|
169
|
-
end
|
170
|
-
|
171
|
-
context "when timeout is not set and read_timeout is set to 6 seconds" do
|
172
|
-
let(:options) { {read_timeout: 6} }
|
173
|
-
|
174
|
-
describe '#read_timeout' do
|
175
|
-
subject { super().read_timeout }
|
176
|
-
it { is_expected.to eq(6) }
|
177
|
-
end
|
178
|
-
|
179
|
-
it "should not set the open_timeout" do
|
180
|
-
http = double(
|
181
|
-
"http",
|
182
|
-
:null_object => true,
|
183
|
-
:use_ssl= => false,
|
184
|
-
:use_ssl? => false,
|
185
|
-
:read_timeout= => 0
|
186
|
-
)
|
187
|
-
expect(http).not_to receive(:open_timeout=)
|
188
|
-
allow(Net::HTTP).to receive_messages(new: http)
|
189
|
-
adapter.connection
|
190
|
-
end
|
191
|
-
end
|
192
|
-
|
193
|
-
context "when timeout is set and read_timeout is set to 6 seconds" do
|
194
|
-
let(:options) { {timeout: 5, read_timeout: 6} }
|
195
|
-
|
196
|
-
describe '#open_timeout' do
|
197
|
-
subject { super().open_timeout }
|
198
|
-
it { is_expected.to eq(5) }
|
199
|
-
end
|
200
|
-
|
201
|
-
describe '#read_timeout' do
|
202
|
-
subject { super().read_timeout }
|
203
|
-
it { is_expected.to eq(6) }
|
204
|
-
end
|
205
|
-
|
206
|
-
it "should override the timeout option" do
|
207
|
-
http = double(
|
208
|
-
"http",
|
209
|
-
:null_object => true,
|
210
|
-
:use_ssl= => false,
|
211
|
-
:use_ssl? => false,
|
212
|
-
:read_timeout= => 0,
|
213
|
-
:open_timeout= => 0
|
214
|
-
)
|
215
|
-
expect(http).to receive(:open_timeout=)
|
216
|
-
expect(http).to receive(:read_timeout=).twice
|
217
|
-
allow(Net::HTTP).to receive_messages(new: http)
|
218
|
-
adapter.connection
|
219
|
-
end
|
220
|
-
end
|
221
|
-
|
222
|
-
context "when timeout is not set and open_timeout is set to 7 seconds" do
|
223
|
-
let(:options) { {open_timeout: 7} }
|
224
|
-
|
225
|
-
describe '#open_timeout' do
|
226
|
-
subject { super().open_timeout }
|
227
|
-
it { is_expected.to eq(7) }
|
228
|
-
end
|
229
|
-
|
230
|
-
it "should not set the read_timeout" do
|
231
|
-
http = double(
|
232
|
-
"http",
|
233
|
-
:null_object => true,
|
234
|
-
:use_ssl= => false,
|
235
|
-
:use_ssl? => false,
|
236
|
-
:open_timeout= => 0
|
237
|
-
)
|
238
|
-
expect(http).not_to receive(:read_timeout=)
|
239
|
-
allow(Net::HTTP).to receive_messages(new: http)
|
240
|
-
adapter.connection
|
241
|
-
end
|
242
|
-
end
|
243
|
-
|
244
|
-
context "when timeout is set and open_timeout is set to 7 seconds" do
|
245
|
-
let(:options) { {timeout: 5, open_timeout: 7} }
|
246
|
-
|
247
|
-
describe '#open_timeout' do
|
248
|
-
subject { super().open_timeout }
|
249
|
-
it { is_expected.to eq(7) }
|
250
|
-
end
|
251
|
-
|
252
|
-
describe '#read_timeout' do
|
253
|
-
subject { super().read_timeout }
|
254
|
-
it { is_expected.to eq(5) }
|
255
|
-
end
|
256
|
-
|
257
|
-
it "should override the timeout option" do
|
258
|
-
http = double(
|
259
|
-
"http",
|
260
|
-
:null_object => true,
|
261
|
-
:use_ssl= => false,
|
262
|
-
:use_ssl? => false,
|
263
|
-
:read_timeout= => 0,
|
264
|
-
:open_timeout= => 0
|
265
|
-
)
|
266
|
-
expect(http).to receive(:open_timeout=).twice
|
267
|
-
expect(http).to receive(:read_timeout=)
|
268
|
-
allow(Net::HTTP).to receive_messages(new: http)
|
269
|
-
adapter.connection
|
270
|
-
end
|
271
|
-
end
|
272
|
-
|
273
|
-
context "when debug_output" do
|
274
|
-
let(:http) { Net::HTTP.new(uri) }
|
275
|
-
before do
|
276
|
-
allow(Net::HTTP).to receive_messages(new: http)
|
277
|
-
end
|
278
|
-
|
279
|
-
context "is set to $stderr" do
|
280
|
-
let(:options) { {debug_output: $stderr} }
|
281
|
-
it "has debug output set" do
|
282
|
-
expect(http).to receive(:set_debug_output).with($stderr)
|
283
|
-
adapter.connection
|
284
|
-
end
|
285
|
-
end
|
286
|
-
|
287
|
-
context "is not provided" do
|
288
|
-
it "does not set_debug_output" do
|
289
|
-
expect(http).not_to receive(:set_debug_output)
|
290
|
-
adapter.connection
|
291
|
-
end
|
292
|
-
end
|
293
|
-
end
|
294
|
-
|
295
|
-
context 'when providing proxy address and port' do
|
296
|
-
let(:options) { {http_proxyaddr: '1.2.3.4', http_proxyport: 8080} }
|
297
|
-
|
298
|
-
it { is_expected.to be_a_proxy }
|
299
|
-
|
300
|
-
describe '#proxy_address' do
|
301
|
-
subject { super().proxy_address }
|
302
|
-
it { is_expected.to eq('1.2.3.4') }
|
303
|
-
end
|
304
|
-
|
305
|
-
describe '#proxy_port' do
|
306
|
-
subject { super().proxy_port }
|
307
|
-
it { is_expected.to eq(8080) }
|
308
|
-
end
|
309
|
-
|
310
|
-
context 'as well as proxy user and password' do
|
311
|
-
let(:options) do
|
312
|
-
{http_proxyaddr: '1.2.3.4', http_proxyport: 8080,
|
313
|
-
http_proxyuser: 'user', http_proxypass: 'pass'}
|
314
|
-
end
|
315
|
-
|
316
|
-
describe '#proxy_user' do
|
317
|
-
subject { super().proxy_user }
|
318
|
-
it { is_expected.to eq('user') }
|
319
|
-
end
|
320
|
-
|
321
|
-
describe '#proxy_pass' do
|
322
|
-
subject { super().proxy_pass }
|
323
|
-
it { is_expected.to eq('pass') }
|
324
|
-
end
|
325
|
-
end
|
326
|
-
end
|
327
|
-
|
328
|
-
context 'when not providing a proxy address' do
|
329
|
-
let(:uri) { URI 'http://proxytest.com' }
|
330
|
-
|
331
|
-
it "does not pass any proxy parameters to the connection" do
|
332
|
-
http = Net::HTTP.new("proxytest.com")
|
333
|
-
expect(Net::HTTP).to receive(:new).once.with("proxytest.com", 80).and_return(http)
|
334
|
-
adapter.connection
|
335
|
-
end
|
336
|
-
end
|
337
|
-
|
338
|
-
context 'when providing a local bind address and port' do
|
339
|
-
let(:options) { {local_host: "127.0.0.1", local_port: 12345 } }
|
340
|
-
|
341
|
-
describe '#local_host' do
|
342
|
-
subject { super().local_host }
|
343
|
-
it { is_expected.to eq('127.0.0.1') }
|
344
|
-
end
|
345
|
-
|
346
|
-
describe '#local_port' do
|
347
|
-
subject { super().local_port }
|
348
|
-
it { is_expected.to eq(12345) }
|
349
|
-
end
|
350
|
-
end if RUBY_VERSION >= '2.0'
|
351
|
-
|
352
|
-
context "when providing PEM certificates" do
|
353
|
-
let(:pem) { :pem_contents }
|
354
|
-
let(:options) { {pem: pem, pem_password: "password"} }
|
355
|
-
|
356
|
-
context "when scheme is https" do
|
357
|
-
let(:uri) { URI 'https://google.com' }
|
358
|
-
let(:cert) { double("OpenSSL::X509::Certificate") }
|
359
|
-
let(:key) { double("OpenSSL::PKey::RSA") }
|
360
|
-
|
361
|
-
before do
|
362
|
-
expect(OpenSSL::X509::Certificate).to receive(:new).with(pem).and_return(cert)
|
363
|
-
expect(OpenSSL::PKey::RSA).to receive(:new).with(pem, "password").and_return(key)
|
364
|
-
end
|
365
|
-
|
366
|
-
it "uses the provided PEM certificate" do
|
367
|
-
expect(subject.cert).to eq(cert)
|
368
|
-
expect(subject.key).to eq(key)
|
369
|
-
end
|
370
|
-
|
371
|
-
it "will verify the certificate" do
|
372
|
-
expect(subject.verify_mode).to eq(OpenSSL::SSL::VERIFY_PEER)
|
373
|
-
end
|
374
|
-
|
375
|
-
context "when options include verify_peer=false" do
|
376
|
-
let(:options) { {pem: pem, pem_password: "password", verify_peer: false} }
|
377
|
-
|
378
|
-
it "should not verify the certificate" do
|
379
|
-
expect(subject.verify_mode).to eq(OpenSSL::SSL::VERIFY_NONE)
|
380
|
-
end
|
381
|
-
end
|
382
|
-
end
|
383
|
-
|
384
|
-
context "when scheme is not https" do
|
385
|
-
let(:uri) { URI 'http://google.com' }
|
386
|
-
let(:http) { Net::HTTP.new(uri) }
|
387
|
-
|
388
|
-
before do
|
389
|
-
allow(Net::HTTP).to receive_messages(new: http)
|
390
|
-
expect(OpenSSL::X509::Certificate).not_to receive(:new).with(pem)
|
391
|
-
expect(OpenSSL::PKey::RSA).not_to receive(:new).with(pem, "password")
|
392
|
-
expect(http).not_to receive(:cert=)
|
393
|
-
expect(http).not_to receive(:key=)
|
394
|
-
end
|
395
|
-
|
396
|
-
it "has no PEM certificate " do
|
397
|
-
expect(subject.cert).to be_nil
|
398
|
-
expect(subject.key).to be_nil
|
399
|
-
end
|
400
|
-
end
|
401
|
-
end
|
402
|
-
|
403
|
-
context "when providing PKCS12 certificates" do
|
404
|
-
let(:p12) { :p12_contents }
|
405
|
-
let(:options) { {p12: p12, p12_password: "password"} }
|
406
|
-
|
407
|
-
context "when scheme is https" do
|
408
|
-
let(:uri) { URI 'https://google.com' }
|
409
|
-
let(:pkcs12) { double("OpenSSL::PKCS12", certificate: cert, key: key) }
|
410
|
-
let(:cert) { double("OpenSSL::X509::Certificate") }
|
411
|
-
let(:key) { double("OpenSSL::PKey::RSA") }
|
412
|
-
|
413
|
-
before do
|
414
|
-
expect(OpenSSL::PKCS12).to receive(:new).with(p12, "password").and_return(pkcs12)
|
415
|
-
end
|
416
|
-
|
417
|
-
it "uses the provided P12 certificate " do
|
418
|
-
expect(subject.cert).to eq(cert)
|
419
|
-
expect(subject.key).to eq(key)
|
420
|
-
end
|
421
|
-
|
422
|
-
it "will verify the certificate" do
|
423
|
-
expect(subject.verify_mode).to eq(OpenSSL::SSL::VERIFY_PEER)
|
424
|
-
end
|
425
|
-
|
426
|
-
context "when options include verify_peer=false" do
|
427
|
-
let(:options) { {p12: p12, p12_password: "password", verify_peer: false} }
|
428
|
-
|
429
|
-
it "should not verify the certificate" do
|
430
|
-
expect(subject.verify_mode).to eq(OpenSSL::SSL::VERIFY_NONE)
|
431
|
-
end
|
432
|
-
end
|
433
|
-
end
|
434
|
-
|
435
|
-
context "when scheme is not https" do
|
436
|
-
let(:uri) { URI 'http://google.com' }
|
437
|
-
let(:http) { Net::HTTP.new(uri) }
|
438
|
-
|
439
|
-
before do
|
440
|
-
allow(Net::HTTP).to receive_messages(new: http)
|
441
|
-
expect(OpenSSL::PKCS12).not_to receive(:new).with(p12, "password")
|
442
|
-
expect(http).not_to receive(:cert=)
|
443
|
-
expect(http).not_to receive(:key=)
|
444
|
-
end
|
445
|
-
|
446
|
-
it "has no PKCS12 certificate " do
|
447
|
-
expect(subject.cert).to be_nil
|
448
|
-
expect(subject.key).to be_nil
|
449
|
-
end
|
450
|
-
end
|
451
|
-
end
|
452
|
-
|
453
|
-
context "when uri port is not defined" do
|
454
|
-
context "falls back to 80 port on http" do
|
455
|
-
let(:uri) { URI 'http://foobar.com' }
|
456
|
-
before { allow(uri).to receive(:port).and_return(nil) }
|
457
|
-
it { expect(subject.port).to be 80 }
|
458
|
-
end
|
459
|
-
|
460
|
-
context "falls back to 443 port on https" do
|
461
|
-
let(:uri) { URI 'https://foobar.com' }
|
462
|
-
before { allow(uri).to receive(:port).and_return(nil) }
|
463
|
-
it { expect(subject.port).to be 443 }
|
464
|
-
end
|
465
|
-
end
|
466
|
-
end
|
467
|
-
end
|
468
|
-
end
|
@@ -1,83 +0,0 @@
|
|
1
|
-
require File.expand_path(File.join(File.dirname(__FILE__), '../spec_helper'))
|
2
|
-
|
3
|
-
RSpec.describe HTTParty::CookieHash do
|
4
|
-
before(:each) do
|
5
|
-
@cookie_hash = HTTParty::CookieHash.new
|
6
|
-
end
|
7
|
-
|
8
|
-
describe "#add_cookies" do
|
9
|
-
describe "with a hash" do
|
10
|
-
it "should add new key/value pairs to the hash" do
|
11
|
-
@cookie_hash.add_cookies(foo: "bar")
|
12
|
-
@cookie_hash.add_cookies(rofl: "copter")
|
13
|
-
expect(@cookie_hash.length).to eql(2)
|
14
|
-
end
|
15
|
-
|
16
|
-
it "should overwrite any existing key" do
|
17
|
-
@cookie_hash.add_cookies(foo: "bar")
|
18
|
-
@cookie_hash.add_cookies(foo: "copter")
|
19
|
-
expect(@cookie_hash.length).to eql(1)
|
20
|
-
expect(@cookie_hash[:foo]).to eql("copter")
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
describe "with a string" do
|
25
|
-
it "should add new key/value pairs to the hash" do
|
26
|
-
@cookie_hash.add_cookies("first=one; second=two; third")
|
27
|
-
expect(@cookie_hash[:first]).to eq('one')
|
28
|
-
expect(@cookie_hash[:second]).to eq('two')
|
29
|
-
expect(@cookie_hash[:third]).to eq(nil)
|
30
|
-
end
|
31
|
-
|
32
|
-
it "should overwrite any existing key" do
|
33
|
-
@cookie_hash[:foo] = 'bar'
|
34
|
-
@cookie_hash.add_cookies("foo=tar")
|
35
|
-
expect(@cookie_hash.length).to eql(1)
|
36
|
-
expect(@cookie_hash[:foo]).to eql("tar")
|
37
|
-
end
|
38
|
-
|
39
|
-
it "should handle '=' within cookie value" do
|
40
|
-
@cookie_hash.add_cookies("first=one=1; second=two=2==")
|
41
|
-
expect(@cookie_hash.keys).to include(:first, :second)
|
42
|
-
expect(@cookie_hash[:first]).to eq('one=1')
|
43
|
-
expect(@cookie_hash[:second]).to eq('two=2==')
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
describe 'with other class' do
|
48
|
-
it "should error" do
|
49
|
-
expect {
|
50
|
-
@cookie_hash.add_cookies([])
|
51
|
-
}.to raise_error
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
# The regexen are required because Hashes aren't ordered, so a test against
|
57
|
-
# a hardcoded string was randomly failing.
|
58
|
-
describe "#to_cookie_string" do
|
59
|
-
before(:each) do
|
60
|
-
@cookie_hash.add_cookies(foo: "bar")
|
61
|
-
@cookie_hash.add_cookies(rofl: "copter")
|
62
|
-
@s = @cookie_hash.to_cookie_string
|
63
|
-
end
|
64
|
-
|
65
|
-
it "should format the key/value pairs, delimited by semi-colons" do
|
66
|
-
expect(@s).to match(/foo=bar/)
|
67
|
-
expect(@s).to match(/rofl=copter/)
|
68
|
-
expect(@s).to match(/^\w+=\w+; \w+=\w+$/)
|
69
|
-
end
|
70
|
-
|
71
|
-
it "should not include client side only cookies" do
|
72
|
-
@cookie_hash.add_cookies(path: "/")
|
73
|
-
@s = @cookie_hash.to_cookie_string
|
74
|
-
expect(@s).not_to match(/path=\//)
|
75
|
-
end
|
76
|
-
|
77
|
-
it "should not include client side only cookies even when attributes use camal case" do
|
78
|
-
@cookie_hash.add_cookies(Path: "/")
|
79
|
-
@s = @cookie_hash.to_cookie_string
|
80
|
-
expect(@s).not_to match(/Path=\//)
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
2
|
-
|
3
|
-
RSpec.describe HTTParty::Error do
|
4
|
-
subject { described_class }
|
5
|
-
|
6
|
-
describe '#ancestors' do
|
7
|
-
subject { super().ancestors }
|
8
|
-
it { is_expected.to include(StandardError) }
|
9
|
-
end
|
10
|
-
|
11
|
-
describe HTTParty::UnsupportedFormat do
|
12
|
-
describe '#ancestors' do
|
13
|
-
subject { super().ancestors }
|
14
|
-
it { is_expected.to include(HTTParty::Error) }
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
describe HTTParty::UnsupportedURIScheme do
|
19
|
-
describe '#ancestors' do
|
20
|
-
subject { super().ancestors }
|
21
|
-
it { is_expected.to include(HTTParty::Error) }
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
describe HTTParty::ResponseError do
|
26
|
-
describe '#ancestors' do
|
27
|
-
subject { super().ancestors }
|
28
|
-
it { is_expected.to include(HTTParty::Error) }
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
describe HTTParty::RedirectionTooDeep do
|
33
|
-
describe '#ancestors' do
|
34
|
-
subject { super().ancestors }
|
35
|
-
it { is_expected.to include(HTTParty::ResponseError) }
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
RSpec.describe HTTParty::HashConversions do
|
2
|
-
describe ".to_params" do
|
3
|
-
it "creates a params string from a hash" do
|
4
|
-
hash = {
|
5
|
-
name: "bob",
|
6
|
-
address: {
|
7
|
-
street: '111 ruby ave.',
|
8
|
-
city: 'ruby central',
|
9
|
-
phones: ['111-111-1111', '222-222-2222']
|
10
|
-
}
|
11
|
-
}
|
12
|
-
expect(HTTParty::HashConversions.to_params(hash)).to eq("name=bob&address[street]=111%20ruby%20ave.&address[city]=ruby%20central&address[phones][]=111-111-1111&address[phones][]=222-222-2222")
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
describe ".normalize_param" do
|
17
|
-
context "value is an array" do
|
18
|
-
it "creates a params string" do
|
19
|
-
expect(
|
20
|
-
HTTParty::HashConversions.normalize_param(:people, ["Bob Jones", "Mike Smith"])
|
21
|
-
).to eq("people[]=Bob%20Jones&people[]=Mike%20Smith&")
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
context "value is hash" do
|
26
|
-
it "creates a params string" do
|
27
|
-
expect(
|
28
|
-
HTTParty::HashConversions.normalize_param(:person, { name: "Bob Jones" })
|
29
|
-
).to eq("person[name]=Bob%20Jones&")
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
context "value is a string" do
|
34
|
-
it "creates a params string" do
|
35
|
-
expect(
|
36
|
-
HTTParty::HashConversions.normalize_param(:name, "Bob Jones")
|
37
|
-
).to eq("name=Bob%20Jones&")
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'spec_helper'))
|
2
|
-
|
3
|
-
RSpec.describe HTTParty::Logger::ApacheFormatter do
|
4
|
-
let(:subject) { described_class.new(logger_double, :info) }
|
5
|
-
let(:logger_double) { double('Logger') }
|
6
|
-
let(:request_double) { double('Request', http_method: Net::HTTP::Get, path: "http://my.domain.com/my_path") }
|
7
|
-
let(:request_time) { Time.new.strftime("%Y-%m-%d %H:%M:%S %z") }
|
8
|
-
|
9
|
-
before do
|
10
|
-
subject.current_time = request_time
|
11
|
-
expect(logger_double).to receive(:info).with(log_message)
|
12
|
-
end
|
13
|
-
|
14
|
-
describe "#format" do
|
15
|
-
let(:log_message) { "[HTTParty] [#{request_time}] 302 \"GET http://my.domain.com/my_path\" - " }
|
16
|
-
|
17
|
-
it "formats a response in a style that resembles apache's access log" do
|
18
|
-
response_double = double(
|
19
|
-
code: 302,
|
20
|
-
:[] => nil
|
21
|
-
)
|
22
|
-
|
23
|
-
subject.format(request_double, response_double)
|
24
|
-
end
|
25
|
-
|
26
|
-
context 'when there is a parsed response' do
|
27
|
-
let(:log_message) { "[HTTParty] [#{request_time}] 200 \"GET http://my.domain.com/my_path\" 512 "}
|
28
|
-
|
29
|
-
it "can handle the Content-Length header" do
|
30
|
-
# Simulate a parsed response that is an array, where accessing a string key will raise an error. See Issue #299.
|
31
|
-
response_double = double(
|
32
|
-
code: 200,
|
33
|
-
headers: { 'Content-Length' => 512 }
|
34
|
-
)
|
35
|
-
allow(response_double).to receive(:[]).with('Content-Length').and_raise(TypeError.new('no implicit conversion of String into Integer'))
|
36
|
-
|
37
|
-
subject.format(request_double, response_double)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'spec_helper'))
|
2
|
-
|
3
|
-
RSpec.describe HTTParty::Logger::CurlFormatter do
|
4
|
-
describe "#format" do
|
5
|
-
it "formats a response in a style that resembles a -v curl" do
|
6
|
-
logger_double = double
|
7
|
-
expect(logger_double).to receive(:info).with(
|
8
|
-
/\[HTTParty\] \[\d{4}-\d\d-\d\d \d\d:\d\d:\d\d\ [+-]\d{4}\] > GET http:\/\/localhost/)
|
9
|
-
|
10
|
-
subject = described_class.new(logger_double, :info)
|
11
|
-
|
12
|
-
stub_http_response_with("google.html")
|
13
|
-
|
14
|
-
response = HTTParty::Request.new.perform
|
15
|
-
subject.format(response.request, response)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|