Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Update gem deps and fix tests

  • Loading branch information...
commit 46a163317b4c9a1a46c2365ace64eeab6ecc06a0 1 parent f2ba71d
Aaron Quint quirkey authored
43 Gemfile.lock
... ... @@ -1,35 +1,36 @@
1 1 GEM
2 2 remote: http://rubygems.org/
3 3 specs:
4   - actionpack (2.3.8)
5   - activesupport (= 2.3.8)
  4 + actionpack (2.3.14)
  5 + activesupport (= 2.3.14)
6 6 rack (~> 1.1.0)
7   - activesupport (2.3.8)
8   - addressable (2.2.0)
9   - crack (0.1.8)
10   - curb (0.7.7.1)
  7 + activesupport (2.3.14)
  8 + addressable (2.2.7)
  9 + crack (0.3.1)
  10 + curb (0.8.0)
11 11 em-http-request (0.2.11)
12 12 addressable (>= 2.0.0)
13 13 eventmachine (>= 0.12.9)
14 14 eventmachine (0.12.10)
15   - gemcutter (0.4.1)
16   - json_pure
17 15 git (1.2.5)
18   - jeweler (1.4.0)
19   - gemcutter (>= 0.1.0)
  16 + jeweler (1.8.3)
  17 + bundler (~> 1.0)
20 18 git (>= 1.2.5)
21   - rubyforge (>= 2.0.0)
22   - json_pure (1.4.3)
23   - mocha (0.9.8)
24 19 rake
25   - rack (1.1.0)
26   - rake (0.8.7)
27   - rubyforge (2.0.4)
28   - json_pure (>= 1.1.7)
29   - typhoeus (0.1.31)
30   - rack
31   - webmock (1.3.5)
32   - addressable (>= 2.1.1)
  20 + rdoc
  21 + json (1.6.6)
  22 + metaclass (0.0.1)
  23 + mime-types (1.18)
  24 + mocha (0.11.1)
  25 + metaclass (~> 0.0.1)
  26 + rack (1.1.3)
  27 + rake (0.9.2.2)
  28 + rdoc (3.12)
  29 + json (~> 1.4)
  30 + typhoeus (0.3.3)
  31 + mime-types
  32 + webmock (1.8.6)
  33 + addressable (>= 2.2.7)
33 34 crack (>= 0.1.7)
34 35
35 36 PLATFORMS
4 test/test_helper.rb
@@ -5,9 +5,11 @@
5 5 require 'oauth'
6 6 require 'mocha'
7 7 require 'stringio'
8   -require 'webmock/test_unit'
  8 +require 'webmock'
9 9
10 10 class Test::Unit::TestCase
  11 + include WebMock::API
  12 +
11 13 def assert_matching_headers(expected, actual)
12 14 # transform into sorted arrays
13 15 auth_intro, auth_params = actual.split(' ', 2)
46 test/test_net_http_client.rb
@@ -15,7 +15,7 @@ def setup
15 15 def test_that_using_auth_headers_on_get_requests_works
16 16 request = Net::HTTP::Get.new(@request_uri.path + "?" + request_parameters_to_s)
17 17 request.oauth!(@http, @consumer, @token, {:nonce => @nonce, :timestamp => @timestamp})
18   -
  18 +
19 19 assert_equal 'GET', request.method
20 20 assert_equal '/test?key=value', request.path
21 21 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\""
@@ -23,7 +23,7 @@ def test_that_using_auth_headers_on_get_requests_works
23 23 assert_equal auth_intro, 'OAuth'
24 24 assert_matching_headers correct_sorted_params, request['authorization']
25 25 end
26   -
  26 +
27 27 def test_that_using_auth_headers_on_get_requests_works_with_plaintext
28 28 require 'oauth/signature/plaintext'
29 29 c = OAuth::Consumer.new('consumer_key_86cad9', '5888bf0345e5d237',{
@@ -31,71 +31,71 @@ def test_that_using_auth_headers_on_get_requests_works_with_plaintext
31 31 })
32 32 request = Net::HTTP::Get.new(@request_uri.path + "?" + request_parameters_to_s)
33 33 request.oauth!(@http, c, @token, {:nonce => @nonce, :timestamp => @timestamp, :signature_method => 'PLAINTEXT'})
34   -
  34 +
35 35 assert_equal 'GET', request.method
36 36 assert_equal '/test?key=value', request.path
37 37 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']
38 38 end
39   -
  39 +
40 40 def test_that_using_auth_headers_on_post_requests_works
41 41 request = Net::HTTP::Post.new(@request_uri.path)
42 42 request.set_form_data( @request_parameters )
43 43 request.oauth!(@http, @consumer, @token, {:nonce => @nonce, :timestamp => @timestamp})
44   -
  44 +
45 45 assert_equal 'POST', request.method
46 46 assert_equal '/test', request.path
47 47 assert_equal 'key=value', request.body
48 48 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\""
49 49 assert_matching_headers correct_sorted_params, request['authorization']
50 50 end
51   -
  51 +
52 52 def test_that_using_auth_headers_on_post_requests_with_data_works
53 53 request = Net::HTTP::Post.new(@request_uri.path)
54 54 request.body = "data"
55 55 request.content_type = 'text/ascii'
56 56 request.oauth!(@http, @consumer, @token, {:nonce => @nonce, :timestamp => @timestamp})
57   -
  57 +
58 58 assert_equal 'POST', request.method
59 59 assert_equal '/test', request.path
60 60 assert_equal 'data', request.body
61 61 assert_equal 'text/ascii', request.content_type
62 62 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']
63 63 end
64   -
  64 +
