Permalink
Browse files

Update gem deps and fix tests

  • Loading branch information...
quirkey committed Apr 21, 2012
1 parent f2ba71d commit 46a163317b4c9a1a46c2365ace64eeab6ecc06a0
Showing with 49 additions and 46 deletions.
  1. +22 −21 Gemfile.lock
  2. +3 −1 test/test_helper.rb
  3. +23 −23 test/test_net_http_client.rb
  4. +1 −1 test/test_net_http_request_proxy.rb
View
@@ -1,35 +1,36 @@
GEM
remote: http://rubygems.org/
specs:
- actionpack (2.3.8)
- activesupport (= 2.3.8)
+ actionpack (2.3.14)
+ activesupport (= 2.3.14)
rack (~> 1.1.0)
- activesupport (2.3.8)
- addressable (2.2.0)
- crack (0.1.8)
- curb (0.7.7.1)
+ activesupport (2.3.14)
+ addressable (2.2.7)
+ crack (0.3.1)
+ curb (0.8.0)
em-http-request (0.2.11)
addressable (>= 2.0.0)
eventmachine (>= 0.12.9)
eventmachine (0.12.10)
- gemcutter (0.4.1)
- json_pure
git (1.2.5)
- jeweler (1.4.0)
- gemcutter (>= 0.1.0)
+ jeweler (1.8.3)
+ bundler (~> 1.0)
git (>= 1.2.5)
- rubyforge (>= 2.0.0)
- json_pure (1.4.3)
- mocha (0.9.8)
rake
- rack (1.1.0)
- rake (0.8.7)
- rubyforge (2.0.4)
- json_pure (>= 1.1.7)
- typhoeus (0.1.31)
- rack
- webmock (1.3.5)
- addressable (>= 2.1.1)
+ rdoc
+ json (1.6.6)
+ metaclass (0.0.1)
+ mime-types (1.18)
+ mocha (0.11.1)
+ metaclass (~> 0.0.1)
+ rack (1.1.3)
+ rake (0.9.2.2)
+ rdoc (3.12)
+ json (~> 1.4)
+ typhoeus (0.3.3)
+ mime-types
+ webmock (1.8.6)
+ addressable (>= 2.2.7)
crack (>= 0.1.7)
PLATFORMS
View
@@ -5,9 +5,11 @@
require 'oauth'
require 'mocha'
require 'stringio'
-require 'webmock/test_unit'
+require 'webmock'
class Test::Unit::TestCase
+ include WebMock::API
+
def assert_matching_headers(expected, actual)
# transform into sorted arrays
auth_intro, auth_params = actual.split(' ', 2)
@@ -15,123 +15,123 @@ def setup
def test_that_using_auth_headers_on_get_requests_works
request = Net::HTTP::Get.new(@request_uri.path + "?" + request_parameters_to_s)
request.oauth!(@http, @consumer, @token, {:nonce => @nonce, :timestamp => @timestamp})
-
+
assert_equal 'GET', request.method
assert_equal '/test?key=value', request.path
correct_sorted_params = "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\""
auth_intro, auth_params = request['authorization'].split(' ', 2)
assert_equal auth_intro, 'OAuth'
assert_matching_headers correct_sorted_params, request['authorization']
end
-
+
def test_that_using_auth_headers_on_get_requests_works_with_plaintext
require 'oauth/signature/plaintext'
c = OAuth::Consumer.new('consumer_key_86cad9', '5888bf0345e5d237',{
:signature_method => 'PLAINTEXT'
})
request = Net::HTTP::Get.new(@request_uri.path + "?" + request_parameters_to_s)
request.oauth!(@http, c, @token, {:nonce => @nonce, :timestamp => @timestamp, :signature_method => 'PLAINTEXT'})
-
+
assert_equal 'GET', request.method
assert_equal '/test?key=value', request.path
assert_matching_headers "oauth_nonce=\"225579211881198842005988698334675835446\", oauth_signature_method=\"PLAINTEXT\", oauth_token=\"token_411a7f\", oauth_timestamp=\"1199645624\", oauth_consumer_key=\"consumer_key_86cad9\", oauth_signature=\"5888bf0345e5d237%263196ffd991c8ebdb\", oauth_version=\"1.0\"", request['authorization']
end
-
+
def test_that_using_auth_headers_on_post_requests_works
request = Net::HTTP::Post.new(@request_uri.path)
request.set_form_data( @request_parameters )
request.oauth!(@http, @consumer, @token, {:nonce => @nonce, :timestamp => @timestamp})
-
+
assert_equal 'POST', request.method
assert_equal '/test', request.path
assert_equal 'key=value', request.body
correct_sorted_params = "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\""
assert_matching_headers correct_sorted_params, request['authorization']
end
-
+
def test_that_using_auth_headers_on_post_requests_with_data_works
request = Net::HTTP::Post.new(@request_uri.path)
request.body = "data"
request.content_type = 'text/ascii'
request.oauth!(@http, @consumer, @token, {:nonce => @nonce, :timestamp => @timestamp})
-
+
assert_equal 'POST', request.method
assert_equal '/test', request.path
assert_equal 'data', request.body
assert_equal 'text/ascii', request.content_type
assert_matching_headers "oauth_nonce=\"225579211881198842005988698334675835446\", oauth_body_hash=\"oXyaqmHoChv3HQ2FCvTluqmAC70%3D\", oauth_signature_method=\"HMAC-SHA1\", oauth_token=\"token_411a7f\", oauth_timestamp=\"1199645624\", oauth_consumer_key=\"consumer_key_86cad9\", oauth_signature=\"0DA6pGTapdHSqC15RZelY5rNLDw%3D\", oauth_version=\"1.0\"", request['authorization']
end
-
+
def test_that_body_hash_is_obmitted_when_no_algorithm_is_defined
request = Net::HTTP::Post.new(@request_uri.path)
request.body = "data"
request.content_type = 'text/ascii'
request.oauth!(@http, @consumer, @token, {:nonce => @nonce, :timestamp => @timestamp, :signature_method => 'plaintext'})
-
+
assert_equal 'POST', request.method
assert_equal '/test', request.path
assert_equal 'data', request.body
assert_equal 'text/ascii', request.content_type
assert_matching_headers "oauth_nonce=\"225579211881198842005988698334675835446\", oauth_signature_method=\"plaintext\", oauth_token=\"token_411a7f\", oauth_timestamp=\"1199645624\", oauth_consumer_key=\"consumer_key_86cad9\", oauth_signature=\"5888bf0345e5d237%263196ffd991c8ebdb\", oauth_version=\"1.0\"", request['authorization']
end
-
+
def test_that_version_is_added_to_existing_user_agent
request = Net::HTTP::Post.new(@request_uri.path)
request['User-Agent'] = "MyApp"
request.set_form_data( @request_parameters )
request.oauth!(@http, @consumer, @token, {:nonce => @nonce, :timestamp => @timestamp})
-
+
assert_equal "MyApp (OAuth gem v#{OAuth::VERSION})", request['User-Agent']
end
-
+
def test_that_version_is_set_when_no_user_agent
request = Net::HTTP::Post.new(@request_uri.path)
request.set_form_data( @request_parameters )
request.oauth!(@http, @consumer, @token, {:nonce => @nonce, :timestamp => @timestamp})
-
+
assert_equal "OAuth gem v#{OAuth::VERSION}", request['User-Agent']
end
-
+
def test_that_using_get_params_works
request = Net::HTTP::Get.new(@request_uri.path + "?" + request_parameters_to_s)
request.oauth!(@http, @consumer, @token, {:scheme => 'query_string', :nonce => @nonce, :timestamp => @timestamp})
-
+
assert_equal 'GET', request.method
uri = URI.parse(request.path)
assert_equal '/test', uri.path
assert_equal nil, uri.fragment
assert_equal "key=value&oauth_consumer_key=consumer_key_86cad9&oauth_nonce=225579211881198842005988698334675835446&oauth_signature=1oO2izFav1GP4kEH2EskwXkCRFg%3D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1199645624&oauth_token=token_411a7f&oauth_version=1.0", uri.query.split("&").sort.join("&")
assert_equal nil, request['authorization']
end
-
+
def test_that_using_get_params_works_with_plaintext
request = Net::HTTP::Get.new(@request_uri.path + "?" + request_parameters_to_s)
request.oauth!(@http, @consumer, @token, {:scheme => 'query_string', :nonce => @nonce, :timestamp => @timestamp, :signature_method => 'PLAINTEXT'})
-
+
assert_equal 'GET', request.method
uri = URI.parse(request.path)
assert_equal '/test', uri.path
assert_equal nil, uri.fragment
assert_equal "key=value&oauth_consumer_key=consumer_key_86cad9&oauth_nonce=225579211881198842005988698334675835446&oauth_signature=5888bf0345e5d237%263196ffd991c8ebdb&oauth_signature_method=PLAINTEXT&oauth_timestamp=1199645624&oauth_token=token_411a7f&oauth_version=1.0", uri.query.split("&").sort.join("&")
assert_equal nil, request['authorization']
end
-
+
def test_that_using_post_params_works
request = Net::HTTP::Post.new(@request_uri.path)
request.set_form_data( @request_parameters )
request.oauth!(@http, @consumer, @token, {:scheme => 'body', :nonce => @nonce, :timestamp => @timestamp})
-
+
assert_equal 'POST', request.method
assert_equal '/test', request.path
assert_match /key=value&oauth_consumer_key=consumer_key_86cad9&oauth_nonce=225579211881198842005988698334675835446&oauth_signature=26g7wHTtNO6ZWJaLltcueppHYiI%3[Dd]&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1199645624&oauth_token=token_411a7f&oauth_version=1.0/, request.body.split("&").sort.join("&")
assert_equal nil, request['authorization']
end
-
+
def test_that_using_post_params_works_with_plaintext
request = Net::HTTP::Post.new(@request_uri.path)
request.set_form_data( @request_parameters )
request.oauth!(@http, @consumer, @token, {:scheme => 'body', :nonce => @nonce, :timestamp => @timestamp, :signature_method => 'PLAINTEXT'})
-
+
assert_equal 'POST', request.method
assert_equal '/test', request.path
assert_equal "key=value&oauth_consumer_key=consumer_key_86cad9&oauth_nonce=225579211881198842005988698334675835446&oauth_signature=5888bf0345e5d237%263196ffd991c8ebdb&oauth_signature_method=PLAINTEXT&oauth_timestamp=1199645624&oauth_token=token_411a7f&oauth_version=1.0", request.body.split("&").sort.join("&")
@@ -149,7 +149,7 @@ def test_that_using_post_body_works
assert_match /OAuth oauth_consumer_key="consumer_key_86cad9", oauth_nonce="225579211881198842005988698334675835446", oauth_signature="%2[fF]DMMBOJzQ6JmEaXlAXDLGtD1z2I%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1199645624", oauth_token="token_411a7f", oauth_version="1.0"/, request['authorization'].split("&").sort.join("&")
# assert_equal nil, request['authorization']
end
-
+
def test_that_using_post_with_uri_params_works
request = Net::HTTP::Post.new(@request_uri.path + "?" + request_parameters_to_s)
request.set_form_data( {} ) # just to make sure we have a correct mime type and thus no body hash
@@ -257,7 +257,7 @@ def test_that_put_bodies_not_signed_even_if_form_urlencoded
request = Net::HTTP::Put.new(@request_uri.path)
request.set_form_data( { 'key2' => 'value2' } )
signature_base_string=request.signature_base_string(@http, @consumer, nil, { :nonce => @nonce, :timestamp => @timestamp })
- assert_equal "PUT&http%3A%2F%2Fexample.com%2Ftest&oauth_consumer_key%3Dconsumer_key_86cad9%26oauth_nonce%3D225579211881198842005988698334675835446%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1199645624%26oauth_version%3D1.0", signature_base_string
+ assert_equal "PUT&http%3A%2F%2Fexample.com%2Ftest&key2%3Dvalue2%26oauth_consumer_key%3Dconsumer_key_86cad9%26oauth_nonce%3D225579211881198842005988698334675835446%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1199645624%26oauth_version%3D1.0", signature_base_string
end
def test_that_post_bodies_signed_if_form_urlencoded
@@ -52,7 +52,7 @@ def test_that_proxy_simple_put_request_works_with_form_data
request.set_form_data(params)
request_proxy = OAuth::RequestProxy.proxy(request, {:uri => 'http://example.com/test'})
- expected_parameters = {}
+ expected_parameters = {'key' => ['value']}
assert_equal expected_parameters, request_proxy.parameters_for_signature
assert_equal 'http://example.com/test', request_proxy.normalized_uri
assert_equal 'PUT', request_proxy.method

0 comments on commit 46a1633

Please sign in to comment.