Skip to content

Commit f877668

Browse files
nikzch1ago
authored andcommitted
Fix adding paths when a full URL has been specified (#113)
Fix adding paths when a full URL has been specified.
1 parent 59da25b commit f877668

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

lib/oauth/consumer.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,8 +355,10 @@ def create_http_request(http_method, path, *arguments)
355355
end
356356

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

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

test/units/test_consumer.rb

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def test_site_without_path
9191
:site=>"http://twitter.com"
9292
})
9393
request = stub(:oauth! => nil)
94-
http = stub(:request => stub(:to_hash => {}))
94+
http = stub(:request => stub(:to_hash => {}), :address => "identi.ca")
9595
Net::HTTP::Get.expects(:new).with('/people', {}).returns(request)
9696
@consumer.expects(:create_http).returns(http)
9797
@consumer.request(:get, '/people', nil, {})
@@ -105,7 +105,7 @@ def test_site_with_path
105105
:site=>"http://identi.ca/api"
106106
})
107107
request = stub(:oauth! => nil)
108-
http = stub(:request => stub(:to_hash => {}))
108+
http = stub(:request => stub(:to_hash => {}), :address => "identi.ca")
109109
Net::HTTP::Get.expects(:new).with('/api/people', {}).returns(request)
110110
@consumer.expects(:create_http).returns(http)
111111
@consumer.request(:get, '/people', nil, {})
@@ -154,6 +154,19 @@ def test_override_paths
154154
assert_equal :post,@consumer.http_method
155155
end
156156

157+
def test_getting_tokens_doesnt_add_paths_if_full_url_is_specified
158+
@consumer = OAuth::Consumer.new(
159+
"key",
160+
"secret",
161+
{
162+
:site => "https://api.mysite.co.nz/v1",
163+
:request_token_url => "https://authentication.mysite.co.nz/Oauth/RequestToken"
164+
})
165+
166+
stub_request(:post, "https://authentication.mysite.co.nz/Oauth/RequestToken").to_return(:body => "success", :status => 200)
167+
@consumer.get_request_token
168+
end
169+
157170
def test_token_request_identifies_itself_as_a_token_request
158171
request_options = {}
159172
@consumer.stubs(:request).returns(create_stub_http_response)

0 commit comments

Comments
 (0)