Detect infinite redirection (i.e. more than 5 redirects).
This originally worked with a timeout. Jonas fixed it so that it follows 5 redirects, but the infinite redirect error was not raised.
This commit is contained in:
parent
87abb6cf0f
commit
5b72525a96
|
@ -256,9 +256,11 @@ private
|
||||||
5.times do
|
5.times do
|
||||||
follow_redirect! if response.redirect?
|
follow_redirect! if response.redirect?
|
||||||
end
|
end
|
||||||
rescue Capybara::TimeoutError
|
|
||||||
|
if response.redirect?
|
||||||
raise Capybara::InfiniteRedirectError, "infinite redirect detected!"
|
raise Capybara::InfiniteRedirectError, "infinite redirect detected!"
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def env
|
def env
|
||||||
env = {}
|
env = {}
|
||||||
|
|
|
@ -194,3 +194,16 @@ shared_examples_for "driver with cookies support" do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
shared_examples_for "driver with infinite redirect detection" do
|
||||||
|
it "should follow 5 redirects" do
|
||||||
|
@driver.visit('/redirect/5/times')
|
||||||
|
@driver.body.should include('redirection complete')
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should not follow more than 5 redirects" do
|
||||||
|
running do
|
||||||
|
@driver.visit('/redirect/6/times')
|
||||||
|
end.should raise_error(Capybara::InfiniteRedirectError)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
|
@ -22,6 +22,15 @@ class TestApp < Sinatra::Base
|
||||||
redirect '/landed'
|
redirect '/landed'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
get '/redirect/:times/times' do
|
||||||
|
times = params[:times].to_i
|
||||||
|
if times.zero?
|
||||||
|
"redirection complete"
|
||||||
|
else
|
||||||
|
redirect "/redirect/#{times - 1}/times"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
get '/landed' do
|
get '/landed' do
|
||||||
"You landed"
|
"You landed"
|
||||||
end
|
end
|
||||||
|
|
|
@ -15,4 +15,5 @@ describe Capybara::Driver::RackTest do
|
||||||
it_should_behave_like "driver with header support"
|
it_should_behave_like "driver with header support"
|
||||||
it_should_behave_like "driver with status code support"
|
it_should_behave_like "driver with status code support"
|
||||||
it_should_behave_like "driver with cookies support"
|
it_should_behave_like "driver with cookies support"
|
||||||
|
it_should_behave_like "driver with infinite redirect detection"
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue