From a4d29661e978d28c4772db149014ca97d61507b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Wed, 4 Mar 2020 15:49:04 +0100 Subject: Remove unnecessary line --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 1100b8981f..697b7bf2dd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,7 +15,6 @@ before_script: 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 -- cgit v1.2.1 From 7bb2f466e91282335ae18a5290c70562020e2f6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Wed, 4 Mar 2020 15:50:34 +0100 Subject: Fix environment for "sudo specs" Previously, sudo specs were running against system ruby, not against RVM ruby. We need to make sure `sudo` is always configured to preserve the path the `ruby`. This was previously done only for ruby 2.3, but needs to be done everywhere to ensure that the specs run against the correct ruby. Together with this change, I added a bare test to make sure that "sudo specs" run against the correct ruby. --- .travis.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 697b7bf2dd..3ea5cd76a2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,7 @@ language: ruby dist: bionic script: - bin/parallel_rspec spec + - test "$(ruby -v)" = "$(sudo -E ruby -v)" - sudo -E bin/rake spec:sudo - sudo chown -R $(whoami) tmp - BUNDLER_SPEC_PRE_RECORDED=1 bin/rake spec:realworld @@ -13,10 +14,7 @@ before_script: then travis_retry sudo apt-get install graphviz -y; fi - - if [ "$TRAVIS_RUBY_VERSION" = "2.3.8" ]; - then - sudo sed -i '/secure_path/d' /etc/sudoers; - fi + sudo sed -i '/secure_path/d' /etc/sudoers; branches: only: -- cgit v1.2.1 From 512cceea4e5b9f6898523b147810b55de32c82d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Wed, 4 Mar 2020 15:51:53 +0100 Subject: Move sudoers confguration together with sudo specs --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 3ea5cd76a2..5faa930a95 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,7 @@ language: ruby dist: bionic script: - bin/parallel_rspec spec + - sudo sed -i '/secure_path/d' /etc/sudoers - test "$(ruby -v)" = "$(sudo -E ruby -v)" - sudo -E bin/rake spec:sudo - sudo chown -R $(whoami) tmp @@ -14,7 +15,6 @@ before_script: then travis_retry sudo apt-get install graphviz -y; fi - sudo sed -i '/secure_path/d' /etc/sudoers; branches: only: -- cgit v1.2.1 From 02c39dd8eef95941d1dcfe8fc11ab469ba2670b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Wed, 4 Mar 2020 16:50:27 +0100 Subject: Move sudo specs setup to `rake spec:sudo` --- .travis.yml | 5 +---- Rakefile | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5faa930a95..638d19b6e1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,10 +2,7 @@ language: ruby dist: bionic script: - bin/parallel_rspec spec - - sudo sed -i '/secure_path/d' /etc/sudoers - - test "$(ruby -v)" = "$(sudo -E ruby -v)" - - 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: diff --git a/Rakefile b/Rakefile index eac9148c60..814a23492c 100644 --- a/Rakefile +++ b/Rakefile @@ -55,7 +55,20 @@ 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 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` + + begin + sh("sudo -E bin/rspec") + ensure + system("sudo", "chown", "-R", ENV["USER"], "tmp") + end + end task :set_sudo do ENV["BUNDLER_SUDO_TESTS"] = "1" -- cgit v1.2.1 From d36920f40dae8bb0cda7f4c14fc32fe30ea7fe0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Wed, 4 Mar 2020 17:01:37 +0100 Subject: Restore sudo configuration after sudo specs --- Rakefile | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Rakefile b/Rakefile index 814a23492c..4a17296ee7 100644 --- a/Rakefile +++ b/Rakefile @@ -57,15 +57,18 @@ namespace :spec do desc "Run the spec suite with the sudo tests" 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? - output, status = Open3.capture2e("sudo sed -i '/secure_path/d' /etc/sudoers") - raise "Couldn't configure sudo to preserve path: #{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` + raise "Couldn't configure sudo correctly to preserve path" unless `ruby -v` == `sudo -E ruby -v` - begin sh("sudo -E bin/rspec") ensure + system("sudo", "cp", "tmp/old_sudoers", "/etc/sudoers") system("sudo", "chown", "-R", ENV["USER"], "tmp") end end -- cgit v1.2.1