chef 17.1.35-universal-mingw32 → 17.2.29-universal-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -0
  3. data/lib/chef/action_collection.rb +6 -26
  4. data/lib/chef/application.rb +1 -1
  5. data/lib/chef/application/base.rb +15 -0
  6. data/lib/chef/client.rb +6 -0
  7. data/lib/chef/cookbook_version.rb +26 -4
  8. data/lib/chef/data_bag.rb +2 -1
  9. data/lib/chef/data_bag_item.rb +2 -1
  10. data/lib/chef/data_collector.rb +0 -1
  11. data/lib/chef/data_collector/run_end_message.rb +1 -1
  12. data/lib/chef/deprecated.rb +4 -0
  13. data/lib/chef/event_dispatch/base.rb +2 -1
  14. data/lib/chef/exceptions.rb +3 -0
  15. data/lib/chef/handler.rb +46 -8
  16. data/lib/chef/handler/slow_report.rb +66 -0
  17. data/lib/chef/node.rb +20 -19
  18. data/lib/chef/provider/support/zypper_repo.erb +4 -2
  19. data/lib/chef/provider/zypper_repository.rb +27 -31
  20. data/lib/chef/resource/alternatives.rb +5 -5
  21. data/lib/chef/resource/apt_preference.rb +2 -2
  22. data/lib/chef/resource/apt_repository.rb +2 -2
  23. data/lib/chef/resource/apt_update.rb +4 -4
  24. data/lib/chef/resource/build_essential.rb +1 -1
  25. data/lib/chef/resource/chef_client_config.rb +3 -3
  26. data/lib/chef/resource/chef_client_cron.rb +2 -2
  27. data/lib/chef/resource/chef_client_launchd.rb +2 -2
  28. data/lib/chef/resource/chef_client_scheduled_task.rb +14 -14
  29. data/lib/chef/resource/chef_client_systemd_timer.rb +2 -2
  30. data/lib/chef/resource/chef_handler.rb +2 -2
  31. data/lib/chef/resource/chef_sleep.rb +1 -1
  32. data/lib/chef/resource/chocolatey_feature.rb +2 -2
  33. data/lib/chef/resource/chocolatey_source.rb +1 -1
  34. data/lib/chef/resource/cron/cron_d.rb +4 -6
  35. data/lib/chef/resource/cron_access.rb +1 -1
  36. data/lib/chef/resource/dmg_package.rb +1 -1
  37. data/lib/chef/resource/group.rb +4 -4
  38. data/lib/chef/resource/homebrew_cask.rb +17 -6
  39. data/lib/chef/resource/homebrew_package.rb +1 -1
  40. data/lib/chef/resource/homebrew_tap.rb +4 -3
  41. data/lib/chef/resource/homebrew_update.rb +2 -2
  42. data/lib/chef/resource/hostname.rb +49 -7
  43. data/lib/chef/resource/inspec_waiver_file_entry.rb +6 -5
  44. data/lib/chef/resource/kernel_module.rb +6 -6
  45. data/lib/chef/resource/locale.rb +1 -1
  46. data/lib/chef/resource/macos_userdefaults.rb +2 -2
  47. data/lib/chef/resource/ohai_hint.rb +2 -6
  48. data/lib/chef/resource/openbsd_package.rb +17 -0
  49. data/lib/chef/resource/openssl_dhparam.rb +1 -2
  50. data/lib/chef/resource/openssl_ec_private_key.rb +1 -3
  51. data/lib/chef/resource/openssl_ec_public_key.rb +1 -3
  52. data/lib/chef/resource/openssl_rsa_private_key.rb +1 -3
  53. data/lib/chef/resource/openssl_rsa_public_key.rb +1 -3
  54. data/lib/chef/resource/openssl_x509_certificate.rb +1 -4
  55. data/lib/chef/resource/openssl_x509_crl.rb +1 -3
  56. data/lib/chef/resource/openssl_x509_request.rb +1 -3
  57. data/lib/chef/resource/osx_profile.rb +3 -3
  58. data/lib/chef/resource/plist.rb +1 -1
  59. data/lib/chef/resource/powershell_package_source.rb +2 -4
  60. data/lib/chef/resource/reboot.rb +38 -9
  61. data/lib/chef/resource/remote_directory.rb +2 -2
  62. data/lib/chef/resource/rhsm_errata.rb +0 -2
  63. data/lib/chef/resource/rhsm_errata_level.rb +1 -5
  64. data/lib/chef/resource/rhsm_repo.rb +15 -0
  65. data/lib/chef/resource/ssh_known_hosts_entry.rb +4 -7
  66. data/lib/chef/resource/sudo.rb +2 -6
  67. data/lib/chef/resource/swap_file.rb +2 -6
  68. data/lib/chef/resource/sysctl.rb +2 -2
  69. data/lib/chef/resource/timezone.rb +1 -1
  70. data/lib/chef/resource/user_ulimit.rb +2 -2
  71. data/lib/chef/resource/windows_ad_join.rb +2 -2
  72. data/lib/chef/resource/windows_audit_policy.rb +2 -2
  73. data/lib/chef/resource/windows_auto_run.rb +2 -2
  74. data/lib/chef/resource/windows_certificate.rb +1 -1
  75. data/lib/chef/resource/windows_dfs_folder.rb +2 -2
  76. data/lib/chef/resource/windows_dfs_namespace.rb +2 -2
  77. data/lib/chef/resource/windows_dns_record.rb +2 -2
  78. data/lib/chef/resource/windows_dns_zone.rb +2 -2
  79. data/lib/chef/resource/windows_feature.rb +3 -3
  80. data/lib/chef/resource/windows_feature_dism.rb +3 -5
  81. data/lib/chef/resource/windows_feature_powershell.rb +3 -3
  82. data/lib/chef/resource/windows_firewall_profile.rb +2 -2
  83. data/lib/chef/resource/windows_firewall_rule.rb +20 -6
  84. data/lib/chef/resource/windows_font.rb +1 -1
  85. data/lib/chef/resource/windows_pagefile.rb +103 -64
  86. data/lib/chef/resource/windows_path.rb +2 -2
  87. data/lib/chef/resource/windows_printer.rb +5 -20
  88. data/lib/chef/resource/windows_printer_port.rb +48 -65
  89. data/lib/chef/resource/windows_security_policy.rb +2 -2
  90. data/lib/chef/resource/windows_share.rb +2 -2
  91. data/lib/chef/resource/windows_shortcut.rb +1 -1
  92. data/lib/chef/resource/windows_task.rb +1 -1
  93. data/lib/chef/resource/windows_uac.rb +3 -5
  94. data/lib/chef/resource/windows_user_privilege.rb +2 -2
  95. data/lib/chef/resource/windows_workgroup.rb +2 -2
  96. data/lib/chef/resource/yum_package.rb +10 -10
  97. data/lib/chef/resource/zypper_package.rb +4 -4
  98. data/lib/chef/resource/zypper_repository.rb +28 -8
  99. data/lib/chef/resource_reporter.rb +0 -1
  100. data/lib/chef/version.rb +1 -1
  101. data/spec/functional/resource/windows_hostname_spec.rb +91 -0
  102. data/spec/functional/resource/windows_pagefile_spec.rb +98 -0
  103. data/spec/unit/cookbook_version_spec.rb +52 -0
  104. data/spec/unit/data_bag_item_spec.rb +2 -2
  105. data/spec/unit/data_bag_spec.rb +1 -1
  106. data/spec/unit/data_collector_spec.rb +47 -1
  107. data/spec/unit/handler_spec.rb +8 -2
  108. data/spec/unit/provider/zypper_repository_spec.rb +3 -10
  109. data/spec/unit/resource/windows_firewall_rule_spec.rb +12 -7
  110. data/spec/unit/resource/windows_pagefile_spec.rb +4 -9
  111. data/spec/unit/resource/zypper_repository_spec.rb +1 -1
  112. metadata +9 -6
