chef 17.1.35-universal-mingw32 → 17.4.38-universal-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (198) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +6 -4
  3. data/chef.gemspec +1 -0
  4. data/lib/chef/action_collection.rb +6 -26
  5. data/lib/chef/application/base.rb +15 -0
  6. data/lib/chef/application.rb +4 -2
  7. data/lib/chef/client.rb +7 -1
  8. data/lib/chef/compliance/default_attributes.rb +5 -3
  9. data/lib/chef/compliance/reporter/automate.rb +1 -1
  10. data/lib/chef/compliance/runner.rb +16 -2
  11. data/lib/chef/cookbook_version.rb +26 -4
  12. data/lib/chef/data_collector/run_end_message.rb +1 -1
  13. data/lib/chef/data_collector.rb +0 -1
  14. data/lib/chef/deprecated.rb +14 -4
  15. data/lib/chef/dsl/render_helpers.rb +44 -0
  16. data/lib/chef/dsl/secret.rb +64 -0
  17. data/lib/chef/dsl/toml.rb +116 -0
  18. data/lib/chef/dsl/universal.rb +5 -0
  19. data/lib/chef/dsl.rb +1 -0
  20. data/lib/chef/event_dispatch/base.rb +2 -1
  21. data/lib/chef/exceptions.rb +23 -0
  22. data/lib/chef/formatters/doc.rb +14 -13
  23. data/lib/chef/formatters/error_mapper.rb +2 -2
  24. data/lib/chef/formatters/minimal.rb +6 -5
  25. data/lib/chef/handler/slow_report.rb +66 -0
  26. data/lib/chef/handler.rb +46 -8
  27. data/lib/chef/http.rb +5 -5
  28. data/lib/chef/json_compat.rb +1 -1
  29. data/lib/chef/node.rb +20 -19
  30. data/lib/chef/policy_builder/policyfile.rb +88 -45
  31. data/lib/chef/provider/execute.rb +1 -1
  32. data/lib/chef/provider/file.rb +2 -2
  33. data/lib/chef/provider/group/dscl.rb +1 -1
  34. data/lib/chef/provider/launchd.rb +6 -6
  35. data/lib/chef/provider/lwrp_base.rb +1 -1
  36. data/lib/chef/provider/package/habitat.rb +168 -0
  37. data/lib/chef/provider/package/powershell.rb +5 -0
  38. data/lib/chef/provider/subversion.rb +4 -4
  39. data/lib/chef/provider/support/yum_repo.erb +1 -1
  40. data/lib/chef/provider/support/zypper_repo.erb +4 -2
  41. data/lib/chef/provider/systemd_unit.rb +17 -16
  42. data/lib/chef/provider/user/mac.rb +3 -3
  43. data/lib/chef/provider/yum_repository.rb +27 -43
  44. data/lib/chef/provider/zypper_repository.rb +30 -34
  45. data/lib/chef/provider.rb +26 -1
  46. data/lib/chef/provider_resolver.rb +8 -2
  47. data/lib/chef/providers.rb +1 -0
  48. data/lib/chef/resource/alternatives.rb +5 -5
  49. data/lib/chef/resource/apt_preference.rb +2 -2
  50. data/lib/chef/resource/apt_repository.rb +2 -2
  51. data/lib/chef/resource/apt_update.rb +4 -4
  52. data/lib/chef/resource/build_essential.rb +1 -1
  53. data/lib/chef/resource/chef_client_config.rb +10 -5
  54. data/lib/chef/resource/chef_client_cron.rb +3 -3
  55. data/lib/chef/resource/chef_client_launchd.rb +3 -3
  56. data/lib/chef/resource/chef_client_scheduled_task.rb +15 -15
  57. data/lib/chef/resource/chef_client_systemd_timer.rb +3 -3
  58. data/lib/chef/resource/chef_client_trusted_certificate.rb +2 -2
  59. data/lib/chef/resource/chef_handler.rb +2 -2
  60. data/lib/chef/resource/chef_sleep.rb +1 -1
  61. data/lib/chef/resource/chef_vault_secret.rb +2 -2
  62. data/lib/chef/resource/chocolatey_feature.rb +2 -2
  63. data/lib/chef/resource/chocolatey_source.rb +1 -1
  64. data/lib/chef/resource/cron/cron_d.rb +4 -6
  65. data/lib/chef/resource/cron_access.rb +1 -1
  66. data/lib/chef/resource/dmg_package.rb +1 -1
  67. data/lib/chef/resource/dsc_resource.rb +1 -1
  68. data/lib/chef/resource/execute.rb +5 -5
  69. data/lib/chef/resource/gem_package.rb +2 -1
  70. data/lib/chef/resource/group.rb +4 -4
  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 +18 -7
  81. data/lib/chef/resource/homebrew_package.rb +1 -1
  82. data/lib/chef/resource/homebrew_tap.rb +4 -3
  83. data/lib/chef/resource/homebrew_update.rb +2 -2
  84. data/lib/chef/resource/hostname.rb +49 -7
  85. data/lib/chef/resource/inspec_waiver_file_entry.rb +8 -7
  86. data/lib/chef/resource/kernel_module.rb +6 -6
  87. data/lib/chef/resource/launchd.rb +3 -3
  88. data/lib/chef/resource/locale.rb +1 -1
  89. data/lib/chef/resource/lwrp_base.rb +1 -1
  90. data/lib/chef/resource/macos_userdefaults.rb +2 -2
  91. data/lib/chef/resource/ohai_hint.rb +2 -6
  92. data/lib/chef/resource/openbsd_package.rb +17 -0
  93. data/lib/chef/resource/openssl_dhparam.rb +1 -2
  94. data/lib/chef/resource/openssl_ec_private_key.rb +1 -3
  95. data/lib/chef/resource/openssl_ec_public_key.rb +1 -3
  96. data/lib/chef/resource/openssl_rsa_private_key.rb +1 -3
  97. data/lib/chef/resource/openssl_rsa_public_key.rb +1 -3
  98. data/lib/chef/resource/openssl_x509_certificate.rb +1 -4
  99. data/lib/chef/resource/openssl_x509_crl.rb +1 -3
  100. data/lib/chef/resource/openssl_x509_request.rb +1 -3
  101. data/lib/chef/resource/osx_profile.rb +3 -3
  102. data/lib/chef/resource/plist.rb +1 -1
  103. data/lib/chef/resource/powershell_package_source.rb +2 -4
  104. data/lib/chef/resource/reboot.rb +38 -9
  105. data/lib/chef/resource/remote_directory.rb +2 -2
  106. data/lib/chef/resource/remote_file.rb +1 -1
  107. data/lib/chef/resource/rhsm_errata.rb +0 -2
  108. data/lib/chef/resource/rhsm_errata_level.rb +1 -5
  109. data/lib/chef/resource/rhsm_repo.rb +15 -0
  110. data/lib/chef/resource/rhsm_subscription.rb +5 -5
  111. data/lib/chef/resource/ruby_block.rb +100 -0
  112. data/lib/chef/resource/scm/subversion.rb +1 -1
  113. data/lib/chef/resource/ssh_known_hosts_entry.rb +4 -7
  114. data/lib/chef/resource/sudo.rb +2 -6
  115. data/lib/chef/resource/support/HabService.dll.config.erb +19 -0
  116. data/lib/chef/resource/support/client.erb +8 -1
  117. data/lib/chef/resource/support/sup.toml.erb +179 -0
  118. data/lib/chef/resource/swap_file.rb +2 -6
  119. data/lib/chef/resource/sysctl.rb +2 -2
  120. data/lib/chef/resource/systemd_unit.rb +3 -3
  121. data/lib/chef/resource/timezone.rb +1 -1
  122. data/lib/chef/resource/user_ulimit.rb +2 -2
  123. data/lib/chef/resource/windows_ad_join.rb +2 -2
  124. data/lib/chef/resource/windows_audit_policy.rb +2 -2
  125. data/lib/chef/resource/windows_auto_run.rb +2 -2
  126. data/lib/chef/resource/windows_certificate.rb +1 -1
  127. data/lib/chef/resource/windows_defender.rb +163 -0
  128. data/lib/chef/resource/windows_defender_exclusion.rb +125 -0
  129. data/lib/chef/resource/windows_dfs_folder.rb +2 -2
  130. data/lib/chef/resource/windows_dfs_namespace.rb +2 -2
  131. data/lib/chef/resource/windows_dns_record.rb +2 -2
  132. data/lib/chef/resource/windows_dns_zone.rb +2 -2
  133. data/lib/chef/resource/windows_feature.rb +3 -3
  134. data/lib/chef/resource/windows_feature_dism.rb +3 -5
  135. data/lib/chef/resource/windows_feature_powershell.rb +3 -3
  136. data/lib/chef/resource/windows_firewall_profile.rb +2 -2
  137. data/lib/chef/resource/windows_firewall_rule.rb +20 -6
  138. data/lib/chef/resource/windows_font.rb +1 -1
  139. data/lib/chef/resource/windows_pagefile.rb +103 -64
  140. data/lib/chef/resource/windows_path.rb +2 -2
  141. data/lib/chef/resource/windows_printer.rb +80 -61
  142. data/lib/chef/resource/windows_printer_port.rb +48 -65
  143. data/lib/chef/resource/windows_security_policy.rb +2 -2
  144. data/lib/chef/resource/windows_share.rb +2 -2
  145. data/lib/chef/resource/windows_shortcut.rb +1 -1
  146. data/lib/chef/resource/windows_task.rb +1 -1
  147. data/lib/chef/resource/windows_uac.rb +3 -5
  148. data/lib/chef/resource/windows_update_settings.rb +259 -0
  149. data/lib/chef/resource/windows_user_privilege.rb +2 -2
  150. data/lib/chef/resource/windows_workgroup.rb +2 -2
  151. data/lib/chef/resource/yum_package.rb +11 -15
  152. data/lib/chef/resource/zypper_package.rb +4 -4
  153. data/lib/chef/resource/zypper_repository.rb +28 -8
  154. data/lib/chef/resource.rb +13 -17
  155. data/lib/chef/resource_inspector.rb +6 -2
  156. data/lib/chef/resource_reporter.rb +0 -1
  157. data/lib/chef/resources.rb +12 -1
  158. data/lib/chef/secret_fetcher/aws_secrets_manager.rb +65 -0
  159. data/lib/chef/secret_fetcher/azure_key_vault.rb +78 -0
  160. data/lib/chef/secret_fetcher/base.rb +76 -0
  161. data/lib/chef/secret_fetcher/example.rb +46 -0
  162. data/lib/chef/secret_fetcher.rb +55 -0
  163. data/lib/chef/version.rb +1 -1
  164. data/spec/functional/mixin/from_file_spec.rb +1 -1
  165. data/spec/functional/resource/windows_hostname_spec.rb +91 -0
  166. data/spec/functional/resource/windows_pagefile_spec.rb +98 -0
  167. data/spec/integration/compliance/compliance_spec.rb +1 -0
  168. data/spec/integration/recipes/recipe_dsl_spec.rb +1 -1
  169. data/spec/integration/recipes/resource_action_spec.rb +6 -6
  170. data/spec/support/shared/unit/provider/file.rb +2 -8
  171. data/spec/unit/compliance/runner_spec.rb +46 -2
  172. data/spec/unit/cookbook_version_spec.rb +52 -0
  173. data/spec/unit/data_collector_spec.rb +47 -1
  174. data/spec/unit/dsl/render_helpers_spec.rb +102 -0
  175. data/spec/unit/dsl/secret_spec.rb +71 -0
  176. data/spec/unit/formatters/doc_spec.rb +1 -1
  177. data/spec/unit/handler_spec.rb +8 -2
  178. data/spec/unit/policy_builder/dynamic_spec.rb +0 -5
  179. data/spec/unit/policy_builder/policyfile_spec.rb +144 -56
  180. data/spec/unit/provider/apt_update_spec.rb +3 -1
  181. data/spec/unit/provider/mount/aix_spec.rb +1 -1
  182. data/spec/unit/provider/package/powershell_spec.rb +74 -12
  183. data/spec/unit/provider/zypper_repository_spec.rb +3 -10
  184. data/spec/unit/provider_spec.rb +23 -0
  185. data/spec/unit/resource/homebrew_cask_spec.rb +29 -11
  186. data/spec/unit/resource/rhsm_subscription_spec.rb +50 -3
  187. data/spec/unit/resource/systemd_unit_spec.rb +1 -1
  188. data/spec/unit/resource/windows_defender_exclusion_spec.rb +62 -0
  189. data/spec/unit/resource/windows_defender_spec.rb +71 -0
  190. data/spec/unit/resource/windows_firewall_rule_spec.rb +12 -7
  191. data/spec/unit/resource/windows_pagefile_spec.rb +4 -9
  192. data/spec/unit/resource/windows_update_settings_spec.rb +64 -0
  193. data/spec/unit/resource/zypper_repository_spec.rb +1 -1
  194. data/spec/unit/resource_spec.rb +19 -8
  195. data/spec/unit/secret_fetcher/aws_secrets_manager_spec.rb +70 -0
  196. data/spec/unit/secret_fetcher/azure_key_vault_spec.rb +70 -0
  197. data/spec/unit/secret_fetcher_spec.rb +82 -0
  198. metadata +55 -7
