summaryrefslogtreecommitdiffstats
path: root/spec/unit/util/suidmanager_spec.rb
diff options
context:
space:
mode:
authorNick Lewis <nick@puppetlabs.com>2011-08-22 17:06:44 -0700
committerNick Lewis <nick@puppetlabs.com>2011-08-22 17:06:44 -0700
commit630ec36089e2224fba99b76d76eaf904af13e4d6 (patch)
treea04dff02eb8f296f7a56952cade0621848280288 /spec/unit/util/suidmanager_spec.rb
parent4684db12b1ca27df4d612fb1a54b7be43f54a6a8 (diff)
parent0f207a8ea61205ba6b47e8da429ab3887b3cda4d (diff)
downloadpuppet-630ec36089e2224fba99b76d76eaf904af13e4d6.tar.gz
puppet-630ec36089e2224fba99b76d76eaf904af13e4d6.tar.xz
puppet-630ec36089e2224fba99b76d76eaf904af13e4d6.zip
Merge pull request #53 from joshcooper/ticket/2.7.x/8662-root-on-windows
Ticket/2.7.x/8662 root on windows
Diffstat (limited to 'spec/unit/util/suidmanager_spec.rb')
-rwxr-xr-xspec/unit/util/suidmanager_spec.rb89
1 files changed, 89 insertions, 0 deletions
diff --git a/spec/unit/util/suidmanager_spec.rb b/spec/unit/util/suidmanager_spec.rb
index abfe3f723..474d0b2a2 100755
--- a/spec/unit/util/suidmanager_spec.rb
+++ b/spec/unit/util/suidmanager_spec.rb
@@ -66,6 +66,14 @@ describe Puppet::Util::SUIDManager do
xids.should be_empty
end
+
+ it "should not get or set euid/egid on Windows" do
+ Puppet.features.stubs(:microsoft_windows?).returns true
+
+ Puppet::Util::SUIDManager.asuser(user[:uid], user[:gid]) {}
+
+ xids.should be_empty
+ end
end
describe "#change_group" do
@@ -195,6 +203,15 @@ describe Puppet::Util::SUIDManager do
xids.should be_empty
end
+
+ it "should not get or set euid/egid on Windows" do
+ Puppet.features.stubs(:microsoft_windows?).returns true
+ Kernel.expects(:system).with('blah')
+
+ Puppet::Util::SUIDManager.system('blah', user[:uid], user[:gid])
+
+ xids.should be_empty
+ end
end
describe "with #run_and_capture" do
@@ -210,4 +227,76 @@ describe Puppet::Util::SUIDManager do
end
end
end
+
+ describe "#root?" do
+ describe "on POSIX systems" do
+ before :each do
+ Puppet.features.stubs(:posix?).returns(true)
+ Puppet.features.stubs(:microsoft_windows?).returns(false)
+ end
+
+ it "should be root if uid is 0" do
+ Process.stubs(:uid).returns(0)
+
+ Puppet::Util::SUIDManager.should be_root
+ end
+
+ it "should not be root if uid is not 0" do
+ Process.stubs(:uid).returns(1)
+
+ Puppet::Util::SUIDManager.should_not be_root
+ end
+ end
+
+ describe "on Microsoft Windows", :if => Puppet.features.microsoft_windows? do
+ describe "2003 without UAC" do
+ it "should be root if user is a member of the Administrators group" do
+ Win32::Security.stubs(:elevated_security?).raises(Win32::Security::Error, "Incorrect function.")
+ Sys::Admin.stubs(:get_login).returns("Administrator")
+ Sys::Group.stubs(:members).returns(%w[Administrator])
+
+ Puppet::Util::SUIDManager.should be_root
+ end
+
+ it "should not be root if the process is running as Guest" do
+ Win32::Security.stubs(:elevated_security?).raises(Win32::Security::Error, "Incorrect function.")
+ Sys::Admin.stubs(:get_login).returns("Guest")
+ Sys::Group.stubs(:members).returns([])
+
+ Puppet::Util::SUIDManager.should_not be_root
+ end
+
+ it "should raise an exception if the process fails to open the process token" do
+ Win32::Security.stubs(:elevated_security?).raises(Win32::Security::Error, "Access denied.")
+ Sys::Admin.stubs(:get_login).returns("Administrator")
+ Sys::Group.expects(:members).never
+
+ lambda { Puppet::Util::SUIDManager.should raise_error(Win32::Security::Error, /Access denied./) }
+ end
+ end
+
+ describe "2008 with UAC" do
+ it "should be root if user is running with elevated privileges" do
+ Win32::Security.stubs(:elevated_security?).returns(true)
+ Sys::Admin.expects(:get_login).never
+
+ Puppet::Util::SUIDManager.should be_root
+ end
+
+ it "should not be root if user is not running with elevated privileges" do
+ Win32::Security.stubs(:elevated_security?).returns(false)
+ Sys::Admin.expects(:get_login).never
+
+ Puppet::Util::SUIDManager.should_not be_root
+ end
+
+ it "should raise an exception if the process fails to open the process token" do
+ Win32::Security.stubs(:elevated_security?).raises(Win32::Security::Error, "Access denied.")
+ Sys::Admin.expects(:get_login).never
+
+ lambda { Puppet::Util::SUIDManager.should raise_error(Win32::Security::Error, /Access denied./) }
+ end
+ end
+ end
+ end
end