@@ -24,21 +24,37 @@ class Chef
24
24
  unified_mode true
25
25
 
26
26
  provides(:zypper_repository) { true }
27
- provides(:zypper_repo) { true }
27
+ provides(:zypper_repo) { true } # legacy cookbook compatibility
28
28
 
29
29
  description "Use the **zypper_repository** resource to create Zypper package repositories on SUSE Enterprise Linux and openSUSE systems. This resource maintains full compatibility with the **zypper_repository** resource in the existing **zypper** cookbook."
30
30
  introduced "13.3"
31
31
  examples <<~DOC
32
32
  **Add the Apache repo on openSUSE Leap 15**:
33
33
 
34
- ``` ruby
34
+ ```ruby
35
35
  zypper_repository 'apache' do
36
36
  baseurl 'http://download.opensuse.org/repositories/Apache'
37
- path '/openSUSE_Leap_15.0'
38
- type 'rpm-md'
37
+ path '/openSUSE_Leap_15.2'
38
+ type 'rpm-md'
39
39
  priority '100'
40
40
  end
41
41
  ```
42
+
43
+ **Remove the repo named 'apache'**:
44
+
45
+ ```ruby
46
+ zypper_repository 'apache' do
47
+ action :delete
48
+ end
49
+ ```
50
+
51
+ **Refresh the repo named 'apache'**:
52
+
53
+ ```ruby
54
+ zypper_repository 'apache' do
55
+ action :refresh
56
+ end
57
+ ```
42
58
  DOC
43
59
 
44
60
  property :repo_name, String,
@@ -66,8 +82,10 @@ class Chef
66
82
  description: "Determines whether or not to perform a GPG signature check on the repository.",
67
83
  default: true
68
84
 
69
- property :gpgkey, String,
70
- description: "The location of the repository key to be imported."
85
+ property :gpgkey, [String, Array],
86
+ description: "The location of the repository key(s) to be imported.",
87
+ coerce: proc { |v| Array(v) },
88
+ default: []
71
89
 
72
90
  property :baseurl, String,
73
91
  description: "The base URL for the Zypper repository, such as `http://download.opensuse.org`."
