summaryrefslogtreecommitdiffstats
path: root/test/puppet
diff options
context:
space:
mode:
authorerikh <erikh@980ebf18-57e1-0310-9a29-db15c13687c0>2006-09-22 17:19:02 +0000
committererikh <erikh@980ebf18-57e1-0310-9a29-db15c13687c0>2006-09-22 17:19:02 +0000
commit6f11dee740e6e9ebc5fffed779212d24584ce6c4 (patch)
tree75f266040521abfc23df7e458e8fea8bd4748d2e /test/puppet
parent320ac389de52e67283fbe455a3ec6917bdd3a348 (diff)
downloadpuppet-6f11dee740e6e9ebc5fffed779212d24584ce6c4.tar.gz
puppet-6f11dee740e6e9ebc5fffed779212d24584ce6c4.tar.xz
puppet-6f11dee740e6e9ebc5fffed779212d24584ce6c4.zip
+ Puppet::SUIDManager - This replaces all calls to the built-in ruby 'Process' library for uid/gid/euid/egid operations, including (not surprisingly) Puppet::Util#asuser and a method to run commands and capture output. This is due to many inconsistencies (through bugfixes) between ruby versions in the 1.8.x branch. This is included in the core puppet library and can be used by all puppet types and providers.
! Modified Puppet::Util#uid to check (and warn) if passed a nil value. ! Changes to use Puppet::SUIDManager instead of Process and relevant Puppet::Util calls. ! Removed Puppet::Util#asuser. git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1666 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'test/puppet')
-rwxr-xr-xtest/puppet/defaults.rb2
-rw-r--r--test/puppet/suidmanager.rb71
2 files changed, 72 insertions, 1 deletions
diff --git a/test/puppet/defaults.rb b/test/puppet/defaults.rb
index 46accc9c6..250fd29c0 100755
--- a/test/puppet/defaults.rb
+++ b/test/puppet/defaults.rb
@@ -63,7 +63,7 @@ class TestPuppetDefaults < Test::Unit::TestCase
# we don't want user defaults in /, or root defaults in ~
def testDefaultsInCorrectRoots
notval = nil
- if Process.uid == 0
+ if Puppet::SUIDManager.uid == 0
notval = Regexp.new(File.expand_path("~"))
else
notval = /^\/var|^\/etc/
diff --git a/test/puppet/suidmanager.rb b/test/puppet/suidmanager.rb
new file mode 100644
index 000000000..f5cb8496e
--- /dev/null
+++ b/test/puppet/suidmanager.rb
@@ -0,0 +1,71 @@
+require 'test/unit'
+require 'puppettest'
+
+class TestProcess < Test::Unit::TestCase
+ def setup
+ if Process.uid != 0
+ $stderr.puts "Process tests must be run as root"
+ @run = false
+ else
+ @run = true
+ end
+ end
+
+ def test_id_set
+ if @run
+ # FIXME: use the test framework uid finder
+ assert_nothing_raised do
+ Puppet::SUIDManager.egid = 501
+ Puppet::SUIDManager.euid = 501
+ end
+
+ assert_equal(Puppet::SUIDManager.euid, Process.euid)
+ assert_equal(Puppet::SUIDManager.egid, Process.egid)
+
+ assert_nothing_raised do
+ Puppet::SUIDManager.euid = 0
+ Puppet::SUIDManager.egid = 0
+ end
+
+ assert_uid_gid(501, 501)
+ end
+ end
+
+ def test_asuser
+ if @run
+ uid, gid = [nil, nil]
+
+ assert_nothing_raised do
+ Puppet::SUIDManager.asuser(501, 501) do
+ uid = Puppet::SUIDManager.euid
+ gid = Puppet::SUIDManager.egid
+ end
+ end
+
+ assert_equal(501, uid)
+ assert_equal(501, gid)
+ end
+ end
+
+ def test_system
+ # NOTE: not sure what shells this will work on..
+ # FIXME: use the test framework uid finder, however the uid needs to be < 255
+ if @run
+ Puppet::SUIDManager.system("exit $EUID", 10, 10)
+ assert_equal($?.exitstatus, 10)
+ end
+ end
+
+ def test_run_and_capture
+ if (RUBY_VERSION <=> "1.8.4") < 0
+ warn "Cannot run this test on ruby < 1.8.4"
+ else
+ # NOTE: because of the way that run_and_capture currently
+ # works, we cannot just blindly echo to stderr. This little
+ # hack gets around our problem, but the real problem is the
+ # way that run_and_capture works.
+ output = Puppet::SUIDManager.run_and_capture("ruby -e '$stderr.puts \"foo\"'")[0].chomp
+ assert_equal(output, 'foo')
+ end
+ end
+end