httparty 0.13.0 → 0.21.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. checksums.yaml +5 -5
  2. data/.editorconfig +18 -0
  3. data/.github/workflows/ci.yml +26 -0
  4. data/.gitignore +4 -0
  5. data/.rubocop.yml +92 -0
  6. data/.rubocop_todo.yml +124 -0
  7. data/CONTRIBUTING.md +23 -0
  8. data/Changelog.md +557 -0
  9. data/Gemfile +15 -3
  10. data/Guardfile +4 -3
  11. data/README.md +24 -25
  12. data/Rakefile +5 -7
  13. data/bin/httparty +20 -14
  14. data/docs/README.md +191 -0
  15. data/examples/README.md +89 -0
  16. data/examples/aaws.rb +10 -6
  17. data/examples/basic.rb +6 -10
  18. data/examples/body_stream.rb +14 -0
  19. data/examples/crack.rb +2 -2
  20. data/examples/custom_parsers.rb +6 -5
  21. data/examples/delicious.rb +8 -8
  22. data/examples/google.rb +2 -2
  23. data/examples/headers_and_user_agents.rb +7 -3
  24. data/examples/idn.rb +10 -0
  25. data/examples/logging.rb +36 -0
  26. data/examples/microsoft_graph.rb +52 -0
  27. data/examples/multipart.rb +22 -0
  28. data/examples/nokogiri_html_parser.rb +0 -3
  29. data/examples/peer_cert.rb +9 -0
  30. data/examples/rescue_json.rb +17 -0
  31. data/examples/rubyurl.rb +3 -3
  32. data/examples/stackexchange.rb +24 -0
  33. data/examples/stream_download.rb +26 -0
  34. data/examples/tripit_sign_in.rb +20 -9
  35. data/examples/twitter.rb +7 -7
  36. data/examples/whoismyrep.rb +1 -1
  37. data/httparty.gemspec +13 -9
  38. data/lib/httparty/connection_adapter.rb +105 -25
  39. data/lib/httparty/cookie_hash.rb +10 -9
  40. data/lib/httparty/decompressor.rb +102 -0
  41. data/lib/httparty/exceptions.rb +8 -2
  42. data/lib/httparty/hash_conversions.rb +39 -19
  43. data/lib/httparty/headers_processor.rb +32 -0
  44. data/lib/httparty/logger/apache_formatter.rb +47 -0
  45. data/lib/httparty/logger/curl_formatter.rb +93 -0
  46. data/lib/httparty/logger/logger.rb +22 -10
  47. data/lib/httparty/logger/logstash_formatter.rb +61 -0
  48. data/lib/httparty/module_inheritable_attributes.rb +6 -4
  49. data/lib/httparty/net_digest_auth.rb +76 -25
  50. data/lib/httparty/parser.rb +28 -15
  51. data/lib/httparty/request/body.rb +105 -0
  52. data/lib/httparty/request/multipart_boundary.rb +13 -0
  53. data/lib/httparty/request.rb +218 -130
  54. data/lib/httparty/response/headers.rb +23 -19
  55. data/lib/httparty/response.rb +99 -15
  56. data/lib/httparty/response_fragment.rb +21 -0
  57. data/lib/httparty/text_encoder.rb +72 -0
  58. data/lib/httparty/utils.rb +13 -0
  59. data/lib/httparty/version.rb +3 -1
  60. data/lib/httparty.rb +191 -83
  61. data/website/css/common.css +1 -1
  62. data/website/index.html +3 -3
  63. metadata +50 -120
  64. data/.travis.yml +0 -7
  65. data/History +0 -303
  66. data/features/basic_authentication.feature +0 -20
  67. data/features/command_line.feature +0 -7
  68. data/features/deals_with_http_error_codes.feature +0 -26
  69. data/features/digest_authentication.feature +0 -20
  70. data/features/handles_compressed_responses.feature +0 -27
  71. data/features/handles_multiple_formats.feature +0 -57
  72. data/features/steps/env.rb +0 -22
  73. data/features/steps/httparty_response_steps.rb +0 -52
  74. data/features/steps/httparty_steps.rb +0 -35
  75. data/features/steps/mongrel_helper.rb +0 -94
  76. data/features/steps/remote_service_steps.rb +0 -74
  77. data/features/supports_redirection.feature +0 -22
  78. data/features/supports_timeout_option.feature +0 -13
  79. data/lib/httparty/core_extensions.rb +0 -32
  80. data/lib/httparty/logger/apache_logger.rb +0 -22
  81. data/lib/httparty/logger/curl_logger.rb +0 -48
  82. data/spec/fixtures/delicious.xml +0 -23
  83. data/spec/fixtures/empty.xml +0 -0
  84. data/spec/fixtures/google.html +0 -3
  85. data/spec/fixtures/ssl/generate.sh +0 -29
  86. data/spec/fixtures/ssl/generated/1fe462c2.0 +0 -16
  87. data/spec/fixtures/ssl/generated/bogushost.crt +0 -13
  88. data/spec/fixtures/ssl/generated/ca.crt +0 -16
  89. data/spec/fixtures/ssl/generated/ca.key +0 -15
  90. data/spec/fixtures/ssl/generated/selfsigned.crt +0 -14
  91. data/spec/fixtures/ssl/generated/server.crt +0 -13
  92. data/spec/fixtures/ssl/generated/server.key +0 -15
  93. data/spec/fixtures/ssl/openssl-exts.cnf +0 -9
  94. data/spec/fixtures/twitter.csv +0 -2
  95. data/spec/fixtures/twitter.json +0 -1
  96. data/spec/fixtures/twitter.xml +0 -403
  97. data/spec/fixtures/undefined_method_add_node_for_nil.xml +0 -2
  98. data/spec/httparty/connection_adapter_spec.rb +0 -298
  99. data/spec/httparty/cookie_hash_spec.rb +0 -83
  100. data/spec/httparty/exception_spec.rb +0 -23
  101. data/spec/httparty/logger/apache_logger_spec.rb +0 -26
  102. data/spec/httparty/logger/curl_logger_spec.rb +0 -18
  103. data/spec/httparty/logger/logger_spec.rb +0 -22
  104. data/spec/httparty/net_digest_auth_spec.rb +0 -152
  105. data/spec/httparty/parser_spec.rb +0 -165
  106. data/spec/httparty/request_spec.rb +0 -631
  107. data/spec/httparty/response_spec.rb +0 -221
  108. data/spec/httparty/ssl_spec.rb +0 -74
  109. data/spec/httparty_spec.rb +0 -764
  110. data/spec/spec.opts +0 -2
  111. data/spec/spec_helper.rb +0 -37
  112. data/spec/support/ssl_test_helper.rb +0 -47
  113. data/spec/support/ssl_test_server.rb +0 -80
  114. data/spec/support/stub_response.rb +0 -43
