diff options
author | Josh Barker <josh.barker.developer@gmail.com> | 2018-10-24 07:45:34 +1100 |
---|---|---|
committer | Josh Barker <josh.barker@au1.ibm.com> | 2018-10-24 09:27:51 +1100 |
commit | 5f76daac96db499617b47785dea6d43ad442b5c1 (patch) | |
tree | 8c9b8943cd19b3f9e674c76ba044a43745171ed9 | |
parent | c6f0eb055601ac50c9b1c24ba815329bccfc7605 (diff) | |
download | chef-5f76daac96db499617b47785dea6d43ad442b5c1.tar.gz |
Fix the registry_key resource so the correct value is set when sensitive is true
Signed-off-by: Josh Barker <josh.barker.developer@gmail.com>
-rw-r--r-- | lib/chef/provider/registry_key.rb | 21 | ||||
-rw-r--r-- | spec/unit/provider/registry_key_spec.rb | 74 |
2 files changed, 89 insertions, 6 deletions
diff --git a/lib/chef/provider/registry_key.rb b/lib/chef/provider/registry_key.rb index 7c7b190b95..6b226cc991 100644 --- a/lib/chef/provider/registry_key.rb +++ b/lib/chef/provider/registry_key.rb @@ -126,16 +126,22 @@ class Chef value[:data] = value[:data].to_i end unless current_value[:type] == value[:type] && current_value[:data] == value[:data] - converge_by_value = value - converge_by_value[:data] = "*sensitive value suppressed*" if new_resource.sensitive + converge_by_value = if new_resource.sensitive + value.merge(data: "*sensitive value suppressed*") + else + value + end converge_by("set value #{converge_by_value}") do registry.set_value(new_resource.key, value) end end else - converge_by_value = value - converge_by_value[:data] = "*sensitive value suppressed*" if new_resource.sensitive + converge_by_value = if new_resource.sensitive + value.merge(data: "*sensitive value suppressed*") + else + value + end converge_by("set value #{converge_by_value}") do registry.set_value(new_resource.key, value) @@ -152,8 +158,11 @@ class Chef end new_resource.unscrubbed_values.each do |value| unless @name_hash.key?(value[:name].downcase) - converge_by_value = value - converge_by_value[:data] = "*sensitive value suppressed*" if new_resource.sensitive + converge_by_value = if new_resource.sensitive + value.merge(data: "*sensitive value suppressed*") + else + value + end converge_by("create value #{converge_by_value}") do registry.set_value(new_resource.key, value) diff --git a/spec/unit/provider/registry_key_spec.rb b/spec/unit/provider/registry_key_spec.rb index 3563af4dc4..9a7dd9996e 100644 --- a/spec/unit/provider/registry_key_spec.rb +++ b/spec/unit/provider/registry_key_spec.rb @@ -309,6 +309,80 @@ describe Chef::Provider::RegistryKey do @provider.action_create end end + + context "when sensitive is true" do + before(:each) do + @new_resource.sensitive(true) + end + + context "and key exists" do + let(:keyname) { 'hklm\\software\\opscode\\testing\\sensitive\exists' } + before(:each) do + expect(@double_registry).to receive(:key_exists?).twice.with(keyname).and_return(true) + expect(@double_registry).to receive(:get_values).with(keyname).and_return( + [ + { name: "one", type: :string, data: "initial value" }, + { name: "two", type: :dword, data: 9001 } + ] + ) + end + + context "and type is a string" do + let(:testval1) { { name: "one", type: :string, data: "first_value" } } + + it "sets the unscrubbed value" do + expect(@double_registry).to receive(:set_value).with(keyname, testval1) + @provider.load_current_resource + @provider.action_create + end + end + + context "and type is a dword" do + let(:testval1) { { name: "two", type: :dword, data: 12345 } } + + it "sets the unscrubbed value" do + expect(@double_registry).to receive(:set_value).with(keyname, testval1) + @provider.load_current_resource + @provider.action_create + end + end + end + + context "and key does not exist" do + let(:keyname) { 'hklm\\software\\opscode\\testing\\sensitive\missing' } + let(:testval1) { { name: "one", type: :string, data: "first_value" } } + + before(:each) do + expect(@double_registry).to receive(:key_exists?).twice.with(keyname).and_return(false) + expect(@double_registry).to receive(:create_key).with(keyname, false) + end + + it "sets the unscrubbed value" do + expect(@double_registry).to receive(:set_value).with(keyname, testval1) + @provider.load_current_resource + @provider.action_create + end + end + end + end + + describe "action_create_if_missing" do + context "when sensitive is true" do + let(:keyname) { 'hklm\\software\\opscode\\testing\\create_if_missing\\sensitive' } + let(:testval1) { { name: "one", type: :string, data: "first_value" } } + + before(:each) do + expect(@double_registry).to receive(:key_exists?).twice.with(keyname).and_return(true) + expect(@double_registry).to receive(:get_values).with(keyname).and_return([]) + @new_resource.sensitive(true) + end + + it "sets the unscrubbed value" do + expect(@double_registry).to receive(:set_value).with(keyname, testval1) + @provider.load_current_resource + @provider.action_create_if_missing + end + end end end |