@@ -95,10 +113,12 @@ class Chef
95
113
  default: true
96
114
 
97
115
  property :source, String,
98
- description: "The name of the template for the repository file. Only necessary if you're not using the built in template."
116
+ description: "The name of the template for the repository file. Only necessary if you're using a custom template for the repository file."
99
117
 
100
118
  property :cookbook, String,
101
- description: "The cookbook to source the repository template file from. Only necessary if you're not using the built in template.",
119
+ description: "The cookbook to source the repository template file from. Only necessary if you're using a custom template for the repository file.",
120
+ default: lazy { cookbook_name },
121
+ default_description: "The cookbook containing the resource",
102
122
  desired_state: false
103
123
 
104
124
  property :gpgautoimportkeys, [TrueClass, FalseClass],
@@ -135,7 +135,6 @@ class Chef
135
135
 
136
136
  def action_collection_registration(action_collection)
137
137
  @action_collection = action_collection
138
- action_collection.register(self) if reporting_enabled?
139
138
  end
140
139
 
141
140
  def post_reporting_data
data/lib/chef/version.rb CHANGED
@@ -23,7 +23,7 @@ require_relative "version_string"
23
23
 
24
24
  class Chef
25
25
  CHEF_ROOT = File.expand_path("..", __dir__)
26
- VERSION = Chef::VersionString.new("17.1.35")
26
+ VERSION = Chef::VersionString.new("17.2.29")
27
27
  end
28
28
 
29
29
  #
