diff options
author | Nick Lewis <nick@puppetlabs.com> | 2011-08-24 15:42:03 -0700 |
---|---|---|
committer | Nick Lewis <nick@puppetlabs.com> | 2011-08-24 15:42:03 -0700 |
commit | da4a2def42639817c4522fc0162bd691956998da (patch) | |
tree | 3cb423a7d2a7a803a922b710c661d675d11bf131 /spec/unit/util | |
parent | 0d51dc9be0bc1c785d749b8b352a1e43b1b6e9c6 (diff) | |
parent | 630ec36089e2224fba99b76d76eaf904af13e4d6 (diff) | |
download | puppet-da4a2def42639817c4522fc0162bd691956998da.tar.gz puppet-da4a2def42639817c4522fc0162bd691956998da.tar.xz puppet-da4a2def42639817c4522fc0162bd691956998da.zip |
Merge branch '2.7.x'
Conflicts:
lib/puppet/feature/base.rb
lib/puppet/file_serving/configuration.rb
spec/unit/indirector/ssl_file_spec.rb
spec/unit/parser/functions/extlookup_spec.rb
spec/unit/resource/catalog_spec.rb
test/language/ast/variable.rb
Diffstat (limited to 'spec/unit/util')
-rwxr-xr-x | spec/unit/util/checksums_spec.rb | 4 | ||||
-rwxr-xr-x | spec/unit/util/constant_inflector_spec.rb | 4 | ||||
-rwxr-xr-x | spec/unit/util/ldap/connection_spec.rb | 4 | ||||
-rwxr-xr-x | spec/unit/util/ldap/generator_spec.rb | 4 | ||||
-rwxr-xr-x | spec/unit/util/ldap/manager_spec.rb | 4 | ||||
-rwxr-xr-x | spec/unit/util/nagios_maker_spec.rb | 4 | ||||
-rwxr-xr-x | spec/unit/util/settings/file_setting_spec.rb | 22 | ||||
-rwxr-xr-x | spec/unit/util/settings_spec.rb | 19 | ||||
-rwxr-xr-x | spec/unit/util/suidmanager_spec.rb | 89 | ||||
-rwxr-xr-x | spec/unit/util/tagging_spec.rb | 4 |
10 files changed, 130 insertions, 28 deletions
diff --git a/spec/unit/util/checksums_spec.rb b/spec/unit/util/checksums_spec.rb index 146544201..f8800b512 100755 --- a/spec/unit/util/checksums_spec.rb +++ b/spec/unit/util/checksums_spec.rb @@ -1,8 +1,4 @@ #!/usr/bin/env rspec -# -# Created by Luke Kanies on 2007-9-22. -# Copyright (c) 2007. All rights reserved. - require 'spec_helper' require 'puppet/util/checksums' diff --git a/spec/unit/util/constant_inflector_spec.rb b/spec/unit/util/constant_inflector_spec.rb index cf2e8f892..88c1d9aa3 100755 --- a/spec/unit/util/constant_inflector_spec.rb +++ b/spec/unit/util/constant_inflector_spec.rb @@ -1,8 +1,4 @@ #!/usr/bin/env rspec -# -# Created by Luke Kanies on 2008-02-12. -# Copyright (c) 2007. All rights reserved. - require 'spec_helper' require 'puppet/util/constant_inflector' diff --git a/spec/unit/util/ldap/connection_spec.rb b/spec/unit/util/ldap/connection_spec.rb index f97c72d77..f02ea10cb 100755 --- a/spec/unit/util/ldap/connection_spec.rb +++ b/spec/unit/util/ldap/connection_spec.rb @@ -1,8 +1,4 @@ #!/usr/bin/env rspec -# -# Created by Luke Kanies on 2008-3-19. -# Copyright (c) 2006. All rights reserved. - require 'spec_helper' require 'puppet/util/ldap/connection' diff --git a/spec/unit/util/ldap/generator_spec.rb b/spec/unit/util/ldap/generator_spec.rb index b3e664d6b..51285e233 100755 --- a/spec/unit/util/ldap/generator_spec.rb +++ b/spec/unit/util/ldap/generator_spec.rb @@ -1,8 +1,4 @@ #!/usr/bin/env rspec -# -# Created by Luke Kanies on 2008-3-28. -# Copyright (c) 2008. All rights reserved. - require 'spec_helper' require 'puppet/util/ldap/generator' diff --git a/spec/unit/util/ldap/manager_spec.rb b/spec/unit/util/ldap/manager_spec.rb index 5cce626b5..16c6b0601 100755 --- a/spec/unit/util/ldap/manager_spec.rb +++ b/spec/unit/util/ldap/manager_spec.rb @@ -1,8 +1,4 @@ #!/usr/bin/env rspec -# -# Created by Luke Kanies on 2008-3-19. -# Copyright (c) 2006. All rights reserved. - require 'spec_helper' require 'puppet/util/ldap/manager' diff --git a/spec/unit/util/nagios_maker_spec.rb b/spec/unit/util/nagios_maker_spec.rb index b61f4fe9d..9cd038ff3 100755 --- a/spec/unit/util/nagios_maker_spec.rb +++ b/spec/unit/util/nagios_maker_spec.rb @@ -1,8 +1,4 @@ #!/usr/bin/env rspec -# -# Created by Luke Kanies on 2007-11-18. -# Copyright (c) 2007. All rights reserved. - require 'spec_helper' require 'puppet/util/nagios_maker' diff --git a/spec/unit/util/settings/file_setting_spec.rb b/spec/unit/util/settings/file_setting_spec.rb index 01d891f08..6344cf1b5 100755 --- a/spec/unit/util/settings/file_setting_spec.rb +++ b/spec/unit/util/settings/file_setting_spec.rb @@ -189,6 +189,8 @@ describe Puppet::Util::Settings::FileSetting do it "should set the owner if running as root and the owner is provided" do Puppet.features.expects(:root?).returns true + Puppet.features.stubs(:microsoft_windows?).returns false + @file.stubs(:owner).returns "foo" @file.to_resource[:owner].should == "foo" end @@ -203,6 +205,8 @@ describe Puppet::Util::Settings::FileSetting do it "should set the group if running as root and the group is provided" do Puppet.features.expects(:root?).returns true + Puppet.features.stubs(:microsoft_windows?).returns false + @file.stubs(:group).returns "foo" @file.to_resource[:group].should == "foo" end @@ -218,16 +222,34 @@ describe Puppet::Util::Settings::FileSetting do it "should not set owner if not running as root" do Puppet.features.expects(:root?).returns false + Puppet.features.stubs(:microsoft_windows?).returns false @file.stubs(:owner).returns "foo" @file.to_resource[:owner].should be_nil end it "should not set group if not running as root" do Puppet.features.expects(:root?).returns false + Puppet.features.stubs(:microsoft_windows?).returns false @file.stubs(:group).returns "foo" @file.to_resource[:group].should be_nil end + describe "on Microsoft Windows systems" do + before :each do + Puppet.features.stubs(:microsoft_windows?).returns true + end + + it "should not set owner" do + @file.stubs(:owner).returns "foo" + @file.to_resource[:owner].should be_nil + end + + it "should not set group" do + @file.stubs(:group).returns "foo" + @file.to_resource[:group].should be_nil + end + end + it "should set :ensure to the file type" do @file.expects(:type).returns :directory @file.to_resource[:ensure].should == :directory diff --git a/spec/unit/util/settings_spec.rb b/spec/unit/util/settings_spec.rb index 76f229c0f..69c117f28 100755 --- a/spec/unit/util/settings_spec.rb +++ b/spec/unit/util/settings_spec.rb @@ -720,9 +720,28 @@ describe Puppet::Util::Settings do @settings.to_catalog end + describe "on Microsoft Windows" do + before :each do + Puppet.features.stubs(:root?).returns true + Puppet.features.stubs(:microsoft_windows?).returns true + + @settings.setdefaults :foo, :mkusers => [true, "e"], :user => ["suser", "doc"], :group => ["sgroup", "doc"] + @settings.setdefaults :other, :otherdir => {:default => "/otherdir", :desc => "a", :owner => "service", :group => "service"} + + @catalog = @settings.to_catalog + end + + it "it should not add users and groups to the catalog" do + @catalog.resource(:user, "suser").should be_nil + @catalog.resource(:group, "sgroup").should be_nil + end + end + describe "when adding users and groups to the catalog" do before do Puppet.features.stubs(:root?).returns true + Puppet.features.stubs(:microsoft_windows?).returns false + @settings.setdefaults :foo, :mkusers => [true, "e"], :user => ["suser", "doc"], :group => ["sgroup", "doc"] @settings.setdefaults :other, :otherdir => {:default => "/otherdir", :desc => "a", :owner => "service", :group => "service"} 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 diff --git a/spec/unit/util/tagging_spec.rb b/spec/unit/util/tagging_spec.rb index 018871bef..1e5abdadd 100755 --- a/spec/unit/util/tagging_spec.rb +++ b/spec/unit/util/tagging_spec.rb @@ -1,8 +1,4 @@ #!/usr/bin/env rspec -# -# Created by Luke Kanies on 2008-01-19. -# Copyright (c) 2007. All rights reserved. - require 'spec_helper' require 'puppet/util/tagging' |