oauth 0.4.2 → 0.4.3
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/Gemfile +1 -1
- data/Gemfile.lock +2 -2
- data/HISTORY +4 -0
- data/lib/digest/hmac.rb +3 -3
- data/lib/oauth.rb +1 -1
- data/lib/oauth/client/em_http.rb +12 -12
- data/lib/oauth/client/helper.rb +1 -1
- data/lib/oauth/consumer.rb +3 -3
- data/lib/oauth/core_ext.rb +2 -2
- data/lib/oauth/errors/problem.rb +1 -1
- data/lib/oauth/errors/unauthorized.rb +1 -1
- data/lib/oauth/helper.rb +4 -4
- data/lib/oauth/oauth.rb +1 -1
- data/lib/oauth/oauth_test_helper.rb +1 -1
- data/lib/oauth/request_proxy/curb_request.rb +13 -13
- data/lib/oauth/request_proxy/em_http_request.rb +11 -12
- data/lib/oauth/request_proxy/typhoeus_request.rb +10 -10
- data/lib/oauth/signature/base.rb +2 -2
- data/lib/oauth/signature/hmac/sha1.rb +1 -1
- data/oauth.gemspec +2 -2
- data/test/cases/oauth_case.rb +3 -3
- data/test/cases/spec/1_0-final/test_construct_request_url.rb +9 -9
- data/test/cases/spec/1_0-final/test_normalize_request_parameters.rb +19 -19
- data/test/cases/spec/1_0-final/test_parameter_encodings.rb +6 -6
- data/test/cases/spec/1_0-final/test_signature_base_strings.rb +21 -21
- data/test/test_consumer.rb +4 -4
- data/test/test_curb_request_proxy.rb +9 -9
- data/test/test_em_http_client.rb +6 -6
- data/test/test_em_http_request_proxy.rb +15 -15
- data/test/test_helper.rb +3 -3
- data/test/test_net_http_client.rb +2 -2
- data/test/test_rsa_sha1.rb +6 -6
- data/test/test_server.rb +5 -5
- data/test/test_token.rb +14 -14
- data/test/test_typhoeus_request_proxy.rb +1 -1
- metadata +4 -4
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -7,7 +7,7 @@ GEM
|
|
7
7
|
activesupport (2.3.8)
|
8
8
|
addressable (2.2.0)
|
9
9
|
curb (0.7.7.1)
|
10
|
-
em-http-request (0.2.
|
10
|
+
em-http-request (0.2.11)
|
11
11
|
addressable (>= 2.0.0)
|
12
12
|
eventmachine (>= 0.12.9)
|
13
13
|
eventmachine (0.12.10)
|
@@ -34,7 +34,7 @@ PLATFORMS
|
|
34
34
|
DEPENDENCIES
|
35
35
|
actionpack (= 2.3.8)
|
36
36
|
curb (>= 0.6.6.0)
|
37
|
-
em-http-request
|
37
|
+
em-http-request (= 0.2.11)
|
38
38
|
jeweler
|
39
39
|
mocha (>= 0.9.8)
|
40
40
|
typhoeus (>= 0.1.13)
|
data/HISTORY
CHANGED
data/lib/digest/hmac.rb
CHANGED
@@ -2,8 +2,8 @@
|
|
2
2
|
#
|
3
3
|
# An implementation of HMAC keyed-hashing algorithm
|
4
4
|
#
|
5
|
-
# == Overview
|
6
|
-
#
|
5
|
+
# == Overview
|
6
|
+
#
|
7
7
|
# This library adds a method named hmac() to Digest classes, which
|
8
8
|
# creates a Digest class for calculating HMAC digests.
|
9
9
|
#
|
@@ -101,4 +101,4 @@ unless defined?(Digest::HMAC)
|
|
101
101
|
end
|
102
102
|
end
|
103
103
|
end
|
104
|
-
end
|
104
|
+
end
|
data/lib/oauth.rb
CHANGED
data/lib/oauth/client/em_http.rb
CHANGED
@@ -13,7 +13,7 @@ class EventMachine::HttpClient
|
|
13
13
|
# this may add a header, additional query string parameters, or additional POST body parameters.
|
14
14
|
# The default scheme is +header+, in which the OAuth parameters as put into the +Authorization+
|
15
15
|
# header.
|
16
|
-
#
|
16
|
+
#
|
17
17
|
# * http - Configured Net::HTTP instance, ignored in this scenario except for getting host.
|
18
18
|
# * consumer - OAuth::Consumer instance
|
19
19
|
# * token - OAuth::Token instance
|
@@ -41,13 +41,13 @@ class EventMachine::HttpClient
|
|
41
41
|
# on the <tt>options[:scheme]</tt> being used so this must match what will be used for the request
|
42
42
|
# itself. The default scheme is +header+, in which the OAuth parameters as put into the +Authorization+
|
43
43
|
# header.
|
44
|
-
#
|
44
|
+
#
|
45
45
|
# * http - Configured Net::HTTP instance
|
46
46
|
# * consumer - OAuth::Consumer instance
|
47
47
|
# * token - OAuth::Token instance
|
48
48
|
# * options - Request-specific options (e.g. +request_uri+, +consumer+, +token+, +scheme+,
|
49
49
|
# +signature_method+, +nonce+, +timestamp+)
|
50
|
-
#
|
50
|
+
#
|
51
51
|
# See Also: {OAuth core spec version 1.0, section 9.1.1}[http://oauth.net/core/1.0#rfc.section.9.1.1]
|
52
52
|
def signature_base_string(http, consumer = nil, token = nil, options = {})
|
53
53
|
options = { :request_uri => normalized_oauth_uri(http),
|
@@ -65,14 +65,14 @@ class EventMachine::HttpClient
|
|
65
65
|
# the gem June 19, 2010
|
66
66
|
# see: http://github.com/igrigorik/em-http-request/commit/d536fc17d56dbe55c487eab01e2ff9382a62598b
|
67
67
|
def normalize_uri
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
68
|
+
@normalized_uri ||= begin
|
69
|
+
uri = @uri.dup
|
70
|
+
encoded_query = encode_query(@uri, @options[:query])
|
71
|
+
path, query = encoded_query.split("?", 2)
|
72
|
+
uri.query = query unless encoded_query.empty?
|
73
|
+
uri.path = path
|
74
|
+
uri
|
75
|
+
end
|
76
76
|
end
|
77
77
|
|
78
78
|
protected
|
@@ -116,5 +116,5 @@ class EventMachine::HttpClient
|
|
116
116
|
def set_oauth_query_string
|
117
117
|
raise NotImplementedError, 'please use the set_oauth_header method instead'
|
118
118
|
end
|
119
|
-
|
119
|
+
|
120
120
|
end
|
data/lib/oauth/client/helper.rb
CHANGED
@@ -63,7 +63,7 @@ module OAuth::Client
|
|
63
63
|
def amend_user_agent_header(headers)
|
64
64
|
@oauth_ua_string ||= "OAuth gem v#{OAuth::VERSION}"
|
65
65
|
# Net::HTTP in 1.9 appends Ruby
|
66
|
-
if headers['User-Agent'] && headers['User-Agent'] != 'Ruby'
|
66
|
+
if headers['User-Agent'] && headers['User-Agent'] != 'Ruby'
|
67
67
|
headers['User-Agent'] += " (#{@oauth_ua_string})"
|
68
68
|
else
|
69
69
|
headers['User-Agent'] = @oauth_ua_string
|
data/lib/oauth/consumer.rb
CHANGED
@@ -39,7 +39,7 @@ module OAuth
|
|
39
39
|
|
40
40
|
# Default http method used for OAuth Token Requests (defaults to :post)
|
41
41
|
:http_method => :post,
|
42
|
-
|
42
|
+
|
43
43
|
# Add a custom ca_file for consumer
|
44
44
|
# :ca_file => '/etc/certs.pem'
|
45
45
|
|
@@ -235,8 +235,8 @@ module OAuth
|
|
235
235
|
end
|
236
236
|
|
237
237
|
def request_endpoint
|
238
|
-
|
239
|
-
|
238
|
+
return nil if @options[:request_endpoint].nil?
|
239
|
+
@options[:request_endpoint].to_s
|
240
240
|
end
|
241
241
|
|
242
242
|
def scheme
|
data/lib/oauth/core_ext.rb
CHANGED
data/lib/oauth/errors/problem.rb
CHANGED
data/lib/oauth/helper.rb
CHANGED
@@ -5,7 +5,7 @@ module OAuth
|
|
5
5
|
module Helper
|
6
6
|
extend self
|
7
7
|
|
8
|
-
# Escape +value+ by URL encoding all non-reserved character.
|
8
|
+
# Escape +value+ by URL encoding all non-reserved character.
|
9
9
|
#
|
10
10
|
# See Also: {OAuth core spec version 1.0, section 5.1}[http://oauth.net/core/1.0#rfc.section.5.1]
|
11
11
|
def escape(value)
|
@@ -54,7 +54,7 @@ module OAuth
|
|
54
54
|
# hash = parse_header(headers['Authorization'] || headers['WWW-Authenticate'])
|
55
55
|
# hash['oauth_timestamp']
|
56
56
|
# #=>"1234567890"
|
57
|
-
#
|
57
|
+
#
|
58
58
|
def parse_header(header)
|
59
59
|
# decompose
|
60
60
|
params = header[6,header.length].split(/[,=]/)
|
@@ -76,10 +76,10 @@ module OAuth
|
|
76
76
|
def unescape(value)
|
77
77
|
URI.unescape(value.gsub('+', '%2B'))
|
78
78
|
end
|
79
|
-
|
79
|
+
|
80
80
|
def stringify_keys(hash)
|
81
81
|
new_h = {}
|
82
|
-
hash.each do |k, v|
|
82
|
+
hash.each do |k, v|
|
83
83
|
new_h[k.to_s] = v.is_a?(Hash) ? stringify_keys(v) : v
|
84
84
|
end
|
85
85
|
new_h
|
data/lib/oauth/oauth.rb
CHANGED
@@ -4,7 +4,7 @@ module OAuth
|
|
4
4
|
OUT_OF_BAND = "oob"
|
5
5
|
|
6
6
|
# required parameters, per sections 6.1.1, 6.3.1, and 7
|
7
|
-
PARAMETERS = %w(oauth_callback oauth_consumer_key oauth_token
|
7
|
+
PARAMETERS = %w(oauth_callback oauth_consumer_key oauth_token
|
8
8
|
oauth_signature_method oauth_timestamp oauth_nonce oauth_verifier
|
9
9
|
oauth_version oauth_signature oauth_body_hash)
|
10
10
|
|
@@ -6,23 +6,23 @@ require 'cgi'
|
|
6
6
|
module OAuth::RequestProxy::Curl
|
7
7
|
class Easy < OAuth::RequestProxy::Base
|
8
8
|
# Proxy for signing Curl::Easy requests
|
9
|
-
# Usage example:
|
10
|
-
# oauth_params = {:consumer => oauth_consumer, :token => access_token}
|
9
|
+
# Usage example:
|
10
|
+
# oauth_params = {:consumer => oauth_consumer, :token => access_token}
|
11
11
|
# req = Curl::Easy.new(uri)
|
12
|
-
# oauth_helper = OAuth::Client::Helper.new(req, oauth_params.merge(:request_uri => uri))
|
12
|
+
# oauth_helper = OAuth::Client::Helper.new(req, oauth_params.merge(:request_uri => uri))
|
13
13
|
# req.headers.merge!({"Authorization" => oauth_helper.header})
|
14
14
|
# req.http_get
|
15
15
|
# response = req.body_str
|
16
|
-
proxies ::Curl::Easy
|
17
|
-
|
16
|
+
proxies ::Curl::Easy
|
17
|
+
|
18
18
|
def method
|
19
19
|
nil
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
def uri
|
23
23
|
options[:uri].to_s
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
def parameters
|
27
27
|
if options[:clobber_request]
|
28
28
|
options[:parameters]
|
@@ -30,20 +30,20 @@ module OAuth::RequestProxy::Curl
|
|
30
30
|
post_parameters.merge(query_parameters).merge(options[:parameters] || {})
|
31
31
|
end
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
private
|
35
|
-
|
35
|
+
|
36
36
|
def query_parameters
|
37
37
|
query = URI.parse(request.url).query
|
38
38
|
return(query ? CGI.parse(query) : {})
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
def post_parameters
|
42
42
|
post_body = {}
|
43
|
-
|
43
|
+
|
44
44
|
# Post params are only used if posting form data
|
45
45
|
if (request.headers['Content-Type'] && request.headers['Content-Type'].downcase == 'application/x-www-form-urlencoded')
|
46
|
-
|
46
|
+
|
47
47
|
request.post_body.split("&").each do |str|
|
48
48
|
param = str.split("=")
|
49
49
|
post_body[param[0]] = param[1]
|
@@ -52,4 +52,4 @@ module OAuth::RequestProxy::Curl
|
|
52
52
|
post_body
|
53
53
|
end
|
54
54
|
end
|
55
|
-
end
|
55
|
+
end
|
@@ -5,22 +5,22 @@ require 'cgi'
|
|
5
5
|
|
6
6
|
module OAuth::RequestProxy::EventMachine
|
7
7
|
class HttpRequest < OAuth::RequestProxy::Base
|
8
|
-
|
8
|
+
|
9
9
|
# A Proxy for use when you need to sign EventMachine::HttpClient instances.
|
10
10
|
# It needs to be called once the client is construct but before data is sent.
|
11
11
|
# Also see oauth/client/em-http
|
12
12
|
proxies ::EventMachine::HttpClient
|
13
|
-
|
13
|
+
|
14
14
|
# Request in this con
|
15
|
-
|
15
|
+
|
16
16
|
def method
|
17
17
|
request.method
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
def uri
|
21
21
|
request.normalize_uri.to_s
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
def parameters
|
25
25
|
if options[:clobber_request]
|
26
26
|
options[:parameters]
|
@@ -28,17 +28,17 @@ module OAuth::RequestProxy::EventMachine
|
|
28
28
|
all_parameters
|
29
29
|
end
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
protected
|
33
|
-
|
33
|
+
|
34
34
|
def all_parameters
|
35
35
|
merged_parameters({}, post_parameters, query_parameters, options[:parameters])
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
38
|
def query_parameters
|
39
39
|
CGI.parse(request.normalize_uri.query.to_s)
|
40
40
|
end
|
41
|
-
|
41
|
+
|
42
42
|
def post_parameters
|
43
43
|
headers = request.options[:head] || {}
|
44
44
|
form_encoded = headers['Content-Type'].to_s.downcase == 'application/x-www-form-urlencoded'
|
@@ -48,7 +48,7 @@ module OAuth::RequestProxy::EventMachine
|
|
48
48
|
{}
|
49
49
|
end
|
50
50
|
end
|
51
|
-
|
51
|
+
|
52
52
|
def merged_parameters(params, *extra_params)
|
53
53
|
extra_params.compact.each do |params_pairs|
|
54
54
|
params_pairs.each_pair do |key, value|
|
@@ -61,7 +61,6 @@ module OAuth::RequestProxy::EventMachine
|
|
61
61
|
end
|
62
62
|
params
|
63
63
|
end
|
64
|
-
|
64
|
+
|
65
65
|
end
|
66
66
|
end
|
67
|
-
|
@@ -7,25 +7,25 @@ require 'cgi'
|
|
7
7
|
module OAuth::RequestProxy::Typhoeus
|
8
8
|
class Request < OAuth::RequestProxy::Base
|
9
9
|
# Proxy for signing Typhoeus::Request requests
|
10
|
-
# Usage example:
|
11
|
-
# oauth_params = {:consumer => oauth_consumer, :token => access_token}
|
10
|
+
# Usage example:
|
11
|
+
# oauth_params = {:consumer => oauth_consumer, :token => access_token}
|
12
12
|
# req = Typhoeus::Request.new(uri, options)
|
13
|
-
# oauth_helper = OAuth::Client::Helper.new(req, oauth_params.merge(:request_uri => uri))
|
13
|
+
# oauth_helper = OAuth::Client::Helper.new(req, oauth_params.merge(:request_uri => uri))
|
14
14
|
# req.headers.merge!({"Authorization" => oauth_helper.header})
|
15
15
|
# hydra = Typhoeus::Hydra.new()
|
16
16
|
# hydra.queue(req)
|
17
17
|
# hydra.run
|
18
18
|
# response = req.response
|
19
|
-
proxies Typhoeus::Request
|
19
|
+
proxies Typhoeus::Request
|
20
20
|
|
21
21
|
def method
|
22
22
|
request.method.to_s.upcase
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
def uri
|
26
26
|
options[:uri].to_s
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
def parameters
|
30
30
|
if options[:clobber_request]
|
31
31
|
options[:parameters]
|
@@ -33,21 +33,21 @@ module OAuth::RequestProxy::Typhoeus
|
|
33
33
|
post_parameters.merge(query_parameters).merge(options[:parameters] || {})
|
34
34
|
end
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
private
|
38
|
-
|
38
|
+
|
39
39
|
def query_parameters
|
40
40
|
query = URI.parse(request.url).query
|
41
41
|
return(query ? CGI.parse(query) : {})
|
42
42
|
end
|
43
|
-
|
43
|
+
|
44
44
|
def post_parameters
|
45
45
|
# Post params are only used if posting form data
|
46
46
|
if(method == 'POST' && request.headers['Content-Type'] && request.headers['Content-Type'].downcase == 'application/x-www-form-urlencoded')
|
47
47
|
request.body || {}
|
48
48
|
else
|
49
49
|
{}
|
50
|
-
end
|
50
|
+
end
|
51
51
|
end
|
52
52
|
end
|
53
53
|
end
|
data/lib/oauth/signature/base.rb
CHANGED
@@ -11,7 +11,7 @@ module OAuth::Signature
|
|
11
11
|
attr_reader :token_secret, :consumer_secret, :request
|
12
12
|
|
13
13
|
def self.implements(signature_method = nil)
|
14
|
-
return @implements if signature_method.nil?
|
14
|
+
return @implements if signature_method.nil?
|
15
15
|
@implements = signature_method
|
16
16
|
OAuth::Signature.available_methods[@implements] = self
|
17
17
|
end
|
@@ -20,7 +20,7 @@ module OAuth::Signature
|
|
20
20
|
return @digest_class if digest_class.nil?
|
21
21
|
@digest_class = digest_class
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
def self.digest_klass(digest_klass = nil)
|
25
25
|
return @digest_klass if digest_klass.nil?
|
26
26
|
@digest_klass = digest_klass
|
data/oauth.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{oauth}
|
8
|
-
s.version = "0.4.
|
8
|
+
s.version = "0.4.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Pelle Braendgaard", "Blaine Cook", "Larry Halff", "Jesse Clark", "Jon Crosby", "Seth Fitzsimmons", "Matt Sanford", "Aaron Quint"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-09-01}
|
13
13
|
s.default_executable = %q{oauth}
|
14
14
|
s.description = %q{OAuth Core Ruby implementation}
|
15
15
|
s.email = %q{oauth-ruby@googlegroups.com}
|
data/test/cases/oauth_case.rb
CHANGED
@@ -9,11 +9,11 @@ class OAuthCase < Test::Unit::TestCase
|
|
9
9
|
return if @method_name.to_s == "default_test"
|
10
10
|
super
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
protected
|
14
|
-
|
14
|
+
|
15
15
|
# Creates a fake request
|
16
16
|
def request(params={},method='GET',uri="http://photos.example.net/photos")
|
17
17
|
OAuth::RequestProxy.proxy({'parameters'=>params,'method'=>method,'uri'=>uri})
|
18
18
|
end
|
19
|
-
end
|
19
|
+
end
|
@@ -19,11 +19,11 @@ require File.expand_path('../../../oauth_case', __FILE__)
|
|
19
19
|
|
20
20
|
|
21
21
|
class ConstructRequestUrlTest < OAuthCase
|
22
|
-
|
22
|
+
|
23
23
|
def test_from_spec
|
24
24
|
assert_request_url("http://example.com/resource","HTTP://Example.com:80/resource?id=123")
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
def test_simple_url_with_ending_slash
|
28
28
|
assert_request_url("http://example.com/","http://example.com/")
|
29
29
|
end
|
@@ -31,7 +31,7 @@ class ConstructRequestUrlTest < OAuthCase
|
|
31
31
|
def test_simple_url_without_ending_slash
|
32
32
|
assert_request_url("http://example.com/","http://example.com")
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
def test_of_normalized_http
|
36
36
|
assert_request_url("http://example.com/resource","http://example.com/resource")
|
37
37
|
end
|
@@ -43,20 +43,20 @@ class ConstructRequestUrlTest < OAuthCase
|
|
43
43
|
def test_of_normalized_https
|
44
44
|
assert_request_url("https://example.com/resource","https://example.com/resource")
|
45
45
|
end
|
46
|
-
|
46
|
+
|
47
47
|
def test_of_http_with_non_standard_port
|
48
48
|
assert_request_url("http://example.com:8080/resource","http://example.com:8080/resource")
|
49
49
|
end
|
50
|
-
|
50
|
+
|
51
51
|
def test_of_https_with_non_standard_port
|
52
52
|
assert_request_url("https://example.com:8080/resource","https://example.com:8080/resource")
|
53
53
|
end
|
54
|
-
|
54
|
+
|
55
55
|
protected
|
56
|
-
|
57
|
-
|
56
|
+
|
57
|
+
|
58
58
|
def assert_request_url(expected,given,message=nil)
|
59
59
|
assert_equal expected, request({},'GET',given).normalized_uri, message
|
60
60
|
end
|
61
|
-
|
61
|
+
|
62
62
|
end
|
@@ -3,29 +3,29 @@ require File.expand_path('../../../oauth_case', __FILE__)
|
|
3
3
|
# See http://oauth.net/core/1.0/#anchor14
|
4
4
|
#
|
5
5
|
# 9.1.1. Normalize Request Parameters
|
6
|
-
#
|
6
|
+
#
|
7
7
|
# The request parameters are collected, sorted and concatenated into a normalized string:
|
8
|
-
#
|
8
|
+
#
|
9
9
|
# Parameters in the OAuth HTTP Authorization header excluding the realm parameter.
|
10
10
|
# Parameters in the HTTP POST request body (with a content-type of application/x-www-form-urlencoded).
|
11
11
|
# HTTP GET parameters added to the URLs in the query part (as defined by [RFC3986] section 3).
|
12
12
|
# The oauth_signature parameter MUST be excluded.
|
13
|
-
#
|
13
|
+
#
|
14
14
|
# The parameters are normalized into a single string as follows:
|
15
|
-
#
|
16
|
-
# Parameters are sorted by name, using lexicographical byte value ordering.
|
15
|
+
#
|
16
|
+
# Parameters are sorted by name, using lexicographical byte value ordering.
|
17
17
|
# If two or more parameters share the same name, they are sorted by their value. For example:
|
18
18
|
#
|
19
19
|
# a=1, c=hi%20there, f=25, f=50, f=a, z=p, z=t
|
20
|
-
# Parameters are concatenated in their sorted order into a single string. For each parameter,
|
21
|
-
# the name is separated from the corresponding value by an ‘=’ character (ASCII code 61), even
|
20
|
+
# Parameters are concatenated in their sorted order into a single string. For each parameter,
|
21
|
+
# the name is separated from the corresponding value by an ‘=’ character (ASCII code 61), even
|
22
22
|
# if the value is empty. Each name-value pair is separated by an ‘&’ character (ASCII code 38). For example:
|
23
23
|
# a=1&c=hi%20there&f=25&f=50&f=a&z=p&z=t
|
24
|
-
#
|
24
|
+
#
|
25
25
|
|
26
26
|
|
27
27
|
class NormalizeRequestParametersTest < OAuthCase
|
28
|
-
|
28
|
+
|
29
29
|
def test_parameters_for_signature
|
30
30
|
params={'a'=>1, 'c'=>'hi there', 'f'=>'25', 'f'=>'50', 'f'=>'a', 'z'=>'p', 'z'=>'t'}
|
31
31
|
assert_equal params,request(params).parameters_for_signature
|
@@ -36,7 +36,7 @@ class NormalizeRequestParametersTest < OAuthCase
|
|
36
36
|
params={'a'=>1, 'c'=>'hi there', 'f'=>'25', 'f'=>'50', 'f'=>'a', 'z'=>'p', 'z'=>'t'}
|
37
37
|
assert_equal params,request(params.merge({'oauth_signature'=>'blalbla'})).parameters_for_signature
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
def test_spec_example
|
41
41
|
assert_normalized 'a=1&c=hi%20there&f=25&f=50&f=a&z=p&z=t', { 'a' => 1, 'c' => 'hi there', 'f' => ['25', '50', 'a'], 'z' => ['p', 't'] }
|
42
42
|
end
|
@@ -49,26 +49,26 @@ class NormalizeRequestParametersTest < OAuthCase
|
|
49
49
|
def test_empty
|
50
50
|
assert_normalized "",{}
|
51
51
|
end
|
52
|
-
|
53
|
-
|
52
|
+
|
53
|
+
|
54
54
|
# These are from the wiki http://wiki.oauth.net/TestCases
|
55
55
|
# in the section Normalize Request Parameters
|
56
56
|
# Parameters have already been x-www-form-urlencoded (i.e. + = <space>)
|
57
57
|
def test_wiki1
|
58
58
|
assert_normalized "name=",{"name"=>nil}
|
59
59
|
end
|
60
|
-
|
60
|
+
|
61
61
|
def test_wiki2
|
62
62
|
assert_normalized "a=b",{'a'=>'b'}
|
63
63
|
end
|
64
|
-
|
64
|
+
|
65
65
|
def test_wiki3
|
66
66
|
assert_normalized "a=b&c=d",{'a'=>'b','c'=>'d'}
|
67
67
|
end
|
68
|
-
|
68
|
+
|
69
69
|
def test_wiki4
|
70
70
|
assert_normalized "a=x%20y&a=x%21y",{'a'=>["x!y","x y"]}
|
71
|
-
|
71
|
+
|
72
72
|
end
|
73
73
|
|
74
74
|
def test_wiki5
|
@@ -76,12 +76,12 @@ class NormalizeRequestParametersTest < OAuthCase
|
|
76
76
|
end
|
77
77
|
|
78
78
|
protected
|
79
|
-
|
80
|
-
|
79
|
+
|
80
|
+
|
81
81
|
def assert_normalized(expected,params,message=nil)
|
82
82
|
assert_equal expected, normalize_request_parameters(params), message
|
83
83
|
end
|
84
|
-
|
84
|
+
|
85
85
|
def normalize_request_parameters(params={})
|
86
86
|
request(params).normalized_parameters
|
87
87
|
end
|
@@ -3,14 +3,14 @@ require File.expand_path('../../../oauth_case', __FILE__)
|
|
3
3
|
# See http://oauth.net/core/1.0/#encoding_parameters
|
4
4
|
#
|
5
5
|
# 5.1. Parameter Encoding
|
6
|
-
#
|
7
|
-
# All parameter names and values are escaped using the [RFC3986] percent-encoding (%xx) mechanism.
|
8
|
-
# Characters not in the unreserved character set ([RFC3986] section 2.3) MUST be encoded. Characters
|
9
|
-
# in the unreserved character set MUST NOT be encoded. Hexadecimal characters in encodings MUST be
|
6
|
+
#
|
7
|
+
# All parameter names and values are escaped using the [RFC3986] percent-encoding (%xx) mechanism.
|
8
|
+
# Characters not in the unreserved character set ([RFC3986] section 2.3) MUST be encoded. Characters
|
9
|
+
# in the unreserved character set MUST NOT be encoded. Hexadecimal characters in encodings MUST be
|
10
10
|
# upper case. Text names and values MUST be encoded as UTF-8 octets before percent-encoding them per [RFC3629].
|
11
|
-
#
|
11
|
+
#
|
12
12
|
# unreserved = ALPHA, DIGIT, '-', '.', '_', '~'
|
13
|
-
#
|
13
|
+
#
|
14
14
|
|
15
15
|
class ParameterEncodingTest < OAuthCase
|
16
16
|
def test_encodings_alpha_num
|
@@ -3,18 +3,18 @@ require File.expand_path('../../../oauth_case', __FILE__)
|
|
3
3
|
# See http://oauth.net/core/1.0/#anchor14
|
4
4
|
#
|
5
5
|
# 9.1. Signature Base String
|
6
|
-
#
|
6
|
+
#
|
7
7
|
# The Signature Base String is a consistent reproducible concatenation of the request elements
|
8
|
-
# into a single string. The string is used as an input in hashing or signing algorithms. The
|
9
|
-
# HMAC-SHA1 signature method provides both a standard and an example of using the Signature
|
10
|
-
# Base String with a signing algorithm to generate signatures. All the request parameters MUST
|
8
|
+
# into a single string. The string is used as an input in hashing or signing algorithms. The
|
9
|
+
# HMAC-SHA1 signature method provides both a standard and an example of using the Signature
|
10
|
+
# Base String with a signing algorithm to generate signatures. All the request parameters MUST
|
11
11
|
# be encoded as described in Parameter Encoding prior to constructing the Signature Base String.
|
12
|
-
#
|
12
|
+
#
|
13
13
|
|
14
14
|
class SignatureBaseStringTest < OAuthCase
|
15
|
-
|
15
|
+
|
16
16
|
def test_A_5_1
|
17
|
-
parameters={
|
17
|
+
parameters={
|
18
18
|
'oauth_consumer_key'=>'dpf43f3p2l4k3l03',
|
19
19
|
'oauth_token'=>'nnch734d00sl2jdk',
|
20
20
|
'oauth_signature_method'=>'HMAC-SHA1',
|
@@ -25,34 +25,34 @@ class SignatureBaseStringTest < OAuthCase
|
|
25
25
|
'size'=>'original'
|
26
26
|
}
|
27
27
|
sbs='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'
|
28
|
-
|
28
|
+
|
29
29
|
assert_signature_base_string sbs,parameters,'GET',"http://photos.example.net/photos"
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
# These are from the wiki http://wiki.oauth.net/TestCases
|
33
33
|
# in the section Concatenate Test Elements
|
34
|
-
|
34
|
+
|
35
35
|
def test_wiki_1_simple_with_ending_slash
|
36
|
-
parameters={
|
36
|
+
parameters={
|
37
37
|
'n'=>'v'
|
38
38
|
}
|
39
39
|
sbs='GET&http%3A%2F%2Fexample.com%2F&n%3Dv'
|
40
|
-
|
40
|
+
|
41
41
|
assert_signature_base_string sbs,parameters,'GET',"http://example.com/"
|
42
42
|
end
|
43
43
|
|
44
|
-
|
44
|
+
|
45
45
|
def test_wiki_2_simple_without_ending_slash
|
46
|
-
parameters={
|
46
|
+
parameters={
|
47
47
|
'n'=>'v'
|
48
48
|
}
|
49
49
|
sbs='GET&http%3A%2F%2Fexample.com%2F&n%3Dv'
|
50
|
-
|
50
|
+
|
51
51
|
assert_signature_base_string sbs,parameters,'GET',"http://example.com"
|
52
52
|
end
|
53
53
|
|
54
54
|
def test_wiki_2_request_token
|
55
|
-
parameters={
|
55
|
+
parameters={
|
56
56
|
'oauth_version'=>'1.0',
|
57
57
|
'oauth_consumer_key'=>'dpf43f3p2l4k3l03',
|
58
58
|
'oauth_timestamp'=>'1191242090',
|
@@ -60,17 +60,17 @@ class SignatureBaseStringTest < OAuthCase
|
|
60
60
|
'oauth_signature_method'=>'PLAINTEXT',
|
61
61
|
'oauth_signature'=>'ignored' }
|
62
62
|
sbs='POST&https%3A%2F%2Fphotos.example.net%2Frequest_token&oauth_consumer_key%3Ddpf43f3p2l4k3l03%26oauth_nonce%3Dhsu94j3884jdopsl%26oauth_signature_method%3DPLAINTEXT%26oauth_timestamp%3D1191242090%26oauth_version%3D1.0'
|
63
|
-
|
63
|
+
|
64
64
|
assert_signature_base_string sbs,parameters,'POST',"https://photos.example.net/request_token"
|
65
65
|
end
|
66
|
-
|
66
|
+
|
67
67
|
protected
|
68
|
-
|
69
|
-
|
68
|
+
|
69
|
+
|
70
70
|
def assert_signature_base_string(expected,params={},method='GET',uri="http://photos.example.net/photos",message="Signature Base String does not match")
|
71
71
|
assert_equal expected, signature_base_string(params,method,uri), message
|
72
72
|
end
|
73
|
-
|
73
|
+
|
74
74
|
def signature_base_string(params={},method='GET',uri="http://photos.example.net/photos")
|
75
75
|
request(params,method,uri).signature_base_string
|
76
76
|
end
|
data/test/test_consumer.rb
CHANGED
@@ -119,7 +119,7 @@ class ConsumerTest < Test::Unit::TestCase
|
|
119
119
|
assert_equal 'token', token.token
|
120
120
|
assert_equal 'secret', token.secret
|
121
121
|
end
|
122
|
-
|
122
|
+
|
123
123
|
def test_that_can_provide_a_block_to_interpret_an_access_token_response
|
124
124
|
stub_token = mock
|
125
125
|
@consumer.expects(:request).returns(create_stub_http_response)
|
@@ -129,8 +129,8 @@ class ConsumerTest < Test::Unit::TestCase
|
|
129
129
|
assert_equal 'token', token.token
|
130
130
|
assert_equal 'secret', token.secret
|
131
131
|
end
|
132
|
-
|
133
|
-
def test_that_not_setting_ignore_callback_will_include_oauth_callback_in_request_options
|
132
|
+
|
133
|
+
def test_that_not_setting_ignore_callback_will_include_oauth_callback_in_request_options
|
134
134
|
request_options = {}
|
135
135
|
@consumer.stubs(:request).returns(create_stub_http_response)
|
136
136
|
|
@@ -147,7 +147,7 @@ class ConsumerTest < Test::Unit::TestCase
|
|
147
147
|
|
148
148
|
assert_nil request_options[:oauth_callback]
|
149
149
|
end
|
150
|
-
|
150
|
+
|
151
151
|
private
|
152
152
|
|
153
153
|
def create_stub_http_response expected_body=nil
|
@@ -19,7 +19,7 @@ class CurbRequestProxyTest < Test::Unit::TestCase
|
|
19
19
|
assert_equal expected_parameters, request_proxy.parameters_for_signature
|
20
20
|
assert_equal 'http://example.com/test', request_proxy.normalized_uri
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
def test_that_proxy_simple_post_request_works_with_arguments
|
24
24
|
request = Curl::Easy.new('/test')
|
25
25
|
params = {'key' => 'value'}
|
@@ -29,19 +29,19 @@ class CurbRequestProxyTest < Test::Unit::TestCase
|
|
29
29
|
assert_equal expected_parameters, request_proxy.parameters_for_signature
|
30
30
|
assert_equal 'http://example.com/test', request_proxy.normalized_uri
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
def test_that_proxy_simple_post_request_works_with_form_data
|
34
34
|
request = Curl::Easy.new('/test')
|
35
35
|
request.post_body = 'key=value'
|
36
36
|
request.headers['Content-Type'] = 'application/x-www-form-urlencoded'
|
37
|
-
|
37
|
+
|
38
38
|
request_proxy = OAuth::RequestProxy.proxy(request, {:uri => 'http://example.com/test'})
|
39
|
-
|
39
|
+
|
40
40
|
expected_parameters = {'key' => 'value'}
|
41
41
|
assert_equal expected_parameters, request_proxy.parameters_for_signature
|
42
42
|
assert_equal 'http://example.com/test', request_proxy.normalized_uri
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
def test_that_proxy_simple_put_request_works_with_arguments
|
46
46
|
request = Curl::Easy.new('/test')
|
47
47
|
params = {'key' => 'value'}
|
@@ -51,11 +51,11 @@ class CurbRequestProxyTest < Test::Unit::TestCase
|
|
51
51
|
assert_equal expected_parameters, request_proxy.parameters_for_signature
|
52
52
|
assert_equal 'http://example.com/test', request_proxy.normalized_uri
|
53
53
|
end
|
54
|
-
|
54
|
+
|
55
55
|
def test_that_proxy_simple_put_request_works_with_form_data
|
56
|
-
request = Curl::Easy.new('/test')
|
56
|
+
request = Curl::Easy.new('/test')
|
57
57
|
request.post_body = 'key=value'
|
58
|
-
|
58
|
+
|
59
59
|
request_proxy = OAuth::RequestProxy.proxy(request, {:uri => 'http://example.com/test'})
|
60
60
|
|
61
61
|
expected_parameters = {}
|
@@ -65,7 +65,7 @@ class CurbRequestProxyTest < Test::Unit::TestCase
|
|
65
65
|
|
66
66
|
def test_that_proxy_post_request_works_with_mixed_parameter_sources
|
67
67
|
request = Curl::Easy.new('/test?key=value')
|
68
|
-
request.post_body = 'key2=value2'
|
68
|
+
request.post_body = 'key2=value2'
|
69
69
|
request.headers['Content-Type'] = 'application/x-www-form-urlencoded'
|
70
70
|
request_proxy = OAuth::RequestProxy.proxy(request, {:uri => 'http://example.com/test?key=value', :parameters => {'key3' => 'value3'}})
|
71
71
|
|
data/test/test_em_http_client.rb
CHANGED
@@ -18,7 +18,7 @@ class EmHttpClientTest < Test::Unit::TestCase
|
|
18
18
|
# This is really unneeded I guess.
|
19
19
|
@http = Net::HTTP.new(@request_uri.host, @request_uri.port)
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
def test_that_using_auth_headers_on_get_requests_works
|
23
23
|
request = create_client
|
24
24
|
request.oauth!(@http, @consumer, @token, {:nonce => @nonce, :timestamp => @timestamp})
|
@@ -28,7 +28,7 @@ class EmHttpClientTest < Test::Unit::TestCase
|
|
28
28
|
assert_equal "key=value", request.normalize_uri.query
|
29
29
|
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)
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
def test_that_using_auth_headers_on_get_requests_works_with_plaintext
|
33
33
|
require 'oauth/signature/plaintext'
|
34
34
|
c = OAuth::Consumer.new('consumer_key_86cad9', '5888bf0345e5d237',{
|
@@ -52,9 +52,9 @@ class EmHttpClientTest < Test::Unit::TestCase
|
|
52
52
|
assert_equal 'key=value', request.normalize_body
|
53
53
|
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)
|
54
54
|
end
|
55
|
-
|
55
|
+
|
56
56
|
protected
|
57
|
-
|
57
|
+
|
58
58
|
def create_client(options = {})
|
59
59
|
method = options.delete(:method) || "GET"
|
60
60
|
uri = options.delete(:uri) || @request_uri.to_s
|
@@ -64,7 +64,7 @@ class EmHttpClientTest < Test::Unit::TestCase
|
|
64
64
|
client.options = options
|
65
65
|
client
|
66
66
|
end
|
67
|
-
|
67
|
+
|
68
68
|
def authz_header(request)
|
69
69
|
headers = request.options[:head] || {}
|
70
70
|
headers['Authorization'].to_s
|
@@ -75,5 +75,5 @@ class EmHttpClientTest < Test::Unit::TestCase
|
|
75
75
|
assert_equal expected[0,6], actual[0, 6]
|
76
76
|
assert_equal expected[6..1].split(', ').sort, actual[6..1].split(', ').sort
|
77
77
|
end
|
78
|
-
|
78
|
+
|
79
79
|
end
|
@@ -10,19 +10,19 @@ end
|
|
10
10
|
|
11
11
|
|
12
12
|
class EmHttpRequestProxyTest < Test::Unit::TestCase
|
13
|
-
|
13
|
+
|
14
14
|
def test_request_proxy_works_with_simple_request
|
15
15
|
proxy = create_request_proxy
|
16
16
|
assert_equal({}, proxy.parameters)
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
def test_request_proxy_works_with_query_string_params
|
20
20
|
assert_equal({"name" => ["Fred"]}, create_request_proxy(:query => "name=Fred").parameters)
|
21
21
|
assert_equal({"name" => ["Fred"]}, create_request_proxy(:query => {:name => "Fred"}).parameters)
|
22
22
|
proxy = create_request_proxy(:query => {:name => "Fred"}, :uri => "http://example.com/?awesome=true")
|
23
23
|
assert_equal({"name" => ["Fred"], "awesome" => ["true"]}, proxy.parameters)
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
def test_request_proxy_works_with_post_body_params_with_correct_content_type
|
27
27
|
proxy = create_request_proxy :head => {'Content-Type' => 'application/x-www-form-urlencoded'}, :method => "POST"
|
28
28
|
assert_equal({}, proxy.parameters)
|
@@ -37,7 +37,7 @@ class EmHttpRequestProxyTest < Test::Unit::TestCase
|
|
37
37
|
proxy = create_request_proxy :head => {'Content-Type' => 'application/x-www-form-urlencoded'}, :method => "PUT", :body => {"a" => 1}
|
38
38
|
assert_equal({"a" => ["1"]}, proxy.parameters)
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
def test_request_proxy_ignore_post_body_with_invalid_content_type
|
42
42
|
proxy = create_request_proxy :head => {'Content-Type' => 'text/plain'}, :method => "POST"
|
43
43
|
assert_equal({}, proxy.parameters)
|
@@ -52,7 +52,7 @@ class EmHttpRequestProxyTest < Test::Unit::TestCase
|
|
52
52
|
proxy = create_request_proxy :head => {'Content-Type' => 'text/plain'}, :method => "PUT", :body => {"a" => 1}
|
53
53
|
assert_equal({}, proxy.parameters)
|
54
54
|
end
|
55
|
-
|
55
|
+
|
56
56
|
def test_request_proxy_ignores_post_body_with_invalid_method
|
57
57
|
proxy = create_request_proxy :head => {'Content-Type' => 'application/x-www-form-urlencoded'}, :method => "DELETE"
|
58
58
|
assert_equal({}, proxy.parameters)
|
@@ -67,35 +67,35 @@ class EmHttpRequestProxyTest < Test::Unit::TestCase
|
|
67
67
|
proxy = create_request_proxy :head => {'Content-Type' => 'application/x-www-form-urlencoded'}, :method => "GET", :body => {"a" => 1}
|
68
68
|
assert_equal({}, proxy.parameters)
|
69
69
|
end
|
70
|
-
|
70
|
+
|
71
71
|
def test_request_proxy_works_with_argument_params
|
72
72
|
assert_equal({"a" => ["1"]}, create_request_proxy(:proxy_options => {:parameters => {"a" => "1"}}).parameters)
|
73
73
|
end
|
74
|
-
|
74
|
+
|
75
75
|
def test_request_proxy_works_with_mixed_params
|
76
76
|
proxy = create_request_proxy(:proxy_options => {:parameters => {"a" => "1"}},:query => {"c" => "1"}, :uri => "http://example.com/test?b=1")
|
77
77
|
assert_equal({"a" => ["1"], "b" => ["1"], "c" => ["1"]}, proxy.parameters)
|
78
78
|
proxy = create_request_proxy(:proxy_options => {:parameters => {"a" => "1"}}, :body => {"b" => "1"}, :query => {"c" => "1"},
|
79
79
|
:uri => "http://example.com/test?d=1", :method => "POST", :head => {"Content-Type" => "application/x-www-form-urlencoded"})
|
80
|
-
assert_equal({"a" => ["1"], "b" => ["1"], "c" => ["1"], "d" => ["1"]}, proxy.parameters)
|
80
|
+
assert_equal({"a" => ["1"], "b" => ["1"], "c" => ["1"], "d" => ["1"]}, proxy.parameters)
|
81
81
|
end
|
82
|
-
|
82
|
+
|
83
83
|
def test_request_has_the_correct_uri
|
84
84
|
assert_equal "http://example.com/", create_request_proxy.uri
|
85
85
|
assert_equal "http://example.com/?a=1", create_request_proxy(:query => "a=1").uri
|
86
86
|
assert_equal "http://example.com/?a=1", create_request_proxy(:query => {"a" => "1"}).uri
|
87
|
-
|
87
|
+
|
88
88
|
end
|
89
|
-
|
89
|
+
|
90
90
|
def test_request_proxy_has_correct_method
|
91
91
|
assert_equal "GET", create_request_proxy(:method => "GET").method
|
92
92
|
assert_equal "PUT", create_request_proxy(:method => "PUT").method
|
93
93
|
assert_equal "POST", create_request_proxy(:method => "POST").method
|
94
94
|
assert_equal "DELETE", create_request_proxy(:method => "DELETE").method
|
95
95
|
end
|
96
|
-
|
96
|
+
|
97
97
|
protected
|
98
|
-
|
98
|
+
|
99
99
|
def create_client(options = {})
|
100
100
|
method = options.delete(:method) || "GET"
|
101
101
|
uri = options.delete(:uri) || "http://example.com/"
|
@@ -105,10 +105,10 @@ class EmHttpRequestProxyTest < Test::Unit::TestCase
|
|
105
105
|
client.options = options
|
106
106
|
client
|
107
107
|
end
|
108
|
-
|
108
|
+
|
109
109
|
def create_request_proxy(opts = {})
|
110
110
|
arguments = opts.delete(:proxy_options) || {}
|
111
111
|
OAuth::RequestProxy.proxy(create_client(opts), arguments)
|
112
112
|
end
|
113
|
-
|
113
|
+
|
114
114
|
end
|
data/test/test_helper.rb
CHANGED
@@ -7,7 +7,7 @@ require 'mocha'
|
|
7
7
|
require 'stringio'
|
8
8
|
|
9
9
|
class Test::Unit::TestCase
|
10
|
-
|
10
|
+
|
11
11
|
def assert_matching_headers(expected, actual)
|
12
12
|
# transform into sorted arrays
|
13
13
|
auth_intro, auth_params = actual.split(' ', 2)
|
@@ -16,5 +16,5 @@ class Test::Unit::TestCase
|
|
16
16
|
auth_params = auth_params.split(/(,|\s)/).reject {|v| v == '' || v =~ /^[\,\s]+/}.sort
|
17
17
|
assert_equal expected, auth_params
|
18
18
|
end
|
19
|
-
|
20
|
-
end
|
19
|
+
|
20
|
+
end
|
@@ -103,7 +103,7 @@ class NetHTTPClientTest < Test::Unit::TestCase
|
|
103
103
|
assert_equal "key=value&oauth_consumer_key=consumer_key_86cad9&oauth_nonce=225579211881198842005988698334675835446&oauth_signature=1oO2izFav1GP4kEH2EskwXkCRFg%3D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1199645624&oauth_token=token_411a7f&oauth_version=1.0", uri.query.split("&").sort.join("&")
|
104
104
|
assert_equal nil, request['authorization']
|
105
105
|
end
|
106
|
-
|
106
|
+
|
107
107
|
def test_that_using_get_params_works_with_plaintext
|
108
108
|
request = Net::HTTP::Get.new(@request_uri.path + "?" + request_parameters_to_s)
|
109
109
|
request.oauth!(@http, @consumer, @token, {:scheme => 'query_string', :nonce => @nonce, :timestamp => @timestamp, :signature_method => 'PLAINTEXT'})
|
@@ -126,7 +126,7 @@ class NetHTTPClientTest < Test::Unit::TestCase
|
|
126
126
|
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("&")
|
127
127
|
assert_equal nil, request['authorization']
|
128
128
|
end
|
129
|
-
|
129
|
+
|
130
130
|
def test_that_using_post_params_works_with_plaintext
|
131
131
|
request = Net::HTTP::Post.new(@request_uri.path)
|
132
132
|
request.set_form_data( @request_parameters )
|
data/test/test_rsa_sha1.rb
CHANGED
@@ -3,18 +3,18 @@ require 'oauth/consumer'
|
|
3
3
|
require 'oauth/signature/rsa/sha1'
|
4
4
|
|
5
5
|
class TestSignatureRsaSha1 < Test::Unit::TestCase
|
6
|
-
|
6
|
+
|
7
7
|
def setup
|
8
8
|
@request = Net::HTTP::Get.new('/photos?file=vacaction.jpg&size=original&oauth_version=1.0&oauth_consumer_key=dpf43f3p2l4k3l03&oauth_timestamp=1196666512&oauth_nonce=13917289812797014437&oauth_signature_method=RSA-SHA1')
|
9
9
|
|
10
10
|
@consumer = OAuth::Consumer.new('dpf43f3p2l4k3l03', OpenSSL::PKey::RSA.new(IO.read(File.dirname(__FILE__) + "/keys/rsa.pem")))
|
11
|
-
|
11
|
+
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
def test_that_rsa_sha1_implements_rsa_sha1
|
15
15
|
assert OAuth::Signature.available_methods.include?('rsa-sha1')
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
def test_that_get_request_from_oauth_test_cases_produces_matching_signature_base_string
|
19
19
|
sbs = OAuth::Signature.signature_base_string(@request, { :consumer => @consumer,
|
20
20
|
:uri => 'http://photos.example.net/photos' } )
|
@@ -27,7 +27,7 @@ class TestSignatureRsaSha1 < Test::Unit::TestCase
|
|
27
27
|
:uri => 'http://photos.example.net/photos' } )
|
28
28
|
|
29
29
|
assert_equal 'jvTp/wX1TYtByB1m+Pbyo0lnCOLIsyGCH7wke8AUs3BpnwZJtAuEJkvQL2/9n4s5wUmUl4aCI4BwpraNx4RtEXMe5qg5T1LVTGliMRpKasKsW//e+RinhejgCuzoH26dyF8iY2ZZ/5D1ilgeijhV/vBka5twt399mXwaYdCwFYE=', signature
|
30
|
-
|
30
|
+
|
31
31
|
end
|
32
32
|
|
33
33
|
def test_that_get_request_from_oauth_test_cases_produces_matching_signature_using_private_key_file
|
@@ -48,7 +48,7 @@ class TestSignatureRsaSha1 < Test::Unit::TestCase
|
|
48
48
|
:uri => 'http://photos.example.net/photos' } )
|
49
49
|
|
50
50
|
end
|
51
|
-
|
51
|
+
|
52
52
|
def test_that_get_request_from_oauth_test_cases_verifies_signature_with_pem
|
53
53
|
@request = Net::HTTP::Get.new('/photos?oauth_signature_method=RSA-SHA1&oauth_version=1.0&oauth_consumer_key=dpf43f3p2l4k3l03&oauth_timestamp=1196666512&oauth_nonce=13917289812797014437&file=vacaction.jpg&size=original&oauth_signature=jvTp%2FwX1TYtByB1m%2BPbyo0lnCOLIsyGCH7wke8AUs3BpnwZJtAuEJkvQL2%2F9n4s5wUmUl4aCI4BwpraNx4RtEXMe5qg5T1LVTGliMRpKasKsW%2F%2Fe%2BRinhejgCuzoH26dyF8iY2ZZ%2F5D1ilgeijhV%2FvBka5twt399mXwaYdCwFYE%3D')
|
54
54
|
assert OAuth::Signature.verify(@request, { :consumer => @consumer,
|
data/test/test_server.rb
CHANGED
@@ -4,19 +4,19 @@ class ServerTest < Test::Unit::TestCase
|
|
4
4
|
def setup
|
5
5
|
@server=OAuth::Server.new "http://test.com"
|
6
6
|
end
|
7
|
-
|
7
|
+
|
8
8
|
def test_default_paths
|
9
9
|
assert_equal "/oauth/request_token",@server.request_token_path
|
10
10
|
assert_equal "/oauth/authorize",@server.authorize_path
|
11
11
|
assert_equal "/oauth/access_token",@server.access_token_path
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
def test_default_urls
|
15
15
|
assert_equal "http://test.com/oauth/request_token",@server.request_token_url
|
16
16
|
assert_equal "http://test.com/oauth/authorize",@server.authorize_url
|
17
17
|
assert_equal "http://test.com/oauth/access_token",@server.access_token_url
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
def test_generate_consumer_credentials
|
21
21
|
consumer=@server.generate_consumer_credentials
|
22
22
|
assert_not_nil consumer.key
|
@@ -35,6 +35,6 @@ class ServerTest < Test::Unit::TestCase
|
|
35
35
|
assert_equal "http://test.com/oauth/request_token",@consumer.request_token_url
|
36
36
|
assert_equal "http://test.com/oauth/authorize",@consumer.authorize_url
|
37
37
|
assert_equal "http://test.com/oauth/access_token",@consumer.access_token_url
|
38
|
-
end
|
39
|
-
|
38
|
+
end
|
39
|
+
|
40
40
|
end
|
data/test/test_token.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
|
-
require File.expand_path('../test_helper', __FILE__)
|
2
|
-
require 'oauth/token'
|
3
|
-
|
4
|
-
class TestToken < Test::Unit::TestCase
|
5
|
-
|
6
|
-
def setup
|
7
|
-
end
|
8
|
-
|
9
|
-
def test_token_constructor_produces_valid_token
|
10
|
-
token = OAuth::Token.new('xyz', '123')
|
11
|
-
assert_equal 'xyz', token.token
|
12
|
-
assert_equal '123', token.secret
|
13
|
-
end
|
14
|
-
end
|
1
|
+
require File.expand_path('../test_helper', __FILE__)
|
2
|
+
require 'oauth/token'
|
3
|
+
|
4
|
+
class TestToken < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_token_constructor_produces_valid_token
|
10
|
+
token = OAuth::Token.new('xyz', '123')
|
11
|
+
assert_equal 'xyz', token.token
|
12
|
+
assert_equal '123', token.secret
|
13
|
+
end
|
14
|
+
end
|
@@ -66,7 +66,7 @@ class TyphoeusRequestProxyTest < Test::Unit::TestCase
|
|
66
66
|
end
|
67
67
|
|
68
68
|
def test_that_proxy_post_request_works_with_mixed_parameter_sources
|
69
|
-
request = Typhoeus::Request.new('/test?key=value',
|
69
|
+
request = Typhoeus::Request.new('/test?key=value',
|
70
70
|
:method => :post,
|
71
71
|
:body => {'key2' => 'value2'},
|
72
72
|
:headers => {'Content-Type' => 'application/x-www-form-urlencoded'})
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oauth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 9
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 4
|
9
|
-
-
|
10
|
-
version: 0.4.
|
9
|
+
- 3
|
10
|
+
version: 0.4.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Pelle Braendgaard
|
@@ -22,7 +22,7 @@ autorequire:
|
|
22
22
|
bindir: bin
|
23
23
|
cert_chain: []
|
24
24
|
|
25
|
-
date: 2010-
|
25
|
+
date: 2010-09-01 00:00:00 -07:00
|
26
26
|
default_executable: oauth
|
27
27
|
dependencies:
|
28
28
|
- !ruby/object:Gem::Dependency
|