chef 17.10.95 → 18.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (329) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +16 -8
  3. data/README.md +7 -7
  4. data/Rakefile +3 -22
  5. data/{chef-universal-mingw32.gemspec → chef-universal-mingw-ucrt.gemspec} +8 -7
  6. data/chef.gemspec +12 -5
  7. data/lib/chef/api_client_v1.rb +9 -1
  8. data/lib/chef/application/exit_code.rb +3 -3
  9. data/lib/chef/chef_fs/file_system.rb +21 -7
  10. data/lib/chef/client.rb +169 -17
  11. data/lib/chef/compliance/input.rb +1 -1
  12. data/lib/chef/compliance/profile.rb +1 -1
  13. data/lib/chef/compliance/profile_collection.rb +0 -1
  14. data/lib/chef/compliance/waiver.rb +1 -1
  15. data/lib/chef/cookbook/syntax_check.rb +2 -2
  16. data/lib/chef/dsl/reader_helpers.rb +1 -1
  17. data/lib/chef/dsl/rest_resource.rb +77 -0
  18. data/lib/chef/event_dispatch/base.rb +3 -0
  19. data/lib/chef/exceptions.rb +8 -0
  20. data/lib/chef/http/authenticator.rb +170 -3
  21. data/lib/chef/http/ssl_policies.rb +3 -3
  22. data/lib/chef/mixin/powershell_exec.rb +5 -28
  23. data/lib/chef/node/mixin/immutablize_array.rb +1 -0
  24. data/lib/chef/property.rb +13 -6
  25. data/lib/chef/provider/cron.rb +5 -1
  26. data/lib/chef/provider/group/windows.rb +1 -1
  27. data/lib/chef/provider/http_request.rb +11 -9
  28. data/lib/chef/provider/launchd.rb +1 -0
  29. data/lib/chef/provider/mount/linux.rb +5 -0
  30. data/lib/chef/provider/mount/mount.rb +8 -0
  31. data/lib/chef/provider/mount/windows.rb +1 -1
  32. data/lib/chef/provider/package/chocolatey.rb +1 -18
  33. data/lib/chef/provider/package/rubygems.rb +1 -1
  34. data/lib/chef/provider/package/snap.rb +1 -1
  35. data/lib/chef/provider/package/windows/msi.rb +2 -2
  36. data/lib/chef/provider/package/windows/registry_uninstall_entry.rb +1 -1
  37. data/lib/chef/provider/package/yum/yum_helper.py +5 -17
  38. data/lib/chef/provider/package/zypper/version.rb +60 -0
  39. data/lib/chef/provider/package/zypper.rb +47 -3
  40. data/lib/chef/provider/service/windows.rb +1 -1
  41. data/lib/chef/provider/user/aix.rb +5 -0
  42. data/lib/chef/provider/user/linux.rb +29 -0
  43. data/lib/chef/provider/user/mac.rb +1 -1
  44. data/lib/chef/provider/user.rb +46 -14
  45. data/lib/chef/provider/yum_repository.rb +13 -1
  46. data/lib/chef/provider.rb +1 -1
  47. data/lib/chef/recipe.rb +1 -1
  48. data/lib/chef/resource/_rest_resource.rb +389 -0
  49. data/lib/chef/resource/alternatives.rb +0 -1
  50. data/lib/chef/resource/apt_package.rb +2 -1
  51. data/lib/chef/resource/apt_preference.rb +0 -1
  52. data/lib/chef/resource/apt_repository.rb +0 -1
  53. data/lib/chef/resource/apt_update.rb +0 -1
  54. data/lib/chef/resource/archive_file.rb +0 -1
  55. data/lib/chef/resource/bash.rb +0 -1
  56. data/lib/chef/resource/batch.rb +0 -1
  57. data/lib/chef/resource/bff_package.rb +0 -1
  58. data/lib/chef/resource/breakpoint.rb +0 -1
  59. data/lib/chef/resource/build_essential.rb +0 -1
  60. data/lib/chef/resource/cab_package.rb +0 -1
  61. data/lib/chef/resource/chef_client_config.rb +12 -14
  62. data/lib/chef/resource/chef_client_cron.rb +1 -2
  63. data/lib/chef/resource/chef_client_launchd.rb +2 -2
  64. data/lib/chef/resource/chef_client_scheduled_task.rb +3 -3
  65. data/lib/chef/resource/chef_client_systemd_timer.rb +0 -1
  66. data/lib/chef/resource/chef_client_trusted_certificate.rb +0 -1
  67. data/lib/chef/resource/chef_gem.rb +0 -1
  68. data/lib/chef/resource/chef_handler.rb +0 -1
  69. data/lib/chef/resource/chef_sleep.rb +1 -3
  70. data/lib/chef/resource/chef_vault_secret.rb +0 -1
  71. data/lib/chef/resource/chocolatey_config.rb +0 -1
  72. data/lib/chef/resource/chocolatey_feature.rb +0 -1
  73. data/lib/chef/resource/chocolatey_package.rb +0 -1
  74. data/lib/chef/resource/chocolatey_source.rb +0 -1
  75. data/lib/chef/resource/cookbook_file.rb +0 -1
  76. data/lib/chef/resource/cron/_cron_shared.rb +0 -1
  77. data/lib/chef/resource/cron/cron.rb +0 -1
  78. data/lib/chef/resource/cron/cron_d.rb +15 -1
  79. data/lib/chef/resource/cron_access.rb +0 -1
  80. data/lib/chef/resource/csh.rb +0 -1
  81. data/lib/chef/resource/directory.rb +0 -1
  82. data/lib/chef/resource/dmg_package.rb +2 -1
  83. data/lib/chef/resource/dnf_package.rb +0 -1
  84. data/lib/chef/resource/dpkg_package.rb +0 -1
  85. data/lib/chef/resource/dsc_resource.rb +0 -1
  86. data/lib/chef/resource/dsc_script.rb +0 -1
  87. data/lib/chef/resource/execute.rb +0 -1
  88. data/lib/chef/resource/file.rb +0 -1
  89. data/lib/chef/resource/freebsd_package.rb +2 -1
  90. data/lib/chef/resource/gem_package.rb +2 -1
  91. data/lib/chef/resource/group.rb +25 -2
  92. data/lib/chef/resource/habitat/habitat_package.rb +0 -1
  93. data/lib/chef/resource/habitat/habitat_sup.rb +6 -7
  94. data/lib/chef/resource/habitat/habitat_sup_windows.rb +1 -1
  95. data/lib/chef/resource/habitat_config.rb +0 -1
  96. data/lib/chef/resource/habitat_install.rb +0 -1
  97. data/lib/chef/resource/habitat_service.rb +0 -1
  98. data/lib/chef/resource/habitat_user_toml.rb +0 -1
  99. data/lib/chef/resource/homebrew_cask.rb +0 -1
  100. data/lib/chef/resource/homebrew_package.rb +2 -1
  101. data/lib/chef/resource/homebrew_tap.rb +0 -1
  102. data/lib/chef/resource/homebrew_update.rb +0 -2
  103. data/lib/chef/resource/hostname.rb +0 -1
  104. data/lib/chef/resource/http_request.rb +0 -1
  105. data/lib/chef/resource/ifconfig.rb +0 -1
  106. data/lib/chef/resource/inspec_input.rb +0 -1
  107. data/lib/chef/resource/inspec_waiver.rb +0 -1
  108. data/lib/chef/resource/inspec_waiver_file_entry.rb +2 -3
  109. data/lib/chef/resource/ips_package.rb +0 -1
  110. data/lib/chef/resource/kernel_module.rb +0 -1
  111. data/lib/chef/resource/ksh.rb +0 -1
  112. data/lib/chef/resource/launchd.rb +3 -1
  113. data/lib/chef/resource/link.rb +0 -1
  114. data/lib/chef/resource/locale.rb +2 -6
  115. data/lib/chef/resource/log.rb +0 -1
  116. data/lib/chef/resource/lwrp_base.rb +0 -4
  117. data/lib/chef/resource/macos_userdefaults.rb +8 -13
  118. data/lib/chef/resource/macosx_service.rb +0 -1
  119. data/lib/chef/resource/macports_package.rb +2 -1
  120. data/lib/chef/resource/mdadm.rb +0 -1
  121. data/lib/chef/resource/mount.rb +0 -1
  122. data/lib/chef/resource/msu_package.rb +0 -1
  123. data/lib/chef/resource/notify_group.rb +0 -2
  124. data/lib/chef/resource/ohai.rb +0 -1
  125. data/lib/chef/resource/ohai_hint.rb +0 -1
  126. data/lib/chef/resource/openbsd_package.rb +2 -1
  127. data/lib/chef/resource/openssl_dhparam.rb +0 -2
  128. data/lib/chef/resource/openssl_ec_private_key.rb +0 -2
  129. data/lib/chef/resource/openssl_ec_public_key.rb +0 -2
  130. data/lib/chef/resource/openssl_rsa_private_key.rb +0 -2
  131. data/lib/chef/resource/openssl_rsa_public_key.rb +0 -2
  132. data/lib/chef/resource/openssl_x509_certificate.rb +0 -2
  133. data/lib/chef/resource/openssl_x509_crl.rb +0 -2
  134. data/lib/chef/resource/openssl_x509_request.rb +0 -2
  135. data/lib/chef/resource/osx_profile.rb +0 -1
  136. data/lib/chef/resource/package.rb +0 -1
  137. data/lib/chef/resource/pacman_package.rb +2 -1
  138. data/lib/chef/resource/paludis_package.rb +0 -1
  139. data/lib/chef/resource/perl.rb +0 -1
  140. data/lib/chef/resource/plist.rb +7 -3
  141. data/lib/chef/resource/portage_package.rb +2 -1
  142. data/lib/chef/resource/powershell_package.rb +0 -1
  143. data/lib/chef/resource/powershell_package_source.rb +0 -1
  144. data/lib/chef/resource/powershell_script.rb +0 -1
  145. data/lib/chef/resource/python.rb +0 -1
  146. data/lib/chef/resource/reboot.rb +0 -1
  147. data/lib/chef/resource/registry_key.rb +0 -1
  148. data/lib/chef/resource/remote_directory.rb +0 -1
  149. data/lib/chef/resource/remote_file.rb +0 -1
  150. data/lib/chef/resource/rhsm_errata.rb +0 -1
  151. data/lib/chef/resource/rhsm_errata_level.rb +0 -1
  152. data/lib/chef/resource/rhsm_register.rb +2 -4
  153. data/lib/chef/resource/rhsm_repo.rb +0 -1
  154. data/lib/chef/resource/rhsm_subscription.rb +0 -1
  155. data/lib/chef/resource/route.rb +0 -1
  156. data/lib/chef/resource/rpm_package.rb +2 -1
  157. data/lib/chef/resource/ruby.rb +0 -1
  158. data/lib/chef/resource/ruby_block.rb +0 -1
  159. data/lib/chef/resource/scm/_scm.rb +0 -2
  160. data/lib/chef/resource/scm/git.rb +0 -2
  161. data/lib/chef/resource/scm/subversion.rb +0 -2
  162. data/lib/chef/resource/script.rb +0 -1
  163. data/lib/chef/resource/selinux/common_helpers.rb +47 -0
  164. data/lib/chef/resource/selinux/selinux_debian.erb +18 -0
  165. data/lib/chef/resource/selinux/selinux_default.erb +15 -0
  166. data/lib/chef/resource/selinux_boolean.rb +101 -0
  167. data/lib/chef/resource/selinux_fcontext.rb +160 -0
  168. data/lib/chef/resource/selinux_install.rb +107 -0
  169. data/lib/chef/resource/selinux_module.rb +143 -0
  170. data/lib/chef/resource/selinux_permissive.rb +64 -0
  171. data/lib/chef/resource/selinux_port.rb +118 -0
  172. data/lib/chef/resource/selinux_state.rb +166 -0
  173. data/lib/chef/resource/service.rb +0 -1
  174. data/lib/chef/resource/smartos_package.rb +2 -1
  175. data/lib/chef/resource/snap_package.rb +2 -1
  176. data/lib/chef/resource/solaris_package.rb +2 -1
  177. data/lib/chef/resource/ssh_known_hosts_entry.rb +0 -1
  178. data/lib/chef/resource/sudo.rb +0 -1
  179. data/lib/chef/resource/support/client.erb +2 -2
  180. data/lib/chef/resource/swap_file.rb +0 -1
  181. data/lib/chef/resource/sysctl.rb +1 -2
  182. data/lib/chef/resource/systemd_unit.rb +0 -1
  183. data/lib/chef/resource/template.rb +0 -1
  184. data/lib/chef/resource/timezone.rb +0 -1
  185. data/lib/chef/resource/user/aix_user.rb +0 -1
  186. data/lib/chef/resource/user/linux_user.rb +0 -1
  187. data/lib/chef/resource/user/mac_user.rb +0 -1
  188. data/lib/chef/resource/user/pw_user.rb +0 -1
  189. data/lib/chef/resource/user/solaris_user.rb +0 -1
  190. data/lib/chef/resource/user/windows_user.rb +0 -1
  191. data/lib/chef/resource/user.rb +10 -1
  192. data/lib/chef/resource/user_ulimit.rb +0 -1
  193. data/lib/chef/resource/whyrun_safe_ruby_block.rb +0 -1
  194. data/lib/chef/resource/windows_ad_join.rb +0 -2
  195. data/lib/chef/resource/windows_audit_policy.rb +0 -2
  196. data/lib/chef/resource/windows_auto_run.rb +0 -1
  197. data/lib/chef/resource/windows_defender.rb +0 -1
  198. data/lib/chef/resource/windows_defender_exclusion.rb +0 -1
  199. data/lib/chef/resource/windows_dfs_folder.rb +0 -1
  200. data/lib/chef/resource/windows_dfs_namespace.rb +0 -1
  201. data/lib/chef/resource/windows_dfs_server.rb +0 -1
  202. data/lib/chef/resource/windows_dns_record.rb +0 -1
  203. data/lib/chef/resource/windows_dns_zone.rb +0 -1
  204. data/lib/chef/resource/windows_env.rb +0 -1
  205. data/lib/chef/resource/windows_feature.rb +0 -1
  206. data/lib/chef/resource/windows_feature_dism.rb +0 -1
  207. data/lib/chef/resource/windows_feature_powershell.rb +0 -1
  208. data/lib/chef/resource/windows_firewall_profile.rb +0 -2
  209. data/lib/chef/resource/windows_firewall_rule.rb +0 -1
  210. data/lib/chef/resource/windows_font.rb +2 -3
  211. data/lib/chef/resource/windows_package.rb +3 -4
  212. data/lib/chef/resource/windows_pagefile.rb +0 -2
  213. data/lib/chef/resource/windows_path.rb +0 -1
  214. data/lib/chef/resource/windows_printer.rb +0 -1
  215. data/lib/chef/resource/windows_printer_port.rb +0 -1
  216. data/lib/chef/resource/windows_script.rb +0 -2
  217. data/lib/chef/resource/windows_security_policy.rb +0 -1
  218. data/lib/chef/resource/windows_service.rb +0 -1
  219. data/lib/chef/resource/windows_share.rb +0 -1
  220. data/lib/chef/resource/windows_shortcut.rb +1 -2
  221. data/lib/chef/resource/windows_task.rb +0 -1
  222. data/lib/chef/resource/windows_uac.rb +0 -1
  223. data/lib/chef/resource/windows_update_settings.rb +0 -1
  224. data/lib/chef/resource/windows_user_privilege.rb +0 -1
  225. data/lib/chef/resource/windows_workgroup.rb +0 -1
  226. data/lib/chef/resource/yum_package.rb +2 -1
  227. data/lib/chef/resource/yum_repository.rb +4 -1
  228. data/lib/chef/resource/zypper_package.rb +2 -1
  229. data/lib/chef/resource/zypper_repository.rb +0 -1
  230. data/lib/chef/resource.rb +12 -5
  231. data/lib/chef/resources.rb +7 -0
  232. data/lib/chef/run_context.rb +3 -3
  233. data/lib/chef/secret_fetcher/azure_key_vault.rb +3 -3
  234. data/lib/chef/version.rb +1 -1
  235. data/lib/chef/win32/handle.rb +6 -7
  236. data/lib/chef/win32/registry.rb +7 -3
  237. data/spec/data/chef_guid +1 -0
  238. data/spec/data/nodes/mcwfhpowell.json +3 -0
  239. data/spec/data/rubygems.org/sexp_processor-info +2 -1
  240. data/spec/data/trusted_certs/example.crt +20 -29
  241. data/spec/data/trusted_certs/example_no_cn.crt +34 -30
  242. data/spec/data/trusted_certs/opscode.pem +54 -33
  243. data/spec/functional/assets/yumrepo-empty/repodata/01a3b489a465bcac22a43492163df43451dc6ce47d27f66de289756b91635523-filelists.sqlite.bz2 +0 -0
  244. data/spec/functional/assets/yumrepo-empty/repodata/401dc19bda88c82c403423fb835844d64345f7e95f5b9835888189c03834cc93-filelists.xml.gz +0 -0
  245. data/spec/functional/assets/yumrepo-empty/repodata/5dc1e6e73c84803f059bb3065e684e56adfc289a7e398946574d79dac6643945-primary.sqlite.bz2 +0 -0
  246. data/spec/functional/assets/yumrepo-empty/repodata/6bf9672d0862e8ef8b8ff05a2fd0208a922b1f5978e6589d87944c88259cb670-other.xml.gz +0 -0
  247. data/spec/functional/assets/yumrepo-empty/repodata/7c36572015e075add2b38b900837bcdbb8a504130ddff49b2351a7fc0affa3d4-other.sqlite.bz2 +0 -0
  248. data/spec/functional/assets/yumrepo-empty/repodata/dabe2ce5481d23de1f4f52bdcfee0f9af98316c9e0de2ce8123adeefa0dd08b9-primary.xml.gz +0 -0
  249. data/spec/functional/assets/yumrepo-empty/repodata/repomd.xml +55 -0
  250. data/spec/functional/resource/chocolatey_package_spec.rb +20 -32
  251. data/spec/functional/resource/dsc_script_spec.rb +1 -1
  252. data/spec/functional/resource/group_spec.rb +10 -6
  253. data/spec/functional/resource/link_spec.rb +8 -8
  254. data/spec/functional/resource/macos_userdefaults_spec.rb +4 -4
  255. data/spec/functional/resource/plist_spec.rb +25 -0
  256. data/spec/functional/resource/user/linux_user_spec.rb +127 -0
  257. data/spec/functional/resource/windows_certificate_spec.rb +1 -26
  258. data/spec/functional/resource/windows_font_spec.rb +12 -9
  259. data/spec/functional/resource/yum_package_spec.rb +17 -1
  260. data/spec/functional/resource/zypper_package_spec.rb +12 -0
  261. data/spec/functional/shell_spec.rb +1 -2
  262. data/spec/functional/version_spec.rb +1 -1
  263. data/spec/integration/client/client_spec.rb +82 -3
  264. data/spec/integration/client/exit_code_spec.rb +1 -1
  265. data/spec/integration/client/fips_spec.rb +20 -0
  266. data/spec/integration/client/ipv6_spec.rb +1 -1
  267. data/spec/integration/compliance/compliance_spec.rb +1 -1
  268. data/spec/integration/recipes/accumulator_spec.rb +1 -1
  269. data/spec/integration/recipes/lwrp_inline_resources_spec.rb +1 -1
  270. data/spec/integration/recipes/lwrp_spec.rb +1 -1
  271. data/spec/integration/recipes/notifies_spec.rb +1 -1
  272. data/spec/integration/recipes/notifying_block_spec.rb +1 -1
  273. data/spec/integration/recipes/remote_directory.rb +1 -1
  274. data/spec/integration/recipes/unified_mode_spec.rb +1 -1
  275. data/spec/integration/recipes/use_partial_spec.rb +2 -1
  276. data/spec/integration/solo/solo_spec.rb +2 -2
  277. data/spec/spec_helper.rb +5 -0
  278. data/spec/support/platform_helpers.rb +8 -0
  279. data/spec/support/ruby_installer.rb +1 -1
  280. data/spec/support/shared/functional/windows_script.rb +2 -2
  281. data/spec/unit/application/client_spec.rb +0 -10
  282. data/spec/unit/chef_fs/file_system_spec.rb +2 -0
  283. data/spec/unit/client_spec.rb +57 -8
  284. data/spec/unit/compliance/reporter/chef_server_automate_spec.rb +1 -1
  285. data/spec/unit/cookbook/syntax_check_spec.rb +3 -0
  286. data/spec/unit/http/authenticator_spec.rb +68 -0
  287. data/spec/unit/mixin/powershell_exec_spec.rb +5 -5
  288. data/spec/unit/platform/query_helpers_spec.rb +2 -17
  289. data/spec/unit/property/validation_spec.rb +30 -0
  290. data/spec/unit/provider/cron_spec.rb +36 -0
  291. data/spec/unit/provider/http_request_spec.rb +60 -72
  292. data/spec/unit/provider/mount/linux_spec.rb +10 -0
  293. data/spec/unit/provider/package/chocolatey_spec.rb +3 -19
  294. data/spec/unit/provider/package/rubygems_spec.rb +1 -1
  295. data/spec/unit/provider/package/zypper_spec.rb +32 -0
  296. data/spec/unit/provider/user/linux_spec.rb +51 -11
  297. data/spec/unit/provider/user_spec.rb +24 -6
  298. data/spec/unit/resource/archive_file_spec.rb +1 -1
  299. data/spec/unit/resource/chef_client_cron_spec.rb +5 -0
  300. data/spec/unit/resource/chef_client_launchd_spec.rb +5 -0
  301. data/spec/unit/resource/chef_client_scheduled_task_spec.rb +5 -0
  302. data/spec/unit/resource/chef_client_systemd_timer_spec.rb +1 -1
  303. data/spec/unit/resource/cron_d_spec.rb +37 -1
  304. data/spec/unit/resource/macos_user_defaults_spec.rb +4 -4
  305. data/spec/unit/resource/rest_resource_spec.rb +381 -0
  306. data/spec/unit/resource/selinux_boolean_spec.rb +92 -0
  307. data/spec/unit/resource/selinux_fcontext_spec.rb +65 -0
  308. data/spec/unit/resource/selinux_install_spec.rb +60 -0
  309. data/spec/unit/resource/selinux_module_spec.rb +55 -0
  310. data/spec/unit/resource/selinux_permissive_spec.rb +39 -0
  311. data/spec/unit/resource/selinux_port_spec.rb +42 -0
  312. data/spec/unit/resource/selinux_state_spec.rb +46 -0
  313. data/spec/unit/resource/sysctl_spec.rb +2 -2
  314. data/spec/unit/resource/user/linux_user_spec.rb +42 -0
  315. data/spec/unit/resource/yum_repository_spec.rb +4 -0
  316. data/spec/unit/resource_spec.rb +0 -1
  317. data/spec/unit/util/dsc/local_configuration_manager_spec.rb +1 -1
  318. data/tasks/rspec.rb +1 -1
  319. metadata +107 -31
  320. /data/spec/functional/assets/chocolatey_feed/{test-A.1.0.0.nupkg → test-A.1.0.nupkg} +0 -0
  321. /data/spec/functional/assets/chocolatey_feed/{test-A.1.5.0.nupkg → test-A.1.5.nupkg} +0 -0
  322. /data/spec/functional/assets/chocolatey_feed/{test-A.2.0.0.nupkg → test-A.2.0.nupkg} +0 -0
  323. /data/spec/functional/assets/chocolatey_feed/{test-B.1.0.0.nupkg → test-B.1.0.nupkg} +0 -0
  324. /data/spec/functional/assets/yumrepo/repodata/{01a3b-filelists.sqlite.bz2 → 4632d67cb92636e7575d911c24f0e04d3505a944e97c483abe0c3e73a7c62d33-filelists.sqlite.bz2} +0 -0
  325. /data/spec/functional/assets/yumrepo/repodata/{6bf96-other.xml.gz → 74599b793e54d877323837d2d81a1c3c594c44e4335f9528234bb490f7b9b439-other.xml.gz} +0 -0
  326. /data/spec/functional/assets/yumrepo/repodata/{5dc1e-primary.sqlite.bz2 → a845d418f919d2115ab95a56b2c76f6825ad0d0bede49181a55c04f58995d057-primary.sqlite.bz2} +0 -0
  327. /data/spec/functional/assets/yumrepo/repodata/{7c365-other.sqlite.bz2 → af9b7cf9ef23bd7b43068d74a460f3b5d06753d638e58e4a0c9edc35bfb9cdc4-other.sqlite.bz2} +0 -0
  328. /data/spec/functional/assets/yumrepo/repodata/{401dc-filelists.xml.gz → bdb4f5f1492a3b9532f22c43110a81500dd744f23da0aec5c33b2a41317c737d-filelists.xml.gz} +0 -0
  329. /data/spec/functional/assets/yumrepo/repodata/{dabe2-primary.xml.gz → c10d1d34ce99e02f12ec96ef68360543ab1bb7c3cb81a4a2bf78df7d8597e9df-primary.xml.gz} +0 -0
