chef 17.2.29-universal-mingw32 → 17.5.22-universal-mingw32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (173) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +6 -5
  3. data/chef.gemspec +3 -0
  4. data/lib/chef/application/base.rb +11 -1
  5. data/lib/chef/application.rb +3 -1
  6. data/lib/chef/client.rb +2 -3
  7. data/lib/chef/compliance/default_attributes.rb +5 -3
  8. data/lib/chef/compliance/input.rb +115 -0
  9. data/lib/chef/compliance/input_collection.rb +139 -0
  10. data/lib/chef/compliance/profile.rb +122 -0
  11. data/lib/chef/compliance/profile_collection.rb +109 -0
  12. data/lib/chef/compliance/reporter/automate.rb +1 -1
  13. data/lib/chef/compliance/runner.rb +62 -6
  14. data/lib/chef/compliance/waiver.rb +115 -0
  15. data/lib/chef/compliance/waiver_collection.rb +143 -0
  16. data/lib/chef/data_bag.rb +1 -2
  17. data/lib/chef/data_bag_item.rb +1 -2
  18. data/lib/chef/deprecated.rb +10 -4
  19. data/lib/chef/dsl/compliance.rb +38 -0
  20. data/lib/chef/dsl/reader_helpers.rb +51 -0
  21. data/lib/chef/dsl/recipe.rb +4 -2
  22. data/lib/chef/dsl/render_helpers.rb +44 -0
  23. data/lib/chef/dsl/secret.rb +62 -0
  24. data/lib/chef/dsl/toml.rb +116 -0
  25. data/lib/chef/dsl/universal.rb +7 -0
  26. data/lib/chef/dsl.rb +1 -0
  27. data/lib/chef/event_dispatch/base.rb +44 -2
  28. data/lib/chef/exceptions.rb +20 -0
  29. data/lib/chef/formatters/doc.rb +60 -13
  30. data/lib/chef/formatters/error_mapper.rb +2 -2
  31. data/lib/chef/formatters/minimal.rb +6 -5
  32. data/lib/chef/handler/slow_report.rb +1 -1
  33. data/lib/chef/http/basic_client.rb +15 -7
  34. data/lib/chef/http.rb +12 -8
  35. data/lib/chef/json_compat.rb +1 -1
  36. data/lib/chef/policy_builder/policyfile.rb +88 -45
  37. data/lib/chef/provider/execute.rb +1 -1
  38. data/lib/chef/provider/file.rb +4 -2
  39. data/lib/chef/provider/group/dscl.rb +1 -1
  40. data/lib/chef/provider/launchd.rb +6 -6
  41. data/lib/chef/provider/link.rb +2 -2
  42. data/lib/chef/provider/lwrp_base.rb +1 -1
  43. data/lib/chef/provider/package/habitat.rb +168 -0
  44. data/lib/chef/provider/package/powershell.rb +5 -0
  45. data/lib/chef/provider/registry_key.rb +3 -2
  46. data/lib/chef/provider/remote_file/http.rb +1 -1
  47. data/lib/chef/provider/subversion.rb +4 -4
  48. data/lib/chef/provider/support/yum_repo.erb +1 -1
  49. data/lib/chef/provider/systemd_unit.rb +17 -16
  50. data/lib/chef/provider/template.rb +1 -1
  51. data/lib/chef/provider/user/mac.rb +3 -3
  52. data/lib/chef/provider/yum_repository.rb +27 -43
  53. data/lib/chef/provider/zypper_repository.rb +3 -3
  54. data/lib/chef/provider.rb +26 -1
  55. data/lib/chef/provider_resolver.rb +8 -2
  56. data/lib/chef/providers.rb +1 -0
  57. data/lib/chef/resource/archive_file.rb +17 -14
  58. data/lib/chef/resource/chef_client_config.rb +7 -2
  59. data/lib/chef/resource/chef_client_cron.rb +1 -1
  60. data/lib/chef/resource/chef_client_launchd.rb +1 -1
  61. data/lib/chef/resource/chef_client_scheduled_task.rb +46 -3
  62. data/lib/chef/resource/chef_client_systemd_timer.rb +1 -1
  63. data/lib/chef/resource/chef_client_trusted_certificate.rb +2 -2
  64. data/lib/chef/resource/chef_vault_secret.rb +2 -2
  65. data/lib/chef/resource/chocolatey_config.rb +13 -13
  66. data/lib/chef/resource/dsc_resource.rb +1 -1
  67. data/lib/chef/resource/execute.rb +5 -5
  68. data/lib/chef/resource/file/verification/json.rb +50 -0
  69. data/lib/chef/resource/file/verification/yaml.rb +52 -0
  70. data/lib/chef/resource/gem_package.rb +2 -1
  71. data/lib/chef/resource/habitat/_habitat_shared.rb +28 -0
  72. data/lib/chef/resource/habitat/habitat_package.rb +129 -0
  73. data/lib/chef/resource/habitat/habitat_sup.rb +329 -0
  74. data/lib/chef/resource/habitat/habitat_sup_systemd.rb +67 -0
  75. data/lib/chef/resource/habitat/habitat_sup_windows.rb +90 -0
  76. data/lib/chef/resource/habitat_config.rb +107 -0
  77. data/lib/chef/resource/habitat_install.rb +247 -0
  78. data/lib/chef/resource/habitat_service.rb +451 -0
  79. data/lib/chef/resource/habitat_user_toml.rb +92 -0
  80. data/lib/chef/resource/homebrew_cask.rb +1 -1
  81. data/lib/chef/resource/inspec_input.rb +128 -0
  82. data/lib/chef/resource/inspec_waiver.rb +185 -0
  83. data/lib/chef/resource/inspec_waiver_file_entry.rb +2 -2
  84. data/lib/chef/resource/launchd.rb +3 -3
  85. data/lib/chef/resource/lwrp_base.rb +1 -1
  86. data/lib/chef/resource/mount.rb +1 -1
  87. data/lib/chef/resource/registry_key.rb +36 -48
  88. data/lib/chef/resource/remote_file.rb +99 -3
  89. data/lib/chef/resource/rhsm_subscription.rb +5 -5
  90. data/lib/chef/resource/ruby_block.rb +100 -0
  91. data/lib/chef/resource/scm/subversion.rb +1 -1
  92. data/lib/chef/resource/support/HabService.dll.config.erb +19 -0
  93. data/lib/chef/resource/support/client.erb +8 -1
  94. data/lib/chef/resource/support/sup.toml.erb +179 -0
  95. data/lib/chef/resource/sysctl.rb +2 -2
  96. data/lib/chef/resource/systemd_unit.rb +3 -3
  97. data/lib/chef/resource/timezone.rb +2 -2
  98. data/lib/chef/resource/user_ulimit.rb +1 -0
  99. data/lib/chef/resource/windows_defender.rb +163 -0
  100. data/lib/chef/resource/windows_defender_exclusion.rb +125 -0
  101. data/lib/chef/resource/windows_printer.rb +78 -44
  102. data/lib/chef/resource/windows_printer_port.rb +1 -1
  103. data/lib/chef/resource/windows_uac.rb +3 -1
  104. data/lib/chef/resource/windows_update_settings.rb +259 -0
  105. data/lib/chef/resource/windows_user_privilege.rb +1 -1
  106. data/lib/chef/resource/yum_package.rb +1 -5
  107. data/lib/chef/resource.rb +13 -17
  108. data/lib/chef/resource_inspector.rb +6 -2
  109. data/lib/chef/resources.rb +14 -1
  110. data/lib/chef/run_context/cookbook_compiler.rb +112 -28
  111. data/lib/chef/run_context.rb +31 -1
  112. data/lib/chef/secret_fetcher/akeyless_vault.rb +57 -0
  113. data/lib/chef/secret_fetcher/aws_secrets_manager.rb +65 -0
  114. data/lib/chef/secret_fetcher/azure_key_vault.rb +78 -0
  115. data/lib/chef/secret_fetcher/base.rb +76 -0
  116. data/lib/chef/secret_fetcher/example.rb +46 -0
  117. data/lib/chef/secret_fetcher/hashi_vault.rb +100 -0
  118. data/lib/chef/secret_fetcher.rb +61 -0
  119. data/lib/chef/version.rb +1 -1
  120. data/spec/data/archive_file/test_archive.tar.gz +0 -0
  121. data/spec/functional/mixin/from_file_spec.rb +1 -1
  122. data/spec/functional/resource/archive_file_spec.rb +87 -0
  123. data/spec/functional/resource/group_spec.rb +5 -1
  124. data/spec/functional/resource/link_spec.rb +8 -0
  125. data/spec/integration/compliance/compliance_spec.rb +61 -0
  126. data/spec/integration/recipes/recipe_dsl_spec.rb +1 -1
  127. data/spec/integration/recipes/resource_action_spec.rb +6 -6
  128. data/spec/spec_helper.rb +3 -0
  129. data/spec/support/platform_helpers.rb +4 -0
  130. data/spec/support/ruby_installer.rb +51 -0
  131. data/spec/support/shared/unit/provider/file.rb +2 -8
  132. data/spec/unit/compliance/input_spec.rb +104 -0
  133. data/spec/unit/compliance/profile_spec.rb +120 -0
  134. data/spec/unit/compliance/runner_spec.rb +46 -2
  135. data/spec/unit/compliance/waiver_spec.rb +104 -0
  136. data/spec/unit/data_bag_item_spec.rb +2 -2
  137. data/spec/unit/data_bag_spec.rb +1 -1
  138. data/spec/unit/dsl/render_helpers_spec.rb +102 -0
  139. data/spec/unit/dsl/secret_spec.rb +71 -0
  140. data/spec/unit/formatters/doc_spec.rb +1 -1
  141. data/spec/unit/http/basic_client_spec.rb +30 -0
  142. data/spec/unit/http_spec.rb +8 -2
  143. data/spec/unit/policy_builder/dynamic_spec.rb +0 -5
  144. data/spec/unit/policy_builder/policyfile_spec.rb +144 -56
  145. data/spec/unit/provider/apt_update_spec.rb +3 -1
  146. data/spec/unit/provider/link_spec.rb +13 -7
  147. data/spec/unit/provider/mount/aix_spec.rb +1 -1
  148. data/spec/unit/provider/package/powershell_spec.rb +74 -12
  149. data/spec/unit/provider/remote_file/http_spec.rb +10 -0
  150. data/spec/unit/provider/template_spec.rb +2 -2
  151. data/spec/unit/provider_spec.rb +23 -0
  152. data/spec/unit/resource/archive_file_spec.rb +414 -3
  153. data/spec/unit/resource/chef_client_scheduled_task_spec.rb +69 -0
  154. data/spec/unit/resource/file/verification/json_spec.rb +72 -0
  155. data/spec/unit/resource/file/verification/yaml_spec.rb +67 -0
  156. data/spec/unit/resource/homebrew_cask_spec.rb +29 -11
  157. data/spec/unit/resource/inspec_input_spec.rb +300 -0
  158. data/spec/unit/resource/inspec_waiver_spec.rb +312 -0
  159. data/spec/unit/resource/mount_spec.rb +10 -0
  160. data/spec/unit/resource/rhsm_subscription_spec.rb +50 -3
  161. data/spec/unit/resource/systemd_unit_spec.rb +1 -1
  162. data/spec/unit/resource/user_ulimit_spec.rb +14 -1
  163. data/spec/unit/resource/windows_defender_exclusion_spec.rb +62 -0
  164. data/spec/unit/resource/windows_defender_spec.rb +71 -0
  165. data/spec/unit/resource/windows_update_settings_spec.rb +64 -0
  166. data/spec/unit/resource_spec.rb +19 -8
  167. data/spec/unit/secret_fetcher/akeyless_vault_spec.rb +37 -0
  168. data/spec/unit/secret_fetcher/aws_secrets_manager_spec.rb +70 -0
  169. data/spec/unit/secret_fetcher/azure_key_vault_spec.rb +70 -0
  170. data/spec/unit/secret_fetcher/hashi_vault_spec.rb +80 -0
  171. data/spec/unit/secret_fetcher_spec.rb +82 -0
  172. data/tasks/rspec.rb +2 -1
  173. metadata +106 -7