@@ -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
@@ -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
@@ -72,40 +72,40 @@ describe Chef::PolicyBuilder::Policyfile do
72
72
 
73
73
  let(:policyfile_default_attributes) do
74
74
  {
75
- "policyfile_default_attr" => "policyfile_default_value",
76
- "top_level_attr" => "hat",
77
- "baseline_attr" => {
78
- "one" => 1,
79
- "two" => 2,
80
- "deep" => {
81
- "three" => 3,
82
- "four" => [4],
83
- "five" => [5],
84
- },
75
+ "policyfile_default_attr" => "policyfile_default_value",
76
+ "top_level_attr" => "hat",
77
+ "baseline_attr" => {
78
+ "one" => 1,
79
+ "two" => 2,
80
+ "deep" => {
81
+ "three" => 3,
82
+ "four" => [4],
83
+ "five" => [5],
85
84
  },
86
- "policy_group_value" => {
87
- "baseline_attr" => {
88
- "one" => 111,
89
- },
85
+ },
86
+ "policy_group_value" => {
87
+ "baseline_attr" => {
88
+ "one" => 111,
90
89
  },
91
- }
90
+ },
91
+ }
92
92
  end
93
93
 
94
94
  let(:policyfile_override_attributes) do
95
95
  {
96
- "policyfile_override_attr" => "policyfile_override_value",
97
- "baseline_attr" => {
98
- "deep" => {
99
- "three" => 333 },
100
- },
101
- "policy_group_value" => {
102
- "top_level_attr" => "cat",
103
- "baseline_attr" => {
104
- "deep" => {
105
- "four" => [444],
106
- },
107
- },
108
- },
96
+ "policyfile_override_attr" => "policyfile_override_value",
97
+ "baseline_attr" => {
98
+ "deep" => {
99
+ "three" => 333 },
100
+ },
101
+ "policy_group_value" => {
102
+ "top_level_attr" => "cat",
103
+ "baseline_attr" => {
104
+ "deep" => {
105
+ "four" => [444],
106
+ },
107
+ },
108
+ },
109
109
  }
110
110
  end
111
111
 
@@ -146,10 +146,6 @@ describe Chef::PolicyBuilder::Policyfile do
146
146
  Chef::PolicyBuilder::Policyfile.new(node_name, ohai_data, json_attribs, override_runlist, events)
147
147
  end
148
148
 
149
- it "always gives `false` for #temporary_policy?" do
150
- expect(initialize_pb.temporary_policy?).to be_falsey
151
- end
152
-
153
149
  context "chef-solo" do
154
150
  before { Chef::Config[:solo_legacy_mode] = true }
155
151
 
@@ -161,16 +157,8 @@ describe Chef::PolicyBuilder::Policyfile do
161
157
  context "when given an override run_list" do
162
158
  let(:override_runlist) { "recipe[foo],recipe[bar]" }
163
159
 
164
- it "errors on create" do
165
- expect { initialize_pb }.to raise_error(err_namespace::UnsupportedFeature)
166
- end
167
- end
168
-
169
- context "when json_attribs contains a run_list" do
170
- let(:json_attribs) { { "run_list" => [] } }
171
-
172
- it "errors on create" do
173
- expect { initialize_pb }.to raise_error(err_namespace::UnsupportedFeature)
160
+ it "does not error" do
161
+ expect { initialize_pb }.not_to raise_error
174
162
  end
175
163
  end
176
164
 
@@ -206,7 +194,7 @@ describe Chef::PolicyBuilder::Policyfile do
206
194
  end
207
195
 
208
196
  before do
209
- Chef::Config[:policy_document_native_api] = false
197
+ Chef::Config[:policy_document_native_api] = true
210
198
  Chef::Config[:deployment_group] = "example-policy-stage"
211
199
  allow(policy_builder).to receive(:api_service).and_return(api_service)
212
200
  end
@@ -214,6 +202,8 @@ describe Chef::PolicyBuilder::Policyfile do
214
202
  describe "when using compatibility mode (policy_document_native_api == false)" do
215
203
 
216
204
  before do
205
+ Chef::Config[:policy_document_native_api] = false
206
+ Chef::Config[:treat_deprecation_warnings_as_errors] = false
217
207
  Chef::Config[:deployment_group] = "example-policy-stage"
218
208
  end
219
209
 
@@ -323,7 +313,7 @@ describe Chef::PolicyBuilder::Policyfile do
323
313
  "example2::server@4.2.0 (feab40e)",
324
314
  ]
