diff options
Diffstat (limited to 'spec/bundler/bundler/source')
-rw-r--r-- | spec/bundler/bundler/source/git/git_proxy_spec.rb | 117 | ||||
-rw-r--r-- | spec/bundler/bundler/source/path_spec.rb | 31 | ||||
-rw-r--r-- | spec/bundler/bundler/source/rubygems/remote_spec.rb | 162 | ||||
-rw-r--r-- | spec/bundler/bundler/source/rubygems_spec.rb | 34 |
4 files changed, 344 insertions, 0 deletions
diff --git a/spec/bundler/bundler/source/git/git_proxy_spec.rb b/spec/bundler/bundler/source/git/git_proxy_spec.rb new file mode 100644 index 0000000000..34fe21e9fb --- /dev/null +++ b/spec/bundler/bundler/source/git/git_proxy_spec.rb @@ -0,0 +1,117 @@ +# frozen_string_literal: true +require "spec_helper" + +RSpec.describe Bundler::Source::Git::GitProxy do + let(:uri) { "https://github.com/bundler/bundler.git" } + subject { described_class.new(Pathname("path"), uri, "HEAD") } + + context "with configured credentials" do + it "adds username and password to URI" do + Bundler.settings[uri] = "u:p" + expect(subject).to receive(:git_retry).with(match("https://u:p@github.com/bundler/bundler.git")) + subject.checkout + end + + it "adds username and password to URI for host" do + Bundler.settings["github.com"] = "u:p" + expect(subject).to receive(:git_retry).with(match("https://u:p@github.com/bundler/bundler.git")) + subject.checkout + end + + it "does not add username and password to mismatched URI" do + Bundler.settings["https://u:p@github.com/bundler/bundler-mismatch.git"] = "u:p" + expect(subject).to receive(:git_retry).with(match(uri)) + subject.checkout + end + + it "keeps original userinfo" do + Bundler.settings["github.com"] = "u:p" + original = "https://orig:info@github.com/bundler/bundler.git" + subject = described_class.new(Pathname("path"), original, "HEAD") + expect(subject).to receive(:git_retry).with(match(original)) + subject.checkout + end + end + + describe "#version" do + context "with a normal version number" do + before do + expect(subject).to receive(:git).with("--version"). + and_return("git version 1.2.3") + end + + it "returns the git version number" do + expect(subject.version).to eq("1.2.3") + end + + it "does not raise an error when passed into Gem::Version.create" do + expect { Gem::Version.create subject.version }.not_to raise_error + end + end + + context "with a OSX version number" do + before do + expect(subject).to receive(:git).with("--version"). + and_return("git version 1.2.3 (Apple Git-BS)") + end + + it "strips out OSX specific additions in the version string" do + expect(subject.version).to eq("1.2.3") + end + + it "does not raise an error when passed into Gem::Version.create" do + expect { Gem::Version.create subject.version }.not_to raise_error + end + end + + context "with a msysgit version number" do + before do + expect(subject).to receive(:git).with("--version"). + and_return("git version 1.2.3.msysgit.0") + end + + it "strips out msysgit specific additions in the version string" do + expect(subject.version).to eq("1.2.3") + end + + it "does not raise an error when passed into Gem::Version.create" do + expect { Gem::Version.create subject.version }.not_to raise_error + end + end + end + + describe "#full_version" do + context "with a normal version number" do + before do + expect(subject).to receive(:git).with("--version"). + and_return("git version 1.2.3") + end + + it "returns the git version number" do + expect(subject.full_version).to eq("1.2.3") + end + end + + context "with a OSX version number" do + before do + expect(subject).to receive(:git).with("--version"). + and_return("git version 1.2.3 (Apple Git-BS)") + end + + it "does not strip out OSX specific additions in the version string" do + expect(subject.full_version).to eq("1.2.3 (Apple Git-BS)") + end + end + + context "with a msysgit version number" do + before do + expect(subject).to receive(:git).with("--version"). + and_return("git version 1.2.3.msysgit.0") + end + + it "does not strip out msysgit specific additions in the version string" do + expect(subject.full_version).to eq("1.2.3.msysgit.0") + end + end + end +end diff --git a/spec/bundler/bundler/source/path_spec.rb b/spec/bundler/bundler/source/path_spec.rb new file mode 100644 index 0000000000..1d13e03ec1 --- /dev/null +++ b/spec/bundler/bundler/source/path_spec.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +RSpec.describe Bundler::Source::Path do + before do + allow(Bundler).to receive(:root) { Pathname.new("root") } + end + + describe "#eql?" do + subject { described_class.new("path" => "gems/a") } + + context "with two equivalent relative paths from different roots" do + let(:a_gem_opts) { { "path" => "../gems/a", "root_path" => Bundler.root.join("nested") } } + let(:a_gem) { described_class.new a_gem_opts } + + it "returns true" do + expect(subject).to eq a_gem + end + end + + context "with the same (but not equivalent) relative path from different roots" do + subject { described_class.new("path" => "gems/a") } + + let(:a_gem_opts) { { "path" => "gems/a", "root_path" => Bundler.root.join("nested") } } + let(:a_gem) { described_class.new a_gem_opts } + + it "returns false" do + expect(subject).to_not eq a_gem + end + end + end +end diff --git a/spec/bundler/bundler/source/rubygems/remote_spec.rb b/spec/bundler/bundler/source/rubygems/remote_spec.rb new file mode 100644 index 0000000000..54394fc0ca --- /dev/null +++ b/spec/bundler/bundler/source/rubygems/remote_spec.rb @@ -0,0 +1,162 @@ +# frozen_string_literal: true +require "spec_helper" +require "bundler/source/rubygems/remote" + +RSpec.describe Bundler::Source::Rubygems::Remote do + def remote(uri) + Bundler::Source::Rubygems::Remote.new(uri) + end + + before do + allow(Digest::MD5).to receive(:hexdigest).with(duck_type(:to_s)) {|string| "MD5HEX(#{string})" } + end + + let(:uri_no_auth) { URI("https://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 + it "returns the original URI" do + expect(remote(uri_no_auth).uri).to eq(uri_no_auth) + end + + 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 + + describe "#anonymized_uri" do + it "returns the original URI" do + expect(remote(uri_no_auth).anonymized_uri).to eq(uri_no_auth) + end + + it "does not apply given credentials" do + Bundler.settings[uri_no_auth.to_s] = credentials + expect(remote(uri_no_auth).anonymized_uri).to eq(uri_no_auth) + end + end + + describe "#cache_slug" do + it "returns the correct slug" do + expect(remote(uri_no_auth).cache_slug).to eq("gems.example.com.443.MD5HEX(gems.example.com.443./)") + end + + it "only applies the given user" do + Bundler.settings[uri_no_auth.to_s] = credentials + expect(remote(uri_no_auth).cache_slug).to eq("gems.example.com.username.443.MD5HEX(gems.example.com.username.443./)") + end + end + end + + context "when the original URI has a username and password" do + describe "#uri" do + it "returns the original URI" do + expect(remote(uri_with_auth).uri).to eq(uri_with_auth) + end + + 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 + + describe "#anonymized_uri" do + it "returns the URI without username and password" do + expect(remote(uri_with_auth).anonymized_uri).to eq(uri_no_auth) + end + + it "does not apply given credentials" do + Bundler.settings[uri_no_auth.to_s] = "other:stuff" + expect(remote(uri_with_auth).anonymized_uri).to eq(uri_no_auth) + end + end + + describe "#cache_slug" do + it "returns the correct slug" do + expect(remote(uri_with_auth).cache_slug).to eq("gems.example.com.username.443.MD5HEX(gems.example.com.username.443./)") + end + + it "does not apply given credentials" do + Bundler.settings[uri_with_auth.to_s] = credentials + expect(remote(uri_with_auth).cache_slug).to eq("gems.example.com.username.443.MD5HEX(gems.example.com.username.443./)") + end + end + end + + context "when the original URI has only a username" do + let(:uri) { URI("https://SeCrEt-ToKeN@gem.fury.io/me/") } + + describe "#anonymized_uri" do + it "returns the URI without username and password" do + expect(remote(uri).anonymized_uri).to eq(URI("https://gem.fury.io/me/")) + end + end + + describe "#cache_slug" do + it "returns the correct slug" do + expect(remote(uri).cache_slug).to eq("gem.fury.io.SeCrEt-ToKeN.443.MD5HEX(gem.fury.io.SeCrEt-ToKeN.443./me/)") + end + end + end + + 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/") } + + before { Bundler.settings["mirror.https://rubygems.org/"] = mirror_uri_with_auth.to_s } + + 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 + + specify "#original_uri returns the original source" do + expect(remote(uri).original_uri).to eq(uri) + end + + specify "#cache_slug returns the correct slug" do + expect(remote(uri).cache_slug).to eq("rubygems.org.443.MD5HEX(rubygems.org.443./)") + 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 + + specify "#original_uri returns the original source" do + expect(remote(uri).original_uri).to eq(uri) + end + + specify "#cache_slug returns the original source" do + expect(remote(uri).cache_slug).to eq("rubygems.org.443.MD5HEX(rubygems.org.443./)") + end + end + + context "when there is no mirror set" do + describe "#original_uri" do + it "is not set" do + expect(remote(uri_no_auth).original_uri).to be_nil + end + end + end +end diff --git a/spec/bundler/bundler/source/rubygems_spec.rb b/spec/bundler/bundler/source/rubygems_spec.rb new file mode 100644 index 0000000000..b8f9f09c20 --- /dev/null +++ b/spec/bundler/bundler/source/rubygems_spec.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true +require "spec_helper" + +RSpec.describe Bundler::Source::Rubygems do + before do + allow(Bundler).to receive(:root) { Pathname.new("root") } + end + + describe "caches" do + it "includes Bundler.app_cache" do + expect(subject.caches).to include(Bundler.app_cache) + end + + it "includes GEM_PATH entries" do + Gem.path.each do |path| + expect(subject.caches).to include(File.expand_path("#{path}/cache")) + end + end + + it "is an array of strings or pathnames" do + subject.caches.each do |cache| + expect([String, Pathname]).to include(cache.class) + end + end + end + + describe "#add_remote" do + context "when the source is an HTTP(s) URI with no host" do + it "raises error" do + expect { subject.add_remote("https:rubygems.org") }.to raise_error(ArgumentError) + end + end + end +end |