chef 17.10.163 → 18.0.169

Sign up to get free protection for your applications and to get access to all the features.
Files changed (330) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +19 -20
  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 +17 -15
  7. data/lib/chef/api_client_v1.rb +9 -1
  8. data/lib/chef/application/exit_code.rb +3 -3
  9. data/lib/chef/client.rb +182 -0
  10. data/lib/chef/compliance/input.rb +1 -1
  11. data/lib/chef/compliance/profile.rb +1 -1
  12. data/lib/chef/compliance/profile_collection.rb +0 -1
  13. data/lib/chef/compliance/waiver.rb +1 -1
  14. data/lib/chef/cookbook/syntax_check.rb +2 -2
  15. data/lib/chef/dsl/reader_helpers.rb +1 -1
  16. data/lib/chef/dsl/rest_resource.rb +77 -0
  17. data/lib/chef/event_dispatch/base.rb +3 -0
  18. data/lib/chef/exceptions.rb +8 -0
  19. data/lib/chef/http/authenticator.rb +170 -3
  20. data/lib/chef/http/ssl_policies.rb +4 -4
  21. data/lib/chef/mixin/checksum.rb +0 -6
  22. data/lib/chef/mixin/homebrew_user.rb +5 -15
  23. data/lib/chef/mixin/openssl_helper.rb +13 -17
  24. data/lib/chef/mixin/powershell_exec.rb +5 -28
  25. data/lib/chef/node/mixin/immutablize_array.rb +1 -0
  26. data/lib/chef/property.rb +5 -3
  27. data/lib/chef/provider/cron.rb +1 -5
  28. data/lib/chef/provider/file.rb +2 -2
  29. data/lib/chef/provider/group/windows.rb +1 -1
  30. data/lib/chef/provider/http_request.rb +11 -9
  31. data/lib/chef/provider/mount/linux.rb +5 -0
  32. data/lib/chef/provider/mount/mount.rb +8 -0
  33. data/lib/chef/provider/mount/windows.rb +1 -1
  34. data/lib/chef/provider/package/chocolatey.rb +1 -14
  35. data/lib/chef/provider/package/rubygems.rb +1 -1
  36. data/lib/chef/provider/package/windows/msi.rb +2 -2
  37. data/lib/chef/provider/package/windows/registry_uninstall_entry.rb +1 -1
  38. data/lib/chef/provider/package/windows.rb +1 -1
  39. data/lib/chef/provider/package/yum/yum_helper.py +14 -2
  40. data/lib/chef/provider/package/zypper/version.rb +60 -0
  41. data/lib/chef/provider/package/zypper.rb +47 -8
  42. data/lib/chef/provider/service/windows.rb +1 -1
  43. data/lib/chef/provider/user/aix.rb +5 -0
  44. data/lib/chef/provider/user/linux.rb +29 -0
  45. data/lib/chef/provider/user/mac.rb +1 -1
  46. data/lib/chef/provider/user.rb +46 -14
  47. data/lib/chef/provider.rb +1 -1
  48. data/lib/chef/recipe.rb +1 -1
  49. data/lib/chef/resource/_rest_resource.rb +389 -0
  50. data/lib/chef/resource/alternatives.rb +0 -1
  51. data/lib/chef/resource/apt_package.rb +0 -1
  52. data/lib/chef/resource/apt_preference.rb +0 -1
  53. data/lib/chef/resource/apt_repository.rb +0 -1
  54. data/lib/chef/resource/apt_update.rb +0 -1
  55. data/lib/chef/resource/archive_file.rb +0 -1
  56. data/lib/chef/resource/bash.rb +0 -1
  57. data/lib/chef/resource/batch.rb +0 -1
  58. data/lib/chef/resource/bff_package.rb +0 -1
  59. data/lib/chef/resource/breakpoint.rb +0 -1
  60. data/lib/chef/resource/build_essential.rb +0 -1
  61. data/lib/chef/resource/cab_package.rb +0 -1
  62. data/lib/chef/resource/chef_client_config.rb +14 -18
  63. data/lib/chef/resource/chef_client_cron.rb +1 -2
  64. data/lib/chef/resource/chef_client_launchd.rb +2 -2
  65. data/lib/chef/resource/chef_client_scheduled_task.rb +3 -3
  66. data/lib/chef/resource/chef_client_systemd_timer.rb +1 -2
  67. data/lib/chef/resource/chef_client_trusted_certificate.rb +0 -1
  68. data/lib/chef/resource/chef_gem.rb +0 -1
  69. data/lib/chef/resource/chef_handler.rb +0 -1
  70. data/lib/chef/resource/chef_sleep.rb +1 -3
  71. data/lib/chef/resource/chef_vault_secret.rb +0 -1
  72. data/lib/chef/resource/chocolatey_config.rb +0 -1
  73. data/lib/chef/resource/chocolatey_feature.rb +0 -1
  74. data/lib/chef/resource/chocolatey_package.rb +0 -1
  75. data/lib/chef/resource/chocolatey_source.rb +0 -1
  76. data/lib/chef/resource/cookbook_file.rb +0 -1
  77. data/lib/chef/resource/cron/_cron_shared.rb +0 -1
  78. data/lib/chef/resource/cron/cron.rb +0 -1
  79. data/lib/chef/resource/cron/cron_d.rb +15 -1
  80. data/lib/chef/resource/cron_access.rb +0 -1
  81. data/lib/chef/resource/csh.rb +0 -1
  82. data/lib/chef/resource/directory.rb +0 -1
  83. data/lib/chef/resource/dmg_package.rb +0 -1
  84. data/lib/chef/resource/dnf_package.rb +0 -1
  85. data/lib/chef/resource/dpkg_package.rb +0 -1
  86. data/lib/chef/resource/dsc_resource.rb +0 -1
  87. data/lib/chef/resource/dsc_script.rb +0 -1
  88. data/lib/chef/resource/execute.rb +0 -1
  89. data/lib/chef/resource/file.rb +0 -1
  90. data/lib/chef/resource/freebsd_package.rb +0 -1
  91. data/lib/chef/resource/gem_package.rb +0 -1
  92. data/lib/chef/resource/group.rb +25 -2
  93. data/lib/chef/resource/habitat/habitat_package.rb +0 -1
  94. data/lib/chef/resource/habitat/habitat_sup.rb +6 -7
  95. data/lib/chef/resource/habitat/habitat_sup_windows.rb +1 -1
  96. data/lib/chef/resource/habitat_config.rb +0 -1
  97. data/lib/chef/resource/habitat_install.rb +0 -1
  98. data/lib/chef/resource/habitat_service.rb +0 -1
  99. data/lib/chef/resource/habitat_user_toml.rb +0 -1
  100. data/lib/chef/resource/homebrew_cask.rb +8 -8
  101. data/lib/chef/resource/homebrew_package.rb +1 -2
  102. data/lib/chef/resource/homebrew_tap.rb +5 -6
  103. data/lib/chef/resource/homebrew_update.rb +0 -2
  104. data/lib/chef/resource/hostname.rb +0 -1
  105. data/lib/chef/resource/http_request.rb +0 -1
  106. data/lib/chef/resource/ifconfig.rb +0 -1
  107. data/lib/chef/resource/inspec_input.rb +0 -1
  108. data/lib/chef/resource/inspec_waiver.rb +0 -1
  109. data/lib/chef/resource/inspec_waiver_file_entry.rb +2 -3
  110. data/lib/chef/resource/ips_package.rb +0 -1
  111. data/lib/chef/resource/kernel_module.rb +0 -1
  112. data/lib/chef/resource/ksh.rb +0 -1
  113. data/lib/chef/resource/launchd.rb +0 -1
  114. data/lib/chef/resource/link.rb +0 -1
  115. data/lib/chef/resource/locale.rb +2 -6
  116. data/lib/chef/resource/log.rb +0 -1
  117. data/lib/chef/resource/lwrp_base.rb +0 -4
  118. data/lib/chef/resource/macos_userdefaults.rb +5 -10
  119. data/lib/chef/resource/macosx_service.rb +0 -1
  120. data/lib/chef/resource/macports_package.rb +0 -1
  121. data/lib/chef/resource/mdadm.rb +0 -1
  122. data/lib/chef/resource/mount.rb +0 -1
  123. data/lib/chef/resource/msu_package.rb +0 -1
  124. data/lib/chef/resource/notify_group.rb +0 -2
  125. data/lib/chef/resource/ohai.rb +0 -1
  126. data/lib/chef/resource/ohai_hint.rb +0 -1
  127. data/lib/chef/resource/openbsd_package.rb +0 -1
  128. data/lib/chef/resource/openssl_dhparam.rb +0 -2
  129. data/lib/chef/resource/openssl_ec_private_key.rb +0 -2
  130. data/lib/chef/resource/openssl_ec_public_key.rb +0 -2
  131. data/lib/chef/resource/openssl_rsa_private_key.rb +0 -2
  132. data/lib/chef/resource/openssl_rsa_public_key.rb +0 -2
  133. data/lib/chef/resource/openssl_x509_certificate.rb +0 -2
  134. data/lib/chef/resource/openssl_x509_crl.rb +0 -2
  135. data/lib/chef/resource/openssl_x509_request.rb +0 -2
  136. data/lib/chef/resource/osx_profile.rb +0 -1
  137. data/lib/chef/resource/package.rb +0 -1
  138. data/lib/chef/resource/pacman_package.rb +0 -1
  139. data/lib/chef/resource/paludis_package.rb +0 -1
  140. data/lib/chef/resource/perl.rb +0 -1
  141. data/lib/chef/resource/plist.rb +7 -3
  142. data/lib/chef/resource/portage_package.rb +0 -1
  143. data/lib/chef/resource/powershell_package.rb +0 -1
  144. data/lib/chef/resource/powershell_package_source.rb +0 -1
  145. data/lib/chef/resource/powershell_script.rb +0 -1
  146. data/lib/chef/resource/python.rb +0 -1
  147. data/lib/chef/resource/reboot.rb +0 -1
  148. data/lib/chef/resource/registry_key.rb +0 -1
  149. data/lib/chef/resource/remote_directory.rb +0 -1
  150. data/lib/chef/resource/remote_file.rb +0 -1
  151. data/lib/chef/resource/rhsm_errata.rb +0 -1
  152. data/lib/chef/resource/rhsm_errata_level.rb +0 -1
  153. data/lib/chef/resource/rhsm_register.rb +0 -3
  154. data/lib/chef/resource/rhsm_repo.rb +0 -1
  155. data/lib/chef/resource/rhsm_subscription.rb +0 -1
  156. data/lib/chef/resource/route.rb +0 -1
  157. data/lib/chef/resource/rpm_package.rb +0 -1
  158. data/lib/chef/resource/ruby.rb +0 -1
  159. data/lib/chef/resource/ruby_block.rb +0 -1
  160. data/lib/chef/resource/scm/_scm.rb +0 -2
  161. data/lib/chef/resource/scm/git.rb +0 -2
  162. data/lib/chef/resource/scm/subversion.rb +0 -2
  163. data/lib/chef/resource/script.rb +0 -1
  164. data/lib/chef/resource/selinux/common_helpers.rb +47 -0
  165. data/lib/chef/resource/selinux/selinux_debian.erb +18 -0
  166. data/lib/chef/resource/selinux/selinux_default.erb +15 -0
  167. data/lib/chef/resource/selinux_boolean.rb +101 -0
  168. data/lib/chef/resource/selinux_fcontext.rb +160 -0
  169. data/lib/chef/resource/selinux_install.rb +107 -0
  170. data/lib/chef/resource/selinux_module.rb +143 -0
  171. data/lib/chef/resource/selinux_permissive.rb +64 -0
  172. data/lib/chef/resource/selinux_port.rb +118 -0
  173. data/lib/chef/resource/selinux_state.rb +166 -0
  174. data/lib/chef/resource/service.rb +0 -1
  175. data/lib/chef/resource/smartos_package.rb +0 -1
  176. data/lib/chef/resource/snap_package.rb +0 -1
  177. data/lib/chef/resource/solaris_package.rb +0 -1
  178. data/lib/chef/resource/ssh_known_hosts_entry.rb +0 -1
  179. data/lib/chef/resource/sudo.rb +0 -1
  180. data/lib/chef/resource/support/client.erb +5 -6
  181. data/lib/chef/resource/swap_file.rb +0 -1
  182. data/lib/chef/resource/sysctl.rb +1 -2
  183. data/lib/chef/resource/systemd_unit.rb +0 -1
  184. data/lib/chef/resource/template.rb +0 -1
  185. data/lib/chef/resource/timezone.rb +0 -1
  186. data/lib/chef/resource/user/aix_user.rb +0 -1
  187. data/lib/chef/resource/user/linux_user.rb +0 -1
  188. data/lib/chef/resource/user/mac_user.rb +0 -1
  189. data/lib/chef/resource/user/pw_user.rb +0 -1
  190. data/lib/chef/resource/user/solaris_user.rb +0 -1
  191. data/lib/chef/resource/user/windows_user.rb +0 -1
  192. data/lib/chef/resource/user.rb +10 -1
  193. data/lib/chef/resource/user_ulimit.rb +0 -1
  194. data/lib/chef/resource/whyrun_safe_ruby_block.rb +0 -1
  195. data/lib/chef/resource/windows_ad_join.rb +0 -2
  196. data/lib/chef/resource/windows_audit_policy.rb +0 -2
  197. data/lib/chef/resource/windows_auto_run.rb +0 -1
  198. data/lib/chef/resource/windows_defender.rb +0 -1
  199. data/lib/chef/resource/windows_defender_exclusion.rb +0 -1
  200. data/lib/chef/resource/windows_dfs_folder.rb +0 -1
  201. data/lib/chef/resource/windows_dfs_namespace.rb +0 -1
  202. data/lib/chef/resource/windows_dfs_server.rb +0 -1
  203. data/lib/chef/resource/windows_dns_record.rb +0 -1
  204. data/lib/chef/resource/windows_dns_zone.rb +0 -1
  205. data/lib/chef/resource/windows_env.rb +0 -1
  206. data/lib/chef/resource/windows_feature.rb +0 -1
  207. data/lib/chef/resource/windows_feature_dism.rb +0 -1
  208. data/lib/chef/resource/windows_feature_powershell.rb +0 -1
  209. data/lib/chef/resource/windows_firewall_profile.rb +0 -2
  210. data/lib/chef/resource/windows_firewall_rule.rb +0 -1
  211. data/lib/chef/resource/windows_font.rb +2 -3
  212. data/lib/chef/resource/windows_package.rb +0 -1
  213. data/lib/chef/resource/windows_pagefile.rb +0 -2
  214. data/lib/chef/resource/windows_path.rb +0 -1
  215. data/lib/chef/resource/windows_printer.rb +0 -1
  216. data/lib/chef/resource/windows_printer_port.rb +0 -1
  217. data/lib/chef/resource/windows_script.rb +0 -2
  218. data/lib/chef/resource/windows_security_policy.rb +0 -1
  219. data/lib/chef/resource/windows_service.rb +0 -1
  220. data/lib/chef/resource/windows_share.rb +0 -1
  221. data/lib/chef/resource/windows_shortcut.rb +1 -2
  222. data/lib/chef/resource/windows_task.rb +0 -1
  223. data/lib/chef/resource/windows_uac.rb +0 -1
  224. data/lib/chef/resource/windows_update_settings.rb +0 -1
  225. data/lib/chef/resource/windows_user_privilege.rb +0 -1
  226. data/lib/chef/resource/windows_workgroup.rb +0 -1
  227. data/lib/chef/resource/yum_package.rb +0 -1
  228. data/lib/chef/resource/yum_repository.rb +0 -1
  229. data/lib/chef/resource/zypper_package.rb +0 -1
  230. data/lib/chef/resource/zypper_repository.rb +0 -1
  231. data/lib/chef/resource.rb +12 -5
  232. data/lib/chef/resources.rb +7 -0
  233. data/lib/chef/run_context.rb +3 -3
  234. data/lib/chef/secret_fetcher/azure_key_vault.rb +1 -1
  235. data/lib/chef/version.rb +1 -1
  236. data/lib/chef/win32/handle.rb +6 -7
  237. data/lib/chef/win32/registry.rb +7 -3
  238. data/spec/data/rubygems.org/sexp_processor-info +2 -1
  239. data/spec/data/trusted_certs/example.crt +20 -29
  240. data/spec/data/trusted_certs/example_no_cn.crt +34 -30
  241. data/spec/data/trusted_certs/opscode.pem +54 -33
  242. data/spec/functional/resource/chocolatey_package_spec.rb +20 -32
  243. data/spec/functional/resource/dsc_script_spec.rb +1 -1
  244. data/spec/functional/resource/group_spec.rb +26 -42
  245. data/spec/functional/resource/link_spec.rb +8 -8
  246. data/spec/functional/resource/macos_userdefaults_spec.rb +4 -4
  247. data/spec/functional/resource/plist_spec.rb +25 -0
  248. data/spec/functional/resource/user/linux_user_spec.rb +127 -0
  249. data/spec/functional/resource/windows_certificate_spec.rb +1 -26
  250. data/spec/functional/resource/windows_font_spec.rb +12 -9
  251. data/spec/functional/resource/yum_package_spec.rb +1 -17
  252. data/spec/functional/resource/zypper_package_spec.rb +12 -10
  253. data/spec/functional/shell_spec.rb +1 -2
  254. data/spec/functional/version_spec.rb +1 -1
  255. data/spec/functional/win32/registry_spec.rb +0 -3
  256. data/spec/integration/client/client_spec.rb +82 -3
  257. data/spec/integration/client/exit_code_spec.rb +1 -1
  258. data/spec/integration/client/ipv6_spec.rb +1 -1
  259. data/spec/integration/compliance/compliance_spec.rb +1 -1
  260. data/spec/integration/recipes/accumulator_spec.rb +1 -1
  261. data/spec/integration/recipes/lwrp_inline_resources_spec.rb +1 -1
  262. data/spec/integration/recipes/lwrp_spec.rb +1 -1
  263. data/spec/integration/recipes/notifies_spec.rb +1 -1
  264. data/spec/integration/recipes/notifying_block_spec.rb +1 -1
  265. data/spec/integration/recipes/remote_directory.rb +1 -1
  266. data/spec/integration/recipes/unified_mode_spec.rb +1 -1
  267. data/spec/integration/recipes/use_partial_spec.rb +2 -1
  268. data/spec/integration/solo/solo_spec.rb +2 -2
  269. data/spec/spec_helper.rb +1 -5
  270. data/spec/support/platform_helpers.rb +0 -4
  271. data/spec/support/ruby_installer.rb +1 -1
  272. data/spec/support/shared/functional/windows_script.rb +2 -2
  273. data/spec/unit/application/client_spec.rb +0 -10
  274. data/spec/unit/client_spec.rb +70 -2
  275. data/spec/unit/compliance/reporter/chef_server_automate_spec.rb +1 -1
  276. data/spec/unit/cookbook/syntax_check_spec.rb +3 -0
  277. data/spec/unit/http/authenticator_spec.rb +68 -0
  278. data/spec/unit/mixin/checksum_spec.rb +0 -28
  279. data/spec/unit/mixin/homebrew_user_spec.rb +7 -30
  280. data/spec/unit/mixin/openssl_helper_spec.rb +1 -1
  281. data/spec/unit/mixin/powershell_exec_spec.rb +5 -5
  282. data/spec/unit/platform/query_helpers_spec.rb +2 -17
  283. data/spec/unit/provider/cron_spec.rb +0 -34
  284. data/spec/unit/provider/http_request_spec.rb +60 -72
  285. data/spec/unit/provider/mount/linux_spec.rb +10 -0
  286. data/spec/unit/provider/package/chocolatey_spec.rb +3 -20
  287. data/spec/unit/provider/package/rubygems_spec.rb +1 -1
  288. data/spec/unit/provider/package/zypper_spec.rb +32 -0
  289. data/spec/unit/provider/user/linux_spec.rb +51 -11
  290. data/spec/unit/provider/user_spec.rb +24 -6
  291. data/spec/unit/resource/archive_file_spec.rb +1 -1
  292. data/spec/unit/resource/chef_client_cron_spec.rb +5 -0
  293. data/spec/unit/resource/chef_client_launchd_spec.rb +5 -0
  294. data/spec/unit/resource/chef_client_scheduled_task_spec.rb +5 -0
  295. data/spec/unit/resource/chef_client_systemd_timer_spec.rb +2 -2
  296. data/spec/unit/resource/cron_d_spec.rb +37 -1
  297. data/spec/unit/resource/macos_user_defaults_spec.rb +4 -4
  298. data/spec/unit/resource/rest_resource_spec.rb +381 -0
  299. data/spec/unit/resource/selinux_boolean_spec.rb +92 -0
  300. data/spec/unit/resource/selinux_fcontext_spec.rb +65 -0
  301. data/spec/unit/resource/selinux_install_spec.rb +60 -0
  302. data/spec/unit/resource/selinux_module_spec.rb +55 -0
  303. data/spec/unit/resource/selinux_permissive_spec.rb +39 -0
  304. data/spec/unit/resource/selinux_port_spec.rb +42 -0
  305. data/spec/unit/resource/selinux_state_spec.rb +46 -0
  306. data/spec/unit/resource/sysctl_spec.rb +2 -2
  307. data/spec/unit/resource/user/linux_user_spec.rb +42 -0
  308. data/spec/unit/resource_spec.rb +8 -2
  309. data/spec/unit/util/dsc/local_configuration_manager_spec.rb +1 -1
  310. data/tasks/rspec.rb +1 -1
  311. metadata +106 -55
  312. data/spec/functional/assets/yumrepo-empty/repodata/01a3b-filelists.sqlite.bz2 +0 -0
  313. data/spec/functional/assets/yumrepo-empty/repodata/401dc-filelists.xml.gz +0 -0
  314. data/spec/functional/assets/yumrepo-empty/repodata/5dc1e-primary.sqlite.bz2 +0 -0
  315. data/spec/functional/assets/yumrepo-empty/repodata/6bf96-other.xml.gz +0 -0
  316. data/spec/functional/assets/yumrepo-empty/repodata/7c365-other.sqlite.bz2 +0 -0
  317. data/spec/functional/assets/yumrepo-empty/repodata/dabe2-primary.xml.gz +0 -0
  318. data/spec/functional/assets/yumrepo-empty/repodata/repomd.xml +0 -55
  319. data/spec/integration/client/fips_spec.rb +0 -29
  320. data/spec/integration/client/open_ssl_spec.rb +0 -20
  321. /data/spec/functional/assets/chocolatey_feed/{test-A.1.0.0.nupkg → test-A.1.0.nupkg} +0 -0
  322. /data/spec/functional/assets/chocolatey_feed/{test-A.1.5.0.nupkg → test-A.1.5.nupkg} +0 -0
  323. /data/spec/functional/assets/chocolatey_feed/{test-A.2.0.0.nupkg → test-A.2.0.nupkg} +0 -0
  324. /data/spec/functional/assets/chocolatey_feed/{test-B.1.0.0.nupkg → test-B.1.0.nupkg} +0 -0
  325. /data/spec/functional/assets/yumrepo/repodata/{01a3b-filelists.sqlite.bz2 → 4632d67cb92636e7575d911c24f0e04d3505a944e97c483abe0c3e73a7c62d33-filelists.sqlite.bz2} +0 -0
  326. /data/spec/functional/assets/yumrepo/repodata/{6bf96-other.xml.gz → 74599b793e54d877323837d2d81a1c3c594c44e4335f9528234bb490f7b9b439-other.xml.gz} +0 -0
  327. /data/spec/functional/assets/yumrepo/repodata/{5dc1e-primary.sqlite.bz2 → a845d418f919d2115ab95a56b2c76f6825ad0d0bede49181a55c04f58995d057-primary.sqlite.bz2} +0 -0
  328. /data/spec/functional/assets/yumrepo/repodata/{7c365-other.sqlite.bz2 → af9b7cf9ef23bd7b43068d74a460f3b5d06753d638e58e4a0c9edc35bfb9cdc4-other.sqlite.bz2} +0 -0
  329. /data/spec/functional/assets/yumrepo/repodata/{401dc-filelists.xml.gz → bdb4f5f1492a3b9532f22c43110a81500dd744f23da0aec5c33b2a41317c737d-filelists.xml.gz} +0 -0
  330. /data/spec/functional/assets/yumrepo/repodata/{dabe2-primary.xml.gz → c10d1d34ce99e02f12ec96ef68360543ab1bb7c3cb81a4a2bf78df7d8597e9df-primary.xml.gz} +0 -0
