summaryrefslogtreecommitdiffstats
path: root/test/util
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-12-19 22:42:39 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-12-19 22:42:39 +0000
commit36e8d65bbdf236203741d3a3b0d98a1eb51a75a9 (patch)
treef636bea92fe2fcc101b6541f1f84524c742a00ba /test/util
parent115ec095357171381e2af3aa5ebbd61164b40064 (diff)
downloadpuppet-36e8d65bbdf236203741d3a3b0d98a1eb51a75a9.tar.gz
puppet-36e8d65bbdf236203741d3a3b0d98a1eb51a75a9.tar.xz
puppet-36e8d65bbdf236203741d3a3b0d98a1eb51a75a9.zip
Fixing #372 and #374. All is not perfect, since OS X still cannot set UID, but it is much better. There is still plenty of bug-fixing to do on other platforms, I expect.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1954 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'test/util')
-rwxr-xr-xtest/util/utiltest.rb46
1 files changed, 46 insertions, 0 deletions
diff --git a/test/util/utiltest.rb b/test/util/utiltest.rb
index ffb2ef347..74a29d56f 100755
--- a/test/util/utiltest.rb
+++ b/test/util/utiltest.rb
@@ -261,6 +261,52 @@ class TestPuppetUtil < Test::Unit::TestCase
assert_equal(nil, ret)
end
+
+ def test_execute
+ command = tempfile()
+ File.open(command, "w") { |f|
+ f.puts %{#!/bin/sh\n/bin/echo "$1">&1; echo "$2">&2}
+ }
+ File.chmod(0755, command)
+ output = nil
+ assert_nothing_raised do
+ output = Puppet::Util.execute([command, "yaytest", "funtest"])
+ end
+ assert_equal("yaytest\nfuntest\n", output)
+
+ # Now try it with a single quote
+ assert_nothing_raised do
+ output = Puppet::Util.execute([command, "yay'test", "funtest"])
+ # output = Puppet::Util.execute(command)
+
+ end
+ assert_equal("yay'test\nfuntest\n", output)
+
+ # Now test that we correctly fail if the command returns non-zero
+ assert_raise(Puppet::ExecutionFailure) do
+ out = Puppet::Util.execute(["touch", "/no/such/file/could/exist"])
+ end
+
+ # And that we can tell it not to fail
+ assert_nothing_raised() do
+ out = Puppet::Util.execute(["touch", "/no/such/file/could/exist"], false)
+ end
+
+ if Process.uid == 0
+ # Make sure we correctly set our uid and gid
+ user = nonrootuser
+ group = nonrootgroup
+ file = tempfile()
+ assert_nothing_raised do
+ Puppet::Util.execute(["touch", file], true, user.name, group.name)
+ end
+ assert(FileTest.exists?(file), "file was not created")
+ assert_equal(user.uid, File.stat(file).uid, "uid was not set correctly")
+
+ # We can't really check the gid, because it just behaves too inconsistently everywhere.
+ # assert_equal(group.gid, File.stat(file).gid, "gid was not set correctly")
+ end
+ end
end
# $Id$