chef 17.0.242-universal-mingw32 → 17.4.25-universal-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (254) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +4 -14
  3. data/Rakefile +2 -2
  4. data/chef.gemspec +10 -20
  5. data/lib/chef/action_collection.rb +6 -26
  6. data/lib/chef/application/base.rb +15 -0
  7. data/lib/chef/application.rb +4 -2
  8. data/lib/chef/chef_fs/file_pattern.rb +2 -2
  9. data/lib/chef/client.rb +7 -1
  10. data/lib/chef/compliance/default_attributes.rb +5 -3
  11. data/lib/chef/compliance/reporter/automate.rb +1 -1
  12. data/lib/chef/compliance/runner.rb +17 -3
  13. data/lib/chef/cookbook/cookbook_version_loader.rb +3 -3
  14. data/lib/chef/cookbook/gem_installer.rb +5 -1
  15. data/lib/chef/cookbook_version.rb +26 -4
  16. data/lib/chef/data_collector/run_end_message.rb +1 -1
  17. data/lib/chef/data_collector.rb +0 -1
  18. data/lib/chef/deprecated.rb +14 -4
  19. data/lib/chef/dsl/declare_resource.rb +5 -10
  20. data/lib/chef/dsl/render_helpers.rb +44 -0
  21. data/lib/chef/dsl/secret.rb +64 -0
  22. data/lib/chef/dsl/toml.rb +116 -0
  23. data/lib/chef/dsl/universal.rb +5 -0
  24. data/lib/chef/dsl.rb +1 -0
  25. data/lib/chef/event_dispatch/base.rb +2 -1
  26. data/lib/chef/exceptions.rb +23 -0
  27. data/lib/chef/formatters/doc.rb +2 -1
  28. data/lib/chef/formatters/error_mapper.rb +2 -2
  29. data/lib/chef/handler/slow_report.rb +66 -0
  30. data/lib/chef/handler.rb +46 -8
  31. data/lib/chef/json_compat.rb +1 -1
  32. data/lib/chef/node.rb +21 -20
  33. data/lib/chef/policy_builder/policyfile.rb +88 -45
  34. data/lib/chef/provider/directory.rb +6 -6
  35. data/lib/chef/provider/execute.rb +1 -1
  36. data/lib/chef/provider/file.rb +2 -2
  37. data/lib/chef/provider/group/dscl.rb +1 -1
  38. data/lib/chef/provider/launchd.rb +6 -6
  39. data/lib/chef/provider/link.rb +1 -1
  40. data/lib/chef/provider/lwrp_base.rb +1 -1
  41. data/lib/chef/provider/package/dnf/dnf_helper.py +11 -10
  42. data/lib/chef/provider/package/dnf/python_helper.rb +9 -8
  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/package/yum/python_helper.rb +15 -10
  46. data/lib/chef/provider/package/yum/yum_helper.py +46 -62
  47. data/lib/chef/provider/package/yum.rb +1 -4
  48. data/lib/chef/provider/registry_key.rb +1 -1
  49. data/lib/chef/provider/service/systemd.rb +1 -1
  50. data/lib/chef/provider/subversion.rb +4 -4
  51. data/lib/chef/provider/support/yum_repo.erb +1 -1
  52. data/lib/chef/provider/support/zypper_repo.erb +4 -2
  53. data/lib/chef/provider/systemd_unit.rb +18 -17
  54. data/lib/chef/provider/template/content.rb +1 -1
  55. data/lib/chef/provider/user/mac.rb +3 -3
  56. data/lib/chef/provider/windows_script.rb +1 -1
  57. data/lib/chef/provider/yum_repository.rb +27 -43
  58. data/lib/chef/provider/zypper_repository.rb +30 -34
  59. data/lib/chef/provider.rb +26 -1
  60. data/lib/chef/provider_resolver.rb +8 -2
  61. data/lib/chef/providers.rb +1 -0
  62. data/lib/chef/resource/alternatives.rb +5 -5
  63. data/lib/chef/resource/apt_preference.rb +2 -2
  64. data/lib/chef/resource/apt_repository.rb +2 -2
  65. data/lib/chef/resource/apt_update.rb +4 -4
  66. data/lib/chef/resource/build_essential.rb +1 -1
  67. data/lib/chef/resource/chef_client_config.rb +10 -5
  68. data/lib/chef/resource/chef_client_cron.rb +3 -3
  69. data/lib/chef/resource/chef_client_launchd.rb +3 -3
  70. data/lib/chef/resource/chef_client_scheduled_task.rb +15 -15
  71. data/lib/chef/resource/chef_client_systemd_timer.rb +3 -3
  72. data/lib/chef/resource/chef_client_trusted_certificate.rb +2 -2
  73. data/lib/chef/resource/chef_handler.rb +2 -2
  74. data/lib/chef/resource/chef_sleep.rb +1 -1
  75. data/lib/chef/resource/chef_vault_secret.rb +2 -2
  76. data/lib/chef/resource/chocolatey_feature.rb +2 -2
  77. data/lib/chef/resource/chocolatey_source.rb +1 -1
  78. data/lib/chef/resource/cron/cron_d.rb +4 -6
  79. data/lib/chef/resource/cron_access.rb +1 -1
  80. data/lib/chef/resource/dmg_package.rb +1 -1
  81. data/lib/chef/resource/dsc_resource.rb +1 -1
  82. data/lib/chef/resource/execute.rb +5 -5
  83. data/lib/chef/resource/gem_package.rb +2 -1
  84. data/lib/chef/resource/group.rb +4 -4
  85. data/lib/chef/resource/habitat/_habitat_shared.rb +28 -0
  86. data/lib/chef/resource/habitat/habitat_package.rb +129 -0
  87. data/lib/chef/resource/habitat/habitat_sup.rb +329 -0
  88. data/lib/chef/resource/habitat/habitat_sup_systemd.rb +67 -0
  89. data/lib/chef/resource/habitat/habitat_sup_windows.rb +90 -0
  90. data/lib/chef/resource/habitat_config.rb +107 -0
  91. data/lib/chef/resource/habitat_install.rb +247 -0
  92. data/lib/chef/resource/habitat_service.rb +451 -0
  93. data/lib/chef/resource/habitat_user_toml.rb +92 -0
  94. data/lib/chef/resource/homebrew_cask.rb +18 -7
  95. data/lib/chef/resource/homebrew_package.rb +1 -1
  96. data/lib/chef/resource/homebrew_tap.rb +4 -3
  97. data/lib/chef/resource/homebrew_update.rb +2 -2
  98. data/lib/chef/resource/hostname.rb +49 -7
  99. data/lib/chef/resource/inspec_waiver_file_entry.rb +156 -0
  100. data/lib/chef/resource/kernel_module.rb +6 -6
  101. data/lib/chef/resource/launchd.rb +3 -3
  102. data/lib/chef/resource/locale.rb +1 -1
  103. data/lib/chef/resource/lwrp_base.rb +18 -3
  104. data/lib/chef/resource/macos_userdefaults.rb +2 -2
  105. data/lib/chef/resource/ohai_hint.rb +2 -6
  106. data/lib/chef/resource/openbsd_package.rb +17 -0
  107. data/lib/chef/resource/openssl_dhparam.rb +1 -2
  108. data/lib/chef/resource/openssl_ec_private_key.rb +1 -3
  109. data/lib/chef/resource/openssl_ec_public_key.rb +1 -3
  110. data/lib/chef/resource/openssl_rsa_private_key.rb +1 -3
  111. data/lib/chef/resource/openssl_rsa_public_key.rb +1 -3
  112. data/lib/chef/resource/openssl_x509_certificate.rb +1 -4
  113. data/lib/chef/resource/openssl_x509_crl.rb +1 -3
  114. data/lib/chef/resource/openssl_x509_request.rb +1 -3
  115. data/lib/chef/resource/osx_profile.rb +3 -3
  116. data/lib/chef/resource/plist.rb +1 -1
  117. data/lib/chef/resource/powershell_package_source.rb +2 -4
  118. data/lib/chef/resource/reboot.rb +38 -9
  119. data/lib/chef/resource/remote_directory.rb +2 -2
  120. data/lib/chef/resource/remote_file.rb +3 -3
  121. data/lib/chef/resource/rhsm_errata.rb +0 -2
  122. data/lib/chef/resource/rhsm_errata_level.rb +1 -5
  123. data/lib/chef/resource/rhsm_repo.rb +15 -0
  124. data/lib/chef/resource/rhsm_subscription.rb +5 -5
  125. data/lib/chef/resource/ruby_block.rb +100 -0
  126. data/lib/chef/resource/scm/subversion.rb +1 -1
  127. data/lib/chef/resource/ssh_known_hosts_entry.rb +4 -7
  128. data/lib/chef/resource/sudo.rb +2 -6
  129. data/lib/chef/resource/support/HabService.dll.config.erb +19 -0
  130. data/lib/chef/resource/support/client.erb +8 -1
  131. data/lib/chef/resource/support/sup.toml.erb +179 -0
  132. data/lib/chef/resource/swap_file.rb +2 -6
  133. data/lib/chef/resource/sysctl.rb +2 -2
  134. data/lib/chef/resource/systemd_unit.rb +3 -3
  135. data/lib/chef/resource/timezone.rb +1 -1
  136. data/lib/chef/resource/user_ulimit.rb +2 -2
  137. data/lib/chef/resource/windows_ad_join.rb +2 -2
  138. data/lib/chef/resource/windows_audit_policy.rb +2 -2
  139. data/lib/chef/resource/windows_auto_run.rb +2 -2
  140. data/lib/chef/resource/windows_certificate.rb +1 -1
  141. data/lib/chef/resource/windows_defender.rb +163 -0
  142. data/lib/chef/resource/windows_defender_exclusion.rb +125 -0
  143. data/lib/chef/resource/windows_dfs_folder.rb +2 -2
  144. data/lib/chef/resource/windows_dfs_namespace.rb +2 -2
  145. data/lib/chef/resource/windows_dns_record.rb +2 -2
  146. data/lib/chef/resource/windows_dns_zone.rb +2 -2
  147. data/lib/chef/resource/windows_env.rb +1 -1
  148. data/lib/chef/resource/windows_feature.rb +3 -3
  149. data/lib/chef/resource/windows_feature_dism.rb +3 -5
  150. data/lib/chef/resource/windows_feature_powershell.rb +3 -3
  151. data/lib/chef/resource/windows_firewall_profile.rb +2 -2
  152. data/lib/chef/resource/windows_firewall_rule.rb +20 -6
  153. data/lib/chef/resource/windows_font.rb +2 -2
  154. data/lib/chef/resource/windows_pagefile.rb +104 -65
  155. data/lib/chef/resource/windows_path.rb +4 -4
  156. data/lib/chef/resource/windows_printer.rb +80 -61
  157. data/lib/chef/resource/windows_printer_port.rb +48 -65
  158. data/lib/chef/resource/windows_security_policy.rb +7 -4
  159. data/lib/chef/resource/windows_share.rb +2 -2
  160. data/lib/chef/resource/windows_shortcut.rb +1 -1
  161. data/lib/chef/resource/windows_task.rb +2 -2
  162. data/lib/chef/resource/windows_uac.rb +3 -5
  163. data/lib/chef/resource/windows_update_settings.rb +259 -0
  164. data/lib/chef/resource/windows_user_privilege.rb +2 -2
  165. data/lib/chef/resource/windows_workgroup.rb +2 -2
  166. data/lib/chef/resource/yum_package.rb +11 -15
  167. data/lib/chef/resource/zypper_package.rb +4 -4
  168. data/lib/chef/resource/zypper_repository.rb +28 -8
  169. data/lib/chef/resource.rb +20 -25
  170. data/lib/chef/resource_builder.rb +8 -2
  171. data/lib/chef/resource_inspector.rb +6 -2
  172. data/lib/chef/resource_reporter.rb +0 -1
  173. data/lib/chef/resources.rb +13 -1
  174. data/lib/chef/run_lock.rb +1 -1
  175. data/lib/chef/runner.rb +1 -1
  176. data/lib/chef/secret_fetcher/aws_secrets_manager.rb +65 -0
  177. data/lib/chef/secret_fetcher/azure_key_vault.rb +78 -0
  178. data/lib/chef/secret_fetcher/base.rb +76 -0
  179. data/lib/chef/secret_fetcher/example.rb +46 -0
  180. data/lib/chef/secret_fetcher.rb +55 -0
  181. data/lib/chef/shell/ext.rb +3 -3
  182. data/lib/chef/version.rb +1 -1
  183. data/lib/chef/win32/api.rb +9 -2
  184. data/spec/data/knife-home/.chef/plugins/knife/example_home_subcommand.rb +0 -0
  185. data/spec/data/knife-site-subcommands/plugins/knife/example_subcommand.rb +0 -0
  186. data/spec/data/knife_subcommand/test_explicit_category.rb +7 -0
  187. data/spec/data/knife_subcommand/test_name_mapping.rb +4 -0
  188. data/spec/data/knife_subcommand/test_yourself.rb +21 -0
  189. data/spec/functional/mixin/from_file_spec.rb +1 -1
  190. data/spec/functional/resource/dnf_package_spec.rb +857 -537
  191. data/spec/functional/resource/group_spec.rb +1 -1
  192. data/spec/functional/resource/link_spec.rb +1 -1
  193. data/spec/functional/resource/remote_file_spec.rb +1 -1
  194. data/spec/functional/resource/windows_env_spec.rb +2 -2
  195. data/spec/functional/resource/windows_hostname_spec.rb +91 -0
  196. data/spec/functional/resource/windows_pagefile_spec.rb +98 -0
  197. data/spec/functional/resource/yum_package_spec.rb +495 -428
  198. data/spec/integration/client/client_spec.rb +0 -20
  199. data/spec/integration/compliance/compliance_spec.rb +1 -0
  200. data/spec/integration/recipes/recipe_dsl_spec.rb +1 -1
  201. data/spec/integration/recipes/resource_action_spec.rb +6 -6
  202. data/spec/integration/recipes/unified_mode_spec.rb +70 -0
  203. data/spec/spec_helper.rb +3 -0
  204. data/spec/support/chef_helpers.rb +1 -1
  205. data/spec/support/shared/functional/execute_resource.rb +1 -1
  206. data/spec/support/shared/functional/knife.rb +37 -0
  207. data/spec/support/shared/integration/knife_support.rb +192 -0
  208. data/spec/support/shared/unit/knife_shared.rb +39 -0
  209. data/spec/support/shared/unit/provider/file.rb +3 -9
  210. data/spec/unit/chef_fs/file_system/repository/directory_spec.rb +1 -1
  211. data/spec/unit/compliance/runner_spec.rb +46 -2
  212. data/spec/unit/cookbook_version_spec.rb +52 -0
  213. data/spec/unit/data_collector_spec.rb +47 -1
  214. data/spec/unit/dsl/render_helpers_spec.rb +102 -0
  215. data/spec/unit/dsl/secret_spec.rb +71 -0
  216. data/spec/unit/handler_spec.rb +8 -2
  217. data/spec/unit/policy_builder/dynamic_spec.rb +0 -5
  218. data/spec/unit/policy_builder/policyfile_spec.rb +144 -56
  219. data/spec/unit/provider/apt_update_spec.rb +3 -1
  220. data/spec/unit/provider/link_spec.rb +1 -1
  221. data/spec/unit/provider/mount/aix_spec.rb +1 -1
  222. data/spec/unit/provider/package/dnf/python_helper_spec.rb +1 -0
  223. data/spec/unit/provider/package/powershell_spec.rb +74 -12
  224. data/spec/unit/provider/package/yum/python_helper_spec.rb +1 -0
  225. data/spec/unit/provider/service/systemd_service_spec.rb +2 -2
  226. data/spec/unit/provider/systemd_unit_spec.rb +2 -2
  227. data/spec/unit/provider/zypper_repository_spec.rb +3 -10
  228. data/spec/unit/provider_spec.rb +23 -0
  229. data/spec/unit/resource/homebrew_cask_spec.rb +29 -11
  230. data/spec/unit/resource/inspec_waiver_file_entry_spec.rb +80 -0
  231. data/spec/unit/resource/rhsm_subscription_spec.rb +50 -3
  232. data/spec/unit/resource/systemd_unit_spec.rb +1 -1
  233. data/spec/unit/resource/windows_defender_exclusion_spec.rb +62 -0
  234. data/spec/unit/resource/windows_defender_spec.rb +71 -0
  235. data/spec/unit/resource/windows_firewall_rule_spec.rb +12 -7
  236. data/spec/unit/resource/windows_pagefile_spec.rb +4 -9
  237. data/spec/unit/resource/windows_update_settings_spec.rb +64 -0
  238. data/spec/unit/resource/zypper_repository_spec.rb +1 -1
  239. data/spec/unit/resource_spec.rb +19 -8
  240. data/spec/unit/secret_fetcher/aws_secrets_manager_spec.rb +70 -0
  241. data/spec/unit/secret_fetcher/azure_key_vault_spec.rb +70 -0
  242. data/spec/unit/secret_fetcher_spec.rb +82 -0
  243. data/tasks/rspec.rb +4 -9
  244. metadata +65 -161
  245. data/lib/chef/provider/package/yum/simplejson/LICENSE.txt +0 -79
  246. data/lib/chef/provider/package/yum/simplejson/__init__.py +0 -318
  247. data/lib/chef/provider/package/yum/simplejson/__init__.pyc +0 -0
  248. data/lib/chef/provider/package/yum/simplejson/decoder.py +0 -354
  249. data/lib/chef/provider/package/yum/simplejson/decoder.pyc +0 -0
  250. data/lib/chef/provider/package/yum/simplejson/encoder.py +0 -440
  251. data/lib/chef/provider/package/yum/simplejson/encoder.pyc +0 -0
  252. data/lib/chef/provider/package/yum/simplejson/scanner.py +0 -65
  253. data/lib/chef/provider/package/yum/simplejson/scanner.pyc +0 -0
  254. data/lib/chef/provider/package/yum/simplejson/tool.py +0 -37