325
315
 
326
- expect(policy_builder.run_list_with_versions_for_display).to eq(expected)
316
+ expect(policy_builder.run_list_with_versions_for_display(policy_builder.run_list)).to eq(expected)
327
317
  end
328
318
 
329
319
  it "generates a RunListExpansion-alike object for feeding to the CookbookCompiler" do
@@ -339,15 +329,19 @@ describe Chef::PolicyBuilder::Policyfile do
339
329
  end
340
330
 
341
331
  describe "validating the Policyfile.lock" do
332
+ before do
333
+ Chef::Config[:policy_group] = "policy-stage"
334
+ Chef::Config[:policy_name] = "example"
335
+ end
342
336
 
343
337
  it "errors if the policyfile json contains any non-recipe items" do
344
338
  parsed_policyfile_json["run_list"] = ["role[foo]"]
345
339
  expect { policy_builder.validate_policyfile }.to raise_error(err_namespace::PolicyfileError)
346
340
  end
347
341
 
348
- it "errors if the policyfile json contains non-fully qualified recipe items" do
342
+ it "does not error if the policyfile json contains non-fully qualified recipe items" do
349
343
  parsed_policyfile_json["run_list"] = ["recipe[foo]"]
350
- expect { policy_builder.validate_policyfile }.to raise_error(err_namespace::PolicyfileError)
344
+ expect { policy_builder.validate_policyfile }.not_to raise_error
351
345
  end
