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

Imported Upstream version 0.4.6

parent 125136db
GEM
remote: http://rubygems.org/
specs:
actionpack (2.3.8)
activesupport (= 2.3.8)
actionpack (2.3.14)
activesupport (= 2.3.14)
rack (~> 1.1.0)
activesupport (2.3.8)
addressable (2.2.0)
crack (0.1.8)
curb (0.7.7.1)
activesupport (2.3.14)
addressable (2.2.7)
crack (0.3.1)
curb (0.8.0)
em-http-request (0.2.11)
addressable (>= 2.0.0)
eventmachine (>= 0.12.9)
eventmachine (0.12.10)
gemcutter (0.4.1)
json_pure
git (1.2.5)
jeweler (1.4.0)
gemcutter (>= 0.1.0)
jeweler (1.8.3)
bundler (~> 1.0)
git (>= 1.2.5)
rubyforge (>= 2.0.0)
json_pure (1.4.3)
mocha (0.9.8)
rake
rack (1.1.0)
rake (0.8.7)
rubyforge (2.0.4)
json_pure (>= 1.1.7)
typhoeus (0.1.31)
rack
webmock (1.3.5)
addressable (>= 2.1.1)
rdoc
json (1.6.6)
metaclass (0.0.1)
mime-types (1.18)
mocha (0.11.1)
metaclass (~> 0.0.1)
rack (1.1.3)
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)
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
* Add explicit require for rsa/sha1 (Juris Galang)
......
$LOAD_PATH << File.dirname(__FILE__) unless $LOAD_PATH.include?(File.dirname(__FILE__))
module OAuth
VERSION = "0.4.5"
VERSION = "0.4.6"
end
require 'oauth/oauth'
......
......@@ -43,9 +43,6 @@ module OAuth
# Add a custom ca_file for consumer
# :ca_file => '/etc/certs.pem'
# Add a custom ca_file for consumer
# :ca_file => '/etc/certs.pem'
:oauth_version => "1.0"
}
......@@ -331,6 +328,10 @@ module OAuth
data = arguments.shift
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 : {}
case http_method
......
......@@ -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]
def normalize(params)
params.sort.map do |k, values|
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
values.sort.collect do |v|
[escape(k),escape(v)] * "="
end
elsif values.is_a?(Hash)
normalize_nested_query(values, k)
else
[escape(k),escape(values)] * "="
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
# removing surrounding quotes. Raises a OAuth::Problem if the header is not parsable into a
......
......@@ -32,6 +32,7 @@ module OAuth::RequestProxy::Net
def all_parameters
request_params = CGI.parse(query_string)
# request_params.each{|k,v| request_params[k] = [nil] if v == []}
if options[:parameters]
options[:parameters].each do |k,v|
......@@ -47,7 +48,7 @@ module OAuth::RequestProxy::Net
def query_string
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('&')
end
......
--- !ruby/object:Gem::Specification
--- !ruby/object:Gem::Specification
name: oauth
version: !ruby/object:Gem::Version
prerelease: false
segments:
- 0
- 4
- 5
version: 0.4.5
version: !ruby/object:Gem::Version
version: 0.4.6
prerelease:
platform: ruby
authors:
authors:
- Pelle Braendgaard
- Blaine Cook
- Larry Halff
......@@ -20,138 +16,106 @@ authors:
autorequire:
bindir: bin
cert_chain: []
date: 2011-06-25 00:00:00 -07:00
default_executable: oauth
dependencies:
- !ruby/object:Gem::Dependency
date: 2012-04-21 00:00:00.000000000 Z
dependencies:
- !ruby/object:Gem::Dependency
name: rake
requirement: &id001 !ruby/object:Gem::Requirement
requirement: &70205509498980 !ruby/object:Gem::Requirement
none: false
requirements:
- - ">="
- !ruby/object:Gem::Version
segments:
- 0
version: "0"
requirements:
- - ! '>='
- !ruby/object:Gem::Version
version: '0'
type: :development
prerelease: false
version_requirements: *id001
- !ruby/object:Gem::Dependency
version_requirements: *70205509498980
- !ruby/object:Gem::Dependency
name: jeweler
requirement: &id002 !ruby/object:Gem::Requirement
requirement: &70205509498480 !ruby/object:Gem::Requirement
none: false
requirements:
- - ">="
- !ruby/object:Gem::Version
segments:
- 0
version: "0"
requirements:
- - ! '>='
- !ruby/object:Gem::Version
version: '0'
type: :development
prerelease: false
version_requirements: *id002
- !ruby/object:Gem::Dependency
version_requirements: *70205509498480
- !ruby/object:Gem::Dependency
name: actionpack
requirement: &id003 !ruby/object:Gem::Requirement
requirement: &70205509497980 !ruby/object:Gem::Requirement
none: false
requirements:
- - ">="
- !ruby/object:Gem::Version
segments:
- 2
- 3
- 5
requirements:
- - ! '>='
- !ruby/object:Gem::Version
version: 2.3.5
type: :development
prerelease: false
version_requirements: *id003
- !ruby/object:Gem::Dependency
version_requirements: *70205509497980
- !ruby/object:Gem::Dependency
name: rack
requirement: &id004 !ruby/object:Gem::Requirement
requirement: &70205509497480 !ruby/object:Gem::Requirement
none: false
requirements:
- - ">="
- !ruby/object:Gem::Version
segments:
- 1
- 0
- 0
requirements:
- - ! '>='
- !ruby/object:Gem::Version
version: 1.0.0
type: :development
prerelease: false
version_requirements: *id004
- !ruby/object:Gem::Dependency
version_requirements: *70205509497480
- !ruby/object:Gem::Dependency
name: mocha
requirement: &id005 !ruby/object:Gem::Requirement
requirement: &70205509496960 !ruby/object:Gem::Requirement
none: false
requirements:
- - ">="
- !ruby/object:Gem::Version
segments:
- 0
- 9
- 8
requirements:
- - ! '>='
- !ruby/object:Gem::Version
version: 0.9.8
type: :development
prerelease: false
version_requirements: *id005
- !ruby/object:Gem::Dependency
version_requirements: *70205509496960
- !ruby/object:Gem::Dependency
name: typhoeus
requirement: &id006 !ruby/object:Gem::Requirement
requirement: &70205509496480 !ruby/object:Gem::Requirement
none: false
requirements:
- - ">="
- !ruby/object:Gem::Version
segments:
- 0
- 1
- 13
requirements:
- - ! '>='
- !ruby/object:Gem::Version
version: 0.1.13
type: :development
prerelease: false
version_requirements: *id006
- !ruby/object:Gem::Dependency
version_requirements: *70205509496480
- !ruby/object:Gem::Dependency
name: em-http-request
requirement: &id007 !ruby/object:Gem::Requirement
requirement: &70205509496000 !ruby/object:Gem::Requirement
none: false
requirements:
- - ">="
- !ruby/object:Gem::Version
segments:
- 0
- 2
- 10
requirements:
- - ! '>='
- !ruby/object:Gem::Version
version: 0.2.10
type: :development
prerelease: false
version_requirements: *id007
- !ruby/object:Gem::Dependency
version_requirements: *70205509496000
- !ruby/object:Gem::Dependency
name: curb
requirement: &id008 !ruby/object:Gem::Requirement
requirement: &70205509495520 !ruby/object:Gem::Requirement
none: false
requirements:
- - ">="
- !ruby/object:Gem::Version
segments:
- 0
- 6
- 6
- 0
requirements:
- - ! '>='
- !ruby/object:Gem::Version
version: 0.6.6.0
type: :development
prerelease: false
version_requirements: *id008
version_requirements: *70205509495520
description: OAuth Core Ruby implementation
email: oauth-ruby@googlegroups.com
executables:
executables:
- oauth
extensions: []
extra_rdoc_files:
extra_rdoc_files:
- LICENSE
- README.rdoc
- TODO
files:
files:
- .gemtest
- Gemfile
- Gemfile.lock
......@@ -239,37 +203,28 @@ files:
- test/test_signature_plain_text.rb
- test/test_token.rb
- test/test_typhoeus_request_proxy.rb
has_rdoc: true
homepage:
licenses: []
post_install_message:
rdoc_options: []
require_paths:
require_paths:
- lib
required_ruby_version: !ruby/object:Gem::Requirement
required_ruby_version: !ruby/object:Gem::Requirement
none: false
requirements:
- - ">="
- !ruby/object:Gem::Version
segments:
- 0
version: "0"
required_rubygems_version: !ruby/object:Gem::Requirement
requirements:
- - ! '>='
- !ruby/object:Gem::Version
version: '0'
required_rubygems_version: !ruby/object:Gem::Requirement
none: false
requirements:
- - ">="
- !ruby/object:Gem::Version
segments:
- 0
version: "0"
requirements:
- - ! '>='
- !ruby/object:Gem::Version
version: '0'
requirements: []
rubyforge_project: oauth
rubygems_version: 1.3.7
rubygems_version: 1.8.16
signing_key:
specification_version: 3
summary: OAuth Core Ruby implementation
test_files: []
......@@ -4,15 +4,14 @@
# -*- encoding: utf-8 -*-
Gem::Specification.new do |s|
s.name = %q{oauth}
s.version = "0.4.5"
s.name = "oauth"
s.version = "0.4.6"
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.date = %q{2011-06-25}
s.default_executable = %q{oauth}
s.description = %q{OAuth Core Ruby implementation}
s.email = %q{oauth-ruby@googlegroups.com}
s.date = "2012-04-21"
s.description = "OAuth Core Ruby implementation"
s.email = "oauth-ruby@googlegroups.com"
s.executables = ["oauth"]
s.extra_rdoc_files = [
"LICENSE",
......@@ -109,12 +108,11 @@ Gem::Specification.new do |s|
"test/test_typhoeus_request_proxy.rb"
]
s.require_paths = ["lib"]
s.rubyforge_project = %q{oauth}
s.rubygems_version = %q{1.3.7}
s.summary = %q{OAuth Core Ruby implementation}
s.rubyforge_project = "oauth"
s.rubygems_version = "1.8.16"
s.summary = "OAuth Core Ruby implementation"
if s.respond_to? :specification_version then
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
s.specification_version = 3
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
......
......@@ -86,7 +86,7 @@ module Integration
assert_equal 'POST', request.method
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']
end
......@@ -111,7 +111,7 @@ module Integration
assert_equal 'POST', request.method
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']
end
......
......@@ -61,6 +61,34 @@ class ConsumerTest < Test::Unit::TestCase
assert_equal :post,@consumer.http_method
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
@consumer=OAuth::Consumer.new(
"key",
......
......@@ -5,9 +5,11 @@ $LOAD_PATH << File.dirname(__FILE__) + '/../lib/'
require 'oauth'
require 'mocha'
require 'stringio'
require 'webmock/test_unit'
require 'webmock'
class Test::Unit::TestCase
include WebMock::API
def assert_matching_headers(expected, actual)
# transform into sorted arrays
auth_intro, auth_params = actual.split(' ', 2)
......
......@@ -123,7 +123,7 @@ class NetHTTPClientTest < Test::Unit::TestCase
assert_equal 'POST', request.method
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']
end
......@@ -138,6 +138,18 @@ class NetHTTPClientTest < Test::Unit::TestCase
assert_equal nil, request['authorization']
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
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
......@@ -245,7 +257,7 @@ class NetHTTPClientTest < Test::Unit::TestCase
request = Net::HTTP::Put.new(@request_uri.path)
request.set_form_data( { 'key2' => 'value2' } )
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
def test_that_post_bodies_signed_if_form_urlencoded
......
......@@ -52,7 +52,7 @@ class NetHTTPRequestProxyTest < Test::Unit::TestCase
request.set_form_data(params)
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 'http://example.com/test', request_proxy.normalized_uri
assert_equal 'PUT', request_proxy.method
......
......@@ -68,4 +68,27 @@ class TestOAuthHelper < Test::Unit::TestCase
assert_equal "nonce", params['oauth_nonce']
assert_equal "1.0", params['oauth_version']
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
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