chef 12.18.31 → 13.0.118

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 (611) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +15 -11
  3. data/README.md +13 -13
  4. data/Rakefile +1 -19
  5. data/VERSION +1 -1
  6. data/acceptance/.shared/kitchen_acceptance/libraries/kitchen.rb +1 -1
  7. data/acceptance/Gemfile +8 -5
  8. data/acceptance/Gemfile.lock +90 -81
  9. data/acceptance/basics/test/integration/chef-current-install/serverspec/chef_client_spec.rb +1 -1
  10. data/acceptance/data-collector/.acceptance/data-collector-test/metadata.rb +1 -1
  11. data/acceptance/data-collector/test/integration/default/serverspec/default_spec.rb +4 -0
  12. data/acceptance/top-cookbooks/.acceptance/acceptance-cookbook/libraries/top_cookbooks.rb +9 -8
  13. data/chef-universal-mingw32.gemspec +2 -3
  14. data/chef.gemspec +8 -7
  15. data/lib/chef/api_client.rb +8 -15
  16. data/lib/chef/api_client_v1.rb +9 -11
  17. data/lib/chef/application/apply.rb +8 -10
  18. data/lib/chef/application/client.rb +1 -1
  19. data/lib/chef/application/exit_code.rb +11 -82
  20. data/lib/chef/application/knife.rb +2 -2
  21. data/lib/chef/application/solo.rb +0 -1
  22. data/lib/chef/application/windows_service.rb +36 -37
  23. data/lib/chef/application/windows_service_manager.rb +1 -1
  24. data/lib/chef/application.rb +15 -25
  25. data/lib/chef/audit/audit_event_proxy.rb +2 -2
  26. data/lib/chef/audit/control_group_data.rb +1 -1
  27. data/lib/chef/blacklist.rb +81 -0
  28. data/lib/chef/chef_class.rb +1 -0
  29. data/lib/chef/chef_fs/chef_fs_data_store.rb +6 -8
  30. data/lib/chef/chef_fs/command_line.rb +15 -16
  31. data/lib/chef/chef_fs/data_handler/client_data_handler.rb +1 -1
  32. data/lib/chef/chef_fs/data_handler/container_data_handler.rb +1 -1
  33. data/lib/chef/chef_fs/data_handler/cookbook_data_handler.rb +1 -1
  34. data/lib/chef/chef_fs/data_handler/data_bag_item_data_handler.rb +1 -1
  35. data/lib/chef/chef_fs/data_handler/environment_data_handler.rb +1 -1
  36. data/lib/chef/chef_fs/data_handler/group_data_handler.rb +1 -1
  37. data/lib/chef/chef_fs/data_handler/node_data_handler.rb +1 -1
  38. data/lib/chef/chef_fs/data_handler/organization_data_handler.rb +1 -1
  39. data/lib/chef/chef_fs/data_handler/role_data_handler.rb +1 -1
  40. data/lib/chef/chef_fs/data_handler/user_data_handler.rb +1 -1
  41. data/lib/chef/chef_fs/file_pattern.rb +2 -2
  42. data/lib/chef/chef_fs/file_system/chef_server/chef_server_root_dir.rb +2 -2
  43. data/lib/chef/chef_fs/file_system/chef_server/cookbook_artifacts_dir.rb +6 -2
  44. data/lib/chef/chef_fs/file_system/chef_server/cookbook_dir.rb +18 -32
  45. data/lib/chef/chef_fs/file_system/chef_server/cookbook_file.rb +8 -10
  46. data/lib/chef/chef_fs/file_system/chef_server/cookbooks_dir.rb +5 -1
  47. data/lib/chef/chef_fs/file_system/chef_server/data_bags_dir.rb +8 -10
  48. data/lib/chef/chef_fs/file_system/chef_server/nodes_dir.rb +10 -12
  49. data/lib/chef/chef_fs/file_system/chef_server/policies_dir.rb +28 -30
  50. data/lib/chef/chef_fs/file_system/chef_server/policy_group_entry.rb +1 -1
  51. data/lib/chef/chef_fs/file_system/chef_server/rest_list_dir.rb +27 -29
  52. data/lib/chef/chef_fs/file_system/chef_server/rest_list_entry.rb +29 -26
  53. data/lib/chef/chef_fs/file_system/chef_server/versioned_cookbooks_dir.rb +5 -1
  54. data/lib/chef/chef_fs/file_system/memory/memory_file.rb +1 -1
  55. data/lib/chef/chef_fs/file_system/multiplexed_dir.rb +10 -12
  56. data/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_dir.rb +13 -16
  57. data/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_entry.rb +9 -13
  58. data/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_root_dir.rb +2 -0
  59. data/lib/chef/chef_fs/file_system/repository/cookbooks_dir.rb +1 -1
  60. data/lib/chef/chef_fs/file_system/repository/nodes_dir.rb +3 -0
  61. data/lib/chef/chef_fs/file_system.rb +1 -1
  62. data/lib/chef/chef_fs/parallelizer.rb +9 -11
  63. data/lib/chef/client.rb +47 -11
  64. data/lib/chef/config_fetcher.rb +4 -4
  65. data/lib/chef/constants.rb +1 -1
  66. data/lib/chef/cookbook/cookbook_version_loader.rb +26 -115
  67. data/lib/chef/cookbook/file_system_file_vendor.rb +1 -1
  68. data/lib/chef/cookbook/gem_installer.rb +10 -6
  69. data/lib/chef/cookbook/manifest_v0.rb +68 -0
  70. data/lib/chef/cookbook/manifest_v2.rb +41 -0
  71. data/lib/chef/cookbook/metadata.rb +25 -134
  72. data/lib/chef/cookbook/remote_file_vendor.rb +3 -3
  73. data/lib/chef/cookbook/synchronizer.rb +24 -21
  74. data/lib/chef/cookbook/syntax_check.rb +1 -1
  75. data/lib/chef/cookbook_manifest.rb +91 -65
  76. data/lib/chef/cookbook_site_streaming_uploader.rb +7 -9
  77. data/lib/chef/cookbook_uploader.rb +1 -1
  78. data/lib/chef/cookbook_version.rb +69 -157
  79. data/lib/chef/data_bag.rb +1 -7
  80. data/lib/chef/data_bag_item.rb +5 -10
  81. data/lib/chef/data_collector/messages.rb +2 -0
  82. data/lib/chef/data_collector/resource_report.rb +32 -4
  83. data/lib/chef/data_collector.rb +3 -4
  84. data/lib/chef/decorator/unchain.rb +0 -16
  85. data/lib/chef/decorator.rb +1 -1
  86. data/lib/chef/deprecated.rb +53 -19
  87. data/lib/chef/dsl/audit.rb +2 -2
  88. data/lib/chef/dsl/declare_resource.rb +11 -17
  89. data/lib/chef/dsl/platform_introspection.rb +29 -31
  90. data/lib/chef/dsl/reboot_pending.rb +1 -1
  91. data/lib/chef/dsl/recipe.rb +1 -4
  92. data/lib/chef/dsl/resources.rb +4 -13
  93. data/lib/chef/encrypted_data_bag_item.rb +2 -2
  94. data/lib/chef/environment.rb +9 -16
  95. data/lib/chef/event_dispatch/base.rb +16 -0
  96. data/lib/chef/event_loggers/windows_eventlog.rb +1 -1
  97. data/lib/chef/exceptions.rb +6 -10
  98. data/lib/chef/file_access_control/unix.rb +14 -14
  99. data/lib/chef/file_access_control/windows.rb +1 -1
  100. data/lib/chef/formatters/error_description.rb +18 -1
  101. data/lib/chef/formatters/error_inspectors/api_error_formatting.rb +4 -5
  102. data/lib/chef/formatters/error_mapper.rb +6 -6
  103. data/lib/chef/guard_interpreter/default_guard_interpreter.rb +4 -2
  104. data/lib/chef/http/api_versions.rb +54 -0
  105. data/lib/chef/http/authenticator.rb +15 -6
  106. data/lib/chef/http/json_output.rb +4 -1
  107. data/lib/chef/http/socketless_chef_zero_client.rb +1 -0
  108. data/lib/chef/http/validate_content_length.rb +2 -2
  109. data/lib/chef/http.rb +39 -0
  110. data/lib/chef/json_compat.rb +7 -103
  111. data/lib/chef/key.rb +5 -10
  112. data/lib/chef/knife/bootstrap/templates/chef-full.erb +6 -6
  113. data/lib/chef/knife/bootstrap.rb +6 -0
  114. data/lib/chef/knife/configure.rb +1 -3
  115. data/lib/chef/knife/configure_client.rb +1 -3
  116. data/lib/chef/knife/cookbook_create.rb +1 -434
  117. data/lib/chef/knife/cookbook_download.rb +3 -4
  118. data/lib/chef/knife/cookbook_show.rb +7 -3
  119. data/lib/chef/knife/cookbook_site_install.rb +2 -2
  120. data/lib/chef/knife/core/bootstrap_context.rb +8 -7
  121. data/lib/chef/knife/core/cookbook_scm_repo.rb +2 -2
  122. data/lib/chef/knife/core/gem_glob_loader.rb +1 -1
  123. data/lib/chef/knife/core/status_presenter.rb +1 -1
  124. data/lib/chef/knife/core/subcommand_loader.rb +2 -32
  125. data/lib/chef/knife/core/ui.rb +20 -27
  126. data/lib/chef/knife/data_bag_create.rb +6 -4
  127. data/lib/chef/knife/data_bag_secret_options.rb +1 -1
  128. data/lib/chef/knife/deps.rb +32 -34
  129. data/lib/chef/knife/edit.rb +1 -1
  130. data/lib/chef/knife/help.rb +1 -1
  131. data/lib/chef/knife/list.rb +1 -1
  132. data/lib/chef/knife/search.rb +9 -20
  133. data/lib/chef/knife/ssh.rb +62 -36
  134. data/lib/chef/knife/ssl_check.rb +1 -1
  135. data/lib/chef/knife/user_delete.rb +1 -1
  136. data/lib/chef/knife/xargs.rb +1 -1
  137. data/lib/chef/knife.rb +6 -7
  138. data/lib/chef/mash.rb +1 -1
  139. data/lib/chef/mixin/create_path.rb +3 -5
  140. data/lib/chef/mixin/from_file.rb +2 -2
  141. data/lib/chef/mixin/get_source_from_package.rb +2 -2
  142. data/lib/chef/mixin/notifying_block.rb +7 -9
  143. data/lib/chef/mixin/params_validate.rb +9 -8
  144. data/lib/chef/mixin/path_sanity.rb +17 -19
  145. data/lib/chef/mixin/securable.rb +1 -1
  146. data/lib/chef/mixin/shell_out.rb +33 -29
  147. data/lib/chef/mixin/unformatter.rb +2 -2
  148. data/lib/chef/mixin/uris.rb +4 -6
  149. data/lib/chef/mixin/versioned_api.rb +84 -0
  150. data/lib/chef/mixin/which.rb +25 -8
  151. data/lib/chef/mixin/windows_architecture_helper.rb +2 -2
  152. data/lib/chef/mixin/xml_escape.rb +3 -5
  153. data/lib/chef/mixins.rb +0 -1
  154. data/lib/chef/monkey_patches/webrick-utils.rb +1 -1
  155. data/lib/chef/node/attribute.rb +9 -32
  156. data/lib/chef/node/attribute_collections.rb +1 -19
  157. data/lib/chef/node/common_api.rb +5 -7
  158. data/lib/chef/node/immutable_collections.rb +42 -38
  159. data/lib/chef/node/mixin/immutablize_array.rb +1 -1
  160. data/lib/chef/node/mixin/immutablize_hash.rb +1 -1
  161. data/lib/chef/node.rb +21 -20
  162. data/lib/chef/node_map.rb +2 -5
  163. data/lib/chef/org.rb +10 -17
  164. data/lib/chef/platform/provider_mapping.rb +2 -169
  165. data/lib/chef/platform/query_helpers.rb +1 -1
  166. data/lib/chef/platform/rebooter.rb +1 -2
  167. data/lib/chef/policy_builder/expand_node_object.rb +3 -29
  168. data/lib/chef/policy_builder/policyfile.rb +8 -6
  169. data/lib/chef/property.rb +66 -80
  170. data/lib/chef/provider/apt_repository.rb +6 -10
  171. data/lib/chef/provider/apt_update.rb +1 -7
  172. data/lib/chef/provider/batch.rb +1 -1
  173. data/lib/chef/provider/breakpoint.rb +2 -2
  174. data/lib/chef/provider/cookbook_file.rb +3 -9
  175. data/lib/chef/provider/cron.rb +42 -60
  176. data/lib/chef/provider/deploy/revision.rb +3 -5
  177. data/lib/chef/provider/deploy.rb +82 -88
  178. data/lib/chef/provider/directory.rb +33 -37
  179. data/lib/chef/provider/dsc_resource.rb +23 -11
  180. data/lib/chef/provider/dsc_script.rb +1 -5
  181. data/lib/chef/provider/env/windows.rb +5 -1
  182. data/lib/chef/provider/env.rb +32 -30
  183. data/lib/chef/provider/erl_call.rb +15 -47
  184. data/lib/chef/provider/execute.rb +7 -8
  185. data/lib/chef/provider/file.rb +49 -61
  186. data/lib/chef/provider/git.rb +56 -60
  187. data/lib/chef/provider/group.rb +1 -7
  188. data/lib/chef/provider/http_request.rb +37 -41
  189. data/lib/chef/provider/ifconfig/redhat.rb +1 -1
  190. data/lib/chef/provider/ifconfig.rb +0 -6
  191. data/lib/chef/provider/launchd.rb +6 -2
  192. data/lib/chef/provider/link.rb +51 -55
  193. data/lib/chef/provider/log.rb +3 -7
  194. data/lib/chef/provider/lwrp_base.rb +0 -9
  195. data/lib/chef/provider/mdadm.rb +25 -33
  196. data/lib/chef/provider/mount/aix.rb +2 -2
  197. data/lib/chef/provider/mount/mount.rb +2 -2
  198. data/lib/chef/provider/mount.rb +1 -5
  199. data/lib/chef/provider/noop.rb +1 -1
  200. data/lib/chef/provider/ohai.rb +1 -7
  201. data/lib/chef/provider/osx_profile.rb +24 -29
  202. data/lib/chef/provider/package/aix.rb +55 -53
  203. data/lib/chef/provider/package/apt.rb +15 -13
  204. data/lib/chef/provider/package/cab.rb +48 -20
  205. data/lib/chef/provider/package/chocolatey.rb +9 -10
  206. data/lib/chef/provider/package/dnf/dnf_helper.py +1 -1
  207. data/lib/chef/provider/package/dnf/python_helper.rb +63 -26
  208. data/lib/chef/provider/package/dnf/version.rb +1 -1
  209. data/lib/chef/provider/package/dnf.rb +21 -19
  210. data/lib/chef/provider/package/dpkg.rb +8 -9
  211. data/lib/chef/provider/package/freebsd/base.rb +10 -10
  212. data/lib/chef/provider/package/freebsd/pkg.rb +15 -15
  213. data/lib/chef/provider/package/freebsd/pkgng.rb +13 -15
  214. data/lib/chef/provider/package/freebsd/port.rb +7 -7
  215. data/lib/chef/provider/package/homebrew.rb +11 -10
  216. data/lib/chef/provider/package/ips.rb +18 -24
  217. data/lib/chef/provider/package/macports.rb +23 -23
  218. data/lib/chef/provider/package/msu.rb +11 -12
  219. data/lib/chef/provider/package/openbsd.rb +25 -22
  220. data/lib/chef/provider/package/pacman.rb +16 -17
  221. data/lib/chef/provider/package/paludis.rb +26 -27
  222. data/lib/chef/provider/package/portage.rb +22 -23
  223. data/lib/chef/provider/package/powershell.rb +17 -17
  224. data/lib/chef/provider/package/rpm.rb +25 -26
  225. data/lib/chef/provider/package/rubygems.rb +64 -62
  226. data/lib/chef/provider/package/smartos.rb +16 -16
  227. data/lib/chef/provider/package/solaris.rb +44 -45
  228. data/lib/chef/provider/package/windows/exe.rb +6 -6
  229. data/lib/chef/provider/package/windows/msi.rb +7 -7
  230. data/lib/chef/provider/package/windows/registry_uninstall_entry.rb +9 -3
  231. data/lib/chef/provider/package/windows.rb +3 -3
  232. data/lib/chef/provider/package/yum/rpm_utils.rb +34 -34
  233. data/lib/chef/provider/package/yum/yum_cache.rb +12 -12
  234. data/lib/chef/provider/package/yum.rb +319 -269
  235. data/lib/chef/provider/package/zypper.rb +10 -20
  236. data/lib/chef/provider/package.rb +71 -63
  237. data/lib/chef/provider/powershell_script.rb +15 -7
  238. data/lib/chef/provider/reboot.rb +10 -14
  239. data/lib/chef/provider/registry_key.rb +39 -43
  240. data/lib/chef/provider/remote_directory.rb +3 -15
  241. data/lib/chef/provider/remote_file.rb +3 -9
  242. data/lib/chef/provider/route.rb +1 -7
  243. data/lib/chef/provider/ruby_block.rb +4 -8
  244. data/lib/chef/provider/script.rb +42 -6
  245. data/lib/chef/provider/service/aix.rb +1 -5
  246. data/lib/chef/provider/service/debian.rb +15 -21
  247. data/lib/chef/provider/service/freebsd.rb +0 -1
  248. data/lib/chef/provider/service/gentoo.rb +0 -1
  249. data/lib/chef/provider/service/init.rb +0 -1
  250. data/lib/chef/provider/service/insserv.rb +2 -2
  251. data/lib/chef/provider/service/openbsd.rb +0 -1
  252. data/lib/chef/provider/service/redhat.rb +2 -2
  253. data/lib/chef/provider/service/simple.rb +0 -5
  254. data/lib/chef/provider/service/solaris.rb +5 -4
  255. data/lib/chef/provider/service/systemd.rb +1 -1
  256. data/lib/chef/provider/service/upstart.rb +10 -12
  257. data/lib/chef/provider/service/windows.rb +1 -5
  258. data/lib/chef/provider/service.rb +51 -58
  259. data/lib/chef/provider/subversion.rb +40 -46
  260. data/lib/chef/provider/systemd_unit.rb +2 -0
  261. data/lib/chef/provider/template/content.rb +24 -1
  262. data/lib/chef/provider/template.rb +3 -9
  263. data/lib/chef/provider/user/dscl.rb +3 -3
  264. data/lib/chef/provider/user/linux.rb +6 -5
  265. data/lib/chef/provider/user/pw.rb +4 -10
  266. data/lib/chef/provider/user/solaris.rb +2 -2
  267. data/lib/chef/provider/user/useradd.rb +5 -5
  268. data/lib/chef/provider/user.rb +43 -59
  269. data/lib/chef/provider/whyrun_safe_ruby_block.rb +4 -4
  270. data/lib/chef/provider/windows_task.rb +418 -0
  271. data/lib/chef/provider/yum_repository.rb +3 -6
  272. data/lib/chef/provider.rb +63 -115
  273. data/lib/chef/provider_resolver.rb +8 -34
  274. data/lib/chef/providers.rb +1 -1
  275. data/lib/chef/recipe.rb +9 -1
  276. data/lib/chef/resource/action_class.rb +13 -17
  277. data/lib/chef/resource/apt_repository.rb +0 -1
  278. data/lib/chef/resource/apt_update.rb +3 -1
  279. data/lib/chef/resource/chef_gem.rb +4 -11
  280. data/lib/chef/resource/chocolatey_package.rb +4 -1
  281. data/lib/chef/resource/dnf_package.rb +6 -3
  282. data/lib/chef/resource/dsc_resource.rb +9 -1
  283. data/lib/chef/resource/execute.rb +66 -19
  284. data/lib/chef/resource/file/verification/systemd_unit.rb +67 -0
  285. data/lib/chef/resource/file/verification.rb +2 -7
  286. data/lib/chef/resource/freebsd_package.rb +1 -1
  287. data/lib/chef/resource/gem_package.rb +16 -2
  288. data/lib/chef/resource/launchd.rb +3 -3
  289. data/lib/chef/resource/lwrp_base.rb +0 -2
  290. data/lib/chef/resource/mount.rb +5 -12
  291. data/lib/chef/resource/package.rb +2 -2
  292. data/lib/chef/resource/powershell_script.rb +1 -1
  293. data/lib/chef/resource/registry_key.rb +1 -1
  294. data/lib/chef/resource/script.rb +8 -34
  295. data/lib/chef/resource/service.rb +15 -13
  296. data/lib/chef/resource/systemd_unit.rb +5 -0
  297. data/lib/chef/resource/user/aix_user.rb +1 -1
  298. data/lib/chef/resource/user/dscl_user.rb +1 -1
  299. data/lib/chef/resource/user/linux_user.rb +1 -10
  300. data/lib/chef/resource/user/pw_user.rb +1 -1
  301. data/lib/chef/resource/user/solaris_user.rb +1 -1
  302. data/lib/chef/resource/user/windows_user.rb +1 -1
  303. data/lib/chef/resource/user.rb +1 -19
  304. data/lib/chef/resource/windows_package.rb +4 -1
  305. data/lib/chef/resource/windows_task.rb +237 -0
  306. data/lib/chef/resource/yum_package.rb +13 -4
  307. data/lib/chef/resource/yum_repository.rb +0 -1
  308. data/lib/chef/resource/zypper_package.rb +2 -0
  309. data/lib/chef/resource.rb +90 -202
  310. data/lib/chef/resource_builder.rb +1 -65
  311. data/lib/chef/resource_collection/resource_collection_serialization.rb +11 -4
  312. data/lib/chef/resource_collection/resource_list.rb +6 -0
  313. data/lib/chef/resource_collection/resource_set.rb +44 -17
  314. data/lib/chef/resource_collection.rb +10 -0
  315. data/lib/chef/resource_reporter.rb +1 -1
  316. data/lib/chef/resource_resolver.rb +1 -25
  317. data/lib/chef/resources.rb +1 -1
  318. data/lib/chef/role.rb +0 -6
  319. data/lib/chef/run_context/cookbook_compiler.rb +49 -5
  320. data/lib/chef/run_context.rb +4 -25
  321. data/lib/chef/run_list/run_list_item.rb +1 -1
  322. data/lib/chef/run_list/versioned_recipe_list.rb +14 -12
  323. data/lib/chef/search/query.rb +26 -31
  324. data/lib/chef/server_api.rb +2 -0
  325. data/lib/chef/{resource/easy_install_package.rb → server_api_versions.rb} +18 -10
  326. data/lib/chef/shell/ext.rb +3 -3
  327. data/lib/chef/shell/shell_session.rb +14 -4
  328. data/lib/chef/shell.rb +32 -7
  329. data/lib/chef/user.rb +9 -16
  330. data/lib/chef/user_v1.rb +9 -16
  331. data/lib/chef/util/diff.rb +1 -1
  332. data/lib/chef/util/dsc/lcm_output_parser.rb +1 -1
  333. data/lib/chef/util/selinux.rb +1 -1
  334. data/lib/chef/util/windows/net_group.rb +18 -30
  335. data/lib/chef/util/windows/net_use.rb +7 -11
  336. data/lib/chef/util/windows/net_user.rb +12 -18
  337. data/lib/chef/util/windows/volume.rb +9 -15
  338. data/lib/chef/version.rb +1 -1
  339. data/lib/chef/version_class.rb +1 -1
  340. data/lib/chef/win32/api/file.rb +25 -31
  341. data/lib/chef/win32/api/installer.rb +2 -2
  342. data/lib/chef/win32/api.rb +4 -6
  343. data/lib/chef/win32/file.rb +4 -6
  344. data/lib/chef/win32/registry.rb +9 -9
  345. data/lib/chef/win32/security/acl.rb +2 -2
  346. data/lib/chef/win32/security/sid.rb +5 -0
  347. data/lib/chef/win32/security.rb +2 -2
  348. data/lib/chef/win32/unicode.rb +2 -2
  349. data/lib/chef/win32/version.rb +1 -1
  350. data/lib/chef.rb +1 -2
  351. data/spec/data/cookbooks/openldap/templates/default/openldap_nested_variable_stuff.erb +1 -0
  352. data/spec/data/lwrp/providers/buck_passer.rb +1 -1
  353. data/spec/data/lwrp/providers/buck_passer_2.rb +1 -1
  354. data/spec/data/lwrp/providers/embedded_resource_accesses_providers_scope.rb +1 -1
  355. data/spec/data/lwrp/providers/inline_compiler.rb +0 -2
  356. data/spec/data/lwrp/resources/buck_passer.rb +5 -0
  357. data/spec/data/lwrp/resources/buck_passer_2.rb +3 -0
  358. data/spec/data/lwrp/resources/embedded_resource_accesses_providers_scope.rb +3 -0
  359. data/spec/data/lwrp/resources/inline_compiler.rb +3 -0
  360. data/spec/data/lwrp/resources/monkey_name_printer.rb +5 -0
  361. data/spec/data/lwrp/resources/paint_drying_watcher.rb +3 -0
  362. data/spec/data/lwrp/resources/thumb_twiddler.rb +3 -0
  363. data/spec/data/prefer_metadata_json/metadata.json +51 -0
  364. data/spec/data/prefer_metadata_json/metadata.rb +6 -0
  365. data/spec/data/prefer_metadata_json/recipes/default.rb +0 -0
  366. data/spec/data/root_alias_cookbooks/dup_attr/attributes/default.rb +1 -0
  367. data/spec/data/root_alias_cookbooks/dup_attr/attributes.rb +1 -0
  368. data/spec/data/root_alias_cookbooks/dup_attr/metadata.rb +2 -0
  369. data/spec/data/root_alias_cookbooks/dup_attr/recipe.rb +3 -0
  370. data/spec/data/root_alias_cookbooks/dup_recipe/attributes.rb +1 -0
  371. data/spec/data/root_alias_cookbooks/dup_recipe/metadata.rb +2 -0
  372. data/spec/data/root_alias_cookbooks/dup_recipe/recipe.rb +3 -0
  373. data/spec/data/root_alias_cookbooks/dup_recipe/recipes/default.rb +3 -0
  374. data/spec/data/root_alias_cookbooks/simple/attributes.rb +1 -0
  375. data/spec/data/root_alias_cookbooks/simple/metadata.rb +2 -0
  376. data/spec/data/root_alias_cookbooks/simple/recipe.rb +3 -0
  377. data/spec/data/shef-config.rb +11 -10
  378. data/spec/functional/knife/ssh_spec.rb +34 -6
  379. data/spec/functional/rebooter_spec.rb +1 -0
  380. data/spec/functional/resource/bash_spec.rb +11 -45
  381. data/spec/functional/resource/batch_spec.rb +5 -1
  382. data/spec/functional/resource/cron_spec.rb +2 -2
  383. data/spec/functional/resource/dsc_script_spec.rb +2 -4
  384. data/spec/functional/resource/execute_spec.rb +17 -0
  385. data/spec/functional/resource/link_spec.rb +3 -3
  386. data/spec/functional/resource/template_spec.rb +33 -0
  387. data/spec/functional/resource/user/dscl_spec.rb +2 -4
  388. data/spec/functional/root_alias_spec.rb +78 -0
  389. data/spec/functional/shell_spec.rb +38 -40
  390. data/spec/integration/client/client_spec.rb +109 -16
  391. data/spec/integration/client/exit_code_spec.rb +1 -105
  392. data/spec/integration/knife/chef_repository_file_system_spec.rb +0 -97
  393. data/spec/integration/knife/cookbook_download_spec.rb +0 -24
  394. data/spec/integration/knife/cookbook_show_spec.rb +12 -23
  395. data/spec/integration/knife/deps_spec.rb +5 -9
  396. data/spec/integration/knife/search_node_spec.rb +39 -0
  397. data/spec/integration/knife/serve_spec.rb +58 -22
  398. data/spec/integration/knife/upload_spec.rb +3 -11
  399. data/spec/integration/recipes/lwrp_inline_resources_spec.rb +7 -11
  400. data/spec/integration/recipes/notifies_spec.rb +60 -0
  401. data/spec/integration/recipes/recipe_dsl_spec.rb +76 -226
  402. data/spec/integration/recipes/resource_action_spec.rb +37 -30
  403. data/spec/spec_helper.rb +7 -0
  404. data/spec/support/chef_helpers.rb +5 -7
  405. data/spec/support/platform_helpers.rb +10 -3
  406. data/spec/support/platforms/prof/gc.rb +4 -6
  407. data/spec/support/shared/context/client.rb +9 -2
  408. data/spec/support/shared/functional/execute_resource.rb +150 -0
  409. data/spec/support/shared/functional/windows_script.rb +74 -4
  410. data/spec/support/shared/integration/knife_support.rb +1 -1
  411. data/spec/support/shared/unit/execute_resource.rb +37 -9
  412. data/spec/support/shared/unit/provider/file.rb +10 -0
  413. data/spec/support/shared/unit/script_resource.rb +1 -9
  414. data/spec/unit/application/exit_code_spec.rb +4 -89
  415. data/spec/unit/application_spec.rb +39 -29
  416. data/spec/unit/chef_fs/file_system/operation_failed_error_spec.rb +1 -1
  417. data/spec/unit/client_spec.rb +72 -31
  418. data/spec/unit/config_fetcher_spec.rb +2 -2
  419. data/spec/unit/cookbook/cookbook_version_loader_spec.rb +31 -19
  420. data/spec/unit/cookbook/file_vendor_spec.rb +20 -9
  421. data/spec/unit/cookbook/gem_installer_spec.rb +85 -0
  422. data/spec/unit/cookbook/manifest_v0_spec.rb +133 -0
  423. data/spec/unit/cookbook/manifest_v2_spec.rb +70 -0
  424. data/spec/unit/cookbook/metadata_spec.rb +29 -108
  425. data/spec/unit/cookbook/synchronizer_spec.rb +5 -6
  426. data/spec/unit/cookbook/syntax_check_spec.rb +9 -2
  427. data/spec/unit/cookbook_loader_spec.rb +17 -19
  428. data/spec/unit/cookbook_manifest_spec.rb +12 -44
  429. data/spec/unit/cookbook_site_streaming_uploader_spec.rb +0 -4
  430. data/spec/unit/cookbook_spec.rb +10 -14
  431. data/spec/unit/cookbook_uploader_spec.rb +1 -1
  432. data/spec/unit/cookbook_version_file_specificity_spec.rb +55 -28
  433. data/spec/unit/cookbook_version_spec.rb +19 -128
  434. data/spec/unit/data_bag_item_spec.rb +4 -0
  435. data/spec/unit/data_collector/messages_spec.rb +137 -0
  436. data/spec/unit/data_collector/resource_report_spec.rb +145 -0
  437. data/spec/unit/deprecation_spec.rb +0 -14
  438. data/spec/unit/encrypted_data_bag_item_spec.rb +6 -6
  439. data/spec/unit/formatters/error_description_spec.rb +52 -7
  440. data/spec/unit/http/api_versions_spec.rb +79 -0
  441. data/spec/unit/http/authenticator_spec.rb +20 -0
  442. data/spec/unit/http/socketless_chef_zero_client_spec.rb +2 -1
  443. data/spec/unit/json_compat_spec.rb +0 -32
  444. data/spec/unit/knife/bootstrap_spec.rb +34 -0
  445. data/spec/unit/knife/configure_client_spec.rb +0 -2
  446. data/spec/unit/knife/cookbook_create_spec.rb +1 -220
  447. data/spec/unit/knife/cookbook_download_spec.rb +46 -28
  448. data/spec/unit/knife/cookbook_show_spec.rb +42 -9
  449. data/spec/unit/knife/core/bootstrap_context_spec.rb +17 -0
  450. data/spec/unit/knife/core/cookbook_scm_repo_spec.rb +1 -1
  451. data/spec/unit/knife/core/subcommand_loader_spec.rb +0 -6
  452. data/spec/unit/knife/core/ui_spec.rb +21 -11
  453. data/spec/unit/knife/data_bag_create_spec.rb +65 -45
  454. data/spec/unit/knife/ssh_spec.rb +34 -36
  455. data/spec/unit/knife_spec.rb +2 -2
  456. data/spec/unit/lwrp_spec.rb +38 -127
  457. data/spec/unit/mixin/path_sanity_spec.rb +7 -7
  458. data/spec/unit/mixin/shell_out_spec.rb +18 -84
  459. data/spec/unit/mixin/versioned_api_spec.rb +128 -0
  460. data/spec/unit/mixin/which.rb +160 -0
  461. data/spec/unit/node/attribute_spec.rb +65 -33
  462. data/spec/unit/node/immutable_collections_spec.rb +104 -1
  463. data/spec/unit/node_map_spec.rb +1 -23
  464. data/spec/unit/node_spec.rb +81 -98
  465. data/spec/unit/policy_builder/expand_node_object_spec.rb +2 -27
  466. data/spec/unit/policy_builder/policyfile_spec.rb +12 -12
  467. data/spec/unit/property/validation_spec.rb +51 -69
  468. data/spec/unit/property_spec.rb +105 -125
  469. data/spec/unit/provider/apt_repository_spec.rb +33 -27
  470. data/spec/unit/provider/cron_spec.rb +15 -39
  471. data/spec/unit/provider/deploy_spec.rb +1 -1
  472. data/spec/unit/provider/directory_spec.rb +10 -0
  473. data/spec/unit/provider/dsc_resource_spec.rb +175 -0
  474. data/spec/unit/provider/erl_call_spec.rb +5 -13
  475. data/spec/unit/provider/execute_spec.rb +3 -14
  476. data/spec/unit/provider/launchd_spec.rb +2 -2
  477. data/spec/unit/provider/package/aix_spec.rb +22 -22
  478. data/spec/unit/provider/package/apt_spec.rb +37 -27
  479. data/spec/unit/provider/package/cab_spec.rb +59 -5
  480. data/{lib-backcompat/chef/chef_fs/file_system/repository/file_system_root_dir.rb → spec/unit/provider/package/dnf/python_helper_spec.rb} +10 -15
  481. data/spec/unit/provider/package/dpkg_spec.rb +16 -16
  482. data/spec/unit/provider/package/freebsd/pkg_spec.rb +15 -15
  483. data/spec/unit/provider/package/freebsd/pkgng_spec.rb +9 -9
  484. data/spec/unit/provider/package/freebsd/port_spec.rb +9 -9
  485. data/spec/unit/provider/package/homebrew_spec.rb +9 -9
  486. data/spec/unit/provider/package/ips_spec.rb +37 -31
  487. data/spec/unit/provider/package/macports_spec.rb +10 -10
  488. data/spec/unit/provider/package/openbsd_spec.rb +10 -10
  489. data/spec/unit/provider/package/pacman_spec.rb +6 -6
  490. data/spec/unit/provider/package/paludis_spec.rb +7 -7
  491. data/spec/unit/provider/package/portage_spec.rb +6 -7
  492. data/spec/unit/provider/package/rpm_spec.rb +23 -23
  493. data/spec/unit/provider/package/rubygems_spec.rb +135 -46
  494. data/spec/unit/provider/package/solaris_spec.rb +15 -15
  495. data/spec/unit/provider/package/windows/msi_spec.rb +1 -1
  496. data/spec/unit/provider/package/windows/registry_uninstall_entry_spec.rb +25 -0
  497. data/spec/unit/provider/package/windows_spec.rb +2 -1
  498. data/spec/unit/provider/package/yum_spec.rb +58 -50
  499. data/spec/unit/provider/package/zypper_spec.rb +54 -97
  500. data/spec/unit/provider/package_spec.rb +8 -0
  501. data/spec/unit/provider/powershell_script_spec.rb +14 -4
  502. data/spec/unit/provider/remote_file/sftp_spec.rb +3 -3
  503. data/spec/unit/provider/route_spec.rb +7 -1
  504. data/spec/unit/provider/script_spec.rb +49 -6
  505. data/spec/unit/provider/service/debian_service_spec.rb +14 -20
  506. data/spec/unit/provider/service/solaris_smf_service_spec.rb +37 -1
  507. data/spec/unit/provider/service/upstart_service_spec.rb +12 -25
  508. data/spec/unit/provider/subversion_spec.rb +2 -2
  509. data/spec/unit/provider/user/linux_spec.rb +5 -43
  510. data/spec/unit/provider/user/pw_spec.rb +7 -27
  511. data/spec/unit/provider/windows_task_spec.rb +392 -0
  512. data/spec/unit/provider_resolver_spec.rb +0 -1
  513. data/spec/unit/provider_spec.rb +10 -3
  514. data/spec/unit/recipe_spec.rb +3 -172
  515. data/spec/unit/resource/chef_gem_spec.rb +16 -62
  516. data/spec/unit/resource/conditional_spec.rb +4 -4
  517. data/spec/unit/resource/cookbook_file_spec.rb +2 -2
  518. data/spec/unit/resource/cron_spec.rb +1 -1
  519. data/spec/unit/resource/deploy_spec.rb +4 -4
  520. data/spec/unit/resource/directory_spec.rb +2 -2
  521. data/spec/unit/resource/dsc_resource_spec.rb +6 -0
  522. data/spec/unit/resource/env_spec.rb +1 -1
  523. data/spec/unit/resource/execute_spec.rb +215 -1
  524. data/spec/unit/resource/file/verification/systemd_unit_spec.rb +103 -0
  525. data/spec/unit/resource/file/verification_spec.rb +8 -14
  526. data/spec/unit/resource/file_spec.rb +3 -3
  527. data/spec/unit/resource/freebsd_package_spec.rb +2 -2
  528. data/spec/unit/resource/group_spec.rb +2 -2
  529. data/spec/unit/resource/ifconfig_spec.rb +1 -1
  530. data/spec/unit/resource/link_spec.rb +2 -2
  531. data/spec/unit/resource/mdadm_spec.rb +1 -1
  532. data/spec/unit/resource/mount_spec.rb +3 -3
  533. data/spec/unit/resource/ohai_spec.rb +1 -1
  534. data/spec/unit/resource/package_spec.rb +14 -4
  535. data/spec/unit/resource/registry_key_spec.rb +2 -2
  536. data/spec/unit/resource/remote_directory_spec.rb +2 -2
  537. data/spec/unit/resource/remote_file_spec.rb +2 -2
  538. data/spec/unit/resource/route_spec.rb +1 -1
  539. data/spec/unit/resource/scm_spec.rb +2 -2
  540. data/spec/unit/resource/script_spec.rb +1 -1
  541. data/spec/unit/resource/service_spec.rb +25 -5
  542. data/spec/unit/resource/systemd_unit_spec.rb +1 -1
  543. data/spec/unit/resource/template_spec.rb +2 -2
  544. data/spec/unit/resource/user_spec.rb +6 -6
  545. data/spec/unit/resource/windows_task_spec.rb +213 -0
  546. data/spec/unit/resource/yum_package_spec.rb +42 -1
  547. data/spec/unit/resource_collection/resource_set_spec.rb +46 -1
  548. data/spec/unit/resource_collection_spec.rb +4 -3
  549. data/spec/unit/resource_reporter_spec.rb +6 -6
  550. data/spec/unit/resource_spec.rb +55 -71
  551. data/spec/unit/run_context/cookbook_compiler_spec.rb +1 -3
  552. data/spec/unit/run_list/versioned_recipe_list_spec.rb +7 -4
  553. data/spec/unit/runner_spec.rb +10 -28
  554. data/spec/unit/search/query_spec.rb +32 -34
  555. data/spec/unit/server_api_versions_spec.rb +44 -0
  556. data/spec/unit/shell/shell_session_spec.rb +33 -2
  557. data/spec/unit/util/selinux_spec.rb +3 -14
  558. data/spec/unit/win32/error_spec.rb +67 -0
  559. data/spec/unit/win32/security_spec.rb +66 -0
  560. data/tasks/bundle.rb +36 -52
  561. data/tasks/changelog.rb +1 -1
  562. data/tasks/dependencies.rb +54 -52
  563. data/tasks/version.rb +41 -0
  564. metadata +91 -76
  565. data/lib/chef/deprecation/mixin/template.rb +0 -48
  566. data/lib/chef/deprecation/provider/cookbook_file.rb +0 -54
  567. data/lib/chef/deprecation/provider/file.rb +0 -198
  568. data/lib/chef/deprecation/provider/remote_directory.rb +0 -52
  569. data/lib/chef/deprecation/provider/remote_file.rb +0 -85
  570. data/lib/chef/deprecation/provider/template.rb +0 -63
  571. data/lib/chef/dsl/method_missing.rb +0 -75
  572. data/lib/chef/knife/cookbook_site_vendor.rb +0 -46
  573. data/lib/chef/knife/core/custom_manifest_loader.rb +0 -69
  574. data/lib/chef/mixin/command/unix.rb +0 -220
  575. data/lib/chef/mixin/command/windows.rb +0 -71
  576. data/lib/chef/mixin/command.rb +0 -194
  577. data/lib/chef/monkey_patches/net-ssh-multi.rb +0 -141
  578. data/lib/chef/provider/package/easy_install.rb +0 -135
  579. data/lib/chef/rest.rb +0 -210
  580. data/lib/chef/shell_out.rb +0 -13
  581. data/lib/chef/tasks/chef_repo.rake +0 -200
  582. data/lib-backcompat/chef/chef_fs/file_system/acl_entry.rb +0 -5
  583. data/lib-backcompat/chef/chef_fs/file_system/already_exists_error.rb +0 -20
  584. data/lib-backcompat/chef/chef_fs/file_system/chef_repository_file_system_root_dir.rb +0 -5
  585. data/lib-backcompat/chef/chef_fs/file_system/chef_server_root_dir.rb +0 -5
  586. data/lib-backcompat/chef/chef_fs/file_system/cookbook_frozen_error.rb +0 -20
  587. data/lib-backcompat/chef/chef_fs/file_system/default_environment_cannot_be_modified_error.rb +0 -20
  588. data/lib-backcompat/chef/chef_fs/file_system/file_system_error.rb +0 -20
  589. data/lib-backcompat/chef/chef_fs/file_system/must_delete_recursively_error.rb +0 -20
  590. data/lib-backcompat/chef/chef_fs/file_system/not_found_error.rb +0 -20
  591. data/lib-backcompat/chef/chef_fs/file_system/operation_failed_error.rb +0 -20
  592. data/lib-backcompat/chef/chef_fs/file_system/operation_not_allowed_error.rb +0 -20
  593. data/lib-backcompat/chef/chef_fs/file_system/repository/chef_repository_file_system_acls_dir.rb +0 -5
  594. data/lib-backcompat/chef/chef_fs/file_system/repository/chef_repository_file_system_client_keys_dir.rb +0 -5
  595. data/lib-backcompat/chef/chef_fs/file_system/repository/chef_repository_file_system_entry.rb +0 -6
  596. data/lib-backcompat/chef/chef_fs/file_system/repository/chef_repository_file_system_policies_dir.rb +0 -5
  597. data/spec/functional/rest_spec.rb +0 -95
  598. data/spec/unit/knife/core/custom_manifest_loader_spec.rb +0 -41
  599. data/spec/unit/lib_backcompat_spec.rb +0 -34
  600. data/spec/unit/mixin/command_spec.rb +0 -107
  601. data/spec/unit/platform_spec.rb +0 -242
  602. data/spec/unit/provider/package/easy_install_spec.rb +0 -114
  603. data/spec/unit/resource/easy_install_package_spec.rb +0 -39
  604. data/spec/unit/rest/auth_credentials_spec.rb +0 -292
  605. data/spec/unit/rest_spec.rb +0 -753
  606. data/spec/unit/shell_out_spec.rb +0 -18
  607. data/tasks/bin/bundle-platform +0 -20
  608. data/tasks/bin/bundle-platform.bat +0 -2
  609. data/tasks/bin/bundler_patch.rb +0 -27
  610. data/tasks/bin/gem-version-diff +0 -37
  611. data/tasks/bundle_util.rb +0 -110
