Commit 0eff7bf7 authored by Taku YASUI's avatar Taku YASUI

Imported Upstream version 0.4.6

parent 125136db
GEM GEM
remote: http://rubygems.org/ remote: http://rubygems.org/
specs: specs:
actionpack (2.3.8) actionpack (2.3.14)
activesupport (= 2.3.8) activesupport (= 2.3.14)
rack (~> 1.1.0) rack (~> 1.1.0)
activesupport (2.3.8) activesupport (2.3.14)
addressable (2.2.0) addressable (2.2.7)
crack (0.1.8) crack (0.3.1)
curb (0.7.7.1) curb (0.8.0)
em-http-request (0.2.11) em-http-request (0.2.11)
addressable (>= 2.0.0) addressable (>= 2.0.0)
eventmachine (>= 0.12.9) eventmachine (>= 0.12.9)
eventmachine (0.12.10) eventmachine (0.12.10)
gemcutter (0.4.1)
json_pure
git (1.2.5) git (1.2.5)
jeweler (1.4.0) jeweler (1.8.3)
gemcutter (>= 0.1.0) bundler (~> 1.0)
git (>= 1.2.5) git (>= 1.2.5)
rubyforge (>= 2.0.0)
json_pure (1.4.3)
mocha (0.9.8)
rake rake
rack (1.1.0) rdoc
rake (0.8.7) json (1.6.6)
rubyforge (2.0.4) metaclass (0.0.1)
json_pure (>= 1.1.7) mime-types (1.18)
typhoeus (0.1.31) mocha (0.11.1)
rack metaclass (~> 0.0.1)
webmock (1.3.5) rack (1.1.3)
addressable (>= 2.1.1) rake (0.9.2.2)
rdoc (3.12)
json (~> 1.4)
typhoeus (0.3.3)
mime-types
webmock (1.8.6)
addressable (>= 2.2.7)
crack (>= 0.1.7) crack (>= 0.1.7)
PLATFORMS PLATFORMS
......
=== 0.4.6 2012-04-21
* Fixed nested attributes in #normalize (Shaliko Usubov)
* Make use the path component of the :site parameter (Jonathon M. Abbott)
* Fixed post body's being dropped in 1.9 (Steven Hammond)
* Fixed PUT request handling (Anton Panasenko)
=== 0.4.5 2011-06-25 === 0.4.5 2011-06-25
* Add explicit require for rsa/sha1 (Juris Galang) * Add explicit require for rsa/sha1 (Juris Galang)
......
$LOAD_PATH << File.dirname(__FILE__) unless $LOAD_PATH.include?(File.dirname(__FILE__)) $LOAD_PATH << File.dirname(__FILE__) unless $LOAD_PATH.include?(File.dirname(__FILE__))
module OAuth module OAuth
VERSION = "0.4.5" VERSION = "0.4.6"
end end
require 'oauth/oauth' require 'oauth/oauth'
......
...@@ -43,9 +43,6 @@ module OAuth ...@@ -43,9 +43,6 @@ module OAuth
# Add a custom ca_file for consumer # Add a custom ca_file for consumer
# :ca_file => '/etc/certs.pem' # :ca_file => '/etc/certs.pem'
# Add a custom ca_file for consumer
# :ca_file => '/etc/certs.pem'
:oauth_version => "1.0" :oauth_version => "1.0"
} }
...@@ -331,6 +328,10 @@ module OAuth ...@@ -331,6 +328,10 @@ module OAuth
data = arguments.shift data = arguments.shift
end end
# if the base site contains a path, add it now
uri = URI.parse(site)
path = uri.path + path if uri.path
headers = arguments.first.is_a?(Hash) ? arguments.shift : {} headers = arguments.first.is_a?(Hash) ? arguments.shift : {}
case http_method case http_method
......
...@@ -35,17 +35,38 @@ module OAuth ...@@ -35,17 +35,38 @@ module OAuth
# See Also: {OAuth core spec version 1.0, section 9.1.1}[http://oauth.net/core/1.0#rfc.section.9.1.1] # See Also: {OAuth core spec version 1.0, section 9.1.1}[http://oauth.net/core/1.0#rfc.section.9.1.1]
def normalize(params) def normalize(params)
params.sort.map do |k, values| params.sort.map do |k, values|
if values.is_a?(Array) if values.is_a?(Array)
# make sure the array has an element so we don't lose the key
values << nil if values.empty?
# multiple values were provided for a single key # multiple values were provided for a single key
values.sort.collect do |v| values.sort.collect do |v|
[escape(k),escape(v)] * "=" [escape(k),escape(v)] * "="
end end
elsif values.is_a?(Hash)
normalize_nested_query(values, k)
else else
[escape(k),escape(values)] * "=" [escape(k),escape(values)] * "="
end end
end * "&" end * "&"
end end
#Returns a string representation of the Hash like in URL query string
# build_nested_query({:level_1 => {:level_2 => ['value_1','value_2']}}, 'prefix'))
# #=> ["prefix%5Blevel_1%5D%5Blevel_2%5D%5B%5D=value_1", "prefix%5Blevel_1%5D%5Blevel_2%5D%5B%5D=value_2"]
def normalize_nested_query(value, prefix = nil)
case value
when Array
value.map do |v|
normalize_nested_query(v, "#{prefix}[]")
end.flatten.sort
when Hash
value.map do |k, v|
normalize_nested_query(v, prefix ? "#{prefix}[#{k}]" : k)
end.flatten.sort
else
[escape(prefix), escape(value)] * "="
end
end
# Parse an Authorization / WWW-Authenticate header into a hash. Takes care of unescaping and # Parse an Authorization / WWW-Authenticate header into a hash. Takes care of unescaping and
# removing surrounding quotes. Raises a OAuth::Problem if the header is not parsable into a # removing surrounding quotes. Raises a OAuth::Problem if the header is not parsable into a
......
...@@ -32,6 +32,7 @@ module OAuth::RequestProxy::Net ...@@ -32,6 +32,7 @@ module OAuth::RequestProxy::Net
def all_parameters def all_parameters
request_params = CGI.parse(query_string) request_params = CGI.parse(query_string)
# request_params.each{|k,v| request_params[k] = [nil] if v == []}
if options[:parameters] if options[:parameters]
options[:parameters].each do |k,v| options[:parameters].each do |k,v|
...@@ -47,7 +48,7 @@ module OAuth::RequestProxy::Net ...@@ -47,7 +48,7 @@ module OAuth::RequestProxy::Net
def query_string def query_string
params = [ query_params, auth_header_params ] params = [ query_params, auth_header_params ]
params << post_params if method.to_s.upcase == 'POST' && form_url_encoded? params << post_params if (method.to_s.upcase == 'POST' || method.to_s.upcase == 'PUT') && form_url_encoded?
params.compact.join('&') params.compact.join('&')
end end
......
--- !ruby/object:Gem::Specification --- !ruby/object:Gem::Specification
name: oauth name: oauth
version: !ruby/object:Gem::Version version: !ruby/object:Gem::Version
prerelease: false version: 0.4.6
segments: prerelease:
- 0
- 4
- 5
version: 0.4.5
platform: ruby platform: ruby
authors: authors:
- Pelle Braendgaard - Pelle Braendgaard
- Blaine Cook - Blaine Cook
- Larry Halff - Larry Halff
...@@ -20,138 +16,106 @@ authors: ...@@ -20,138 +16,106 @@ authors:
autorequire: autorequire:
bindir: bin bindir: bin
cert_chain: [] cert_chain: []
date: 2012-04-21 00:00:00.000000000 Z
date: 2011-06-25 00:00:00 -07:00 dependencies:
default_executable: oauth - !ruby/object:Gem::Dependency
dependencies:
- !ruby/object:Gem::Dependency
name: rake name: rake
requirement: &id001 !ruby/object:Gem::Requirement requirement: &70205509498980 !ruby/object:Gem::Requirement
none: false none: false
requirements: requirements:
- - ">=" - - ! '>='
- !ruby/object:Gem::Version - !ruby/object:Gem::Version
segments: version: '0'
- 0
version: "0"
type: :development type: :development
prerelease: false prerelease: false
version_requirements: *id001 version_requirements: *70205509498980
- !ruby/object:Gem::Dependency - !ruby/object:Gem::Dependency
name: jeweler name: jeweler
requirement: &id002 !ruby/object:Gem::Requirement requirement: &70205509498480 !ruby/object:Gem::Requirement
none: false none: false
requirements: requirements:
- - ">=" - - ! '>='
- !ruby/object:Gem::Version - !ruby/object:Gem::Version
segments: version: '0'
- 0
version: "0"
type: :development type: :development
prerelease: false prerelease: false
version_requirements: *id002 version_requirements: *70205509498480
- !ruby/object:Gem::Dependency - !ruby/object:Gem::Dependency
name: actionpack name: actionpack
requirement: &id003 !ruby/object:Gem::Requirement requirement: &70205509497980 !ruby/object:Gem::Requirement
none: false none: false
requirements: requirements:
- - ">=" - - ! '>='
- !ruby/object:Gem::Version - !ruby/object:Gem::Version
segments:
- 2
- 3
- 5
version: 2.3.5 version: 2.3.5
type: :development type: :development
prerelease: false prerelease: false
version_requirements: *id003 version_requirements: *70205509497980
- !ruby/object:Gem::Dependency - !ruby/object:Gem::Dependency
name: rack name: rack
requirement: &id004 !ruby/object:Gem::Requirement requirement: &70205509497480 !ruby/object:Gem::Requirement
none: false none: false
requirements: requirements:
- - ">=" - - ! '>='
- !ruby/object:Gem::Version - !ruby/object:Gem::Version
segments:
- 1
- 0
- 0
version: 1.0.0 version: 1.0.0
type: :development type: :development
prerelease: false prerelease: false
version_requirements: *id004 version_requirements: *70205509497480
- !ruby/object:Gem::Dependency - !ruby/object:Gem::Dependency
name: mocha name: mocha
requirement: &id005 !ruby/object:Gem::Requirement requirement: &70205509496960 !ruby/object:Gem::Requirement
none: false none: false
requirements: requirements:
- - ">=" - - ! '>='
- !ruby/object:Gem::Version - !ruby/object:Gem::Version
segments:
- 0
- 9
- 8
version: 0.9.8 version: 0.9.8
type: :development type: :development
prerelease: false prerelease: false
version_requirements: *id005 version_requirements: *70205509496960
- !ruby/object:Gem::Dependency - !ruby/object:Gem::Dependency
name: typhoeus name: typhoeus
requirement: &id006 !ruby/object:Gem::Requirement requirement: &70205509496480 !ruby/object:Gem::Requirement
none: false none: false
requirements: requirements:
- - ">=" - - ! '>='
- !ruby/object:Gem::Version - !ruby/object:Gem::Version
segments:
- 0
- 1
- 13
version: 0.1.13 version: 0.1.13
type: :development type: :development
prerelease: false prerelease: false
version_requirements: *id006 version_requirements: *70205509496480
- !ruby/object:Gem::Dependency - !ruby/object:Gem::Dependency
name: em-http-request name: em-http-request
requirement: &id007 !ruby/object:Gem::Requirement requirement: &70205509496000 !ruby/object:Gem::Requirement
none: false none: false
requirements: requirements:
- - ">=" - - ! '>='
- !ruby/object:Gem::Version - !ruby/object:Gem::Version
segments:
- 0
- 2
- 10
version: 0.2.10 version: 0.2.10
type: :development type: :development
prerelease: false prerelease: false
version_requirements: *id007 version_requirements: *70205509496000
- !ruby/object:Gem::Dependency - !ruby/object:Gem::Dependency
name: curb name: curb
requirement: &id008 !ruby/object:Gem::Requirement requirement: &70205509495520 !ruby/object:Gem::Requirement
none: false none: false
requirements: requirements:
- - ">=" - - ! '>='
- !ruby/object:Gem::Version - !ruby/object:Gem::Version
segments:
- 0
- 6
- 6
- 0
version: 0.6.6.0 version: 0.6.6.0
type: :development type: :development
prerelease: false prerelease: false
version_requirements: *id008 version_requirements: *70205509495520
description: OAuth Core Ruby implementation description: OAuth Core Ruby implementation
email: oauth-ruby@googlegroups.com email: oauth-ruby@googlegroups.com
executables: executables:
- oauth - oauth
extensions: [] extensions: []
extra_rdoc_files:
extra_rdoc_files:
- LICENSE - LICENSE
- README.rdoc - README.rdoc
- TODO - TODO
files: files:
- .gemtest - .gemtest
- Gemfile - Gemfile
- Gemfile.lock - Gemfile.lock
...@@ -239,37 +203,28 @@ files: ...@@ -239,37 +203,28 @@ files:
- test/test_signature_plain_text.rb - test/test_signature_plain_text.rb
- test/test_token.rb - test/test_token.rb
- test/test_typhoeus_request_proxy.rb - test/test_typhoeus_request_proxy.rb
has_rdoc: true
homepage: homepage:
licenses: [] licenses: []
post_install_message: post_install_message:
rdoc_options: [] rdoc_options: []
require_paths:
require_paths:
- lib - lib
required_ruby_version: !ruby/object:Gem::Requirement required_ruby_version: !ruby/object:Gem::Requirement
none: false none: false
requirements: requirements:
- - ">=" - - ! '>='
- !ruby/object:Gem::Version - !ruby/object:Gem::Version
segments: version: '0'
- 0 required_rubygems_version: !ruby/object:Gem::Requirement
version: "0"
required_rubygems_version: !ruby/object:Gem::Requirement
none: false none: false
requirements: requirements:
- - ">=" - - ! '>='
- !ruby/object:Gem::Version - !ruby/object:Gem::Version
segments: version: '0'
- 0
version: "0"
requirements: [] requirements: []
rubyforge_project: oauth rubyforge_project: oauth
rubygems_version: 1.3.7 rubygems_version: 1.8.16
signing_key: signing_key:
specification_version: 3 specification_version: 3
summary: OAuth Core Ruby implementation summary: OAuth Core Ruby implementation
test_files: [] test_files: []
...@@ -4,15 +4,14 @@ ...@@ -4,15 +4,14 @@
# -*- encoding: utf-8 -*- # -*- encoding: utf-8 -*-
Gem::Specification.new do |s| Gem::Specification.new do |s|
s.name = %q{oauth} s.name = "oauth"
s.version = "0.4.5" s.version = "0.4.6"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Pelle Braendgaard", "Blaine Cook", "Larry Halff", "Jesse Clark", "Jon Crosby", "Seth Fitzsimmons", "Matt Sanford", "Aaron Quint"] s.authors = ["Pelle Braendgaard", "Blaine Cook", "Larry Halff", "Jesse Clark", "Jon Crosby", "Seth Fitzsimmons", "Matt Sanford", "Aaron Quint"]
s.date = %q{2011-06-25} s.date = "2012-04-21"
s.default_executable = %q{oauth} s.description = "OAuth Core Ruby implementation"
s.description = %q{OAuth Core Ruby implementation} s.email = "oauth-ruby@googlegroups.com"
s.email = %q{oauth-ruby@googlegroups.com}
s.executables = ["oauth"] s.executables = ["oauth"]
s.extra_rdoc_files = [ s.extra_rdoc_files = [
"LICENSE", "LICENSE",
...@@ -109,12 +108,11 @@ Gem::Specification.new do |s| ...@@ -109,12 +108,11 @@ Gem::Specification.new do |s|
"test/test_typhoeus_request_proxy.rb" "test/test_typhoeus_request_proxy.rb"
] ]
s.require_paths = ["lib"] s.require_paths = ["lib"]
s.rubyforge_project = %q{oauth} s.rubyforge_project = "oauth"
s.rubygems_version = %q{1.3.7} s.rubygems_version = "1.8.16"
s.summary = %q{OAuth Core Ruby implementation} s.summary = "OAuth Core Ruby implementation"
if s.respond_to? :specification_version then if s.respond_to? :specification_version then
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
s.specification_version = 3 s.specification_version = 3
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
......
...@@ -86,7 +86,7 @@ module Integration ...@@ -86,7 +86,7 @@ module Integration
assert_equal 'POST', request.method assert_equal 'POST', request.method
assert_equal '/test', request.path assert_equal '/test', request.path
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("&") 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("&")
assert_equal nil, request['authorization'] assert_equal nil, request['authorization']
end end
...@@ -111,7 +111,7 @@ module Integration ...@@ -111,7 +111,7 @@ module Integration
assert_equal 'POST', request.method assert_equal 'POST', request.method
assert_equal '/test', request.path assert_equal '/test', request.path
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("&") 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("&")
assert_equal nil, request['authorization'] assert_equal nil, request['authorization']
end end
......
...@@ -61,6 +61,34 @@ class ConsumerTest < Test::Unit::TestCase ...@@ -61,6 +61,34 @@ class ConsumerTest < Test::Unit::TestCase
assert_equal :post,@consumer.http_method assert_equal :post,@consumer.http_method
end end
def test_site_without_path
@consumer=OAuth::Consumer.new(
"key",
"secret",
{
:site=>"http://twitter.com"
})
request = stub(:oauth! => nil)
http = stub(:request => stub(:to_hash => {}))
Net::HTTP::Get.expects(:new).with('/people', {}).returns(request)
@consumer.expects(:create_http).returns(http)
@consumer.request(:get, '/people', nil, {})
end
def test_site_with_path
@consumer=OAuth::Consumer.new(
"key",
"secret",
{
:site=>"http://identi.ca/api"
})
request = stub(:oauth! => nil)
http = stub(:request => stub(:to_hash => {}))
Net::HTTP::Get.expects(:new).with('/api/people', {}).returns(request)
@consumer.expects(:create_http).returns(http)
@consumer.request(:get, '/people', nil, {})
end
def test_override_paths def test_override_paths
@consumer=OAuth::Consumer.new( @consumer=OAuth::Consumer.new(
"key", "key",
......
...@@ -5,9 +5,11 @@ $LOAD_PATH << File.dirname(__FILE__) + '/../lib/' ...@@ -5,9 +5,11 @@ $LOAD_PATH << File.dirname(__FILE__) + '/../lib/'
require 'oauth' require 'oauth'
require 'mocha' require 'mocha'
require 'stringio' require 'stringio'
require 'webmock/test_unit' require 'webmock'
class Test::Unit::TestCase class Test::Unit::TestCase
include WebMock::API
def assert_matching_headers(expected, actual) def assert_matching_headers(expected, actual)
# transform into sorted arrays # transform into sorted arrays
auth_intro, auth_params = actual.split(' ', 2) auth_intro, auth_params = actual.split(' ', 2)
......
...@@ -123,7 +123,7 @@ class NetHTTPClientTest < Test::Unit::TestCase ...@@ -123,7 +123,7 @@ class NetHTTPClientTest < Test::Unit::TestCase
assert_equal 'POST', request.method assert_equal 'POST', request.method
assert_equal '/test', request.path assert_equal '/test', request.path
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("&") 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("&")
assert_equal nil, request['authorization'] assert_equal nil, request['authorization']
end end
...@@ -138,6 +138,18 @@ class NetHTTPClientTest < Test::Unit::TestCase ...@@ -138,6 +138,18 @@ class NetHTTPClientTest < Test::Unit::TestCase
assert_equal nil, request['authorization'] assert_equal nil, request['authorization']
end end
def test_that_using_post_body_works
request = Net::HTTP::Post.new(@request_uri.path)
request['content-type'] = 'application/x-www-form-urlencoded'
request.body = 'this is a test of the emergency broad cast system. This is only a test.'
request.oauth!(@http, @consumer, @token, {:nonce => @nonce, :timestamp => @timestamp})
assert_equal 'POST', request.method
assert_equal '/test', request.path
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("&")
# assert_equal nil, request['authorization']
end
def test_that_using_post_with_uri_params_works def test_that_using_post_with_uri_params_works
request = Net::HTTP::Post.new(@request_uri.path + "?" + request_parameters_to_s) request = Net::HTTP::Post.new(@request_uri.path + "?" + request_parameters_to_s)
request.set_form_data( {} ) # just to make sure we have a correct mime type and thus no body hash request.set_form_data( {} ) # just to make sure we have a correct mime type and thus no body hash
...@@ -245,7 +257,7 @@ class NetHTTPClientTest < Test::Unit::TestCase ...@@ -245,7 +257,7 @@ class NetHTTPClientTest < Test::Unit::TestCase
request = Net::HTTP::Put.new(@request_uri.path) request = Net::HTTP::Put.new(@request_uri.path)
request.set_form_data( { 'key2' => 'value2' } ) request.set_form_data( { 'key2' => 'value2' } )
signature_base_string=request.signature_base_string(@http, @consumer, nil, { :nonce => @nonce, :timestamp => @timestamp }) signature_base_string=request.signature_base_string(@http, @consumer, nil, { :nonce => @nonce, :timestamp => @timestamp })
assert_equal "PUT&http%3A%2F%2Fexample.com%2Ftest&oauth_consumer_key%3Dconsumer_key_86cad9%26oauth_nonce%3D225579211881198842005988698334675835446%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1199645624%26oauth_version%3D1.0", signature_base_string 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
end end
def test_that_post_bodies_signed_if_form_urlencoded def test_that_post_bodies_signed_if_form_urlencoded
......
...@@ -52,7 +52,7 @@ class NetHTTPRequestProxyTest < Test::Unit::TestCase ...@@ -52,7 +52,7 @@ class NetHTTPRequestProxyTest < Test::Unit::TestCase
request.set_form_data(params) request.set_form_data(params)
request_proxy = OAuth::RequestProxy.proxy(request, {:uri => 'http://example.com/test'}) request_proxy = OAuth::RequestProxy.proxy(request, {:uri => 'http://example.com/test'})
expected_parameters = {} expected_parameters = {'key' => ['value']}
assert_equal expected_parameters, request_proxy.parameters_for_signature assert_equal expected_parameters, request_proxy.parameters_for_signature
assert_equal 'http://example.com/test', request_proxy.normalized_uri assert_equal 'http://example.com/test', request_proxy.normalized_uri
assert_equal 'PUT', request_proxy.method assert_equal 'PUT', request_proxy.method
......
...@@ -68,4 +68,27 @@ class TestOAuthHelper < Test::Unit::TestCase ...@@ -68,4 +68,27 @@ class TestOAuthHelper < Test::Unit::TestCase
assert_equal "nonce", params['oauth_nonce'] assert_equal "nonce", params['oauth_nonce']
assert_equal "1.0", params['oauth_version'] assert_equal "1.0", params['oauth_version']
end end
def test_normalize
params = {
'oauth_nonce' => 'nonce',
'weight' => { :value => "65" },
'oauth_signature_method' => 'HMAC-SHA1',
'oauth_timestamp' => "1240004133",
'oauth_consumer_key' => 'vince_clortho',
'oauth_token' => 'token_value',
'oauth_version' => "1.0"
}
assert_equal("oauth_consumer_key=vince_clortho&oauth_nonce=nonce&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1240004133&oauth_token=token_value&oauth_version=1.0&weight%5Bvalue%5D=65", OAuth::Helper.normalize(params))
end
def test_normalize_nested_query
assert_equal([], OAuth::Helper.normalize_nested_query({}))
assert_equal(["foo=bar"], OAuth::Helper.normalize_nested_query({:foo => 'bar'}))
assert_equal(["prefix%5Bfoo%5D=bar"], OAuth::Helper.normalize_nested_query({:foo => 'bar'}, 'prefix'))
assert_equal(["prefix%5Buser%5D%5Bage%5D=12",
"prefix%5Buser%5D%5Bdate%5D=2011-10-05",
"prefix%5Buser%5D%5Btwitter_id%5D=123"], OAuth::Helper.normalize_nested_query({:user => {:twitter_id => 123, :date => '2011-10-05', :age => 12}}, 'prefix'))
end
end end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment