chef 17.10.114 → 18.0.169

Sign up to get free protection for your applications and to get access to all the features.
Files changed (315) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +19 -12
  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 +15 -8
  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 +171 -20
  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 +3 -3
  21. data/lib/chef/mixin/checksum.rb +0 -6
  22. data/lib/chef/mixin/homebrew_user.rb +5 -15
  23. data/lib/chef/mixin/powershell_exec.rb +5 -28
  24. data/lib/chef/node/mixin/immutablize_array.rb +1 -0
  25. data/lib/chef/property.rb +5 -3
  26. data/lib/chef/provider/file.rb +2 -2
  27. data/lib/chef/provider/group/windows.rb +1 -1
  28. data/lib/chef/provider/http_request.rb +11 -9
  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/windows/msi.rb +2 -2
  35. data/lib/chef/provider/package/windows/registry_uninstall_entry.rb +1 -1
  36. data/lib/chef/provider/package/windows.rb +1 -1
  37. data/lib/chef/provider/package/zypper/version.rb +60 -0
  38. data/lib/chef/provider/package/zypper.rb +47 -8
  39. data/lib/chef/provider/service/windows.rb +1 -2
  40. data/lib/chef/provider/user/aix.rb +5 -0
  41. data/lib/chef/provider/user/linux.rb +29 -0
  42. data/lib/chef/provider/user/mac.rb +1 -1
  43. data/lib/chef/provider/user.rb +46 -14
  44. data/lib/chef/provider.rb +1 -1
  45. data/lib/chef/recipe.rb +1 -1
  46. data/lib/chef/resource/_rest_resource.rb +389 -0
  47. data/lib/chef/resource/alternatives.rb +0 -1
  48. data/lib/chef/resource/apt_package.rb +0 -1
  49. data/lib/chef/resource/apt_preference.rb +0 -1
  50. data/lib/chef/resource/apt_repository.rb +0 -1
  51. data/lib/chef/resource/apt_update.rb +0 -1
  52. data/lib/chef/resource/archive_file.rb +0 -1
  53. data/lib/chef/resource/bash.rb +0 -1
  54. data/lib/chef/resource/batch.rb +0 -1
  55. data/lib/chef/resource/bff_package.rb +0 -1
  56. data/lib/chef/resource/breakpoint.rb +0 -1
  57. data/lib/chef/resource/build_essential.rb +0 -1
  58. data/lib/chef/resource/cab_package.rb +0 -1
  59. data/lib/chef/resource/chef_client_config.rb +12 -14
  60. data/lib/chef/resource/chef_client_cron.rb +1 -2
  61. data/lib/chef/resource/chef_client_launchd.rb +2 -2
  62. data/lib/chef/resource/chef_client_scheduled_task.rb +3 -3
  63. data/lib/chef/resource/chef_client_systemd_timer.rb +1 -2
  64. data/lib/chef/resource/chef_client_trusted_certificate.rb +0 -1
  65. data/lib/chef/resource/chef_gem.rb +0 -1
  66. data/lib/chef/resource/chef_handler.rb +0 -1
  67. data/lib/chef/resource/chef_sleep.rb +1 -3
  68. data/lib/chef/resource/chef_vault_secret.rb +0 -1
  69. data/lib/chef/resource/chocolatey_config.rb +0 -1
  70. data/lib/chef/resource/chocolatey_feature.rb +0 -1
  71. data/lib/chef/resource/chocolatey_package.rb +0 -1
  72. data/lib/chef/resource/chocolatey_source.rb +0 -1
  73. data/lib/chef/resource/cookbook_file.rb +0 -1
  74. data/lib/chef/resource/cron/_cron_shared.rb +0 -1
  75. data/lib/chef/resource/cron/cron.rb +0 -1
  76. data/lib/chef/resource/cron/cron_d.rb +15 -1
  77. data/lib/chef/resource/cron_access.rb +0 -1
  78. data/lib/chef/resource/csh.rb +0 -1
  79. data/lib/chef/resource/directory.rb +0 -1
  80. data/lib/chef/resource/dmg_package.rb +0 -1
  81. data/lib/chef/resource/dnf_package.rb +0 -1
  82. data/lib/chef/resource/dpkg_package.rb +0 -1
  83. data/lib/chef/resource/dsc_resource.rb +0 -1
  84. data/lib/chef/resource/dsc_script.rb +0 -1
  85. data/lib/chef/resource/execute.rb +0 -1
  86. data/lib/chef/resource/file.rb +0 -1
  87. data/lib/chef/resource/freebsd_package.rb +0 -1
  88. data/lib/chef/resource/gem_package.rb +0 -1
  89. data/lib/chef/resource/group.rb +25 -2
  90. data/lib/chef/resource/habitat/habitat_package.rb +0 -1
  91. data/lib/chef/resource/habitat/habitat_sup.rb +6 -7
  92. data/lib/chef/resource/habitat/habitat_sup_windows.rb +1 -1
  93. data/lib/chef/resource/habitat_config.rb +0 -1
  94. data/lib/chef/resource/habitat_install.rb +0 -1
  95. data/lib/chef/resource/habitat_service.rb +0 -1
  96. data/lib/chef/resource/habitat_user_toml.rb +0 -1
  97. data/lib/chef/resource/homebrew_cask.rb +8 -8
  98. data/lib/chef/resource/homebrew_package.rb +1 -2
  99. data/lib/chef/resource/homebrew_tap.rb +5 -6
  100. data/lib/chef/resource/homebrew_update.rb +0 -2
  101. data/lib/chef/resource/hostname.rb +0 -1
  102. data/lib/chef/resource/http_request.rb +0 -1
  103. data/lib/chef/resource/ifconfig.rb +0 -1
  104. data/lib/chef/resource/inspec_input.rb +0 -1
  105. data/lib/chef/resource/inspec_waiver.rb +0 -1
  106. data/lib/chef/resource/inspec_waiver_file_entry.rb +2 -3
  107. data/lib/chef/resource/ips_package.rb +0 -1
  108. data/lib/chef/resource/kernel_module.rb +0 -1
  109. data/lib/chef/resource/ksh.rb +0 -1
  110. data/lib/chef/resource/launchd.rb +0 -1
  111. data/lib/chef/resource/link.rb +0 -1
  112. data/lib/chef/resource/locale.rb +2 -6
  113. data/lib/chef/resource/log.rb +0 -1
  114. data/lib/chef/resource/lwrp_base.rb +0 -4
  115. data/lib/chef/resource/macos_userdefaults.rb +5 -10
  116. data/lib/chef/resource/macosx_service.rb +0 -1
  117. data/lib/chef/resource/macports_package.rb +0 -1
  118. data/lib/chef/resource/mdadm.rb +0 -1
  119. data/lib/chef/resource/mount.rb +0 -1
  120. data/lib/chef/resource/msu_package.rb +0 -1
  121. data/lib/chef/resource/notify_group.rb +0 -2
  122. data/lib/chef/resource/ohai.rb +0 -1
  123. data/lib/chef/resource/ohai_hint.rb +0 -1
  124. data/lib/chef/resource/openbsd_package.rb +0 -1
  125. data/lib/chef/resource/openssl_dhparam.rb +0 -2
  126. data/lib/chef/resource/openssl_ec_private_key.rb +0 -2
  127. data/lib/chef/resource/openssl_ec_public_key.rb +0 -2
  128. data/lib/chef/resource/openssl_rsa_private_key.rb +0 -2
  129. data/lib/chef/resource/openssl_rsa_public_key.rb +0 -2
  130. data/lib/chef/resource/openssl_x509_certificate.rb +0 -2
  131. data/lib/chef/resource/openssl_x509_crl.rb +0 -2
  132. data/lib/chef/resource/openssl_x509_request.rb +0 -2
  133. data/lib/chef/resource/osx_profile.rb +0 -1
  134. data/lib/chef/resource/package.rb +0 -1
  135. data/lib/chef/resource/pacman_package.rb +0 -1
  136. data/lib/chef/resource/paludis_package.rb +0 -1
  137. data/lib/chef/resource/perl.rb +0 -1
  138. data/lib/chef/resource/plist.rb +7 -3
  139. data/lib/chef/resource/portage_package.rb +0 -1
  140. data/lib/chef/resource/powershell_package.rb +0 -1
  141. data/lib/chef/resource/powershell_package_source.rb +0 -1
  142. data/lib/chef/resource/powershell_script.rb +0 -1
  143. data/lib/chef/resource/python.rb +0 -1
  144. data/lib/chef/resource/reboot.rb +0 -1
  145. data/lib/chef/resource/registry_key.rb +0 -1
  146. data/lib/chef/resource/remote_directory.rb +0 -1
  147. data/lib/chef/resource/remote_file.rb +0 -1
  148. data/lib/chef/resource/rhsm_errata.rb +0 -1
  149. data/lib/chef/resource/rhsm_errata_level.rb +0 -1
  150. data/lib/chef/resource/rhsm_register.rb +0 -3
  151. data/lib/chef/resource/rhsm_repo.rb +0 -1
  152. data/lib/chef/resource/rhsm_subscription.rb +0 -1
  153. data/lib/chef/resource/route.rb +0 -1
  154. data/lib/chef/resource/rpm_package.rb +0 -1
  155. data/lib/chef/resource/ruby.rb +0 -1
  156. data/lib/chef/resource/ruby_block.rb +0 -1
  157. data/lib/chef/resource/scm/_scm.rb +0 -2
  158. data/lib/chef/resource/scm/git.rb +0 -2
  159. data/lib/chef/resource/scm/subversion.rb +0 -2
  160. data/lib/chef/resource/script.rb +0 -1
  161. data/lib/chef/resource/selinux/common_helpers.rb +47 -0
  162. data/lib/chef/resource/selinux/selinux_debian.erb +18 -0
  163. data/lib/chef/resource/selinux/selinux_default.erb +15 -0
  164. data/lib/chef/resource/selinux_boolean.rb +101 -0
  165. data/lib/chef/resource/selinux_fcontext.rb +160 -0
  166. data/lib/chef/resource/selinux_install.rb +107 -0
  167. data/lib/chef/resource/selinux_module.rb +143 -0
  168. data/lib/chef/resource/selinux_permissive.rb +64 -0
  169. data/lib/chef/resource/selinux_port.rb +118 -0
  170. data/lib/chef/resource/selinux_state.rb +166 -0
  171. data/lib/chef/resource/service.rb +0 -1
  172. data/lib/chef/resource/smartos_package.rb +0 -1
  173. data/lib/chef/resource/snap_package.rb +0 -1
  174. data/lib/chef/resource/solaris_package.rb +0 -1
  175. data/lib/chef/resource/ssh_known_hosts_entry.rb +0 -1
  176. data/lib/chef/resource/sudo.rb +0 -1
  177. data/lib/chef/resource/support/client.erb +2 -2
  178. data/lib/chef/resource/swap_file.rb +0 -1
  179. data/lib/chef/resource/sysctl.rb +1 -2
  180. data/lib/chef/resource/systemd_unit.rb +0 -1
  181. data/lib/chef/resource/template.rb +0 -1
  182. data/lib/chef/resource/timezone.rb +0 -1
  183. data/lib/chef/resource/user/aix_user.rb +0 -1
  184. data/lib/chef/resource/user/linux_user.rb +0 -1
  185. data/lib/chef/resource/user/mac_user.rb +0 -1
  186. data/lib/chef/resource/user/pw_user.rb +0 -1
  187. data/lib/chef/resource/user/solaris_user.rb +0 -1
  188. data/lib/chef/resource/user/windows_user.rb +0 -1
  189. data/lib/chef/resource/user.rb +10 -1
  190. data/lib/chef/resource/user_ulimit.rb +0 -1
  191. data/lib/chef/resource/whyrun_safe_ruby_block.rb +0 -1
  192. data/lib/chef/resource/windows_ad_join.rb +0 -2
  193. data/lib/chef/resource/windows_audit_policy.rb +0 -2
  194. data/lib/chef/resource/windows_auto_run.rb +0 -1
  195. data/lib/chef/resource/windows_defender.rb +0 -1
  196. data/lib/chef/resource/windows_defender_exclusion.rb +0 -1
  197. data/lib/chef/resource/windows_dfs_folder.rb +0 -1
  198. data/lib/chef/resource/windows_dfs_namespace.rb +0 -1
  199. data/lib/chef/resource/windows_dfs_server.rb +0 -1
  200. data/lib/chef/resource/windows_dns_record.rb +0 -1
  201. data/lib/chef/resource/windows_dns_zone.rb +0 -1
  202. data/lib/chef/resource/windows_env.rb +0 -1
  203. data/lib/chef/resource/windows_feature.rb +0 -1
  204. data/lib/chef/resource/windows_feature_dism.rb +0 -1
  205. data/lib/chef/resource/windows_feature_powershell.rb +0 -1
  206. data/lib/chef/resource/windows_firewall_profile.rb +0 -2
  207. data/lib/chef/resource/windows_firewall_rule.rb +0 -1
  208. data/lib/chef/resource/windows_font.rb +2 -3
  209. data/lib/chef/resource/windows_package.rb +0 -1
  210. data/lib/chef/resource/windows_pagefile.rb +0 -2
  211. data/lib/chef/resource/windows_path.rb +0 -1
  212. data/lib/chef/resource/windows_printer.rb +0 -1
  213. data/lib/chef/resource/windows_printer_port.rb +0 -1
  214. data/lib/chef/resource/windows_script.rb +0 -2
  215. data/lib/chef/resource/windows_security_policy.rb +0 -1
  216. data/lib/chef/resource/windows_service.rb +0 -1
  217. data/lib/chef/resource/windows_share.rb +0 -1
  218. data/lib/chef/resource/windows_shortcut.rb +1 -2
  219. data/lib/chef/resource/windows_task.rb +0 -1
  220. data/lib/chef/resource/windows_uac.rb +0 -1
  221. data/lib/chef/resource/windows_update_settings.rb +0 -1
  222. data/lib/chef/resource/windows_user_privilege.rb +0 -1
  223. data/lib/chef/resource/windows_workgroup.rb +0 -1
  224. data/lib/chef/resource/yum_package.rb +0 -1
  225. data/lib/chef/resource/yum_repository.rb +0 -1
  226. data/lib/chef/resource/zypper_package.rb +0 -1
  227. data/lib/chef/resource/zypper_repository.rb +0 -1
  228. data/lib/chef/resource.rb +12 -5
  229. data/lib/chef/resources.rb +7 -0
  230. data/lib/chef/run_context.rb +3 -3
  231. data/lib/chef/secret_fetcher/azure_key_vault.rb +3 -3
  232. data/lib/chef/version.rb +1 -1
  233. data/lib/chef/win32/handle.rb +6 -7
  234. data/lib/chef/win32/registry.rb +7 -3
  235. data/spec/data/rubygems.org/sexp_processor-info +2 -1
  236. data/spec/data/trusted_certs/example.crt +20 -29
  237. data/spec/data/trusted_certs/example_no_cn.crt +34 -30
  238. data/spec/data/trusted_certs/opscode.pem +54 -33
  239. data/spec/functional/resource/chocolatey_package_spec.rb +20 -32
  240. data/spec/functional/resource/dsc_script_spec.rb +1 -1
  241. data/spec/functional/resource/group_spec.rb +10 -6
  242. data/spec/functional/resource/link_spec.rb +8 -8
  243. data/spec/functional/resource/macos_userdefaults_spec.rb +4 -4
  244. data/spec/functional/resource/plist_spec.rb +25 -0
  245. data/spec/functional/resource/user/linux_user_spec.rb +127 -0
  246. data/spec/functional/resource/windows_certificate_spec.rb +1 -26
  247. data/spec/functional/resource/windows_font_spec.rb +12 -9
  248. data/spec/functional/resource/yum_package_spec.rb +1 -1
  249. data/spec/functional/resource/zypper_package_spec.rb +12 -10
  250. data/spec/functional/shell_spec.rb +1 -2
  251. data/spec/functional/version_spec.rb +1 -1
  252. data/spec/integration/client/client_spec.rb +82 -3
  253. data/spec/integration/client/exit_code_spec.rb +1 -1
  254. data/spec/integration/client/ipv6_spec.rb +1 -1
  255. data/spec/integration/compliance/compliance_spec.rb +1 -1
  256. data/spec/integration/recipes/accumulator_spec.rb +1 -1
  257. data/spec/integration/recipes/lwrp_inline_resources_spec.rb +1 -1
  258. data/spec/integration/recipes/lwrp_spec.rb +1 -1
  259. data/spec/integration/recipes/notifies_spec.rb +1 -1
  260. data/spec/integration/recipes/notifying_block_spec.rb +1 -1
  261. data/spec/integration/recipes/remote_directory.rb +1 -1
  262. data/spec/integration/recipes/unified_mode_spec.rb +1 -1
  263. data/spec/integration/recipes/use_partial_spec.rb +2 -1
  264. data/spec/integration/solo/solo_spec.rb +2 -2
  265. data/spec/spec_helper.rb +1 -0
  266. data/spec/support/platform_helpers.rb +4 -0
  267. data/spec/support/ruby_installer.rb +1 -1
  268. data/spec/support/shared/functional/windows_script.rb +2 -2
  269. data/spec/unit/application/client_spec.rb +0 -10
  270. data/spec/unit/client_spec.rb +57 -8
  271. data/spec/unit/compliance/reporter/chef_server_automate_spec.rb +1 -1
  272. data/spec/unit/cookbook/syntax_check_spec.rb +3 -0
  273. data/spec/unit/http/authenticator_spec.rb +68 -0
  274. data/spec/unit/mixin/checksum_spec.rb +0 -28
  275. data/spec/unit/mixin/homebrew_user_spec.rb +7 -30
  276. data/spec/unit/mixin/powershell_exec_spec.rb +5 -5
  277. data/spec/unit/platform/query_helpers_spec.rb +2 -17
  278. data/spec/unit/provider/http_request_spec.rb +60 -72
  279. data/spec/unit/provider/mount/linux_spec.rb +10 -0
  280. data/spec/unit/provider/package/chocolatey_spec.rb +3 -19
  281. data/spec/unit/provider/package/rubygems_spec.rb +1 -1
  282. data/spec/unit/provider/package/zypper_spec.rb +32 -0
  283. data/spec/unit/provider/user/linux_spec.rb +51 -11
  284. data/spec/unit/provider/user_spec.rb +24 -6
  285. data/spec/unit/resource/archive_file_spec.rb +1 -1
  286. data/spec/unit/resource/chef_client_cron_spec.rb +5 -0
  287. data/spec/unit/resource/chef_client_launchd_spec.rb +5 -0
  288. data/spec/unit/resource/chef_client_scheduled_task_spec.rb +5 -0
  289. data/spec/unit/resource/chef_client_systemd_timer_spec.rb +2 -2
  290. data/spec/unit/resource/cron_d_spec.rb +37 -1
  291. data/spec/unit/resource/macos_user_defaults_spec.rb +4 -4
  292. data/spec/unit/resource/rest_resource_spec.rb +381 -0
  293. data/spec/unit/resource/selinux_boolean_spec.rb +92 -0
  294. data/spec/unit/resource/selinux_fcontext_spec.rb +65 -0
  295. data/spec/unit/resource/selinux_install_spec.rb +60 -0
  296. data/spec/unit/resource/selinux_module_spec.rb +55 -0
  297. data/spec/unit/resource/selinux_permissive_spec.rb +39 -0
  298. data/spec/unit/resource/selinux_port_spec.rb +42 -0
  299. data/spec/unit/resource/selinux_state_spec.rb +46 -0
  300. data/spec/unit/resource/sysctl_spec.rb +2 -2
  301. data/spec/unit/resource/user/linux_user_spec.rb +42 -0
  302. data/spec/unit/resource_spec.rb +0 -1
  303. data/spec/unit/util/dsc/local_configuration_manager_spec.rb +1 -1
  304. data/tasks/rspec.rb +1 -1
  305. metadata +103 -37
  306. /data/spec/functional/assets/chocolatey_feed/{test-A.1.0.0.nupkg → test-A.1.0.nupkg} +0 -0
  307. /data/spec/functional/assets/chocolatey_feed/{test-A.1.5.0.nupkg → test-A.1.5.nupkg} +0 -0
  308. /data/spec/functional/assets/chocolatey_feed/{test-A.2.0.0.nupkg → test-A.2.0.nupkg} +0 -0
  309. /data/spec/functional/assets/chocolatey_feed/{test-B.1.0.0.nupkg → test-B.1.0.nupkg} +0 -0
  310. /data/spec/functional/assets/yumrepo/repodata/{01a3b-filelists.sqlite.bz2 → 4632d67cb92636e7575d911c24f0e04d3505a944e97c483abe0c3e73a7c62d33-filelists.sqlite.bz2} +0 -0
  311. /data/spec/functional/assets/yumrepo/repodata/{6bf96-other.xml.gz → 74599b793e54d877323837d2d81a1c3c594c44e4335f9528234bb490f7b9b439-other.xml.gz} +0 -0
  312. /data/spec/functional/assets/yumrepo/repodata/{5dc1e-primary.sqlite.bz2 → a845d418f919d2115ab95a56b2c76f6825ad0d0bede49181a55c04f58995d057-primary.sqlite.bz2} +0 -0
  313. /data/spec/functional/assets/yumrepo/repodata/{7c365-other.sqlite.bz2 → af9b7cf9ef23bd7b43068d74a460f3b5d06753d638e58e4a0c9edc35bfb9cdc4-other.sqlite.bz2} +0 -0
  314. /data/spec/functional/assets/yumrepo/repodata/{401dc-filelists.xml.gz → bdb4f5f1492a3b9532f22c43110a81500dd744f23da0aec5c33b2a41317c737d-filelists.xml.gz} +0 -0
  315. /data/spec/functional/assets/yumrepo/repodata/{dabe2-primary.xml.gz → c10d1d34ce99e02f12ec96ef68360543ab1bb7c3cb81a4a2bf78df7d8597e9df-primary.xml.gz} +0 -0