@@ -20,7 +20,7 @@ require "chef/mixin/shell_out"
20
20
 
21
21
  # run this test only for following platforms.
22
22
  exclude_test = !(%w{rhel fedora amazon}.include?(OHAI_SYSTEM[:platform_family]) && !File.exist?("/usr/bin/dnf"))
23
- describe Chef::Resource::YumPackage, :requires_root, external: exclude_test, not_rhel6: true do
23
+ describe Chef::Resource::YumPackage, :requires_root, external: exclude_test do
24
24
  include RecipeDSLHelper
25
25
  include Chef::Mixin::ShellOut
26
26
 
@@ -57,6 +57,12 @@ describe Chef::Resource::YumPackage, :requires_root, external: exclude_test, not
57
57
  baseurl=file://#{CHEF_SPEC_ASSETS}/yumrepo
58
58
  enable=1
59
59
  gpgcheck=0
60
+ [chef-yum-empty]
61
+ name=Chef DNF spec empty repo
62
+ baseurl=file://#{CHEF_SPEC_ASSETS}/yumrepo-empty
63
+ enable=1
64
+ gpgcheck=0
65
+
60
66
  EOF
61
67
  end
62
68
  # ensure we don't have any stray chef_rpms installed
@@ -1095,6 +1101,16 @@ describe Chef::Resource::YumPackage, :requires_root, external: exclude_test, not
1095
1101
  end.should_not_be_updated