@@ -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
 
@@ -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,15 +138,13 @@ 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?
142
-
143
- config.filter_run_excluding not_supported_on_freebsd_gte_12_3: true if freebsd_gte_12_3?
144
141
  config.filter_run_excluding windows_only: true unless windows?
145
142
  config.filter_run_excluding not_supported_on_windows: true if windows?
146
143
  config.filter_run_excluding not_supported_on_macos: true if macos?
147
144
  config.filter_run_excluding macos_only: true unless macos?
148
145
  config.filter_run_excluding not_macos_gte_11: true if macos_gte_11?
149
146
  config.filter_run_excluding not_supported_on_aix: true if aix?
147
+ config.filter_run_excluding not_supported_on_freebsd_gte_12_3: true if freebsd_gte_12_3?
150
148
  config.filter_run_excluding not_supported_on_solaris: true if solaris?
151
149
  config.filter_run_excluding not_supported_on_gce: true if gce?
152
150
  config.filter_run_excluding win2012r2_only: true unless windows_2012r2?
@@ -166,8 +164,6 @@ RSpec.configure do |config|
166
164
  config.filter_run_excluding linux_only: true unless linux?
167
165
  config.filter_run_excluding aix_only: true unless aix?
168
166
  config.filter_run_excluding suse_only: true unless suse?
