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 ...@@ -222,6 +222,8 @@ module Pod
attr_accessor :consumer attr_accessor :consumer
attr_accessor :subspec_name attr_accessor :subspec_name
MAX_HTTP_REDIRECTS = 3
# Performs validations related to the `homepage` attribute. # Performs validations related to the `homepage` attribute.
# #
def validate_homepage(spec) def validate_homepage(spec)
...@@ -230,6 +232,7 @@ module Pod ...@@ -230,6 +232,7 @@ module Pod
return unless homepage return unless homepage
begin begin
redirects = 0
resp = nil resp = nil
loop do loop do
resp = ::REST.head(homepage) resp = ::REST.head(homepage)
...@@ -240,9 +243,12 @@ module Pod ...@@ -240,9 +243,12 @@ module Pod
if [301, 302, 303, 307, 308].include? resp.status_code if [301, 302, 303, 307, 308].include? resp.status_code
homepage = resp.headers['location'].first homepage = resp.headers['location'].first
redirects += 1
else else
break break
end end
break unless redirects < MAX_HTTP_REDIRECTS
end end
rescue rescue
warning "There was a problem validating the homepage." warning "There was a problem validating the homepage."
......
...@@ -125,6 +125,14 @@ module Pod ...@@ -125,6 +125,14 @@ module Pod
@sut.validate @sut.validate
@sut.results.length.should.equal 0 @sut.results.length.should.equal 0
end 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 end
it "respects the no clean option" do 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