@@ -0,0 +1,91 @@
1
+ # Author: John McCrae (john.mccrae@progress.com)
2
+ # Copyright:: Copyright (c) Chef Software Inc.
3
+ # License: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ require "spec_helper"
19
+ require "chef/mixin/powershell_exec"
20
+ require "chef/resource/hostname"
21
+
22
+ describe Chef::Resource::Hostname, :windows_only do
23
+ include Chef::Mixin::PowershellExec
24
+
25
+ def get_domain_status
26
+ powershell_exec!("(Get-WmiObject -Class Win32_ComputerSystem).PartofDomain").result
27
+ end
28
+
29
+ let(:new_hostname) { "New-Hostname" }
30
+ let(:local_domain_user) { "'mydomain\\Groucho'" }
31
+ let(:local_domain_password) { "'P@ssw0rd'" }
32
+ let(:local_windows_reboot) { false }
33
+ let(:domain_status) { get_domain_status }
34
+
35
+ let(:run_context) do
36
+ node = Chef::Node.new
37
+ node.consume_external_attrs(OHAI_SYSTEM.data, {}) # node[:languages][:powershell][:version]
38
+ node.automatic["os"] = "windows"
39
+ node.automatic["platform"] = "windows"
40
+ node.automatic["platform_version"] = "6.1"
41
+ node.automatic["kernel"][:machine] = :x86_64 # Only 64-bit architecture is supported
42
+ empty_events = Chef::EventDispatch::Dispatcher.new
43
+ Chef::RunContext.new(node, {}, empty_events)
44
+ end
45
+
46
+ subject do
47
+ new_resource = Chef::Resource::Hostname.new("oldhostname", run_context)
48
+ new_resource.hostname = "Grendel"
49
+ new_resource.windows_reboot = false
50
+ new_resource
51
+ end
52
+
53
+ describe "Changing machine names" do
54
+ context "The system can be renamed without a user or password when in a Workgroup" do
55
+ let(:hostname) { "Cucumber" }
56
+ it "does change" do
57
+ subject.run_action(:set)
58
+ expect(subject).to be_updated_by_last_action
59
+ end
60
+ end
61
+
62
+ describe "Mocking being joined to a domain" do
63
+ before do
64
+ allow(subject).to receive(:is_domain_joined?) { true }
65
+ end
66
+ context "the system gets renamed when in a domain" do
67
+ let(:hostname) { "Gherkin" }
68
+ it "does change the domain account" do
69
+ subject.windows_reboot true
70
+ subject.domain_user local_domain_user
71
+ subject.domain_password local_domain_password
72
+ subject.run_action(:set)
73
+ expect(subject).to be_updated_by_last_action
74
+ end
75
+ end
76
+ end
77
+
78
+ describe "testing for error handling" do
79
+ before do
80
+ allow(subject).to receive(:is_domain_joined?) { true }
81
+ end
82
+ context "when a node is renamed while in a domain" do
83
+ it "and fails because of missing credentials" do
84
+ subject.windows_reboot true
85
+ subject.domain_user local_domain_user
86
+ expect { subject.run_action(:set) }.to raise_error(RuntimeError)
87
+ end
88
+ end
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,98 @@
1
+ # Author: John McCrae (john.mccrae@progress.com)
2
+ # Copyright:: Copyright (c) Chef Software Inc.
3
+ # License: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ require "spec_helper"
19
+ require "chef/mixin/powershell_exec"
20
+
21
+ describe Chef::Resource::WindowsPagefile, :windows_only do
22
+ include Chef::Mixin::PowershellExec
23
+
24
+ let(:c_path) { "c:\\" }
25
+ let(:e_path) { "e:\pagefile.sys" }
26
+
27
+ let(:run_context) do
28
+ node = Chef::Node.new
29
+ node.consume_external_attrs(OHAI_SYSTEM.data, {}) # node[:languages][:powershell][:version]
30
+ node.automatic["os"] = "windows"
31
+ node.automatic["platform"] = "windows"
32
+ node.automatic["platform_version"] = "6.1"
33
+ node.automatic["kernel"][:machine] = :x86_64 # Only 64-bit architecture is supported
34
+ empty_events = Chef::EventDispatch::Dispatcher.new
35
+ Chef::RunContext.new(node, {}, empty_events)
36
+ end
37
+
38
+ subject do
39
+ new_resource = Chef::Resource::WindowsPagefile.new("pagefile", run_context)
40
+ new_resource
41
+ end
42
+
43
+ describe "Setting Up Pagefile Management" do
44
+ context "Disable Automatic Management" do
45
+ it "Disables Automatic Management" do
46
+ subject.path c_path
47
+ subject.automatic_managed false
48
+ subject.run_action(:set)
49
+ expect(subject).to be_updated_by_last_action
50
+ end
51
+
52
+ it "Enable Automatic Management " do
53
+ subject.path c_path
54
+ subject.automatic_managed true
55
+ subject.run_action(:set)
56
+ expect(subject).to be_updated_by_last_action
57
+ end
58
+ end
59
+ end
60
+
61
+ describe "Creating a new Pagefile" do
62
+ context "Create new pagefile" do
63
+ it "Creates a new pagefile on a different drive that doesn't exist" do
64
+ subject.path e_path
65
+ expect { subject.run_action(:set) }.to raise_error(RuntimeError)
66
+ end
67
+ end
68
+
69
+ context "Update a pagefile" do
70
+ it "Changes a pagefile to use custom sizes" do
71
+ subject.path c_path
72
+ subject.initial_size 20000
73
+ subject.maximum_size 80000
74
+ subject.run_action(:set)
75
+ expect(subject).to be_updated_by_last_action
76
+ end
77
+ end
78
+ end
79
+
80
+ describe "Deleting a Pagefile and Resetting to Automatically Managed" do
81
+ context "delete the pagefile on disk" do
82
+ it "deletes the pagefile located at the given path" do
83
+ subject.path c_path
84
+ subject.run_action(:delete)
85
+ expect(subject).to be_updated_by_last_action
86
+ end
87
+ end
88
+
89
+ context "Re-enable automatic management of pagefiles" do
90
+ it "Enable Automatic Management " do
91
+ subject.path c_path
92
+ subject.automatic_managed true
93
+ subject.run_action(:set)
94
+ expect(subject).to be_updated_by_last_action
95
+ end
96
+ end
97
+ end
98
+ end
@@ -41,7 +41,59 @@ describe Chef::CookbookVersion do
41
41
  it "has empty metadata" do