169
- # These aren't valid on verify pipeline because the docker container brings its own OpenSSL
170
- config.filter_run_excluding openssl_version_check: true if ENV["BUILDKITE_PIPELINE_SLUG"] =~ /verify/
171
167
  config.filter_run_excluding opensuse: true unless opensuse?
172
168
  config.filter_run_excluding debian_family_only: true unless debian_family?
173
169
  config.filter_run_excluding supports_cloexec: true unless supports_cloexec?
@@ -223,10 +223,6 @@ def aes_256_gcm?
223
223
  OpenSSL::Cipher.ciphers.include?("aes-256-gcm")
224
224
  end
225
225
 
226
- def fips_mode_build?
227
- OpenSSL::OPENSSL_FIPS
228
- end
229
-
230
226
  def fips?
231
227
  ENV["CHEF_FIPS"] == "1"
232
228
  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
 
@@ -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
 
@@ -308,6 +360,22 @@ describe Chef::Client do
308
360
  end
309
361
  end
310
362
 
363
+ describe "eol release warning" do
364
+ it "warns when running an EOL release" do
365
+ stub_const("Chef::VERSION", 15)
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/)
368
+ client.warn_if_eol
369
+ end
370
+
371
+ it "does not warn when running an non-EOL release" do
372
+ stub_const("Chef::VERSION", 15)
373
+ allow(Time).to receive(:now).and_return(Time.new(2021, 4, 31))
374
+ expect(logger).to_not receive(:warn).with(/became end of life/)
375
+ client.warn_if_eol
376
+ end
377
+ end
378
+
311
379
  describe "authentication protocol selection" do
