summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndré Arko <mail@arko.net>2014-09-28 02:06:55 +0900
committerAndré Arko <mail@arko.net>2014-09-28 02:06:55 +0900
commitf904cf7c7b365900fd0542ea7c2c1544ac2698b9 (patch)
tree9055d704a8348d5cb76b8696f4262ad99c611bc8
parent8dbb7881c0463807bb8883e084818924fd3df09e (diff)
parentf87da4f5c11442f7c3b61a7ec04f8462154fd5b0 (diff)
downloadbundler-f904cf7c7b365900fd0542ea7c2c1544ac2698b9.tar.gz
Merge pull request #3191 from fvaleur/fix_use_api_auth
Use HTTP auth if configured when checking for presence of API
-rw-r--r--lib/bundler/fetcher.rb13
-rw-r--r--spec/install/gems/dependency_api_spec.rb2
2 files changed, 13 insertions, 2 deletions
diff --git a/lib/bundler/fetcher.rb b/lib/bundler/fetcher.rb
index 8c8c868909..48cdf26e1d 100644
--- a/lib/bundler/fetcher.rb
+++ b/lib/bundler/fetcher.rb
@@ -226,6 +226,12 @@ module Bundler
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
@@ -233,6 +239,9 @@ module Bundler
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
@@ -268,6 +277,8 @@ module Bundler
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
@@ -282,8 +293,6 @@ module Bundler
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
diff --git a/spec/install/gems/dependency_api_spec.rb b/spec/install/gems/dependency_api_spec.rb
index b3e5edf468..b8f8011f99 100644
--- a/spec/install/gems/dependency_api_spec.rb
+++ b/spec/install/gems/dependency_api_spec.rb
@@ -467,6 +467,8 @@ describe "gemcutter's dependency API" do
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