42
42
  expect(cookbook_version.metadata).to eq(Chef::Cookbook::Metadata.new)
43
43
  end
44
+ end
45
+
46
+ describe "#recipe_yml_filenames_by_name" do
47
+ let(:cookbook_version) { Chef::CookbookVersion.new("mycb", "/tmp/mycb") }
48
+
49
+ def files_for_recipe(extension)
50
+ [
51
+ { name: "recipes/default.#{extension}", full_path: "/home/user/repo/cookbooks/test/recipes/default.#{extension}" },
52
+ { name: "recipes/other.#{extension}", full_path: "/home/user/repo/cookbooks/test/recipes/other.#{extension}" },
53
+ ]
54
+ end
55
+ context "and YAML files present include both a recipes/default.yml and a recipes/default.yaml" do
56
+ before(:each) do
57
+ allow(cookbook_version).to receive(:files_for).with("recipes").and_return(
58
+ [
59
+ { name: "recipes/default.yml", full_path: "/home/user/repo/cookbooks/test/recipes/default.yml" },
60
+ { name: "recipes/default.yaml", full_path: "/home/user/repo/cookbooks/test/recipes/default.yaml" },
61
+ ]
62
+ )
63
+ end
64
+ it "because both are valid and we can't pick, it raises an error that contains the info needed to fix the problem" do
65
+ expect { cookbook_version.recipe_yml_filenames_by_name }
66
+ .to raise_error(Chef::Exceptions::AmbiguousYAMLFile, /.*default.yml.*default.yaml.*update the cookbook to remove/)
67
+ end
68
+ end
69
+
70
+ %w{yml yaml}.each do |extension|
71
+
72
+ context "and YAML files are present including a recipes/default.#{extension}" do
73
+ before(:each) do
74
+ allow(cookbook_version).to receive(:files_for).with("recipes").and_return(files_for_recipe(extension))
75
+ end
76
+
77
+ context "and manifest does not include a root_files/recipe.#{extension}" do
78
+ it "returns all YAML recipes with a correct default of default.#{extension}" do
79
+ expect(cookbook_version.recipe_yml_filenames_by_name).to eq({ "default" => "/home/user/repo/cookbooks/test/recipes/default.#{extension}",
80
+ "other" => "/home/user/repo/cookbooks/test/recipes/other.#{extension}" })
81
+ end
82
+ end
83
+
84
+ context "and manifest also includes a root_files/recipe.#{extension}" do
85
+ let(:root_files) { [{ name: "root_files/recipe.#{extension}", full_path: "/home/user/repo/cookbooks/test/recipe.#{extension}" } ] }
86
+ before(:each) do
87
+ allow(cookbook_version.cookbook_manifest).to receive(:root_files).and_return(root_files)
88
+ end
44
89
 