312
380
  context "when FIPS is disabled" do
313
381
  before do
@@ -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
 
@@ -19,6 +19,70 @@
19
19
  require "spec_helper"
20
20
  require "chef/http/authenticator"
21
21
 
22
+ describe Chef::HTTP::Authenticator, :windows_only do
23
+ let(:class_instance) { Chef::HTTP::Authenticator.new(client_name: "test") }
24
+ let(:method) { "GET" }
25
+ let(:url) { URI("https://chef.example.com/organizations/test") }
26
+ let(:headers) { {} }
27
+ let(:data) { "" }
28
+ let(:node_name) { "test" }
29
+ let(:passwrd) { "some_insecure_password" }
30
+
31
+ before do
32
+ Chef::Config[:node_name] = node_name
33
+ cert_name = "chef-#{node_name}"
34
+ d = Time.now
35
+ end_date = Time.new + (3600 * 24 * 90)
36
+ end_date = end_date.utc.iso8601
37
+
38
+ my_client = Chef::Client.new
39
+ pfx = my_client.generate_pfx_package(cert_name, end_date)
40
+ my_client.import_pfx_to_store(pfx)
41
+ end
42
+
43
+ after(:each) do
44
+ require "chef/mixin/powershell_exec"
45
+ extend Chef::Mixin::PowershellExec
46
+ cert_name = "chef-#{node_name}"
47
+ delete_certificate(cert_name)
48
+ end
49
+
50
+ context "when retrieving a certificate from the certificate store" do
51
+ it "retrieves a certificate password from the registry when the hive does not already exist" do
52
+ delete_registry_hive
53
+ expect { class_instance.get_cert_password }.not_to raise_error
54
+ end
55
+
56
+ it "should return a password of at least 14 characters in length" do
57
+ password = class_instance.get_cert_password
58
+ expect(password.length).to eql(14)
59
+ end
60
+
61
+ it "correctly retrieves a valid certificate in pem format from the certstore" do
62
+ require "openssl"
63
+ certificate = class_instance.retrieve_certificate_key(node_name)
64
+ cert_object = OpenSSL::PKey::RSA.new(certificate)
65
+ expect(cert_object.to_s).to match(/BEGIN RSA PRIVATE KEY/)
66
+ end
67
+ end
68
+
69
+ def delete_certificate(cert_name)
70
+ powershell_code = <<~CODE
71
+ Get-ChildItem -path cert:\\LocalMachine\\My -Recurse -Force | Where-Object { $_.Subject -Match "#{cert_name}" } | Remove-item
72
+ CODE
73
+ powershell_exec!(powershell_code)
74
+ end
75
+
76
+ def delete_registry_hive
77
+ @win32registry = Chef::Win32::Registry.new
78
+ path = "HKEY_LOCAL_MACHINE\\Software\\Progress\\Authentication"
79
+ present = @win32registry.get_values(path)
80
+ unless present.nil? || present.empty?
81
+ @win32registry.delete_key(path, true)
82
+ end
83
+ end
84
+ end
85
+
22
86
  describe Chef::HTTP::Authenticator do
