2018-11-02 19:07:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
RSpec.describe "when using sudo", :sudo => true do
|
|
|
|
describe "and BUNDLE_PATH is writable" do
|
|
|
|
context "but BUNDLE_PATH/build_info is not writable" do
|
2019-06-01 05:49:40 -04:00
|
|
|
let(:subdir) do
|
|
|
|
system_gem_path("cache")
|
|
|
|
end
|
|
|
|
|
2018-11-02 19:07:56 -04:00
|
|
|
before do
|
2020-06-03 14:45:36 -04:00
|
|
|
bundle "config set path.system true"
|
2018-11-02 19:07:56 -04:00
|
|
|
subdir.mkpath
|
|
|
|
sudo "chmod u-w #{subdir}"
|
|
|
|
end
|
|
|
|
|
2019-06-01 05:49:40 -04:00
|
|
|
after do
|
|
|
|
sudo "chmod u+w #{subdir}"
|
|
|
|
end
|
|
|
|
|
2018-11-02 19:07:56 -04:00
|
|
|
it "installs" do
|
|
|
|
install_gemfile <<-G
|
2019-05-06 12:06:21 -04:00
|
|
|
source "#{file_uri_for(gem_repo1)}"
|
2018-11-02 19:07:56 -04:00
|
|
|
gem "rack"
|
|
|
|
G
|
|
|
|
|
|
|
|
expect(out).to_not match(/an error occurred/i)
|
|
|
|
expect(system_gem_path("cache/rack-1.0.0.gem")).to exist
|
|
|
|
expect(the_bundle).to include_gems "rack 1.0"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "and GEM_HOME is owned by root" do
|
|
|
|
before :each do
|
2020-06-03 14:45:36 -04:00
|
|
|
bundle "config set path.system true"
|
2018-11-02 19:07:56 -04:00
|
|
|
chown_system_gems_to_root
|
|
|
|
end
|
|
|
|
|
|
|
|
it "installs" do
|
|
|
|
install_gemfile <<-G
|
2019-05-06 12:06:21 -04:00
|
|
|
source "#{file_uri_for(gem_repo1)}"
|
2018-11-02 19:07:56 -04:00
|
|
|
gem "rack", '1.0'
|
|
|
|
gem "thin"
|
|
|
|
G
|
|
|
|
|
|
|
|
expect(system_gem_path("gems/rack-1.0.0")).to exist
|
|
|
|
expect(system_gem_path("gems/rack-1.0.0").stat.uid).to eq(0)
|
|
|
|
expect(the_bundle).to include_gems "rack 1.0"
|
|
|
|
end
|
|
|
|
|
|
|
|
it "installs rake and a gem dependent on rake in the same session" do
|
|
|
|
gemfile <<-G
|
2019-05-06 12:06:21 -04:00
|
|
|
source "#{file_uri_for(gem_repo1)}"
|
2018-11-02 19:07:56 -04:00
|
|
|
gem "rake"
|
|
|
|
gem "another_implicit_rake_dep"
|
|
|
|
G
|
|
|
|
bundle "install"
|
|
|
|
expect(system_gem_path("gems/another_implicit_rake_dep-1.0")).to exist
|
|
|
|
end
|
|
|
|
|
|
|
|
it "installs when BUNDLE_PATH is owned by root" do
|
|
|
|
bundle_path = tmp("owned_by_root")
|
|
|
|
FileUtils.mkdir_p bundle_path
|
|
|
|
sudo "chown -R root #{bundle_path}"
|
|
|
|
|
|
|
|
ENV["BUNDLE_PATH"] = bundle_path.to_s
|
|
|
|
install_gemfile <<-G
|
2019-05-06 12:06:21 -04:00
|
|
|
source "#{file_uri_for(gem_repo1)}"
|
2018-11-02 19:07:56 -04:00
|
|
|
gem "rack", '1.0'
|
|
|
|
G
|
|
|
|
|
2019-06-01 05:49:40 -04:00
|
|
|
expect(bundle_path.join(Bundler.ruby_scope, "gems/rack-1.0.0")).to exist
|
|
|
|
expect(bundle_path.join(Bundler.ruby_scope, "gems/rack-1.0.0").stat.uid).to eq(0)
|
2018-11-02 19:07:56 -04:00
|
|
|
expect(the_bundle).to include_gems "rack 1.0"
|
|
|
|
end
|
|
|
|
|
|
|
|
it "installs when BUNDLE_PATH does not exist" do
|
|
|
|
root_path = tmp("owned_by_root")
|
|
|
|
FileUtils.mkdir_p root_path
|
|
|
|
sudo "chown -R root #{root_path}"
|
|
|
|
bundle_path = root_path.join("does_not_exist")
|
|
|
|
|
|
|
|
ENV["BUNDLE_PATH"] = bundle_path.to_s
|
|
|
|
install_gemfile <<-G
|
2019-05-06 12:06:21 -04:00
|
|
|
source "#{file_uri_for(gem_repo1)}"
|
2018-11-02 19:07:56 -04:00
|
|
|
gem "rack", '1.0'
|
|
|
|
G
|
|
|
|
|
2019-06-01 05:49:40 -04:00
|
|
|
expect(bundle_path.join(Bundler.ruby_scope, "gems/rack-1.0.0")).to exist
|
|
|
|
expect(bundle_path.join(Bundler.ruby_scope, "gems/rack-1.0.0").stat.uid).to eq(0)
|
2018-11-02 19:07:56 -04:00
|
|
|
expect(the_bundle).to include_gems "rack 1.0"
|
|
|
|
end
|
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
it "installs extensions/" do
|
2018-11-02 19:07:56 -04:00
|
|
|
install_gemfile <<-G
|
2019-05-06 12:06:21 -04:00
|
|
|
source "#{file_uri_for(gem_repo1)}"
|
2018-11-02 19:07:56 -04:00
|
|
|
gem "very_simple_binary"
|
|
|
|
G
|
|
|
|
|
|
|
|
expect(system_gem_path("gems/very_simple_binary-1.0")).to exist
|
|
|
|
binary_glob = system_gem_path("extensions/*/*/very_simple_binary-1.0")
|
|
|
|
expect(Dir.glob(binary_glob).first).to be
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "and BUNDLE_PATH is not writable" do
|
|
|
|
before do
|
2020-06-07 09:54:38 -04:00
|
|
|
bundle "config set --local path .bundle"
|
|
|
|
sudo "chmod ugo-w .bundle"
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
|
2019-06-01 05:49:40 -04:00
|
|
|
after do
|
2020-06-07 09:54:38 -04:00
|
|
|
sudo "chmod ugo+w .bundle"
|
2019-06-01 05:49:40 -04:00
|
|
|
end
|
|
|
|
|
2018-11-02 19:07:56 -04:00
|
|
|
it "installs" do
|
|
|
|
install_gemfile <<-G
|
2019-05-06 12:06:21 -04:00
|
|
|
source "#{file_uri_for(gem_repo1)}"
|
2018-11-02 19:07:56 -04:00
|
|
|
gem "rack", '1.0'
|
|
|
|
G
|
|
|
|
|
2020-06-07 09:54:38 -04:00
|
|
|
expect(local_gem_path("gems/rack-1.0.0")).to exist
|
2018-11-02 19:07:56 -04:00
|
|
|
expect(the_bundle).to include_gems "rack 1.0"
|
|
|
|
end
|
|
|
|
|
|
|
|
it "cleans up the tmpdirs generated" do
|
|
|
|
require "tmpdir"
|
|
|
|
Dir.glob("#{Dir.tmpdir}/bundler*").each do |tmpdir|
|
|
|
|
FileUtils.remove_entry_secure(tmpdir)
|
|
|
|
end
|
|
|
|
|
|
|
|
install_gemfile <<-G
|
2019-05-06 12:06:21 -04:00
|
|
|
source "#{file_uri_for(gem_repo1)}"
|
2018-11-02 19:07:56 -04:00
|
|
|
gem "rack"
|
|
|
|
G
|
|
|
|
tmpdirs = Dir.glob("#{Dir.tmpdir}/bundler*")
|
|
|
|
|
|
|
|
expect(tmpdirs).to be_empty
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "and GEM_HOME is not writable" do
|
|
|
|
it "installs" do
|
2020-06-03 14:45:36 -04:00
|
|
|
bundle "config set path.system true"
|
2018-11-02 19:07:56 -04:00
|
|
|
gem_home = tmp("sudo_gem_home")
|
|
|
|
sudo "mkdir -p #{gem_home}"
|
|
|
|
sudo "chmod ugo-w #{gem_home}"
|
|
|
|
|
2020-05-15 08:31:12 -04:00
|
|
|
system_gems :bundler, :path => gem_home
|
|
|
|
|
2018-11-02 19:07:56 -04:00
|
|
|
gemfile <<-G
|
2019-05-06 12:06:21 -04:00
|
|
|
source "#{file_uri_for(gem_repo1)}"
|
2018-11-02 19:07:56 -04:00
|
|
|
gem "rack", '1.0'
|
|
|
|
G
|
|
|
|
|
|
|
|
bundle :install, :env => { "GEM_HOME" => gem_home.to_s, "GEM_PATH" => nil }
|
|
|
|
expect(gem_home.join("bin/rackup")).to exist
|
|
|
|
expect(the_bundle).to include_gems "rack 1.0", :env => { "GEM_HOME" => gem_home.to_s, "GEM_PATH" => nil }
|
2019-06-01 05:49:40 -04:00
|
|
|
|
|
|
|
sudo "rm -rf #{tmp("sudo_gem_home")}"
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "and root runs install" do
|
|
|
|
let(:warning) { "Don't run Bundler as root." }
|
|
|
|
|
|
|
|
before do
|
2019-05-06 12:06:21 -04:00
|
|
|
gemfile %(source "#{file_uri_for(gem_repo1)}")
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "warns against that" do
|
2020-05-08 01:19:04 -04:00
|
|
|
bundle :install, :sudo => :preserve_env
|
2019-04-14 02:01:35 -04:00
|
|
|
expect(err).to include(warning)
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context "when ENV['BUNDLE_SILENCE_ROOT_WARNING'] is set" do
|
|
|
|
it "skips the warning" do
|
2019-12-14 05:49:16 -05:00
|
|
|
bundle :install, :sudo => :preserve_env, :env => { "BUNDLE_SILENCE_ROOT_WARNING" => "true" }
|
2019-04-14 02:01:35 -04:00
|
|
|
expect(err).to_not include(warning)
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when silence_root_warning = false" do
|
|
|
|
it "warns against that" do
|
2020-05-08 01:19:04 -04:00
|
|
|
bundle :install, :sudo => :preserve_env, :env => { "BUNDLE_SILENCE_ROOT_WARNING" => "false" }
|
2019-04-14 02:01:35 -04:00
|
|
|
expect(err).to include(warning)
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|