diff options
author | Tim Smith <tsmith@chef.io> | 2018-10-24 09:55:44 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-24 09:55:44 -0700 |
commit | 8995c6b93ff39661278c6c5e3b689bbaed94ede2 (patch) | |
tree | 283b96061f4e3c32dd292997db6adec8b50ef99b | |
parent | de14532bf420f5e99da22a23870043882c89b9f0 (diff) | |
parent | 5f76daac96db499617b47785dea6d43ad442b5c1 (diff) | |
download | chef-8995c6b93ff39661278c6c5e3b689bbaed94ede2.tar.gz |
Merge pull request #7767 from josh-barker/fix-registry-key-sensitive
Fix registry key bug when sensitive is true
-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 |