@@ -349,26 +349,6 @@ describe "chef-client" do
349
349
  expect(result.stdout).to include("Run List is [recipe[x::default]]")
350
350
  result.error!
351
351
  end
352
-
353
- it "should complete with success when using --profile-ruby and output a profile file", :not_supported_on_aix do
354
- file "config/client.rb", <<~EOM
355
- local_mode true
356
- cookbook_path "#{path_to("cookbooks")}"
357
- EOM
358
- result = shell_out!("#{chef_client} -c \"#{path_to("config/client.rb")}\" -o 'x::default' -z --profile-ruby", cwd: chef_dir)
359
- result.error!
360
- expect(File.exist?(path_to("config/local-mode-cache/cache/graph_profile.out"))).to be true
361
- end
362
-
363
- it "doesn't produce a profile when --profile-ruby is not present" do
364
- file "config/client.rb", <<~EOM
365
- local_mode true
366
- cookbook_path "#{path_to("cookbooks")}"
367
- EOM
368
- result = shell_out!("#{chef_client} -c \"#{path_to("config/client.rb")}\" -o 'x::default' -z", cwd: chef_dir)
369
- result.error!
370
- expect(File.exist?(path_to("config/local-mode-cache/cache/graph_profile.out"))).to be false
371
- end
372
352
  end
