mojodna-oauth 0.3.2.1 → 0.3.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/Manifest.txt +1 -0
- data/lib/oauth/consumer.rb +1 -0
- data/lib/oauth/helper.rb +3 -0
- data/lib/oauth/oauth.rb +1 -1
- data/lib/oauth/request_proxy/action_controller_request.rb +1 -1
- data/lib/oauth/version.rb +1 -1
- data/oauth.gemspec +3 -3
- data/test/test_action_controller_request_proxy.rb +91 -9
- data/test/test_net_http_client.rb +24 -24
- data/test/test_net_http_request_proxy.rb +43 -8
- data/test/test_oauth_helper.rb +43 -0
- data/test/test_signature.rb +19 -11
- metadata +3 -1
data/History.txt
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
== 0.3.3 / 0.4.0
|
2
2
|
|
3
3
|
* Corrected OAuth XMPP namespace (Seth)
|
4
|
+
* Improved error handling for invalid Authorization headers (Matt Sanford)
|
5
|
+
* Fixed signatures for non-ASCII under $KCODE other than 'u' (Matt Sanford)
|
6
|
+
* Fixed edge cases in ActionControllerRequestProxy where params were being
|
7
|
+
incorrectly signed (Marcos Wright Kuhns)
|
4
8
|
|
5
9
|
== 0.3.2 2009-03-23
|
6
10
|
|
data/Manifest.txt
CHANGED
data/lib/oauth/consumer.rb
CHANGED
data/lib/oauth/helper.rb
CHANGED
@@ -38,6 +38,9 @@ module OAuth
|
|
38
38
|
# decompose
|
39
39
|
params = header[6,header.length].split(/[,=]/)
|
40
40
|
|
41
|
+
# odd number of arguments - must be a malformed header.
|
42
|
+
raise OAuth::Problem.new("Invalid authorization header") if params.size % 2 != 0
|
43
|
+
|
41
44
|
# strip and unescape
|
42
45
|
params.map! { |v| unescape(v.strip) }
|
43
46
|
|
data/lib/oauth/oauth.rb
CHANGED
@@ -3,5 +3,5 @@ module OAuth
|
|
3
3
|
PARAMETERS = %w(oauth_consumer_key oauth_token oauth_signature_method oauth_timestamp oauth_nonce oauth_version oauth_signature)
|
4
4
|
|
5
5
|
# reserved character regexp, per section 5.1
|
6
|
-
RESERVED_CHARACTERS = /[
|
6
|
+
RESERVED_CHARACTERS = /[^a-zA-Z0-9\-\.\_\~]/
|
7
7
|
end
|
@@ -35,7 +35,7 @@ module OAuth::RequestProxy
|
|
35
35
|
unless options[:clobber_request]
|
36
36
|
params << header_params.to_query
|
37
37
|
params << request.query_string unless request.query_string.blank?
|
38
|
-
if request.content_type == Mime::Type.lookup("application/x-www-form-urlencoded")
|
38
|
+
if request.post? && request.content_type == Mime::Type.lookup("application/x-www-form-urlencoded")
|
39
39
|
params << request.raw_post
|
40
40
|
end
|
41
41
|
end
|
data/lib/oauth/version.rb
CHANGED
data/oauth.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{oauth}
|
5
|
-
s.version = "0.3.2.
|
5
|
+
s.version = "0.3.2.2"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Pelle Braendgaard", "Blaine Cook", "Larry Halff", "Jesse Clark", "Jon Crosby", "Seth Fitzsimmons"]
|
@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
|
|
12
12
|
s.email = %q{oauth-ruby@googlegroups.com}
|
13
13
|
s.executables = ["oauth"]
|
14
14
|
s.extra_rdoc_files = ["History.txt", "License.txt", "Manifest.txt", "README.rdoc", "website/index.txt"]
|
15
|
-
s.files = ["History.txt", "License.txt", "Manifest.txt", "README.rdoc", "Rakefile", "TODO", "bin/oauth", "examples/yql.rb", "lib/oauth.rb", "lib/oauth/oauth.rb", "lib/oauth/cli.rb", "lib/oauth/client.rb", "lib/oauth/client/action_controller_request.rb", "lib/oauth/client/helper.rb", "lib/oauth/client/net_http.rb", "lib/oauth/consumer.rb", "lib/oauth/errors.rb", "lib/oauth/errors/error.rb", "lib/oauth/errors/problem.rb", "lib/oauth/errors/unauthorized.rb", "lib/oauth/helper.rb", "lib/oauth/oauth_test_helper.rb", "lib/oauth/request_proxy.rb", "lib/oauth/request_proxy/action_controller_request.rb", "lib/oauth/request_proxy/base.rb", "lib/oauth/request_proxy/jabber_request.rb", "lib/oauth/request_proxy/mock_request.rb", "lib/oauth/request_proxy/net_http.rb", "lib/oauth/request_proxy/rack_request.rb", "lib/oauth/server.rb", "lib/oauth/signature.rb", "lib/oauth/signature/base.rb", "lib/oauth/signature/hmac/base.rb", "lib/oauth/signature/hmac/md5.rb", "lib/oauth/signature/hmac/rmd160.rb", "lib/oauth/signature/hmac/sha1.rb", "lib/oauth/signature/hmac/sha2.rb", "lib/oauth/signature/md5.rb", "lib/oauth/signature/plaintext.rb", "lib/oauth/signature/rsa/sha1.rb", "lib/oauth/signature/sha1.rb", "lib/oauth/token.rb", "lib/oauth/tokens/access_token.rb", "lib/oauth/tokens/consumer_token.rb", "lib/oauth/tokens/request_token.rb", "lib/oauth/tokens/server_token.rb", "lib/oauth/tokens/token.rb", "lib/oauth/version.rb", "oauth.gemspec", "script/destroy", "script/generate", "script/txt2html", "setup.rb", "tasks/deployment.rake", "tasks/environment.rake", "tasks/website.rake", "test/cases/oauth_case.rb", "test/cases/spec/1_0-final/test_construct_request_url.rb", "test/cases/spec/1_0-final/test_normalize_request_parameters.rb", "test/cases/spec/1_0-final/test_parameter_encodings.rb", "test/cases/spec/1_0-final/test_signature_base_strings.rb", "test/keys/rsa.cert", "test/keys/rsa.pem", "test/test_access_token.rb", "test/test_action_controller_request_proxy.rb", "test/test_consumer.rb", "test/test_helper.rb", "test/test_hmac_sha1.rb", "test/test_net_http_client.rb", "test/test_net_http_request_proxy.rb", "test/test_rack_request_proxy.rb", "test/test_request_token.rb", "test/test_rsa_sha1.rb", "test/test_server.rb", "test/test_signature.rb", "test/test_signature_base.rb", "test/test_signature_plain_text.rb", "test/test_token.rb", "website/index.html", "website/index.txt", "website/javascripts/rounded_corners_lite.inc.js", "website/stylesheets/screen.css", "website/template.rhtml"]
|
15
|
+
s.files = ["History.txt", "License.txt", "Manifest.txt", "README.rdoc", "Rakefile", "TODO", "bin/oauth", "examples/yql.rb", "lib/oauth.rb", "lib/oauth/oauth.rb", "lib/oauth/cli.rb", "lib/oauth/client.rb", "lib/oauth/client/action_controller_request.rb", "lib/oauth/client/helper.rb", "lib/oauth/client/net_http.rb", "lib/oauth/consumer.rb", "lib/oauth/errors.rb", "lib/oauth/errors/error.rb", "lib/oauth/errors/problem.rb", "lib/oauth/errors/unauthorized.rb", "lib/oauth/helper.rb", "lib/oauth/oauth_test_helper.rb", "lib/oauth/request_proxy.rb", "lib/oauth/request_proxy/action_controller_request.rb", "lib/oauth/request_proxy/base.rb", "lib/oauth/request_proxy/jabber_request.rb", "lib/oauth/request_proxy/mock_request.rb", "lib/oauth/request_proxy/net_http.rb", "lib/oauth/request_proxy/rack_request.rb", "lib/oauth/server.rb", "lib/oauth/signature.rb", "lib/oauth/signature/base.rb", "lib/oauth/signature/hmac/base.rb", "lib/oauth/signature/hmac/md5.rb", "lib/oauth/signature/hmac/rmd160.rb", "lib/oauth/signature/hmac/sha1.rb", "lib/oauth/signature/hmac/sha2.rb", "lib/oauth/signature/md5.rb", "lib/oauth/signature/plaintext.rb", "lib/oauth/signature/rsa/sha1.rb", "lib/oauth/signature/sha1.rb", "lib/oauth/token.rb", "lib/oauth/tokens/access_token.rb", "lib/oauth/tokens/consumer_token.rb", "lib/oauth/tokens/request_token.rb", "lib/oauth/tokens/server_token.rb", "lib/oauth/tokens/token.rb", "lib/oauth/version.rb", "oauth.gemspec", "script/destroy", "script/generate", "script/txt2html", "setup.rb", "tasks/deployment.rake", "tasks/environment.rake", "tasks/website.rake", "test/cases/oauth_case.rb", "test/cases/spec/1_0-final/test_construct_request_url.rb", "test/cases/spec/1_0-final/test_normalize_request_parameters.rb", "test/cases/spec/1_0-final/test_parameter_encodings.rb", "test/cases/spec/1_0-final/test_signature_base_strings.rb", "test/keys/rsa.cert", "test/keys/rsa.pem", "test/test_access_token.rb", "test/test_action_controller_request_proxy.rb", "test/test_consumer.rb", "test/test_helper.rb", "test/test_hmac_sha1.rb", "test/test_net_http_client.rb", "test/test_net_http_request_proxy.rb", "test/test_oauth_helper.rb", "test/test_rack_request_proxy.rb", "test/test_request_token.rb", "test/test_rsa_sha1.rb", "test/test_server.rb", "test/test_signature.rb", "test/test_signature_base.rb", "test/test_signature_plain_text.rb", "test/test_token.rb", "website/index.html", "website/index.txt", "website/javascripts/rounded_corners_lite.inc.js", "website/stylesheets/screen.css", "website/template.rhtml"]
|
16
16
|
s.has_rdoc = true
|
17
17
|
s.homepage = %q{http://oauth.rubyforge.org}
|
18
18
|
s.rdoc_options = ["--main", "README.rdoc"]
|
@@ -20,7 +20,7 @@ Gem::Specification.new do |s|
|
|
20
20
|
s.rubyforge_project = %q{oauth}
|
21
21
|
s.rubygems_version = %q{1.3.1}
|
22
22
|
s.summary = %q{OAuth Core Ruby implementation}
|
23
|
-
s.test_files = ["test/cases/spec/1_0-final/test_construct_request_url.rb", "test/cases/spec/1_0-final/test_normalize_request_parameters.rb", "test/cases/spec/1_0-final/test_parameter_encodings.rb", "test/cases/spec/1_0-final/test_signature_base_strings.rb", "test/test_access_token.rb", "test/test_action_controller_request_proxy.rb", "test/test_consumer.rb", "test/test_helper.rb", "test/test_hmac_sha1.rb", "test/test_net_http_client.rb", "test/test_net_http_request_proxy.rb", "test/test_rack_request_proxy.rb", "test/test_request_token.rb", "test/test_rsa_sha1.rb", "test/test_server.rb", "test/test_signature.rb", "test/test_signature_base.rb", "test/test_signature_plain_text.rb", "test/test_token.rb"]
|
23
|
+
s.test_files = ["test/cases/spec/1_0-final/test_construct_request_url.rb", "test/cases/spec/1_0-final/test_normalize_request_parameters.rb", "test/cases/spec/1_0-final/test_parameter_encodings.rb", "test/cases/spec/1_0-final/test_signature_base_strings.rb", "test/test_access_token.rb", "test/test_action_controller_request_proxy.rb", "test/test_consumer.rb", "test/test_helper.rb", "test/test_hmac_sha1.rb", "test/test_net_http_client.rb", "test/test_net_http_request_proxy.rb", "test/test_oauth_helper.rb", "test/test_rack_request_proxy.rb", "test/test_request_token.rb", "test/test_rsa_sha1.rb", "test/test_server.rb", "test/test_signature.rb", "test/test_signature_base.rb", "test/test_signature_plain_text.rb", "test/test_token.rb"]
|
24
24
|
|
25
25
|
if s.respond_to? :specification_version then
|
26
26
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
@@ -5,34 +5,116 @@ require 'action_controller/test_process'
|
|
5
5
|
|
6
6
|
class ActionControllerRequestProxyTest < Test::Unit::TestCase
|
7
7
|
|
8
|
-
def request_proxy(
|
9
|
-
request = ActionController::TestRequest.new
|
8
|
+
def request_proxy(request_method = :get, uri_params = {}, body_params = {})
|
9
|
+
request = ActionController::TestRequest.new
|
10
|
+
|
11
|
+
case request_method
|
12
|
+
when :post
|
13
|
+
request.env['REQUEST_METHOD'] = 'POST'
|
14
|
+
when :put
|
15
|
+
request.env['REQUEST_METHOD'] = 'PUT'
|
16
|
+
end
|
17
|
+
|
18
|
+
request.env['RAW_POST_DATA'] = body_params.to_query
|
10
19
|
request.env['CONTENT_TYPE'] = 'application/x-www-form-urlencoded'
|
20
|
+
|
11
21
|
yield request if block_given?
|
12
|
-
OAuth::RequestProxy.proxy(request)
|
22
|
+
OAuth::RequestProxy.proxy(request, :parameters=>uri_params)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_that_proxy_simple_get_request_works_with_query_params
|
26
|
+
request_proxy = request_proxy(:get, {'key'=>'value'})
|
27
|
+
|
28
|
+
expected_parameters = [["key", "value"]]
|
29
|
+
assert_equal expected_parameters, request_proxy.parameters_for_signature
|
30
|
+
assert_equal 'GET', request_proxy.method
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_that_proxy_simple_post_request_works_with_query_params
|
34
|
+
request_proxy = request_proxy(:post, {'key'=>'value'})
|
35
|
+
|
36
|
+
expected_parameters = [["key", "value"]]
|
37
|
+
assert_equal expected_parameters, request_proxy.parameters_for_signature
|
38
|
+
assert_equal 'POST', request_proxy.method
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_that_proxy_simple_put_request_works_with_query_params
|
42
|
+
request_proxy = request_proxy(:put, {'key'=>'value'})
|
43
|
+
|
44
|
+
expected_parameters = [["key", "value"]]
|
45
|
+
assert_equal expected_parameters, request_proxy.parameters_for_signature
|
46
|
+
assert_equal 'PUT', request_proxy.method
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_that_proxy_simple_put_request_works_with_post_params
|
50
|
+
request_proxy = request_proxy(:get, {}, {'key'=>'value'})
|
51
|
+
|
52
|
+
expected_parameters = []
|
53
|
+
assert_equal expected_parameters, request_proxy.parameters_for_signature
|
54
|
+
assert_equal 'GET', request_proxy.method
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_that_proxy_simple_post_request_works_with_post_params
|
58
|
+
request_proxy = request_proxy(:post, {}, {'key'=>'value'})
|
59
|
+
|
60
|
+
expected_parameters = [["key", "value"]]
|
61
|
+
assert_equal expected_parameters, request_proxy.parameters_for_signature
|
62
|
+
assert_equal 'POST', request_proxy.method
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_that_proxy_simple_put_request_works_with_post_params
|
66
|
+
request_proxy = request_proxy(:put, {}, {'key'=>'value'})
|
67
|
+
|
68
|
+
expected_parameters = []
|
69
|
+
assert_equal expected_parameters, request_proxy.parameters_for_signature
|
70
|
+
assert_equal 'PUT', request_proxy.method
|
13
71
|
end
|
14
|
-
|
72
|
+
|
73
|
+
def test_that_proxy_simple_put_request_works_with_mixed_params
|
74
|
+
request_proxy = request_proxy(:get, {'key'=>'value'}, {'key2'=>'value2'})
|
75
|
+
|
76
|
+
expected_parameters = [["key", "value"]]
|
77
|
+
assert_equal expected_parameters, request_proxy.parameters_for_signature
|
78
|
+
assert_equal 'GET', request_proxy.method
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_that_proxy_simple_post_request_works_with_mixed_params
|
82
|
+
request_proxy = request_proxy(:post, {'key'=>'value'}, {'key2'=>'value2'})
|
83
|
+
|
84
|
+
expected_parameters = [["key", "value"],["key2", "value2"]]
|
85
|
+
assert_equal expected_parameters, request_proxy.parameters_for_signature
|
86
|
+
assert_equal 'POST', request_proxy.method
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_that_proxy_simple_put_request_works_with_mixed_params
|
90
|
+
request_proxy = request_proxy(:put, {'key'=>'value'}, {'key2'=>'value2'})
|
91
|
+
|
92
|
+
expected_parameters = [["key", "value"]]
|
93
|
+
assert_equal expected_parameters, request_proxy.parameters_for_signature
|
94
|
+
assert_equal 'PUT', request_proxy.method
|
95
|
+
end
|
96
|
+
|
15
97
|
def test_parameter_keys_should_preserve_brackets_from_hash
|
16
98
|
assert_equal(
|
17
99
|
[["message[body]", "This is a test"]],
|
18
|
-
request_proxy({ :message => { :body => 'This is a test' }}).parameters_for_signature
|
100
|
+
request_proxy(:post, { :message => { :body => 'This is a test' }}).parameters_for_signature
|
19
101
|
)
|
20
102
|
end
|
21
|
-
|
103
|
+
|
22
104
|
def test_parameter_values_with_amps_should_not_break_parameter_parsing
|
23
105
|
assert_equal(
|
24
106
|
[['message[body]', 'http://foo.com/?a=b&c=d']],
|
25
|
-
request_proxy({ :message => { :body => 'http://foo.com/?a=b&c=d'}}).parameters_for_signature
|
107
|
+
request_proxy(:post, { :message => { :body => 'http://foo.com/?a=b&c=d'}}).parameters_for_signature
|
26
108
|
)
|
27
109
|
end
|
28
110
|
|
29
111
|
def test_parameter_keys_should_preserve_brackets_from_array
|
30
112
|
assert_equal(
|
31
113
|
[["foo[]", "123"], ["foo[]", "456"]],
|
32
|
-
request_proxy({ :foo => [123, 456] }).parameters_for_signature.sort
|
114
|
+
request_proxy(:post, { :foo => [123, 456] }).parameters_for_signature.sort
|
33
115
|
)
|
34
116
|
end
|
35
|
-
|
117
|
+
|
36
118
|
def test_query_string_parameter_values_should_be_cgi_unescaped
|
37
119
|
request = request_proxy do |r|
|
38
120
|
r.env['QUERY_STRING'] = 'url=http%3A%2F%2Ffoo.com%2F%3Fa%3Db%26c%3Dd'
|
@@ -16,7 +16,7 @@ class NetHTTPClientTest < Test::Unit::TestCase
|
|
16
16
|
def test_that_using_auth_headers_on_get_requests_works
|
17
17
|
request = Net::HTTP::Get.new(@request_uri.path + "?" + request_parameters_to_s)
|
18
18
|
request.oauth!(@http, @consumer, @token, {:nonce => @nonce, :timestamp => @timestamp})
|
19
|
-
|
19
|
+
|
20
20
|
assert_equal 'GET', request.method
|
21
21
|
assert_equal '/test?key=value', request.path
|
22
22
|
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
|
@@ -32,17 +32,6 @@ class NetHTTPClientTest < Test::Unit::TestCase
|
|
32
32
|
assert_equal 'key=value', request.body
|
33
33
|
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
|
34
34
|
end
|
35
|
-
|
36
|
-
def test_that_using_post_params_works
|
37
|
-
request = Net::HTTP::Post.new(@request_uri.path)
|
38
|
-
request.set_form_data( @request_parameters )
|
39
|
-
request.oauth!(@http, @consumer, @token, {:scheme => 'body', :nonce => @nonce, :timestamp => @timestamp})
|
40
|
-
|
41
|
-
assert_equal 'POST', request.method
|
42
|
-
assert_equal '/test', request.path
|
43
|
-
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("&")
|
44
|
-
assert_equal nil, request['authorization']
|
45
|
-
end
|
46
35
|
|
47
36
|
def test_that_using_get_params_works
|
48
37
|
request = Net::HTTP::Get.new(@request_uri.path + "?" + request_parameters_to_s)
|
@@ -56,7 +45,18 @@ class NetHTTPClientTest < Test::Unit::TestCase
|
|
56
45
|
assert_equal nil, request['authorization']
|
57
46
|
end
|
58
47
|
|
59
|
-
def
|
48
|
+
def test_that_using_post_params_works
|
49
|
+
request = Net::HTTP::Post.new(@request_uri.path)
|
50
|
+
request.set_form_data( @request_parameters )
|
51
|
+
request.oauth!(@http, @consumer, @token, {:scheme => 'body', :nonce => @nonce, :timestamp => @timestamp})
|
52
|
+
|
53
|
+
assert_equal 'POST', request.method
|
54
|
+
assert_equal '/test', request.path
|
55
|
+
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("&")
|
56
|
+
assert_equal nil, request['authorization']
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_that_using_post_with_uri_params_works
|
60
60
|
request = Net::HTTP::Post.new(@request_uri.path + "?" + request_parameters_to_s)
|
61
61
|
request.oauth!(@http, @consumer, @token, {:scheme => 'query_string', :nonce => @nonce, :timestamp => @timestamp})
|
62
62
|
|
@@ -69,7 +69,7 @@ class NetHTTPClientTest < Test::Unit::TestCase
|
|
69
69
|
assert_equal nil, request['authorization']
|
70
70
|
end
|
71
71
|
|
72
|
-
def
|
72
|
+
def test_that_using_post_with_uri_and_form_params_works
|
73
73
|
request = Net::HTTP::Post.new(@request_uri.path + "?" + request_parameters_to_s)
|
74
74
|
request.set_form_data( { 'key2' => 'value2' } )
|
75
75
|
request.oauth!(@http, @consumer, @token, {:scheme => :query_string, :nonce => @nonce, :timestamp => @timestamp})
|
@@ -82,8 +82,8 @@ class NetHTTPClientTest < Test::Unit::TestCase
|
|
82
82
|
assert_equal "key2=value2", request.body
|
83
83
|
assert_equal nil, request['authorization']
|
84
84
|
end
|
85
|
-
|
86
|
-
|
85
|
+
|
86
|
+
|
87
87
|
def test_example_from_specs
|
88
88
|
consumer=OAuth::Consumer.new("dpf43f3p2l4k3l03","kd94hf93k423kf44")
|
89
89
|
token = OAuth::Token.new('nnch734d00sl2jdk', 'pfkkdhi9sl3r4s00')
|
@@ -101,22 +101,22 @@ class NetHTTPClientTest < Test::Unit::TestCase
|
|
101
101
|
|
102
102
|
assert_equal 'GET', request.method
|
103
103
|
assert_equal 'OAuth realm="http://photos.example.net/", oauth_nonce="kllo9940pd9333jh", oauth_signature_method="HMAC-SHA1", oauth_token="nnch734d00sl2jdk", oauth_timestamp="1191242096", oauth_consumer_key="dpf43f3p2l4k3l03", oauth_signature="tR3%2BTy81lMeYAr%2FFid0kMTYa%2FWM%3D", oauth_version="1.0"'.split(', ').sort, request['authorization'].split(', ').sort
|
104
|
-
|
104
|
+
|
105
105
|
end
|
106
|
-
|
106
|
+
|
107
107
|
def test_step_by_step_token_request
|
108
|
-
consumer=OAuth::Consumer.new(
|
108
|
+
consumer=OAuth::Consumer.new(
|
109
109
|
"key",
|
110
110
|
"secret")
|
111
111
|
request_uri = URI.parse('http://term.ie/oauth/example/request_token.php')
|
112
112
|
nonce = rand(2**128).to_s
|
113
113
|
timestamp = Time.now.to_i.to_s
|
114
114
|
http = Net::HTTP.new(request_uri.host, request_uri.port)
|
115
|
-
|
115
|
+
|
116
116
|
request = Net::HTTP::Get.new(request_uri.path)
|
117
117
|
signature_base_string=request.signature_base_string(http, consumer, nil, {:scheme=>:query_string,:nonce => nonce, :timestamp => timestamp})
|
118
118
|
assert_equal "GET&http%3A%2F%2Fterm.ie%2Foauth%2Fexample%2Frequest_token.php&oauth_consumer_key%3Dkey%26oauth_nonce%3D#{nonce}%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D#{timestamp}%26oauth_version%3D1.0",signature_base_string
|
119
|
-
|
119
|
+
|
120
120
|
# request = Net::HTTP::Get.new(request_uri.path)
|
121
121
|
request.oauth!(http, consumer, nil, {:scheme=>:query_string,:nonce => nonce, :timestamp => timestamp})
|
122
122
|
assert_equal 'GET', request.method
|
@@ -129,7 +129,7 @@ class NetHTTPClientTest < Test::Unit::TestCase
|
|
129
129
|
# assert_equal request['authorization'],response.body
|
130
130
|
assert_equal "oauth_token=requestkey&oauth_token_secret=requestsecret",response.body
|
131
131
|
end
|
132
|
-
|
132
|
+
|
133
133
|
def test_that_put_bodies_not_signed
|
134
134
|
request = Net::HTTP::Put.new(@request_uri.path)
|
135
135
|
request.body = "<?xml version=\"1.0\"?><foo><bar>baz</bar></foo>"
|
@@ -144,14 +144,14 @@ class NetHTTPClientTest < Test::Unit::TestCase
|
|
144
144
|
signature_base_string=request.signature_base_string(@http, @consumer, nil, { :nonce => @nonce, :timestamp => @timestamp })
|
145
145
|
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
|
146
146
|
end
|
147
|
-
|
147
|
+
|
148
148
|
def test_that_post_bodies_signed_if_form_urlencoded
|
149
149
|
request = Net::HTTP::Post.new(@request_uri.path)
|
150
150
|
request.set_form_data( { 'key2' => 'value2' } )
|
151
151
|
signature_base_string=request.signature_base_string(@http, @consumer, nil, { :nonce => @nonce, :timestamp => @timestamp })
|
152
152
|
assert_equal "POST&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
|
153
153
|
end
|
154
|
-
|
154
|
+
|
155
155
|
def test_that_post_bodies_not_signed_if_other_content_type
|
156
156
|
request = Net::HTTP::Post.new(@request_uri.path)
|
157
157
|
request.body = "<?xml version=\"1.0\"?><foo><bar>baz</bar></foo>"
|
@@ -8,29 +8,64 @@ class NetHTTPRequestProxyTest < Test::Unit::TestCase
|
|
8
8
|
request_proxy = OAuth::RequestProxy.proxy(request, {:uri => 'http://example.com/test?key=value'})
|
9
9
|
|
10
10
|
expected_parameters = {'key' => ['value']}
|
11
|
-
assert_equal expected_parameters, request_proxy.
|
11
|
+
assert_equal expected_parameters, request_proxy.parameters_for_signature
|
12
12
|
assert_equal 'http://example.com/test', request_proxy.normalized_uri
|
13
13
|
assert_equal 'GET', request_proxy.method
|
14
14
|
end
|
15
15
|
|
16
|
-
def
|
16
|
+
def test_that_proxy_simple_post_request_works_with_arguments
|
17
17
|
request = Net::HTTP::Post.new('/test')
|
18
18
|
params = {'key' => 'value'}
|
19
19
|
request_proxy = OAuth::RequestProxy.proxy(request, {:uri => 'http://example.com/test', :parameters => params})
|
20
20
|
|
21
21
|
expected_parameters = {'key' => ['value']}
|
22
|
-
assert_equal expected_parameters, request_proxy.
|
22
|
+
assert_equal expected_parameters, request_proxy.parameters_for_signature
|
23
23
|
assert_equal 'http://example.com/test', request_proxy.normalized_uri
|
24
24
|
assert_equal 'POST', request_proxy.method
|
25
25
|
end
|
26
26
|
|
27
|
-
def
|
27
|
+
def test_that_proxy_simple_post_request_works_with_form_data
|
28
|
+
request = Net::HTTP::Post.new('/test')
|
29
|
+
params = {'key' => 'value'}
|
30
|
+
request.set_form_data(params)
|
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
|
+
assert_equal 'POST', request_proxy.method
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_that_proxy_simple_put_request_works_with_argugments
|
40
|
+
request = Net::HTTP::Put.new('/test')
|
41
|
+
params = {'key' => 'value'}
|
42
|
+
request_proxy = OAuth::RequestProxy.proxy(request, {:uri => 'http://example.com/test', :parameters => params})
|
43
|
+
|
44
|
+
expected_parameters = {'key' => ['value']}
|
45
|
+
assert_equal expected_parameters, request_proxy.parameters_for_signature
|
46
|
+
assert_equal 'http://example.com/test', request_proxy.normalized_uri
|
47
|
+
assert_equal 'PUT', request_proxy.method
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_that_proxy_simple_put_request_works_with_form_data
|
51
|
+
request = Net::HTTP::Put.new('/test')
|
52
|
+
params = {'key' => 'value'}
|
53
|
+
request.set_form_data(params)
|
54
|
+
request_proxy = OAuth::RequestProxy.proxy(request, {:uri => 'http://example.com/test'})
|
55
|
+
|
56
|
+
expected_parameters = {}
|
57
|
+
assert_equal expected_parameters, request_proxy.parameters_for_signature
|
58
|
+
assert_equal 'http://example.com/test', request_proxy.normalized_uri
|
59
|
+
assert_equal 'PUT', request_proxy.method
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_that_proxy_post_request_works_with_mixed_parameter_sources
|
28
63
|
request = Net::HTTP::Post.new('/test?key=value')
|
29
|
-
|
30
|
-
request_proxy = OAuth::RequestProxy.proxy(request, {:uri => 'http://example.com/test?key=value', :parameters =>
|
64
|
+
request.set_form_data({'key2' => 'value2'})
|
65
|
+
request_proxy = OAuth::RequestProxy.proxy(request, {:uri => 'http://example.com/test?key=value', :parameters => {'key3' => 'value3'}})
|
31
66
|
|
32
|
-
expected_parameters = {'key' => ['value'], 'key2' => ['value2']}
|
33
|
-
assert_equal expected_parameters, request_proxy.
|
67
|
+
expected_parameters = {'key' => ['value'], 'key2' => ['value2'], 'key3' => ['value3']}
|
68
|
+
assert_equal expected_parameters, request_proxy.parameters_for_signature
|
34
69
|
assert_equal 'http://example.com/test', request_proxy.normalized_uri
|
35
70
|
assert_equal 'POST', request_proxy.method
|
36
71
|
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
require 'oauth/helper'
|
3
|
+
|
4
|
+
class TestOAuthHelper < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def test_parse_valid_header
|
7
|
+
header = 'OAuth ' \
|
8
|
+
'realm="http://example.com/method", ' \
|
9
|
+
'oauth_consumer_key="vince_clortho", ' \
|
10
|
+
'oauth_token="token_value", ' \
|
11
|
+
'oauth_signature_method="HMAC-SHA1", ' \
|
12
|
+
'oauth_signature="signature_here", ' \
|
13
|
+
'oauth_timestamp="1240004133", oauth_nonce="nonce", ' \
|
14
|
+
'oauth_version="1.0" '
|
15
|
+
|
16
|
+
params = OAuth::Helper.parse_header(header)
|
17
|
+
|
18
|
+
assert_equal "http://example.com/method", params['realm']
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_parse_header_ill_formed
|
22
|
+
header = "OAuth garbage"
|
23
|
+
|
24
|
+
assert_raise OAuth::Problem do
|
25
|
+
OAuth::Helper.parse_header(header)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_parse_header_contains_equals
|
30
|
+
header = 'OAuth ' \
|
31
|
+
'realm="http://example.com/method", ' \
|
32
|
+
'oauth_consumer_key="vince_clortho", ' \
|
33
|
+
'oauth_token="token_value", ' \
|
34
|
+
'oauth_signature_method="HMAC-SHA1", ' \
|
35
|
+
'oauth_signature="signature_here_with_=", ' \
|
36
|
+
'oauth_timestamp="1240004133", oauth_nonce="nonce", ' \
|
37
|
+
'oauth_version="1.0" '
|
38
|
+
|
39
|
+
assert_raise OAuth::Problem do
|
40
|
+
OAuth::Helper.parse_header(header)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/test/test_signature.rb
CHANGED
@@ -1,11 +1,19 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
-
|
3
|
-
class TestOauth < Test::Unit::TestCase
|
4
|
-
|
5
|
-
def
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
|
3
|
+
class TestOauth < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_parameter_escaping_kcode_invariant
|
6
|
+
old = $KCODE
|
7
|
+
begin
|
8
|
+
%w(n N e E s S u U).each do |kcode|
|
9
|
+
$KCODE = kcode
|
10
|
+
assert_equal '%E3%81%82', OAuth::Helper.escape('あ'),
|
11
|
+
"Failed to correctly escape Japanese under $KCODE = #{kcode}"
|
12
|
+
assert_equal '%C3%A9', OAuth::Helper.escape('é'),
|
13
|
+
"Failed to correctly escape e+acute under $KCODE = #{kcode}"
|
14
|
+
end
|
15
|
+
ensure
|
16
|
+
$KCODE = old
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mojodna-oauth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.2.
|
4
|
+
version: 0.3.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pelle Braendgaard
|
@@ -150,6 +150,7 @@ files:
|
|
150
150
|
- test/test_hmac_sha1.rb
|
151
151
|
- test/test_net_http_client.rb
|
152
152
|
- test/test_net_http_request_proxy.rb
|
153
|
+
- test/test_oauth_helper.rb
|
153
154
|
- test/test_rack_request_proxy.rb
|
154
155
|
- test/test_request_token.rb
|
155
156
|
- test/test_rsa_sha1.rb
|
@@ -202,6 +203,7 @@ test_files:
|
|
202
203
|
- test/test_hmac_sha1.rb
|
203
204
|
- test/test_net_http_client.rb
|
204
205
|
- test/test_net_http_request_proxy.rb
|
206
|
+
- test/test_oauth_helper.rb
|
205
207
|
- test/test_rack_request_proxy.rb
|
206
208
|
- test/test_request_token.rb
|
207
209
|
- test/test_rsa_sha1.rb
|