summaryrefslogtreecommitdiffstats
path: root/test/puppet/tc_suidmanager.rb
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2007-11-27 18:35:25 -0600
committerLuke Kanies <luke@madstop.com>2007-11-27 18:35:25 -0600
commit168fa5f912b0b15dbd3773a23649093e69e3d185 (patch)
treee14924005141a6af6a23135d2be6403f938ffa7c /test/puppet/tc_suidmanager.rb
parent30547c93050a958b289fe1c85b76bb2dc5ae4048 (diff)
downloadpuppet-168fa5f912b0b15dbd3773a23649093e69e3d185.tar.gz
puppet-168fa5f912b0b15dbd3773a23649093e69e3d185.tar.xz
puppet-168fa5f912b0b15dbd3773a23649093e69e3d185.zip
Fixing the asuser method in Puppet::Util::SUIDManager
so that it correctly just yields if you're not root. It also no longer tries to set :uid or :gid; just :euid and :egid, and it once again sets :egid before it sets :euid, which is important because you usually can't change your group after you've changed your user id.
Diffstat (limited to 'test/puppet/tc_suidmanager.rb')
-rwxr-xr-xtest/puppet/tc_suidmanager.rb36
1 files changed, 27 insertions, 9 deletions
diff --git a/test/puppet/tc_suidmanager.rb b/test/puppet/tc_suidmanager.rb
index 2e44ead6f..08d957cc0 100755
--- a/test/puppet/tc_suidmanager.rb
+++ b/test/puppet/tc_suidmanager.rb
@@ -42,19 +42,35 @@ class TestSUIDManager < Test::Unit::TestCase
assert_not_equal(nil, Puppet::Util.uid(@user.name))
end
- def test_asuser
+ def test_asuser_as_root
+ Process.stubs(:uid).returns(0)
expects_id_set_and_revert @user.uid, @user.gid
Puppet::Util::SUIDManager.asuser @user.uid, @user.gid do end
end
+ def test_asuser_as_nonroot
+ Process.stubs(:uid).returns(1)
+ expects_no_id_set
+ Puppet::Util::SUIDManager.asuser @user.uid, @user.gid do end
+ end
+
- def test_system
+ def test_system_as_root
+ Process.stubs(:uid).returns(0)
set_exit_status!
expects_id_set_and_revert @user.uid, @user.gid
Kernel.expects(:system).with('blah')
Puppet::Util::SUIDManager.system('blah', @user.uid, @user.gid)
end
+ def test_system_as_nonroot
+ Process.stubs(:uid).returns(1)
+ set_exit_status!
+ expects_no_id_set
+ Kernel.expects(:system).with('blah')
+ Puppet::Util::SUIDManager.system('blah', @user.uid, @user.gid)
+ end
+
def test_run_and_capture
if (RUBY_VERSION <=> "1.8.4") < 0
warn "Cannot run this test on ruby < 1.8.4"
@@ -78,23 +94,25 @@ class TestSUIDManager < Test::Unit::TestCase
end
private
- def expects_id_set_and_revert uid, gid
- Process.expects(:uid).returns(99999)
- Process.expects(:gid).returns(99998)
+
+ def expects_id_set_and_revert(uid, gid)
Process.expects(:euid).returns(99997)
Process.expects(:egid).returns(99996)
- Process.expects(:uid=).with(uid)
- Process.expects(:gid=).with(gid)
Process.expects(:euid=).with(uid)
Process.expects(:egid=).with(gid)
- Process.expects(:uid=).with(99999)
- Process.expects(:gid=).with(99998)
Process.expects(:euid=).with(99997)
Process.expects(:egid=).with(99996)
end
+ def expects_no_id_set
+ Process.expects(:egid).never
+ Process.expects(:euid).never
+ Process.expects(:egid=).never
+ Process.expects(:euid=).never
+ end
+
def set_exit_status!
# We want to make sure $? is set, this is the only way I know how.
Kernel.system '' if $?.nil?