@@ -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)
@@ -177,15 +189,6 @@ describe Chef::Resource::ZypperPackage, :requires_root, :suse_only do
177
189
  expect(zypper_package.updated_by_last_action?).to be true
178
190
  expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^package chef_rpm is not installed$")
179
191
  end
180
-
181
- context "Package doesn't exist" do
182
- let(:package_name) { "nonexistent_repo" }
183
- it "does nothing if the package is not installed" do
184
- zypper_package.run_action(:remove)
185
- expect(zypper_package.updated_by_last_action?).to be false
186
- end
187
-
188
- end
189
192
  end
190
193
 
191
194
  context "with no available version" do
@@ -256,7 +259,6 @@ describe Chef::Resource::ZypperPackage, :requires_root, :suse_only do
256
259
  expect(shell_out("zypper locks | grep chef_rpm_provides").stdout.chomp).not_to match("chef_rpm_provides")
257
260
  end
258
261
  end
259
-
260
262
  def remove_package
261
263
  pkg_to_remove = Chef::Resource::ZypperPackage.new(package_name, run_context)
262
264
  pkg_to_remove.run_action(:remove)
@@ -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
 
@@ -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
@@ -144,6 +144,7 @@ RSpec.configure do |config|
144
144
  config.filter_run_excluding macos_only: true unless macos?
145
145
  config.filter_run_excluding not_macos_gte_11: true if macos_gte_11?
146
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?
147
148
  config.filter_run_excluding not_supported_on_solaris: true if solaris?
148
149
  config.filter_run_excluding not_supported_on_gce: true if gce?
149
150
  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
@@ -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
 
@@ -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(2024, 12, 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 Nov 30, 2024. 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
 
@@ -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