summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith84@gmail.com>2020-02-28 12:24:14 -0800
committerTim Smith <tsmith84@gmail.com>2020-02-28 14:02:26 -0800
commit2c55b1bf424522fe253e515f6237be130d58859d (patch)
tree2cda48e4dee7655f22022c1c5afc8ba9f01b4f98
parentc08cf41a46b7b1f957c6073a73d0a1f2ccc4fce1 (diff)
downloadchef-2c55b1bf424522fe253e515f6237be130d58859d.tar.gz
Deprecate supports_powershell_execution_bypass? check
All the platforms we support have PowerShell 3.0+ now so this is always true. Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--lib/chef/platform/query_helpers.rb4
-rw-r--r--lib/chef/resource/powershell_script.rb22
-rw-r--r--spec/unit/provider/powershell_script_spec.rb36
3 files changed, 15 insertions, 47 deletions
diff --git a/lib/chef/platform/query_helpers.rb b/lib/chef/platform/query_helpers.rb
index 1ddbe09bf4..169d762a45 100644
--- a/lib/chef/platform/query_helpers.rb
+++ b/lib/chef/platform/query_helpers.rb
@@ -48,9 +48,9 @@ class Chef
end
end
+ # @deprecated we don't support any release of Windows that isn't PS 3+
def supports_powershell_execution_bypass?(node)
- node[:languages] && node[:languages][:powershell] &&
- node[:languages][:powershell][:version].to_i >= 3
+ true
end
def supports_dsc?(node)
diff --git a/lib/chef/resource/powershell_script.rb b/lib/chef/resource/powershell_script.rb
index 154655f4d9..727ff6609a 100644
--- a/lib/chef/resource/powershell_script.rb
+++ b/lib/chef/resource/powershell_script.rb
@@ -1,6 +1,6 @@
#
# Author:: Adam Edwards (<adamed@chef.io>)
-# Copyright:: Copyright 2013-2016, Chef Software Inc.
+# Copyright:: Copyright 2013-2020, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -71,22 +71,12 @@ class Chef
end
# Options that will be passed to Windows PowerShell command
+ #
+ # @returns [String]
def default_flags
- # Execution policy 'Bypass' is preferable since it doesn't require
- # user input confirmation for files such as PowerShell modules
- # downloaded from the Internet. However, 'Bypass' is not supported
- # prior to PowerShell 3.0, so the fallback is 'Unrestricted'
- execution_policy = Chef::Platform.supports_powershell_execution_bypass?(run_context.node) ? "Bypass" : "Unrestricted"
-
- [
- "-NoLogo",
- "-NonInteractive",
- "-NoProfile",
- "-ExecutionPolicy #{execution_policy}",
- # PowerShell will hang if STDIN is redirected
- # http://connect.microsoft.com/PowerShell/feedback/details/572313/powershell-exe-can-hang-if-stdin-is-redirected
- "-InputFormat None",
- ].join(" ")
+ # Set InputFormat to None as PowerShell will hang if STDIN is redirected
+ # http://connect.microsoft.com/PowerShell/feedback/details/572313/powershell-exe-can-hang-if-stdin-is-redirected
+ "-NoLogo -NonInteractive -NoProfile -ExecutionPolicy Bypass -InputFormat None"
end
end
end
diff --git a/spec/unit/provider/powershell_script_spec.rb b/spec/unit/provider/powershell_script_spec.rb
index 0bb0bf701b..43af9cee2c 100644
--- a/spec/unit/provider/powershell_script_spec.rb
+++ b/spec/unit/provider/powershell_script_spec.rb
@@ -1,6 +1,6 @@
#
# Author:: Adam Edwards (<adamed@chef.io>)
-# Copyright:: Copyright 2013-2017, Chef Software Inc.
+# Copyright:: Copyright 2013-2020, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -73,35 +73,13 @@ describe Chef::Provider::PowershellScript, "action_run" do
execution_policy_index ? provider_flags[execution_policy_index + 1] : nil
end
- context "when running with an unspecified PowerShell version" do
- let(:powershell_version) { nil }
- it "sets default -ExecutionPolicy flag to 'Unrestricted'" do
- expect(execution_policy_flag.downcase).to eq("unrestricted".downcase)
- end
- it "sets user defined -ExecutionPolicy flag to 'RemoteSigned'" do
- set_user_defined_flag
- expect(execution_policy_flag.downcase).to eq("RemoteSigned".downcase)
- end
+ it "sets default -ExecutionPolicy flag to 'Bypass'" do
+ expect(execution_policy_flag).to eq("Bypass")
end
- { "2.0" => "Unrestricted",
- "2.5" => "Unrestricted",
- "3.0" => "Bypass",
- "3.6" => "Bypass",
- "4.0" => "Bypass",
- "5.0" => "Bypass" }.each do |version_policy|
- let(:powershell_version) { version_policy[0].to_f }
- context "when running PowerShell version #{version_policy[0]}" do
- let(:powershell_version) { version_policy[0].to_f }
-
- it "sets default -ExecutionPolicy flag to '#{version_policy[1]}'" do
- expect(execution_policy_flag.downcase).to eq(version_policy[1].downcase)
- end
- it "sets user defined -ExecutionPolicy flag to 'RemoteSigned'" do
- set_user_defined_flag
- expect(execution_policy_flag.downcase).to eq("RemoteSigned".downcase)
- end
- end
- end
+ it "sets user defined -ExecutionPolicy flag to 'RemoteSigned'" do
+ set_user_defined_flag
+ expect(execution_policy_flag).to eq("RemoteSigned")
+ end
end
end