From 402fd96ddc401cf35bced8d394c44df98d6fc466 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Ondruch?= Date: Tue, 12 Dec 2023 14:38:45 +0100 Subject: [rubygems/rubygems] Make sure `--no-user-install` is respected for auto user installation The `options[:user_install]` might have three states: * `true`: `--user-install` * `false`: `--no-user-install` and * `nil`: option was not specified However, this had not been respected previously and the `false` and `nil` were treated the same. This could lead to auto user installation despite `--no-user-install` being specified on the command line. Fixes https://github.com/rubygems/rubygems/pull/7237 https://github.com/rubygems/rubygems/commit/9281545474 --- test/rubygems/test_gem_installer.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'test') diff --git a/test/rubygems/test_gem_installer.rb b/test/rubygems/test_gem_installer.rb index 4fa8b7f4fe..3110ac63a6 100644 --- a/test/rubygems/test_gem_installer.rb +++ b/test/rubygems/test_gem_installer.rb @@ -1995,6 +1995,27 @@ end ENV["GEM_HOME"] = orig_gem_home end + def test_process_options_does_not_fallback_to_user_install_when_gem_home_not_writable_and_no_user_install + if Process.uid.zero? + pend("skipped in root privilege") + return + end + + orig_gem_home = ENV.delete("GEM_HOME") + + @gem = setup_base_gem + + FileUtils.chmod 0o000, @gemhome + + installer = use_ui(@ui) { Gem::Installer.at @gem, user_install: false } + + assert_equal @gemhome, installer.gem_home + assert_empty @ui.output.strip + ensure + FileUtils.chmod 0o755, @gemhome + ENV["GEM_HOME"] = orig_gem_home + end + def test_shebang_arguments load_relative "no" do installer = setup_base_installer -- cgit v1.2.3