Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Use HTTP auth if configured when checking for presence of API #3191

Merged
merged 1 commit into from
Sep 27, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions lib/bundler/fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,22 @@ def fetch_remote_specs(gem_names, full_dependency_list = [], last_spec_list = []
end

def use_api
_use_api(true)
rescue AuthenticationRequiredError
retry_with_auth{_use_api(false)}
end

def _use_api(reraise_auth_error = false)
return @use_api if defined?(@use_api)

if @remote_uri.scheme == "file" || Bundler::Fetcher.disable_endpoint
@use_api = false
elsif fetch(dependency_api_uri)
@use_api = true
end
rescue AuthenticationRequiredError => e
raise e if reraise_auth_error
false
rescue HTTPError
@use_api = false
end
Expand Down Expand Up @@ -268,6 +277,8 @@ def fetch(uri, counter = 0)
response.body
when Net::HTTPRequestEntityTooLarge
raise FallbackError, response.body
when Net::HTTPUnauthorized
raise AuthenticationRequiredError, "#{response.class}: #{response.body}"
else
raise HTTPError, "#{response.class}: #{response.body}"
end
Expand All @@ -282,8 +293,6 @@ def request(uri)
req.basic_auth(user, password)
end
connection.request(uri, req)
rescue Net::HTTPUnauthorized, Net::HTTPForbidden
retry_with_auth { request(uri) }
rescue OpenSSL::SSL::SSLError
raise CertificateFailureError.new(uri)
rescue *HTTP_ERRORS => e
Expand Down
2 changes: 2 additions & 0 deletions spec/install/gems/dependency_api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,8 @@ def require(*args)
bundle "config #{source_uri}/ #{user}:#{password}"

bundle :install, :artifice => "endpoint_strict_basic_authentication"

expect(out).to include("Fetching gem metadata from #{source_uri}")
should_be_installed "rack 1.0.0"
end

Expand Down