oauth 0.3.6 → 0.3.7.pre1

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.

Potentially problematic release.


This version of oauth might be problematic. Click here for more details.

Files changed (43) hide show
  1. data/.gitignore +1 -0
  2. data/History.txt +16 -0
  3. data/Manifest.txt +2 -0
  4. data/README.rdoc +13 -0
  5. data/Rakefile +27 -27
  6. data/TODO +1 -0
  7. data/lib/digest/hmac.rb +104 -0
  8. data/lib/oauth.rb +5 -1
  9. data/lib/oauth/client/action_controller_request.rb +1 -1
  10. data/lib/oauth/client/em_http.rb +94 -0
  11. data/lib/oauth/client/helper.rb +7 -4
  12. data/lib/oauth/client/net_http.rb +9 -6
  13. data/lib/oauth/consumer.rb +45 -25
  14. data/lib/oauth/core_ext.rb +31 -0
  15. data/lib/oauth/helper.rb +11 -1
  16. data/lib/oauth/request_proxy/base.rb +4 -3
  17. data/lib/oauth/request_proxy/curb_request.rb +55 -0
  18. data/lib/oauth/request_proxy/em_http_request.rb +67 -0
  19. data/lib/oauth/request_proxy/net_http.rb +9 -6
  20. data/lib/oauth/request_proxy/typhoeus_request.rb +53 -0
  21. data/lib/oauth/signature.rb +4 -1
  22. data/lib/oauth/signature/base.rb +9 -3
  23. data/lib/oauth/signature/hmac/base.rb +5 -2
  24. data/lib/oauth/signature/hmac/md5.rb +1 -2
  25. data/lib/oauth/signature/hmac/rmd160.rb +1 -2
  26. data/lib/oauth/signature/hmac/sha1.rb +2 -3
  27. data/lib/oauth/signature/hmac/sha2.rb +1 -2
  28. data/lib/oauth/signature/plaintext.rb +2 -2
  29. data/lib/oauth/version.rb +1 -1
  30. data/oauth.gemspec +157 -27
  31. data/test/integration/consumer_test.rb +304 -0
  32. data/test/test_action_controller_request_proxy.rb +4 -1
  33. data/test/test_consumer.rb +51 -254
  34. data/test/test_curb_request_proxy.rb +69 -0
  35. data/test/test_em_http_client.rb +74 -0
  36. data/test/test_em_http_request_proxy.rb +107 -0
  37. data/test/test_helper.rb +15 -9
  38. data/test/test_net_http_client.rb +59 -5
  39. data/test/test_net_http_request_proxy.rb +1 -1
  40. data/test/test_signature.rb +6 -3
  41. data/test/test_typhoeus_request_proxy.rb +73 -0
  42. data/website/index.html +2 -2
  43. metadata +43 -25
@@ -7,6 +7,7 @@ require 'action_controller/test_process'
7
7
  class ActionControllerRequestProxyTest < Test::Unit::TestCase
8
8
  def request_proxy(request_method = :get, uri_params = {}, body_params = {})
9
9
  request = ActionController::TestRequest.new
10
+ request.set_REQUEST_URI('/')
10
11
 
11
12
  case request_method
12
13
  when :post
@@ -117,7 +118,9 @@ class ActionControllerRequestProxyTest < Test::Unit::TestCase
117
118
  )
118
119
  end
119
120
 
120
- def test_query_string_parameter_values_should_be_cgi_unescaped
121
+ # TODO disabled; ActionController::TestRequest does not appear to parse
122
+ # QUERY_STRING
123
+ def x_test_query_string_parameter_values_should_be_cgi_unescaped
121
124
  request = request_proxy do |r|
122
125
  r.env['QUERY_STRING'] = 'url=http%3A%2F%2Ffoo.com%2F%3Fa%3Db%26c%3Dd'
123
126
  end
@@ -1,4 +1,5 @@
1
1
  require File.dirname(__FILE__) + '/test_helper'
2
+ require 'mocha'
2
3
 
3
4
  require 'stringio'
4
5
 
@@ -7,7 +8,7 @@ require 'stringio'
7
8
  # This also means you have to be online to be able to run these.