@@ -1,753 +0,0 @@
1
- #
2
- # Author:: Adam Jacob (<adam@chef.io>)
3
- # Author:: Christopher Brown (<cb@chef.io>)
4
- # Author:: Daniel DeLeo (<dan@chef.io>)
5
- # Copyright:: Copyright 2008-2016, Chef Software Inc.
6
- # Copyright:: Copyright 2010-2016, Chef Software Inc.
7
- # License:: Apache License, Version 2.0
8
- #
9
- # Licensed under the Apache License, Version 2.0 (the "License");
10
- # you may not use this file except in compliance with the License.
11
- # You may obtain a copy of the License at
12
- #
13
- # http://www.apache.org/licenses/LICENSE-2.0
14
- #
15
- # Unless required by applicable law or agreed to in writing, software
16
- # distributed under the License is distributed on an "AS IS" BASIS,
17
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
- # See the License for the specific language governing permissions and
19
- # limitations under the License.
20
- #
21
-
22
- require "spec_helper"
23
- require "uri"
24
- require "net/https"
25
- require "stringio"
26
-
27
- SIGNING_KEY_DOT_PEM = "-----BEGIN RSA PRIVATE KEY-----
28
- MIIEpAIBAAKCAQEA49TA0y81ps0zxkOpmf5V4/c4IeR5yVyQFpX3JpxO4TquwnRh
29
- 8VSUhrw8kkTLmB3cS39Db+3HadvhoqCEbqPE6915kXSuk/cWIcNozujLK7tkuPEy
30
- YVsyTioQAddSdfe+8EhQVf3oHxaKmUd6waXrWqYCnhxgOjxocenREYNhZ/OETIei
31
- PbOku47vB4nJK/0GhKBytL2XnsRgfKgDxf42BqAi1jglIdeq8lAWZNF9TbNBU21A
32
- O1iuT7Pm6LyQujhggPznR5FJhXKRUARXBJZawxpGV4dGtdcahwXNE4601aXPra+x
33
- PcRd2puCNoEDBzgVuTSsLYeKBDMSfs173W1QYwIDAQABAoIBAGF05q7vqOGbMaSD
34
- 2Q7YbuE/JTHKTBZIlBI1QC2x+0P5GDxyEFttNMOVzcs7xmNhkpRw8eX1LrInrpMk
35
- WsIBKAFFEfWYlf0RWtRChJjNl+szE9jQxB5FJnWtJH/FHa78tR6PsF24aQyzVcJP
36
- g0FGujBihwgfV0JSCNOBkz8MliQihjQA2i8PGGmo4R4RVzGfxYKTIq9vvRq/+QEa
37
- Q4lpVLoBqnENpnY/9PTl6JMMjW2b0spbLjOPVwDaIzXJ0dChjNXo15K5SHI5mALJ
38
- I5gN7ODGb8PKUf4619ez194FXq+eob5YJdilTFKensIUvt3YhP1ilGMM+Chi5Vi/
39
- /RCTw3ECgYEA9jTw4wv9pCswZ9wbzTaBj9yZS3YXspGg26y6Ohq3ZmvHz4jlT6uR
40
- xK+DDcUiK4072gci8S4Np0fIVS7q6ivqcOdzXPrTF5/j+MufS32UrBbUTPiM1yoO
41
- ECcy+1szl/KoLEV09bghPbvC58PFSXV71evkaTETYnA/F6RK12lEepcCgYEA7OSy
42
- bsMrGDVU/MKJtwqyGP9ubA53BorM4Pp9VVVSCrGGVhb9G/XNsjO5wJC8J30QAo4A
43
- s59ZzCpyNRy046AB8jwRQuSwEQbejSdeNgQGXhZ7aIVUtuDeFFdaIz/zjVgxsfj4
44
- DPOuzieMmJ2MLR4F71ocboxNoDI7xruPSE8dDhUCgYA3vx732cQxgtHwAkeNPJUz
45
- dLiE/JU7CnxIoSB9fYUfPLI+THnXgzp7NV5QJN2qzMzLfigsQcg3oyo6F2h7Yzwv
46
- GkjlualIRRzCPaCw4Btkp7qkPvbs1QngIHALt8fD1N69P3DPHkTwjG4COjKWgnJq
47
- qoHKS6Fe/ZlbigikI6KsuwKBgQCTlSLoyGRHr6oj0hqz01EDK9ciMJzMkZp0Kvn8
48
- OKxlBxYW+jlzut4MQBdgNYtS2qInxUoAnaz2+hauqhSzntK3k955GznpUatCqx0R
49
- b857vWviwPX2/P6+E3GPdl8IVsKXCvGWOBZWTuNTjQtwbDzsUepWoMgXnlQJSn5I
50
- YSlLxQKBgQD16Gw9kajpKlzsPa6XoQeGmZALT6aKWJQlrKtUQIrsIWM0Z6eFtX12
51
- 2jjHZ0awuCQ4ldqwl8IfRogWMBkHOXjTPVK0YKWWlxMpD/5+bGPARa5fir8O1Zpo
52
- Y6S6MeZ69Rp89ma4ttMZ+kwi1+XyHqC/dlcVRW42Zl5Dc7BALRlJjQ==
53
- -----END RSA PRIVATE KEY-----"
54
-
55
- describe Chef::REST do
56
- let(:base_url) { "http://chef.example.com:4000" }
57
-
58
- let(:monkey_uri) { URI.parse("http://chef.example.com:4000/monkey") }
59
-
60
- let(:log_stringio) { StringIO.new }
61
-
62
- let(:request_id) { "1234" }
63
-
64
- let(:rest) do
65
- allow(Chef::REST::CookieJar).to receive(:instance).and_return({})
66
- allow(Chef::RequestID.instance).to receive(:request_id).and_return(request_id)
67
- rest = Chef::REST.new(base_url, nil, nil)
68
- Chef::REST::CookieJar.instance.clear
69
- rest
70
- end
71
-
72
- let(:standard_read_headers) { { "Accept" => "application/json", "Accept-Encoding" => "gzip;q=1.0,deflate;q=0.6,identity;q=0.3", "X-REMOTE-REQUEST-ID" => request_id, "X-Ops-Server-API-Version" => Chef::HTTP::Authenticator::DEFAULT_SERVER_API_VERSION } }
73
- let(:standard_write_headers) { { "Accept" => "application/json", "Content-Type" => "application/json", "Accept-Encoding" => "gzip;q=1.0,deflate;q=0.6,identity;q=0.3", "X-REMOTE-REQUEST-ID" => request_id, "X-Ops-Server-API-Version" => Chef::HTTP::Authenticator::DEFAULT_SERVER_API_VERSION } }
74
-
75
- before(:each) do
76
- Chef::Log.init(log_stringio)
77
- Chef::Config[:treat_deprecation_warnings_as_errors] = false
78
- end
79
-
80
- it "should have content length validation middleware after compressor middleware" do
81
- middlewares = rest.instance_variable_get(:@middlewares)
82
- content_length = middlewares.find_index { |e| e.is_a? Chef::HTTP::ValidateContentLength }
83
- decompressor = middlewares.find_index { |e| e.is_a? Chef::HTTP::Decompressor }
84
-
85
- expect(content_length).not_to be_nil
86
- expect(decompressor).not_to be_nil
87
- expect(decompressor < content_length).to be_truthy
88
- end
89
-
90
- it "should allow the options hash to be frozen" do
91
- options = {}.freeze
92
- # should not raise any exception
93
- Chef::REST.new(base_url, nil, nil, options)
94
- end
95
-
96
- it "emits a deprecation warning" do
97
- Chef::Config[:treat_deprecation_warnings_as_errors] = true
98
- expect { Chef::REST.new(base_url) }.to raise_error Chef::Exceptions::DeprecatedFeatureError,
99
- /Chef::REST is deprecated. Please use Chef::ServerAPI, or investigate Ridley or ChefAPI./
100
- end
101
-
102
- context "when created with a chef zero URL" do
103
-
104
- let(:url) { "chefzero://localhost:1" }
105
-
106
- it "does not load the signing key" do
107
- expect { Chef::REST.new(url) }.to_not raise_error
108
- end
109
- end
110
-
111
- describe "calling an HTTP verb on a path or absolute URL" do
112
- it "adds a relative URL to the base url it was initialized with" do
113
- expect(rest.create_url("foo/bar/baz")).to eq(URI.parse(base_url + "/foo/bar/baz"))
114
- end
115
-
116
- it "replaces the base URL when given an absolute URL" do
117
- expect(rest.create_url("http://chef-rulez.example.com:9000")).to eq(URI.parse("http://chef-rulez.example.com:9000"))
118
- end
119
-
120
- it "makes a :GET request with the composed url object" do
121
- expect(rest).to receive(:send_http_request).
122
- with(:GET, monkey_uri, standard_read_headers, false).
123
- and_return([1, 2, 3])
124
- expect(rest).to receive(:apply_response_middleware).with(1, 2, 3).and_return([1, 2, 3])
125
- expect(rest).to receive("success_response?".to_sym).with(1).and_return(true)
126
- rest.get_rest("monkey")
127
- end
128
-
129
- it "makes a :GET reqest for a streaming download with the composed url" do
130
- expect(rest).to receive(:streaming_request).with("monkey", {})
131
- rest.get_rest("monkey", true)
132
- end
133
-
134
- it "makes a :DELETE request with the composed url object" do
135
- expect(rest).to receive(:send_http_request).
136
- with(:DELETE, monkey_uri, standard_read_headers, false).
137
- and_return([1, 2, 3])
138
- expect(rest).to receive(:apply_response_middleware).with(1, 2, 3).and_return([1, 2, 3])
139
- expect(rest).to receive("success_response?".to_sym).with(1).and_return(true)
140
- rest.delete_rest("monkey")
141
- end
142
-
143
- it "makes a :POST request with the composed url object and data" do
144
- expect(rest).to receive(:send_http_request).
145
- with(:POST, monkey_uri, standard_write_headers, "\"data\"").
146
- and_return([1, 2, 3])
147
- expect(rest).to receive(:apply_response_middleware).with(1, 2, 3).and_return([1, 2, 3])
148
- expect(rest).to receive("success_response?".to_sym).with(1).and_return(true)
149
- rest.post_rest("monkey", "data")
150
- end
151
-
152
- it "makes a :PUT request with the composed url object and data" do
153
- expect(rest).to receive(:send_http_request).
154
- with(:PUT, monkey_uri, standard_write_headers, "\"data\"").
155
- and_return([1, 2, 3])
156
- expect(rest).to receive(:apply_response_middleware).with(1, 2, 3).and_return([1, 2, 3])
157
- expect(rest).to receive("success_response?".to_sym).with(1).and_return(true)
158
- rest.put_rest("monkey", "data")
159
- end
160
- end
161
-
162
- describe "legacy API" do
163
- let(:rest) do
164
- Chef::REST.new(base_url)
165
- end
166
-
167
- before(:each) do
168
- Chef::Config[:node_name] = "webmonkey.example.com"
169
- Chef::Config[:client_key] = CHEF_SPEC_DATA + "/ssl/private_key.pem"
170
- end
171
-
172
- it "responds to raw_http_request as a public method" do
173
- expect(rest.public_methods.map(&:to_s)).to include("raw_http_request")
174
- end
175
-
176
- it "calls the authn middleware" do
177
- data = "\"secure data\""
178
-
179
- auth_headers = standard_write_headers.merge({ "auth_done" => "yep" })
180
-
181
- expect(rest.authenticator).to receive(:handle_request).
182
- with(:POST, monkey_uri, standard_write_headers, data).
183
- and_return([:POST, monkey_uri, auth_headers, data])
184
- expect(rest).to receive(:send_http_request).
185
- with(:POST, monkey_uri, auth_headers, data).
186
- and_return([1, 2, 3])
187
- expect(rest).to receive("success_response?".to_sym).with(1).and_return(true)
188
- rest.raw_http_request(:POST, monkey_uri, standard_write_headers, data)
189
- end
190
-
191
- it "sets correct authn headers" do
192
- data = "\"secure data\""
193
- method, uri, auth_headers, d = rest.authenticator.handle_request(:POST, monkey_uri, standard_write_headers, data)
194
-
195
- expect(rest).to receive(:send_http_request).
196
- with(:POST, monkey_uri, auth_headers, data).
197
- and_return([1, 2, 3])
198
- expect(rest).to receive("success_response?".to_sym).with(1).and_return(true)
199
- rest.raw_http_request(:POST, monkey_uri, standard_write_headers, data)
200
- end
201
- end
202
-
203
- describe "when configured to authenticate to the Chef server" do
204
- let(:base_url) { URI.parse("http://chef.example.com:4000") }
205
-
206
- let(:rest) do
207
- Chef::REST.new(base_url)
208
- end
209
-
210
- before do
211
- Chef::Config[:node_name] = "webmonkey.example.com"
212
- Chef::Config[:client_key] = CHEF_SPEC_DATA + "/ssl/private_key.pem"
213
- end
214
-
215
- it "configures itself to use the node_name and client_key in the config by default" do
216
- expect(rest.client_name).to eq("webmonkey.example.com")
217
- expect(rest.signing_key_filename).to eq(CHEF_SPEC_DATA + "/ssl/private_key.pem")
218
- end
219
-
220
- it "provides access to the raw key data" do
221
- expect(rest.signing_key).to eq(SIGNING_KEY_DOT_PEM)
222
- end
223
-
224
- it "does not error out when initialized without credentials" do
225
- rest = Chef::REST.new(base_url, nil, nil) #should_not raise_error hides the bt from you, so screw it.
226
- expect(rest.client_name).to be_nil
227
- expect(rest.signing_key).to be_nil
228
- end
229
-
230
- it "indicates that requests should not be signed when it has no credentials" do
231
- rest = Chef::REST.new(base_url, nil, nil)
232
- expect(rest.sign_requests?).to be_falsey
233
- end
234
-
235
- it "raises PrivateKeyMissing when the key file doesn't exist" do
236
- expect { Chef::REST.new(base_url, "client-name", "/dev/null/nothing_here") }.to raise_error(Chef::Exceptions::PrivateKeyMissing)
237
- end
238
-
239
- it "raises InvalidPrivateKey when the key file doesnt' look like a key" do
240
- invalid_key_file = CHEF_SPEC_DATA + "/bad-config.rb"
241
- expect { Chef::REST.new(base_url, "client-name", invalid_key_file) }.to raise_error(Chef::Exceptions::InvalidPrivateKey)
242
- end
243
-
244
- it "can take private key as a sting :raw_key in options during initializaton" do
245
- expect(Chef::REST.new(base_url, "client-name", nil, :raw_key => SIGNING_KEY_DOT_PEM).signing_key).to eq(SIGNING_KEY_DOT_PEM)
246
- end
247
-
248
- it "raises InvalidPrivateKey when the key passed as string :raw_key in options doesnt' look like a key" do
249
- expect { Chef::REST.new(base_url, "client-name", nil, :raw_key => "bad key string") }.to raise_error(Chef::Exceptions::InvalidPrivateKey)
250
- end
251
-
252
- end
253
-
254
- context "when making REST requests" do
255
- let(:body) { "ninja" }
256
-
257
- let(:http_response) do
258
- http_response = Net::HTTPSuccess.new("1.1", "200", "successful rest req")
259
- allow(http_response).to receive(:read_body)
260
- allow(http_response).to receive(:body).and_return(body)
261
- http_response["Content-Length"] = body.bytesize.to_s
262
- http_response
263
- end
264
-
265
- let(:host_header) { "one" }
266
-
267
- let(:url) { URI.parse("http://one:80/?foo=bar") }
268
-
269
- let(:base_url) { "http://chef.example.com:4000" }
270
-
271
- let!(:http_client) do
272
- http_client = Net::HTTP.new(url.host, url.port)
273
- allow(http_client).to receive(:request).and_yield(http_response).and_return(http_response)
274
- http_client
275
- end
276
-
277
- let(:rest) do
278
- allow(Net::HTTP).to receive(:new).and_return(http_client)
279
- allow(Chef::REST::CookieJar).to receive(:instance).and_return({})
280
- allow(Chef::RequestID.instance).to receive(:request_id).and_return(request_id)
281
- rest = Chef::REST.new(base_url, nil, nil)
282
- Chef::REST::CookieJar.instance.clear
283
- rest
284
- end
285
-
286
- before(:each) do
287
- Chef::Config[:ssl_client_cert] = nil
288
- Chef::Config[:ssl_client_key] = nil
289
- end
290
-
291
- describe "as JSON API requests" do
292
- let(:request_mock) { {} }
293
-
294
- let(:base_headers) do #FIXME: huh?
295
- {
296
- "Accept" => "application/json",
297
- "X-Chef-Version" => Chef::VERSION,
298
- "Accept-Encoding" => Chef::REST::RESTRequest::ENCODING_GZIP_DEFLATE,
299
- "Host" => host_header,
300
- "X-REMOTE-REQUEST-ID" => request_id,
301
- "X-Ops-Server-API-Version" => Chef::HTTP::Authenticator::DEFAULT_SERVER_API_VERSION,
302
- }
303
- end
304
-
305
- before do
306
- allow(Net::HTTP::Get).to receive(:new).and_return(request_mock)
307
- end
308
-
309
- it "should always include the X-Chef-Version header" do
310
- expect(Net::HTTP::Get).to receive(:new).with("/?foo=bar", base_headers).and_return(request_mock)
311
- rest.request(:GET, url, {})
312
- end
313
-
314
- it "should always include the X-Remote-Request-Id header" do
315
- expect(Net::HTTP::Get).to receive(:new).with("/?foo=bar", base_headers).and_return(request_mock)
316
- rest.request(:GET, url, {})
317
- end
318
-
319
- it "sets the user agent to chef-client" do
320
- # XXX: must reset to default b/c knife changes the UA
321
- Chef::REST::RESTRequest.user_agent = Chef::REST::RESTRequest::DEFAULT_UA
322
- rest.request(:GET, url, {})
323
- expect(request_mock["User-Agent"]).to match(/^Chef Client\/#{Chef::VERSION}/)
324
- end
325
-
326
- # CHEF-3140
327
- context "when configured to disable compression" do
328
- let(:rest) do
329
- allow(Net::HTTP).to receive(:new).and_return(http_client)
330
- Chef::REST.new(base_url, nil, nil, :disable_gzip => true)
331
- end
332
-
333
- it "does not accept encoding gzip" do
334
- expect(rest.send(:build_headers, :GET, url, {})).not_to have_key("Accept-Encoding")
335
- end
336
-
337
- it "does not decompress a response encoded as gzip" do
338
- http_response.add_field("content-encoding", "gzip")
339
- request = Net::HTTP::Get.new(url.path)
340
- expect(Net::HTTP::Get).to receive(:new).and_return(request)
341
- # will raise a Zlib error if incorrect
342
- expect(rest.request(:GET, url, {})).to eq("ninja")
343
- end
344
- end
345
-
346
- context "when configured with custom http headers" do
347
- let(:custom_headers) do
348
- {
349
- "X-Custom-ChefSecret" => "sharpknives",
350
- "X-Custom-RequestPriority" => "extremely low",
351
- }
352
- end
353
-
354
- before(:each) do
355
- Chef::Config[:custom_http_headers] = custom_headers
356
- end
357
-
358
- after(:each) do
359
- Chef::Config[:custom_http_headers] = nil
360
- end
361
-
362
- it "should set them on the http request" do
363
- url_string = an_instance_of(String)
364
- header_hash = hash_including(custom_headers)
365
- expect(Net::HTTP::Get).to receive(:new).with(url_string, header_hash)
366
- rest.request(:GET, url, {})
367
- end
368
- end
369
-
370
- context "when setting cookies" do
371
- let(:rest) do
372
- allow(Net::HTTP).to receive(:new).and_return(http_client)
373
- Chef::REST::CookieJar.instance["#{url.host}:#{url.port}"] = "cookie monster"
374
- allow(Chef::RequestID.instance).to receive(:request_id).and_return(request_id)
375
- rest = Chef::REST.new(base_url, nil, nil)
376
- rest
377
- end
378
-
379
- it "should set the cookie for this request if one exists for the given host:port" do
380
- expect(Net::HTTP::Get).to receive(:new).with("/?foo=bar", base_headers.merge("Cookie" => "cookie monster")).and_return(request_mock)
381
- rest.request(:GET, url, {})
382
- end
383
- end
384
-
385
- it "should build a new HTTP GET request" do
386
- expect(Net::HTTP::Get).to receive(:new).with("/?foo=bar", base_headers).and_return(request_mock)
387
- rest.request(:GET, url, {})
388
- end
389
-
390
- it "should build a new HTTP POST request" do
391
- request = Net::HTTP::Post.new(url.path)
392
- expected_headers = base_headers.merge("Content-Type" => "application/json", "Content-Length" => "13")
393
-
394
- expect(Net::HTTP::Post).to receive(:new).with("/?foo=bar", expected_headers).and_return(request)
395
- rest.request(:POST, url, {}, { :one => :two })
396
- expect(request.body).to eq('{"one":"two"}')
397
- end
398
-
399
- it "should build a new HTTP PUT request" do
400
- request = Net::HTTP::Put.new(url.path)
401
- expected_headers = base_headers.merge("Content-Type" => "application/json", "Content-Length" => "13")
402
- expect(Net::HTTP::Put).to receive(:new).with("/?foo=bar", expected_headers).and_return(request)
403
- rest.request(:PUT, url, {}, { :one => :two })
404
- expect(request.body).to eq('{"one":"two"}')
405
- end
406
-
407
- it "should build a new HTTP DELETE request" do
408
- expect(Net::HTTP::Delete).to receive(:new).with("/?foo=bar", base_headers).and_return(request_mock)
409
- rest.request(:DELETE, url)
410
- end
411
-
412
- it "should raise an error if the method is not GET/PUT/POST/DELETE" do
413
- expect { rest.request(:MONKEY, url) }.to raise_error(ArgumentError)
414
- end
415
-
416
- it "returns nil when the response is successful but content-type is not JSON" do
417
- expect(rest.request(:GET, url)).to eq("ninja")
418
- end
419
-
420
- it "should fail if the response is truncated" do
421
- http_response["Content-Length"] = (body.bytesize + 99).to_s
422
- expect { rest.request(:GET, url) }.to raise_error(Chef::Exceptions::ContentLengthMismatch)
423
- end
424
-
425
- context "when JSON is returned" do
426
- let(:body) { '{"ohai2u":"json_api"}' }
427
- it "should inflate the body as to an object" do
428
- http_response.add_field("content-type", "application/json")
429
- expect(rest.request(:GET, url, {})).to eq({ "ohai2u" => "json_api" })
430
- end
431
-
432
- it "should fail if the response is truncated" do
433
- http_response.add_field("content-type", "application/json")
434
- http_response["Content-Length"] = (body.bytesize + 99).to_s
435
- expect { rest.request(:GET, url, {}) }.to raise_error(Chef::Exceptions::ContentLengthMismatch)
436
- end
437
- end
438
-
439
- %w{ HTTPFound HTTPMovedPermanently HTTPSeeOther HTTPUseProxy HTTPTemporaryRedirect HTTPMultipleChoice }.each do |resp_name|
440
- describe "when encountering a #{resp_name} redirect" do
441
- let(:http_response) do
442
- resp_cls = Net.const_get(resp_name)
443
- resp_code = Net::HTTPResponse::CODE_TO_OBJ.keys.detect { |k| Net::HTTPResponse::CODE_TO_OBJ[k] == resp_cls }
444
- http_response = Net::HTTPFound.new("1.1", resp_code, "bob is somewhere else again")
445
- http_response.add_field("location", url.path)
446
- allow(http_response).to receive(:read_body)
447
- http_response
448
- end
449
- it "should call request again" do
450
-
451
- expect { rest.request(:GET, url) }.to raise_error(Chef::Exceptions::RedirectLimitExceeded)
452
-
453
- [:PUT, :POST, :DELETE].each do |method|
454
- expect { rest.request(method, url) }.to raise_error(Chef::Exceptions::InvalidRedirect)
455
- end
456
- end
457
- end
458
- end
459
-
460
- context "when the response is 304 NotModified" do
461
- let (:http_response) do
462
- http_response = Net::HTTPNotModified.new("1.1", "304", "it's the same as when you asked 5 minutes ago")
463
- allow(http_response).to receive(:read_body)
464
- http_response
465
- end
466
-
467
- it "should return `false`" do
468
- expect(rest.request(:GET, url)).to be_falsey
469
- end
470
- end
471
-
472
- describe "when the request fails" do
473
- before do
474
- @original_log_level = Chef::Log.level
475
- Chef::Log.level = :info
476
- end
477
-
478
- after do
479
- Chef::Log.level = @original_log_level
480
- end
481
-
482
- context "on an unsuccessful response with a JSON error" do
483
- let(:http_response) do
484
- http_response = Net::HTTPServerError.new("1.1", "500", "drooling from inside of mouth")
485
- http_response.add_field("content-type", "application/json")
486
- allow(http_response).to receive(:body).and_return('{ "error":[ "Ears get sore!", "Not even four" ] }')
487
- allow(http_response).to receive(:read_body)
488
- http_response
489
- end
490
-
491
- it "should show the JSON error message" do
492
- allow(rest).to receive(:sleep)
493
-
494
- expect { rest.request(:GET, url) }.to raise_error(Net::HTTPFatalError)
495
- expect(log_stringio.string).to match(Regexp.escape("INFO: HTTP Request Returned 500 drooling from inside of mouth: Ears get sore!, Not even four"))
496
- end
497
- end
498
-
499
- context "on an unsuccessful response with a JSON error that is compressed" do
500
- let(:http_response) do
501
- http_response = Net::HTTPServerError.new("1.1", "500", "drooling from inside of mouth")
502
- http_response.add_field("content-type", "application/json")
503
- http_response.add_field("content-encoding", "deflate")
504
- unzipped_body = '{ "error":[ "Ears get sore!", "Not even four" ] }'
505
- gzipped_body = Zlib::Deflate.deflate(unzipped_body)
506
- gzipped_body.force_encoding(Encoding::BINARY) if "strings".respond_to?(:force_encoding)
507
-
508
- allow(http_response).to receive(:body).and_return gzipped_body
509
- allow(http_response).to receive(:read_body)
510
- http_response
511
- end
512
-
513
- before do
514
- allow(rest).to receive(:sleep)
515
- allow(rest).to receive(:http_retry_count).and_return(0)
516
- end
517
-
518
- it "decompresses the JSON error message" do
519
- expect { rest.request(:GET, url) }.to raise_error(Net::HTTPFatalError)
520
- expect(log_stringio.string).to match(Regexp.escape("INFO: HTTP Request Returned 500 drooling from inside of mouth: Ears get sore!, Not even four"))
521
- end
522
-
523
- it "fails when the compressed body is truncated" do
524
- http_response["Content-Length"] = (body.bytesize + 99).to_s
525
- expect { rest.request(:GET, url) }.to raise_error(Chef::Exceptions::ContentLengthMismatch)
526
- end
527
- end
528
-
529
- context "on a generic unsuccessful request" do
530
- let(:http_response) do
531
- http_response = Net::HTTPServerError.new("1.1", "500", "drooling from inside of mouth")
532
- allow(http_response).to receive(:body)
533
- allow(http_response).to receive(:read_body)
534
- http_response
535
- end
536
-
537
- it "retries then throws an exception" do
538
- allow(rest).to receive(:sleep)
539
- expect { rest.request(:GET, url) }.to raise_error(Net::HTTPFatalError)
540
- count = Chef::Config[:http_retry_count]
541
- expect(log_stringio.string).to match(Regexp.escape("ERROR: Server returned error 500 for #{url}, retrying #{count}/#{count}"))
542
- end
543
- end
544
- end
545
- end # as JSON API requests
546
-
547
- context "when streaming downloads to a tempfile" do
548
- let!(:tempfile) { Tempfile.open("chef-rspec-rest_spec-line-@{__LINE__}--") }
549
-
550
- let(:request_mock) { {} }
551
-
552
- let(:http_response) do
553
- http_response = Net::HTTPSuccess.new("1.1", "200", "it-works")
554
-
555
- allow(http_response).to receive(:read_body)
556
- expect(http_response).not_to receive(:body)
557
- http_response["Content-Length"] = "0" # call set_content_length (in test), if otherwise
558
- http_response
559
- end
560
-
561
- def set_content_length
562
- content_length = 0
563
- http_response.read_body do |chunk|
564
- content_length += chunk.bytesize
565
- end
566
- http_response["Content-Length"] = content_length.to_s
567
- end
568
-
569
- before do
570
- allow(Tempfile).to receive(:new).with("chef-rest").and_return(tempfile)
571
- allow(Net::HTTP::Get).to receive(:new).and_return(request_mock)
572
- end
573
-
574
- after do
575
- tempfile.close!
576
- end
577
-
578
- it " build a new HTTP GET request without the application/json accept header" do
579
- expected_headers = { "Accept" => "*/*",
580
- "X-Chef-Version" => Chef::VERSION,
581
- "Accept-Encoding" => Chef::REST::RESTRequest::ENCODING_GZIP_DEFLATE,
582
- "Host" => host_header,
583
- "X-REMOTE-REQUEST-ID" => request_id,
584
- "X-Ops-Server-API-Version" => Chef::HTTP::Authenticator::DEFAULT_SERVER_API_VERSION,
585
- }
586
- expect(Net::HTTP::Get).to receive(:new).with("/?foo=bar", expected_headers).and_return(request_mock)
587
- rest.streaming_request(url, {})
588
- end
589
-
590
- it "build a new HTTP GET request with the X-Remote-Request-Id header" do
591
- expected_headers = { "Accept" => "*/*",
592
- "X-Chef-Version" => Chef::VERSION,
593
- "Accept-Encoding" => Chef::REST::RESTRequest::ENCODING_GZIP_DEFLATE,
594
- "Host" => host_header,
595
- "X-REMOTE-REQUEST-ID" => request_id,
596
- "X-Ops-Server-API-Version" => Chef::HTTP::Authenticator::DEFAULT_SERVER_API_VERSION,
597
- }
598
- expect(Net::HTTP::Get).to receive(:new).with("/?foo=bar", expected_headers).and_return(request_mock)
599
- rest.streaming_request(url, {})
600
- end
601
-
602
- it "returns a tempfile containing the streamed response body" do
603
- expect(rest.streaming_request(url, {})).to equal(tempfile)
604
- end
605
-
606
- it "writes the response body to a tempfile" do
607
- allow(http_response).to receive(:read_body).and_yield("real").and_yield("ultimate").and_yield("power")
608
- set_content_length
609
- rest.streaming_request(url, {})
610
- expect(IO.read(tempfile.path).chomp).to eq("realultimatepower")
611
- end
612
-
613
- it "closes the tempfile" do
614
- rest.streaming_request(url, {})
615
- expect(tempfile).to be_closed
616
- end
617
-
618
- it "yields the tempfile containing the streamed response body and then unlinks it when given a block" do
619
- allow(http_response).to receive(:read_body).and_yield("real").and_yield("ultimate").and_yield("power")
620
- set_content_length
621
- tempfile_path = nil
622
- rest.streaming_request(url, {}) do |tempfile|
623
- tempfile_path = tempfile.path
624
- expect(File.exist?(tempfile.path)).to be_truthy
625
- expect(IO.read(tempfile.path).chomp).to eq("realultimatepower")
626
- end
627
- expect(File.exist?(tempfile_path)).to be_falsey
628
- end
629
-
630
- it "does not raise a divide by zero exception if the content's actual size is 0" do
631
- http_response["Content-Length"] = "5"
632
- allow(http_response).to receive(:read_body).and_yield("")
633
- expect { rest.streaming_request(url, {}) }.to raise_error(Chef::Exceptions::ContentLengthMismatch)
634
- end
635
-
636
- it "does not raise a divide by zero exception when the Content-Length is 0" do
637
- http_response["Content-Length"] = "0"
638
- allow(http_response).to receive(:read_body).and_yield("ninja")
639
- expect { rest.streaming_request(url, {}) }.to raise_error(Chef::Exceptions::ContentLengthMismatch)
640
- end
641
-
642
- it "it raises an exception when the download is truncated" do
643
- http_response["Content-Length"] = (body.bytesize + 99).to_s
644
- allow(http_response).to receive(:read_body).and_yield("ninja")
645
- expect { rest.streaming_request(url, {}) }.to raise_error(Chef::Exceptions::ContentLengthMismatch)
646
- end
647
-
648
- it "fetches a file and yields the tempfile it is streamed to" do
649
- allow(http_response).to receive(:read_body).and_yield("real").and_yield("ultimate").and_yield("power")
650
- set_content_length
651
- tempfile_path = nil
652
- rest.fetch("cookbooks/a_cookbook") do |tempfile|
653
- tempfile_path = tempfile.path
654
- expect(IO.read(tempfile.path).chomp).to eq("realultimatepower")
655
- end
656
- expect(File.exist?(tempfile_path)).to be_falsey
657
- end
658
-
659
- it "closes and unlinks the tempfile if there is an error while streaming the content to the tempfile" do
660
- path = tempfile.path
661
- expect(path).not_to be_nil
662
- allow(tempfile).to receive(:write).and_raise(IOError)
663
- rest.fetch("cookbooks/a_cookbook") { |tmpfile| "shouldn't get here" }
664
- expect(File.exists?(path)).to be_falsey
665
- end
666
-
667
- it "closes and unlinks the tempfile when the response is a redirect" do
668
- tempfile = double("A tempfile", :path => "/tmp/ragefist", :close => true, :binmode => true)
669
- expect(tempfile).to receive(:close!).at_least(1).times
670
- allow(Tempfile).to receive(:new).with("chef-rest").and_return(tempfile)
671
-
672
- redirect = Net::HTTPFound.new("1.1", "302", "bob is taking care of that one for me today")
673
- redirect.add_field("location", url.path)
674
- allow(redirect).to receive(:read_body)
675
-
676
- expect(http_client).to receive(:request).and_yield(redirect).and_return(redirect)
677
- expect(http_client).to receive(:request).and_yield(http_response).and_return(http_response)
678
- rest.fetch("cookbooks/a_cookbook") { |tmpfile| "shouldn't get here" }
679
- end
680
-
681
- it "passes the original block to the redirected request" do
682
- http_redirect = Net::HTTPFound.new("1.1", "302", "bob is taking care of that one for me today")
683
- http_redirect.add_field("location", "/that-thing-is-here-now")
684
- allow(http_redirect).to receive(:read_body)
685
-
686
- block_called = false
687
- allow(http_client).to receive(:request).and_yield(http_response).and_return(http_redirect, http_response)
688
- rest.fetch("cookbooks/a_cookbook") do |tmpfile|
689
- block_called = true
690
- end
691
- expect(block_called).to be_truthy
692
- end
693
- end
694
- end # when making REST requests
695
-
696
- context "when following redirects" do
697
- let(:rest) do
698
- Chef::REST.new(base_url)
699
- end
700
-
701
- before do
702
- Chef::Config[:node_name] = "webmonkey.example.com"
703
- Chef::Config[:client_key] = CHEF_SPEC_DATA + "/ssl/private_key.pem"
704
- end
705
-
706
- it "raises a RedirectLimitExceeded when redirected more than 10 times" do
707
- redirected = lambda { rest.follow_redirect { redirected.call } }
708
- expect { redirected.call }.to raise_error(Chef::Exceptions::RedirectLimitExceeded)
709
- end
710
-
711
- it "does not count redirects from previous calls against the redirect limit" do
712
- total_redirects = 0
713
- redirected = lambda do
714
- rest.follow_redirect do
715
- total_redirects += 1
716
- redirected.call unless total_redirects >= 9
717
- end
718
- end
719
- expect { redirected.call }.not_to raise_error
720
- total_redirects = 0
721
- expect { redirected.call }.not_to raise_error
722
- end
723
-
724
- it "does not sign the redirected request when sign_on_redirect is false" do
725
- rest.sign_on_redirect = false
726
- rest.follow_redirect { expect(rest.sign_requests?).to be_falsey }
727
- end
728
-
729
- it "resets sign_requests to the original value after following an unsigned redirect" do
730
- rest.sign_on_redirect = false
731
- expect(rest.sign_requests?).to be_truthy
732
-
733
- rest.follow_redirect { expect(rest.sign_requests?).to be_falsey }
734
- expect(rest.sign_requests?).to be_truthy
735
- end
736
-
737
- it "configures the redirect limit" do
738
- total_redirects = 0
739
- redirected = lambda do
740
- rest.follow_redirect do
741
- total_redirects += 1
742
- redirected.call unless total_redirects >= 9
743
- end
744
- end
745
- expect { redirected.call }.not_to raise_error
746
-
747
- total_redirects = 0
748
- rest.redirect_limit = 3
749
- expect { redirected.call }.to raise_error(Chef::Exceptions::RedirectLimitExceeded)
750
- end
751
-
752
- end
753
- end