352
346
 
353
347
  it "errors if the policyfile doesn't have a run_list key" do
@@ -395,8 +389,8 @@ describe Chef::PolicyBuilder::Policyfile do
395
389
  {
396
390
  id: "_policy_node",
397
391
  run_list: [
398
- { type: "recipe", name: "test::default", skipped: false, version: nil },
399
- { type: "recipe", name: "test::other", skipped: false, version: nil },
392
+ { type: "recipe", name: "test::default", skipped: false, version: nil },
393
+ { type: "recipe", name: "test::other", skipped: false, version: nil },
400
394
  ],
401
395
  }
402
396
  end
@@ -577,11 +571,9 @@ describe Chef::PolicyBuilder::Policyfile do
577
571
  expect(node.automatic_attrs[:policy_name]).to eq("policy_name_from_node_json")
578
572
  expect(node.automatic_attrs[:policy_group]).to eq("policy_group_from_node_json")
579
573
  expect(node.automatic_attrs[:chef_environment]).to eq("policy_group_from_node_json")
580
-
581
574
  end
582
575
 
583
576
  end
584
-
585
577
  end
586
578
 
587
579
  it "resets default and override data" do
@@ -664,18 +656,29 @@ describe Chef::PolicyBuilder::Policyfile do
664
656
  expect(policy_builder.run_list).to eq([ "recipe[example1::default]" ])
