summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndré Arko <andre@arko.net>2013-10-26 11:38:41 -0700
committerAndré Arko <andre@arko.net>2013-10-26 11:38:41 -0700
commitbead9260b6eea2ef6bc1327f945caa79d764118a (patch)
tree8ac90173a70f963310ed9913135db0ddf828d661
parent5d4577447d1324182b1a9e4e6e5065186b7aa2ed (diff)
parenta413606f199875f1d4640cf2482ee9608aa0a05d (diff)
downloadbundler-bead9260b6eea2ef6bc1327f945caa79d764118a.tar.gz
Merge pull request #2686 from grddev/redirect_fix_13
Handle cross-host redirects with plain Net::HTTP
-rw-r--r--lib/bundler/fetcher.rb7
-rw-r--r--spec/install/gems/dependency_api_spec.rb34
-rw-r--r--spec/support/artifice/endpoint_host_redirect.rb15
3 files changed, 55 insertions, 1 deletions
diff --git a/lib/bundler/fetcher.rb b/lib/bundler/fetcher.rb
index f5ad0347e7..951cc95200 100644
--- a/lib/bundler/fetcher.rb
+++ b/lib/bundler/fetcher.rb
@@ -203,7 +203,12 @@ module Bundler
else
req = Net::HTTP::Get.new uri.request_uri
req.basic_auth(uri.user, uri.password) if uri.user && uri.password
- response = @connection.request(req)
+ if uri.host == @connection.address && uri.port == @connection.port
+ connection = @connection
+ else
+ connection = Net::HTTP.new(uri.host, uri.port)
+ end
+ response = connection.request(req)
end
rescue OpenSSL::SSL::SSLError
raise CertificateFailureError.new(@public_uri)
diff --git a/spec/install/gems/dependency_api_spec.rb b/spec/install/gems/dependency_api_spec.rb
index c88fdcc2d2..093b314e5f 100644
--- a/spec/install/gems/dependency_api_spec.rb
+++ b/spec/install/gems/dependency_api_spec.rb
@@ -162,6 +162,40 @@ describe "gemcutter's dependency API" do
should_be_installed "rack 1.0.0"
end
+ it "handles host redirects" do
+ gemfile <<-G
+ source "#{source_uri}"
+ gem "rack"
+ G
+
+ bundle :install, :artifice => "endpoint_host_redirect"
+ should_be_installed "rack 1.0.0"
+ end
+
+ it "handles host redirects without Net::HTTP::Persistent" do
+ gemfile <<-G
+ source "#{source_uri}"
+ gem "rack"
+ G
+
+ FileUtils.mkdir_p lib_path
+ File.open(lib_path("disable_net_http_persistent.rb"), "w") do |h|
+ h.write <<-H
+ module Kernel
+ alias require_without_disabled_net_http require
+ def require(*args)
+ raise LoadError, 'simulated' if args.first == 'openssl' && !caller.grep(/vendored_persistent/).empty?
+ require_without_disabled_net_http(*args)
+ end
+ end
+ H
+ end
+
+ bundle :install, :artifice => "endpoint_host_redirect", :requires => [lib_path("disable_net_http_persistent.rb")]
+ expect(out).to_not match(/Too many redirects/)
+ should_be_installed "rack 1.0.0"
+ end
+
it "timeouts when Bundler::Fetcher redirects too much" do
gemfile <<-G
source "#{source_uri}"
diff --git a/spec/support/artifice/endpoint_host_redirect.rb b/spec/support/artifice/endpoint_host_redirect.rb
new file mode 100644
index 0000000000..e44d63e2a6
--- /dev/null
+++ b/spec/support/artifice/endpoint_host_redirect.rb
@@ -0,0 +1,15 @@
+require File.expand_path("../endpoint", __FILE__)
+
+Artifice.deactivate
+
+class EndpointHostRedirect < Endpoint
+ get "/fetch/actual/gem/:id", :host_name => 'localgemserver.test' do
+ redirect "http://bundler.localgemserver.test#{request.path_info}"
+ end
+
+ get "/api/v1/dependencies" do
+ status 404
+ end
+end
+
+Artifice.activate_with(EndpointHostRedirect)