summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSerdar Sutay <serdar@opscode.com>2014-12-10 20:47:58 -0800
committerSerdar Sutay <serdar@opscode.com>2014-12-10 20:48:50 -0800
commit17fde6ac33b1facc51046047348a50de5c569029 (patch)
treeaf76821200146be77b4f05c7d312a46f4a73806a
parentbe51b583056d84d3b79f61695da005222fb5a60f (diff)
downloadchef-17fde6ac33b1facc51046047348a50de5c569029.tar.gz
Merge pull request #2616 from jaymzh/whitelist
Fix attribute whitelisting
-rw-r--r--lib/chef/whitelist.rb4
-rw-r--r--spec/unit/node_spec.rb34
2 files changed, 37 insertions, 1 deletions
diff --git a/lib/chef/whitelist.rb b/lib/chef/whitelist.rb
index ad52215f11..86c229d22c 100644
--- a/lib/chef/whitelist.rb
+++ b/lib/chef/whitelist.rb
@@ -57,7 +57,9 @@ class Chef
all_data = all_data[part]
end
- unless all_data[parts[-1]]
+ # Note: You can't do all_data[parts[-1]] here because the value
+ # may be false-y
+ unless all_data.key?(parts[-1])
Chef::Log.warn("Could not find whitelist attribute #{item}.")
return nil
end
diff --git a/spec/unit/node_spec.rb b/spec/unit/node_spec.rb
index 695da8d671..0bccc6d482 100644
--- a/spec/unit/node_spec.rb
+++ b/spec/unit/node_spec.rb
@@ -1213,6 +1213,40 @@ describe Chef::Node do
node.save
end
+ it "should save false-y whitelisted attributes" do
+ Chef::Config[:default_attribute_whitelist] = [
+ "foo/bar/baz"
+ ]
+
+ data = {
+ "default" => {
+ "foo" => {
+ "bar" => {
+ "baz" => false,
+ },
+ "other" => {
+ "stuff" => true,
+ }
+ }
+ }
+ }
+
+ selected_data = {
+ "default" => {
+ "foo" => {
+ "bar" => {
+ "baz" => false,
+ }
+ }
+ }
+ }
+
+ node.name("falsey-monkey")
+ allow(node).to receive(:for_json).and_return(data)
+ expect(@rest).to receive(:put_rest).with("nodes/falsey-monkey", selected_data).and_return("foo")
+ node.save
+ end
+
it "should not save any attributes if the whitelist is empty" do
Chef::Config[:automatic_attribute_whitelist] = []