Skip to content

Commit

Permalink
Fix adding paths when a full URL has been specified (oauth-xx#113)
Browse files Browse the repository at this point in the history
Fix adding paths when a full URL has been specified.
  • Loading branch information
nikz authored and ch1ago committed May 30, 2016
1 parent 59da25b commit f877668
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
6 changes: 4 additions & 2 deletions lib/oauth/consumer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,10 @@ def create_http_request(http_method, path, *arguments)
end

# if the base site contains a path, add it now
uri = URI.parse(site)
path = uri.path + path if uri.path && uri.path != '/'
# only add if the site host matches the current http object's host
# (in case we've specified a full url for token requests)
uri = URI.parse(site)
path = uri.path + path if uri.path && uri.path != '/' && uri.host == http.address

headers = arguments.first.is_a?(Hash) ? arguments.shift : {}

Expand Down
17 changes: 15 additions & 2 deletions test/units/test_consumer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def test_site_without_path
:site=>"http://twitter.com"
})
request = stub(:oauth! => nil)
http = stub(:request => stub(:to_hash => {}))
http = stub(:request => stub(:to_hash => {}), :address => "identi.ca")
Net::HTTP::Get.expects(:new).with('/people', {}).returns(request)
@consumer.expects(:create_http).returns(http)
@consumer.request(:get, '/people', nil, {})
Expand All @@ -105,7 +105,7 @@ def test_site_with_path
:site=>"http://identi.ca/api"
})
request = stub(:oauth! => nil)
http = stub(:request => stub(:to_hash => {}))
http = stub(:request => stub(:to_hash => {}), :address => "identi.ca")
Net::HTTP::Get.expects(:new).with('/api/people', {}).returns(request)
@consumer.expects(:create_http).returns(http)
@consumer.request(:get, '/people', nil, {})
Expand Down Expand Up @@ -154,6 +154,19 @@ def test_override_paths
assert_equal :post,@consumer.http_method
end

def test_getting_tokens_doesnt_add_paths_if_full_url_is_specified
@consumer = OAuth::Consumer.new(
"key",
"secret",
{
:site => "https://api.mysite.co.nz/v1",
:request_token_url => "https://authentication.mysite.co.nz/Oauth/RequestToken"
})

stub_request(:post, "https://authentication.mysite.co.nz/Oauth/RequestToken").to_return(:body => "success", :status => 200)
@consumer.get_request_token
end

def test_token_request_identifies_itself_as_a_token_request
request_options = {}
@consumer.stubs(:request).returns(create_stub_http_response)
Expand Down

0 comments on commit f877668

Please sign in to comment.