Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cdn_url? check shouldn't crash operations. Catch YAML.load failure #11033

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/cocoapods/sources_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def cdn_url?(url)
response = OpenURI.open_uri(url.chomp('/') + '/CocoaPods-version.yml', uri_options)
response_hash = YAML.load(response.read) # rubocop:disable Security/YAMLLoad
response_hash.is_a?(Hash) && !Source::Metadata.new(response_hash).latest_cocoapods_version.nil?
rescue ::OpenURI::HTTPError, SocketError
rescue Psych::SyntaxError, ::OpenURI::HTTPError, SocketError
return false
rescue => e
raise Informative, "Couldn't determine repo type for URL: `#{url}`: #{e}"
Expand Down
16 changes: 6 additions & 10 deletions spec/unit/sources_manager_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -179,16 +179,12 @@ module Pod
end

it 'fake 200 response' do
HTML_RESPONSE = '<!doctype html>
<html>
<head>
<title>Some page</title>\n\n <meta charset=\"utf-8\" />
<body>
<div>
<h1>Some page</h1>
</div>
</body>
</html>"'.freeze
# really broken (not compatible with YAML) html that may return any endpoint
# i.e. login page after request redirect
HTML_RESPONSE = '<!DOCTYPE html>
<html class="devise-layout-html">
<head prefix="og: http://ogp.me/ns#">
<meta charset="utf-8">'.freeze
WebMock.stub_request(:get, 'https://some_host.com/something/CocoaPods-version.yml').
to_return(:status => 200, :body => HTML_RESPONSE)
@sources_manager.cdn_url?('https://some_host.com/something').should == false
Expand Down