summaryrefslogtreecommitdiff
path: root/spec/unit/node_spec.rb
diff options
context:
space:
mode:
authorRobert Mullins <rmullins@secureworks.com>2017-03-03 14:39:07 -0500
committerRobert Mullins <rmullins@secureworks.com>2017-03-08 11:41:56 -0500
commit848fbf3c081dabe4a7f18a42597b1a68f68b6009 (patch)
treec7d49291f920dbde14b43c70953b3c1f9bc800b1 /spec/unit/node_spec.rb
parent5dc375d6dd7acb1d32f06b3ee663201d0a119ccf (diff)
downloadchef-848fbf3c081dabe4a7f18a42597b1a68f68b6009.tar.gz
Add the ability to blacklist attributes
Signed-off-by: Robert Mullins <rmullins@secureworks.com>
Diffstat (limited to 'spec/unit/node_spec.rb')
-rw-r--r--spec/unit/node_spec.rb75
1 files changed, 75 insertions, 0 deletions
diff --git a/spec/unit/node_spec.rb b/spec/unit/node_spec.rb
index 7dc7dd2380..01100c914d 100644
--- a/spec/unit/node_spec.rb
+++ b/spec/unit/node_spec.rb
@@ -1609,6 +1609,81 @@ describe Chef::Node do
end
end
+ context "with blacklisted attributes configured" do
+ it "should only save non-blacklisted attributes (and subattributes)" do
+ Chef::Config[:automatic_attribute_blacklist] = [
+ ["filesystem", "/dev/disk0s2"],
+ "network/interfaces/eth0",
+ ]
+
+ data = {
+ "automatic" => {
+ "filesystem" => {
+ "/dev/disk0s2" => { "size" => "10mb" },
+ "map - autohome" => { "size" => "10mb" },
+ },
+ "network" => {
+ "interfaces" => {
+ "eth0" => {},
+ "eth1" => {},
+ },
+ },
+ },
+ "default" => {}, "normal" => {}, "override" => {}
+ }
+
+ selected_data = {
+ "automatic" => {
+ "filesystem" => {
+ "/dev/disk0s2" => nil,
+ "map - autohome" => { "size" => "10mb" },
+ },
+ "network" => {
+ "interfaces" => {
+ "eth0" => nil,
+ "eth1" => {},
+ },
+ },
+ },
+ "default" => {}, "normal" => {}, "override" => {}
+ }
+ node.name("picky-monkey")
+ allow(node).to receive(:for_json).and_return(data)
+ expect(@rest).to receive(:put).with("nodes/picky-monkey", selected_data).and_return("foo")
+ node.save
+ end
+
+ it "should save all attributes if the blacklist is empty" do
+ Chef::Config[:automatic_attribute_blacklist] = []
+
+ data = {
+ "automatic" => {
+ "filesystem" => {
+ "/dev/disk0s2" => { "size" => "10mb" },
+ "map - autohome" => { "size" => "10mb" },
+ },
+ },
+ "default" => {}, "normal" => {}, "override" => {}
+ }
+
+ selected_data = {
+ "automatic" => {
+ "filesystem" => {
+ "/dev/disk0s2" => { "size" => "10mb" },
+ "map - autohome" => { "size" => "10mb" },
+ },
+ },
+ "default" => {}, "normal" => {}, "override" => {}
+ }
+
+ node.name("picky-monkey")
+ allow(node).to receive(:for_json).and_return(data)
+ expect(@rest).to receive(:put).with("nodes/picky-monkey", selected_data).and_return("foo")
+ node.save
+ end
+ end
+
+
context "when policyfile attributes are present" do
before do