1096
1102
  end
1097
1103
 
1104
+ it "should work to disable a repo" do
1105
+ flush_cache
1106
+ expect {
1107
+ yum_package "chef_rpm" do
1108
+ options "--disablerepo=chef-yum-localtesting --enablerepo=chef-yum-empty"
1109
+ action :install
1110
+ end
1111
+ }.to raise_error(Chef::Exceptions::Package, /No candidate version available/)
1112
+ end
1113
+
1098
1114
  it "when an idempotent install action is run, does not leave repos disabled" do
1099
1115
  flush_cache
1100
1116
  # this is a bit tricky -- we need this action to be idempotent, so that it doesn't recycle any
@@ -74,6 +74,18 @@ describe Chef::Resource::ZypperPackage, :requires_root, :suse_only do
74
74
  expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^chef_rpm-1.10-1.#{pkg_arch}$")
75
75
  end
76
76
 
77
+ it "install package with source argument" do
78
+ zypper_package.source = "#{CHEF_SPEC_ASSETS}/zypprepo/chef_rpm-1.10-1.#{pkg_arch}.rpm"
79
+ zypper_package.run_action(:install)
80
+ expect(zypper_package.updated_by_last_action?).to be true
81
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^chef_rpm-1.10-1.#{pkg_arch}$")
82
+ end
83
+
84
+ it "raises an error when passed a source that does not exist" do
85
+ zypper_package.source = "#{CHEF_SPEC_ASSETS}/false/zypprepo/chef_rpm-1.10-1.#{pkg_arch}.rpm"
86
+ expect { zypper_package.run_action(:install) }.to raise_error(Mixlib::ShellOut::ShellCommandFailed)
87
+ end
88
+
77
89
  it "does not install if the package is installed" do
