summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith84@gmail.com>2020-07-23 15:37:36 -0700
committerTim Smith <tsmith84@gmail.com>2020-07-23 15:53:28 -0700
commit9da12c53341984ebc2ae31540b34356b33cc14f2 (patch)
treeb87fd28aaa8c2f20173b82f1f4859282603ac9b8
parente157f64bcb292ff91136cd401ed8ba42de880972 (diff)
downloadchef-9da12c53341984ebc2ae31540b34356b33cc14f2.tar.gz
Add a basic test for the legacy attributes
Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--spec/unit/node_spec.rb87
1 files changed, 87 insertions, 0 deletions
diff --git a/spec/unit/node_spec.rb b/spec/unit/node_spec.rb
index cb2499a7ee..55a858ce04 100644
--- a/spec/unit/node_spec.rb
+++ b/spec/unit/node_spec.rb
@@ -1583,6 +1583,93 @@ describe Chef::Node do
end
end
+ context "with deprecated whitelist attributes configured" do
+ it "should only save allowed attributes (and subattributes)" do
+ Chef::Config[:default_attribute_whitelist] = [
+ ["filesystem", "/dev/disk0s2"],
+ "network/interfaces/eth0",
+ ]
+
+ node.default = {
+ "filesystem" => {
+ "/dev/disk0s2" => { "size" => "10mb" },
+ "map - autohome" => { "size" => "10mb" },
+ },
+ "network" => {
+ "interfaces" => {
+ "eth0" => {},
+ "eth1" => {},
+ },
+ },
+ }
+ node.automatic = {}
+ node.normal = {}
+ node.override = {}
+
+ selected_data = {
+ "default" => {
+ "filesystem" => {
+ "/dev/disk0s2" => { "size" => "10mb" },
+ },
+ "network" => {
+ "interfaces" => {
+ "eth0" => {},
+ },
+ },
+ },
+ "automatic" => {}, "normal" => {}, "override" => {}
+ }
+
+ node.name("picky-monkey")
+ Chef::Config[:treat_deprecation_warnings_as_errors] = false
+ expect(@rest).to receive(:put).with("nodes/picky-monkey", hash_including(selected_data)).and_return("foo")
+ node.save
+ end
+ end
+
+ context "with deprecated blacklist attributes configured" do
+ it "should only save non-blocklisted attributes (and subattributes)" do
+ Chef::Config[:default_attribute_blacklist] = [
+ ["filesystem", "/dev/disk0s2"],
+ "network/interfaces/eth0",
+ ]
+
+ node.default = {
+ "filesystem" => {
+ "/dev/disk0s2" => { "size" => "10mb" },
+ "map - autohome" => { "size" => "10mb" },
+ },
+ "network" => {
+ "interfaces" => {
+ "eth0" => {},
+ "eth1" => {},
+ },
+ },
+ }
+ node.automatic = {}
+ node.normal = {}
+ node.override = {}
+
+ selected_data = {
+ "default" => {
+ "filesystem" => {
+ "map - autohome" => { "size" => "10mb" },
+ },
+ "network" => {
+ "interfaces" => {
+ "eth1" => {},
+ },
+ },
+ },
+ "automatic" => {}, "normal" => {}, "override" => {}
+ }
+ node.name("picky-monkey")
+ Chef::Config[:treat_deprecation_warnings_as_errors] = false
+ expect(@rest).to receive(:put).with("nodes/picky-monkey", hash_including(selected_data)).and_return("foo")
+ node.save
+ end
+ end
+
context "with blocklisted attributes configured" do
it "should only save non-blocklisted attributes (and subattributes)" do
Chef::Config[:blocked_default_attributes] = [