23
87
  let(:class_instance) { Chef::HTTP::Authenticator.new(client_name: "test") }
24
88
  let(:method) { "GET" }
@@ -26,6 +90,10 @@ describe Chef::HTTP::Authenticator do
26
90
  let(:headers) { {} }
27
91
  let(:data) { "" }
28
92
 
93
+ before do
94
+ ::Chef::Config[:node_name] = "foo"
95
+ end
96
+
29
97
  context "when handle_request is called" do
30
98
  shared_examples_for "merging the server API version into the headers" do
31
99
  before do
@@ -51,32 +51,4 @@ describe Chef::Mixin::Checksum do
51
51
  end
52
52
  end
53
53
 
54
- describe "checksum_match?" do
55
- context "when checksum cases match" do
56
- it "returns true" do
57
- expect(@checksum_user.checksum_match?("u7ghbxikk3i9blsimmy2y2ionmxx", "u7ghbxikk3i9blsimmy2y2ionmxx")).to be true
58
- end
59
- end
60
-
61
- context "when one checksum is uppercase and other is lowercase" do
62
- it "returns true" do
63
- expect(@checksum_user.checksum_match?("U7GHBXIKK3I9BLSIMMY2Y2IONMXX", "u7ghbxikk3i9blsimmy2y2ionmxx")).to be true
64
- end
65
- end
66
-
67
- context "when checksums do not match" do
68
- it "returns false" do
69
- expect(@checksum_user.checksum_match?("u7ghbxikk3i9blsimmy2y2ionmxx", "09ee9c8cc70501763563bcf9c218")).to be false
70
- end
71
- end
72
-
73
- context "when checksum is nil" do
74
- it "returns false" do
75
- expect(@checksum_user.checksum_match?("u7ghbxikk3i9blsimmy2y2ionmxx", nil)).to be false
76
- expect(@checksum_user.checksum_match?(nil, "09ee9c8cc70501763563bcf9c218")).to be false
77
- expect(@checksum_user.checksum_match?(nil, nil)).to be false
78
- end
79
- end
80
- end
81
-
82
54
  end