665
657
  expected_expansion = Chef::PolicyBuilder::Policyfile::RunListExpansionIsh.new([ "example1::default" ], [])
666
658
  expect(policy_builder.run_list_expansion).to eq(expected_expansion)
667
- expect(policy_builder.run_list_with_versions_for_display).to eq(["example1::default@2.3.5 (168d210)"])
659
+ expect(policy_builder.run_list_with_versions_for_display(policy_builder.run_list)).to eq(["example1::default@2.3.5 (168d210)"])
668
660
  expect(node.run_list).to eq([ Chef::RunList::RunListItem.new("recipe[example1::default]") ])
669
661
  expect(node[:roles]).to eq( [] )
670
662
  expect(node[:recipes]).to eq( ["example1::default"] )
671
663
  end
672
664
 
673
- it "disables the cookbook cache cleaner" do
674
- expect(Chef::CookbookCacheCleaner.instance.skip_removal).to be(true)
675
- end
665
+ end
666
+ end
667
+
668
+ context "when an override run_list is given" do
669
+ let(:override_runlist) { [ "recipe[example2::server]" ] }
676
670
 
671
+ before do
672
+ policy_builder.build_node
677
673
  end
678
674
 
675
+ it "gives `true` for #temporary_policy?" do
676
+ expect(policy_builder.temporary_policy?).to be true
677
+ end
678
+
679
+ it "returns the override_runlist for the run_list" do
680
+ expect(policy_builder.run_list).to eql override_runlist
681
+ end
679
682
  end
680
683
 
681
684
  describe "hoisting attribute values" do
@@ -806,6 +809,10 @@ describe Chef::PolicyBuilder::Policyfile do
806
809
  context "when using compatibility mode (policy_document_native_api == false)" do
807
810
  let(:cookbook1_url) { "cookbooks/example1/#{example1_xyz_version}" }
808
811
  let(:cookbook2_url) { "cookbooks/example2/#{example2_xyz_version}" }
812
+ before do
813
+ Chef::Config[:policy_document_native_api] = false
814
+ Chef::Config[:treat_deprecation_warnings_as_errors] = false
815
+ end
809
816
 
810
817
  context "when the cookbooks don't exist on the server" do
811
818
  include_examples "fetching cookbooks when they don't exist"
@@ -826,6 +833,7 @@ describe Chef::PolicyBuilder::Policyfile do
826
833
  end
827
834
 
828
835
  include_examples "fetching cookbooks when they exist"
836
+
829
837
  end
830
838
  end
831
839
 
@@ -863,10 +871,90 @@ describe Chef::PolicyBuilder::Policyfile do
863
871
  end
864
872
 
865
873
  end
874
+ end
866
875
 