78
90
  preinstall("chef_rpm-1.10-1.#{pkg_arch}.rpm")
79
91
  zypper_package.run_action(:install)
@@ -78,7 +78,6 @@ describe Shell do
78
78
  def run_chef_shell_with(options)
79
79
  # Windows ruby installs don't (always?) have PTY,
80
80
  # so hide the require here
81
-
82
81
  require "pty"
83
82
 
84
83
  # FIXME this is temporary... Solaris envs have TERM set to unknown
@@ -87,7 +86,7 @@ describe Shell do
87
86
  ENV["TERM"] = "vt100" if ["", "unknown"].include?(ENV["TERM"].to_s)
88
87
 
89
88
  config = File.expand_path("shef-config.rb", CHEF_SPEC_DATA)
90
- reader, writer, pid = PTY.spawn("bundle exec chef-shell --no-multiline --no-singleline --no-colorize -c #{config} #{options}")
89
+ reader, writer, pid = PTY.spawn("bundle exec #{ChefUtils::Dist::Infra::SHELL} --no-multiline --no-singleline --no-colorize -c #{config} #{options}")
91
90
  read_until(reader, "chef (#{Chef::VERSION})>")
92
91
  yield reader, writer if block_given?
93
92
  writer.puts('"done"')
@@ -25,7 +25,7 @@ describe "Chef Versions", :executables do
25
25
  include Chef::Mixin::ShellOut