90
+ it "returns all YAML recipes with a correct default of recipe.#{extension}" do
91
+ expect(cookbook_version.recipe_yml_filenames_by_name).to eq({ "default" => "/home/user/repo/cookbooks/test/recipe.#{extension}",
92
+ "other" => "/home/user/repo/cookbooks/test/recipes/other.#{extension}" })
93
+ end
94
+ end
95
+ end
96
+ end
45
97
  end
46
98
 
47
99
  describe "with a cookbook directory named tatft" do
@@ -73,11 +73,11 @@ describe Chef::DataBagItem do
73
73
  end
74
74
 
75
75
  it "should accept alphanum.alphanum for the id" do
76
- expect { data_bag_item.raw_data = { "id" => "foo.bar" } }.not_to raise_error
76
+ expect { data_bag_item.raw_data = { "id" => "foo.bar" } }.to raise_error(ArgumentError)
77
77
  end
78
78
 
79
79
  it "should accept .alphanum for the id" do
80
- expect { data_bag_item.raw_data = { "id" => ".bozo" } }.not_to raise_error
80
+ expect { data_bag_item.raw_data = { "id" => ".bozo" } }.to raise_error(ArgumentError)
81
81
  end
82
82
 
83
83
  it "should raise an exception if the id contains anything but alphanum/-/_" do
@@ -49,7 +49,7 @@ describe Chef::DataBag do
49
49
  expect { @data_bag.name({}) }.to raise_error(ArgumentError)
50
50
  end
51
51
 
52
- [ ".", "-", "_", "1"].each do |char|
52
+ ["-", "_", "1"].each do |char|
53
53
  it "should allow a '#{char}' character in the data bag name" do
54
54
  expect(@data_bag.name("clown#{char}clown")).to eq("clown#{char}clown")
55
55
  end
@@ -142,11 +142,17 @@ describe Chef::DataCollector do
142
142
  def expect_converge_message(keys)
143
143
  keys["message_type"] = "run_converge"
144
144
  keys["message_version"] = "1.1.0"
145
+ # if (keys.key?("node") && !keys["node"].empty?)
146
+ # expect(rest_client).to receive(:post) do |_a, hash, _b|
147
+ # require 'pry'; binding.pry
148
+ # end
149
+ # else
145
150
  expect(rest_client).to receive(:post).with(
146
151
  nil,
147
152
  hash_including(keys),
148
153
  { "Content-Type" => "application/json" }
149
154
  )
155
+ # end
150
156
  end
151
157
 
152
158
  def resource_has_diff(new_resource, status)
@@ -202,7 +208,7 @@ describe Chef::DataCollector do
202
208
  end
203
209
 
204
210
  it "has a node" do
205
- expect_converge_message("node" => expected_node)
211
+ expect_converge_message("node" => expected_node.is_a?(Chef::Node) ? expected_node.data_for_save : expected_node)
206
212
  send_run_failed_or_completed_event
207
213
  end
208
214
 
@@ -808,6 +814,46 @@ describe Chef::DataCollector do
808
814
  it_behaves_like "sends a converge message"
