Commit 7691aedd authored by Boris Bügling's avatar Boris Bügling

Do not follow redirects infinitely.

parent 1bc839c3
......@@ -222,6 +222,8 @@ module Pod
attr_accessor :consumer
attr_accessor :subspec_name
MAX_HTTP_REDIRECTS = 3
# Performs validations related to the `homepage` attribute.
#
def validate_homepage(spec)
......@@ -230,6 +232,7 @@ module Pod
return unless homepage
begin
redirects = 0
resp = nil
loop do
resp = ::REST.head(homepage)
......@@ -240,9 +243,12 @@ module Pod
if [301, 302, 303, 307, 308].include? resp.status_code
homepage = resp.headers['location'].first
redirects += 1
else
break
end
break unless redirects < MAX_HTTP_REDIRECTS
end
rescue
warning "There was a problem validating the homepage."
......
......@@ -125,6 +125,14 @@ module Pod
@sut.validate
@sut.results.length.should.equal 0
end
it "does not follow redirects infinitely" do
WebMock::API.stub_request(:head, /redirect/).to_return(
:status => 301, :headers => { 'Location' => 'http://banana-corp.local/redirect/' } )
Specification.any_instance.stubs(:homepage).returns('http://banana-corp.local/redirect/')
@sut.validate
@sut.results.map(&:to_s).first.should.match /The homepage is not reachable/
end
end
it "respects the no clean option" do
......
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