@@ -0,0 +1,104 @@
1
+ #
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 "tempfile"
20
+
21
+ describe Chef::Compliance::Input do
22
+ let(:events) { Chef::EventDispatch::Dispatcher.new }
23
+ let(:data) { { "ssh-01" => { "expiration_date" => Date.jd(2463810), "justification" => "waived, yo", "run" => false } } }
24
+ let(:path) { "/var/chef/cache/cookbooks/acme_compliance/compliance/inputs/default.yml" }
25
+ let(:cookbook_name) { "acme_compliance" }
26
+ let(:input) { Chef::Compliance::Input.new(events, data, path, cookbook_name) }
27
+
28
+ it "has a cookbook_name" do
29
+ expect(input.cookbook_name).to eql(cookbook_name)
30
+ end
31
+
32
+ it "has a path" do
33
+ expect(input.path).to eql(path)
34
+ end
35
+
36
+ it "has a pathname based on the path" do
37
+ expect(input.pathname).to eql("default")
38
+ end
39
+
40
+ it "is disabled" do
41
+ expect(input.enabled).to eql(false)
42
+ expect(input.enabled?).to eql(false)
43
+ end
44
+
45
+ it "has an event handler" do
46
+ expect(input.events).to eql(events)
47
+ end
48
+
49
+ it "can be enabled by enable!" do
50
+ input.enable!
51
+ expect(input.enabled).to eql(true)
52
+ expect(input.enabled?).to eql(true)
53
+ end
54
+
55
+ it "enabling sends an event" do
56
+ expect(events).to receive(:compliance_input_enabled).with(input)
57
+ input.enable!
58
+ end
59
+
60
+ it "can be disabled by disable!" do
61
+ input.enable!
62
+ input.disable!
63
+ expect(input.enabled).to eql(false)
64
+ expect(input.enabled?).to eql(false)
65
+ end
66
+
67
+ it "has a #inspec_data method that renders the data" do
68
+ expect(input.inspec_data).to eql(data)
69
+ end
70
+
71
+ it "doesn't render the events in the inspect output" do
72
+ expect(input.inspect).not_to include("events")
73
+ end
74
+
75
+ it "inflates objects from YAML" do
76
+ string = <<~EOH
77
+ ssh-01:
78
+ expiration_date: 2033-07-31
79
+ run: false
80
+ justification: "waived, yo"
81
+ EOH
82
+ newinput = Chef::Compliance::Input.from_yaml(events, string, path, cookbook_name)
83
+ expect(newinput.data).to eql(data)
84
+ end
85
+
86
+ it "inflates objects from files" do
87
+ string = <<~EOH
88
+ ssh-01:
89
+ expiration_date: 2033-07-31
90
+ run: false
91
+ justification: "waived, yo"
92
+ EOH
93
+ tempfile = Tempfile.new("chef-compliance-test")
94
+ tempfile.write string
95
+ tempfile.close
96
+ newinput = Chef::Compliance::Input.from_file(events, tempfile.path, cookbook_name)
97
+ expect(newinput.data).to eql(data)
98
+ end
99
+
100
+ it "inflates objects from hashes" do
101
+ newinput = Chef::Compliance::Input.from_hash(events, data, path, cookbook_name)
102
+ expect(newinput.data).to eql(data)
103
+ end
104
+ end
@@ -0,0 +1,120 @@
1
+ #
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 "tempfile"
20
+
21
+ describe Chef::Compliance::Profile do
22
+ let(:events) { Chef::EventDispatch::Dispatcher.new }
23
+ let(:data) { { "copyright" => "DevSec Hardening Framework Team", "copyright_email" => "hello@dev-sec.io", "license" => "Apache-2.0", "maintainer" => "DevSec Hardening Framework Team", "name" => "ssh-baseline", "summary" => "Test-suite for best-practice SSH hardening", "supports" => [{ "os-family" => "unix" }], "title" => "DevSec SSH Baseline", "version" => "2.6.4" } }
24
+ let(:path) { "/var/chef/cache/cookbooks/acme_compliance/compliance/profiles/thisdirectoryisnotthename/inspec.yml" }
25
+ let(:cookbook_name) { "acme_compliance" }
26
+ let(:profile) { Chef::Compliance::Profile.new(events, data, path, cookbook_name) }
27
+
28
+ it "has a cookbook_name" do
29
+ expect(profile.cookbook_name).to eql(cookbook_name)
30
+ end
31
+
32
+ it "has a path" do
33
+ expect(profile.path).to eql(path)
34
+ end
35
+
36
+ it "has a name based on the yml" do
37
+ expect(profile.name).to eql("ssh-baseline")
38
+ end
39
+
40
+ it "has a pathname based on the path" do
41
+ expect(profile.pathname).to eql("thisdirectoryisnotthename")
42
+ end
43
+
44
+ it "is disabled" do
45
+ expect(profile.enabled).to eql(false)
46
+ expect(profile.enabled?).to eql(false)
47
+ end
48
+
49
+ it "has an event handler" do
50
+ expect(profile.events).to eql(events)
51
+ end
52
+
53
+ it "can be enabled by enable!" do
54
+ profile.enable!
55
+ expect(profile.enabled).to eql(true)
56
+ expect(profile.enabled?).to eql(true)
57
+ end
58
+
59
+ it "enabling sends an event" do
60
+ expect(events).to receive(:compliance_profile_enabled).with(profile)
61
+ profile.enable!
62
+ end
63
+
64
+ it "can be disabled by disable!" do
65
+ profile.enable!
66
+ profile.disable!
67
+ expect(profile.enabled).to eql(false)
68
+ expect(profile.enabled?).to eql(false)
69
+ end
70
+
71
+ it "has a #inspec_data method that renders the path" do
72
+ expect(profile.inspec_data).to eql( { name: "ssh-baseline", path: "/var/chef/cache/cookbooks/acme_compliance/compliance/profiles/thisdirectoryisnotthename" } )
73
+ end
74
+
75
+ it "doesn't render the events in the inspect output" do
76
+ expect(profile.inspect).not_to include("events")
77
+ end
78
+
79
+ it "inflates objects from YAML" do
80
+ string = <<~EOH
81
+ name: ssh-baseline#{" "}
82
+ title: DevSec SSH Baseline#{" "}
83
+ maintainer: DevSec Hardening Framework Team#{" "}
84
+ copyright: DevSec Hardening Framework Team#{" "}
85
+ copyright_email: hello@dev-sec.io#{" "}
86
+ license: Apache-2.0#{" "}
87
+ summary: Test-suite for best-practice SSH hardening#{" "}
88
+ version: 2.6.4#{" "}
89
+ supports:#{" "}
90
+ - os-family: unix
91
+ EOH
92
+ newprofile = Chef::Compliance::Profile.from_yaml(events, string, path, cookbook_name)
93
+ expect(newprofile.data).to eql(data)
94
+ end
95
+
96
+ it "inflates objects from files" do
97
+ string = <<~EOH
98
+ name: ssh-baseline#{" "}
99
+ title: DevSec SSH Baseline#{" "}
100
+ maintainer: DevSec Hardening Framework Team#{" "}
101
+ copyright: DevSec Hardening Framework Team#{" "}
102
+ copyright_email: hello@dev-sec.io#{" "}
103
+ license: Apache-2.0#{" "}
104
+ summary: Test-suite for best-practice SSH hardening#{" "}
105
+ version: 2.6.4#{" "}
106
+ supports:#{" "}
107
+ - os-family: unix
108
+ EOH
109
+ tempfile = Tempfile.new("chef-compliance-test")
110
+ tempfile.write string
111
+ tempfile.close
112
+ newprofile = Chef::Compliance::Profile.from_file(events, tempfile.path, cookbook_name)
113
+ expect(newprofile.data).to eql(data)
114
+ end
115
+
116
+ it "inflates objects from hashes" do
117
+ newprofile = Chef::Compliance::Profile.from_hash(events, data, path, cookbook_name)
118
+ expect(newprofile.data).to eql(data)
119
+ end
120
+ end
@@ -202,6 +202,16 @@ describe Chef::Compliance::Runner do
202
202
  expect { runner.load_and_validate! }.to raise_error(/^CMPL002:/)