373
353
 
374
354
  when_the_repository "has a cookbook that outputs some node attributes" do
@@ -47,6 +47,7 @@ describe "chef-client with compliance phase" do
47
47
  {
48
48
  "audit": {
49
49
  "compliance_phase": true,
50
+ "reporter": "json-file",
50
51
  "json_file": {
51
52
  "location": "#{report_file}"
52
53
  },
@@ -19,7 +19,7 @@ describe "Recipe DSL methods" do
19
19
  provides :base_thingy
20
20
  default_action :create
21
21
 
22
- class<<self
22
+ class << self
23
23
  attr_accessor :created_name
24
24
  attr_accessor :created_resource
25
25
  attr_accessor :created_provider
@@ -9,7 +9,7 @@ class NoActionJackson < Chef::Resource
9
9
  @foo
10
10
  end
11
11
 
12
- class <<self
12
+ class << self
13
13
  attr_accessor :action_was
14
14
  end
15
15
  end
@@ -17,7 +17,7 @@ end
17
17
  class WeirdActionJackson < Chef::Resource
18
18
  provides :weird_action_jackson
19
19
 
20
- class <<self
20
+ class << self
21
21
  attr_accessor :action_was
22
22
  end
23
23
 
@@ -176,7 +176,7 @@ module ResourceActionSpec
176
176
  @blarghle
177
177
  end
178
178
 
179
- class <<self
179
+ class << self
180
180
  attr_accessor :ran_action
181
181
  attr_accessor :succeeded
182
182
  attr_accessor :ruby_block_converged
@@ -284,7 +284,7 @@ module ResourceActionSpec
284
284
  @bar = "#{value}alope" if value
285
285
  @bar
286
286
  end
287
- class <<self
287
+ class << self
288
288
  attr_accessor :load_current_resource_ran
289
289
  attr_accessor :jackalope_ran
290
290
  end
@@ -354,8 +354,8 @@ module ResourceActionSpec
354
354
  end
355
355
 
356
356
  it "allows overridden action to have a description separate from the action defined in the base resource" do
357
- expect(ActionJackson.action_description(:test1)).to eql "Original description"
358
- expect(ActionJackalope.action_description(:test1)).to eql "An old action with a new description"
357
+ expect(ActionJackson.new("ActionJackson", nil).action_description(:test1)).to eql "Original description"
358
+ expect(ActionJackalope.new("ActionJackalope", nil).action_description(:test1)).to eql "An old action with a new description"
359
359
  end
360
360
 
361
361
  it "non-overridden actions run and can access overridden and non-overridden variables (but not necessarily new ones)" do
@@ -874,4 +874,74 @@ describe "Unified Mode" do
874
874
  result.error!
875
875
  end
876
876
  end
877
+
878
+ when_the_repository "has a resource that uses edit_resource to create a subresource" do
879
+ before do
880
+ directory "cookbooks/x" do
881
+ file "recipes/default.rb", <<~EOM
882
+ my_resource "doit"
883
+ EOM
884
+
885
+ file "resources/my_resource.rb", <<~EOM
886
+ unified_mode true
887
+ provides :my_resource
888
+
889
+ action :doit do
890
+ edit_resource(:log, "name") do
891
+ message "GOOD"
892
+ level :warn
893
+ end
894
+ end
895
+ EOM
896
+ end
897
+ end
898
+
899
+ it "recipes should still have a compile/converge mode" do
900
+ file "config/client.rb", <<~EOM
901
+ local_mode true
902
+ cookbook_path "#{path_to("cookbooks")}"
903
+ log_level :warn
904
+ EOM
905
+
906
+ result = shell_out("#{chef_client} -c \"#{path_to("config/client.rb")}\" --no-color -F doc -o 'x::default'", cwd: chef_dir)
907
+ # in recipe mode we should still run normally with a compile/converge mode
908
+ expect(result.stdout).to include("GOOD")
909
+ result.error!
910
+ end
911
+ end
912
+
913
+ when_the_repository "has a resource that uses find_resource to create a subresource" do
914
+ before do
915
+ directory "cookbooks/x" do
916
+ file "recipes/default.rb", <<~EOM
917
+ my_resource "doit"
918
+ EOM
919
+
920
+ file "resources/my_resource.rb", <<~EOM
921
+ unified_mode true
922
+ provides :my_resource
923
+
924
+ action :doit do
925
+ find_resource(:log, "name") do
926
+ message "GOOD"
927
+ level :warn
928
+ end
929
+ end
930
+ EOM
931
+ end
932
+ end
933
+
934
+ it "recipes should still have a compile/converge mode" do
935
+ file "config/client.rb", <<~EOM
936
+ local_mode true
937
+ cookbook_path "#{path_to("cookbooks")}"
938
+ log_level :warn
939
+ EOM
940
+
941
+ result = shell_out("#{chef_client} -c \"#{path_to("config/client.rb")}\" --no-color -F doc -o 'x::default'", cwd: chef_dir)
942
+ # in recipe mode we should still run normally with a compile/converge mode
943
+ expect(result.stdout).to include("GOOD")
944
+ result.error!
945
+ end
946
+ end
877
947
  end
data/spec/spec_helper.rb CHANGED
@@ -24,6 +24,9 @@ module Shell
24
24
  IRB = nil unless defined? IRB
25
25
  end
26
26
 
27
+ # show the deprecation warnings
28
+ Warning[:deprecated] = true
29
+
27
30
  $LOAD_PATH.unshift File.expand_path("..", __dir__)
28
31
 
29
32
  $LOAD_PATH.unshift File.expand_path("../chef-config/lib", __dir__)
@@ -43,7 +43,7 @@ end
43
43
  # This is a helper to canonicalize paths that we're using in the file
44
44
  # tests.
45
45
  def canonicalize_path(path)
46
- windows? ? path.tr("/", '\\') : path
46
+ windows? ? path.tr("/", "\\") : path
47
47
  end
48
48
 
49
49
  # Makes a temp directory with a canonical path on any platform.
@@ -58,7 +58,7 @@ shared_context "a command that can be executed as an alternate user" do
58
58
  include Chef::Mixin::ShellOut
59
59
 
60
60
  before do
61
- shell_out!("icacls \"#{script_output_dir.tr("/", '\\')}\" /grant \"authenticated users:(F)\"")
61
+ shell_out!("icacls \"#{script_output_dir.tr("/", "\\")}\" /grant \"authenticated users:(F)\"")
62
62
  end
63
63
 
64
64
  after do
@@ -0,0 +1,37 @@
1
+ #
2
+ # Author:: Adam Jacob (<adam@chef.io>)
3
+ # Author:: AJ Christensen (<aj@junglist.gen.nz>)
4
+ # Author:: Ho-Sheng Hsiao (<hosh@chef.io>)
5
+ # Copyright:: Copyright (c) Chef Software Inc.
6
+ # License:: Apache License, Version 2.0
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ # See the License for the specific language governing permissions and
18
+ # limitations under the License.
19
+ #
20
+ module SpecHelpers
21
+ module Knife
22
+ def redefine_argv(value)
23
+ Object.send(:remove_const, :ARGV)
24
+ Object.send(:const_set, :ARGV, value)
25
+ end
26
+
27
+ def with_argv(*argv)
28
+ original_argv = ARGV
29
+ redefine_argv(argv.flatten)
30
+ begin
31
+ yield
32
+ ensure
33
+ redefine_argv(original_argv)
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,192 @@
1
+ #
2
+ # Author:: John Keiser (<jkeiser@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
+ require "chef/config"
19
+ require "chef/knife"
20
+ require "chef/application/knife"
21
+ require "logger"
22
+ require "chef/log"
23
+ require "chef/chef_fs/file_system_cache"
24
+
25
+ module KnifeSupport
26
+ DEBUG = ENV["DEBUG"]
27
+ def knife(*args, input: nil, instance_filter: nil)
28
+ # Allow knife('role from file roles/blah.json') rather than requiring the
29
+ # arguments to be split like knife('role', 'from', 'file', 'roles/blah.json')
30
+ # If any argument will have actual spaces in it, the long form is required.
31
+ # (Since knife commands always start with the command name, and command
32
+ # names with spaces are always multiple args, this is safe.)
33
+ if args.length == 1
34
+ args = args[0].split(/\s+/)
35
+ end
36
+
37
+ # Make output stable
38
+ Chef::Config[:concurrency] = 1
39
+
40
+ # Work on machines where we can't access /var
41
+ Dir.mktmpdir("checksums") do |checksums_cache_dir|
42
+ Chef::Config[:syntax_check_cache_path] = checksums_cache_dir
43
+
44
+ # This is Chef::Knife.run without load_commands--we'll load stuff
45
+ # ourselves, thank you very much
46
+ stdout = StringIO.new
47
+ stderr = StringIO.new
48
+
49
+ stdin = if input
50
+ StringIO.new(input)
51
+ else
52
+ STDIN
53
+ end
54
+
55
+ begin
56
+ puts "knife: #{args.join(" ")}" if DEBUG
57
+ subcommand_class = Chef::Knife.subcommand_class_from(args)
58
+ subcommand_class.options = Chef::Application::Knife.options.merge(subcommand_class.options)
59
+ subcommand_class.load_deps
60
+ instance = subcommand_class.new(args)
61
+
62
+ # Load configs
63
+ instance.merge_configs
64
+
65
+ # Capture stdout/stderr
66
+ instance.ui = Chef::Knife::UI.new(stdout, stderr, stdin, instance.config.merge(disable_editing: true))
67
+
68
+ # Don't print stuff
69
+ Chef::Config[:verbosity] = ( DEBUG ? 2 : 0 )
70
+ instance.config[:config_file] = File.join(CHEF_SPEC_DATA, "null_config.rb")
71
+
72
+ # Ensure the ChefFS cache is empty
73
+ Chef::ChefFS::FileSystemCache.instance.reset!
74
+
75
+ # Configure chef with a (mostly) blank knife.rb
76
+ # We set a global and then mutate it in our stub knife.rb so we can be
77
+ # extra sure that we're not loading someone's real knife.rb and then
78
+ # running test scenarios against a real chef server. If things don't
79
+ # smell right, abort.
80
+
81
+ # To ensure that we don't pick up a user's credentials file we lie through our teeth about
82
+ # it's existence.
83
+ allow(File).to receive(:file?).and_call_original
84
+ allow(File).to receive(:file?).with(File.expand_path("~/.chef/credentials")).and_return(false)
85
+
86
+ # Set a canary that is modified by the default null_config.rb config file.
87
+ $__KNIFE_INTEGRATION_FAILSAFE_CHECK = "ole"
88
+
89
+ # Allow tweaking the knife instance before configuration.
90
+ instance_filter.call(instance) if instance_filter
91
+
92
+ instance.configure_chef
93
+
94
+ # The canary is incorrect, meaning the normal null_config.rb didn't run. Something is wrong.
95
+ unless $__KNIFE_INTEGRATION_FAILSAFE_CHECK == "ole ole"
96
+ raise Exception, "Potential misconfiguration of integration tests detected. Aborting test."
97
+ end
98
+
99
+ logger = Logger.new(stderr)
100
+ logger.formatter = proc { |severity, datetime, progname, msg| "#{severity}: #{msg}\n" }
101
+ Chef::Log.use_log_devices([logger])
102
+ Chef::Log.level = ( DEBUG ? :debug : :warn )
103
+ Chef::Log::Formatter.show_time = false
104
+
105
+ instance.run_with_pretty_exceptions(true)
106
+
107
+ exit_code = 0
108
+
109
+ # This is how rspec catches exit()
110
+ rescue SystemExit => e
111
+ exit_code = e.status
112
+ ensure
113
+ Chef::Config.delete(:syntax_check_cache_path)
114
+ Chef::Config.delete(:concurrency)
115
+ end
116
+
117
+ KnifeResult.new(stdout.string, stderr.string, exit_code)
118
+ end
119
+ end
120
+
121
+ class KnifeResult
122
+
123
+ include ::RSpec::Matchers
124
+
125
+ def initialize(stdout, stderr, exit_code)
126
+ @stdout = stdout
127
+ @stderr = stderr
128
+ @exit_code = exit_code
129
+ end
130
+
131
+ attr_reader :stdout
132
+ attr_reader :stderr
133
+ attr_reader :exit_code
134
+
135
+ def should_fail(*args)
136
+ expected = {}
137
+ args.each do |arg|
138
+ if arg.is_a?(Hash)
139
+ expected.merge!(arg)
140
+ elsif arg.is_a?(Integer)
141
+ expected[:exit_code] = arg
142
+ else
143
+ expected[:stderr] = arg
144
+ end
145
+ end
146
+ expected[:exit_code] = 1 unless expected[:exit_code]
147
+ should_result_in(expected)
148
+ end
149
+
150
+ def should_succeed(*args)
151
+ expected = {}
152
+ args.each do |arg|
153
+ if arg.is_a?(Hash)
154
+ expected.merge!(arg)
155
+ else
156
+ expected[:stdout] = arg
157
+ end
158
+ end
159
+ should_result_in(expected)
160
+ end
161
+
162
+ private
163
+
164
+ def should_result_in(expected)
165
+ expected[:stdout] = "" unless expected[:stdout]
166
+ expected[:stdout] = expected[:stdout].is_a?(String) ? expected[:stdout].gsub(/[ \t\f\v]+$/, "") : expected[:stdout]
167
+ expected[:stderr] = "" unless expected[:stderr]
168
+ expected[:stderr] = expected[:stderr].is_a?(String) ? expected[:stderr].gsub(/[ \t\f\v]+$/, "") : expected[:stderr]
169
+ expected[:exit_code] = 0 unless expected[:exit_code]
170
+ # TODO make this go away
171
+ stderr_actual = @stderr.sub(/^WARNING: No knife configuration file found\n/, "")
172
+ stderr_actual = stderr_actual.gsub(/[ \t\f\v]+$/, "")
173
+ stdout_actual = @stdout
174
+ stdout_actual = stdout_actual.gsub(/[ \t\f\v]+$/, "")
175
+ if ChefUtils.windows?
176
+ stderr_actual = stderr_actual.gsub("\r\n", "\n")
177
+ stdout_actual = stdout_actual.gsub("\r\n", "\n")
178
+ end
179
+ if expected[:stderr].is_a?(Regexp)
180
+ expect(stderr_actual).to match(expected[:stderr])
181
+ else
182
+ expect(stderr_actual).to eq(expected[:stderr])
183
+ end
184
+ expect(@exit_code).to eq(expected[:exit_code])
185
+ if expected[:stdout].is_a?(Regexp)
186
+ expect(stdout_actual).to match(expected[:stdout])
187
+ else
188
+ expect(stdout_actual).to eq(expected[:stdout])
189
+ end
190
+ end
191
+ end
192
+ end
@@ -0,0 +1,39 @@
1
+ #
2
+ # Author:: Tyler Cloke (<tyler@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
+ shared_examples_for "mandatory field missing" do
20
+ context "when field is nil" do
21
+ before do
22
+ knife.name_args = name_args
23
+ end
24
+
25
+ it "exits 1" do
26
+ expect { knife.run }.to raise_error(SystemExit)
27
+ end
28
+
29
+ it "prints the usage" do
30
+ expect(knife).to receive(:show_usage)
31
+ expect { knife.run }.to raise_error(SystemExit)
32
+ end
33
+
34
+ it "prints a relevant error message" do
35
+ expect { knife.run }.to raise_error(SystemExit)
36
+ expect(stderr.string).to match(/You must specify a #{fieldname}/)
37
+ end
38
+ end
39
+ end