diff options
author | Andre Arko <andre@arko.net> | 2015-01-25 18:16:06 -0800 |
---|---|---|
committer | Andre Arko <andre@arko.net> | 2015-01-25 18:16:06 -0800 |
commit | 8a510325addfd1f1ad07df5eb98099860695911d (patch) | |
tree | 34f97e042c9f691006d28b00f9ed8777090013cf | |
parent | 96ca0b8a7f06f86ec0cb1e364d47de15ce4d3df2 (diff) | |
download | bundler-8a510325addfd1f1ad07df5eb98099860695911d.tar.gz |
test AnonymizableURI auth parameter
-rw-r--r-- | lib/bundler/anonymizable_uri.rb | 6 | ||||
-rw-r--r-- | spec/bundler/anonymizable_uri_spec.rb | 20 |
2 files changed, 19 insertions, 7 deletions
diff --git a/lib/bundler/anonymizable_uri.rb b/lib/bundler/anonymizable_uri.rb index fe1cf9a5e8..333a568f84 100644 --- a/lib/bundler/anonymizable_uri.rb +++ b/lib/bundler/anonymizable_uri.rb @@ -3,15 +3,15 @@ module Bundler attr_reader :original_uri, :without_credentials - def initialize(original_uri, fallback_auth) + def initialize(original_uri, fallback_auth = nil) @original_uri = apply_auth(original_uri, fallback_auth).freeze @without_credentials = remove_auth(@original_uri).freeze end private - def apply_auth(uri, auth) - if uri.userinfo.nil? + def apply_auth(uri, auth = nil) + if auth && uri.userinfo.nil? uri = uri.dup uri.userinfo = auth end diff --git a/spec/bundler/anonymizable_uri_spec.rb b/spec/bundler/anonymizable_uri_spec.rb index e5d9faeb84..c444ea04d7 100644 --- a/spec/bundler/anonymizable_uri_spec.rb +++ b/spec/bundler/anonymizable_uri_spec.rb @@ -2,14 +2,22 @@ require 'spec_helper' require 'bundler/anonymizable_uri' describe Bundler::AnonymizableURI do - let(:anonymizable_uri) { Bundler::AnonymizableURI.new(original_uri) } + def auri(uri, auth = nil) + Bundler::AnonymizableURI.new(uri, auth) + end describe "#without_credentials" do context "when the original URI has no credentials" do let(:original_uri) { URI('https://rubygems.org') } it "returns the original URI" do - expect(anonymizable_uri.without_credentials).to eq(original_uri) + expect(auri(original_uri).without_credentials).to eq(original_uri) + end + + it "applies given credentials" do + with_auth = original_uri.dup + with_auth.userinfo = "user:pass" + expect(auri(original_uri, "user:pass").original_uri).to eq(with_auth) end end @@ -17,7 +25,11 @@ describe Bundler::AnonymizableURI do let(:original_uri) { URI("https://username:password@gems.example.com") } it "returns the URI without username and password" do - expect(anonymizable_uri.without_credentials).to eq(URI("https://gems.example.com")) + expect(auri(original_uri).without_credentials).to eq(URI("https://gems.example.com")) + end + + it "does not apply given credentials" do + expect(auri(original_uri, "other:stuff").original_uri).to eq(original_uri) end end @@ -25,7 +37,7 @@ describe Bundler::AnonymizableURI do let(:original_uri) { URI("https://SeCrEt-ToKeN@gem.fury.io/me/") } it "returns the URI without username and password" do - expect(anonymizable_uri.without_credentials).to eq(URI("https://gem.fury.io/me/")) + expect(auri(original_uri).without_credentials).to eq(URI("https://gem.fury.io/me/")) end end end |