203
203
  end
204
204
 
205
+ it "raises CMPL004 if both the inputs and attributes node attributes are set" do
206
+ node.normal["audit"]["attributes"] = {
207
+ "tacos" => "lunch",
208
+ }
209
+ node.normal["audit"]["inputs"] = {
210
+ "tacos" => "lunch",
211
+ }
212
+ expect { runner.load_and_validate! }.to raise_error(/^CMPL011:/)
213
+ end
214
+
205
215
  it "validates configured reporters" do
206
216
  node.normal["audit"]["reporter"] = [ "chef-automate" ]
207
217
  reporter_double = double("reporter", validate_config!: nil)
@@ -212,6 +222,40 @@ describe Chef::Compliance::Runner do
212
222
  end
213
223
 
214
224
  describe "#inspec_opts" do
225
+ it "pulls inputs from the attributes setting" do
226
+ node.normal["audit"]["attributes"] = {
227
+ "tacos" => "lunch",
228
+ }
229
+
230
+ inputs = runner.inspec_opts[:inputs]
231
+
232
+ expect(inputs["tacos"]).to eq("lunch")
233
+ end
234
+
235
+ it "pulls inputs from the inputs setting" do
236
+ node.normal["audit"]["inputs"] = {
237
+ "tacos" => "lunch",
238
+ }
239
+
240
+ inputs = runner.inspec_opts[:inputs]
241
+
242
+ expect(inputs["tacos"]).to eq("lunch")
243
+ end
244
+
245
+ it "favors inputs over attributes" do
246
+ node.normal["audit"]["attributes"] = {
247
+ "tacos" => "dinner",
248
+ }
249
+
250
+ node.normal["audit"]["inputs"] = {
251
+ "tacos" => "lunch",
252
+ }
253
+
254
+ inputs = runner.inspec_opts[:inputs]
255
+
256
+ expect(inputs["tacos"]).to eq("lunch")
257
+ end
258
+
215
259
  it "does not include chef_node in inputs by default" do
