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

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -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
@@ -125,7 +125,7 @@ describe Chef::Resource::Link do
125
125
 
126
126
  describe "when the target doesn't exist" do
127
127
  before do
128
- allow(File).to receive(:exists?).with("#{CHEF_SPEC_DATA}/fofile-link").and_return(false)
128
+ allow(File).to receive(:exist?).with("#{CHEF_SPEC_DATA}/fofile-link").and_return(false)
129
129
  allow(provider.file_class).to receive(:symlink?).with("#{CHEF_SPEC_DATA}/fofile-link").and_return(false)
130
130
  provider.load_current_resource
131
131
  end
@@ -152,13 +152,16 @@ describe Chef::Resource::Link do
152
152
  allow(stat).to receive(:mode).and_return(0755)
153
153
  allow(provider.file_class).to receive(:stat).with("#{CHEF_SPEC_DATA}/fofile-link").and_return(stat)
154
154
 
155
- allow(File).to receive(:exists?).with("#{CHEF_SPEC_DATA}/fofile-link").and_return(true)
155
+ # XXX: this might be broken? it preserves prior behavior in the specs caused by File.exist?/exists? interactions
156
+ allow(Chef::ScanAccessControl).to receive(:new).and_return(instance_double(Chef::ScanAccessControl, set_all!: nil))
157
+
158
+ allow(File).to receive(:exist?).with("#{CHEF_SPEC_DATA}/fofile-link").and_return(true)
156
159
  allow(provider.file_class).to receive(:symlink?).with("#{CHEF_SPEC_DATA}/fofile-link").and_return(false)
157
160
  end
158
161
 
159
162
  describe "and the source does not exist" do
160
163
  before do
161
- allow(File).to receive(:exists?).with("#{CHEF_SPEC_DATA}/fofile").and_return(false)
164
+ expect(File).to receive(:exist?).with("#{CHEF_SPEC_DATA}/fofile").and_return(false)
162
165
  provider.load_current_resource
163
166
  end
164
167
 
@@ -185,7 +188,7 @@ describe Chef::Resource::Link do
185
188
 
186
189
  allow(provider.file_class).to receive(:stat).with("#{CHEF_SPEC_DATA}/fofile").and_return(stat)
187
190
 
188
- allow(File).to receive(:exists?).with("#{CHEF_SPEC_DATA}/fofile").and_return(true)
191
+ allow(File).to receive(:exist?).with("#{CHEF_SPEC_DATA}/fofile").and_return(true)
189
192
  provider.load_current_resource
190
193
  end
191
194
 
@@ -212,7 +215,7 @@ describe Chef::Resource::Link do
212
215
 
213
216
  allow(provider.file_class).to receive(:stat).with("#{CHEF_SPEC_DATA}/fofile").and_return(stat)
214
217
 
215
- allow(File).to receive(:exists?).with("#{CHEF_SPEC_DATA}/fofile").and_return(true)
218
+ allow(File).to receive(:exist?).with("#{CHEF_SPEC_DATA}/fofile").and_return(true)
216
219
  provider.load_current_resource
217
220
  end
218
221
 
@@ -262,6 +265,9 @@ describe Chef::Resource::Link do
262
265
  "#{CHEF_SPEC_DATA}/fofile-link"
263
266
  ).and_return(stat)
264
267
 
268
+ # XXX: this might be broken? it preserves prior behavior in the specs caused by File.exist?/exists? interactions
269
+ allow(Chef::ScanAccessControl).to receive(:new).and_return(instance_double(Chef::ScanAccessControl, set_all!: nil))
270
+
265
271
  provider.load_current_resource
266
272
  end
267
273
 
@@ -336,10 +342,10 @@ describe Chef::Resource::Link do
336
342
  "#{CHEF_SPEC_DATA}/fofile-link"
337
343
  ).and_return(false)
338
344
 
339
- allow(File).to receive(:exists?).with(
345
+ allow(File).to receive(:exist?).with(
340
346
  "#{CHEF_SPEC_DATA}/fofile-link"
341
347
  ).and_return(true)
342
- allow(File).to receive(:exists?).with(
348
+ allow(File).to receive(:exist?).with(
343
349
  "#{CHEF_SPEC_DATA}/fofile"
344
350
  ).and_return(true)
345
351
 
@@ -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
@@ -321,4 +321,14 @@ describe Chef::Provider::RemoteFile::HTTP do
321
321
 
322
322
  end
323
323
 
324
+ describe "#http_client_opts" do
325
+ before do
326
+ new_resource.http_options({ retries: 2, retry_delay: 3 })
327
+ end
328
+
329
+ it "should set http client options" do
330
+ expect(fetcher.send(:http_client_opts)).to eq({ retries: 2, retry_delay: 3 })
331
+ end
332
+ end
333
+
324
334
  end
@@ -50,7 +50,7 @@ describe Chef::Provider::Template do
50
50
 
51
51
  let(:content) do
52
52
  content = double("Chef::Provider::File::Content::Template", template_location: "/foo/bar/baz")
53
- allow(File).to receive(:exists?).with("/foo/bar/baz").and_return(true)
53
+ allow(File).to receive(:exist?).with("/foo/bar/baz").and_return(true)
54
54
  content
55
55
  end
56
56
 
@@ -76,7 +76,7 @@ describe Chef::Provider::Template do
76
76
  it "stops executing when the local template source can't be found" do
77
77
  setup_normal_file
78
78
  allow(content).to receive(:template_location).and_return("/baz/bar/foo")
79
- allow(File).to receive(:exists?).with("/baz/bar/foo").and_return(false)
79
+ allow(File).to receive(:exist?).with("/baz/bar/foo").and_return(false)
80
80
  expect { provider.run_action(:create) }.to raise_error Chef::Mixin::WhyRun::ResourceRequirements::Assertion::AssertionFailure
81
81
  end
82
82
 
@@ -32,6 +32,21 @@ class NoWhyrunDemonstrator < Chef::Provider
32
32
  end
33
33
  end
34
34
 
35
+ class ActionDescriptionDemonstrator < Chef::Provider
36
+ def load_current_resource; end
37
+
38
+ action :foo, description: "foo described" do
39
+ true
40
+ end
41
+
42
+ action :foo2 do
43
+ true
44
+ end
45
+
46
+ end
47
+
48
+ context "blah" do
49
+ end
35
50
  class ConvergeActionDemonstrator < Chef::Provider
36
51
  attr_reader :system_state_altered
37
52
 
@@ -98,6 +113,14 @@ describe Chef::Provider do
98
113
  expect(@provider.action_nothing).to eql(true)
99
114
  end
100
115
 
116
+ it "should return an action description for action_description when one is available" do
117
+ expect(ActionDescriptionDemonstrator.action_description(:foo)).to eq "foo described"
118
+ end
119
+
120
+ it "should return nil for action_description when no description is available" do
121
+ expect(ActionDescriptionDemonstrator.action_description(:none)).to eq nil
122
+ end
123
+
101
124
  it "evals embedded recipes with a pristine resource collection" do
102
125
  @provider.run_context.instance_variable_set(:@resource_collection, "doesn't matter what this is")
103
126
  temporary_collection = nil