26
26
  let(:chef_dir) { File.join(__dir__, "..", "..") }
27
27
 
28
- binaries = [ ChefUtils::Dist::Infra::CLIENT, "chef-shell", "chef-apply", ChefUtils::Dist::Solo::EXEC ]
28
+ binaries = [ ChefUtils::Dist::Infra::CLIENT, ChefUtils::Dist::Infra::SHELL, "chef-apply", ChefUtils::Dist::Solo::EXEC ]
29
29
 
30
30
  binaries.each do |binary|
31
31
  it "#{binary} version should be sane" do
@@ -4,6 +4,10 @@ require "chef/mixin/shell_out"
4
4
  require "tiny_server"
5
5
  require "tmpdir"
6
6
  require "chef-utils/dist"
7
+ require "chef/mixin/powershell_exec"
8
+
9
+ # cspell:disable-next-line
10
+ SOME_CHARS = "~!@#%^&*_-+=`|\\(){}[<]:;'>,.?/0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz".each_char.to_a.freeze
7
11
 
8
12
  describe "chef-client" do
9
13
 
@@ -31,8 +35,56 @@ describe "chef-client" do
31
35
  @server = @api = nil
32
36
  end
33
37
 
38
+ def install_certificate_in_store(client_name)
39
+ if ChefUtils.windows?
40
+ powershell_exec! <<~EOH
41
+ if (-not (($PSVersionTable.PSVersion.Major -ge 5) -and ($PSVersionTable.PSVersion.Build -ge 22000)) ) {
42
+ New-SelfSignedCertificate -CertStoreLocation Cert:\\LocalMachine\\My -DnsName "#{client_name}"
43
+ }
44
+ else {
45
+ New-SelfSignedCertificate -CertStoreLocation Cert:\\LocalMachine\\My -Subject "#{client_name}" -FriendlyName "#{client_name}" -KeyExportPolicy Exportable
46
+ }
47
+ EOH
48
+ end
49
+ end
50
+
51
+ def create_registry_key
52
+ ::Chef::HTTP::Authenticator.get_cert_password
53
+ # @win32registry = Chef::Win32::Registry.new
54
+ # path = "HKEY_LOCAL_MACHINE\\Software\\Progress\\Authentication"
55
+ # unless @win32registry.key_exists?(path)
56
+ # @win32registry.create_key(path, true)
57
+ # end
58
+ # password = SOME_CHARS.sample(1 + rand(SOME_CHARS.count)).join[0...14]
59
+ # values = { name: "PfxPass", type: :string, data: password }
60
+ # @win32registry.set_value(path, values)
61
+ end
62
+
63
+ def remove_certificate_from_store
64
+ powershell_exec! <<~EOH
65
+ Get-ChildItem -path cert:\\LocalMachine\\My -Recurse -Force | Where-Object { $_.Subject -Match "#{client_name}" } -ErrorAction Stop | Remove-Item
66
+ EOH
67
+ end
68
+
69
+ def remove_registry_key
70
+ powershell_exec!("Remove-ItemProperty -Path HKLM:\\SOFTWARE\\Progress\\Authentication -Name 'PfxPass' ")
71
+ end
72
+
73
+ def verify_export_password_exists
74
+ powershell_exec! <<~EOH
75
+ Try {
76
+ $response = Get-ItemProperty -Path "HKLM:\\Software\\Progress\\Authentication" -Name "PfxPass" -ErrorAction Stop
77
+ if ($response) {return $true}
78
+ }
79
+ Catch {
80
+ return $false
81
+ }
82
+ EOH
83
+ end
84
+
34
85
  include IntegrationSupport
35
86
  include Chef::Mixin::ShellOut
87
+ include Chef::Mixin::PowershellExec
36
88
 
37
89
  let(:chef_dir) { File.join(__dir__, "..", "..", "..") }
38
90
 
@@ -45,8 +97,10 @@ describe "chef-client" do
45
97
  # machine that has omnibus chef installed. In that case we need to ensure
46
98
  # we're running `chef-client` from the source tree and not the external one.
47
99
  # cf. CHEF-4914
48
- let(:chef_client) { "bundle exec #{ChefUtils::Dist::Infra::CLIENT} --minimal-ohai" }
49
- let(:chef_solo) { "bundle exec #{ChefUtils::Dist::Solo::EXEC} --legacy-mode --minimal-ohai" }
100
+ let(:chef_client) { "bundle exec #{ChefUtils::Dist::Infra::CLIENT} --minimal-ohai --always-dump-stacktrace" }
101
+ let(:chef_solo) { "bundle exec #{ChefUtils::Dist::Solo::EXEC} --legacy-mode --minimal-ohai --always-dump-stacktrace" }
102
+ let(:client_name) { "chef-973334" }
103
+ let(:hostname) { "973334" }
50
104
 
51
105
  context "when validation.pem in current Directory" do
52
106
  let(:validation_path) { "" }
@@ -133,7 +187,6 @@ describe "chef-client" do
133
187
  # FATAL: Configuration error NoMethodError: undefined method `xxx' for nil:NilClass
134
188
  expect(result.stdout).to include("xxx")
135
189
  end
136
-
137
190
  end
138
191
 
139
192
  it "should complete with success" do
@@ -146,6 +199,32 @@ describe "chef-client" do
146
199
  result.error!