216
260
  node.normal["audit"]["attributes"] = {
217
261
  "tacos" => "lunch",
@@ -221,7 +265,7 @@ describe Chef::Compliance::Runner do
221
265
  inputs = runner.inspec_opts[:inputs]
222
266
 
223
267
  expect(inputs["tacos"]).to eq("lunch")
224
- expect(inputs.key?("chef_node")).to eq(false)
268
+ expect(inputs.key?("chef_node")).to eq(true)
225
269
  end
226
270
 
227
271
  it "includes chef_node in inputs with chef_node_attribute_enabled set" do
@@ -234,7 +278,7 @@ describe Chef::Compliance::Runner do
234
278
  inputs = runner.inspec_opts[:inputs]
235
279
 
236
280
  expect(inputs["tacos"]).to eq("lunch")
237
- expect(inputs["chef_node"]["audit"]["reporter"]).to eq(%w{json-file cli})
281
+ expect(inputs["chef_node"]["audit"]["reporter"]).to eq("cli")
238
282
  expect(inputs["chef_node"]["chef_environment"]).to eq("_default")
239
283
  end
240
284
  end
@@ -0,0 +1,104 @@
1
+ #
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 "tempfile"
20
+
21
+ describe Chef::Compliance::Waiver do
22
+ let(:events) { Chef::EventDispatch::Dispatcher.new }
23
+ let(:data) { { "ssh-01" => { "expiration_date" => Date.jd(2463810), "justification" => "waived, yo", "run" => false } } }
24
+ let(:path) { "/var/chef/cache/cookbooks/acme_compliance/compliance/waivers/default.yml" }
25
+ let(:cookbook_name) { "acme_compliance" }
26
+ let(:waiver) { Chef::Compliance::Waiver.new(events, data, path, cookbook_name) }
27
+
28
+ it "has a cookbook_name" do
29
+ expect(waiver.cookbook_name).to eql(cookbook_name)
30
+ end
31
+
32
+ it "has a path" do
33
+ expect(waiver.path).to eql(path)
34
+ end
35
+
36
+ it "has a pathname based on the path" do
37
+ expect(waiver.pathname).to eql("default")
38
+ end
39
+
40
+ it "is disabled" do
41
+ expect(waiver.enabled).to eql(false)
42
+ expect(waiver.enabled?).to eql(false)
43
+ end
44
+
45
+ it "has an event handler" do
46
+ expect(waiver.events).to eql(events)
47
+ end
48
+
49
+ it "can be enabled by enable!" do
50
+ waiver.enable!
51
+ expect(waiver.enabled).to eql(true)
52
+ expect(waiver.enabled?).to eql(true)
53
+ end
54
+
55
+ it "enabling sends an event" do
56
+ expect(events).to receive(:compliance_waiver_enabled).with(waiver)
57
+ waiver.enable!
58
+ end
59
+
60
+ it "can be disabled by disable!" do
61
+ waiver.enable!
62
+ waiver.disable!
63
+ expect(waiver.enabled).to eql(false)
64
+ expect(waiver.enabled?).to eql(false)
65
+ end
66
+
67
+ it "has a #inspec_data method that renders the data" do
68
+ expect(waiver.inspec_data).to eql(data)
69
+ end
70
+
71
+ it "doesn't render the events in the inspect output" do
72
+ expect(waiver.inspect).not_to include("events")
73
+ end
74
+
75
+ it "inflates objects from YAML" do
76
+ string = <<~EOH
77
+ ssh-01:
78
+ expiration_date: 2033-07-31
79
+ run: false
80
+ justification: "waived, yo"
81
+ EOH
82
+ newwaiver = Chef::Compliance::Waiver.from_yaml(events, string, path, cookbook_name)
83
+ expect(newwaiver.data).to eql(data)
84
+ end
85
+
86
+ it "inflates objects from files" do
87
+ string = <<~EOH
88
+ ssh-01:
89
+ expiration_date: 2033-07-31
90
+ run: false
91
+ justification: "waived, yo"
92
+ EOH
93
+ tempfile = Tempfile.new("chef-compliance-test")
94
+ tempfile.write string
95
+ tempfile.close
96
+ newwaiver = Chef::Compliance::Waiver.from_file(events, tempfile.path, cookbook_name)
97
+ expect(newwaiver.data).to eql(data)
98
+ end
99
+
100
+ it "inflates objects from hashes" do
101
+ newwaiver = Chef::Compliance::Waiver.from_hash(events, data, path, cookbook_name)
102
+ expect(newwaiver.data).to eql(data)
103
+ end
104
+ end
@@ -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" } }.to raise_error(ArgumentError)
76
+ expect { data_bag_item.raw_data = { "id" => "foo.bar" } }.not_to raise_error
77
77
  end
78
78
 
79
79
  it "should accept .alphanum for the id" do
80
- expect { data_bag_item.raw_data = { "id" => ".bozo" } }.to raise_error(ArgumentError)
80
+ expect { data_bag_item.raw_data = { "id" => ".bozo" } }.not_to raise_error
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
@@ -0,0 +1,102 @@
1
+ #
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/dsl/render_helpers"
20
+
21
+ describe Chef::DSL::RenderHelpers do
22
+
23
+ hash = {
24
+ "golf": "hotel",
25
+ "kilo": %w{lima mike},
26
+ "india": {
27
+ "juliett": "blue",
28
+ },
29
+ "alpha": {
30
+ "charlie": true,
31
+ "bravo": 10,
32
+ },
33
+ "echo": "foxtrot",
34
+ }
35
+
36
+ context "render_json" do
37
+ json = Chef::DSL::RenderHelpers.render_json(hash)
38
+ describe "JSON content" do
39
+ it "expected JSON output" do
40
+ expected = <<-EXPECTED
41
+ {
42
+ "golf": "hotel",
43
+ "kilo": [
44
+ "lima",
45
+ "mike"
46
+ ],
47
+ "india": {
48
+ "juliett": "blue"
49
+ },
50
+ "alpha": {
51
+ "charlie": true,
52
+ "bravo": 10
53
+ },
54
+ "echo": "foxtrot"
55
+ }
56
+ EXPECTED
57
+ expect(json).to eq(expected)
58
+ end
59
+ end
60
+ end
61
+
62
+ context "render_toml" do
63
+ toml = Chef::DSL::RenderHelpers.render_toml(hash)
64
+ describe "TOML content" do
65
+ it "expected TOML output" do
66
+ expected = <<-EXPECTED
67
+ echo = "foxtrot"
68
+ golf = "hotel"
69
+ kilo = ["lima", "mike"]
70
+ [alpha]
71
+ bravo = 10
72
+ charlie = true
73
+ [india]
74
+ juliett = "blue"
75
+ EXPECTED
76
+ expect(toml).to eq(expected)
77
+ end
78
+ end
79
+ end
80
+
81
+ context "render_yaml" do
82
+ yaml = Chef::DSL::RenderHelpers.render_yaml(hash)
83
+ describe "YAML content" do
84
+ it "expected YAML output" do
85
+ expected = <<-EXPECTED
86
+ ---
87
+ golf: hotel
88
+ kilo:
89
+ - lima
90
+ - mike
91
+ india:
92
+ juliett: blue
93
+ alpha:
94
+ charlie: true
95
+ bravo: 10
96
+ echo: foxtrot
97
+ EXPECTED
98
+ expect(yaml).to eq(expected)
99
+ end
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,71 @@
1
+ #
2
+ # Author:: Marc Paradise <marc@chef.io>
3
+ # Copyright:: Copyright (c) Chef Software Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require "spec_helper"
20
+ require "chef/dsl/secret"
21
+ require "chef/secret_fetcher/base"
22
+ class SecretDSLTester
23
+ include Chef::DSL::Secret
24
+ # Because DSL is invoked in the context of a recipe,
25
+ # we expect run_context to always be available when SecretFetcher::Base
26
+ # requests it - making it safe to mock here
27
+ def run_context
28
+ nil
29
+ end
30
+ end
31
+
32
+ class SecretFetcherImpl < Chef::SecretFetcher::Base
33
+ def do_fetch(name, version)
34
+ name
35
+ end
36
+ end
37
+
38
+ describe Chef::DSL::Secret do
39
+ let(:dsl) { SecretDSLTester.new }
40
+ it "responds to 'secret'" do
41
+ expect(dsl.respond_to?(:secret)).to eq true
42
+ end
43
+
44
+ it "uses SecretFetcher.for_service to find the fetcher" do
45
+ substitute_fetcher = SecretFetcherImpl.new({}, nil)
46
+ expect(Chef::SecretFetcher).to receive(:for_service).with(:example, {}, nil).and_return(substitute_fetcher)
47
+ expect(substitute_fetcher).to receive(:fetch).with("key1", nil)
48
+ dsl.secret(name: "key1", service: :example, config: {})
49
+ end
50
+
51
+ it "resolves a secret when using the example fetcher" do
52
+ secret_value = dsl.secret(name: "test1", service: :example, config: { "test1" => "secret value" })
53
+ expect(secret_value).to eq "secret value"
54
+ end
55
+
56
+ context "when used within a resource" do
57
+ let(:run_context) {
58
+ Chef::RunContext.new(Chef::Node.new,
59
+ Chef::CookbookCollection.new(Chef::CookbookLoader.new(File.join(CHEF_SPEC_DATA, "cookbooks"))),
60
+ Chef::EventDispatch::Dispatcher.new)
61
+ }
62
+
63
+ it "marks that resource as 'sensitive'" do
64
+ recipe = Chef::Recipe.new("secrets", "test", run_context)
65
+ recipe.zen_master "secret_test" do
66
+ peace secret(name: "test1", service: :example, config: { "test1" => true })
67
+ end
68
+ expect(run_context.resource_collection.lookup("zen_master[secret_test]").sensitive).to eql(true)
69
+ end
70
+ end
71
+ end
@@ -40,7 +40,7 @@ describe Chef::Formatters::Base do
40
40
  }
