From 3b389790688adb1007b33476ec2e2b6111e26d76 Mon Sep 17 00:00:00 2001 From: kaustubh-d Date: Tue, 19 Aug 2014 15:45:46 +0530 Subject: aix does not allow resetting real uid once the euid is changed to non-root. --- spec/mixlib/shellout_spec.rb | 21 +++++++++++++++++++++ spec/spec_helper.rb | 1 + spec/support/platform_helpers.rb | 5 +++++ 3 files changed, 27 insertions(+) (limited to 'spec') diff --git a/spec/mixlib/shellout_spec.rb b/spec/mixlib/shellout_spec.rb index dca66ae..e009dd8 100644 --- a/spec/mixlib/shellout_spec.rb +++ b/spec/mixlib/shellout_spec.rb @@ -1319,4 +1319,25 @@ describe Mixlib::ShellOut do end end end + + context "when running under *nix", :requires_root, :unix_only do + let(:cmd) { 'whoami' } + let(:running_user) { shell_cmd.run_command.stdout.chomp } + + context "when no user is set" do + it "should run as current user" do + running_user.should eql(ENV["USER"]) + end + end + + context "when user is specified" do + let(:user) { 'nobody' } + + let(:options) { { :user => user } } + + it "should run as specified user" do + running_user.should eql("#{user}") + end + end + end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 9d51c5e..b435176 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -19,6 +19,7 @@ RSpec.configure do |config| # Add jruby filters here config.filter_run_excluding :windows_only => true unless windows? config.filter_run_excluding :unix_only => true unless unix? + config.filter_run_excluding :requires_root => true unless root? config.run_all_when_everything_filtered = true config.treat_symbols_as_metadata_keys_with_true_values = true diff --git a/spec/support/platform_helpers.rb b/spec/support/platform_helpers.rb index 69bdbf7..c730b4d 100644 --- a/spec/support/platform_helpers.rb +++ b/spec/support/platform_helpers.rb @@ -24,3 +24,8 @@ else LINE_ENDING = "\n" ECHO_LC_ALL = "echo $LC_ALL" end + +def root? + return false if windows? + Process.euid == 0 +end -- cgit v1.2.1