oauth 0.3.6 → 0.3.7.pre1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of oauth might be problematic. Click here for more details.
- data/.gitignore +1 -0
- data/History.txt +16 -0
- data/Manifest.txt +2 -0
- data/README.rdoc +13 -0
- data/Rakefile +27 -27
- data/TODO +1 -0
- data/lib/digest/hmac.rb +104 -0
- data/lib/oauth.rb +5 -1
- data/lib/oauth/client/action_controller_request.rb +1 -1
- data/lib/oauth/client/em_http.rb +94 -0
- data/lib/oauth/client/helper.rb +7 -4
- data/lib/oauth/client/net_http.rb +9 -6
- data/lib/oauth/consumer.rb +45 -25
- data/lib/oauth/core_ext.rb +31 -0
- data/lib/oauth/helper.rb +11 -1
- data/lib/oauth/request_proxy/base.rb +4 -3
- data/lib/oauth/request_proxy/curb_request.rb +55 -0
- data/lib/oauth/request_proxy/em_http_request.rb +67 -0
- data/lib/oauth/request_proxy/net_http.rb +9 -6
- data/lib/oauth/request_proxy/typhoeus_request.rb +53 -0
- data/lib/oauth/signature.rb +4 -1
- data/lib/oauth/signature/base.rb +9 -3
- data/lib/oauth/signature/hmac/base.rb +5 -2
- data/lib/oauth/signature/hmac/md5.rb +1 -2
- data/lib/oauth/signature/hmac/rmd160.rb +1 -2
- data/lib/oauth/signature/hmac/sha1.rb +2 -3
- data/lib/oauth/signature/hmac/sha2.rb +1 -2
- data/lib/oauth/signature/plaintext.rb +2 -2
- data/lib/oauth/version.rb +1 -1
- data/oauth.gemspec +157 -27
- data/test/integration/consumer_test.rb +304 -0
- data/test/test_action_controller_request_proxy.rb +4 -1
- data/test/test_consumer.rb +51 -254
- data/test/test_curb_request_proxy.rb +69 -0
- data/test/test_em_http_client.rb +74 -0
- data/test/test_em_http_request_proxy.rb +107 -0
- data/test/test_helper.rb +15 -9
- data/test/test_net_http_client.rb +59 -5
- data/test/test_net_http_request_proxy.rb +1 -1
- data/test/test_signature.rb +6 -3
- data/test/test_typhoeus_request_proxy.rb +73 -0
- data/website/index.html +2 -2
- metadata +43 -25
@@ -0,0 +1,74 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
require 'oauth/client/em_http'
|
3
|
+
|
4
|
+
class EmHttpClientTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@consumer = OAuth::Consumer.new('consumer_key_86cad9', '5888bf0345e5d237')
|
8
|
+
@token = OAuth::Token.new('token_411a7f', '3196ffd991c8ebdb')
|
9
|
+
@request_uri = URI.parse('http://example.com/test?key=value')
|
10
|
+
@request_parameters = { 'key' => 'value' }
|
11
|
+
@nonce = 225579211881198842005988698334675835446
|
12
|
+
@timestamp = "1199645624"
|
13
|
+
# This is really unneeded I guess.
|
14
|
+
@http = Net::HTTP.new(@request_uri.host, @request_uri.port)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_that_using_auth_headers_on_get_requests_works
|
18
|
+
request = create_client
|
19
|
+
request.oauth!(@http, @consumer, @token, {:nonce => @nonce, :timestamp => @timestamp})
|
20
|
+
|
21
|
+
assert_equal 'GET', request.method
|
22
|
+
assert_equal '/test', request.normalize_uri.path
|
23
|
+
assert_equal "key=value", request.normalize_uri.query
|
24
|
+
assert_equal_authz_headers "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\"", authz_header(request)
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_that_using_auth_headers_on_get_requests_works_with_plaintext
|
28
|
+
require 'oauth/signature/plaintext'
|
29
|
+
c = OAuth::Consumer.new('consumer_key_86cad9', '5888bf0345e5d237',{
|
30
|
+
:signature_method => 'PLAINTEXT'
|
31
|
+
})
|
32
|
+
request = create_client
|
33
|
+
request.oauth!(@http, c, @token, {:nonce => @nonce, :timestamp => @timestamp, :signature_method => 'PLAINTEXT'})
|
34
|
+
|
35
|
+
assert_equal 'GET', request.method
|
36
|
+
assert_equal '/test', request.normalize_uri.path
|
37
|
+
assert_equal "key=value", request.normalize_uri.query
|
38
|
+
assert_equal_authz_headers "OAuth 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\"", authz_header(request)
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_that_using_auth_headers_on_post_requests_works
|
42
|
+
request = create_client(:uri => "http://example.com/test", :method => "POST", :body => @request_parameters, :head => {"Content-Type" => "application/x-www-form-urlencoded"})
|
43
|
+
request.oauth!(@http, @consumer, @token, {:nonce => @nonce, :timestamp => @timestamp})
|
44
|
+
|
45
|
+
assert_equal 'POST', request.method
|
46
|
+
assert_equal '/test', request.uri.path
|
47
|
+
assert_equal 'key=value', request.normalize_body
|
48
|
+
assert_equal_authz_headers "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\"", authz_header(request)
|
49
|
+
end
|
50
|
+
|
51
|
+
protected
|
52
|
+
|
53
|
+
def create_client(options = {})
|
54
|
+
method = options.delete(:method) || "GET"
|
55
|
+
uri = options.delete(:uri) || @request_uri.to_s
|
56
|
+
client = EventMachine::HttpClient.new("")
|
57
|
+
client.uri = URI.parse(uri)
|
58
|
+
client.method = method.to_s.upcase
|
59
|
+
client.options = options
|
60
|
+
client
|
61
|
+
end
|
62
|
+
|
63
|
+
def authz_header(request)
|
64
|
+
headers = request.options[:head] || {}
|
65
|
+
headers['Authorization'].to_s
|
66
|
+
end
|
67
|
+
|
68
|
+
def assert_equal_authz_headers(expected, actual)
|
69
|
+
assert !actual.nil?
|
70
|
+
assert_equal expected[0,6], actual[0, 6]
|
71
|
+
assert_equal expected[6..1].split(', ').sort, actual[6..1].split(', ').sort
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
require 'em-http'
|
3
|
+
require 'oauth/request_proxy/em_http_request'
|
4
|
+
|
5
|
+
class EmHttpRequestProxyTest < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def test_request_proxy_works_with_simple_request
|
8
|
+
proxy = create_request_proxy
|
9
|
+
assert_equal({}, proxy.parameters)
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_request_proxy_works_with_query_string_params
|
13
|
+
assert_equal({"name" => ["Fred"]}, create_request_proxy(:query => "name=Fred").parameters)
|
14
|
+
assert_equal({"name" => ["Fred"]}, create_request_proxy(:query => {:name => "Fred"}).parameters)
|
15
|
+
proxy = create_request_proxy(:query => {:name => "Fred"}, :uri => "http://example.com/?awesome=true")
|
16
|
+
assert_equal({"name" => ["Fred"], "awesome" => ["true"]}, proxy.parameters)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_request_proxy_works_with_post_body_params_with_correct_content_type
|
20
|
+
proxy = create_request_proxy :head => {'Content-Type' => 'application/x-www-form-urlencoded'}, :method => "POST"
|
21
|
+
assert_equal({}, proxy.parameters)
|
22
|
+
proxy = create_request_proxy :head => {'Content-Type' => 'application/x-www-form-urlencoded'}, :method => "POST", :body => "a=1"
|
23
|
+
assert_equal({"a" => ["1"]}, proxy.parameters)
|
24
|
+
proxy = create_request_proxy :head => {'Content-Type' => 'application/x-www-form-urlencoded'}, :method => "POST", :body => {"a" => 1}
|
25
|
+
assert_equal({"a" => ["1"]}, proxy.parameters)
|
26
|
+
proxy = create_request_proxy :head => {'Content-Type' => 'application/x-www-form-urlencoded'}, :method => "PUT"
|
27
|
+
assert_equal({}, proxy.parameters)
|
28
|
+
proxy = create_request_proxy :head => {'Content-Type' => 'application/x-www-form-urlencoded'}, :method => "PUT", :body => "a=1"
|
29
|
+
assert_equal({"a" => ["1"]}, proxy.parameters)
|
30
|
+
proxy = create_request_proxy :head => {'Content-Type' => 'application/x-www-form-urlencoded'}, :method => "PUT", :body => {"a" => 1}
|
31
|
+
assert_equal({"a" => ["1"]}, proxy.parameters)
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_request_proxy_ignore_post_body_with_invalid_content_type
|
35
|
+
proxy = create_request_proxy :head => {'Content-Type' => 'text/plain'}, :method => "POST"
|
36
|
+
assert_equal({}, proxy.parameters)
|
37
|
+
proxy = create_request_proxy :head => {'Content-Type' => 'text/plain'}, :method => "POST", :body => "a=1"
|
38
|
+
assert_equal({}, proxy.parameters)
|
39
|
+
proxy = create_request_proxy :head => {'Content-Type' => 'text/plain'}, :method => "POST", :body => {"a" => 1}
|
40
|
+
assert_equal({}, proxy.parameters)
|
41
|
+
proxy = create_request_proxy :head => {'Content-Type' => 'text/plain'}, :method => "PUT"
|
42
|
+
assert_equal({}, proxy.parameters)
|
43
|
+
proxy = create_request_proxy :head => {'Content-Type' => 'text/plain'}, :method => "PUT", :body => "a=1"
|
44
|
+
assert_equal({}, proxy.parameters)
|
45
|
+
proxy = create_request_proxy :head => {'Content-Type' => 'text/plain'}, :method => "PUT", :body => {"a" => 1}
|
46
|
+
assert_equal({}, proxy.parameters)
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_request_proxy_ignores_post_body_with_invalid_method
|
50
|
+
proxy = create_request_proxy :head => {'Content-Type' => 'application/x-www-form-urlencoded'}, :method => "DELETE"
|
51
|
+
assert_equal({}, proxy.parameters)
|
52
|
+
proxy = create_request_proxy :head => {'Content-Type' => 'application/x-www-form-urlencoded'}, :method => "DELETE", :body => "a=1"
|
53
|
+
assert_equal({}, proxy.parameters)
|
54
|
+
proxy = create_request_proxy :head => {'Content-Type' => 'application/x-www-form-urlencoded'}, :method => "DELETE", :body => {"a" => 1}
|
55
|
+
assert_equal({}, proxy.parameters)
|
56
|
+
proxy = create_request_proxy :head => {'Content-Type' => 'application/x-www-form-urlencoded'}, :method => "GET"
|
57
|
+
assert_equal({}, proxy.parameters)
|
58
|
+
proxy = create_request_proxy :head => {'Content-Type' => 'application/x-www-form-urlencoded'}, :method => "GET", :body => "a=1"
|
59
|
+
assert_equal({}, proxy.parameters)
|
60
|
+
proxy = create_request_proxy :head => {'Content-Type' => 'application/x-www-form-urlencoded'}, :method => "GET", :body => {"a" => 1}
|
61
|
+
assert_equal({}, proxy.parameters)
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_request_proxy_works_with_argument_params
|
65
|
+
assert_equal({"a" => ["1"]}, create_request_proxy(:proxy_options => {:parameters => {"a" => "1"}}).parameters)
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_request_proxy_works_with_mixed_params
|
69
|
+
proxy = create_request_proxy(:proxy_options => {:parameters => {"a" => "1"}},:query => {"c" => "1"}, :uri => "http://example.com/test?b=1")
|
70
|
+
assert_equal({"a" => ["1"], "b" => ["1"], "c" => ["1"]}, proxy.parameters)
|
71
|
+
proxy = create_request_proxy(:proxy_options => {:parameters => {"a" => "1"}}, :body => {"b" => "1"}, :query => {"c" => "1"},
|
72
|
+
:uri => "http://example.com/test?d=1", :method => "POST", :head => {"Content-Type" => "application/x-www-form-urlencoded"})
|
73
|
+
assert_equal({"a" => ["1"], "b" => ["1"], "c" => ["1"], "d" => ["1"]}, proxy.parameters)
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_request_has_the_correct_uri
|
77
|
+
assert_equal "http://example.com/", create_request_proxy.uri
|
78
|
+
assert_equal "http://example.com/?a=1", create_request_proxy(:query => "a=1").uri
|
79
|
+
assert_equal "http://example.com/?a=1", create_request_proxy(:query => {"a" => "1"}).uri
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_request_proxy_has_correct_method
|
84
|
+
assert_equal "GET", create_request_proxy(:method => "GET").method
|
85
|
+
assert_equal "PUT", create_request_proxy(:method => "PUT").method
|
86
|
+
assert_equal "POST", create_request_proxy(:method => "POST").method
|
87
|
+
assert_equal "DELETE", create_request_proxy(:method => "DELETE").method
|
88
|
+
end
|
89
|
+
|
90
|
+
protected
|
91
|
+
|
92
|
+
def create_client(options = {})
|
93
|
+
method = options.delete(:method) || "GET"
|
94
|
+
uri = options.delete(:uri) || "http://example.com/"
|
95
|
+
client = EventMachine::HttpClient.new("")
|
96
|
+
client.uri = URI.parse(uri)
|
97
|
+
client.method = method.to_s.upcase
|
98
|
+
client.options = options
|
99
|
+
client
|
100
|
+
end
|
101
|
+
|
102
|
+
def create_request_proxy(opts = {})
|
103
|
+
arguments = opts.delete(:proxy_options) || {}
|
104
|
+
OAuth::RequestProxy.proxy(create_client(opts), arguments)
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -1,14 +1,20 @@
|
|
1
1
|
require 'test/unit'
|
2
|
+
require 'rubygems'
|
2
3
|
|
3
4
|
$LOAD_PATH << File.dirname(__FILE__) + '/../lib/'
|
4
5
|
require 'oauth'
|
6
|
+
require 'mocha'
|
7
|
+
require 'stringio'
|
5
8
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
9
|
+
class Test::Unit::TestCase
|
10
|
+
|
11
|
+
def assert_matching_headers(expected, actual)
|
12
|
+
# transform into sorted arrays
|
13
|
+
auth_intro, auth_params = actual.split(' ', 2)
|
14
|
+
assert_equal auth_intro, 'OAuth'
|
15
|
+
expected = expected.split(/(,|\s)/).reject {|v| v == '' || v =~ /^[\,\s]+/}.sort
|
16
|
+
auth_params = auth_params.split(/(,|\s)/).reject {|v| v == '' || v =~ /^[\,\s]+/}.sort
|
17
|
+
assert_equal expected, auth_params
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
@@ -18,7 +18,36 @@ class NetHTTPClientTest < Test::Unit::TestCase
|
|
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\""
|
22
|
+
auth_intro, auth_params = request['authorization'].split(' ', 2)
|
23
|
+
assert_equal auth_intro, 'OAuth'
|
24
|
+
assert_matching_headers correct_sorted_params, request['authorization']
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_that_using_auth_headers_on_get_requests_works_with_plaintext
|
28
|
+
require 'oauth/signature/plaintext'
|
29
|
+
c = OAuth::Consumer.new('consumer_key_86cad9', '5888bf0345e5d237',{
|
30
|
+
:signature_method => 'PLAINTEXT'
|
31
|
+
})
|
32
|
+
request = Net::HTTP::Get.new(@request_uri.path + "?" + request_parameters_to_s)
|
33
|
+
request.oauth!(@http, c, @token, {:nonce => @nonce, :timestamp => @timestamp, :signature_method => 'PLAINTEXT'})
|
34
|
+
|
35
|
+
assert_equal 'GET', request.method
|
36
|
+
assert_equal '/test?key=value', request.path
|
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=\"1oO2izFav1GP4kEH2EskwXkCRFg%3D\", oauth_version=\"1.0\"", request['authorization']
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_that_using_auth_headers_on_get_requests_works_with_plaintext
|
41
|
+
require 'oauth/signature/plaintext'
|
42
|
+
c = OAuth::Consumer.new('consumer_key_86cad9', '5888bf0345e5d237',{
|
43
|
+
:signature_method => 'PLAINTEXT'
|
44
|
+
})
|
45
|
+
request = Net::HTTP::Get.new(@request_uri.path + "?" + request_parameters_to_s)
|
46
|
+
request.oauth!(@http, c, @token, {:nonce => @nonce, :timestamp => @timestamp, :signature_method => 'PLAINTEXT'})
|
47
|
+
|
48
|
+
assert_equal 'GET', request.method
|
49
|
+
assert_equal '/test?key=value', request.path
|
50
|
+
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']
|
22
51
|
end
|
23
52
|
|
24
53
|
def test_that_using_auth_headers_on_post_requests_works
|
@@ -29,7 +58,8 @@ class NetHTTPClientTest < Test::Unit::TestCase
|
|
29
58
|
assert_equal 'POST', request.method
|
30
59
|
assert_equal '/test', request.path
|
31
60
|
assert_equal 'key=value', request.body
|
32
|
-
|
61
|
+
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\""
|
62
|
+
assert_matching_headers correct_sorted_params, request['authorization']
|
33
63
|
end
|
34
64
|
|
35
65
|
def test_that_version_is_added_to_existing_user_agent
|
@@ -60,6 +90,18 @@ class NetHTTPClientTest < Test::Unit::TestCase
|
|
60
90
|
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("&")
|
61
91
|
assert_equal nil, request['authorization']
|
62
92
|
end
|
93
|
+
|
94
|
+
def test_that_using_get_params_works_with_plaintext
|
95
|
+
request = Net::HTTP::Get.new(@request_uri.path + "?" + request_parameters_to_s)
|
96
|
+
request.oauth!(@http, @consumer, @token, {:scheme => 'query_string', :nonce => @nonce, :timestamp => @timestamp, :signature_method => 'PLAINTEXT'})
|
97
|
+
|
98
|
+
assert_equal 'GET', request.method
|
99
|
+
uri = URI.parse(request.path)
|
100
|
+
assert_equal '/test', uri.path
|
101
|
+
assert_equal nil, uri.fragment
|
102
|
+
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("&")
|
103
|
+
assert_equal nil, request['authorization']
|
104
|
+
end
|
63
105
|
|
64
106
|
def test_that_using_post_params_works
|
65
107
|
request = Net::HTTP::Post.new(@request_uri.path)
|
@@ -71,6 +113,17 @@ class NetHTTPClientTest < Test::Unit::TestCase
|
|
71
113
|
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("&")
|
72
114
|
assert_equal nil, request['authorization']
|
73
115
|
end
|
116
|
+
|
117
|
+
def test_that_using_post_params_works_with_plaintext
|
118
|
+
request = Net::HTTP::Post.new(@request_uri.path)
|
119
|
+
request.set_form_data( @request_parameters )
|
120
|
+
request.oauth!(@http, @consumer, @token, {:scheme => 'body', :nonce => @nonce, :timestamp => @timestamp, :signature_method => 'PLAINTEXT'})
|
121
|
+
|
122
|
+
assert_equal 'POST', request.method
|
123
|
+
assert_equal '/test', request.path
|
124
|
+
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("&")
|
125
|
+
assert_equal nil, request['authorization']
|
126
|
+
end
|
74
127
|
|
75
128
|
def test_that_using_post_with_uri_params_works
|
76
129
|
request = Net::HTTP::Post.new(@request_uri.path + "?" + request_parameters_to_s)
|
@@ -113,11 +166,12 @@ class NetHTTPClientTest < Test::Unit::TestCase
|
|
113
166
|
assert_equal 'GET&http%3A%2F%2Fphotos.example.net%2Fphotos&file%3Dvacation.jpg%26oauth_consumer_key%3Ddpf43f3p2l4k3l03%26oauth_nonce%3Dkllo9940pd9333jh%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1191242096%26oauth_token%3Dnnch734d00sl2jdk%26oauth_version%3D1.0%26size%3Doriginal',signature_base_string
|
114
167
|
|
115
168
|
# request = Net::HTTP::Get.new(request_uri.path + "?" + request_uri.query)
|
116
|
-
request.oauth!(http, consumer, token, {:nonce => nonce, :timestamp => timestamp
|
169
|
+
request.oauth!(http, consumer, token, {:nonce => nonce, :timestamp => timestamp, :realm=>"http://photos.example.net/"})
|
117
170
|
|
118
171
|
assert_equal 'GET', request.method
|
119
|
-
|
120
|
-
|
172
|
+
correct_sorted_params = '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
|
173
|
+
correct_sorted_params.unshift 'OAuth realm="http://photos.example.net/"'
|
174
|
+
assert_equal correct_sorted_params, request['authorization'].split(', ').sort
|
121
175
|
end
|
122
176
|
|
123
177
|
def test_step_by_step_token_request
|
@@ -58,7 +58,7 @@ class NetHTTPRequestProxyTest < Test::Unit::TestCase
|
|
58
58
|
assert_equal 'PUT', request_proxy.method
|
59
59
|
end
|
60
60
|
|
61
|
-
def
|
61
|
+
def test_that_proxy_post_request_uses_post_parameters
|
62
62
|
request = Net::HTTP::Post.new('/test?key=value')
|
63
63
|
request.set_form_data({'key2' => 'value2'})
|
64
64
|
request_proxy = OAuth::RequestProxy.proxy(request, {:uri => 'http://example.com/test?key=value', :parameters => {'key3' => 'value3'}})
|
data/test/test_signature.rb
CHANGED
@@ -1,19 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
1
3
|
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
4
|
|
3
5
|
class TestOauth < Test::Unit::TestCase
|
4
6
|
|
5
7
|
def test_parameter_escaping_kcode_invariant
|
6
|
-
|
8
|
+
ruby19 = RUBY_VERSION =~ /^1\.9/
|
9
|
+
old = $KCODE if !ruby19
|
7
10
|
begin
|
8
11
|
%w(n N e E s S u U).each do |kcode|
|
9
|
-
$KCODE = kcode
|
12
|
+
$KCODE = kcode if !ruby19
|
10
13
|
assert_equal '%E3%81%82', OAuth::Helper.escape('あ'),
|
11
14
|
"Failed to correctly escape Japanese under $KCODE = #{kcode}"
|
12
15
|
assert_equal '%C3%A9', OAuth::Helper.escape('é'),
|
13
16
|
"Failed to correctly escape e+acute under $KCODE = #{kcode}"
|
14
17
|
end
|
15
18
|
ensure
|
16
|
-
$KCODE = old
|
19
|
+
$KCODE = old if !ruby19
|
17
20
|
end
|
18
21
|
end
|
19
22
|
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
require 'oauth/request_proxy/typhoeus_request'
|
3
|
+
require 'typhoeus'
|
4
|
+
|
5
|
+
class TyphoeusRequestProxyTest < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def test_that_proxy_simple_get_request_works
|
8
|
+
request = ::Typhoeus::Request.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
|
+
assert_equal 'GET', request_proxy.method
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_that_proxy_simple_post_request_works_with_arguments
|
18
|
+
request = Typhoeus::Request.new('/test', :method => :post)
|
19
|
+
params = {'key' => 'value'}
|
20
|
+
request_proxy = OAuth::RequestProxy.proxy(request, {:uri => 'http://example.com/test', :parameters => params})
|
21
|
+
|
22
|
+
expected_parameters = {'key' => 'value'}
|
23
|
+
assert_equal expected_parameters, request_proxy.parameters_for_signature
|
24
|
+
assert_equal 'http://example.com/test', request_proxy.normalized_uri
|
25
|
+
assert_equal 'POST', request_proxy.method
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_that_proxy_simple_post_request_works_with_form_data
|
29
|
+
request = Typhoeus::Request.new('/test', :method => :post,
|
30
|
+
:body => {'key' => 'value'},
|
31
|
+
:headers => {'Content-Type' => 'application/x-www-form-urlencoded'})
|
32
|
+
request_proxy = OAuth::RequestProxy.proxy(request, {:uri => 'http://example.com/test'})
|
33
|
+
|
34
|
+
expected_parameters = {'key' => 'value'}
|
35
|
+
assert_equal expected_parameters, request_proxy.parameters_for_signature
|
36
|
+
assert_equal 'http://example.com/test', request_proxy.normalized_uri
|
37
|
+
assert_equal 'POST', request_proxy.method
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_that_proxy_simple_put_request_works_with_arguments
|
41
|
+
request = Typhoeus::Request.new('/test', :method => :put)
|
42
|
+
params = {'key' => 'value'}
|
43
|
+
request_proxy = OAuth::RequestProxy.proxy(request, {:uri => 'http://example.com/test', :parameters => params})
|
44
|
+
|
45
|
+
expected_parameters = {'key' => 'value'}
|
46
|
+
assert_equal expected_parameters, request_proxy.parameters_for_signature
|
47
|
+
assert_equal 'http://example.com/test', request_proxy.normalized_uri
|
48
|
+
assert_equal 'PUT', request_proxy.method
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_that_proxy_simple_put_request_works_with_form_data
|
52
|
+
request = Typhoeus::Request.new('/test', :method => :put, :body => {'key' => 'value'})
|
53
|
+
request_proxy = OAuth::RequestProxy.proxy(request, {:uri => 'http://example.com/test'})
|
54
|
+
|
55
|
+
expected_parameters = {}
|
56
|
+
assert_equal expected_parameters, request_proxy.parameters_for_signature
|
57
|
+
assert_equal 'http://example.com/test', request_proxy.normalized_uri
|
58
|
+
assert_equal 'PUT', request_proxy.method
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_that_proxy_post_request_works_with_mixed_parameter_sources
|
62
|
+
request = Typhoeus::Request.new('/test?key=value',
|
63
|
+
:method => :post,
|
64
|
+
:body => {'key2' => 'value2'},
|
65
|
+
:headers => {'Content-Type' => 'application/x-www-form-urlencoded'})
|
66
|
+
request_proxy = OAuth::RequestProxy.proxy(request, {:uri => 'http://example.com/test?key=value', :parameters => {'key3' => 'value3'}})
|
67
|
+
|
68
|
+
expected_parameters = {'key' => ['value'], 'key2' => 'value2', 'key3' => 'value3'}
|
69
|
+
assert_equal expected_parameters, request_proxy.parameters_for_signature
|
70
|
+
assert_equal 'http://example.com/test', request_proxy.normalized_uri
|
71
|
+
assert_equal 'POST', request_proxy.method
|
72
|
+
end
|
73
|
+
end
|
data/website/index.html
CHANGED
@@ -41,7 +41,7 @@
|
|
41
41
|
<h2>Installing</h2>
|
42
42
|
<p><pre class='syntax'><span class="ident">sudo</span> <span class="ident">gem</span> <span class="ident">install</span> <span class="ident">oauth</span></pre></p>
|
43
43
|
<p>You can also install it from the <a href="http://rubyforge.org/projects/oauth/">oauth rubyforge project</a>.</p>
|
44
|
-
<p>The source code is
|
44
|
+
<p>The source code is hosted on <a href="http://github.com/oauth/oauth-ruby">GitHub</a></p>
|
45
45
|
<h2>The basics</h2>
|
46
46
|
<p>This is a ruby library which is intended to be used in creating Ruby Consumer and Service Provider applications. It is <span class="caps">NOT</span> a Rails plugin, but could easily be used for the foundation for such a Rails plugin.</p>
|
47
47
|
<p>As a matter of fact it has been pulled out from an <a href="http://code.google.com/p/oauth-plugin/">OAuth Rails Plugin</a> which now requires this <span class="caps">GEM</span>.</p>
|
@@ -74,7 +74,7 @@ redirect_to @request_token.authorize_url</code></pre>
|
|
74
74
|
<h2>License</h2>
|
75
75
|
<p>This code is free to use under the terms of the <span class="caps">MIT</span> license.</p>
|
76
76
|
<h2>Contact</h2>
|
77
|
-
<p>Comments are welcome. Send an email to
|
77
|
+
<p>Comments are welcome. Send an email to the <a href="http://groups.google.com/group/oauth-ruby">OAuth Ruby mailing list</a></p>
|
78
78
|
<p class="coda">
|
79
79
|
<a href="FIXME email">FIXME full name</a>, 9th September 2008<br>
|
80
80
|
Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a>
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oauth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.7.pre1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pelle Braendgaard
|
@@ -10,62 +10,64 @@ authors:
|
|
10
10
|
- Jesse Clark
|
11
11
|
- Jon Crosby
|
12
12
|
- Seth Fitzsimmons
|
13
|
+
- Matt Sanford
|
14
|
+
- Aaron Quint
|
13
15
|
autorequire:
|
14
16
|
bindir: bin
|
15
17
|
cert_chain: []
|
16
18
|
|
17
|
-
date:
|
18
|
-
default_executable:
|
19
|
+
date: 2010-02-15 00:00:00 -08:00
|
20
|
+
default_executable: oauth
|
19
21
|
dependencies:
|
20
22
|
- !ruby/object:Gem::Dependency
|
21
|
-
name:
|
22
|
-
type: :
|
23
|
+
name: actionpack
|
24
|
+
type: :development
|
23
25
|
version_requirement:
|
24
26
|
version_requirements: !ruby/object:Gem::Requirement
|
25
27
|
requirements:
|
26
28
|
- - ">="
|
27
29
|
- !ruby/object:Gem::Version
|
28
|
-
version:
|
30
|
+
version: 2.2.0
|
29
31
|
version:
|
30
32
|
- !ruby/object:Gem::Dependency
|
31
|
-
name:
|
33
|
+
name: rack
|
32
34
|
type: :development
|
33
35
|
version_requirement:
|
34
36
|
version_requirements: !ruby/object:Gem::Requirement
|
35
37
|
requirements:
|
36
38
|
- - ">="
|
37
39
|
- !ruby/object:Gem::Version
|
38
|
-
version: 1.
|
40
|
+
version: 1.0.0
|
39
41
|
version:
|
40
42
|
- !ruby/object:Gem::Dependency
|
41
|
-
name:
|
43
|
+
name: mocha
|
42
44
|
type: :development
|
43
45
|
version_requirement:
|
44
46
|
version_requirements: !ruby/object:Gem::Requirement
|
45
47
|
requirements:
|
46
48
|
- - ">="
|
47
49
|
- !ruby/object:Gem::Version
|
48
|
-
version:
|
50
|
+
version: 0.9.8
|
49
51
|
version:
|
50
52
|
- !ruby/object:Gem::Dependency
|
51
|
-
name:
|
53
|
+
name: typhoeus
|
52
54
|
type: :development
|
53
55
|
version_requirement:
|
54
56
|
version_requirements: !ruby/object:Gem::Requirement
|
55
57
|
requirements:
|
56
58
|
- - ">="
|
57
59
|
- !ruby/object:Gem::Version
|
58
|
-
version:
|
60
|
+
version: 0.1.13
|
59
61
|
version:
|
60
62
|
- !ruby/object:Gem::Dependency
|
61
|
-
name:
|
63
|
+
name: em-http-request
|
62
64
|
type: :development
|
63
65
|
version_requirement:
|
64
66
|
version_requirements: !ruby/object:Gem::Requirement
|
65
67
|
requirements:
|
66
68
|
- - ">="
|
67
69
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
70
|
+
version: "0"
|
69
71
|
version:
|
70
72
|
description: OAuth Core Ruby implementation
|
71
73
|
email: oauth-ruby@googlegroups.com
|
@@ -74,11 +76,10 @@ executables:
|
|
74
76
|
extensions: []
|
75
77
|
|
76
78
|
extra_rdoc_files:
|
77
|
-
-
|
78
|
-
-
|
79
|
-
- Manifest.txt
|
80
|
-
- website/index.txt
|
79
|
+
- README.rdoc
|
80
|
+
- TODO
|
81
81
|
files:
|
82
|
+
- .gitignore
|
82
83
|
- History.txt
|
83
84
|
- License.txt
|
84
85
|
- Manifest.txt
|
@@ -87,27 +88,33 @@ files:
|
|
87
88
|
- TODO
|
88
89
|
- bin/oauth
|
89
90
|
- examples/yql.rb
|
91
|
+
- lib/digest/hmac.rb
|
90
92
|
- lib/oauth.rb
|
91
|
-
- lib/oauth/oauth.rb
|
92
93
|
- lib/oauth/cli.rb
|
93
94
|
- lib/oauth/client.rb
|
94
95
|
- lib/oauth/client/action_controller_request.rb
|
96
|
+
- lib/oauth/client/em_http.rb
|
95
97
|
- lib/oauth/client/helper.rb
|
96
98
|
- lib/oauth/client/net_http.rb
|
97
99
|
- lib/oauth/consumer.rb
|
100
|
+
- lib/oauth/core_ext.rb
|
98
101
|
- lib/oauth/errors.rb
|
99
102
|
- lib/oauth/errors/error.rb
|
100
103
|
- lib/oauth/errors/problem.rb
|
101
104
|
- lib/oauth/errors/unauthorized.rb
|
102
105
|
- lib/oauth/helper.rb
|
106
|
+
- lib/oauth/oauth.rb
|
103
107
|
- lib/oauth/oauth_test_helper.rb
|
104
108
|
- lib/oauth/request_proxy.rb
|
105
109
|
- lib/oauth/request_proxy/action_controller_request.rb
|
106
110
|
- lib/oauth/request_proxy/base.rb
|
111
|
+
- lib/oauth/request_proxy/curb_request.rb
|
112
|
+
- lib/oauth/request_proxy/em_http_request.rb
|
107
113
|
- lib/oauth/request_proxy/jabber_request.rb
|
108
114
|
- lib/oauth/request_proxy/mock_request.rb
|
109
115
|
- lib/oauth/request_proxy/net_http.rb
|
110
116
|
- lib/oauth/request_proxy/rack_request.rb
|
117
|
+
- lib/oauth/request_proxy/typhoeus_request.rb
|
111
118
|
- lib/oauth/server.rb
|
112
119
|
- lib/oauth/signature.rb
|
113
120
|
- lib/oauth/signature/base.rb
|
@@ -140,11 +147,15 @@ files:
|
|
140
147
|
- test/cases/spec/1_0-final/test_normalize_request_parameters.rb
|
141
148
|
- test/cases/spec/1_0-final/test_parameter_encodings.rb
|
142
149
|
- test/cases/spec/1_0-final/test_signature_base_strings.rb
|
150
|
+
- test/integration/consumer_test.rb
|
143
151
|
- test/keys/rsa.cert
|
144
152
|
- test/keys/rsa.pem
|
145
153
|
- test/test_access_token.rb
|
146
154
|
- test/test_action_controller_request_proxy.rb
|
147
155
|
- test/test_consumer.rb
|
156
|
+
- test/test_curb_request_proxy.rb
|
157
|
+
- test/test_em_http_client.rb
|
158
|
+
- test/test_em_http_request_proxy.rb
|
148
159
|
- test/test_helper.rb
|
149
160
|
- test/test_hmac_sha1.rb
|
150
161
|
- test/test_net_http_client.rb
|
@@ -158,19 +169,19 @@ files:
|
|
158
169
|
- test/test_signature_base.rb
|
159
170
|
- test/test_signature_plain_text.rb
|
160
171
|
- test/test_token.rb
|
172
|
+
- test/test_typhoeus_request_proxy.rb
|
161
173
|
- website/index.html
|
162
174
|
- website/index.txt
|
163
175
|
- website/javascripts/rounded_corners_lite.inc.js
|
164
176
|
- website/stylesheets/screen.css
|
165
177
|
- website/template.rhtml
|
166
178
|
has_rdoc: true
|
167
|
-
homepage:
|
179
|
+
homepage:
|
168
180
|
licenses: []
|
169
181
|
|
170
182
|
post_install_message:
|
171
183
|
rdoc_options:
|
172
|
-
- --
|
173
|
-
- README.txt
|
184
|
+
- --charset=UTF-8
|
174
185
|
require_paths:
|
175
186
|
- lib
|
176
187
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -181,25 +192,30 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
181
192
|
version:
|
182
193
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
183
194
|
requirements:
|
184
|
-
- - "
|
195
|
+
- - ">"
|
185
196
|
- !ruby/object:Gem::Version
|
186
|
-
version:
|
197
|
+
version: 1.3.1
|
187
198
|
version:
|
188
199
|
requirements: []
|
189
200
|
|
190
201
|
rubyforge_project: oauth
|
191
|
-
rubygems_version: 1.3.
|
202
|
+
rubygems_version: 1.3.5
|
192
203
|
signing_key:
|
193
204
|
specification_version: 3
|
194
205
|
summary: OAuth Core Ruby implementation
|
195
206
|
test_files:
|
207
|
+
- test/cases/oauth_case.rb
|
196
208
|
- test/cases/spec/1_0-final/test_construct_request_url.rb
|
197
209
|
- test/cases/spec/1_0-final/test_normalize_request_parameters.rb
|
198
210
|
- test/cases/spec/1_0-final/test_parameter_encodings.rb
|
199
211
|
- test/cases/spec/1_0-final/test_signature_base_strings.rb
|
212
|
+
- test/integration/consumer_test.rb
|
200
213
|
- test/test_access_token.rb
|
201
214
|
- test/test_action_controller_request_proxy.rb
|
202
215
|
- test/test_consumer.rb
|
216
|
+
- test/test_curb_request_proxy.rb
|
217
|
+
- test/test_em_http_client.rb
|
218
|
+
- test/test_em_http_request_proxy.rb
|
203
219
|
- test/test_helper.rb
|
204
220
|
- test/test_hmac_sha1.rb
|
205
221
|
- test/test_net_http_client.rb
|
@@ -213,3 +229,5 @@ test_files:
|
|
213
229
|
- test/test_signature_base.rb
|
214
230
|
- test/test_signature_plain_text.rb
|
215
231
|
- test/test_token.rb
|
232
|
+
- test/test_typhoeus_request_proxy.rb
|
233
|
+
- examples/yql.rb
|