41
41
 
42
42
  formatter.policyfile_loaded(minimal_policyfile)
43
- expect(out.string).to include("Using policy 'jenkins' at revision '613f803bdd035d574df7fa6da525b38df45a74ca82b38b79655efed8a189e073'")
43
+ expect(out.string).to include("Using Policyfile 'jenkins' at revision '613f803bdd035d574df7fa6da525b38df45a74ca82b38b79655efed8a189e073'")
44
44
  end
45
45
 
46
46
  it "prints cookbook name and version" do
@@ -47,6 +47,36 @@ describe "HTTP Connection" do
47
47
  expect(Net::HTTP).to receive(:new).and_return(net_http_mock)
48
48
  expect(basic_client.http_client).to eql(net_http_mock)
49
49
  end
50
+
51
+ it "allows setting net-http accessor options" do
52
+ basic_client = Chef::HTTP::BasicClient.new(uri, nethttp_opts: {
53
+ "continue_timeout" => 5,
54
+ "max_retries" => 5,
55
+ "read_timeout" => 5,
56
+ "write_timeout" => 5,
57
+ "ssl_timeout" => 5,
58
+ })
59
+ expect(basic_client.http_client.continue_timeout).to eql(5)
60
+ expect(basic_client.http_client.max_retries).to eql(5)
61
+ expect(basic_client.http_client.read_timeout).to eql(5)
62
+ expect(basic_client.http_client.write_timeout).to eql(5)
63
+ expect(basic_client.http_client.ssl_timeout).to eql(5)
64
+ end
65
+
66
+ it "allows setting net-http accssor options as symbols" do
67
+ basic_client = Chef::HTTP::BasicClient.new(uri, nethttp_opts: {
68
+ continue_timeout: 5,
69
+ max_retries: 5,
70
+ read_timeout: 5,
71
+ write_timeout: 5,
72
+ ssl_timeout: 5,
73
+ })
74
+ expect(basic_client.http_client.continue_timeout).to eql(5)
75
+ expect(basic_client.http_client.max_retries).to eql(5)
76
+ expect(basic_client.http_client.read_timeout).to eql(5)
77
+ expect(basic_client.http_client.write_timeout).to eql(5)
78
+ expect(basic_client.http_client.ssl_timeout).to eql(5)
79
+ end
50
80
  end
