Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Check silence_root_warning option to skip warning on root install cmds #4113

Merged
merged 2 commits into from
Nov 21, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/bundler/cli/install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def run
private

def warn_if_root
return if Bundler::WINDOWS || !Process.uid.zero?
return if Bundler.settings[:silence_root_warning] || Bundler::WINDOWS || !Process.uid.zero?
Bundler.ui.warn "Don't run Bundler as root. Bundler can ask for sudo " \
"if it is needed, and installing your bundle as root will break this " \
"application for all non-root users on this machine.", :wrap => true
Expand Down
2 changes: 1 addition & 1 deletion lib/bundler/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Bundler
class Settings
BOOL_KEYS = %w(frozen cache_all no_prune disable_local_branch_check ignore_messages gem.mit gem.coc).freeze
BOOL_KEYS = %w(frozen cache_all no_prune disable_local_branch_check ignore_messages gem.mit gem.coc silence_root_warning).freeze
NUMBER_KEYS = %w(retry timeout redirect ssl_verify_mode).freeze
DEFAULT_CONFIG = { :retry => 3, :timeout => 10, :redirect => 5 }

Expand Down
30 changes: 28 additions & 2 deletions spec/install/gems/sudo_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,36 @@
end

describe "and root runs install" do
it "warns against that" do
let(:warning) { "Don't run Bundler as root." }

before do
gemfile %|source "file://#{gem_repo1}"|
end

it "warns against that" do
bundle :install, :sudo => true
expect(out).to include("Don't run Bundler as root.")
expect(out).to include(warning)
end

context "when ENV['BUNDLE_SILENCE_ROOT_WARNING'] is set" do
it "skips the warning" do
bundle :install, :sudo => :preserve_env, :env => { "BUNDLE_SILENCE_ROOT_WARNING" => true }
expect(out).to_not include(warning)
end
end

context "when silence_root_warning is passed as an option" do
it "skips the warning" do
bundle :install, :sudo => true, :silence_root_warning => true
expect(out).to_not include(warning)
end
end

context "when silence_root_warning = false" do
it "warns against that" do
bundle :install, :sudo => true, :silence_root_warning => false
expect(out).to include(warning)
end
end
end
end
4 changes: 3 additions & 1 deletion spec/support/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ def spec

def bundle(cmd, options = {})
expect_err = options.delete(:expect_err)
sudo = "sudo" if options.delete(:sudo)
with_sudo = options.delete(:sudo)
sudo = with_sudo == :preserve_env ? "sudo -E" : "sudo" if with_sudo

options["no-color"] = true unless options.key?("no-color") || %w(exec conf).include?(cmd.to_s[0..3])

bundle_bin = File.expand_path("../../../exe/bundle", __FILE__)
Expand Down