test/util/utiltest.rb in puppet-0.23.2 vs test/util/utiltest.rb in puppet-0.24.0

- old
+ new

@@ -1,8 +1,8 @@ #!/usr/bin/env ruby -$:.unshift("../lib").unshift("../../lib") if __FILE__ =~ /\.rb$/ +require File.dirname(__FILE__) + '/../lib/puppettest' require 'puppettest' require 'mocha' class TestPuppetUtil < Test::Unit::TestCase @@ -82,119 +82,10 @@ assert_equal(str, val) end end - unless Puppet::Util::SUIDManager.uid == 0 - $stderr.puts "Run as root to perform Utility tests" - def test_nothing - end - else - - def mknverify(file, user, group = nil, id = false) - if File.exists?(file) - File.unlink(file) - end - args = [] - unless user or group - args << nil - end - if user - if id - args << user.uid - else - args << user.name - end - end - - if group - if id - args << group.gid - else - args << group.name - end - end - - gid = nil - if group - gid = group.gid - else - gid = Puppet::Util::SUIDManager.gid - end - - uid = nil - if user - uid = user.uid - else - uid = Puppet::Util::SUIDManager.uid - end - - assert_nothing_raised { - Puppet::Util::SUIDManager.asuser(*args) { - assert_equal(Puppet::Util::SUIDManager.euid, uid, "UID is %s instead of %s" % - [Puppet::Util::SUIDManager.euid, uid] - ) - assert_equal(Puppet::Util::SUIDManager.egid, gid, "GID is %s instead of %s" % - [Puppet::Util::SUIDManager.egid, gid] - ) - system("touch %s" % file) - } - } - if uid == 0 - #Puppet.warning "Not testing user" - else - #Puppet.warning "Testing user %s" % uid - assert(File.exists?(file), "File does not exist") - assert_equal(File.stat(file).uid, uid, - "File is owned by %s instead of %s" % - [File.stat(file).uid, uid] - ) - #system("ls -l %s" % file) - end - # I'm skipping these, because it seems so system dependent. - #if gid == 0 - # #Puppet.warning "Not testing group" - #else - # Puppet.warning "Testing group %s" % gid.inspect - # system("ls -l %s" % file) - # assert_equal(gid, File.stat(file).gid, - # "File group is %s instead of %s" % - # [File.stat(file).gid, gid] - # ) - #end - assert_nothing_raised { - File.unlink(file) - } - end - - def test_asuser - file = File.join(tmpdir, "asusertest") - @@tmpfiles << file - [ - [nil], # Nothing - [nonrootuser()], # just user, by name - [nonrootuser(), nil, true], # user, by uid - [nonrootuser(), nonrootgroup()], # user and group, by name - [nonrootuser(), nonrootgroup(), true], # user and group, by id - ].each { |ary| - mknverify(file, *ary) - } - end - - # Verify that we get reset back to the right user - def test_asuser_recovery - begin - Puppet::Util.asuser(nonrootuser()) { - raise "an error" - } - rescue - end - - assert(Puppet::Util::SUIDManager.euid == 0, "UID did not get reset") - end - end - def test_proxy klass = Class.new do attr_accessor :hash class << self attr_accessor :ohash @@ -392,6 +283,5 @@ end assert_equal(0, val, "got invalid uid for root") end end -# $Id: utiltest.rb 2604 2007-06-18 18:09:22Z luke $