876
+ describe "selecting the run_list" do
877
+ let(:node) do
878
+ node = Chef::Node.new
879
+ node.name(node_name)
880
+ node
881
+ end
882
+
883
+ before do
884
+ allow(policy_builder).to receive(:node).and_return(node)
885
+ end
886
+
887
+ context "when json_attribs contains a run_list" do
888
+ let(:json_attribs) { { "run_list" => [ "recipe[something::default]" ] } }
889
+
890
+ it "reads the run_list from the json_attribs" do
891
+ expect(policy_builder.run_list).to eql(json_attribs["run_list"])
892
+ end
893
+
894
+ it "ignores the node.run_list" do
895
+ node.run_list.reset!("recipe[incorrect::incorrect]")
896
+ expect(policy_builder.run_list).to eql(json_attribs["run_list"])
897
+ end
898
+
899
+ it "ignores the node.run_list if the Chef::Config value is set" do
900
+ Chef::Config[:policy_persist_run_list] = true
901
+ node.run_list.reset!("recipe[incorrect::incorrect]")
902
+ expect(policy_builder.run_list).to eql(json_attribs["run_list"])
903
+ end
904
+ end
905
+
906
+ it "reads the run_list from the policyfile" do
907
+ expect(policy_builder.run_list).to eql(policyfile_run_list)
908
+ end
909
+
910
+ it "ignores the node.run_list by default" do
911
+ node.run_list.reset!("recipe[incorrect::incorrect]")
912
+ expect(policy_builder.run_list).to eql(policyfile_run_list)
913
+ end
914
+
915
+ it "uses the node.run_list if the Chef::Config value is set" do
916
+ Chef::Config[:policy_persist_run_list] = true
917
+ node.run_list.reset!("recipe[correct::default]")
918
+ expect(policy_builder.run_list).to eql(node.run_list)
919
+ end
920
+
921
+ it "does not use an empty node.run_list" do
922
+ Chef::Config[:policy_persist_run_list] = true
923
+ node.run_list.reset!
924
+ expect(policy_builder.run_list).to eql(policyfile_run_list)
925
+ end
926
+
927
+ context "with a valid named_run_list" do
928
+ let(:parsed_policyfile_json) do
929
+ basic_valid_policy_data.dup.tap do |p|
930
+ p["named_run_lists"] = {
931
+ "deploy-app" => [ "recipe[example1::default]" ],
932
+ }
933
+ end
934
+ end
935
+
936
+ it "uses the named_run_list over the policyfile" do
937
+ Chef::Config[:named_run_list] = "deploy-app"
938
+ expect(policy_builder.run_list).to eq([ "recipe[example1::default]" ])
939
+ end
940
+
941
+ it "is overridden if the run_list is persistent" do
942
+ Chef::Config[:named_run_list] = "deploy-app"
943
+ Chef::Config[:policy_persist_run_list] = true
944
+ node.run_list.reset!("recipe[correct::default]")
945
+ expect(policy_builder.run_list).to eql(node.run_list)
946
+ end
947
+
948
+ context "when json_attribs contains a run_list" do
949
+ let(:json_attribs) { { "run_list" => [ "recipe[something::default]" ] } }
950
+
951
+ it "overrides the named_run_list" do
952
+ expect(policy_builder.run_list).to eql(json_attribs["run_list"])
953
+ end
954
+ end
955
+
956
+ end
867
957
  end
868
958
  end
869
-
870
959
  end
871
-
872
960
  end
@@ -75,7 +75,9 @@ describe "Chef::Provider::AptUpdate" do
75
75
 
76
76
  describe "#action_periodic" do
77
77
  before do
78
- allow(File).to receive(:exist?)
78
+ allow(File).to receive(:exist?).with(config_file).and_return(true)
79
+ allow(File).to receive(:exist?).with(config_dir).and_return(true)
80
+ allow(File).to receive(:exist?).with(stamp_dir).and_return(true)
79
81
  allow(File).to receive(:exist?).with(Dir.tmpdir).and_return(true)
80
82
  expect(File).to receive(:exist?).with("#{stamp_dir}/update-success-stamp").and_return(true)
81
83
  end
@@ -202,7 +202,7 @@ describe Chef::Provider::Mount::Aix do
202
202
  it "should enable mount if it is mounted and not enabled" do
203
203
  @new_resource.options("nodev,rw")
204
204
  stub_mounted_enabled(@provider, @mounted_output, "")
205
- # Add existing mount to test enable action appends additional mount with seperating blank line
205
+ # Add existing mount to test enable action appends additional mount with separating blank line
206
206
  filesystems = StringIO.new
207
207
  filesystems.puts <<~ETCFILESYSTEMS
208
208
  /tmp/abc:
@@ -105,6 +105,10 @@ describe Chef::Provider::Package::Powershell, :windows_only, :windows_gte_10 do
105
105
  let(:generated_install_cmdlet) { "#{tls_set_command} ( Install-Package xNetworking -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version" }
106
106
  let(:generated_install_cmdlet_with_version) { "#{tls_set_command} ( Install-Package xNetworking -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 1.0.0.0 ).Version" }
107
107
  let(:generated_install_cmdlet_with_source) { "#{tls_set_command} ( Install-Package xNetworking -Force -ForceBootstrap -WarningAction SilentlyContinue -Source MyGallery ).Version" }