809
815
  end
810
816
 
817
+ context "when node attributes are block-listed" do
818
+ let(:status) { "success" }
819
+ before do
820
+ Chef::Config[:blocked_default_attributes] = [
821
+ %w{secret key_to_the_kingdom},
822
+ ]
823
+ node.default = {
824
+ "secret" => { "key_to_the_kingdom" => "under the flower pot to the left of the drawbridge" },
825
+ "publicinfo" => { "num_flower_pots" => 18 },
826
+ }
827
+ end
828
+
829
+ it "payload should exclude blocked attributes" do
830
+ expect(rest_client).to receive(:post) do |_addr, hash, _headers|
831
+ expect(hash["node"]["default"]).to eq({ "secret" => {}, "publicinfo" => { "num_flower_pots" => 18 } })
832
+ end
833
+ send_run_failed_or_completed_event
834
+ end
835
+ end
836
+
837
+ context "when node attributes are allow-listed" do
838
+ let(:status) { "success" }
839
+ before do
840
+ Chef::Config[:allowed_default_attributes] = [
841
+ %w{public entrance},
842
+ ]
843
+ node.default = {
844
+ "public" => { "entrance" => "is the drawbridge" },
845
+ "secret" => { "entrance" => "is the tunnel" },
846
+ }
847
+ end
848
+
849
+ it "payload should include only allowed attributes" do
850
+ expect(rest_client).to receive(:post) do |_addr, hash, _headers|
851
+ expect(hash["node"]["default"]).to eq({ "public" => { "entrance" => "is the drawbridge" } })
852
+ end
853
+ send_run_failed_or_completed_event
854
+ end
855
+ end
856
+
811
857
  end
812
858
  end
813
859
 
@@ -38,6 +38,8 @@ describe Chef::Handler do
38
38
  @run_context = Chef::RunContext.new(@node, {}, @events)
39
39
  @all_resources = [Chef::Resource::Cat.new("lolz"), Chef::Resource::ZenMaster.new("tzu")]
40
40
  @all_resources.first.updated_by_last_action true
41
+ @handler.instance_variable_set(:@all_resources, @all_resources)
42
+ @handler.instance_variable_set(:@updated_resources, [@all_resources.first])
41
43
  @run_context.resource_collection.all_resources.replace(@all_resources)
42
44
  @run_status.run_context = @run_context
43
45
  @start_time = Time.now
@@ -119,6 +121,8 @@ describe Chef::Handler do
119
121
  @run_context = Chef::RunContext.new(@node, {}, @events)
120
122
  @all_resources = [Chef::Resource::Cat.new("foo"), Chef::Resource::ZenMaster.new("moo")]
121
123
  @all_resources.first.updated_by_last_action true
124
+ @handler.instance_variable_set(:@all_resources, @all_resources)
125
+ @handler.instance_variable_set(:@updated_resources, [@all_resources.first])
122
126
  @run_context.resource_collection.all_resources.replace(@all_resources)
123
127
  @run_status.run_context = @run_context
124
128
  @start_time = Time.now
@@ -169,17 +173,19 @@ describe Chef::Handler do
169
173
  # and this would test the start handler
170
174
  describe "when running a start handler" do
171
175
  before do
176
+ @handler.instance_variable_set(:@all_resources, [])
177
+ @handler.instance_variable_set(:@updated_resources, [])
172
178
  @start_time = Time.now
173
179
  allow(Time).to receive(:now).and_return(@start_time)
174
180
  @run_status.start_clock
175
181
  end
176
182
 
177
183
  it "should not have all resources" do
178
- expect(@handler.all_resources).to be_falsey
184
+ expect(@handler.all_resources).to be_empty
179
185
  end
180
186
 
181
187
  it "should not have updated resources" do
182
- expect(@handler.updated_resources).to be_falsey
188
+ expect(@handler.updated_resources).to be_empty
183
189
  end
184
190
 
185
191
  it "has a shortcut for the start time" do