8
9
  class ConsumerTest < Test::Unit::TestCase
9
10
  def setup
10
- @consumer=OAuth::Consumer.new(
11
+ @consumer=OAuth::Consumer.new(
11
12
  'consumer_key_86cad9', '5888bf0345e5d237',
12
13
  {
13
14
  :site=>"http://blabla.bla",
@@ -25,7 +26,7 @@ class ConsumerTest < Test::Unit::TestCase
25
26
  @timestamp = "1199645624"
26
27
  @consumer.http=Net::HTTP.new(@request_uri.host, @request_uri.port)
27
28
  end
28
-
29
+
29
30
  def test_initializer
30
31
  assert_equal "consumer_key_86cad9",@consumer.key
31
32
  assert_equal "5888bf0345e5d237",@consumer.secret
@@ -40,7 +41,7 @@ class ConsumerTest < Test::Unit::TestCase
40
41
  assert_equal :get,@consumer.http_method
41
42
  end
42
43
 
43
- def test_defaults
44
+ def test_defaults
44
45
  @consumer=OAuth::Consumer.new(
45
46
  "key",
46
47
  "secret",
@@ -57,7 +58,7 @@ class ConsumerTest < Test::Unit::TestCase
57
58
  assert_equal "http://twitter.com/oauth/access_token",@consumer.access_token_url
58
59
  assert_equal "http://twitter.com/oauth/authorize",@consumer.authorize_url
59
60
  assert_equal :header,@consumer.scheme
60
- assert_equal :post,@consumer.http_method
61
+ assert_equal :post,@consumer.http_method
61
62
  end
62
63
 
63
64
  def test_override_paths
@@ -79,284 +80,80 @@ class ConsumerTest < Test::Unit::TestCase
79
80
  assert_equal "http://oauth.twitter.com/access_token",@consumer.access_token_url
80
81
  assert_equal "http://site.twitter.com/authorize",@consumer.authorize_url
81
82
  assert_equal :header,@consumer.scheme
82
- assert_equal :post,@consumer.http_method
83
+ assert_equal :post,@consumer.http_method
83
84
  end
84
85
 
85
- def test_that_signing_auth_headers_on_get_requests_works
86
- request = Net::HTTP::Get.new(@request_uri.path + "?" + request_parameters_to_s)
87
- @token.sign!(request, {:nonce => @nonce, :timestamp => @timestamp})
88
-
89
- assert_equal 'GET', request.method
90
- assert_equal '/test?key=value', request.path
91
- assert_equal "OAuth oauth_nonce=\"225579211881198842005988698334675835446\", oauth_signature_method=\"HMAC-SHA1\", oauth_token=\"token_411a7f\", oauth_timestamp=\"1199645624\", oauth_consumer_key=\"consumer_key_86cad9\", oauth_signature=\"1oO2izFav1GP4kEH2EskwXkCRFg%3D\", oauth_version=\"1.0\"".split(', ').sort, request['authorization'].split(', ').sort
92
- end
93
-
94
- def test_that_setting_signature_method_on_consumer_effects_signing
95
- require 'oauth/signature/plaintext'
96
- request = Net::HTTP::Get.new(@request_uri.path)
97
- consumer = @consumer.dup
98
- consumer.options[:signature_method] = 'PLAINTEXT'
99
- token = OAuth::ConsumerToken.new(consumer, 'token_411a7f', '3196ffd991c8ebdb')
100
- token.sign!(request, {:nonce => @nonce, :timestamp => @timestamp})
101
-
102
- assert_no_match( /oauth_signature_method="HMAC-SHA1"/, request['authorization'])
103
- assert_match( /oauth_signature_method="PLAINTEXT"/, request['authorization'])
104
- end
86
+ def test_that_token_response_should_be_uri_parameter_format_as_default
87
+ @consumer.expects(:request).returns(create_stub_http_response("oauth_token=token&oauth_token_secret=secret"))
105
88
 
106
- def test_that_setting_signature_method_on_consumer_effects_signature_base_string
107
- require 'oauth/signature/plaintext'
108
- request = Net::HTTP::Get.new(@request_uri.path)
109
- consumer = @consumer.dup
110
- consumer.options[:signature_method] = 'PLAINTEXT'
111
-
112
- request = Net::HTTP::Get.new('/')
113
- signature_base_string = consumer.signature_base_string(request)
89
+ hash = @consumer.token_request(:get, "")
114
90
 
115
- assert_no_match( /HMAC-SHA1/, signature_base_string)
116
- assert_equal( "#{consumer.secret}%26", signature_base_string)
91
+ assert_equal "token", hash[:oauth_token]
92
+ assert_equal "secret", hash[:oauth_token_secret]
117
93
  end
118
94
 
119
- def test_that_plaintext_signature_works
120
- require 'oauth/signature/plaintext'
121
- consumer = OAuth::Consumer.new("key", "secret",
122
- :site => "http://term.ie", :signature_method => 'PLAINTEXT')
123
- access_token = OAuth::AccessToken.new(consumer, 'accesskey', 'accesssecret')
124
- response = access_token.get("/oauth/example/echo_api.php?echo=hello")
95
+ def test_can_provided_a_block_to_interpret_token_response
96
+ @consumer.expects(:request).returns(create_stub_http_response)
125
97
 
126
- assert_equal 'echo=hello', response.body
127
- end
128
-
129
- def test_that_signing_auth_headers_on_post_requests_works
130
- request = Net::HTTP::Post.new(@request_uri.path)
131
- request.set_form_data( @request_parameters )
132
- @token.sign!(request, {:nonce => @nonce, :timestamp => @timestamp})
133
- # assert_equal "",request.oauth_helper.signature_base_string
98
+ hash = @consumer.token_request(:get, '') {{ :oauth_token => 'token', :oauth_token_secret => 'secret' }}
134
99
 
135
- assert_equal 'POST', request.method
136
- assert_equal '/test', request.path
137
- assert_equal 'key=value', request.body
138
- assert_equal "OAuth oauth_nonce=\"225579211881198842005988698334675835446\", oauth_signature_method=\"HMAC-SHA1\", oauth_token=\"token_411a7f\", oauth_timestamp=\"1199645624\", oauth_consumer_key=\"consumer_key_86cad9\", oauth_signature=\"26g7wHTtNO6ZWJaLltcueppHYiI%3D\", oauth_version=\"1.0\"".split(', ').sort, request['authorization'].split(', ').sort
100
+ assert_equal 'token', hash[:oauth_token]
101
+ assert_equal 'secret', hash[:oauth_token_secret]
139
102
  end
140
-
141
- def test_that_signing_post_params_works
142
- request = Net::HTTP::Post.new(@request_uri.path)
143
- request.set_form_data( @request_parameters )
144
- @token.sign!(request, {:scheme => 'body', :nonce => @nonce, :timestamp => @timestamp})
145
103
 
146
- assert_equal 'POST', request.method
147
- assert_equal '/test', request.path
148
- assert_equal "key=value&oauth_consumer_key=consumer_key_86cad9&oauth_nonce=225579211881198842005988698334675835446&oauth_signature=26g7wHTtNO6ZWJaLltcueppHYiI%3d&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1199645624&oauth_token=token_411a7f&oauth_version=1.0", request.body.split("&").sort.join("&")
149
- assert_equal nil, request['authorization']
150
- end
104
+ def test_that_can_provide_a_block_to_interpret_a_request_token_response
105
+ @consumer.expects(:request).returns(create_stub_http_response)
151
106
 
152
- def test_that_using_auth_headers_on_get_on_create_signed_requests_works
153
- request=@consumer.create_signed_request(:get,@request_uri.path+ "?" + request_parameters_to_s,@token,{:nonce => @nonce, :timestamp => @timestamp},@request_parameters)
154
-
155
- assert_equal 'GET', request.method
156
- assert_equal '/test?key=value', request.path
157
- assert_equal "OAuth oauth_nonce=\"225579211881198842005988698334675835446\", oauth_signature_method=\"HMAC-SHA1\", oauth_token=\"token_411a7f\", oauth_timestamp=\"1199645624\", oauth_consumer_key=\"consumer_key_86cad9\", oauth_signature=\"1oO2izFav1GP4kEH2EskwXkCRFg%3D\", oauth_version=\"1.0\"".split(', ').sort, request['authorization'].split(', ').sort
158
- end
107
+ token = @consumer.get_request_token {{ :oauth_token => 'token', :oauth_token_secret => 'secret' }}
159
108
 
160
- def test_that_using_auth_headers_on_post_on_create_signed_requests_works
161
- request=@consumer.create_signed_request(:post,@request_uri.path,@token,{:nonce => @nonce, :timestamp => @timestamp},@request_parameters,{})
162
- assert_equal 'POST', request.method
163
- assert_equal '/test', request.path
164
- assert_equal 'key=value', request.body
165
- assert_equal "OAuth oauth_nonce=\"225579211881198842005988698334675835446\", oauth_signature_method=\"HMAC-SHA1\", oauth_token=\"token_411a7f\", oauth_timestamp=\"1199645624\", oauth_consumer_key=\"consumer_key_86cad9\", oauth_signature=\"26g7wHTtNO6ZWJaLltcueppHYiI%3D\", oauth_version=\"1.0\"".split(', ').sort, request['authorization'].split(', ').sort
109
+ assert_equal 'token', token.token
110
+ assert_equal 'secret', token.secret
166
111
  end
167
112
 
168
- def test_that_signing_post_params_works_2
169
- request=@consumer.create_signed_request(:post,@request_uri.path,@token,{:scheme => 'body', :nonce => @nonce, :timestamp => @timestamp},@request_parameters,{})
113
+ def test_that_block_is_not_mandatory_for_getting_an_access_token
114
+ stub_token = mock
115
+ @consumer.expects(:request).returns(create_stub_http_response("oauth_token=token&oauth_token_secret=secret"))
170
116
 
171
- assert_equal 'POST', request.method
172
- assert_equal '/test', request.path
173
- assert_equal "key=value&oauth_consumer_key=consumer_key_86cad9&oauth_nonce=225579211881198842005988698334675835446&oauth_signature=26g7wHTtNO6ZWJaLltcueppHYiI%3d&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1199645624&oauth_token=token_411a7f&oauth_version=1.0", request.body.split("&").sort.join("&")
174
- assert_equal nil, request['authorization']
175
- end
176
-
177
- def test_step_by_step_token_request
178
- @consumer=OAuth::Consumer.new(
179
- "key",
180
- "secret",
181
- {
182
- :site=>"http://term.ie",
183
- :request_token_path=>"/oauth/example/request_token.php",
184
- :access_token_path=>"/oauth/example/access_token.php",
185
- :authorize_path=>"/oauth/example/authorize.php",
186
- :scheme=>:header
187
- })
188
- options={:nonce=>'nonce',:timestamp=>Time.now.to_i.to_s}
189
-
190
- request = Net::HTTP::Get.new("/oauth/example/request_token.php")
191
- signature_base_string=@consumer.signature_base_string(request,nil,options)
192
- assert_equal "GET&http%3A%2F%2Fterm.ie%2Foauth%2Fexample%2Frequest_token.php&oauth_consumer_key%3Dkey%26oauth_nonce%3D#{options[:nonce]}%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D#{options[:timestamp]}%26oauth_version%3D1.0",signature_base_string
193
- @consumer.sign!(request, nil,options)
117
+ token = @consumer.get_access_token(stub_token)
194
118
 
195
- assert_equal 'GET', request.method
196
- assert_equal nil, request.body
197
- response=@consumer.http.request(request)
198
- assert_equal "200",response.code
199
- assert_equal "oauth_token=requestkey&oauth_token_secret=requestsecret",response.body
119
+ assert_equal 'token', token.token
120
+ assert_equal 'secret', token.secret
200
121
  end
201
122
 
202
- def test_get_token_sequence
203
- @consumer=OAuth::Consumer.new(
204
- "key",
205
- "secret",
206
- {
207
- :site=>"http://term.ie",
208
- :request_token_path=>"/oauth/example/request_token.php",
209
- :access_token_path=>"/oauth/example/access_token.php",
210
- :authorize_path=>"/oauth/example/authorize.php"
211
- })
212
- assert_equal "http://term.ie/oauth/example/request_token.php",@consumer.request_token_url
213
- assert_equal "http://term.ie/oauth/example/access_token.php",@consumer.access_token_url
123
+ def test_that_can_provide_a_block_to_interpret_an_access_token_response
124
+ stub_token = mock
125
+ @consumer.expects(:request).returns(create_stub_http_response)
214
126
 
215
- assert !@consumer.request_token_url?, "Should not use fully qualified request token url"
216
- assert !@consumer.access_token_url?, "Should not use fully qualified access token url"
217
- assert !@consumer.authorize_url?, "Should not use fully qualified url"
127
+ token = @consumer.get_access_token(stub_token) {{ :oauth_token => 'token', :oauth_token_secret => 'secret' }}
218
128
 
219
- @request_token=@consumer.get_request_token
220
- assert_not_nil @request_token
221
- assert_equal "requestkey",@request_token.token
222
- assert_equal "requestsecret",@request_token.secret
223
- assert_equal "http://term.ie/oauth/example/authorize.php?oauth_token=requestkey",@request_token.authorize_url
224
-
225
- @access_token=@request_token.get_access_token
226
- assert_not_nil @access_token
227
- assert_equal "accesskey",@access_token.token
228
- assert_equal "accesssecret",@access_token.secret
229
-
230
- @response=@access_token.get("/oauth/example/echo_api.php?ok=hello&test=this")
231
- assert_not_nil @response
232
- assert_equal "200",@response.code
233
- assert_equal( "ok=hello&test=this",@response.body)
234
-
235
- @response=@access_token.post("/oauth/example/echo_api.php",{'ok'=>'hello','test'=>'this'})
236
- assert_not_nil @response
237
- assert_equal "200",@response.code
238
- assert_equal( "ok=hello&test=this",@response.body)
129
+ assert_equal 'token', token.token
130
+ assert_equal 'secret', token.secret
239
131
  end
132
+
133
+ def test_that_not_setting_ignore_callback_will_include_oauth_callback_in_request_options
134
+ request_options = {}
135
+ @consumer.stubs(:request).returns(create_stub_http_response)
240
136
 
241
- def test_get_token_sequence_using_fqdn
242
- @consumer=OAuth::Consumer.new(
243
- "key",
244
- "secret",
245
- {
246
- :site=>"http://term.ie",
247
- :request_token_url=>"http://term.ie/oauth/example/request_token.php",
248
- :access_token_url=>"http://term.ie/oauth/example/access_token.php",
249
- :authorize_url=>"http://term.ie/oauth/example/authorize.php"
250
- })
251
- assert_equal "http://term.ie/oauth/example/request_token.php",@consumer.request_token_url
252
- assert_equal "http://term.ie/oauth/example/access_token.php",@consumer.access_token_url
253
-
254
- assert @consumer.request_token_url?, "Should use fully qualified request token url"
255
- assert @consumer.access_token_url?, "Should use fully qualified access token url"
256
- assert @consumer.authorize_url?, "Should use fully qualified url"
257
-
258
- @request_token=@consumer.get_request_token
259
- assert_not_nil @request_token
260
- assert_equal "requestkey",@request_token.token
261
- assert_equal "requestsecret",@request_token.secret
262
- assert_equal "http://term.ie/oauth/example/authorize.php?oauth_token=requestkey",@request_token.authorize_url
137
+ @consumer.get_request_token(request_options) {{ :oauth_token => 'token', :oauth_token_secret => 'secret' }}
263
138
 
264
- @access_token=@request_token.get_access_token
265
- assert_not_nil @access_token
266
- assert_equal "accesskey",@access_token.token
267
- assert_equal "accesssecret",@access_token.secret
268
-
269
- @response=@access_token.get("/oauth/example/echo_api.php?ok=hello&test=this")
270
- assert_not_nil @response
271
- assert_equal "200",@response.code
272
- assert_equal( "ok=hello&test=this",@response.body)
273
-
274
- @response=@access_token.post("/oauth/example/echo_api.php",{'ok'=>'hello','test'=>'this'})
275
- assert_not_nil @response
276
- assert_equal "200",@response.code
277
- assert_equal( "ok=hello&test=this",@response.body)
139
+ assert_equal 'oob', request_options[:oauth_callback]
278
140
  end
279
141
 
142
+ def test_that_setting_ignore_callback_will_exclude_oauth_callback_in_request_options
143
+ request_options = { :exclude_callback=> true }
144
+ @consumer.stubs(:request).returns(create_stub_http_response)
280
145
 
281
- # This test does an actual https request (the result doesn't matter)
282
- # to initialize the same way as get_request_token does. Can be any
283
- # site that supports https.
284
- #
285
- # It also generates "warning: using default DH parameters." which I
286
- # don't know how to get rid of
287
- # def test_serialization_with_https
288
- # consumer = OAuth::Consumer.new('token', 'secret', :site => 'https://plazes.net')
289
- # consumer.http.verify_mode = OpenSSL::SSL::VERIFY_NONE
290
- # consumer.http.get('/')
291
- #
292
- # assert_nothing_raised do
293
- # # Specifically this should not raise TypeError: no marshal_dump
294
- # # is defined for class OpenSSL::SSL::SSLContext
295
- # Marshal.dump(consumer)
296
- # end
297
- # end
298
- #
299
- def test_get_request_token_with_custom_arguments
300
- @consumer=OAuth::Consumer.new(
301
- "key",
302
- "secret",
303
- {
304
- :site=>"http://term.ie",
305
- :request_token_path=>"/oauth/example/request_token.php",
306
- :access_token_path=>"/oauth/example/access_token.php",
307
- :authorize_path=>"/oauth/example/authorize.php"
308
- })
309
-
310
-
311
- debug = ""
312
- @consumer.http.set_debug_output(debug)
313
-
314
- # get_request_token should receive our custom request_options and *arguments parameters from get_request_token.
315
- @consumer.get_request_token({}, {:scope => "http://www.google.com/calendar/feeds http://picasaweb.google.com/data"})
316
-
317
- # Because this is a POST request, create_http_request should take the first element of *arguments
318
- # and turn it into URL-encoded data in the body of the POST.
319
- assert_match( /^<- "scope=http%3a%2f%2fwww.google.com%2fcalendar%2ffeeds%20http%3a%2f%2fpicasaweb.google.com%2fdata"/,
320
- debug)
321
- end
146
+ @consumer.get_request_token(request_options) {{ :oauth_token => 'token', :oauth_token_secret => 'secret' }}
322
147
 
323
- def test_post_with_body_stream
324
- @consumer=OAuth::Consumer.new(
325
- "key",
326
- "secret",
327
- {
328
- :site=>"http://term.ie",
329
- :request_token_path=>"/oauth/example/request_token.php",
330
- :access_token_path=>"/oauth/example/access_token.php",
331
- :authorize_path=>"/oauth/example/authorize.php"
332
- })
333
-
334
-
335
- @request_token=@consumer.get_request_token
336
- @access_token=@request_token.get_access_token
337
-
338
- request_body_string = "Hello, hello, hello"
339
- request_body_stream = StringIO.new( request_body_string )
340
-
341
- @response=@access_token.post("/oauth/example/echo_api.php",request_body_stream)
342
- assert_not_nil @response
343
- assert_equal "200",@response.code
344
-
345
- request_body_file = File.open(__FILE__)
346
-
347
- @response=@access_token.post("/oauth/example/echo_api.php",request_body_file)
348
- assert_not_nil @response
349
- assert_equal "200",@response.code
350
-
351
- # unfortunately I don't know of a way to test that the body data was received correctly since the test server at http://term.ie
352
- # echos back any non-oauth parameters but not the body. However, this does test that the request is still correctly signed
353
- # (including the Content-Length header) and that the server received Content-Length bytes of body since it won't process the
354
- # request & respond until the full body length is received.
148
+ assert_nil request_options[:oauth_callback]
355
149
  end
150
+
151
+ private
356
152
 
357
- protected
358
-
359
- def request_parameters_to_s
360
- @request_parameters.map { |k,v| "#{k}=#{v}" }.join("&")
153
+ def create_stub_http_response expected_body=nil
154
+ stub_http_response = stub
155
+ stub_http_response.stubs(:code).returns(200)
156
+ stub_http_response.stubs(:body).tap {|expectation| expectation.returns(expected_body) unless expected_body.nil? }
157
+ return stub_http_response
361
158
  end
362
159
  end
@@ -0,0 +1,69 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+ require 'oauth/request_proxy/curb_request'
3
+ require 'curb'
4
+
5
+ class CurbRequestProxyTest < Test::Unit::TestCase
6
+
7
+ def test_that_proxy_simple_get_request_works
8
+ request = Curl::Easy.new('/test?key=value')
9
+ request_proxy = OAuth::RequestProxy.proxy(request, {:uri => 'http://example.com/test?key=value'})
10
+
11
+ expected_parameters = {'key' => ['value']}
12
+ assert_equal expected_parameters, request_proxy.parameters_for_signature
13
+ assert_equal 'http://example.com/test', request_proxy.normalized_uri
14
+ end
15
+
16
+ def test_that_proxy_simple_post_request_works_with_arguments
17
+ request = Curl::Easy.new('/test')
18
+ params = {'key' => 'value'}
19
+ request_proxy = OAuth::RequestProxy.proxy(request, {:uri => 'http://example.com/test', :parameters => params})
20
+
21
+ expected_parameters = {'key' => 'value'}
22
+ assert_equal expected_parameters, request_proxy.parameters_for_signature
23
+ assert_equal 'http://example.com/test', request_proxy.normalized_uri
24
+ end
25
+
26
+ def test_that_proxy_simple_post_request_works_with_form_data
27
+ request = Curl::Easy.new('/test')
28
+ request.post_body = 'key=value'
29
+ request.headers['Content-Type'] = 'application/x-www-form-urlencoded'
30
+
31
+ request_proxy = OAuth::RequestProxy.proxy(request, {:uri => 'http://example.com/test'})
32
+
33
+ expected_parameters = {'key' => 'value'}
34
+ assert_equal expected_parameters, request_proxy.parameters_for_signature
35
+ assert_equal 'http://example.com/test', request_proxy.normalized_uri
36
+ end
37
+
38
+ def test_that_proxy_simple_put_request_works_with_arguments
39
+ request = Curl::Easy.new('/test')
40
+ params = {'key' => 'value'}
41
+ request_proxy = OAuth::RequestProxy.proxy(request, {:uri => 'http://example.com/test', :parameters => params})
42
+
43
+ expected_parameters = {'key' => 'value'}
44
+ assert_equal expected_parameters, request_proxy.parameters_for_signature
45
+ assert_equal 'http://example.com/test', request_proxy.normalized_uri
46
+ end
47
+
48
+ def test_that_proxy_simple_put_request_works_with_form_data
49
+ request = Curl::Easy.new('/test')
50
+ request.post_body = 'key=value'
51
+
52
+ request_proxy = OAuth::RequestProxy.proxy(request, {:uri => 'http://example.com/test'})
53
+
54
+ expected_parameters = {}
55
+ assert_equal expected_parameters, request_proxy.parameters_for_signature
56
+ assert_equal 'http://example.com/test', request_proxy.normalized_uri
57
+ end
58
+
59
+ def test_that_proxy_post_request_works_with_mixed_parameter_sources
60
+ request = Curl::Easy.new('/test?key=value')
61
+ request.post_body = 'key2=value2'
62
+ request.headers['Content-Type'] = 'application/x-www-form-urlencoded'
63
+ request_proxy = OAuth::RequestProxy.proxy(request, {:uri => 'http://example.com/test?key=value', :parameters => {'key3' => 'value3'}})
64
+
65
+ expected_parameters = {'key' => ['value'], 'key2' => 'value2', 'key3' => 'value3'}
66
+ assert_equal expected_parameters, request_proxy.parameters_for_signature
67
+ assert_equal 'http://example.com/test', request_proxy.normalized_uri
68
+ end
69
+ end