@@ -1,298 +0,0 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
2
-
3
- describe HTTParty::ConnectionAdapter do
4
-
5
- describe "initialization" do
6
- let(:uri) { URI 'http://www.google.com' }
7
- it "takes a URI as input" do
8
- HTTParty::ConnectionAdapter.new(uri)
9
- end
10
-
11
- it "raises an ArgumentError if the uri is nil" do
12
- expect { HTTParty::ConnectionAdapter.new(nil) }.to raise_error ArgumentError
13
- end
14
-
15
- it "raises an ArgumentError if the uri is a String" do
16
- expect { HTTParty::ConnectionAdapter.new('http://www.google.com') }.to raise_error ArgumentError
17
- end
18
-
19
- it "sets the uri" do
20
- adapter = HTTParty::ConnectionAdapter.new(uri)
21
- adapter.uri.should be uri
22
- end
23
-
24
- it "also accepts an optional options hash" do
25
- HTTParty::ConnectionAdapter.new(uri, {})
26
- end
27
-
28
- it "sets the options" do
29
- options = {:foo => :bar}
30
- adapter = HTTParty::ConnectionAdapter.new(uri, options)
31
- adapter.options.should be options
32
- end
33
- end
34
-
35
- describe ".call" do
36
- it "generates an HTTParty::ConnectionAdapter instance with the given uri and options" do
37
- HTTParty::ConnectionAdapter.should_receive(:new).with(@uri, @options).and_return(stub(:connection => nil))
38
- HTTParty::ConnectionAdapter.call(@uri, @options)
39
- end
40
-
41
- it "calls #connection on the connection adapter" do
42
- adapter = mock('Adapter')
43
- connection = mock('Connection')
44
- adapter.should_receive(:connection).and_return(connection)
45
- HTTParty::ConnectionAdapter.stub(:new => adapter)
46
- HTTParty::ConnectionAdapter.call(@uri, @options).should be connection
47
- end
48
- end
49
-
50
- describe '#connection' do
51
- let(:uri) { URI 'http://www.google.com' }
52
- let(:options) { Hash.new }
53
- let(:adapter) { HTTParty::ConnectionAdapter.new(uri, options) }
54
-
55
- describe "the resulting connection" do
56
- subject { adapter.connection }
57
- it { should be_an_instance_of Net::HTTP }
58
-
59
- context "using port 80" do
60
- let(:uri) { URI 'http://foobar.com' }
61
- it { should_not use_ssl }
62
- end
63
-
64
- context "when dealing with ssl" do
65
- let(:uri) { URI 'https://foobar.com' }
66
-
67
- context "uses the system cert_store, by default" do
68
- let(:system_cert_store) do
69
- system_cert_store = mock('default_cert_store')
70
- system_cert_store.should_receive(:set_default_paths)
71
- OpenSSL::X509::Store.should_receive(:new).and_return(system_cert_store)
72
- system_cert_store
73
- end
74
- it { should use_cert_store(system_cert_store) }
75
- end
76
-
77
- context "should use the specified cert store, when one is given" do
78
- let(:custom_cert_store) { mock('custom_cert_store') }
79
- let(:options) { {:cert_store => custom_cert_store} }
80
- it { should use_cert_store(custom_cert_store) }
81
- end
82
-
83
- context "using port 443 for ssl" do
84
- let(:uri) { URI 'https://api.foo.com/v1:443' }
85
- it { should use_ssl }
86
- end
87
-
88
- context "https scheme with default port" do
89
- it { should use_ssl }
90
- end
91
-
92
- context "https scheme with non-standard port" do
93
- let(:uri) { URI 'https://foobar.com:123456' }
94
- it { should use_ssl }
95
- end
96
-
97
-
98
- context "when ssl version is set" do
99
- let(:options) { {:ssl_version => :TLSv1} }
100
-
101
- it "sets ssl version" do
102
- subject.ssl_version.should == :TLSv1
103
- end
104
- end if RUBY_VERSION > '1.9'
105
- end
106
-
107
- context "when dealing with IPv6" do
108
- let(:uri) { URI 'http://[fd00::1]' }
109
-
110
- it "strips brackets from the address" do
111
- subject.address.should == 'fd00::1'
112
- end
113
- end
114
-
115
- context "specifying ciphers" do
116
- let(:options) { {:ciphers => 'RC4-SHA' } }
117
-
118
- it "should set the ciphers on the connection" do
119
- subject.ciphers.should == 'RC4-SHA'
120
- end
121
- end if RUBY_VERSION > '1.9'
122
-
123
- context "when timeout is not set" do
124
- it "doesn't set the timeout" do
125
- http = mock("http", :null_object => true)
126
- http.should_not_receive(:open_timeout=)
127
- http.should_not_receive(:read_timeout=)
128
- Net::HTTP.stub(:new => http)
129
-
130
- adapter.connection
131
- end
132
- end
133
-
134
- context "when setting timeout" do
135
- context "to 5 seconds" do
136
- let(:options) { {:timeout => 5} }
137
-
138
- its(:open_timeout) { should == 5 }
139
- its(:read_timeout) { should == 5 }
140
- end
141
-
142
- context "and timeout is a string" do
143
- let(:options) { {:timeout => "five seconds"} }
144
-
145
- it "doesn't set the timeout" do
146
- http = mock("http", :null_object => true)
147
- http.should_not_receive(:open_timeout=)
148
- http.should_not_receive(:read_timeout=)
149
- Net::HTTP.stub(:new => http)
150
-
151
- adapter.connection
152
- end
153
- end
154
- end
155
-
156
- context "when debug_output" do
157
- let(:http) { Net::HTTP.new(uri) }
158
- before do
159
- Net::HTTP.stub(:new => http)
160
- end
161
-
162
- context "is set to $stderr" do
163
- let(:options) { {:debug_output => $stderr} }
164
- it "has debug output set" do
165
- http.should_receive(:set_debug_output).with($stderr)
166
- adapter.connection
167
- end
168
- end
169
-
170
- context "is not provided" do
171
- it "does not set_debug_output" do
172
- http.should_not_receive(:set_debug_output)
173
- adapter.connection
174
- end
175
- end
176
- end
177
-
178
- context 'when providing proxy address and port' do
179
- let(:options) { {:http_proxyaddr => '1.2.3.4', :http_proxyport => 8080} }
180
-
181
- it { should be_a_proxy }
182
- its(:proxy_address) { should == '1.2.3.4' }
183
- its(:proxy_port) { should == 8080 }
184
-
185
- context 'as well as proxy user and password' do
186
- let(:options) do
187
- {:http_proxyaddr => '1.2.3.4', :http_proxyport => 8080,
188
- :http_proxyuser => 'user', :http_proxypass => 'pass'}
189
- end
190
- its(:proxy_user) { should == 'user' }
191
- its(:proxy_pass) { should == 'pass' }
192
- end
193
- end
194
-
195
- context 'when not providing a proxy address' do
196
- let(:uri) { URI 'http://proxytest.com' }
197
-
198
- it "does not pass any proxy parameters to the connection" do
199
- http = Net::HTTP.new("proxytest.com")
200
- Net::HTTP.should_receive(:new).once.with("proxytest.com", 80).and_return(http)
201
- adapter.connection
202
- end
203
- end
204
-
205
- context 'when providing a local bind address and port' do
206
- let(:options) { {:local_host => "127.0.0.1", :local_port => 12345 } }
207
-
208
- its(:local_host) { should == '127.0.0.1' }
209
- its(:local_port) { should == 12345 }
210
- end if RUBY_VERSION >= '2.0'
211
-
212
- context "when providing PEM certificates" do
213
- let(:pem) { :pem_contents }
214
- let(:options) { {:pem => pem, :pem_password => "password"} }
215
-
216
- context "when scheme is https" do
217
- let(:uri) { URI 'https://google.com' }
218
- let(:cert) { mock("OpenSSL::X509::Certificate") }
219
- let(:key) { mock("OpenSSL::PKey::RSA") }
220
-
221
- before do
222
- OpenSSL::X509::Certificate.should_receive(:new).with(pem).and_return(cert)
223
- OpenSSL::PKey::RSA.should_receive(:new).with(pem, "password").and_return(key)
224
- end
225
-
226
- it "uses the provided PEM certificate " do
227
- subject.cert.should == cert
228
- subject.key.should == key
229
- end
230
-
231
- it "will verify the certificate" do
232
- subject.verify_mode.should == OpenSSL::SSL::VERIFY_PEER
233
- end
234
- end
235
-
236
- context "when scheme is not https" do
237
- let(:uri) { URI 'http://google.com' }
238
- let(:http) { Net::HTTP.new(uri) }
239
-
240
- before do
241
- Net::HTTP.stub(:new => http)
242
- OpenSSL::X509::Certificate.should_not_receive(:new).with(pem)
243
- OpenSSL::PKey::RSA.should_not_receive(:new).with(pem, "password")
244
- http.should_not_receive(:cert=)
245
- http.should_not_receive(:key=)
246
- end
247
-
248
- it "has no PEM certificate " do
249
- subject.cert.should be_nil
250
- subject.key.should be_nil
251
- end
252
- end
253
- end
254
-
255
- context "when providing PKCS12 certificates" do
256
- let(:p12) { :p12_contents }
257
- let(:options) { {:p12 => p12, :p12_password => "password"} }
258
-
259
- context "when scheme is https" do
260
- let(:uri) { URI 'https://google.com' }
261
- let(:pkcs12) { mock("OpenSSL::PKCS12", :certificate => cert, :key => key) }
262
- let(:cert) { mock("OpenSSL::X509::Certificate") }
263
- let(:key) { mock("OpenSSL::PKey::RSA") }
264
-
265
- before do
266
- OpenSSL::PKCS12.should_receive(:new).with(p12, "password").and_return(pkcs12)
267
- end
268
-
269
- it "uses the provided P12 certificate " do
270
- subject.cert.should == cert
271
- subject.key.should == key
272
- end
273
-
274
- it "will verify the certificate" do
275
- subject.verify_mode.should == OpenSSL::SSL::VERIFY_PEER
276
- end
277
- end
278
-
279
- context "when scheme is not https" do
280
- let(:uri) { URI 'http://google.com' }
281
- let(:http) { Net::HTTP.new(uri) }
282
-
283
- before do
284
- Net::HTTP.stub(:new => http)
285
- OpenSSL::PKCS12.new.should_not_receive(:new).with(p12, "password")
286
- http.should_not_receive(:cert=)
287
- http.should_not_receive(:key=)
288
- end
289
-
290
- it "has no PKCS12 certificate " do
291
- subject.cert.should be_nil
292
- subject.key.should be_nil
293
- end
294
- end
295
- end
296
- end
297
- end
298
- end
@@ -1,83 +0,0 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), '../spec_helper'))
2
-
3
- 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
- @cookie_hash.length.should 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
- @cookie_hash.length.should eql(1)
20
- @cookie_hash[:foo].should 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
- @cookie_hash[:first].should == 'one'
28
- @cookie_hash[:second].should == 'two'
29
- @cookie_hash[:third].should == 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
- @cookie_hash.length.should eql(1)
36
- @cookie_hash[:foo].should 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
- @cookie_hash.keys.should include(:first, :second)
42
- @cookie_hash[:first].should == 'one=1'
43
- @cookie_hash[:second].should == 'two=2=='
44
- end
45
- end
46
-
47
- describe 'with other class' do
48
- it "should error" do
49
- lambda {
50
- @cookie_hash.add_cookies(Array.new)
51
- }.should 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
- @s.should match(/foo=bar/)
67
- @s.should match(/rofl=copter/)
68
- @s.should 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
- @s.should_not 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
- @s.should_not match(/Path=\//)
81
- end
82
- end
83
- end
@@ -1,23 +0,0 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
2
-
3
- describe HTTParty::Error do
4
- subject { described_class }
5
-
6
- its(:ancestors) { should include(StandardError) }
7
-
8
- describe HTTParty::UnsupportedFormat do
9
- its(:ancestors) { should include(HTTParty::Error) }
10
- end
11
-
12
- describe HTTParty::UnsupportedURIScheme do
13
- its(:ancestors) { should include(HTTParty::Error) }
14
- end
15
-
16
- describe HTTParty::ResponseError do
17
- its(:ancestors) { should include(HTTParty::Error) }
18
- end
19
-
20
- describe HTTParty::RedirectionTooDeep do
21
- its(:ancestors) { should include(HTTParty::ResponseError) }
22
- end
23
- end
@@ -1,26 +0,0 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'spec_helper'))
2
-
3
- describe HTTParty::Logger::ApacheLogger do
4
- describe "#format" do
5
- it "formats a response in a style that resembles apache's access log" do
6
- request_time = Time.new.strftime("%Y-%m-%d %H:%M:%S %z")
7
- log_message = "[HTTParty] [#{request_time}] 302 \"GET http://my.domain.com/my_path\" - "
8
-
9
- request_double = double(
10
- :http_method => Net::HTTP::Get,
11
- :path => "http://my.domain.com/my_path"
12
- )
13
- response_double = double(
14
- :code => 302,
15
- :[] => nil
16
- )
17
-
18
- logger_double = double
19
- logger_double.should_receive(:info).with(log_message)
20
-
21
- subject = described_class.new(logger_double, :info)
22
- subject.current_time = request_time
23
- subject.format(request_double, response_double)
24
- end
25
- end
26
- end
@@ -1,18 +0,0 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'spec_helper'))
2
-
3
- describe HTTParty::Logger::CurlLogger do
4
- describe "#format" do
5
- it "formats a response in a style that resembles a -v curl" do
6
- logger_double = double
7
- logger_double.should_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
@@ -1,22 +0,0 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'spec_helper'))
2
-
3
- describe HTTParty::Logger do
4
- describe ".build" do
5
- subject { HTTParty::Logger }
6
-
7
- it "defaults level to :info" do
8
- logger_double = double()
9
- subject.build(logger_double, nil, nil).level.should == :info
10
- end
11
-
12
- it "defaults format to :apache" do
13
- logger_double = double()
14
- subject.build(logger_double, nil, nil).should be_an_instance_of(HTTParty::Logger::ApacheLogger)
15
- end
16
-
17
- it "builds :curl style logger" do
18
- logger_double = double()
19
- subject.build(logger_double, nil, :curl).should be_an_instance_of(HTTParty::Logger::CurlLogger)
20
- end
21
- end
22
- end
@@ -1,152 +0,0 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
2
-
3
- describe Net::HTTPHeader::DigestAuthenticator do
4
- def setup_digest(response)
5
- digest = Net::HTTPHeader::DigestAuthenticator.new("Mufasa",
6
- "Circle Of Life", "GET", "/dir/index.html", response)
7
- digest.stub(:random).and_return("deadbeef")
8
- Digest::MD5.stub(:hexdigest) { |str| "md5(#{str})" }
9
- digest
10
- end
11
-
12
- def authorization_header
13
- @digest.authorization_header.join(", ")
14
- end
15
-
16
-
17
- context "with an opaque value in the response header" do
18
- before do
19
- @digest = setup_digest({
20
- 'www-authenticate' => 'Digest realm="myhost@testrealm.com", opaque="solid"'
21
- })
22
- end
23
-
24
- it "should set opaque" do
25
- authorization_header.should include(%Q(opaque="solid"))
26
- end
27
- end
28
-
29
- context "without an opaque valid in the response header" do
30
- before do
31
- @digest = setup_digest({
32
- 'www-authenticate' => 'Digest realm="myhost@testrealm.com"'
33
- })
34
- end
35
-
36
- it "should not set opaque" do
37
- authorization_header.should_not include(%Q(opaque=))
38
- end
39
- end
40
-
41
- context "with specified quality of protection (qop)" do
42
- before do
43
- @digest = setup_digest({
44
- 'www-authenticate' => 'Digest realm="myhost@testrealm.com", nonce="NONCE", qop="auth"',
45
- })
46
- end
47
-
48
- it "should set prefix" do
49
- authorization_header.should =~ /^Digest /
50
- end
51
-
52
- it "should set username" do
53
- authorization_header.should include(%Q(username="Mufasa"))
54
- end
55
-
56
- it "should set digest-uri" do
57
- authorization_header.should include(%Q(uri="/dir/index.html"))
58
- end
59
-
60
- it "should set qop" do
61
- authorization_header.should include(%Q(qop="auth"))
62
- end
63
-
64
- it "should set cnonce" do
65
- authorization_header.should include(%Q(cnonce="md5(deadbeef)"))
66
- end
67
-
68
- it "should set nonce-count" do
69
- authorization_header.should include(%Q(nc=00000001))
70
- end
71
-
72
- it "should set response" do
73
- request_digest = "md5(md5(Mufasa:myhost@testrealm.com:Circle Of Life):NONCE:00000001:md5(deadbeef):auth:md5(GET:/dir/index.html))"
74
- authorization_header.should include(%Q(response="#{request_digest}"))
75
- end
76
- end
77
-
78
-
79
- context "with unspecified quality of protection (qop)" do
80
- before do
81
- @digest = setup_digest({
82
- 'www-authenticate' => 'Digest realm="myhost@testrealm.com", nonce="NONCE"',
83
- })
84
- end
85
-
86
- it "should set prefix" do
87
- authorization_header.should =~ /^Digest /
88
- end
89
-
90
- it "should set username" do
91
- authorization_header.should include(%Q(username="Mufasa"))
92
- end
93
-
94
- it "should set digest-uri" do
95
- authorization_header.should include(%Q(uri="/dir/index.html"))
96
- end
97
-
98
- it "should not set qop" do
99
- authorization_header.should_not include(%Q(qop=))
100
- end
101
-
102
- it "should not set cnonce" do
103
- authorization_header.should_not include(%Q(cnonce=))
104
- end
105
-
106
- it "should not set nonce-count" do
107
- authorization_header.should_not include(%Q(nc=))
108
- end
109
-
110
- it "should set response" do
111
- request_digest = "md5(md5(Mufasa:myhost@testrealm.com:Circle Of Life):NONCE:md5(GET:/dir/index.html))"
112
- authorization_header.should include(%Q(response="#{request_digest}"))
113
- end
114
- end
115
-
116
- context "with multiple authenticate headers" do
117
- before do
118
- @digest = setup_digest({
119
- 'www-authenticate' => 'NTLM, Digest realm="myhost@testrealm.com", nonce="NONCE", qop="auth"',
120
- })
121
- end
122
-
123
- it "should set prefix" do
124
- authorization_header.should =~ /^Digest /
125
- end
126
-
127
- it "should set username" do
128
- authorization_header.should include(%Q(username="Mufasa"))
129
- end
130
-
131
- it "should set digest-uri" do
132
- authorization_header.should include(%Q(uri="/dir/index.html"))
133
- end
134
-
135
- it "should set qop" do
136
- authorization_header.should include(%Q(qop="auth"))
137
- end
138
-
139
- it "should set cnonce" do
140
- authorization_header.should include(%Q(cnonce="md5(deadbeef)"))
141
- end
142
-
143
- it "should set nonce-count" do
144
- authorization_header.should include(%Q(nc=00000001))
145
- end
146
-
147
- it "should set response" do
148
- request_digest = "md5(md5(Mufasa:myhost@testrealm.com:Circle Of Life):NONCE:00000001:md5(deadbeef):auth:md5(GET:/dir/index.html))"
149
- authorization_header.should include(%Q(response="#{request_digest}"))
150
- end
151
- end
152
- end