(#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.
This commit is contained in:
sgzijl 2013-09-09 16:20:36 +02:00 committed by Adrien Thebo
parent 806430224a
commit 9e0d8a8e0a
2 changed files with 9 additions and 0 deletions

View file

@ -32,6 +32,7 @@ module Puppet::Parser::Functions
tmpfile = Tempfile.new("validate_cmd") tmpfile = Tempfile.new("validate_cmd")
begin begin
tmpfile.write(content) tmpfile.write(content)
tmpfile.close
if Puppet::Util::Execution.respond_to?('execute') if Puppet::Util::Execution.respond_to?('execute')
Puppet::Util::Execution.execute("#{checkscript} #{tmpfile.path}") Puppet::Util::Execution.execute("#{checkscript} #{tmpfile.path}")
else else

View file

@ -78,4 +78,12 @@ describe Puppet::Parser::Functions.function(:validate_cmd) do
end end
end 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 end