[Pkg-puppet-devel] [facter] 43/352: (#9546) Do not execute com, cmd, exe, or bat files if not on windows

Stig Sandbeck Mathisen ssm at debian.org
Sun Apr 6 22:21:30 UTC 2014


This is an automated email from the git hooks/post-receive script.

ssm pushed a commit to branch master
in repository facter.

commit 20a2de6e5a158f185e26b6ed6797de781ee874d6
Author: John Julien <john at julienfamily.com>
Date:   Tue Oct 15 22:23:15 2013 -0500

    (#9546) Do not execute com, cmd, exe, or bat files if not on windows
    
    Facter currently only executes com, exe, and bat files if on a windows
    system.  It should also exclude these on unix flavored systems since
    the interpreter for these "cmd.exe" will not be present.
    
    This also supports the use of pluginsync for external facts where in a
    hybrid environment external facts for windows may end up getting syncd
    to a unix system.
---
 lib/facter/util/parser.rb     |  2 +-
 spec/unit/util/parser_spec.rb | 22 ++++++++++++++++++++++
 2 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/lib/facter/util/parser.rb b/lib/facter/util/parser.rb
index 4596c8f..1b46908 100644
--- a/lib/facter/util/parser.rb
+++ b/lib/facter/util/parser.rb
@@ -125,7 +125,7 @@ module Facter::Util::Parser
     if Facter::Util::Config.is_windows?
       extension_matches?(filename, %w{bat cmd com exe}) && File.file?(filename)
     else
-      File.executable?(filename) && File.file?(filename)
+      File.executable?(filename) && File.file?(filename) && ! extension_matches?(filename, %w{bat cmd com exe})
     end
   end
 
diff --git a/spec/unit/util/parser_spec.rb b/spec/unit/util/parser_spec.rb
index 00bba5d..11e55c1 100644
--- a/spec/unit/util/parser_spec.rb
+++ b/spec/unit/util/parser_spec.rb
@@ -130,6 +130,28 @@ describe Facter::Util::Parser do
         parser.results.should == data
       end
     end
+
+    context "exe, bat, cmd, and com files" do
+      let :cmds do ["/tmp/foo.bat", "/tmp/foo.cmd", "/tmp/foo.exe", "/tmp/foo.com"] end
+
+      before :each do
+        cmds.each {|cmd|
+          File.stubs(:executable?).with(cmd).returns(true)
+          File.stubs(:file?).with(cmd).returns(true)
+        }
+      end
+
+      it "should return nothing parser if not on windows" do
+        Facter::Util::Config.stubs(:is_windows?).returns(false)
+        cmds.each {|cmd| Facter::Util::Parser.parser_for(cmd).should be_an_instance_of(Facter::Util::Parser::NothingParser) }
+      end
+
+      it "should return script  parser if on windows" do
+        Facter::Util::Config.stubs(:is_windows?).returns(true)
+        cmds.each {|cmd| Facter::Util::Parser.parser_for(cmd).should be_an_instance_of(Facter::Util::Parser::ScriptParser) }
+      end
+
+     end
   end
 
   describe "powershell parser" do

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-puppet/facter.git



More information about the Pkg-puppet-devel mailing list