147
200
  end
148
201
 
202
+ if ChefUtils.windows?
203
+ context "and the private key is in the Windows CertStore" do
204
+ before do
205
+ install_certificate_in_store(client_name)
206
+ create_registry_key
207
+ end
208
+
209
+ after do
210
+ remove_certificate_from_store
211
+ remove_registry_key
212
+ end
213
+
214
+ it "should verify that the cert is loaded in the LocalMachine\\My" do
215
+ expect(Chef::HTTP::Authenticator.check_certstore_for_key(hostname)).to eq(true)
216
+ end
217
+
218
+ it "should verify that the export password for the pfx is loaded in the Registry" do
219
+ expect(verify_export_password_exists.result).to eq(true)
220
+ end
221
+
222
+ it "should verify that a private key is returned to me" do
223
+ expect(Chef::HTTP::Authenticator.retrieve_certificate_key(client_name)).not_to be nil
224
+ end
225
+ end
226
+ end
227
+
149
228
  context "and a private key" do
150
229
  before do
151
230
  file "mykey.pem", <<~EOM
@@ -23,7 +23,7 @@ describe "chef-client" do
23
23
  # machine that has omnibus chef installed. In that case we need to ensure
24
24
  # we're running `chef-client` from the source tree and not the external one.
25
25
  # cf. CHEF-4914
26
- let(:chef_client) { "bundle exec #{ChefUtils::Dist::Infra::CLIENT} --no-fork --minimal-ohai" }
26
+ let(:chef_client) { "bundle exec #{ChefUtils::Dist::Infra::CLIENT} --no-fork --minimal-ohai --always-dump-stacktrace" }
27
27
 
28
28
  let(:critical_env_vars) { %w{PATH RUBYOPT BUNDLE_GEMFILE GEM_PATH}.map { |o| "#{o}=#{ENV[o]}" } .join(" ") }
29
29
 
@@ -0,0 +1,20 @@
1
+ require "spec_helper"
2
+
3
+ describe "chef-client fips" do
4
+ def enable_fips
5
+ OpenSSL.fips_mode = true
6
+ end
7
+
8
+ # All tests assume fips mode is off at present
9
+ after { OpenSSL.fips_mode = false }
10
+
11
+ # For non-FIPS OSes/builds of Ruby, enabling FIPS should error
12
+ example "Error enabling fips_mode if FIPS not linked", fips_mode: false do
13
+ expect { enable_fips }.to raise_error(OpenSSL::OpenSSLError)
14
+ end
15
+
16
+ # For FIPS OSes/builds of Ruby, enabling FIPS should not error
17
+ example "Do not error enabling fips_mode if FIPS linked", fips_mode: true do
18
+ expect { enable_fips }.not_to raise_error
19
+ end
20
+ end
@@ -76,7 +76,7 @@ describe "chef-client" do
76
76
 
77
77
  let(:chef_dir) { File.join(__dir__, "..", "..", "..") }
78
78
 
