diff options
author | Bundlerbot <bot@bundler.io> | 2020-03-05 12:18:57 +0000 |
---|---|---|
committer | Bundlerbot <bot@bundler.io> | 2020-03-05 12:18:57 +0000 |
commit | c645636cc8e76a53772e3ab15693ed716132159a (patch) | |
tree | d50d99b9eabc864366d70981a42f7e9bb58a96d5 | |
parent | b39df5e3b4f926fa8a928ae2fa0a2a9dcfe5eb33 (diff) | |
parent | d36920f40dae8bb0cda7f4c14fc32fe30ea7fe0e (diff) | |
download | bundler-c645636cc8e76a53772e3ab15693ed716132159a.tar.gz |
Merge #7665
7665: Fix sudo specs environment r=hsbt a=deivid-rodriguez
### What was the end-user or developer problem that led to this PR?
The developer problem is that sudo specs are not correctly setting the environment (except for ruby 2.3). The specs are accidentally passing but you can tell that they are running against the system ruby by the [warning messages they print](https://travis-ci.org/rubygems/bundler/jobs/658272719#L531-L558).
This causes problems when migrating to github actions. See https://github.com/rubygems/bundler/pull/7660#discussion_r385616844.
Another problem is that the environment is setup manually outside of `rake spec:sudo`, so there's no easy way of running sudo specs manually if your system does not have the right sudoers configuration.
### What is your fix for the problem, implemented in this PR?
My fix is to properly set sudo configuration to preserve the environment so that the correct ruby can be found by sudo specs, and also to move the logic inside `rake spec:sudo` so that the specs can easily be run manually without side effects.
Co-authored-by: David RodrÃguez <deivid.rodriguez@riseup.net>
-rw-r--r-- | .travis.yml | 8 | ||||
-rw-r--r-- | Rakefile | 18 |
2 files changed, 18 insertions, 8 deletions
diff --git a/.travis.yml b/.travis.yml index 1100b8981f..638d19b6e1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,8 +2,7 @@ language: ruby dist: bionic script: - bin/parallel_rspec spec - - sudo -E bin/rake spec:sudo - - sudo chown -R $(whoami) tmp + - bin/rake spec:sudo - BUNDLER_SPEC_PRE_RECORDED=1 bin/rake spec:realworld before_script: @@ -13,11 +12,6 @@ before_script: then travis_retry sudo apt-get install graphviz -y; fi - - if [ "$TRAVIS_RUBY_VERSION" = "2.3.8" ]; - then - sudo sed -i 's/1000::/1000:Travis:/g' /etc/passwd; - sudo sed -i '/secure_path/d' /etc/sudoers; - fi branches: only: @@ -55,7 +55,23 @@ namespace :spec do end desc "Run the spec suite with the sudo tests" - task :sudo => %w[set_sudo spec] + task :sudo => %w[set_sudo] do + require "open3" + output, status = Open3.capture2e("sudo", "cp", "/etc/sudoers", "tmp/old_sudoers") + raise "Couldn't read sudoers file: #{output}" unless status.success? + + begin + output, status = Open3.capture2e("sudo sed -i '/secure_path/d' /etc/sudoers") + raise "Couldn't configure sudo to preserve path: #{output}" unless status.success? + + raise "Couldn't configure sudo correctly to preserve path" unless `ruby -v` == `sudo -E ruby -v` + + sh("sudo -E bin/rspec") + ensure + system("sudo", "cp", "tmp/old_sudoers", "/etc/sudoers") + system("sudo", "chown", "-R", ENV["USER"], "tmp") + end + end task :set_sudo do ENV["BUNDLER_SUDO_TESTS"] = "1" |