51
81
 
52
82
  describe "#build_http_client" do
@@ -46,13 +46,19 @@ describe Chef::HTTP do
46
46
  describe "#initialize" do
47
47
  it "accepts a keepalive option and passes it to the http_client" do
48
48
  http = Chef::HTTP.new(uri, keepalives: true)
49
- expect(Chef::HTTP::BasicClient).to receive(:new).with(uri, ssl_policy: Chef::HTTP::APISSLPolicy, keepalives: true).and_call_original
49
+ expect(Chef::HTTP::BasicClient).to receive(:new).with(uri, ssl_policy: Chef::HTTP::APISSLPolicy, nethttp_opts: {}, keepalives: true).and_call_original
50
50
  expect(http.http_client).to be_a_kind_of(Chef::HTTP::BasicClient)
51
51
  end
52
52
 
53
53
  it "the default is not to use keepalives" do
54
54
  http = Chef::HTTP.new(uri)
55
- expect(Chef::HTTP::BasicClient).to receive(:new).with(uri, ssl_policy: Chef::HTTP::APISSLPolicy, keepalives: false).and_call_original
55
+ expect(Chef::HTTP::BasicClient).to receive(:new).with(uri, ssl_policy: Chef::HTTP::APISSLPolicy, nethttp_opts: {}, keepalives: false).and_call_original
56
+ expect(http.http_client).to be_a_kind_of(Chef::HTTP::BasicClient)
57
+ end
58
+
59
+ it "allows setting the nethttp options hash" do
60
+ http = Chef::HTTP.new(uri, { nethttp: { "continue_timeout" => 5 } })
61
+ expect(Chef::HTTP::BasicClient).to receive(:new).with(uri, ssl_policy: Chef::HTTP::APISSLPolicy, nethttp_opts: { "continue_timeout" => 5 }, keepalives: false).and_call_original
56
62
  expect(http.http_client).to be_a_kind_of(Chef::HTTP::BasicClient)
57
63
  end
58
64
  end
@@ -55,11 +55,6 @@ describe Chef::PolicyBuilder::Dynamic do
55
55
  expect(policy_builder).to respond_to(:load_node)
56
56
  end
57
57
 
58
- it "forwards #original_runlist" do
59
- expect(implementation).to receive(:original_runlist)
60
- policy_builder.original_runlist
61
- end
62
-
63
58
  it "forwards #run_context" do
64
59
  expect(implementation).to receive(:run_context)
65
60
  policy_builder.run_context