summaryrefslogtreecommitdiffstats
path: root/test
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
parent320ac389de52e67283fbe455a3ec6917bdd3a348 (diff)
+ 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')
-rwxr-xr-xtest/executables/puppetca.rb2
-rwxr-xr-xtest/language/interpreter.rb2
-rw-r--r--test/lib/puppettest/exetest.rb4
-rw-r--r--test/lib/puppettest/support/helpers.rb4
-rwxr-xr-xtest/other/config.rb8
-rwxr-xr-xtest/providers/group.rb2
-rw-r--r--test/providers/package.rb2
-rw-r--r--test/providers/user.rb2
-rwxr-xr-xtest/puppet/defaults.rb2
-rw-r--r--test/puppet/suidmanager.rb71
-rwxr-xr-xtest/types/cron.rb2
-rwxr-xr-xtest/types/exec.rb2
-rw-r--r--test/types/file.rb2
-rwxr-xr-xtest/types/mount.rb2
-rw-r--r--test/types/package.rb2
-rw-r--r--test/types/service.rb2
-rwxr-xr-xtest/types/user.rb2
-rwxr-xr-xtest/types/zone.rb2
-rwxr-xr-xtest/util/utiltest.rb26
19 files changed, 106 insertions, 35 deletions
diff --git a/test/executables/puppetca.rb b/test/executables/puppetca.rb
index a6ea9aae4..d7a6933b4 100755
--- a/test/executables/puppetca.rb
+++ b/test/executables/puppetca.rb
@@ -68,7 +68,7 @@ class TestPuppetCA < Test::Unit::TestCase
uid = Puppet::Util.uid(Puppet[:user])
- if Process.uid == 0
+ if Puppet::SUIDManager.uid == 0
assert(! FileTest.owned?(signedfile), "cert is owned by root")
end
assert_nothing_raised {
diff --git a/test/language/interpreter.rb b/test/language/interpreter.rb
index 37b4e9022..c127ab517 100755
--- a/test/language/interpreter.rb
+++ b/test/language/interpreter.rb
@@ -212,7 +212,7 @@ class TestInterpreter < Test::Unit::TestCase
}
end
- if Process.uid == 0 and Facter["hostname"].value == "culain"
+ if Puppet::SUIDManager.uid == 0 and Facter["hostname"].value == "culain"
def test_ldapreconnect
Puppet[:ldapbase] = "ou=hosts, dc=madstop, dc=com"
Puppet[:ldapnodes] = true
diff --git a/test/lib/puppettest/exetest.rb b/test/lib/puppettest/exetest.rb
index 5f155b47f..94e8ec8c9 100644
--- a/test/lib/puppettest/exetest.rb
+++ b/test/lib/puppettest/exetest.rb
@@ -47,8 +47,8 @@ module PuppetTest::ExeTest
args += " --confdir %s" % Puppet[:confdir]
args += " --vardir %s" % Puppet[:vardir]
args += " --masterport %s" % @@port
- args += " --user %s" % Process.uid
- args += " --group %s" % Process.gid
+ args += " --user %s" % Puppet::SUIDManager.uid
+ args += " --group %s" % Puppet::SUIDManager.gid
args += " --nonodes"
args += " --autosign true"
diff --git a/test/lib/puppettest/support/helpers.rb b/test/lib/puppettest/support/helpers.rb
index 7fae994d9..cbcbcb1f6 100644
--- a/test/lib/puppettest/support/helpers.rb
+++ b/test/lib/puppettest/support/helpers.rb
@@ -3,7 +3,7 @@ require 'puppettest'
module PuppetTest
def nonrootuser
Etc.passwd { |user|
- if user.uid != Process.uid and user.uid > 0
+ if user.uid != Puppet::SUIDManager.uid and user.uid > 0
return user
end
}
@@ -11,7 +11,7 @@ module PuppetTest
def nonrootgroup
Etc.group { |group|
- if group.gid != Process.gid and group.gid > 0
+ if group.gid != Puppet::SUIDManager.gid and group.gid > 0
return group
end
}
diff --git a/test/other/config.rb b/test/other/config.rb
index 3e2c125c7..0afe8979b 100755
--- a/test/other/config.rb
+++ b/test/other/config.rb
@@ -524,7 +524,7 @@ yay = /a/path
user = nonrootuser()
group = nonrootgroup()
- if Process.uid == 0
+ if Puppet::SUIDManager.uid == 0
args[:owner] = user.name
args[:group] = group.name
end
@@ -540,7 +540,7 @@ yay = /a/path
assert_equal(mode, filemode(path), "Modes are not equal")
# OS X is broken in how it chgrps files
- if Process.uid == 0
+ if Puppet::SUIDManager.uid == 0
assert_equal(user.uid, File.stat(path).uid, "UIDS are not equal")
case Facter["operatingsystem"].value
@@ -562,7 +562,7 @@ yay = /a/path
user = nonrootuser()
group = nonrootgroup()
- if Process.uid == 0
+ if Puppet::SUIDManager.uid == 0
args[:owner] = user.name
args[:group] = group.name
end
@@ -577,7 +577,7 @@ yay = /a/path
# OS X and *BSD is broken in how it chgrps files
- if Process.uid == 0
+ if Puppet::SUIDManager.uid == 0
assert_equal(user.uid, File.stat(path).uid, "UIDS are not equal")
case Facter["operatingsystem"].value
diff --git a/test/providers/group.rb b/test/providers/group.rb
index 63aafc1f7..1948dbdc4 100755
--- a/test/providers/group.rb
+++ b/test/providers/group.rb
@@ -173,7 +173,7 @@ class TestGroupProvider < Test::Unit::TestCase
}
end
- if Process.uid == 0
+ if Puppet::SUIDManager.uid == 0
def test_mkgroup
gobj = nil
comp = nil
diff --git a/test/providers/package.rb b/test/providers/package.rb
index 1c3621909..64c443c00 100644
--- a/test/providers/package.rb
+++ b/test/providers/package.rb
@@ -18,7 +18,7 @@ class TestPackageProvider < Test::Unit::TestCase
def test_nothing
end
- if Facter["operatingsystem"].value == "Solaris" and Process.uid == 0
+ if Facter["operatingsystem"].value == "Solaris" and Puppet::SUIDManager.uid == 0
if Puppet.type(:package).provider(:blastwave).suitable?
# FIXME The packaging crap needs to be rewritten to support testing
# multiple package types on the same platform.
diff --git a/test/providers/user.rb b/test/providers/user.rb
index 15fc202f5..1244f6acd 100644
--- a/test/providers/user.rb
+++ b/test/providers/user.rb
@@ -399,7 +399,7 @@ class TestUserProvider < Test::Unit::TestCase
assert_equal(main.sort, list.sort, "Group list is not equal")
end
- if Process.uid == 0
+ if Puppet::SUIDManager.uid == 0
def test_simpleuser
name = "pptest"
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
diff --git a/test/types/cron.rb b/test/types/cron.rb
index b802a1c77..2794ec358 100755
--- a/test/types/cron.rb
+++ b/test/types/cron.rb
@@ -360,7 +360,7 @@ class TestCron < Test::Unit::TestCase
obj = nil
assert_nothing_raised {
- obj = type.new(Process.uid)
+ obj = type.new(Puppet::SUIDManager.uid)
}
txt = nil
diff --git a/test/types/exec.rb b/test/types/exec.rb
index 615dd86cd..c5decb80a 100755
--- a/test/types/exec.rb
+++ b/test/types/exec.rb
@@ -305,7 +305,7 @@ class TestExec < Test::Unit::TestCase
assert_events([:executed_command], comp)
end
- if Process.uid == 0
+ if Puppet::SUIDManager.uid == 0
# Verify that we can execute commands as a special user
def mknverify(file, user, group = nil, id = true)
args = {
diff --git a/test/types/file.rb b/test/types/file.rb
index d2c593c8b..71a04a40d 100644
--- a/test/types/file.rb
+++ b/test/types/file.rb
@@ -103,7 +103,7 @@ class TestFile < Test::Unit::TestCase
}
end
- if Process.uid == 0
+ if Puppet::SUIDManager.uid == 0
def test_createasuser
dir = tmpdir()
diff --git a/test/types/mount.rb b/test/types/mount.rb
index e0838e072..78a5443b2 100755
--- a/test/types/mount.rb
+++ b/test/types/mount.rb
@@ -156,7 +156,7 @@ class TestMounts < Test::Unit::TestCase
assert_events([:mount_changed], fs)
end
- if Process.uid == 0
+ if Puppet::SUIDManager.uid == 0
def test_mountfs
fs = nil
case Facter["hostname"].value
diff --git a/test/types/package.rb b/test/types/package.rb
index 38bb3b08d..e290d12ad 100644
--- a/test/types/package.rb
+++ b/test/types/package.rb
@@ -191,7 +191,7 @@ class TestPackages < Test::Unit::TestCase
end
end
- unless Process.uid == 0
+ unless Puppet::SUIDManager.uid == 0
$stderr.puts "Run as root to perform package installation tests"
else
def test_installpkg
diff --git a/test/types/service.rb b/test/types/service.rb
index f9d6251ad..79ec0c40c 100644
--- a/test/types/service.rb
+++ b/test/types/service.rb
@@ -227,7 +227,7 @@ class TestLocalService < Test::Unit::TestCase
}
end
- unless Process.uid == 0
+ unless Puppet::SUIDManager.uid == 0
puts "run as root to test service start/stop"
else
def test_servicestartstop
diff --git a/test/types/user.rb b/test/types/user.rb
index 703004f57..9a2781308 100755
--- a/test/types/user.rb
+++ b/test/types/user.rb
@@ -64,7 +64,7 @@ class TestUser < Test::Unit::TestCase
user = Puppet.type(:user).create(
:name => name,
:comment => "Puppet Testing User",
- :gid => Process.gid,
+ :gid => Puppet::SUIDManager.gid,
:shell => findshell(),
:home => "/home/%s" % name
)
diff --git a/test/types/zone.rb b/test/types/zone.rb
index 46f411ef3..b0d02d748 100755
--- a/test/types/zone.rb
+++ b/test/types/zone.rb
@@ -186,7 +186,7 @@ end"
"Got incorrect config text")
end
- if Process.uid == 0
+ if Puppet::SUIDManager.uid == 0
# Make sure our ensure process actually works.
def test_ensure_sync
zone = mkzone("ensuretesting")
diff --git a/test/util/utiltest.rb b/test/util/utiltest.rb
index b3a356429..f18f16906 100755
--- a/test/util/utiltest.rb
+++ b/test/util/utiltest.rb
@@ -73,7 +73,7 @@ class TestPuppetUtil < Test::Unit::TestCase
# know them
def test_gidbyunknownid
gid = nil
- group = Process.gid
+ group = Puppet::SUIDManager.gid
assert_nothing_raised {
gid = Puppet::Util.gid(group)
}
@@ -85,7 +85,7 @@ class TestPuppetUtil < Test::Unit::TestCase
def user
require 'etc'
unless defined? @user
- obj = Etc.getpwuid(Process.uid)
+ obj = Etc.getpwuid(Puppet::SUIDManager.uid)
@user = obj.name
end
return @user
@@ -101,7 +101,7 @@ class TestPuppetUtil < Test::Unit::TestCase
}
assert(uid, "Could not retrieve uid for %s" % user)
- assert_equal(Process.uid, uid, "UIDs did not match")
+ assert_equal(Puppet::SUIDManager.uid, uid, "UIDs did not match")
assert(Puppet.type(:user)[user], "Util did not create %s" % user)
end
@@ -127,7 +127,7 @@ class TestPuppetUtil < Test::Unit::TestCase
# know them
def test_uidbyunknownid
uid = nil
- user = Process.uid
+ user = Puppet::SUIDManager.uid
assert_nothing_raised {
uid = Puppet::Util.uid(user)
}
@@ -179,7 +179,7 @@ class TestPuppetUtil < Test::Unit::TestCase
end
end
- unless Process.uid == 0
+ unless Puppet::SUIDManager.uid == 0
$stderr.puts "Run as root to perform Utility tests"
def test_nothing
end
@@ -213,23 +213,23 @@ class TestPuppetUtil < Test::Unit::TestCase
if group
gid = group.gid
else
- gid = Process.gid
+ gid = Puppet::SUIDManager.gid
end
uid = nil
if user
uid = user.uid
else
- uid = Process.uid
+ uid = Puppet::SUIDManager.uid
end
assert_nothing_raised {
- Puppet::Util.asuser(*args) {
- assert_equal(Process.euid, uid, "UID is %s instead of %s" %
- [Process.euid, uid]
+ Puppet::SUIDManager.asuser(*args) {
+ assert_equal(Puppet::SUIDManager.euid, uid, "UID is %s instead of %s" %
+ [Puppet::SUIDManager.euid, uid]
)
- assert_equal(Process.egid, gid, "GID is %s instead of %s" %
- [Process.egid, gid]
+ assert_equal(Puppet::SUIDManager.egid, gid, "GID is %s instead of %s" %
+ [Puppet::SUIDManager.egid, gid]
)
system("touch %s" % file)
}
@@ -284,7 +284,7 @@ class TestPuppetUtil < Test::Unit::TestCase
rescue
end
- assert(Process.euid == 0, "UID did not get reset")
+ assert(Puppet::SUIDManager.euid == 0, "UID did not get reset")
end
end