From cd078034cbd1888e5f3a29d36c1c766b141142f0 Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Wed, 26 Jun 2013 21:45:35 -0500 Subject: [PATCH 1/4] set require 'mocha' to 'mocha/api' to get fix deprecated messages --- spec/spec_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index a3b13bbe..88b3c537 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,10 +1,10 @@ dir = File.expand_path(File.dirname(__FILE__)) $LOAD_PATH.unshift File.join(dir, 'lib') -require 'mocha' require 'puppet' require 'rspec' #require 'spec/autorun' +require 'mocha/api' RSpec.configure do |config| config.mock_with :mocha From 6a9d9111414d399bf2264222f328cb4872595f9b Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Wed, 26 Jun 2013 22:03:31 -0500 Subject: [PATCH 2/4] no need for double quotes around powershell.exe --- lib/puppet/provider/exec/powershell.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/puppet/provider/exec/powershell.rb b/lib/puppet/provider/exec/powershell.rb index b1481007..9063ff44 100644 --- a/lib/puppet/provider/exec/powershell.rb +++ b/lib/puppet/provider/exec/powershell.rb @@ -9,7 +9,7 @@ elsif File.exists?("#{ENV['SYSTEMROOT']}\\system32\\WindowsPowershell\\v1.0\\powershell.exe") "#{ENV['SYSTEMROOT']}\\system32\\WindowsPowershell\\v1.0\\powershell.exe" else - "powershell.exe" + 'powershell.exe' end commands :powershell => POWERSHELL From c4191ec754ee0f1cb548eaa9927d6ca6f07cd2ae Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Wed, 26 Jun 2013 22:04:43 -0500 Subject: [PATCH 3/4] adding a PS_ARGS value --- lib/puppet/provider/exec/powershell.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/puppet/provider/exec/powershell.rb b/lib/puppet/provider/exec/powershell.rb index 9063ff44..d445a55f 100644 --- a/lib/puppet/provider/exec/powershell.rb +++ b/lib/puppet/provider/exec/powershell.rb @@ -12,6 +12,8 @@ 'powershell.exe' end + PS_ARGS = '-NoProfile -NonInteractive -NoLogo -ExecutionPolicy Bypass' + commands :powershell => POWERSHELL desc <<-EOT From 3193385a75596ec9c85dc7b43b4db5754b3832a1 Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Wed, 26 Jun 2013 22:06:01 -0500 Subject: [PATCH 4/4] Adding the startup args for powershell. Surrounding the powershell command with quotes --- lib/puppet/provider/exec/powershell.rb | 2 +- spec/unit/provider/exec/powershell_spec.rb | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/puppet/provider/exec/powershell.rb b/lib/puppet/provider/exec/powershell.rb index d445a55f..18df77c6 100644 --- a/lib/puppet/provider/exec/powershell.rb +++ b/lib/puppet/provider/exec/powershell.rb @@ -30,7 +30,7 @@ EOT def run(command, check = false) - super("\"#{POWERSHELL}\" #{command}", check) + super("\"#{POWERSHELL}\" #{PS_ARGS} -Command \"#{command}\"", check) end def checkexe(command) diff --git a/spec/unit/provider/exec/powershell_spec.rb b/spec/unit/provider/exec/powershell_spec.rb index 19d9eb09..8e9d8f1c 100644 --- a/spec/unit/provider/exec/powershell_spec.rb +++ b/spec/unit/provider/exec/powershell_spec.rb @@ -3,12 +3,23 @@ describe Puppet::Type.type(:exec).provider(:powershell), :if => Puppet.features.microsoft_windows? do let(:command) { '$(Get-WMIObject Win32_UserAccount -Filter "Name=\'Administrator\'")' } + let(:args) { '-NoProfile -NonInteractive -NoLogo -ExecutionPolicy Bypass' } let(:resource) { Puppet::Type.type(:exec).new(:command => command, :provider => :powershell) } let(:provider) { described_class.new(resource) } + + let(:powershell) { + if File.exists?("#{ENV['SYSTEMROOT']}\\sysnative\\WindowsPowershell\\v1.0\\powershell.exe") + "#{ENV['SYSTEMROOT']}\\sysnative\\WindowsPowershell\\v1.0\\powershell.exe" + elsif File.exists?("#{ENV['SYSTEMROOT']}\\system32\\WindowsPowershell\\v1.0\\powershell.exe") + "#{ENV['SYSTEMROOT']}\\system32\\WindowsPowershell\\v1.0\\powershell.exe" + else + 'powershell.exe' + end + } describe "#run" do it "should be able to run powershell commands" do - Puppet::Util::Execution.expects(:execute).with(['powershell.exe', command], anything) + Puppet::Util::Execution.expects(:execute).with("\"#{powershell}\" #{args} -Command \"#{command}\"", anything) provider.run(command) end end