Commit dc49ae52 authored by Boris Bügling's avatar Boris Bügling

Merge pull request #2027 from CocoaPods/feature-allow-homepage-redirects

Feature allow homepage redirects
parents d3b515b3 ab2de1c5
......@@ -33,6 +33,12 @@ To install or update CocoaPods see this [guide](http://docs.cocoapods.org/guides
[Samuel Ford](https://github.com/samuelwford)
[#1042](https://github.com/CocoaPods/CocoaPods/issues/1042)
##### Bug Fixes
* Support HTTP redirects when linting homepage and screenshots.
[Boris Bügling](https://github.com/neonichu)
[#2027](https://github.com/CocoaPods/CocoaPods/pull/2027)
## 0.31.1
[CocoaPods](https://github.com/CocoaPods/CocoaPods/compare/0.31.1...0.31.0)
[CocoaPods-Core](https://github.com/CocoaPods/Core/compare/0.31.1...0.31.0)
......
......@@ -223,13 +223,32 @@ module Pod
attr_accessor :consumer
attr_accessor :subspec_name
MAX_HTTP_REDIRECTS = 3
# Performs validation of a URL
#
def validate_url(url)
require 'rest'
begin
redirects = 0
resp = nil
loop do
resp = ::REST.head(url)
if resp.status_code == 405
resp = ::REST.get(url)
end
if [301, 302, 303, 307, 308].include? resp.status_code
url = resp.headers['location'].first
redirects += 1
else
break
end
break unless redirects < MAX_HTTP_REDIRECTS
end
rescue
warning "There was a problem validating the URL #{url}."
resp = nil
......@@ -253,7 +272,7 @@ module Pod
# Performs validation related to the `screenshots` attribute.
#
def validate_screenshots(spec)
spec.screenshots.each do |screenshot|
spec.screenshots.compact.each do |screenshot|
request = validate_url(screenshot)
if request && !(request.headers['content-type'] && request.headers['content-type'].first =~ /image\/.*/i)
warning "The screenshot #{screenshot} is not a valid image."
......
......@@ -109,6 +109,33 @@ module Pod
@sut.validate
@sut.results.map(&:to_s).first.should.match /There was a problem validating the URL/
end
it "does not fail if the homepage redirects" do
WebMock::API.stub_request(:head, /redirect/).to_return(
:status => 301, :headers => { 'Location' => 'http://banana-corp.local/found/' } )
WebMock::API.stub_request(:head, /found/).to_return( :status => 200 )
Specification.any_instance.stubs(:homepage).returns('http://banana-corp.local/redirect/')
@sut.validate
@sut.results.length.should.equal 0
end
it "does not fail if the homepage does not support HEAD" do
WebMock::API.stub_request(:head, /page/).to_return( :status => 405 )
WebMock::API.stub_request(:get, /page/).to_return( :status => 200 )
Specification.any_instance.stubs(:homepage).returns('http://banana-corp.local/page/')
@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 URL \(.*\) is not reachable/
end
end
describe "Screenshot validation" 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