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:47:58 -0800
commit16b1b5f977f6858d914d5b1fe748b4d6a4cff7f4 (patch)
treeb31663e760760bbf1249420da6d812bfbc982a88
parent01c7e4dc402c3252a96ba05680747fe773b78f39 (diff)
parent0d9c6de889d2a221bfbed8f705f68ccf913b5bda (diff)
downloadchef-16b1b5f977f6858d914d5b1fe748b4d6a4cff7f4.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 1daaf9ec52..0bc76db272 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] = []