]> gitweb.fluxo.info Git - puppet-stdlib.git/commitdiff
(#22214): close content file before executing checkscript
authorsgzijl <sgzijl@gmail.com>
Mon, 9 Sep 2013 14:20:36 +0000 (16:20 +0200)
committerAdrien Thebo <git@somethingsinistral.net>
Thu, 19 Sep 2013 04:32:07 +0000 (21:32 -0700)
Right now validation seems to be done against zero byte generated temp
files. We need to close the file before executing validation against it.

lib/puppet/parser/functions/validate_cmd.rb
spec/unit/puppet/parser/functions/validate_cmd_spec.rb

index 344a80cd3652ad6c03b1f84944ef31baa96e05c1..2ebe91cf78e13c9b5a42d36da65602f16f682d89 100644 (file)
@@ -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
index 69ea7f4960aa00f9acb04430f9029ba44cf46aeb..c0defbc08c048f57eb04ad923d71da8992062f49 100644 (file)
@@ -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