108
+ let(:generated_install_cmdlet_with_options) { "#{tls_set_command} ( Install-Package xNetworking -Force -ForceBootstrap -WarningAction SilentlyContinue -AcceptLicense -Verbose ).Version" }
109
+ let(:generated_install_cmdlet_with_version_and_options) { "#{tls_set_command} ( Install-Package xNetworking -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 1.0.0.0 -AcceptLicense -Verbose ).Version" }
110
+ let(:generated_install_cmdlet_with_source_and_options) { "#{tls_set_command} ( Install-Package xNetworking -Force -ForceBootstrap -WarningAction SilentlyContinue -Source MyGallery -AcceptLicense -Verbose ).Version" }
111
+ let(:generated_install_cmdlet_with_source_and_version_and_options) { "#{tls_set_command} ( Install-Package xNetworking -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 1.0.0.0 -Source MyGallery -AcceptLicense -Verbose ).Version" }
108
112
  let(:generated_install_cmdlet_with_source_and_version) { "#{tls_set_command} ( Install-Package xNetworking -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 1.0.0.0 -Source MyGallery ).Version" }
109
113
  let(:generated_uninstall_cmdlet) { "#{tls_set_command} ( Uninstall-Package xNetworking -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version" }
110
114
  let(:generated_uninstall_cmdlet_with_version) { "#{tls_set_command} ( Uninstall-Package xNetworking -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 1.0.0.0 ).Version" }
@@ -204,11 +208,11 @@ describe Chef::Provider::Package::Powershell, :windows_only, :windows_gte_10 do
204
208
  end
205
209
 
206
210
  context "when source is nil" do
207
- it "build get commands correctly" do
211
+ it "builds get commands correctly" do
208
212
  expect(provider.build_powershell_package_command("Get-Package xNetworking")).to eql(generated_get_cmdlet)
209
213
  end
210
214
 
211
- it "build get commands correctly when a version is passed" do
215
+ it "builds get commands correctly when a version is passed" do
212
216
  expect(provider.build_powershell_package_command("Get-Package xNetworking", "1.0.0.0")).to eql(generated_get_cmdlet_with_version)
213
217
  end
214
218
 
@@ -220,30 +224,45 @@ describe Chef::Provider::Package::Powershell, :windows_only, :windows_gte_10 do
220
224
  expect(provider.build_powershell_package_command("Find-Package xNetworking", "1.0.0.0")).to eql(generated_find_cmdlet_with_version)
221
225
  end
222
226
 
223
- it "build install commands correctly" do
227
+ it "builds install commands correctly" do
224
228
  expect(provider.build_powershell_package_command("Install-Package xNetworking")).to eql(generated_install_cmdlet)
225
229
  end
226
230
 
227
- it "build install commands correctly when a version is passed" do
231
+ it "builds install commands correctly when a version is passed" do
228
232
  expect(provider.build_powershell_package_command("Install-Package xNetworking", "1.0.0.0")).to eql(generated_install_cmdlet_with_version)
229
233
  end
230
234
 
231
- it "build install commands correctly" do
235
+ it "builds install commands correctly when options are passed" do
236
+ new_resource.options("-AcceptLicense -Verbose")
237
+ expect(provider.build_powershell_package_command("Install-Package xNetworking")).to eql(generated_install_cmdlet_with_options)
238
+ end
239
+
240
+ it "builds install commands correctly when duplicate options are passed" do
241
+ new_resource.options("-WarningAction SilentlyContinue")
242
+ expect(provider.build_powershell_package_command("Install-Package xNetworking")).to eql(generated_install_cmdlet)
243
+ end
244
+
245
+ it "builds install commands correctly when a version and options are passed" do
246
+ new_resource.options("-AcceptLicense -Verbose")
247
+ expect(provider.build_powershell_package_command("Install-Package xNetworking", "1.0.0.0")).to eql(generated_install_cmdlet_with_version_and_options)
248
+ end
249
+
250
+ it "builds install commands correctly" do
232
251
  expect(provider.build_powershell_package_command("Uninstall-Package xNetworking")).to eql(generated_uninstall_cmdlet)
233
252
  end
234
253
 
235
- it "build install commands correctly when a version is passed" do
254
+ it "builds install commands correctly when a version is passed" do
236
255
  expect(provider.build_powershell_package_command("Uninstall-Package xNetworking", "1.0.0.0")).to eql(generated_uninstall_cmdlet_with_version)
237
256
  end
238
257
  end
239
258
 
240
259
  context "when source is set" do
241
- it "build get commands correctly" do
260
+ it "builds get commands correctly" do
242
261
  new_resource.source("MyGallery")
243
262
  expect(provider.build_powershell_package_command("Get-Package xNetworking")).to eql(generated_get_cmdlet)
244
263
  end
245
264
 
246
- it "build get commands correctly when a version is passed" do
265
+ it "builds get commands correctly when a version is passed" do
247
266
  new_resource.source("MyGallery")
248
267
  expect(provider.build_powershell_package_command("Get-Package xNetworking", "1.0.0.0")).to eql(generated_get_cmdlet_with_version)
249
268
  end
