summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThom May <thom@may.lt>2018-01-05 14:09:32 +0000
committerGitHub <noreply@github.com>2018-01-05 14:09:32 +0000
commit6597d0576628696f2ac1cef6c117b5c269abd53f (patch)
tree81e3d5271a92f45821d7eb0bc6b922485326c8af
parentc6433605bae0a9f52c843ca8cb97e64b2bcf5f0a (diff)
parent4da3e139ccce5ca9813ec2900109cf3cee3b130d (diff)
downloadchef-6597d0576628696f2ac1cef6c117b5c269abd53f.tar.gz
Merge pull request #6627 from MsysTechnologiesllc/vasundhara/issue_6073_allow_forcing_sensitive_to_false_on_execute_or_batch_resource
[MSYS-725] [chef#6073] allow forcing sensitive to false on execute and batch resource if password is set.
-rw-r--r--lib/chef/resource/execute.rb3
-rw-r--r--spec/support/shared/unit/execute_resource.rb9
2 files changed, 10 insertions, 2 deletions
diff --git a/lib/chef/resource/execute.rb b/lib/chef/resource/execute.rb
index de927ec06e..616195deee 100644
--- a/lib/chef/resource/execute.rb
+++ b/lib/chef/resource/execute.rb
@@ -133,7 +133,8 @@ class Chef
property :password, String, sensitive: true
- property :sensitive, [ TrueClass, FalseClass ], default: false, coerce: proc { |x| password ? true : x }
+ # lazy used to set default value of sensitive to true if password is set
+ property :sensitive, [ TrueClass, FalseClass ], default: lazy { |r| r.password ? true : false }
property :elevated, [ TrueClass, FalseClass ], default: false
diff --git a/spec/support/shared/unit/execute_resource.rb b/spec/support/shared/unit/execute_resource.rb
index ae56a9697d..c15b02612e 100644
--- a/spec/support/shared/unit/execute_resource.rb
+++ b/spec/support/shared/unit/execute_resource.rb
@@ -139,7 +139,14 @@ shared_examples_for "an execute resource" do
it "should be true if the password is non-nil but the value is explicitly set to false" do
@resource.password("we.funk!")
@resource.sensitive false
- expect(@resource.sensitive).to eq(true)
+ expect(@resource.sensitive).to eq(false)
+ end
+
+ # added this test to ensure setting of password property after or before sensitive does not matter
+ it "should be false if the sensitive is set before password property" do
+ @resource.sensitive false
+ @resource.password("we.funk!")
+ expect(@resource.sensitive).to eq(false)
end
end