@@ -47,8 +47,6 @@ describe Chef::Mixin::HomebrewUser do
47
47
  let(:user) { nil }
48
48
  let(:brew_owner) { 2001 }
49
49
  let(:default_brew_path) { "/usr/local/bin/brew" }
50
- let(:default_brew_path_arm) { "/opt/homebrew/bin/brew" }
51
- let(:default_brew_path_linux) { "/home/linuxbrew/.linuxbrew/bin/brew" }
52
50
  let(:stat_double) do
53
51
  d = double
54
52
  expect(d).to receive(:uid).and_return(brew_owner)
@@ -61,38 +59,16 @@ describe Chef::Mixin::HomebrewUser do
61
59
  expect(Etc).to receive(:getpwuid).with(brew_owner).and_return(OpenStruct.new(name: "name"))
62
60
  end
63
61
 
64
- def false_unless_specific_value(object, method, value)
65
- allow(object).to receive(method).and_return(false)
66
- allow(object).to receive(method).with(value).and_return(true)
67
- end
68
-
69
- it "returns the owner of the brew executable when it is at a default location for x86_64 machines" do
70
- false_unless_specific_value(File, :exist?, default_brew_path)
71
- false_unless_specific_value(File, :executable?, default_brew_path)
72
- allow(File).to receive(:stat).with(default_brew_path).and_return(stat_double)
73
- expect(homebrew_user.find_homebrew_uid(user)).to eq(brew_owner)
74
- end
75
-
76
- it "returns the owner of the brew executable when it is at a default location for arm machines" do
77
- false_unless_specific_value(File, :exist?, default_brew_path_arm)
78
- false_unless_specific_value(File, :executable?, default_brew_path_arm)
79
- allow(File).to receive(:stat).with(default_brew_path_arm).and_return(stat_double)
80
- expect(homebrew_user.find_homebrew_uid(user)).to eq(brew_owner)
81
- end
82
-
83
- it "returns the owner of the brew executable when it is at a default location for linux machines" do
84
- false_unless_specific_value(File, :exist?, default_brew_path_linux)
85
- false_unless_specific_value(File, :executable?, default_brew_path_linux)
86
- allow(File).to receive(:stat).with(default_brew_path_linux).and_return(stat_double)
62
+ it "returns the owner of the brew executable when it is at a default location" do
63
+ expect(File).to receive(:exist?).with(default_brew_path).and_return(true)
64
+ expect(File).to receive(:stat).with(default_brew_path).and_return(stat_double)
87
65
  expect(homebrew_user.find_homebrew_uid(user)).to eq(brew_owner)