@@ -258,22 +277,40 @@ describe Chef::Provider::Package::Powershell, :windows_only, :windows_gte_10 do
258
277
  expect(provider.build_powershell_package_command("Find-Package xNetworking", "1.0.0.0")).to eql(generated_find_cmdlet_with_source_and_version)
259
278
  end
260
279
 
261
- it "build install commands correctly" do
280
+ it "builds install commands correctly" do
262
281
  new_resource.source("MyGallery")
263
282
  expect(provider.build_powershell_package_command("Install-Package xNetworking")).to eql(generated_install_cmdlet_with_source)
264
283
  end
265
284
 
266
- it "build install commands correctly when a version is passed" do
285
+ it "builds install commands correctly when a version is passed" do
267
286
  new_resource.source("MyGallery")
268
287
  expect(provider.build_powershell_package_command("Install-Package xNetworking", "1.0.0.0")).to eql(generated_install_cmdlet_with_source_and_version)
269
288
  end
270
289
 
271
- it "build install commands correctly" do
290
+ it "builds install commands correctly when options are passed" do
291
+ new_resource.source("MyGallery")
292
+ new_resource.options("-AcceptLicense -Verbose")
293
+ expect(provider.build_powershell_package_command("Install-Package xNetworking")).to eql(generated_install_cmdlet_with_source_and_options)
294
+ end
295
+
296
+ it "builds install commands correctly when duplicate options are passed" do
297
+ new_resource.source("MyGallery")
298
+ new_resource.options("-Force -ForceBootstrap")
299
+ expect(provider.build_powershell_package_command("Install-Package xNetworking")).to eql(generated_install_cmdlet_with_source)
300
+ end
301
+
302
+ it "builds install commands correctly when a version and options are passed" do
303
+ new_resource.source("MyGallery")
304
+ new_resource.options("-AcceptLicense -Verbose")
305
+ expect(provider.build_powershell_package_command("Install-Package xNetworking", "1.0.0.0")).to eql(generated_install_cmdlet_with_source_and_version_and_options)
306
+ end
307
+
308
+ it "builds install commands correctly" do
272
309
  new_resource.source("MyGallery")
273
310
  expect(provider.build_powershell_package_command("Uninstall-Package xNetworking")).to eql(generated_uninstall_cmdlet)
274
311
  end
275
312
 
276
- it "build install commands correctly when a version is passed" do
313
+ it "builds install commands correctly when a version is passed" do
277
314
  new_resource.source("MyGallery")
278
315
  expect(provider.build_powershell_package_command("Uninstall-Package xNetworking", "1.0.0.0")).to eql(generated_uninstall_cmdlet_with_version)
279
316
  end
@@ -434,6 +471,19 @@ describe Chef::Provider::Package::Powershell, :windows_only, :windows_gte_10 do
434
471
  provider.run_action(:install)
435
472
  expect(new_resource).to be_updated_by_last_action
436
473
  end
474
+
475
+ it "should install a package using provided options" do
476
+ provider.load_current_resource
477
+ new_resource.package_name(["xCertificate"])
478
+ new_resource.version(nil)
479
+ new_resource.options(%w{-AcceptLicense -Verbose})
480
+ allow(provider).to receive(:powershell_out).with("#{tls_set_command} ( Find-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
481
+ allow(provider).to receive(:powershell_out).with("#{tls_set_command} ( Get-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_not_available)
482
+ allow(provider).to receive(:powershell_out).with("$PSVersionTable.PSVersion.Major").and_return(powershell_installed_version)
483
+ expect(provider).to receive(:powershell_out).with("#{tls_set_command} ( Install-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.1.0.0 -AcceptLicense -Verbose ).Version", { timeout: new_resource.timeout })
484
+ provider.run_action(:install)
485
+ expect(new_resource).to be_updated_by_last_action
486
+ end
437
487
  end
438
488
 
439
489
  describe "#action_remove" do
@@ -499,5 +549,17 @@ describe Chef::Provider::Package::Powershell, :windows_only, :windows_gte_10 do
499
549
  provider.run_action(:remove)
500
550
  expect(new_resource).to be_updated_by_last_action
501
551
  end
552
+
553
+ it "should remove a package using provided options" do
554
+ new_resource.package_name(["xCertificate"])
555
+ new_resource.options(%w{-AllVersions})
556
+ allow(provider).to receive(:powershell_out).with("#{tls_set_command} ( Find-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
557
+ allow(provider).to receive(:powershell_out).with("#{tls_set_command} ( Get-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
558
+ allow(provider).to receive(:powershell_out).with("$PSVersionTable.PSVersion.Major").and_return(powershell_installed_version)
559
+ provider.load_current_resource
560
+ expect(provider).to receive(:powershell_out).with("#{tls_set_command} ( Uninstall-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue -AllVersions ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_not_available)
561
+ provider.run_action(:remove)
562
+ expect(new_resource).to be_updated_by_last_action
563
+ end
502
564
  end
503
565
  end