oauth 0.5.1 → 0.5.2
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.
- checksums.yaml +4 -4
- data/README.rdoc +12 -2
- data/bin/oauth +8 -2
- data/lib/oauth.rb +2 -1
- data/lib/oauth/cli.rb +32 -360
- data/lib/oauth/cli/authorize_command.rb +71 -0
- data/lib/oauth/cli/base_command.rb +203 -0
- data/lib/oauth/cli/help_command.rb +22 -0
- data/lib/oauth/cli/query_command.rb +25 -0
- data/lib/oauth/cli/sign_command.rb +81 -0
- data/lib/oauth/cli/version_command.rb +7 -0
- data/lib/oauth/client/action_controller_request.rb +0 -1
- data/lib/oauth/client/em_http.rb +0 -1
- data/lib/oauth/client/net_http.rb +0 -1
- data/lib/oauth/consumer.rb +26 -3
- data/lib/oauth/core_ext.rb +24 -2
- data/lib/oauth/helper.rb +10 -6
- data/lib/oauth/request_proxy/base.rb +5 -1
- data/lib/oauth/version.rb +1 -1
- metadata +100 -83
- data/test/cases/oauth_case.rb +0 -19
- data/test/cases/spec/1_0-final/test_construct_request_url.rb +0 -62
- data/test/cases/spec/1_0-final/test_normalize_request_parameters.rb +0 -88
- data/test/cases/spec/1_0-final/test_parameter_encodings.rb +0 -86
- data/test/cases/spec/1_0-final/test_signature_base_strings.rb +0 -77
- data/test/integration/consumer_test.rb +0 -307
- data/test/test_access_token.rb +0 -26
- data/test/test_action_controller_request_proxy.rb +0 -157
- data/test/test_consumer.rb +0 -226
- data/test/test_curb_request_proxy.rb +0 -77
- data/test/test_em_http_client.rb +0 -80
- data/test/test_em_http_request_proxy.rb +0 -115
- data/test/test_helper.rb +0 -33
- data/test/test_hmac_sha1.rb +0 -20
- data/test/test_net_http_client.rb +0 -302
- data/test/test_net_http_request_proxy.rb +0 -72
- data/test/test_oauth_helper.rb +0 -94
- data/test/test_rack_request_proxy.rb +0 -40
- data/test/test_request_token.rb +0 -56
- data/test/test_rest_client_request_proxy.rb +0 -81
- data/test/test_rsa_sha1.rb +0 -59
- data/test/test_server.rb +0 -41
- data/test/test_signature.rb +0 -15
- data/test/test_signature_base.rb +0 -32
- data/test/test_signature_hmac_sha1.rb +0 -40
- data/test/test_signature_plain_text.rb +0 -31
- data/test/test_token.rb +0 -14
- data/test/test_typhoeus_request_proxy.rb +0 -101
data/test/test_em_http_client.rb
DELETED
@@ -1,80 +0,0 @@
|
|
1
|
-
require File.expand_path('../test_helper', __FILE__)
|
2
|
-
begin
|
3
|
-
|
4
|
-
require 'oauth/client/em_http'
|
5
|
-
|
6
|
-
class EmHttpClientTest < Minitest::Test
|
7
|
-
|
8
|
-
def setup
|
9
|
-
@consumer = OAuth::Consumer.new('consumer_key_86cad9', '5888bf0345e5d237')
|
10
|
-
@token = OAuth::Token.new('token_411a7f', '3196ffd991c8ebdb')
|
11
|
-
@request_uri = URI.parse('http://example.com/test?key=value')
|
12
|
-
@request_parameters = { 'key' => 'value' }
|
13
|
-
@nonce = 225579211881198842005988698334675835446
|
14
|
-
@timestamp = "1199645624"
|
15
|
-
# This is really unneeded I guess.
|
16
|
-
@http = Net::HTTP.new(@request_uri.host, @request_uri.port)
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_that_using_auth_headers_on_get_requests_works
|
20
|
-
request = create_client
|
21
|
-
request.oauth!(@http, @consumer, @token, {:nonce => @nonce, :timestamp => @timestamp})
|
22
|
-
|
23
|
-
assert_equal 'GET', request.method
|
24
|
-
assert_equal '/test', request.normalize_uri.path
|
25
|
-
assert_equal "key=value", request.normalize_uri.query
|
26
|
-
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)
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_that_using_auth_headers_on_get_requests_works_with_plaintext
|
30
|
-
require 'oauth/signature/plaintext'
|
31
|
-
c = OAuth::Consumer.new('consumer_key_86cad9', '5888bf0345e5d237',{
|
32
|
-
:signature_method => 'PLAINTEXT'
|
33
|
-
})
|
34
|
-
request = create_client
|
35
|
-
request.oauth!(@http, c, @token, {:nonce => @nonce, :timestamp => @timestamp, :signature_method => 'PLAINTEXT'})
|
36
|
-
|
37
|
-
assert_equal 'GET', request.method
|
38
|
-
assert_equal '/test', request.normalize_uri.path
|
39
|
-
assert_equal "key=value", request.normalize_uri.query
|
40
|
-
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)
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_that_using_auth_headers_on_post_requests_works
|
44
|
-
request = create_client(:uri => "http://example.com/test", :method => "POST", :body => @request_parameters, :head => {"Content-Type" => "application/x-www-form-urlencoded"})
|
45
|
-
request.oauth!(@http, @consumer, @token, {:nonce => @nonce, :timestamp => @timestamp})
|
46
|
-
|
47
|
-
assert_equal 'POST', request.method
|
48
|
-
assert_equal '/test', request.uri.path
|
49
|
-
assert_equal 'key=value', request.normalize_body
|
50
|
-
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)
|
51
|
-
end
|
52
|
-
|
53
|
-
protected
|
54
|
-
|
55
|
-
def create_client(options = {})
|
56
|
-
method = options.delete(:method) || "GET"
|
57
|
-
uri = options.delete(:uri) || @request_uri.to_s
|
58
|
-
client = EventMachine::HttpClient.new("")
|
59
|
-
client.uri = URI.parse(uri)
|
60
|
-
client.method = method.to_s.upcase
|
61
|
-
client.options = options
|
62
|
-
client
|
63
|
-
end
|
64
|
-
|
65
|
-
def authz_header(request)
|
66
|
-
headers = request.options[:head] || {}
|
67
|
-
headers['Authorization'].to_s
|
68
|
-
end
|
69
|
-
|
70
|
-
def assert_equal_authz_headers(expected, actual)
|
71
|
-
assert !actual.nil?
|
72
|
-
assert_equal expected[0,6], actual[0, 6]
|
73
|
-
assert_equal expected[6..1].split(', ').sort, actual[6..1].split(', ').sort
|
74
|
-
end
|
75
|
-
|
76
|
-
end
|
77
|
-
|
78
|
-
rescue LoadError => e
|
79
|
-
warn "! problem loading em-http, skipping these tests: #{e}"
|
80
|
-
end
|
@@ -1,115 +0,0 @@
|
|
1
|
-
require File.expand_path('../test_helper', __FILE__)
|
2
|
-
|
3
|
-
begin
|
4
|
-
|
5
|
-
require 'em-http'
|
6
|
-
require 'oauth/request_proxy/em_http_request'
|
7
|
-
|
8
|
-
|
9
|
-
class EmHttpRequestProxyTest < Minitest::Test
|
10
|
-
|
11
|
-
def test_request_proxy_works_with_simple_request
|
12
|
-
proxy = create_request_proxy
|
13
|
-
assert_equal({}, proxy.parameters)
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_request_proxy_works_with_query_string_params
|
17
|
-
assert_equal({"name" => ["Fred"]}, create_request_proxy(:query => "name=Fred").parameters)
|
18
|
-
assert_equal({"name" => ["Fred"]}, create_request_proxy(:query => {:name => "Fred"}).parameters)
|
19
|
-
proxy = create_request_proxy(:query => {:name => "Fred"}, :uri => "http://example.com/?awesome=true")
|
20
|
-
assert_equal({"name" => ["Fred"], "awesome" => ["true"]}, proxy.parameters)
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_request_proxy_works_with_post_body_params_with_correct_content_type
|
24
|
-
proxy = create_request_proxy :head => {'Content-Type' => 'application/x-www-form-urlencoded'}, :method => "POST"
|
25
|
-
assert_equal({}, proxy.parameters)
|
26
|
-
proxy = create_request_proxy :head => {'Content-Type' => 'application/x-www-form-urlencoded'}, :method => "POST", :body => "a=1"
|
27
|
-
assert_equal({"a" => ["1"]}, proxy.parameters)
|
28
|
-
proxy = create_request_proxy :head => {'Content-Type' => 'application/x-www-form-urlencoded'}, :method => "POST", :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"
|
31
|
-
assert_equal({}, proxy.parameters)
|
32
|
-
proxy = create_request_proxy :head => {'Content-Type' => 'application/x-www-form-urlencoded'}, :method => "PUT", :body => "a=1"
|
33
|
-
assert_equal({"a" => ["1"]}, proxy.parameters)
|
34
|
-
proxy = create_request_proxy :head => {'Content-Type' => 'application/x-www-form-urlencoded'}, :method => "PUT", :body => {"a" => 1}
|
35
|
-
assert_equal({"a" => ["1"]}, proxy.parameters)
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_request_proxy_ignore_post_body_with_invalid_content_type
|
39
|
-
proxy = create_request_proxy :head => {'Content-Type' => 'text/plain'}, :method => "POST"
|
40
|
-
assert_equal({}, proxy.parameters)
|
41
|
-
proxy = create_request_proxy :head => {'Content-Type' => 'text/plain'}, :method => "POST", :body => "a=1"
|
42
|
-
assert_equal({}, proxy.parameters)
|
43
|
-
proxy = create_request_proxy :head => {'Content-Type' => 'text/plain'}, :method => "POST", :body => {"a" => 1}
|
44
|
-
assert_equal({}, proxy.parameters)
|
45
|
-
proxy = create_request_proxy :head => {'Content-Type' => 'text/plain'}, :method => "PUT"
|
46
|
-
assert_equal({}, proxy.parameters)
|
47
|
-
proxy = create_request_proxy :head => {'Content-Type' => 'text/plain'}, :method => "PUT", :body => "a=1"
|
48
|
-
assert_equal({}, proxy.parameters)
|
49
|
-
proxy = create_request_proxy :head => {'Content-Type' => 'text/plain'}, :method => "PUT", :body => {"a" => 1}
|
50
|
-
assert_equal({}, proxy.parameters)
|
51
|
-
end
|
52
|
-
|
53
|
-
def test_request_proxy_ignores_post_body_with_invalid_method
|
54
|
-
proxy = create_request_proxy :head => {'Content-Type' => 'application/x-www-form-urlencoded'}, :method => "DELETE"
|
55
|
-
assert_equal({}, proxy.parameters)
|
56
|
-
proxy = create_request_proxy :head => {'Content-Type' => 'application/x-www-form-urlencoded'}, :method => "DELETE", :body => "a=1"
|
57
|
-
assert_equal({}, proxy.parameters)
|
58
|
-
proxy = create_request_proxy :head => {'Content-Type' => 'application/x-www-form-urlencoded'}, :method => "DELETE", :body => {"a" => 1}
|
59
|
-
assert_equal({}, proxy.parameters)
|
60
|
-
proxy = create_request_proxy :head => {'Content-Type' => 'application/x-www-form-urlencoded'}, :method => "GET"
|
61
|
-
assert_equal({}, proxy.parameters)
|
62
|
-
proxy = create_request_proxy :head => {'Content-Type' => 'application/x-www-form-urlencoded'}, :method => "GET", :body => "a=1"
|
63
|
-
assert_equal({}, proxy.parameters)
|
64
|
-
proxy = create_request_proxy :head => {'Content-Type' => 'application/x-www-form-urlencoded'}, :method => "GET", :body => {"a" => 1}
|
65
|
-
assert_equal({}, proxy.parameters)
|
66
|
-
end
|
67
|
-
|
68
|
-
def test_request_proxy_works_with_argument_params
|
69
|
-
assert_equal({"a" => ["1"]}, create_request_proxy(:proxy_options => {:parameters => {"a" => "1"}}).parameters)
|
70
|
-
end
|
71
|
-
|
72
|
-
def test_request_proxy_works_with_mixed_params
|
73
|
-
proxy = create_request_proxy(:proxy_options => {:parameters => {"a" => "1"}},:query => {"c" => "1"}, :uri => "http://example.com/test?b=1")
|
74
|
-
assert_equal({"a" => ["1"], "b" => ["1"], "c" => ["1"]}, proxy.parameters)
|
75
|
-
proxy = create_request_proxy(:proxy_options => {:parameters => {"a" => "1"}}, :body => {"b" => "1"}, :query => {"c" => "1"},
|
76
|
-
:uri => "http://example.com/test?d=1", :method => "POST", :head => {"Content-Type" => "application/x-www-form-urlencoded"})
|
77
|
-
assert_equal({"a" => ["1"], "b" => ["1"], "c" => ["1"], "d" => ["1"]}, proxy.parameters)
|
78
|
-
end
|
79
|
-
|
80
|
-
def test_request_has_the_correct_uri
|
81
|
-
assert_equal "http://example.com/", create_request_proxy.uri
|
82
|
-
assert_equal "http://example.com/?a=1", create_request_proxy(:query => "a=1").uri
|
83
|
-
assert_equal "http://example.com/?a=1", create_request_proxy(:query => {"a" => "1"}).uri
|
84
|
-
|
85
|
-
end
|
86
|
-
|
87
|
-
def test_request_proxy_has_correct_method
|
88
|
-
assert_equal "GET", create_request_proxy(:method => "GET").method
|
89
|
-
assert_equal "PUT", create_request_proxy(:method => "PUT").method
|
90
|
-
assert_equal "POST", create_request_proxy(:method => "POST").method
|
91
|
-
assert_equal "DELETE", create_request_proxy(:method => "DELETE").method
|
92
|
-
end
|
93
|
-
|
94
|
-
protected
|
95
|
-
|
96
|
-
def create_client(options = {})
|
97
|
-
method = options.delete(:method) || "GET"
|
98
|
-
uri = options.delete(:uri) || "http://example.com/"
|
99
|
-
client = EventMachine::HttpClient.new("")
|
100
|
-
client.uri = URI.parse(uri)
|
101
|
-
client.method = method.to_s.upcase
|
102
|
-
client.options = options
|
103
|
-
client
|
104
|
-
end
|
105
|
-
|
106
|
-
def create_request_proxy(opts = {})
|
107
|
-
arguments = opts.delete(:proxy_options) || {}
|
108
|
-
OAuth::RequestProxy.proxy(create_client(opts), arguments)
|
109
|
-
end
|
110
|
-
|
111
|
-
end
|
112
|
-
|
113
|
-
rescue LoadError => e
|
114
|
-
warn "! problem loading em-http, skipping these tests: #{e}"
|
115
|
-
end
|
data/test/test_helper.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'minitest/autorun'
|
3
|
-
require 'mocha/mini_test'
|
4
|
-
require 'rack/test'
|
5
|
-
|
6
|
-
ENV['RACK_ENV'] = 'test'
|
7
|
-
|
8
|
-
require 'byebug'
|
9
|
-
|
10
|
-
$LOAD_PATH << File.dirname(__FILE__) + '/../lib/'
|
11
|
-
require 'oauth'
|
12
|
-
require 'stringio'
|
13
|
-
require 'webmock'
|
14
|
-
|
15
|
-
class Minitest::Test
|
16
|
-
include WebMock::API
|
17
|
-
|
18
|
-
def assert_matching_headers(expected, actual)
|
19
|
-
# transform into sorted arrays
|
20
|
-
auth_intro, auth_params = actual.split(' ', 2)
|
21
|
-
assert_equal auth_intro, 'OAuth'
|
22
|
-
expected = expected.split(/(,|\s)/).reject {|v| v == '' || v =~ /^[\,\s]+/}.sort
|
23
|
-
auth_params = auth_params.split(/(,|\s)/).reject {|v| v == '' || v =~ /^[\,\s]+/}.sort
|
24
|
-
assert_equal expected, auth_params
|
25
|
-
end
|
26
|
-
|
27
|
-
def stub_test_ie
|
28
|
-
stub_request(:any, "http://term.ie/oauth/example/request_token.php").to_return(:body => "oauth_token=requestkey&oauth_token_secret=requestsecret")
|
29
|
-
stub_request(:post, "http://term.ie/oauth/example/access_token.php").to_return(:body => "oauth_token=accesskey&oauth_token_secret=accesssecret")
|
30
|
-
stub_request(:get, %r{http://term\.ie/oauth/example/echo_api\.php\?.+}).to_return(lambda {|request| {:body => request.uri.query}})
|
31
|
-
stub_request(:post, "http://term.ie/oauth/example/echo_api.php").to_return(lambda {|request| {:body => request.body}})
|
32
|
-
end
|
33
|
-
end
|
data/test/test_hmac_sha1.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
require File.expand_path('../test_helper', __FILE__)
|
2
|
-
|
3
|
-
class TestSignatureHmacSha1 < Minitest::Test
|
4
|
-
def test_that_hmac_sha1_implements_hmac_sha1
|
5
|
-
assert OAuth::Signature.available_methods.include?('hmac-sha1')
|
6
|
-
end
|
7
|
-
|
8
|
-
def test_that_get_request_from_oauth_test_cases_produces_matching_signature
|
9
|
-
request = Net::HTTP::Get.new('/photos?file=vacation.jpg&size=original&oauth_version=1.0&oauth_consumer_key=dpf43f3p2l4k3l03&oauth_token=nnch734d00sl2jdk&oauth_timestamp=1191242096&oauth_nonce=kllo9940pd9333jh&oauth_signature_method=HMAC-SHA1')
|
10
|
-
|
11
|
-
consumer = OAuth::Consumer.new('dpf43f3p2l4k3l03', 'kd94hf93k423kf44')
|
12
|
-
token = OAuth::Token.new('nnch734d00sl2jdk', 'pfkkdhi9sl3r4s00')
|
13
|
-
|
14
|
-
signature = OAuth::Signature.sign(request, { :consumer => consumer,
|
15
|
-
:token => token,
|
16
|
-
:uri => 'http://photos.example.net/photos' } )
|
17
|
-
|
18
|
-
assert_equal 'tR3+Ty81lMeYAr/Fid0kMTYa/WM=', signature
|
19
|
-
end
|
20
|
-
end
|
@@ -1,302 +0,0 @@
|
|
1
|
-
require File.expand_path('../test_helper', __FILE__)
|
2
|
-
|
3
|
-
class NetHTTPClientTest < Minitest::Test
|
4
|
-
|
5
|
-
def setup
|
6
|
-
@consumer = OAuth::Consumer.new('consumer_key_86cad9', '5888bf0345e5d237')
|
7
|
-
@token = OAuth::Token.new('token_411a7f', '3196ffd991c8ebdb')
|
8
|
-
@request_uri = URI.parse('http://example.com/test?key=value')
|
9
|
-
@request_parameters = { 'key' => 'value' }
|
10
|
-
@nonce = 225579211881198842005988698334675835446
|
11
|
-
@timestamp = "1199645624"
|
12
|
-
@http = Net::HTTP.new(@request_uri.host, @request_uri.port)
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_that_using_auth_headers_on_get_requests_works
|
16
|
-
request = Net::HTTP::Get.new(@request_uri.path + "?" + request_parameters_to_s)
|
17
|
-
request.oauth!(@http, @consumer, @token, {:nonce => @nonce, :timestamp => @timestamp})
|
18
|
-
|
19
|
-
assert_equal 'GET', request.method
|
20
|
-
assert_equal '/test?key=value', request.path
|
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=\"5888bf0345e5d237%263196ffd991c8ebdb\", oauth_version=\"1.0\"", request['authorization']
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_that_using_auth_headers_on_post_requests_works
|
41
|
-
request = Net::HTTP::Post.new(@request_uri.path)
|
42
|
-
request.set_form_data( @request_parameters )
|
43
|
-
request.oauth!(@http, @consumer, @token, {:nonce => @nonce, :timestamp => @timestamp})
|
44
|
-
|
45
|
-
assert_equal 'POST', request.method
|
46
|
-
assert_equal '/test', request.path
|
47
|
-
assert_equal 'key=value', request.body
|
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
|
-
assert_matching_headers correct_sorted_params, request['authorization']
|
50
|
-
end
|
51
|
-
|
52
|
-
def test_that_using_auth_headers_on_post_requests_with_data_works
|
53
|
-
request = Net::HTTP::Post.new(@request_uri.path)
|
54
|
-
request.body = "data"
|
55
|
-
request.content_type = 'text/ascii'
|
56
|
-
request.oauth!(@http, @consumer, @token, {:nonce => @nonce, :timestamp => @timestamp})
|
57
|
-
|
58
|
-
assert_equal 'POST', request.method
|
59
|
-
assert_equal '/test', request.path
|
60
|
-
assert_equal 'data', request.body
|
61
|
-
assert_equal 'text/ascii', request.content_type
|
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
|
-
end
|
64
|
-
|
65
|
-
def test_that_body_hash_is_obmitted_when_token_request
|
66
|
-
request = Net::HTTP::Post.new(@request_uri.path)
|
67
|
-
request.oauth!(@http, @consumer, @token, {:nonce => @nonce, :timestamp => @timestamp, :token_request => true})
|
68
|
-
assert_no_match(/oauth_body_hash/, request['authorization'])
|
69
|
-
end
|
70
|
-
|
71
|
-
def test_that_body_hash_is_obmitted_when_no_algorithm_is_defined
|
72
|
-
request = Net::HTTP::Post.new(@request_uri.path)
|
73
|
-
request.body = "data"
|
74
|
-
request.content_type = 'text/ascii'
|
75
|
-
request.oauth!(@http, @consumer, @token, {:nonce => @nonce, :timestamp => @timestamp, :signature_method => 'plaintext'})
|
76
|
-
|
77
|
-
assert_equal 'POST', request.method
|
78
|
-
assert_equal '/test', request.path
|
79
|
-
assert_equal 'data', request.body
|
80
|
-
assert_equal 'text/ascii', request.content_type
|
81
|
-
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']
|
82
|
-
end
|
83
|
-
|
84
|
-
def test_that_version_is_added_to_existing_user_agent
|
85
|
-
request = Net::HTTP::Post.new(@request_uri.path)
|
86
|
-
request['User-Agent'] = "MyApp"
|
87
|
-
request.set_form_data( @request_parameters )
|
88
|
-
request.oauth!(@http, @consumer, @token, {:nonce => @nonce, :timestamp => @timestamp})
|
89
|
-
|
90
|
-
assert_equal "MyApp (OAuth gem v#{OAuth::VERSION})", request['User-Agent']
|
91
|
-
end
|
92
|
-
|
93
|
-
def test_that_version_is_set_when_no_user_agent
|
94
|
-
request = Net::HTTP::Post.new(@request_uri.path)
|
95
|
-
request.set_form_data( @request_parameters )
|
96
|
-
request.oauth!(@http, @consumer, @token, {:nonce => @nonce, :timestamp => @timestamp})
|
97
|
-
|
98
|
-
assert_equal "OAuth gem v#{OAuth::VERSION}", request['User-Agent']
|
99
|
-
end
|
100
|
-
|
101
|
-
def test_that_using_get_params_works
|
102
|
-
request = Net::HTTP::Get.new(@request_uri.path + "?" + request_parameters_to_s)
|
103
|
-
request.oauth!(@http, @consumer, @token, {:scheme => 'query_string', :nonce => @nonce, :timestamp => @timestamp})
|
104
|
-
|
105
|
-
assert_equal 'GET', request.method
|
106
|
-
uri = URI.parse(request.path)
|
107
|
-
assert_equal '/test', uri.path
|
108
|
-
assert_equal nil, uri.fragment
|
109
|
-
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("&")
|
110
|
-
assert_equal nil, request['authorization']
|
111
|
-
end
|
112
|
-
|
113
|
-
def test_that_using_get_params_works_with_plaintext
|
114
|
-
request = Net::HTTP::Get.new(@request_uri.path + "?" + request_parameters_to_s)
|
115
|
-
request.oauth!(@http, @consumer, @token, {:scheme => 'query_string', :nonce => @nonce, :timestamp => @timestamp, :signature_method => 'PLAINTEXT'})
|
116
|
-
|
117
|
-
assert_equal 'GET', request.method
|
118
|
-
uri = URI.parse(request.path)
|
119
|
-
assert_equal '/test', uri.path
|
120
|
-
assert_equal nil, uri.fragment
|
121
|
-
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("&")
|
122
|
-
assert_equal nil, request['authorization']
|
123
|
-
end
|
124
|
-
|
125
|
-
def test_that_using_post_params_works
|
126
|
-
request = Net::HTTP::Post.new(@request_uri.path)
|
127
|
-
request.set_form_data( @request_parameters )
|
128
|
-
request.oauth!(@http, @consumer, @token, {:scheme => 'body', :nonce => @nonce, :timestamp => @timestamp})
|
129
|
-
|
130
|
-
assert_equal 'POST', request.method
|
131
|
-
assert_equal '/test', request.path
|
132
|
-
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("&")
|
133
|
-
assert_equal nil, request['authorization']
|
134
|
-
end
|
135
|
-
|
136
|
-
def test_that_using_post_params_works_with_plaintext
|
137
|
-
request = Net::HTTP::Post.new(@request_uri.path)
|
138
|
-
request.set_form_data( @request_parameters )
|
139
|
-
request.oauth!(@http, @consumer, @token, {:scheme => 'body', :nonce => @nonce, :timestamp => @timestamp, :signature_method => 'PLAINTEXT'})
|
140
|
-
|
141
|
-
assert_equal 'POST', request.method
|
142
|
-
assert_equal '/test', request.path
|
143
|
-
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("&")
|
144
|
-
assert_equal nil, request['authorization']
|
145
|
-
end
|
146
|
-
|
147
|
-
def test_that_using_post_body_works
|
148
|
-
request = Net::HTTP::Post.new(@request_uri.path)
|
149
|
-
request['content-type'] = 'application/x-www-form-urlencoded'
|
150
|
-
request.body = 'this is a test of the emergency broad cast system. This is only a test.'
|
151
|
-
request.oauth!(@http, @consumer, @token, {:nonce => @nonce, :timestamp => @timestamp})
|
152
|
-
|
153
|
-
assert_equal 'POST', request.method
|
154
|
-
assert_equal '/test', request.path
|
155
|
-
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("&")
|
156
|
-
# assert_equal nil, request['authorization']
|
157
|
-
end
|
158
|
-
|
159
|
-
def test_that_using_post_with_uri_params_works
|
160
|
-
request = Net::HTTP::Post.new(@request_uri.path + "?" + request_parameters_to_s)
|
161
|
-
request.set_form_data( {} ) # just to make sure we have a correct mime type and thus no body hash
|
162
|
-
request.oauth!(@http, @consumer, @token, {:scheme => 'query_string', :nonce => @nonce, :timestamp => @timestamp})
|
163
|
-
|
164
|
-
assert_equal 'POST', request.method
|
165
|
-
uri = URI.parse(request.path)
|
166
|
-
assert_equal '/test', uri.path
|
167
|
-
assert_equal nil, uri.fragment
|
168
|
-
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", uri.query.split("&").sort.join('&')
|
169
|
-
assert_equal "", request.body
|
170
|
-
assert_equal nil, request['authorization']
|
171
|
-
end
|
172
|
-
|
173
|
-
def test_that_using_post_with_uri_and_form_params_works
|
174
|
-
request = Net::HTTP::Post.new(@request_uri.path + "?" + request_parameters_to_s)
|
175
|
-
request.set_form_data( { 'key2' => 'value2' } )
|
176
|
-
request.oauth!(@http, @consumer, @token, {:scheme => :query_string, :nonce => @nonce, :timestamp => @timestamp})
|
177
|
-
|
178
|
-
assert_equal 'POST', request.method
|
179
|
-
uri = URI.parse(request.path)
|
180
|
-
assert_equal '/test', uri.path
|
181
|
-
assert_equal nil, uri.fragment
|
182
|
-
assert_equal "key=value&oauth_consumer_key=consumer_key_86cad9&oauth_nonce=225579211881198842005988698334675835446&oauth_signature=4kSU8Zd1blWo3W6qJH7eaRTMkg0%3D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1199645624&oauth_token=token_411a7f&oauth_version=1.0", uri.query.split("&").sort.join('&')
|
183
|
-
assert_equal "key2=value2", request.body
|
184
|
-
assert_equal nil, request['authorization']
|
185
|
-
end
|
186
|
-
|
187
|
-
def test_that_using_post_with_uri_and_data_works
|
188
|
-
request = Net::HTTP::Post.new(@request_uri.path + "?" + request_parameters_to_s)
|
189
|
-
request.body = "data"
|
190
|
-
request.content_type = 'text/ascii'
|
191
|
-
request.oauth!(@http, @consumer, @token, {:scheme => :query_string, :nonce => @nonce, :timestamp => @timestamp})
|
192
|
-
|
193
|
-
assert_equal 'POST', request.method
|
194
|
-
uri = URI.parse(request.path)
|
195
|
-
assert_equal '/test', uri.path
|
196
|
-
assert_equal nil, uri.fragment
|
197
|
-
assert_equal "data", request.body
|
198
|
-
assert_equal 'text/ascii', request.content_type
|
199
|
-
assert_equal "key=value&oauth_body_hash=oXyaqmHoChv3HQ2FCvTluqmAC70%3D&oauth_consumer_key=consumer_key_86cad9&oauth_nonce=225579211881198842005988698334675835446&oauth_signature=MHRKU42iVHU4Ke9kBUDa9Zw6IAM%3D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1199645624&oauth_token=token_411a7f&oauth_version=1.0", uri.query.split("&").sort.join('&')
|
200
|
-
assert_equal nil, request['authorization']
|
201
|
-
end
|
202
|
-
|
203
|
-
|
204
|
-
def test_example_from_specs
|
205
|
-
consumer=OAuth::Consumer.new("dpf43f3p2l4k3l03","kd94hf93k423kf44")
|
206
|
-
token = OAuth::Token.new('nnch734d00sl2jdk', 'pfkkdhi9sl3r4s00')
|
207
|
-
request_uri = URI.parse('http://photos.example.net/photos?file=vacation.jpg&size=original')
|
208
|
-
nonce = 'kllo9940pd9333jh'
|
209
|
-
timestamp = "1191242096"
|
210
|
-
http = Net::HTTP.new(request_uri.host, request_uri.port)
|
211
|
-
|
212
|
-
request = Net::HTTP::Get.new(request_uri.path + "?" + request_uri.query)
|
213
|
-
signature_base_string=request.signature_base_string(http, consumer, token, {:nonce => nonce, :timestamp => timestamp})
|
214
|
-
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
|
215
|
-
|
216
|
-
# request = Net::HTTP::Get.new(request_uri.path + "?" + request_uri.query)
|
217
|
-
request.oauth!(http, consumer, token, {:nonce => nonce, :timestamp => timestamp, :realm=>"http://photos.example.net/"})
|
218
|
-
|
219
|
-
assert_equal 'GET', request.method
|
220
|
-
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
|
221
|
-
correct_sorted_params.unshift 'OAuth realm="http://photos.example.net/"'
|
222
|
-
assert_equal correct_sorted_params, request['authorization'].split(', ').sort
|
223
|
-
end
|
224
|
-
|
225
|
-
def test_step_by_step_token_request
|
226
|
-
token_response = "oauth_token=requestkey&oauth_token_secret=requestsecret"
|
227
|
-
stub_request(:get, %r{http://term\.ie/oauth/example/request_token\.php(\?.*)?}).to_return(:body => token_response)
|
228
|
-
|
229
|
-
consumer=OAuth::Consumer.new(
|
230
|
-
"key",
|
231
|
-
"secret")
|
232
|
-
request_uri = URI.parse('http://term.ie/oauth/example/request_token.php')
|
233
|
-
nonce = rand(2**128).to_s
|
234
|
-
timestamp = Time.now.to_i.to_s
|
235
|
-
http = Net::HTTP.new(request_uri.host, request_uri.port)
|
236
|
-
|
237
|
-
request = Net::HTTP::Get.new(request_uri.path)
|
238
|
-
signature_base_string=request.signature_base_string(http, consumer, nil, {:scheme=>:query_string,:nonce => nonce, :timestamp => timestamp})
|
239
|
-
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
|
240
|
-
|
241
|
-
# request = Net::HTTP::Get.new(request_uri.path)
|
242
|
-
request.oauth!(http, consumer, nil, {:scheme=>:query_string,:nonce => nonce, :timestamp => timestamp})
|
243
|
-
assert_equal 'GET', request.method
|
244
|
-
assert_nil request.body
|
245
|
-
assert_nil request['authorization']
|
246
|
-
# assert_equal 'OAuth oauth_nonce="kllo9940pd9333jh", oauth_signature_method="HMAC-SHA1", oauth_token="", oauth_timestamp="'+timestamp+'", oauth_consumer_key="key", oauth_signature="tR3%2BTy81lMeYAr%2FFid0kMTYa%2FWM%3D", oauth_version="1.0"', request['authorization']
|
247
|
-
|
248
|
-
response=http.request(request)
|
249
|
-
assert_equal "200",response.code
|
250
|
-
# assert_equal request['authorization'],response.body
|
251
|
-
assert_equal token_response, response.body
|
252
|
-
end
|
253
|
-
|
254
|
-
def test_that_put_bodies_signed
|
255
|
-
request = Net::HTTP::Put.new(@request_uri.path)
|
256
|
-
request.body = "<?xml version=\"1.0\"?><foo><bar>baz</bar></foo>"
|
257
|
-
request["Content-Type"] = "application/xml"
|
258
|
-
signature_base_string=request.signature_base_string(@http, @consumer, nil, { :nonce => @nonce, :timestamp => @timestamp })
|
259
|
-
assert_equal "PUT&http%3A%2F%2Fexample.com%2Ftest&oauth_body_hash%3DDvAa1AWdFoH9K%252B%252F2AHm3f6wH27k%253D%26oauth_consumer_key%3Dconsumer_key_86cad9%26oauth_nonce%3D225579211881198842005988698334675835446%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1199645624%26oauth_version%3D1.0", signature_base_string
|
260
|
-
end
|
261
|
-
|
262
|
-
def test_that_put_bodies_not_signed_even_if_form_urlencoded
|
263
|
-
request = Net::HTTP::Put.new(@request_uri.path)
|
264
|
-
request.set_form_data( { 'key2' => 'value2' } )
|
265
|
-
signature_base_string=request.signature_base_string(@http, @consumer, nil, { :nonce => @nonce, :timestamp => @timestamp })
|
266
|
-
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
|
267
|
-
end
|
268
|
-
|
269
|
-
def test_that_post_bodies_signed_if_form_urlencoded
|
270
|
-
request = Net::HTTP::Post.new(@request_uri.path)
|
271
|
-
request.set_form_data( { 'key2' => 'value2' } )
|
272
|
-
signature_base_string=request.signature_base_string(@http, @consumer, nil, { :nonce => @nonce, :timestamp => @timestamp })
|
273
|
-
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
|
274
|
-
end
|
275
|
-
|
276
|
-
def test_that_post_bodies_signed_if_other_content_type
|
277
|
-
request = Net::HTTP::Post.new(@request_uri.path)
|
278
|
-
request.body = "<?xml version=\"1.0\"?><foo><bar>baz</bar></foo>"
|
279
|
-
request["Content-Type"] = "application/xml"
|
280
|
-
signature_base_string=request.signature_base_string(@http, @consumer, nil, { :nonce => @nonce, :timestamp => @timestamp })
|
281
|
-
assert_equal "POST&http%3A%2F%2Fexample.com%2Ftest&oauth_body_hash%3DDvAa1AWdFoH9K%252B%252F2AHm3f6wH27k%253D%26oauth_consumer_key%3Dconsumer_key_86cad9%26oauth_nonce%3D225579211881198842005988698334675835446%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1199645624%26oauth_version%3D1.0", signature_base_string
|
282
|
-
end
|
283
|
-
|
284
|
-
def test_that_site_address_is_not_modified_in_place
|
285
|
-
options = { :site => 'http://twitter.com', :request_endpoint => 'http://api.twitter.com' }
|
286
|
-
request = Net::HTTP::Get.new(@request_uri.path + "?" + request_parameters_to_s)
|
287
|
-
request.oauth!(@http, @consumer, @token, options)
|
288
|
-
assert_equal "http://twitter.com", options[:site]
|
289
|
-
assert_equal "http://api.twitter.com", options[:request_endpoint]
|
290
|
-
end
|
291
|
-
|
292
|
-
protected
|
293
|
-
|
294
|
-
def assert_no_match exp, act, msg = "Expected #{act.inspect} to not match #{exp.inspect}"
|
295
|
-
assert act !~ exp, msg
|
296
|
-
end
|
297
|
-
|
298
|
-
def request_parameters_to_s
|
299
|
-
@request_parameters.map { |k,v| "#{k}=#{v}" }.join("&")
|
300
|
-
end
|
301
|
-
|
302
|
-
end
|