79
- let(:chef_client_cmd) { %Q{bundle exec chef-client --minimal-ohai -c "#{path_to("config/client.rb")}" -lwarn} }
79
+ let(:chef_client_cmd) { %Q{bundle exec #{ChefUtils::Dist::Infra::CLIENT} --minimal-ohai -c "#{path_to("config/client.rb")}" -lwarn --always-dump-stacktrace} }
80
80
 
81
81
  after do
82
82
  FileUtils.rm_rf(cache_path)
@@ -20,7 +20,7 @@ describe "chef-client with compliance phase" do
20
20
  # machine that has omnibus chef installed. In that case we need to ensure
21
21
  # we're running `chef-client` from the source tree and not the external one.
22
22
  # cf. CHEF-4914
23
- let(:chef_client) { "bundle exec #{ChefUtils::Dist::Infra::CLIENT} --minimal-ohai" }
23
+ let(:chef_client) { "bundle exec #{ChefUtils::Dist::Infra::CLIENT} --minimal-ohai --always-dump-stacktrace" }
24
24
 
25
25
  when_the_repository "has a custom profile" do
26
26
  let(:report_file) { path_to("report_file.json") }
@@ -17,7 +17,7 @@ describe "Accumulators" do
17
17
  # machine that has omnibus chef installed. In that case we need to ensure
18
18
  # we're running `chef-client` from the source tree and not the external one.
19
19
  # cf. CHEF-4914
20
- let(:chef_client) { "bundle exec chef-client --minimal-ohai" }
20
+ let(:chef_client) { "bundle exec #{ChefUtils::Dist::Infra::CLIENT} --minimal-ohai --always-dump-stacktrace" }
21
21
 
22
22
  let(:aliases_temppath) do
23
23
  t = Tempfile.new("chef_accumulator_test")
@@ -17,7 +17,7 @@ describe "LWRPs with inline resources" do
17
17
  # machine that has omnibus chef installed. In that case we need to ensure
18
18
  # we're running `chef-client` from the source tree and not the external one.
19
19
  # cf. CHEF-4914
20
- let(:chef_client) { "bundle exec chef-client --minimal-ohai" }
20
+ let(:chef_client) { "bundle exec #{ChefUtils::Dist::Infra::CLIENT} --minimal-ohai --always-dump-stacktrace" }
21
21
 
22
22
  context "with a use_inline_resources provider with 'def action_a' instead of action :a" do
23
23
  class LwrpInlineResourcesTest < Chef::Resource
@@ -17,7 +17,7 @@ describe "LWRPs" do
17
17
  # machine that has omnibus chef installed. In that case we need to ensure
18
18
  # we're running `chef-client` from the source tree and not the external one.
19
19
  # cf. CHEF-4914
20
- let(:chef_client) { "bundle exec chef-client --minimal-ohai" }
20
+ let(:chef_client) { "bundle exec #{ChefUtils::Dist::Infra::CLIENT} --minimal-ohai --always-dump-stacktrace" }
21
21
 
22
22
  when_the_repository "has a cookbook named l-w-r-p" do
23
23
  before do
@@ -23,7 +23,7 @@ describe "notifications" do
23
23
  include Chef::Mixin::ShellOut
24
24
 
25
25
  let(:chef_dir) { File.expand_path("../../..", __dir__) }
26
- let(:chef_client) { "bundle exec chef-client --minimal-ohai" }
26
+ let(:chef_client) { "bundle exec #{ChefUtils::Dist::Infra::CLIENT} --minimal-ohai --always-dump-stacktrace" }
27
27
 
28
28
  when_the_repository "notifies a nameless resource" do
29
29
  before do
@@ -24,7 +24,7 @@ describe "notifying_block" do
24
24
  include Chef::Mixin::ShellOut
25
25
 
26
26
  let(:chef_dir) { File.expand_path("../../..", __dir__) }
27
- let(:chef_client) { "bundle exec chef-client --minimal-ohai" }
27
+ let(:chef_client) { "bundle exec #{ChefUtils::Dist::Infra::CLIENT} --minimal-ohai --always-dump-stacktrace" }
28
28
 
29
29
  when_the_repository "notifying_block test one" do
30
30
  before do
@@ -16,7 +16,7 @@ describe Chef::Resource::RemoteDirectory do
16
16
  # machine that has omnibus chef installed. In that case we need to ensure
17
17
  # we're running `chef-client` from the source tree and not the external one.
18
18
  # cf. CHEF-4914
19
- let(:chef_client) { "bundle exec chef-client --minimal-ohai" }
19
+ let(:chef_client) { "bundle exec #{ChefUtils::Dist::Infra::CLIENT} --minimal-ohai --always-dump-stacktrace" }
20
20
 
21
21
  when_the_repository "has a cookbook with a source_dir with two subdirectories, each with one file and subdir in a different alphabetical order" do
22
22
  before do
@@ -8,7 +8,7 @@ describe "Unified Mode" do
8
8
 
9
9
  let(:chef_dir) { File.expand_path("../../..", __dir__) }
10
10
 
11
- let(:chef_client) { "bundle exec chef-client --minimal-ohai" }
11
+ let(:chef_client) { "bundle exec #{ChefUtils::Dist::Infra::CLIENT} --minimal-ohai --always-dump-stacktrace" }
12
12
 
13
13
  when_the_repository "has a cookbook with a unified_mode resource with a delayed notification from the second block to the first block" do
14
14
  before do
@@ -23,10 +23,11 @@ describe "notifying_block" do
23
23
  include Chef::Mixin::ShellOut
24
24
 
25
25
  let(:chef_dir) { File.expand_path("../../..", __dir__) }
26
- let(:chef_client) { "bundle exec chef-client --minimal-ohai" }
26
+ let(:chef_client) { "bundle exec #{ChefUtils::Dist::Infra::CLIENT} --minimal-ohai --always-dump-stacktrace" }
27
27
 
28
28
  when_the_repository "has a cookbook with partial resources" do
29
29
  before do
30
+ ::Chef::HTTP::Authenticator.get_cert_password if windows?
30
31
  directory "cookbooks/x" do
31
32
  file "resources/_shared_properties.rb", <<-EOM
32
33
  property :content, String
@@ -18,7 +18,7 @@ describe ChefUtils::Dist::Solo::EXEC do
18
18
 
19
19
  let(:cookbook_ancient_100_metadata_rb) { cb_metadata("ancient", "1.0.0") }
20
20
 
21
- let(:chef_solo) { "bundle exec #{ChefUtils::Dist::Solo::EXEC} --legacy-mode --minimal-ohai" }
21
+ let(:chef_solo) { "bundle exec #{ChefUtils::Dist::Solo::EXEC} --legacy-mode --minimal-ohai --always-dump-stacktrace" }
22
22
 
23
23
  when_the_repository "creates nodes" do
24
24
  let(:nodes_dir) { File.join(@repository_dir, "nodes") }
@@ -28,7 +28,7 @@ describe ChefUtils::Dist::Solo::EXEC do
28
28
  file "config/solo.rb", <<~EOM
29
29
  chef_repo_path "#{@repository_dir}"
30
30
  EOM
31
- result = shell_out("bundle exec chef-solo -c \"#{path_to("config/solo.rb")}\" -l debug", cwd: chef_dir)
31
+ result = shell_out("bundle exec #{ChefUtils::Dist::Solo::EXEC} --minimal-ohai --always-dump-stacktrace -c \"#{path_to("config/solo.rb")}\" -l debug", cwd: chef_dir)
32
32
  result.error!
33
33
  end
34
34
 
data/spec/spec_helper.rb CHANGED
@@ -138,12 +138,17 @@ RSpec.configure do |config|
138
138
 
139
139
  config.filter_run_excluding skip_buildkite: true if ENV["BUILDKITE"]
140
140
 
141
+ config.filter_run_excluding fips_mode: !fips_mode_build? unless opensuse?
142
+ # RubyDistros OpenSUSE docker images have a broken fips
143
+ config.filter_run_excluding :fips_mode if opensuse?
144
+
141
145
  config.filter_run_excluding windows_only: true unless windows?
142
146
  config.filter_run_excluding not_supported_on_windows: true if windows?
143
147
  config.filter_run_excluding not_supported_on_macos: true if macos?
144
148
  config.filter_run_excluding macos_only: true unless macos?
145
149
  config.filter_run_excluding not_macos_gte_11: true if macos_gte_11?
146
150
  config.filter_run_excluding not_supported_on_aix: true if aix?
151
+ config.filter_run_excluding not_supported_on_freebsd_gte_12_3: true if freebsd_gte_12_3?
147
152
  config.filter_run_excluding not_supported_on_solaris: true if solaris?
148
153
  config.filter_run_excluding not_supported_on_gce: true if gce?
149
154
  config.filter_run_excluding win2012r2_only: true unless windows_2012r2?
@@ -127,6 +127,10 @@ def freebsd?
127
127
  RUBY_PLATFORM.include?("freebsd")
128
128
  end
129
129
 
130
+ def freebsd_gte_12_3?
131
+ RUBY_PLATFORM.include?("freebsd") && !!(ohai[:platform_version].to_f >= 12.3)
132
+ end
133
+
130
134
  def intel_64bit?
131
135
  !!(ohai[:kernel][:machine] == "x86_64")
132
136
  end
@@ -219,6 +223,10 @@ def aes_256_gcm?
219
223
  OpenSSL::Cipher.ciphers.include?("aes-256-gcm")
220
224
  end
221
225
 
226
+ def fips_mode_build?
227
+ OpenSSL::OPENSSL_FIPS
228
+ end
229
+
222
230
  def fips?
223
231
  ENV["CHEF_FIPS"] == "1"
224
232
  end
@@ -48,4 +48,4 @@ rescue LoadError
48
48
  $stderr.puts "Failed to load ruby_installer. Assuming Ruby Installer is not being used."
49
49
  end
50
50
 
51
- add_libarchive_dll_directory if RUBY_PLATFORM.match?(/mswin|mingw32|windows/)
51
+ add_libarchive_dll_directory if RUBY_PLATFORM.match?(/mswin|mingw|windows/)
@@ -163,7 +163,7 @@ shared_context Chef::Resource::WindowsScript do
163
163
 
164
164
  describe "when the run action is invoked on Windows" do
165
165
  it "executes the script code" do
166
- resource.code("whoami > \"#{script_output_path}\"")
166
+ resource.code("chcp > \"#{script_output_path}\"")
167
167
  resource.returns(0)
168
168
  resource.run_action(:run)
169
169
  end
@@ -199,7 +199,7 @@ shared_context Chef::Resource::WindowsScript do
199
199
  end
200
200
 
201
201
  it "executes the script code" do
202
- resource.code("whoami > \"#{script_output_path}\"")
202
+ resource.code("chcp > \"#{script_output_path}\"")
203
203
  resource.returns(0)
204
204
  resource.run_action(:run)
205
205
  end
@@ -564,16 +564,6 @@ describe Chef::Application::Client, "run_application", :unix_only do
564
564
  expect(IO.select([@pipe[0]], nil, nil, 0)).not_to be_nil
565
565
  expect(@pipe[0].gets).to eq("finished\n")
566
566
  end
567
-
568
- it "should exit hard when sent before converge" do
569
- pid = fork do
570
- sleep 3
571
- @app.run_application
572
- end
573
- Process.kill("TERM", pid)
574
- _pid, result = Process.waitpid2(pid)
575
- expect(result.exitstatus).to eq(3)
576
- end
577
567
  end
578
568
  end
579
569
 
@@ -145,4 +145,6 @@ describe Chef::ChefFS::FileSystem, ruby: ">= 3.0" do
145
145
  end
146
146
  end
147
147
  end
148
+
149
+ # Need to add the test case for copy_to method - not able to do the implimentation with Dir.mktmpdir
148
150
  end
@@ -23,6 +23,11 @@ require "chef/run_context"
23
23
  require "chef/server_api"
24
24
  require "rbconfig"
25
25
 
26
+ begin
27
+ require "chef-powershell"
28
+ rescue LoadError
29
+ end
30
+
26
31
  class FooError < RuntimeError
27
32
  end
28
33
 
@@ -113,6 +118,7 @@ shared_context "a client run" do
113
118
  # --Client.register
114
119
  # Make sure Client#register thinks the client key doesn't
115
120
  # exist, so it tries to register and create one.
121
+ allow(Chef::HTTP::Authenticator).to receive(:detect_certificate_key).with(fqdn).and_return(false)
116
122
  allow(File).to receive(:exists?).and_call_original
117
123
  expect(File).to receive(:exists?)
118
124
  .with(Chef::Config[:client_key])
@@ -201,7 +207,6 @@ shared_context "a client run" do
201
207
 
202
208
  # Post conditions: check that node has been filled in correctly
203
209
  expect(client).to receive(:run_started)
204
-
205
210
  stub_for_run
206
211
  end
207
212
  end
@@ -262,7 +267,7 @@ end
262
267
 
263
268
  # requires platform and platform_version be defined
264
269
  shared_examples "a completed run" do
265
- include_context "run completed"
270
+ include_context "run completed" # should receive run_completed_successfully
266
271
 
267
272
  it "runs ohai, sets up authentication, loads node state, synchronizes policy, converges" do
268
273
  # This is what we're testing.
@@ -282,6 +287,53 @@ shared_examples "a failed run" do
282
287
  end
283
288
  end
284
289
 
290
+ describe Chef::Client, :windows_only do
291
+ let(:hostname) { "test" }
292
+ let(:my_client) { Chef::Client.new }
293
+ let(:cert_name) { "chef-#{hostname}" }
294
+ let(:node_name) { "#{hostname}" }
295
+ let(:end_date) do
296
+ d = Time.now
297
+ if d.month == 10 || d.month == 11 || d.month == 12
298
+ end_date = Time.new(d.year + 1, d.month - 9, d.day, d.hour, d.min, d.sec).utc.iso8601
299
+ else
300
+ end_date = Time.new(d.year, d.month + 3, d.day, d.hour, d.min, d.sec).utc.iso8601
301
+ end
302
+ end
303
+ # include_context "client"
304
+ before(:each) do
305
+ Chef::Config[:migrate_key_to_keystore] = true
306
+ end
307
+
308
+ after(:each) do
309
+ delete_certificate(cert_name)
310
+ end
311
+
312
+ context "when the client intially boots the first time" do
313
+ it "verfies that a certificate was correctly created and exists in the Cert Store" do
314
+ new_pfx = my_client.generate_pfx_package(cert_name, end_date)
315
+ my_client.import_pfx_to_store(new_pfx)
316
+ expect(my_client.check_certstore_for_key(cert_name)).not_to be false
317
+ end
318
+
319
+ it "correctly returns a new Publc Key" do
320
+ new_pfx = my_client.generate_pfx_package(cert_name, end_date)
321
+ cert_object = new_pfx.certificate.public_key.to_pem
322
+ expect(cert_object.to_s).to match(/PUBLIC KEY/)
323
+ end
324
+
325
+ end
326
+
327
+ def delete_certificate(cert_name)
328
+ require "chef/mixin/powershell_exec"
329
+ extend Chef::Mixin::PowershellExec
330
+ powershell_code = <<~CODE
331
+ Get-ChildItem -path cert:\\LocalMachine\\My -Recurse -Force | Where-Object { $_.Subject -Match "#{cert_name}" } | Remove-item
332
+ CODE
333
+ powershell_exec!(powershell_code)
334
+ end
335
+ end
336
+
285
337
  describe Chef::Client do
286
338
  include_context "client"
287
339
 
@@ -311,17 +363,14 @@ describe Chef::Client do
311
363
  describe "eol release warning" do
312
364
  it "warns when running an EOL release" do
313
365
  stub_const("Chef::VERSION", 15)
314
- # added a call to client because Time.now gets invoked multiple times during instantiation. Don't mock Time until after client initialized
315
- client
316
- expect(Time).to receive(:now).and_return(Time.new(2021, 5, 1, 5))
317
- allow(client).to receive(:eol_override).and_return(false)
318
- expect(logger).to receive(:warn).with("This release of Chef Infra Client became end of life (EOL) on May 01, 2021. Please update to a supported release to receive new features, bug fixes, and security updates.")
366
+ allow(Time).to receive(:now).and_return(Time.new(2021, 5, 1, 5))
367
+ expect(logger).to receive(:warn).with(/This release of.*became end of life \(EOL\) on May 1st 2021/)
319
368
  client.warn_if_eol
320
369
  end
321
370
 
322
371
  it "does not warn when running an non-EOL release" do
323
372
  stub_const("Chef::VERSION", 15)
324
- allow(Time).to receive(:now).and_return(Time.new(2021, 4, 30))
373
+ allow(Time).to receive(:now).and_return(Time.new(2021, 4, 31))
325
374
  expect(logger).to_not receive(:warn).with(/became end of life/)
326
375
  client.warn_if_eol
327
376
  end
@@ -170,7 +170,7 @@ describe Chef::Compliance::Reporter::ChefServerAutomate do
170
170
  "X-Ops-Userid" => "spec-node",
171
171
  "X-Remote-Request-Id" => /.+/,
172
172
  }
173
- ).to_return(status: 200, body: "OK")
173
+ ).to_return(status: 200)
174
174
 
175
175
  expect(reporter.send_report(inspec_report)).to eq(true)
176
176
 
@@ -159,12 +159,15 @@ describe Chef::Cookbook::SyntaxCheck do
159
159
  end
160
160
 
161
161
  describe "and a file has a syntax error" do
162
+
162
163
  before do
163
164
  cookbook_path = File.join(CHEF_SPEC_DATA, "cookbooks", "borken")
164
165
  syntax_check.cookbook_path.replace(cookbook_path)
165
166
  end
166
167
 
167
168
  it "it indicates that a ruby file has a syntax error" do
169
+ expect(Chef::Log).to receive(:fatal).with("Cookbook file borken/recipes/default.rb has a ruby syntax error.")
170
+ allow(Chef::Log).to receive(:fatal)
168
171
  expect(syntax_check.validate_ruby_files).to be_falsey
169
172
  end
170
173