Skip to content

Commit 16902af

Browse files
authored
🔀 Merge pull request #210 from oauth-xx/morganick-revert-0.5.5-regression
Morganick revert 0.5.5 regression
2 parents 051a45c + aaad894 commit 16902af

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

‎lib/oauth/consumer.rb‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,16 +242,18 @@ def token_request(http_method, path, token = nil, request_options = {}, *argumen
242242
end
243243
end
244244
when (300..399)
245-
# this is a redirect
245+
# Parse redirect to follow
246246
uri = URI.parse(response["location"])
247247
our_uri = URI.parse(site)
248248

249+
# Guard against infinite redirects
250+
response.error! if uri.path == path && our_uri.host == uri.host
251+
249252
if uri.path == path && our_uri.host != uri.host
250253
options[:site] = "#{uri.scheme}://#{uri.host}"
251254
@http = create_http
252255
end
253256

254-
response.error! if uri.path == path && our_uri.host == uri.host # careful of those infinite redirects
255257
self.token_request(http_method, uri.path, token, request_options, arguments)
256258
when (400..499)
257259
raise OAuth::Unauthorized, response

‎test/units/test_consumer.rb‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,22 @@ def test_follow_redirect_different_host_same_path
263263
assert_equal "secret", hash[:oauth_token_secret]
264264
end
265265

266+
def test_not_following_redirect_with_same_uri
267+
request_uri = URI.parse("http://example.com/request_token")
268+
redirect_uri = request_uri.clone
269+
270+
stub_request(:get, request_uri.to_s).to_return(
271+
:status => 301,
272+
:headers => {"Location" => redirect_uri.to_s}
273+
)
274+
275+
assert_raises Net::HTTPRetriableError do
276+
@consumer.token_request(:get, request_uri.path) do
277+
{ :oauth_token => "token", :oauth_token_secret => "secret" }
278+
end
279+
end
280+
end
281+
266282
def test_that_can_provide_a_block_to_interpret_a_request_token_response
267283
@consumer.expects(:request).returns(create_stub_http_response)
268284

0 commit comments

Comments
 (0)