summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsgzijl <sgzijl@gmail.com>2013-09-09 16:20:36 +0200
committerAdrien Thebo <git@somethingsinistral.net>2013-09-18 21:32:07 -0700
commit9e0d8a8e0a83e1659fdb289078fd15862dca028b (patch)
tree6799c4402adcad6c9fdd0be56a70a1d9a8624003
parent806430224ad0da860be3761ab83f1e574b64fc60 (diff)
downloadpuppet-stdlib-9e0d8a8e0a83e1659fdb289078fd15862dca028b.tar.gz
puppet-stdlib-9e0d8a8e0a83e1659fdb289078fd15862dca028b.tar.bz2
(#22214): close content file before executing checkscript
Right now validation seems to be done against zero byte generated temp files. We need to close the file before executing validation against it.
-rw-r--r--lib/puppet/parser/functions/validate_cmd.rb1
-rw-r--r--spec/unit/puppet/parser/functions/validate_cmd_spec.rb8
2 files changed, 9 insertions, 0 deletions
diff --git a/lib/puppet/parser/functions/validate_cmd.rb b/lib/puppet/parser/functions/validate_cmd.rb
index 344a80c..2ebe91c 100644
--- a/lib/puppet/parser/functions/validate_cmd.rb
+++ b/lib/puppet/parser/functions/validate_cmd.rb
@@ -32,6 +32,7 @@ module Puppet::Parser::Functions
tmpfile = Tempfile.new("validate_cmd")
begin
tmpfile.write(content)
+ tmpfile.close
if Puppet::Util::Execution.respond_to?('execute')
Puppet::Util::Execution.execute("#{checkscript} #{tmpfile.path}")
else
diff --git a/spec/unit/puppet/parser/functions/validate_cmd_spec.rb b/spec/unit/puppet/parser/functions/validate_cmd_spec.rb
index 69ea7f4..c0defbc 100644
--- a/spec/unit/puppet/parser/functions/validate_cmd_spec.rb
+++ b/spec/unit/puppet/parser/functions/validate_cmd_spec.rb
@@ -78,4 +78,12 @@ describe Puppet::Parser::Functions.function(:validate_cmd) do
end
end
end
+
+ it "can positively validate file content" do
+ expect { subject.call ["non-empty", "/usr/bin/test -s"] }.to_not raise_error
+ end
+
+ it "can negatively validate file content" do
+ expect { subject.call ["", "/usr/bin/test -s"] }.to raise_error Puppet::ParseError, /failed to validate.*test -s/
+ end
end