65 65 def test_that_body_hash_is_obmitted_when_no_algorithm_is_defined
66 66 request = Net::HTTP::Post.new(@request_uri.path)
67 67 request.body = "data"
68 68 request.content_type = 'text/ascii'
69 69 request.oauth!(@http, @consumer, @token, {:nonce => @nonce, :timestamp => @timestamp, :signature_method => 'plaintext'})
70   -
  70 +
71 71 assert_equal 'POST', request.method
72 72 assert_equal '/test', request.path
73 73 assert_equal 'data', request.body
74 74 assert_equal 'text/ascii', request.content_type
75 75 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']
76 76 end
77   -
  77 +
78 78 def test_that_version_is_added_to_existing_user_agent
79 79 request = Net::HTTP::Post.new(@request_uri.path)
80 80 request['User-Agent'] = "MyApp"
81 81 request.set_form_data( @request_parameters )
82 82 request.oauth!(@http, @consumer, @token, {:nonce => @nonce, :timestamp => @timestamp})
83   -
  83 +
84 84 assert_equal "MyApp (OAuth gem v#{OAuth::VERSION})", request['User-Agent']
85 85 end
86   -
  86 +
87 87 def test_that_version_is_set_when_no_user_agent
88 88 request = Net::HTTP::Post.new(@request_uri.path)
89 89 request.set_form_data( @request_parameters )
90 90 request.oauth!(@http, @consumer, @token, {:nonce => @nonce, :timestamp => @timestamp})
91   -
  91 +
92 92 assert_equal "OAuth gem v#{OAuth::VERSION}", request['User-Agent']
93 93 end
94   -
  94 +
95 95 def test_that_using_get_params_works
96 96 request = Net::HTTP::Get.new(@request_uri.path + "?" + request_parameters_to_s)
97 97 request.oauth!(@http, @consumer, @token, {:scheme => 'query_string', :nonce => @nonce, :timestamp => @timestamp})
98   -
  98 +
99 99 assert_equal 'GET', request.method
100 100 uri = URI.parse(request.path)
101 101 assert_equal '/test', uri.path
@@ -103,11 +103,11 @@ def test_that_using_get_params_works
103 103 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("&")
104 104 assert_equal nil, request['authorization']
105 105 end
106   -
  106 +
107 107 def test_that_using_get_params_works_with_plaintext
108 108 request = Net::HTTP::Get.new(@request_uri.path + "?" + request_parameters_to_s)
109 109 request.oauth!(@http, @consumer, @token, {:scheme => 'query_string', :nonce => @nonce, :timestamp => @timestamp, :signature_method => 'PLAINTEXT'})
110   -
  110 +
111 111 assert_equal 'GET', request.method
112 112 uri = URI.parse(request.path)
113 113 assert_equal '/test', uri.path
@@ -115,23 +115,23 @@ def test_that_using_get_params_works_with_plaintext
115 115 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("&")
116 116 assert_equal nil, request['authorization']
117 117 end
118   -
  118 +
119 119 def test_that_using_post_params_works
120 120 request = Net::HTTP::Post.new(@request_uri.path)
121 121 request.set_form_data( @request_parameters )
122 122 request.oauth!(@http, @consumer, @token, {:scheme => 'body', :nonce => @nonce, :timestamp => @timestamp})
123   -
  123 +
124 124 assert_equal 'POST', request.method
125 125 assert_equal '/test', request.path
126 126 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("&")
127 127 assert_equal nil, request['authorization']
128 128 end
129   -
  129 +
130 130 def test_that_using_post_params_works_with_plaintext
131 131 request = Net::HTTP::Post.new(@request_uri.path)
132 132 request.set_form_data( @request_parameters )
133 133 request.oauth!(@http, @consumer, @token, {:scheme => 'body', :nonce => @nonce, :timestamp => @timestamp, :signature_method => 'PLAINTEXT'})
134   -
  134 +
135 135 assert_equal 'POST', request.method
136 136 assert_equal '/test', request.path
137 137 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
149 149 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("&")
150 150 # assert_equal nil, request['authorization']
151 151 end
152   -
  152 +
153 153 def test_that_using_post_with_uri_params_works
154 154 request = Net::HTTP::Post.new(@request_uri.path + "?" + request_parameters_to_s)
155 155 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
257 257 request = Net::HTTP::Put.new(@request_uri.path)
258 258 request.set_form_data( { 'key2' => 'value2' } )
259 259 signature_base_string=request.signature_base_string(@http, @consumer, nil, { :nonce => @nonce, :timestamp => @timestamp })
260   - 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
  260 + 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
261 261 end
262 262
263 263 def test_that_post_bodies_signed_if_form_urlencoded
2  test/test_net_http_request_proxy.rb
@@ -52,7 +52,7 @@ def test_that_proxy_simple_put_request_works_with_form_data
52 52 request.set_form_data(params)
53 53 request_proxy = OAuth::RequestProxy.proxy(request, {:uri => 'http://example.com/test'})
54 54
55   - expected_parameters = {}
  55 + expected_parameters = {'key' => ['value']}
56 56 assert_equal expected_parameters, request_proxy.parameters_for_signature
57 57 assert_equal 'http://example.com/test', request_proxy.normalized_uri
58 58 assert_equal 'PUT', request_proxy.method

0 comments on commit 46a1633

Please sign in to comment.
Something went wrong with that request. Please try again.