diff options
author | Tim Smith <tsmith@chef.io> | 2018-10-16 09:27:23 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-16 09:27:23 +0100 |
commit | 283cdc1e0fc4e470c40f9764d856a1ad6d1032d4 (patch) | |
tree | 3ae4f1cce264316267ef55bf362603d747cf4804 /spec | |
parent | 2c9017cd97ff7c8079945b54d03b84a077191fc8 (diff) | |
parent | 598146da16425de86b42732f2e6a9078435bf5e7 (diff) | |
download | chef-283cdc1e0fc4e470c40f9764d856a1ad6d1032d4.tar.gz |
Merge pull request #7752 from chef/lcg/deep-merge-cache-fix
Node Attributes: Build ImmutableMash properly in deep_merge!
Diffstat (limited to 'spec')
-rw-r--r-- | spec/unit/node_spec.rb | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/spec/unit/node_spec.rb b/spec/unit/node_spec.rb index 0ca5f83adc..ff912ee7a6 100644 --- a/spec/unit/node_spec.rb +++ b/spec/unit/node_spec.rb @@ -1818,4 +1818,37 @@ describe Chef::Node do expect(node["a"]["key"]).to eql(1) end end + + describe "when abusing the deep merge cache" do + # https://github.com/chef/chef/issues/7738 + it "do not corrupt VividMashes that are part of the merge set and not the merge_onto set" do + # need to have a merge two-deep (not at the top-level) between at least two default (or two override) + # levels where the lowest priority one is the one that is going to be corrupted + node.default["foo"]["bar"]["baz"] = "fizz" + node.env_default["foo"]["bar"]["quux"] = "buzz" + node.default["foo"]["bar"].tap do |bar| + bar["test"] = "wrong" + # this triggers a deep merge + node["foo"]["bar"]["test"] + # this should correctly write and dirty the cache so the next read does another deep merge on the correct __root__ + bar["test"] = "right" + end + expect(node["foo"]["bar"]["test"]).to eql("right") + end + + it "do not corrupt VividMashes that are part of the merge set and not the merge_onto set (when priorities are reversed)" do + # need to have a merge two-deep (not at the top-level) between at least two default (or two override) + # levels where the *HIGHEST* priority one is the one that is going to be corrupted + node.env_default["foo"]["bar"]["baz"] = "fizz" + node.default["foo"]["bar"]["quux"] = "buzz" + node.env_default["foo"]["bar"].tap do |bar| + bar["test"] = "wrong" + # this triggers a deep merge + node["foo"]["bar"]["test"] + # this should correctly write and dirty the cache so the next read does another deep merge on the correct __root__ + bar["test"] = "right" + end + expect(node["foo"]["bar"]["test"]).to eql("right") + end + end end |