summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Moore <tmoore@incrementalism.net>2015-03-15 15:32:06 +1100
committerTim Moore <tmoore@incrementalism.net>2015-03-15 15:32:06 +1100
commit5ccddd4c9fd8a9793396439b6c3eb20964323333 (patch)
treeac0113d05a8ef31f64606b82afc0497bed378600
parentd80e5f1ffd59821c33a45798232e129f6b1d8899 (diff)
downloadbundler-5ccddd4c9fd8a9793396439b6c3eb20964323333.tar.gz
Move remote URI resolution logic into Remote.
-rw-r--r--lib/bundler/fetcher.rb3
-rw-r--r--lib/bundler/source/rubygems/remote.rb6
-rw-r--r--spec/bundler/source/rubygems/remote_spec.rb44
3 files changed, 39 insertions, 14 deletions
diff --git a/lib/bundler/fetcher.rb b/lib/bundler/fetcher.rb
index e8d3e36b4c..e23521aa0f 100644
--- a/lib/bundler/fetcher.rb
+++ b/lib/bundler/fetcher.rb
@@ -397,8 +397,7 @@ module Bundler
private
def configured_uri_for(uri)
- config_auth = Bundler.settings.credentials_for(uri)
- Source::Rubygems::Remote.new(uri, config_auth)
+ Source::Rubygems::Remote.new(uri)
end
def fetch_uri
diff --git a/lib/bundler/source/rubygems/remote.rb b/lib/bundler/source/rubygems/remote.rb
index 835daf05df..82ce1a4f9e 100644
--- a/lib/bundler/source/rubygems/remote.rb
+++ b/lib/bundler/source/rubygems/remote.rb
@@ -5,15 +5,17 @@ module Bundler
attr_reader :uri,
:anonymized_uri
- def initialize(uri, fallback_auth = nil)
+ def initialize(uri)
uri = Bundler.settings.mirror_for(uri)
+ fallback_auth = Bundler.settings.credentials_for(uri)
+
@uri = apply_auth(uri, fallback_auth).freeze
@anonymized_uri = remove_auth(@uri).freeze
end
private
- def apply_auth(uri, auth = nil)
+ def apply_auth(uri, auth)
if auth && uri.userinfo.nil?
uri = uri.dup
uri.userinfo = auth
diff --git a/spec/bundler/source/rubygems/remote_spec.rb b/spec/bundler/source/rubygems/remote_spec.rb
index a248f43e1d..cec243bfb1 100644
--- a/spec/bundler/source/rubygems/remote_spec.rb
+++ b/spec/bundler/source/rubygems/remote_spec.rb
@@ -2,12 +2,13 @@ require "spec_helper"
require "bundler/source/rubygems/remote"
describe Bundler::Source::Rubygems::Remote do
- def remote(uri, auth = nil)
- Bundler::Source::Rubygems::Remote.new(uri, auth)
+ def remote(uri)
+ Bundler::Source::Rubygems::Remote.new(uri)
end
let(:uri_no_auth) { URI("https://gems.example.com") }
- let(:uri_with_auth) { URI("https://username:password@gems.example.com") }
+ let(:uri_with_auth) { URI("https://#{credentials}@gems.example.com") }
+ let(:credentials) { "username:password" }
context "when the original URI has no credentials" do
describe "#uri" do
@@ -15,8 +16,9 @@ describe Bundler::Source::Rubygems::Remote do
expect(remote(uri_no_auth).uri).to eq(uri_no_auth)
end
- it "applies given credentials" do
- expect(remote(uri_no_auth, "username:password").uri).to eq(uri_with_auth)
+ it "applies configured credentials" do
+ Bundler.settings[uri_no_auth.to_s] = credentials
+ expect(remote(uri_no_auth).uri).to eq(uri_with_auth)
end
end
@@ -26,7 +28,8 @@ describe Bundler::Source::Rubygems::Remote do
end
it "does not apply given credentials" do
- expect(remote(uri_no_auth, "username:password").anonymized_uri).to eq(uri_no_auth)
+ Bundler.settings[uri_no_auth.to_s] = credentials
+ expect(remote(uri_no_auth).anonymized_uri).to eq(uri_no_auth)
end
end
end
@@ -37,8 +40,9 @@ describe Bundler::Source::Rubygems::Remote do
expect(remote(uri_with_auth).uri).to eq(uri_with_auth)
end
- it "does not apply given credentials" do
- expect(remote(uri_with_auth, "other:stuff").uri).to eq(uri_with_auth)
+ it "does not apply configured credentials" do
+ Bundler.settings[uri_no_auth.to_s] = "other:stuff"
+ expect(remote(uri_with_auth).uri).to eq(uri_with_auth)
end
end
@@ -48,7 +52,8 @@ describe Bundler::Source::Rubygems::Remote do
end
it "does not apply given credentials" do
- expect(remote(uri_with_auth, "other:stuff").anonymized_uri).to eq(uri_no_auth)
+ Bundler.settings[uri_no_auth.to_s] = "other:stuff"
+ expect(remote(uri_with_auth).anonymized_uri).to eq(uri_no_auth)
end
end
end
@@ -63,7 +68,7 @@ describe Bundler::Source::Rubygems::Remote do
end
end
- context "when a mirror with credentials is configured for the URI" do
+ context "when a mirror with inline credentials is configured for the URI" do
let(:uri) { URI("https://rubygems.org/") }
let(:mirror_uri_with_auth) { URI("https://username:password@rubygems-mirror.org/") }
let(:mirror_uri_no_auth) { URI("https://rubygems-mirror.org/") }
@@ -78,4 +83,23 @@ describe Bundler::Source::Rubygems::Remote do
expect(remote(uri).anonymized_uri).to eq(mirror_uri_no_auth)
end
end
+
+ context "when a mirror with configured credentials is configured for the URI" do
+ let(:uri) { URI("https://rubygems.org/") }
+ let(:mirror_uri_with_auth) { URI("https://#{credentials}@rubygems-mirror.org/") }
+ let(:mirror_uri_no_auth) { URI("https://rubygems-mirror.org/") }
+
+ before do
+ Bundler.settings["mirror.https://rubygems.org/"] = mirror_uri_no_auth.to_s
+ Bundler.settings[mirror_uri_no_auth.to_s] = credentials
+ end
+
+ specify "#uri returns the mirror URI with credentials" do
+ expect(remote(uri).uri).to eq(mirror_uri_with_auth)
+ end
+
+ specify "#anonymized_uri returns the mirror URI without credentials" do
+ expect(remote(uri).anonymized_uri).to eq(mirror_uri_no_auth)
+ end
+ end
end