88
66
  end
89
67
 
90
68
  it "returns the owner of the brew executable when it is not at a default location" do
91
- allow_any_instance_of(ExampleHomebrewUser).to receive(:which).and_return("/foo")
92
- false_unless_specific_value(File, :exist?, "/foo")
93
- false_unless_specific_value(File, :executable?, "/foo")
69
+ expect(File).to receive(:exist?).with(default_brew_path).and_return(false)
94
70
  allow(homebrew_user).to receive_message_chain(:shell_out, :stdout, :strip).and_return("/foo")
95
- allow(File).to receive(:stat).with("/foo").and_return(stat_double)
71
+ expect(File).to receive(:stat).with("/foo").and_return(stat_double)
96
72
  expect(homebrew_user.find_homebrew_uid(user)).to eq(brew_owner)
97
73
  end
98
74
 
@@ -102,7 +78,8 @@ describe Chef::Mixin::HomebrewUser do
102
78
  describe "when the homebrew user is not provided" do
103
79
 
104
80
  it "raises an error if no executable is found" do
105
- expect(File).to receive(:exist?).and_return(nil).at_least(:once)
81
+ expect(File).to receive(:exist?).with(default_brew_path).and_return(false)
82
+ allow(homebrew_user).to receive_message_chain(:shell_out, :stdout, :strip).and_return("")
106
83
  expect { homebrew_user.find_homebrew_uid(user) }.to raise_error(Chef::Exceptions::CannotDetermineHomebrewOwner)
107
84
  end
108
85