chef 12.0.0.alpha.2-x86-mingw32 → 12.0.0.rc.0-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (628) hide show
  1. data/CONTRIBUTING.md +9 -0
  2. data/README.md +1 -1
  3. data/Rakefile +12 -0
  4. data/bin/chef-service-manager +1 -1
  5. data/bin/chef-windows-service +35 -0
  6. data/distro/common/html/_sources/ctl_chef_server.txt +307 -10
  7. data/distro/common/html/ctl_chef_client.html +3 -7
  8. data/distro/common/html/ctl_chef_server.html +609 -41
  9. data/distro/common/html/ctl_chef_shell.html +2 -2
  10. data/distro/common/html/ctl_chef_solo.html +1 -1
  11. data/distro/common/html/index.html +13 -13
  12. data/distro/common/html/knife.html +10 -10
  13. data/distro/common/html/knife_bootstrap.html +8 -8
  14. data/distro/common/html/knife_client.html +12 -12
  15. data/distro/common/html/knife_common_options.html +7 -7
  16. data/distro/common/html/knife_configure.html +3 -3
  17. data/distro/common/html/knife_cookbook.html +19 -19
  18. data/distro/common/html/knife_cookbook_site.html +28 -28
  19. data/distro/common/html/knife_data_bag.html +28 -13
  20. data/distro/common/html/knife_delete.html +2 -2
  21. data/distro/common/html/knife_deps.html +3 -3
  22. data/distro/common/html/knife_diff.html +4 -4
  23. data/distro/common/html/knife_download.html +3 -3
  24. data/distro/common/html/knife_edit.html +2 -2
  25. data/distro/common/html/knife_environment.html +14 -14
  26. data/distro/common/html/knife_exec.html +11 -11
  27. data/distro/common/html/knife_index_rebuild.html +2 -2
  28. data/distro/common/html/knife_list.html +3 -3
  29. data/distro/common/html/knife_node.html +23 -23
  30. data/distro/common/html/knife_raw.html +4 -4
  31. data/distro/common/html/knife_recipe_list.html +3 -3
  32. data/distro/common/html/knife_role.html +11 -11
  33. data/distro/common/html/knife_search.html +4 -4
  34. data/distro/common/html/knife_serve.html +3 -3
  35. data/distro/common/html/knife_show.html +3 -3
  36. data/distro/common/html/knife_ssh.html +7 -7
  37. data/distro/common/html/knife_ssl_check.html +7 -7
  38. data/distro/common/html/knife_ssl_fetch.html +9 -9
  39. data/distro/common/html/knife_status.html +3 -3
  40. data/distro/common/html/knife_tag.html +9 -9
  41. data/distro/common/html/knife_upload.html +3 -3
  42. data/distro/common/html/knife_user.html +9 -9
  43. data/distro/common/html/knife_using.html +11 -11
  44. data/distro/common/html/knife_xargs.html +14 -5
  45. data/distro/common/html/search.html +2 -2
  46. data/distro/common/html/searchindex.js +1 -1
  47. data/distro/common/man/man1/chef-shell.1 +2 -2
  48. data/distro/common/man/man1/knife-bootstrap.1 +7 -7
  49. data/distro/common/man/man1/knife-client.1 +10 -10
  50. data/distro/common/man/man1/knife-configure.1 +5 -5
  51. data/distro/common/man/man1/knife-cookbook-site.1 +24 -24
  52. data/distro/common/man/man1/knife-cookbook.1 +12 -12
  53. data/distro/common/man/man1/knife-data-bag.1 +34 -10
  54. data/distro/common/man/man1/knife-delete.1 +5 -5
  55. data/distro/common/man/man1/knife-deps.1 +5 -5
  56. data/distro/common/man/man1/knife-diff.1 +7 -7
  57. data/distro/common/man/man1/knife-download.1 +5 -5
  58. data/distro/common/man/man1/knife-edit.1 +5 -5
  59. data/distro/common/man/man1/knife-environment.1 +11 -11
  60. data/distro/common/man/man1/knife-exec.1 +11 -11
  61. data/distro/common/man/man1/knife-index-rebuild.1 +1 -1
  62. data/distro/common/man/man1/knife-list.1 +5 -5
  63. data/distro/common/man/man1/knife-node.1 +16 -16
  64. data/distro/common/man/man1/knife-raw.1 +6 -6
  65. data/distro/common/man/man1/knife-recipe-list.1 +1 -1
  66. data/distro/common/man/man1/knife-role.1 +7 -7
  67. data/distro/common/man/man1/knife-search.1 +6 -6
  68. data/distro/common/man/man1/knife-serve.1 +6 -6
  69. data/distro/common/man/man1/knife-show.1 +5 -5
  70. data/distro/common/man/man1/knife-ssh.1 +9 -9
  71. data/distro/common/man/man1/knife-ssl-check.1 +7 -7
  72. data/distro/common/man/man1/knife-ssl-fetch.1 +9 -9
  73. data/distro/common/man/man1/knife-status.1 +5 -5
  74. data/distro/common/man/man1/knife-tag.1 +8 -8
  75. data/distro/common/man/man1/knife-upload.1 +5 -5
  76. data/distro/common/man/man1/knife-user.1 +8 -8
  77. data/distro/common/man/man1/knife-xargs.1 +36 -10
  78. data/distro/common/man/man1/knife.1 +14 -14
  79. data/distro/common/man/man8/chef-client.8 +3 -10
  80. data/distro/common/man/man8/chef-solo.8 +1 -1
  81. data/ext/win32-eventlog/Rakefile +50 -0
  82. data/ext/win32-eventlog/chef-log.man +26 -0
  83. data/lib/chef/application.rb +313 -241
  84. data/lib/chef/application/apply.rb +10 -8
  85. data/lib/chef/application/client.rb +58 -33
  86. data/lib/chef/application/solo.rb +33 -12
  87. data/lib/chef/chef_fs/chef_fs_data_store.rb +1 -1
  88. data/lib/chef/chef_fs/command_line.rb +1 -1
  89. data/lib/chef/chef_fs/file_system/organization_invites_entry.rb +2 -1
  90. data/lib/chef/chef_fs/file_system/organization_members_entry.rb +2 -1
  91. data/lib/chef/chef_fs/file_system/rest_list_entry.rb +2 -1
  92. data/lib/chef/client.rb +18 -48
  93. data/lib/chef/config.rb +43 -11
  94. data/lib/chef/cookbook/cookbook_version_loader.rb +14 -7
  95. data/lib/chef/cookbook/metadata.rb +81 -38
  96. data/lib/chef/cookbook/syntax_check.rb +18 -52
  97. data/lib/chef/cookbook_loader.rb +1 -1
  98. data/lib/chef/cookbook_version.rb +58 -39
  99. data/lib/chef/data_bag.rb +2 -2
  100. data/lib/chef/deprecation/provider/file.rb +2 -1
  101. data/lib/chef/dsl/data_query.rb +2 -29
  102. data/lib/chef/dsl/recipe.rb +8 -22
  103. data/lib/chef/encrypted_data_bag_item/assertions.rb +1 -1
  104. data/lib/chef/encrypted_data_bag_item/check_encrypted.rb +56 -0
  105. data/lib/chef/encrypted_data_bag_item/encrypted_data_bag_item_assertions.rb +1 -1
  106. data/lib/chef/event_loggers/base.rb +62 -0
  107. data/lib/chef/event_loggers/windows_eventlog.rb +104 -0
  108. data/lib/chef/exceptions.rb +18 -1
  109. data/lib/chef/file_cache.rb +3 -2
  110. data/lib/chef/guard_interpreter/resource_guard_interpreter.rb +15 -6
  111. data/lib/chef/http.rb +20 -13
  112. data/lib/chef/http/ssl_policies.rb +2 -1
  113. data/lib/chef/json_compat.rb +9 -3
  114. data/lib/chef/knife.rb +2 -1
  115. data/lib/chef/knife/bootstrap.rb +12 -18
  116. data/lib/chef/knife/bootstrap/archlinux-gems.erb +2 -2
  117. data/lib/chef/knife/bootstrap/chef-aix.erb +2 -2
  118. data/lib/chef/knife/bootstrap/chef-full.erb +2 -2
  119. data/lib/chef/knife/cookbook_create.rb +1 -1
  120. data/lib/chef/knife/cookbook_site_share.rb +43 -8
  121. data/lib/chef/knife/core/bootstrap_context.rb +6 -11
  122. data/lib/chef/knife/core/object_loader.rb +5 -5
  123. data/lib/chef/knife/core/status_presenter.rb +156 -0
  124. data/lib/chef/knife/core/subcommand_loader.rb +6 -5
  125. data/lib/chef/knife/core/ui.rb +4 -4
  126. data/lib/chef/knife/data_bag_create.rb +7 -32
  127. data/lib/chef/knife/data_bag_edit.rb +24 -43
  128. data/lib/chef/knife/data_bag_from_file.rb +6 -31
  129. data/lib/chef/knife/data_bag_secret_options.rb +142 -0
  130. data/lib/chef/knife/data_bag_show.rb +19 -33
  131. data/lib/chef/knife/node_from_file.rb +9 -8
  132. data/lib/chef/knife/ssh.rb +0 -7
  133. data/lib/chef/knife/ssl_check.rb +70 -6
  134. data/lib/chef/knife/status.rb +11 -58
  135. data/lib/chef/mixin/command/unix.rb +2 -2
  136. data/lib/chef/mixin/convert_to_class_name.rb +54 -0
  137. data/lib/chef/mixin/descendants_tracker.rb +82 -0
  138. data/lib/chef/mixin/homebrew_user.rb +68 -0
  139. data/lib/chef/mixin/shell_out.rb +0 -4
  140. data/lib/chef/mixin/windows_architecture_helper.rb +16 -0
  141. data/lib/chef/mixin/windows_env_helper.rb +56 -0
  142. data/lib/chef/node.rb +2 -2
  143. data/lib/chef/node_map.rb +146 -0
  144. data/lib/chef/platform/provider_mapping.rb +11 -39
  145. data/lib/chef/platform/provider_priority_map.rb +80 -0
  146. data/lib/chef/platform/query_helpers.rb +5 -1
  147. data/lib/chef/platform/service_helpers.rb +113 -0
  148. data/lib/chef/provider.rb +24 -0
  149. data/lib/chef/provider/breakpoint.rb +2 -0
  150. data/lib/chef/provider/cookbook_file.rb +2 -0
  151. data/lib/chef/provider/cron.rb +1 -1
  152. data/lib/chef/provider/cron/unix.rb +13 -9
  153. data/lib/chef/provider/deploy.rb +3 -2
  154. data/lib/chef/provider/deploy/revision.rb +4 -2
  155. data/lib/chef/provider/deploy/timestamped.rb +2 -0
  156. data/lib/chef/provider/directory.rb +2 -0
  157. data/lib/chef/provider/dsc_script.rb +179 -0
  158. data/lib/chef/provider/env.rb +25 -10
  159. data/lib/chef/provider/env/windows.rb +9 -16
  160. data/lib/chef/provider/erl_call.rb +2 -0
  161. data/lib/chef/provider/execute.rb +5 -2
  162. data/lib/chef/provider/file.rb +2 -0
  163. data/lib/chef/provider/git.rb +51 -23
  164. data/lib/chef/provider/group/dscl.rb +2 -2
  165. data/lib/chef/provider/group/pw.rb +9 -13
  166. data/lib/chef/provider/http_request.rb +2 -0
  167. data/lib/chef/provider/link.rb +3 -0
  168. data/lib/chef/provider/log.rb +2 -0
  169. data/lib/chef/provider/lwrp_base.rb +11 -9
  170. data/lib/chef/provider/mount/mount.rb +1 -1
  171. data/lib/chef/provider/package/aix.rb +2 -0
  172. data/lib/chef/provider/package/apt.rb +2 -0
  173. data/lib/chef/provider/package/dpkg.rb +2 -0
  174. data/lib/chef/provider/package/easy_install.rb +2 -0
  175. data/lib/chef/provider/package/freebsd/pkg.rb +2 -1
  176. data/lib/chef/provider/package/freebsd/pkgng.rb +1 -1
  177. data/lib/chef/provider/package/freebsd/port.rb +1 -9
  178. data/lib/chef/provider/package/homebrew.rb +127 -0
  179. data/lib/chef/provider/package/ips.rb +2 -0
  180. data/lib/chef/provider/package/macports.rb +3 -0
  181. data/lib/chef/provider/package/pacman.rb +5 -4
  182. data/lib/chef/provider/package/paludis.rb +4 -2
  183. data/lib/chef/provider/package/portage.rb +4 -1
  184. data/lib/chef/provider/package/rpm.rb +2 -0
  185. data/lib/chef/provider/package/rubygems.rb +4 -0
  186. data/lib/chef/provider/package/smartos.rb +2 -0
  187. data/lib/chef/provider/package/solaris.rb +2 -0
  188. data/lib/chef/provider/package/windows.rb +5 -2
  189. data/lib/chef/provider/package/yum.rb +2 -0
  190. data/lib/chef/provider/powershell_script.rb +3 -1
  191. data/lib/chef/provider/remote_directory.rb +25 -10
  192. data/lib/chef/provider/route.rb +2 -0
  193. data/lib/chef/provider/ruby_block.rb +2 -0
  194. data/lib/chef/provider/script.rb +6 -0
  195. data/lib/chef/provider/service/aix.rb +128 -0
  196. data/lib/chef/provider/service/aixinit.rb +117 -0
  197. data/lib/chef/provider/service/arch.rb +6 -0
  198. data/lib/chef/provider/service/debian.rb +35 -29
  199. data/lib/chef/provider/service/freebsd.rb +7 -1
  200. data/lib/chef/provider/service/gentoo.rb +5 -1
  201. data/lib/chef/provider/service/init.rb +2 -0
  202. data/lib/chef/provider/service/insserv.rb +15 -8
  203. data/lib/chef/provider/service/invokercd.rb +6 -0
  204. data/lib/chef/provider/service/macosx.rb +4 -1
  205. data/lib/chef/provider/service/redhat.rb +9 -3
  206. data/lib/chef/provider/service/simple.rb +2 -0
  207. data/lib/chef/provider/service/solaris.rb +2 -0
  208. data/lib/chef/provider/service/systemd.rb +7 -0
  209. data/lib/chef/provider/service/upstart.rb +7 -0
  210. data/lib/chef/provider/service/windows.rb +5 -0
  211. data/lib/chef/provider/subversion.rb +2 -0
  212. data/lib/chef/provider/template.rb +1 -0
  213. data/lib/chef/provider/user/dscl.rb +3 -2
  214. data/lib/chef/provider/whyrun_safe_ruby_block.rb +2 -0
  215. data/lib/chef/provider_resolver.rb +103 -0
  216. data/lib/chef/providers.rb +6 -2
  217. data/lib/chef/recipe.rb +2 -0
  218. data/lib/chef/resource.rb +69 -78
  219. data/lib/chef/resource/apt_package.rb +3 -1
  220. data/lib/chef/resource/bash.rb +1 -0
  221. data/lib/chef/resource/bff_package.rb +0 -1
  222. data/lib/chef/resource/breakpoint.rb +1 -1
  223. data/lib/chef/resource/chef_gem.rb +1 -2
  224. data/lib/chef/resource/conditional.rb +26 -6
  225. data/lib/chef/resource/cookbook_file.rb +2 -3
  226. data/lib/chef/resource/csh.rb +1 -0
  227. data/lib/chef/resource/deploy.rb +0 -1
  228. data/lib/chef/resource/deploy_revision.rb +6 -1
  229. data/lib/chef/resource/directory.rb +1 -2
  230. data/lib/chef/resource/dpkg_package.rb +2 -1
  231. data/lib/chef/resource/dsc_script.rb +125 -0
  232. data/lib/chef/resource/easy_install_package.rb +2 -1
  233. data/lib/chef/resource/erl_call.rb +1 -0
  234. data/lib/chef/resource/execute.rb +26 -9
  235. data/lib/chef/resource/file.rb +1 -3
  236. data/lib/chef/resource/freebsd_package.rb +10 -23
  237. data/lib/chef/resource/gem_package.rb +2 -1
  238. data/lib/chef/resource/git.rb +2 -1
  239. data/lib/chef/resource/homebrew_package.rb +46 -0
  240. data/lib/chef/resource/http_request.rb +1 -0
  241. data/lib/chef/resource/ips_package.rb +3 -1
  242. data/lib/chef/resource/link.rb +1 -2
  243. data/lib/chef/resource/log.rb +4 -0
  244. data/lib/chef/resource/lwrp_base.rb +24 -15
  245. data/lib/chef/resource/macports_package.rb +3 -1
  246. data/lib/chef/resource/pacman_package.rb +2 -1
  247. data/lib/chef/resource/paludis_package.rb +3 -1
  248. data/lib/chef/resource/perl.rb +1 -0
  249. data/lib/chef/resource/powershell_script.rb +0 -2
  250. data/lib/chef/resource/python.rb +1 -1
  251. data/lib/chef/resource/remote_directory.rb +1 -2
  252. data/lib/chef/resource/remote_file.rb +1 -1
  253. data/lib/chef/resource/rpm_package.rb +2 -1
  254. data/lib/chef/resource/ruby.rb +1 -0
  255. data/lib/chef/resource/ruby_block.rb +3 -0
  256. data/lib/chef/resource/script.rb +2 -25
  257. data/lib/chef/resource/service.rb +0 -4
  258. data/lib/chef/resource/smartos_package.rb +3 -4
  259. data/lib/chef/resource/solaris_package.rb +7 -1
  260. data/lib/chef/resource/subversion.rb +0 -1
  261. data/lib/chef/resource/template.rb +2 -3
  262. data/lib/chef/resource/timestamped_deploy.rb +1 -2
  263. data/lib/chef/resource/whyrun_safe_ruby_block.rb +0 -1
  264. data/lib/chef/resource/windows_package.rb +3 -4
  265. data/lib/chef/resource/windows_script.rb +3 -0
  266. data/lib/chef/resource/windows_service.rb +2 -2
  267. data/lib/chef/resource/yum_package.rb +3 -1
  268. data/lib/chef/resource_collection.rb +50 -227
  269. data/lib/chef/resource_collection/resource_collection_serialization.rb +59 -0
  270. data/lib/chef/resource_collection/resource_list.rb +89 -0
  271. data/lib/chef/resource_collection/resource_set.rb +170 -0
  272. data/lib/chef/resources.rb +2 -0
  273. data/lib/chef/role.rb +1 -1
  274. data/lib/chef/run_context.rb +5 -1
  275. data/lib/chef/shell/ext.rb +1 -1
  276. data/lib/chef/util/backup.rb +3 -2
  277. data/lib/chef/util/dsc/configuration_generator.rb +115 -0
  278. data/lib/chef/util/dsc/lcm_output_parser.rb +133 -0
  279. data/lib/chef/util/dsc/local_configuration_manager.rb +141 -0
  280. data/lib/chef/util/dsc/resource_info.rb +26 -0
  281. data/lib/chef/util/path_helper.rb +12 -0
  282. data/lib/chef/util/powershell/cmdlet.rb +136 -0
  283. data/lib/chef/util/powershell/cmdlet_result.rb +46 -0
  284. data/lib/chef/version.rb +1 -1
  285. data/lib/chef/win32/api/system.rb +9 -0
  286. data/lib/chef/win32/version.rb +2 -0
  287. data/spec/.DS_Store +0 -0
  288. data/spec/data/.DS_Store +0 -0
  289. data/spec/data/bootstrap/test-hints.erb +1 -1
  290. data/spec/data/bootstrap/test.erb +1 -1
  291. data/spec/data/cb_version_cookbooks/cookbook2/files/test.txt +0 -0
  292. data/spec/data/cb_version_cookbooks/cookbook2/templates/test.erb +0 -0
  293. data/spec/data/cookbooks/ignorken/files/default/not_me.rb +2 -0
  294. data/spec/data/cookbooks/ignorken/templates/ubuntu-12.10/not_me.rb +2 -0
  295. data/spec/data/cookbooks/openldap/libraries/openldap.rb +4 -0
  296. data/spec/data/cookbooks/openldap/libraries/openldap/version.rb +3 -0
  297. data/spec/data/lwrp/.DS_Store +0 -0
  298. data/spec/data/lwrp/providers/.DS_Store +0 -0
  299. data/spec/data/lwrp/providers/buck_passer.rb +9 -2
  300. data/spec/data/lwrp/resources/.DS_Store +0 -0
  301. data/spec/data/lwrp/resources/foo.rb +3 -2
  302. data/spec/data/lwrp_override/.DS_Store +0 -0
  303. data/spec/data/lwrp_override/providers/.DS_Store +0 -0
  304. data/spec/data/lwrp_override/providers/buck_passer.rb +5 -10
  305. data/spec/data/lwrp_override/resources/.DS_Store +0 -0
  306. data/spec/data/lwrp_override/resources/foo.rb +4 -3
  307. data/spec/functional/assets/chefinittest +34 -0
  308. data/spec/functional/assets/testchefsubsys +11 -0
  309. data/spec/functional/dsl/reboot_pending_spec.rb +19 -16
  310. data/spec/functional/event_loggers/windows_eventlog_spec.rb +82 -0
  311. data/spec/functional/knife/cookbook_delete_spec.rb +3 -3
  312. data/spec/functional/knife/exec_spec.rb +1 -1
  313. data/spec/functional/resource/aix_service_spec.rb +136 -0
  314. data/spec/functional/resource/aixinit_service_spec.rb +211 -0
  315. data/spec/functional/resource/base.rb +1 -0
  316. data/spec/functional/resource/batch_spec.rb +4 -11
  317. data/spec/functional/resource/cron_spec.rb +7 -1
  318. data/spec/functional/resource/dsc_script_spec.rb +382 -0
  319. data/spec/functional/resource/env_spec.rb +54 -0
  320. data/spec/functional/resource/execute_spec.rb +113 -0
  321. data/spec/functional/resource/file_spec.rb +2 -0
  322. data/spec/functional/resource/group_spec.rb +7 -4
  323. data/spec/functional/resource/powershell_spec.rb +198 -185
  324. data/spec/functional/resource/rpm_spec.rb +5 -4
  325. data/spec/functional/resource/user/dscl_spec.rb +2 -1
  326. data/spec/functional/util/path_helper_spec.rb +37 -0
  327. data/spec/functional/util/powershell/cmdlet_spec.rb +114 -0
  328. data/spec/integration/client/client_spec.rb +1 -1
  329. data/spec/integration/client/ipv6_spec.rb +1 -1
  330. data/spec/integration/knife/chef_fs_data_store_spec.rb +1 -1
  331. data/spec/integration/knife/chef_repo_path_spec.rb +1 -1
  332. data/spec/integration/knife/chef_repository_file_system_spec.rb +1 -1
  333. data/spec/integration/knife/chefignore_spec.rb +1 -1
  334. data/spec/integration/knife/common_options_spec.rb +1 -1
  335. data/spec/integration/knife/cookbook_api_ipv6_spec.rb +2 -2
  336. data/spec/integration/knife/delete_spec.rb +1 -1
  337. data/spec/integration/knife/deps_spec.rb +1 -1
  338. data/spec/integration/knife/diff_spec.rb +1 -1
  339. data/spec/integration/knife/download_spec.rb +1 -1
  340. data/spec/integration/knife/list_spec.rb +1 -1
  341. data/spec/integration/knife/raw_spec.rb +1 -1
  342. data/spec/integration/knife/redirection_spec.rb +1 -1
  343. data/spec/integration/knife/serve_spec.rb +1 -1
  344. data/spec/integration/knife/show_spec.rb +1 -1
  345. data/spec/integration/knife/upload_spec.rb +4 -3
  346. data/spec/integration/recipes/lwrp_inline_resources_spec.rb +1 -1
  347. data/spec/spec_helper.rb +15 -0
  348. data/spec/support/chef_helpers.rb +1 -0
  349. data/spec/support/lib/chef/provider/snakeoil.rb +1 -0
  350. data/spec/support/lib/chef/resource/zen_follower.rb +1 -7
  351. data/spec/support/platform_helpers.rb +28 -0
  352. data/spec/support/shared/functional/file_resource.rb +6 -0
  353. data/spec/support/shared/functional/windows_script.rb +118 -0
  354. data/spec/support/shared/integration/integration_helper.rb +5 -2
  355. data/spec/support/shared/matchers/exit_with_code.rb +28 -0
  356. data/spec/support/shared/matchers/match_environment_variable.rb +17 -0
  357. data/spec/support/shared/shared_examples.rb +14 -0
  358. data/spec/support/shared/unit/execute_resource.rb +0 -7
  359. data/spec/support/shared/unit/resource/static_provider_resolution.rb +71 -0
  360. data/spec/support/shared/unit/script_resource.rb +1 -1
  361. data/spec/support/shared/unit/windows_script_resource.rb +35 -2
  362. data/spec/tiny_server.rb +1 -2
  363. data/spec/unit/api_client_spec.rb +5 -1
  364. data/spec/unit/application/{apply.rb → apply_spec.rb} +13 -5
  365. data/spec/unit/application/client_spec.rb +106 -13
  366. data/spec/unit/application/solo_spec.rb +25 -1
  367. data/spec/unit/client_spec.rb +1 -26
  368. data/spec/unit/config_fetcher_spec.rb +2 -1
  369. data/spec/unit/config_spec.rb +91 -2
  370. data/spec/unit/cookbook/cookbook_version_loader_spec.rb +8 -0
  371. data/spec/unit/cookbook/metadata_spec.rb +43 -6
  372. data/spec/unit/cookbook/syntax_check_spec.rb +8 -2
  373. data/spec/unit/cookbook_loader_spec.rb +4 -2
  374. data/spec/unit/cookbook_version_spec.rb +83 -2
  375. data/spec/unit/data_bag_item_spec.rb +5 -1
  376. data/spec/unit/data_bag_spec.rb +6 -1
  377. data/spec/unit/dsl/data_query_spec.rb +8 -110
  378. data/spec/unit/encrypted_data_bag_item/check_encrypted_spec.rb +95 -0
  379. data/spec/unit/encrypted_data_bag_item_spec.rb +16 -23
  380. data/spec/unit/environment_spec.rb +6 -2
  381. data/spec/unit/exceptions_spec.rb +6 -0
  382. data/spec/unit/guard_interpreter/resource_guard_interpreter_spec.rb +16 -15
  383. data/spec/unit/json_compat_spec.rb +12 -2
  384. data/spec/unit/knife/bootstrap_spec.rb +16 -63
  385. data/spec/unit/knife/cookbook_site_share_spec.rb +59 -6
  386. data/spec/unit/knife/core/bootstrap_context_spec.rb +8 -37
  387. data/spec/unit/knife/core/subcommand_loader_spec.rb +1 -1
  388. data/spec/unit/knife/core/ui_spec.rb +28 -0
  389. data/spec/unit/knife/data_bag_create_spec.rb +63 -71
  390. data/spec/unit/knife/data_bag_edit_spec.rb +83 -49
  391. data/spec/unit/knife/data_bag_from_file_spec.rb +104 -126
  392. data/spec/unit/knife/data_bag_secret_options_spec.rb +165 -0
  393. data/spec/unit/knife/data_bag_show_spec.rb +74 -72
  394. data/spec/unit/knife/environment_from_file_spec.rb +3 -2
  395. data/spec/unit/knife/ssl_check_spec.rb +46 -1
  396. data/spec/unit/knife/status_spec.rb +1 -2
  397. data/spec/unit/knife_spec.rb +18 -1
  398. data/spec/unit/lwrp_spec.rb +29 -8
  399. data/spec/unit/mixin/homebrew_user_spec.rb +100 -0
  400. data/spec/unit/node_map_spec.rb +155 -0
  401. data/spec/unit/node_spec.rb +11 -0
  402. data/spec/unit/platform/query_helpers_spec.rb +23 -0
  403. data/spec/unit/platform_spec.rb +23 -0
  404. data/spec/unit/provider/breakpoint_spec.rb +9 -9
  405. data/spec/unit/provider/cookbook_file/content_spec.rb +3 -3
  406. data/spec/unit/provider/cookbook_file_spec.rb +1 -1
  407. data/spec/unit/provider/cron/unix_spec.rb +78 -60
  408. data/spec/unit/provider/cron_spec.rb +175 -175
  409. data/spec/unit/provider/deploy/revision_spec.rb +22 -21
  410. data/spec/unit/provider/deploy/timestamped_spec.rb +3 -3
  411. data/spec/unit/provider/deploy_spec.rb +231 -230
  412. data/spec/unit/provider/directory_spec.rb +55 -55
  413. data/spec/unit/provider/dsc_script_spec.rb +174 -0
  414. data/spec/unit/provider/env/windows_spec.rb +70 -34
  415. data/spec/unit/provider/env_spec.rb +95 -49
  416. data/spec/unit/provider/erl_call_spec.rb +9 -9
  417. data/spec/unit/provider/execute_spec.rb +43 -27
  418. data/spec/unit/provider/file/content_spec.rb +9 -9
  419. data/spec/unit/provider/file_spec.rb +1 -1
  420. data/spec/unit/provider/git_spec.rb +221 -159
  421. data/spec/unit/provider/group/dscl_spec.rb +64 -63
  422. data/spec/unit/provider/group/gpasswd_spec.rb +14 -14
  423. data/spec/unit/provider/group/groupadd_spec.rb +33 -33
  424. data/spec/unit/provider/group/groupmod_spec.rb +23 -23
  425. data/spec/unit/provider/group/pw_spec.rb +21 -21
  426. data/spec/unit/provider/group/usermod_spec.rb +20 -20
  427. data/spec/unit/provider/group/windows_spec.rb +15 -15
  428. data/spec/unit/provider/group_spec.rb +76 -76
  429. data/spec/unit/provider/http_request_spec.rb +30 -30
  430. data/spec/unit/provider/ifconfig/aix_spec.rb +20 -20
  431. data/spec/unit/provider/ifconfig/debian_spec.rb +25 -9
  432. data/spec/unit/provider/ifconfig/redhat_spec.rb +13 -13
  433. data/spec/unit/provider/ifconfig_spec.rb +43 -43
  434. data/spec/unit/provider/link_spec.rb +60 -60
  435. data/spec/unit/provider/log_spec.rb +0 -4
  436. data/spec/unit/provider/mdadm_spec.rb +23 -23
  437. data/spec/unit/provider/mount/aix_spec.rb +17 -17
  438. data/spec/unit/provider/mount/mount_spec.rb +115 -119
  439. data/spec/unit/provider/mount/solaris_spec.rb +72 -72
  440. data/spec/unit/provider/mount/windows_spec.rb +24 -24
  441. data/spec/unit/provider/ohai_spec.rb +11 -11
  442. data/spec/unit/provider/package/aix_spec.rb +34 -34
  443. data/spec/unit/provider/package/apt_spec.rb +36 -36
  444. data/spec/unit/provider/package/dpkg_spec.rb +27 -27
  445. data/spec/unit/provider/package/easy_install_spec.rb +16 -16
  446. data/spec/unit/provider/package/freebsd/pkg_spec.rb +53 -53
  447. data/spec/unit/provider/package/freebsd/pkgng_spec.rb +24 -24
  448. data/spec/unit/provider/package/freebsd/port_spec.rb +45 -35
  449. data/spec/unit/provider/package/homebrew_spec.rb +266 -0
  450. data/spec/unit/provider/package/ips_spec.rb +34 -34
  451. data/spec/unit/provider/package/macports_spec.rb +49 -49
  452. data/spec/unit/provider/package/pacman_spec.rb +35 -39
  453. data/spec/unit/provider/package/paludis_spec.rb +20 -20
  454. data/spec/unit/provider/package/portage_spec.rb +38 -38
  455. data/spec/unit/provider/package/rpm_spec.rb +29 -29
  456. data/spec/unit/provider/package/rubygems_spec.rb +284 -270
  457. data/spec/unit/provider/package/smartos_spec.rb +15 -15
  458. data/spec/unit/provider/package/solaris_spec.rb +35 -35
  459. data/spec/unit/provider/package/windows/msi_spec.rb +3 -3
  460. data/spec/unit/provider/package/windows_spec.rb +6 -6
  461. data/spec/unit/provider/package/yum_spec.rb +416 -416
  462. data/spec/unit/provider/package/zypper_spec.rb +47 -47
  463. data/spec/unit/provider/package_spec.rb +107 -107
  464. data/spec/unit/provider/powershell_spec.rb +1 -1
  465. data/spec/unit/provider/registry_key_spec.rb +61 -61
  466. data/spec/unit/provider/remote_directory_spec.rb +36 -36
  467. data/spec/unit/provider/remote_file/cache_control_data_spec.rb +24 -24
  468. data/spec/unit/provider/remote_file/content_spec.rb +45 -45
  469. data/spec/unit/provider/remote_file/fetcher_spec.rb +9 -9
  470. data/spec/unit/provider/remote_file/ftp_spec.rb +32 -32
  471. data/spec/unit/provider/remote_file/http_spec.rb +44 -44
  472. data/spec/unit/provider/remote_file/local_file_spec.rb +9 -9
  473. data/spec/unit/provider/remote_file_spec.rb +3 -3
  474. data/spec/unit/provider/route_spec.rb +63 -63
  475. data/spec/unit/provider/ruby_block_spec.rb +4 -4
  476. data/spec/unit/provider/script_spec.rb +12 -12
  477. data/spec/unit/provider/service/aix_service_spec.rb +181 -0
  478. data/spec/unit/provider/service/aixinit_service_spec.rb +269 -0
  479. data/spec/unit/provider/service/arch_service_spec.rb +48 -48
  480. data/spec/unit/provider/service/debian_service_spec.rb +40 -40
  481. data/spec/unit/provider/service/gentoo_service_spec.rb +28 -28
  482. data/spec/unit/provider/service/init_service_spec.rb +39 -39
  483. data/spec/unit/provider/service/insserv_service_spec.rb +8 -8
  484. data/spec/unit/provider/service/invokercd_service_spec.rb +35 -35
  485. data/spec/unit/provider/service/macosx_spec.rb +49 -49
  486. data/spec/unit/provider/service/redhat_spec.rb +27 -27
  487. data/spec/unit/provider/service/simple_service_spec.rb +28 -28
  488. data/spec/unit/provider/service/solaris_smf_service_spec.rb +43 -46
  489. data/spec/unit/provider/service/systemd_service_spec.rb +63 -63
  490. data/spec/unit/provider/service/upstart_service_spec.rb +78 -78
  491. data/spec/unit/provider/service/windows_spec.rb +92 -92
  492. data/spec/unit/provider/service_spec.rb +40 -40
  493. data/spec/unit/provider/subversion_spec.rb +80 -80
  494. data/spec/unit/provider/template/content_spec.rb +9 -9
  495. data/spec/unit/provider/template_spec.rb +6 -6
  496. data/spec/unit/provider/user/dscl_spec.rb +170 -167
  497. data/spec/unit/provider/user/pw_spec.rb +48 -48
  498. data/spec/unit/provider/user/solaris_spec.rb +8 -8
  499. data/spec/unit/provider/user/useradd_spec.rb +1 -1
  500. data/spec/unit/provider/user/windows_spec.rb +26 -26
  501. data/spec/unit/provider/user_spec.rb +72 -72
  502. data/spec/unit/provider/whyrun_safe_ruby_block_spec.rb +4 -4
  503. data/spec/unit/provider_resolver_spec.rb +387 -0
  504. data/spec/unit/recipe_spec.rb +33 -12
  505. data/spec/unit/resource/apt_package_spec.rb +10 -13
  506. data/spec/unit/resource/bash_spec.rb +4 -4
  507. data/spec/unit/resource/batch_spec.rb +1 -1
  508. data/spec/unit/resource/breakpoint_spec.rb +11 -7
  509. data/spec/unit/resource/chef_gem_spec.rb +8 -15
  510. data/spec/unit/resource/conditional_action_not_nothing_spec.rb +2 -2
  511. data/spec/unit/resource/conditional_spec.rb +35 -16
  512. data/spec/unit/resource/cookbook_file_spec.rb +13 -13
  513. data/spec/unit/resource/cron_spec.rb +37 -37
  514. data/spec/unit/resource/csh_spec.rb +4 -4
  515. data/spec/unit/resource/deploy_revision_spec.rb +13 -18
  516. data/spec/unit/resource/deploy_spec.rb +60 -55
  517. data/spec/unit/resource/directory_spec.rb +18 -18
  518. data/spec/unit/resource/dpkg_package_spec.rb +8 -14
  519. data/spec/unit/resource/dsc_script_spec.rb +98 -0
  520. data/spec/unit/resource/easy_install_package_spec.rb +9 -18
  521. data/spec/unit/resource/env_spec.rb +12 -12
  522. data/spec/unit/resource/erl_call_spec.rb +11 -11
  523. data/spec/unit/resource/execute_spec.rb +5 -0
  524. data/spec/unit/resource/file_spec.rb +29 -29
  525. data/spec/unit/resource/freebsd_package_spec.rb +11 -12
  526. data/spec/unit/resource/gem_package_spec.rb +8 -15
  527. data/spec/unit/resource/git_spec.rb +12 -8
  528. data/spec/unit/resource/group_spec.rb +27 -27
  529. data/spec/unit/resource/homebrew_package_spec.rb +50 -0
  530. data/spec/unit/resource/http_request_spec.rb +6 -6
  531. data/spec/unit/resource/ifconfig_spec.rb +8 -8
  532. data/spec/unit/resource/ips_package_spec.rb +10 -13
  533. data/spec/unit/resource/link_spec.rb +25 -25
  534. data/spec/unit/resource/log_spec.rb +9 -9
  535. data/spec/unit/resource/macports_package_spec.rb +8 -13
  536. data/spec/unit/resource/mdadm_spec.rb +18 -18
  537. data/spec/unit/resource/mount_spec.rb +45 -45
  538. data/spec/unit/resource/ohai_spec.rb +7 -7
  539. data/spec/unit/resource/package_spec.rb +12 -12
  540. data/spec/unit/resource/pacman_package_spec.rb +8 -14
  541. data/spec/unit/resource/perl_spec.rb +4 -4
  542. data/spec/unit/resource/portage_package_spec.rb +3 -3
  543. data/spec/unit/resource/powershell_spec.rb +7 -7
  544. data/spec/unit/resource/python_spec.rb +4 -4
  545. data/spec/unit/resource/registry_key_spec.rb +32 -32
  546. data/spec/unit/resource/remote_directory_spec.rb +17 -17
  547. data/spec/unit/resource/remote_file_spec.rb +41 -41
  548. data/spec/unit/resource/route_spec.rb +19 -19
  549. data/spec/unit/resource/rpm_package_spec.rb +9 -13
  550. data/spec/unit/resource/ruby_block_spec.rb +8 -8
  551. data/spec/unit/resource/ruby_spec.rb +4 -4
  552. data/spec/unit/resource/scm_spec.rb +40 -40
  553. data/spec/unit/resource/script_spec.rb +2 -2
  554. data/spec/unit/resource/service_spec.rb +37 -47
  555. data/spec/unit/resource/smartos_package_spec.rb +10 -15
  556. data/spec/unit/resource/solaris_package_spec.rb +13 -28
  557. data/spec/unit/resource/subversion_spec.rb +16 -12
  558. data/spec/unit/resource/template_spec.rb +35 -35
  559. data/spec/unit/resource/timestamped_deploy_spec.rb +30 -4
  560. data/spec/unit/resource/user_spec.rb +23 -23
  561. data/spec/unit/resource/windows_package_spec.rb +17 -10
  562. data/spec/unit/resource/windows_service_spec.rb +9 -6
  563. data/spec/unit/resource/yum_package_spec.rb +16 -21
  564. data/spec/unit/resource_collection/resource_list_spec.rb +137 -0
  565. data/spec/unit/resource_collection/resource_set_spec.rb +199 -0
  566. data/spec/unit/resource_collection_spec.rb +73 -92
  567. data/spec/unit/resource_definition_spec.rb +38 -40
  568. data/spec/unit/resource_reporter_spec.rb +3 -3
  569. data/spec/unit/resource_spec.rb +68 -33
  570. data/spec/unit/rest_spec.rb +83 -76
  571. data/spec/unit/role_spec.rb +5 -0
  572. data/spec/unit/run_list_spec.rb +5 -1
  573. data/spec/unit/runner_spec.rb +245 -238
  574. data/spec/unit/shell/shell_ext_spec.rb +1 -1
  575. data/spec/unit/user_spec.rb +5 -1
  576. data/spec/unit/util/dsc/configuration_generator_spec.rb +171 -0
  577. data/spec/unit/util/dsc/lcm_output_parser_spec.rb +169 -0
  578. data/spec/unit/util/dsc/local_configuration_manager_spec.rb +139 -0
  579. data/spec/unit/util/path_helper_spec.rb +23 -1
  580. data/spec/unit/util/powershell/cmdlet_spec.rb +106 -0
  581. data/spec/unit/workstation_config_loader_spec.rb +1 -1
  582. metadata +303 -196
  583. checksums.yaml +0 -7
  584. data/distro/README +0 -2
  585. data/distro/arch/etc/conf.d/chef-client.conf +0 -5
  586. data/distro/arch/etc/conf.d/chef-expander.conf +0 -8
  587. data/distro/arch/etc/conf.d/chef-server-webui.conf +0 -10
  588. data/distro/arch/etc/conf.d/chef-server.conf +0 -10
  589. data/distro/arch/etc/conf.d/chef-solr.conf +0 -8
  590. data/distro/arch/etc/rc.d/chef-client +0 -90
  591. data/distro/arch/etc/rc.d/chef-expander +0 -78
  592. data/distro/arch/etc/rc.d/chef-server +0 -78
  593. data/distro/arch/etc/rc.d/chef-server-webui +0 -78
  594. data/distro/arch/etc/rc.d/chef-solr +0 -78
  595. data/distro/debian/etc/default/chef-client +0 -4
  596. data/distro/debian/etc/default/chef-expander +0 -8
  597. data/distro/debian/etc/default/chef-server +0 -9
  598. data/distro/debian/etc/default/chef-server-webui +0 -9
  599. data/distro/debian/etc/default/chef-solr +0 -8
  600. data/distro/debian/etc/init.d/chef-client +0 -212
  601. data/distro/debian/etc/init.d/chef-expander +0 -176
  602. data/distro/debian/etc/init.d/chef-server +0 -122
  603. data/distro/debian/etc/init.d/chef-server-webui +0 -123
  604. data/distro/debian/etc/init.d/chef-solr +0 -176
  605. data/distro/debian/etc/init/chef-client.conf +0 -17
  606. data/distro/debian/etc/init/chef-expander.conf +0 -17
  607. data/distro/debian/etc/init/chef-server-webui.conf +0 -17
  608. data/distro/debian/etc/init/chef-server.conf +0 -17
  609. data/distro/debian/etc/init/chef-solr.conf +0 -17
  610. data/distro/redhat/etc/init.d/chef-client +0 -121
  611. data/distro/redhat/etc/init.d/chef-expander +0 -104
  612. data/distro/redhat/etc/init.d/chef-server +0 -112
  613. data/distro/redhat/etc/init.d/chef-server-webui +0 -112
  614. data/distro/redhat/etc/init.d/chef-solr +0 -104
  615. data/distro/redhat/etc/logrotate.d/chef-client +0 -8
  616. data/distro/redhat/etc/logrotate.d/chef-expander +0 -8
  617. data/distro/redhat/etc/logrotate.d/chef-server +0 -8
  618. data/distro/redhat/etc/logrotate.d/chef-server-webui +0 -8
  619. data/distro/redhat/etc/logrotate.d/chef-solr +0 -8
  620. data/distro/redhat/etc/sysconfig/chef-client +0 -15
  621. data/distro/redhat/etc/sysconfig/chef-expander +0 -7
  622. data/distro/redhat/etc/sysconfig/chef-server +0 -14
  623. data/distro/redhat/etc/sysconfig/chef-server-webui +0 -14
  624. data/distro/redhat/etc/sysconfig/chef-solr +0 -8
  625. data/distro/windows/service_manager.rb +0 -20
  626. data/lib/chef/resource_platform_map.rb +0 -151
  627. data/spec/support/shared/matchers.rb +0 -17
  628. data/spec/unit/resource_platform_map_spec.rb +0 -164
@@ -29,9 +29,10 @@ describe Chef::Knife::Core::BootstrapContext do
29
29
  :validation_client_name => 'chef-validator-testing'
30
30
  }
31
31
  end
32
- let(:secret_file) { File.join(CHEF_SPEC_DATA, 'bootstrap', 'encrypted_data_bag_secret') }
33
32
 
34
- subject(:bootstrap_context) { described_class.new(config, run_list, chef_config) }
33
+ let(:secret) { nil }
34
+
35
+ subject(:bootstrap_context) { described_class.new(config, run_list, chef_config, secret) }
35
36
 
36
37
  it "runs chef with the first-boot.json in the _default environment" do
37
38
  bootstrap_context.start_chef.should eq "chef-client -j /etc/chef/first-boot.json -E _default"
@@ -94,50 +95,20 @@ EXPECTED
94
95
  describe "when JSON attributes are given" do
95
96
  let(:config) { {:first_boot_attributes => {:baz => :quux}} }
96
97
  it "adds the attributes to first_boot" do
97
- bootstrap_context.first_boot.to_json.should eq({:baz => :quux, :run_list => run_list}.to_json)
98
+ Chef::JSONCompat.to_json(bootstrap_context.first_boot).should eq(Chef::JSONCompat.to_json({:baz => :quux, :run_list => run_list}))
98
99
  end
99
100
  end
100
101
 
101
102
  describe "when JSON attributes are NOT given" do
102
103
  it "sets first_boot equal to run_list" do
103
- bootstrap_context.first_boot.to_json.should eq({:run_list => run_list}.to_json)
104
+ Chef::JSONCompat.to_json(bootstrap_context.first_boot).should eq(Chef::JSONCompat.to_json({:run_list => run_list}))
104
105
  end
105
106
  end
106
107
 
107
108
  describe "when an encrypted_data_bag_secret is provided" do
108
- context "via config[:secret]" do
109
- let(:chef_config) do
110
- {
111
- :knife => {:secret => "supersekret" }
112
- }
113
- end
114
- it "reads the encrypted_data_bag_secret" do
115
- bootstrap_context.encrypted_data_bag_secret.should eq "supersekret"
116
- end
117
- end
118
-
119
- context "via config[:secret_file]" do
120
- let(:chef_config) do
121
- {
122
- :knife => {:secret_file => secret_file}
123
- }
124
- end
125
- it "reads the encrypted_data_bag_secret" do
126
- bootstrap_context.encrypted_data_bag_secret.should eq IO.read(secret_file)
127
- end
128
- end
129
-
130
- context "via config[:secret_file] with short home path" do
131
- let(:chef_config) do
132
- home_path = File.expand_path("~")
133
- shorted_secret_file_path = secret_file.gsub(home_path, "~")
134
- {
135
- :knife => {:secret_file => shorted_secret_file_path}
136
- }
137
- end
138
- it "reads the encrypted_data_bag_secret" do
139
- bootstrap_context.encrypted_data_bag_secret.should eq IO.read(secret_file)
140
- end
109
+ let(:secret) { "supersekret" }
110
+ it "reads the encrypted_data_bag_secret" do
111
+ bootstrap_context.encrypted_data_bag_secret.should eq "supersekret"
141
112
  end
142
113
  end
143
114
 
@@ -20,7 +20,7 @@ require 'spec_helper'
20
20
 
21
21
  describe Chef::Knife::SubcommandLoader do
22
22
  before do
23
-
23
+ Chef::Platform.stub(:windows?) { false }
24
24
  @home = File.join(CHEF_SPEC_DATA, 'knife-home')
25
25
  @env = {'HOME' => @home}
26
26
  @loader = Chef::Knife::SubcommandLoader.new(File.join(CHEF_SPEC_DATA, 'knife-site-subcommands'), @env)
@@ -403,6 +403,34 @@ EOM
403
403
  @ui.format_cookbook_list_for_display(@item).should == response
404
404
  end
405
405
  end
406
+
407
+ context "when running on Windows" do
408
+ before(:each) do
409
+ stdout = double('StringIO', :tty? => true)
410
+ @ui.stub(:stdout).and_return(stdout)
411
+ Chef::Platform.stub(:windows?) { true }
412
+ Chef::Config.reset
413
+ end
414
+
415
+ after(:each) do
416
+ Chef::Config.reset
417
+ end
418
+
419
+ it "should have color set to true if knife config has color explicitly set to true" do
420
+ Chef::Config[:color] = true
421
+ @ui.config[:color] = true
422
+ expect(@ui.color?).to eql(true)
423
+ end
424
+
425
+ it "should have color set to false if knife config has color explicitly set to false" do
426
+ Chef::Config[:color] = false
427
+ expect(@ui.color?).to eql(false)
428
+ end
429
+
430
+ it "should not have color set to false by default" do
431
+ expect(@ui.color?).to eql(false)
432
+ end
433
+ end
406
434
  end
407
435
 
408
436
  describe "confirm" do
@@ -20,97 +20,89 @@
20
20
  require 'spec_helper'
21
21
  require 'tempfile'
22
22
 
23
- module ChefSpecs
24
- class ChefRest
25
- attr_reader :args_received
26
- def initialize
27
- @args_received = []
28
- end
29
-
30
- def post_rest(*args)
31
- @args_received << args
32
- end
23
+ describe Chef::Knife::DataBagCreate do
24
+ let(:knife) do
25
+ k = Chef::Knife::DataBagCreate.new
26
+ allow(k).to receive(:rest).and_return(rest)
27
+ allow(k.ui).to receive(:stdout).and_return(stdout)
28
+ k
33
29
  end
34
- end
35
30
 
31
+ let(:rest) { double("Chef::REST") }
32
+ let(:stdout) { StringIO.new }
36
33
 
37
- describe Chef::Knife::DataBagCreate do
38
- before do
39
- Chef::Config[:node_name] = "webmonkey.example.com"
40
- @knife = Chef::Knife::DataBagCreate.new
41
- @rest = ChefSpecs::ChefRest.new
42
- @knife.stub(:rest).and_return(@rest)
43
- @stdout = StringIO.new
44
- @knife.ui.stub(:stdout).and_return(@stdout)
45
- end
34
+ let(:bag_name) { "sudoing_admins" }
35
+ let(:item_name) { "ME" }
36
+
37
+ let(:secret) { "abc123SECRET" }
46
38
 
39
+ let(:raw_hash) {{ "login_name" => "alphaomega", "id" => item_name }}
47
40
 
48
- it "creates a data bag when given one argument" do
49
- @knife.name_args = ['sudoing_admins']
50
- @rest.should_receive(:post_rest).with("data", {"name" => "sudoing_admins"})
51
- @knife.ui.should_receive(:info).with("Created data_bag[sudoing_admins]")
41
+ let(:config) { {} }
52
42
 
53
- @knife.run
43
+ before do
44
+ Chef::Config[:node_name] = "webmonkey.example.com"
45
+ knife.name_args = [bag_name, item_name]
46
+ allow(knife).to receive(:config).and_return(config)
54
47
  end
55
48
 
56
49
  it "tries to create a data bag with an invalid name when given one argument" do
57
- @knife.name_args = ['invalid&char']
58
- @knife.should_receive(:exit).with(1)
59
-
60
- @knife.run
50
+ knife.name_args = ['invalid&char']
51
+ expect(Chef::DataBag).to receive(:validate_name!).with(knife.name_args[0]).and_raise(Chef::Exceptions::InvalidDataBagName)
52
+ expect {knife.run}.to exit_with_code(1)
61
53
  end
62
54
 
63
- it "creates a data bag item when given two arguments" do
64
- @knife.name_args = ['sudoing_admins', 'ME']
65
- user_supplied_hash = {"login_name" => "alphaomega", "id" => "ME"}
66
- data_bag_item = Chef::DataBagItem.from_hash(user_supplied_hash)
67
- data_bag_item.data_bag("sudoing_admins")
68
- @knife.should_receive(:create_object).and_yield(user_supplied_hash)
69
- @rest.should_receive(:post_rest).with("data", {'name' => 'sudoing_admins'}).ordered
70
- @rest.should_receive(:post_rest).with("data/sudoing_admins", data_bag_item).ordered
55
+ context "when given one argument" do
56
+ before do
57
+ knife.name_args = [bag_name]
58
+ end
59
+
60
+ it "creates a data bag" do
61
+ expect(rest).to receive(:post_rest).with("data", {"name" => bag_name})
62
+ expect(knife.ui).to receive(:info).with("Created data_bag[#{bag_name}]")
71
63
 
72
- @knife.run
64
+ knife.run
65
+ end
73
66
  end
74
67
 
75
- describe "encrypted data bag items" do
76
- before(:each) do
77
- @secret = "abc123SECRET"
78
- @plain_data = {"login_name" => "alphaomega", "id" => "ME"}
79
- @enc_data = Chef::EncryptedDataBagItem.encrypt_data_bag_item(@plain_data,
80
- @secret)
81
- @knife.name_args = ['sudoing_admins', 'ME']
82
- @knife.should_receive(:create_object).and_yield(@plain_data)
83
- data_bag_item = Chef::DataBagItem.from_hash(@enc_data)
84
- data_bag_item.data_bag("sudoing_admins")
85
-
86
- # Random IV is used each time the data bag item is encrypted, so values
87
- # will not be equal if we re-encrypt.
88
- Chef::EncryptedDataBagItem.should_receive(:encrypt_data_bag_item).and_return(@enc_data)
89
-
90
- @rest.should_receive(:post_rest).with("data", {'name' => 'sudoing_admins'}).ordered
91
- @rest.should_receive(:post_rest).with("data/sudoing_admins", data_bag_item).ordered
92
-
93
- @secret_file = Tempfile.new("encrypted_data_bag_secret_file_test")
94
- @secret_file.puts(@secret)
95
- @secret_file.flush
68
+ context "no secret is specified for encryption" do
69
+ let(:item) do
70
+ item = Chef::DataBagItem.from_hash(raw_hash)
71
+ item.data_bag(bag_name)
72
+ item
96
73
  end
97
74
 
98
- after do
99
- @secret_file.close
100
- @secret_file.unlink
75
+ it "creates a data bag item" do
76
+ expect(knife).to receive(:create_object).and_yield(raw_hash)
77
+ expect(knife).to receive(:encryption_secret_provided?).and_return(false)
78
+ expect(rest).to receive(:post_rest).with("data", {'name' => bag_name}).ordered
79
+ expect(rest).to receive(:post_rest).with("data/#{bag_name}", item).ordered
80
+
81
+ knife.run
101
82
  end
83
+ end
84
+
85
+ context "a secret is specified for encryption" do
86
+ let(:encoded_data) { Chef::EncryptedDataBagItem.encrypt_data_bag_item(raw_hash, secret) }
102
87
 
103
- it "creates an encrypted data bag item via --secret" do
104
- @knife.stub(:config).and_return({:secret => @secret})
105
- @knife.run
88
+ let(:item) do
89
+ item = Chef::DataBagItem.from_hash(encoded_data)
90
+ item.data_bag(bag_name)
91
+ item
106
92
  end
107
93
 
108
- it "creates an encrypted data bag item via --secret_file" do
109
- secret_file = Tempfile.new("encrypted_data_bag_secret_file_test")
110
- secret_file.puts(@secret)
111
- secret_file.flush
112
- @knife.stub(:config).and_return({:secret_file => secret_file.path})
113
- @knife.run
94
+ it "creates an encrypted data bag item" do
95
+ expect(knife).to receive(:create_object).and_yield(raw_hash)
96
+ expect(knife).to receive(:encryption_secret_provided?).and_return(true)
97
+ expect(knife).to receive(:read_secret).and_return(secret)
98
+ expect(Chef::EncryptedDataBagItem)
99
+ .to receive(:encrypt_data_bag_item)
100
+ .with(raw_hash, secret)
101
+ .and_return(encoded_data)
102
+ expect(rest).to receive(:post_rest).with("data", {"name" => bag_name}).ordered
103
+ expect(rest).to receive(:post_rest).with("data/#{bag_name}", item).ordered
104
+
105
+ knife.run
114
106
  end
115
107
  end
116
108
 
@@ -21,73 +21,107 @@ require 'tempfile'
21
21
 
22
22
  describe Chef::Knife::DataBagEdit do
23
23
  before do
24
- @plain_data = {"login_name" => "alphaomega", "id" => "item_name"}
25
- @edited_data = {
26
- "login_name" => "rho", "id" => "item_name",
27
- "new_key" => "new_value" }
24
+ Chef::Config[:node_name] = "webmonkey.example.com"
25
+ knife.name_args = [bag_name, item_name]
26
+ allow(knife).to receive(:config).and_return(config)
27
+ end
28
+
29
+ let(:knife) do
30
+ k = Chef::Knife::DataBagEdit.new
31
+ allow(k).to receive(:rest).and_return(rest)
32
+ allow(k.ui).to receive(:stdout).and_return(stdout)
33
+ k
34
+ end
35
+
36
+ let(:raw_hash) { {"login_name" => "alphaomega", "id" => "item_name"} }
37
+ let(:db) { Chef::DataBagItem.from_hash(raw_hash)}
38
+ let(:raw_edited_hash) { {"login_name" => "rho", "id" => "item_name", "new_key" => "new_value"} }
39
+
40
+ let(:rest) { double("Chef::REST") }
41
+ let(:stdout) { StringIO.new }
28
42
 
29
- Chef::Config[:node_name] = "webmonkey.example.com"
43
+ let(:bag_name) { "sudoing_admins" }
44
+ let(:item_name) { "ME" }
30
45
 
31
- @knife = Chef::Knife::DataBagEdit.new
32
- @rest = double('chef-rest-mock')
33
- @knife.stub(:rest).and_return(@rest)
46
+ let(:secret) { "abc123SECRET" }
34
47
 
35
- @stdout = StringIO.new
36
- @knife.stub(:stdout).and_return(@stdout)
37
- @log = Chef::Log
38
- @knife.name_args = ['bag_name', 'item_name']
48
+ let(:config) { {} }
49
+
50
+ let(:is_encrypted?) { false }
51
+ let(:transmitted_hash) { raw_edited_hash }
52
+ let(:data_to_edit) { db }
53
+
54
+ shared_examples_for "editing a data bag" do
55
+ it "correctly edits then uploads the data bag" do
56
+ expect(Chef::DataBagItem).to receive(:load).with(bag_name, item_name).and_return(db)
57
+ expect(knife).to receive(:encrypted?).with(db.raw_data).and_return(is_encrypted?)
58
+ expect(knife).to receive(:edit_data).with(data_to_edit).and_return(raw_edited_hash)
59
+ expect(rest).to receive(:put_rest).with("data/#{bag_name}/#{item_name}", transmitted_hash).ordered
60
+
61
+ knife.run
62
+ end
39
63
  end
40
64
 
41
65
  it "requires data bag and item arguments" do
42
- @knife.name_args = []
43
- lambda { @knife.run }.should raise_error(SystemExit)
44
- @stdout.string.should match(/^You must supply the data bag and an item to edit/)
66
+ knife.name_args = []
67
+ expect(stdout).to receive(:puts).twice.with(anything)
68
+ expect {knife.run}.to exit_with_code(1)
69
+ expect(stdout.string).to eq("")
45
70
  end
46
71
 
47
- it "saves edits on a data bag item" do
48
- Chef::DataBagItem.stub(:load).with('bag_name', 'item_name').and_return(@plain_data)
49
- @knife.should_receive(:edit_data).with(@plain_data).and_return(@edited_data)
50
- @rest.should_receive(:put_rest).with("data/bag_name/item_name", @edited_data).ordered
51
- @knife.run
72
+ context "when no secret is provided" do
73
+ include_examples "editing a data bag"
52
74
  end
53
75
 
54
- describe "encrypted data bag items" do
55
- before(:each) do
56
- @secret = "abc123SECRET"
57
- @enc_data = Chef::EncryptedDataBagItem.encrypt_data_bag_item(@plain_data,
58
- @secret)
59
- @enc_edited_data = Chef::EncryptedDataBagItem.encrypt_data_bag_item(@edited_data,
60
- @secret)
61
- Chef::DataBagItem.stub(:load).with('bag_name', 'item_name').and_return(@enc_data)
62
-
63
- # Random IV is used each time the data bag item is encrypted, so values
64
- # will not be equal if we encrypt same value twice.
65
- Chef::EncryptedDataBagItem.should_receive(:encrypt_data_bag_item).and_return(@enc_edited_data)
66
-
67
- @secret_file = Tempfile.new("encrypted_data_bag_secret_file_test")
68
- @secret_file.puts(@secret)
69
- @secret_file.flush
76
+ context "when config[:print_after] is set" do
77
+ let(:config) { {:print_after => true} }
78
+ before do
79
+ expect(knife.ui).to receive(:output).with(raw_edited_hash)
70
80
  end
71
81
 
72
- after do
73
- @secret_file.close
74
- @secret_file.unlink
82
+ include_examples "editing a data bag"
83
+ end
84
+
85
+ context "when a secret is provided" do
86
+ let!(:enc_raw_hash) { Chef::EncryptedDataBagItem.encrypt_data_bag_item(raw_hash, secret) }
87
+ let!(:enc_edited_hash) { Chef::EncryptedDataBagItem.encrypt_data_bag_item(raw_edited_hash, secret) }
88
+ let(:transmitted_hash) { enc_edited_hash }
89
+
90
+ before(:each) do
91
+ expect(knife).to receive(:read_secret).at_least(1).times.and_return(secret)
92
+ expect(Chef::EncryptedDataBagItem).to receive(:encrypt_data_bag_item).with(raw_edited_hash, secret).and_return(enc_edited_hash)
75
93
  end
76
94
 
77
- it "decrypts and encrypts via --secret" do
78
- @knife.stub(:config).and_return({:secret => @secret})
79
- @knife.should_receive(:edit_data).with(@plain_data).and_return(@edited_data)
80
- @rest.should_receive(:put_rest).with("data/bag_name/item_name", @enc_edited_data).ordered
95
+ context "the data bag starts encrypted" do
96
+ let(:is_encrypted?) { true }
97
+ let(:db) { Chef::DataBagItem.from_hash(enc_raw_hash) }
98
+ # If the data bag is encrypted, it gets passed to `edit` as a hash. Otherwise, it gets passed as a DataBag
99
+ let (:data_to_edit) { raw_hash }
100
+
101
+ before(:each) do
102
+ expect(knife).to receive(:encryption_secret_provided_ignore_encrypt_flag?).and_return(true)
103
+ end
81
104
 
82
- @knife.run
105
+ include_examples "editing a data bag"
83
106
  end
84
107
 
85
- it "decrypts and encrypts via --secret_file" do
86
- @knife.stub(:config).and_return({:secret_file => @secret_file.path})
87
- @knife.should_receive(:edit_data).with(@plain_data).and_return(@edited_data)
88
- @rest.should_receive(:put_rest).with("data/bag_name/item_name", @enc_edited_data).ordered
108
+ context "the data bag starts unencrypted" do
109
+ before(:each) do
110
+ expect(knife).to receive(:encryption_secret_provided_ignore_encrypt_flag?).exactly(0).times
111
+ expect(knife).to receive(:encryption_secret_provided?).and_return(true)
112
+ end
89
113
 
90
- @knife.run
114
+ include_examples "editing a data bag"
91
115
  end
92
116
  end
117
+
118
+ it "fails to edit an encrypted data bag if the secret is missing" do
119
+ expect(Chef::DataBagItem).to receive(:load).with(bag_name, item_name).and_return(db)
120
+ expect(knife).to receive(:encrypted?).with(db.raw_data).and_return(true)
121
+ expect(knife).to receive(:encryption_secret_provided_ignore_encrypt_flag?).and_return(false)
122
+
123
+ expect(knife.ui).to receive(:fatal).with("You cannot edit an encrypted data bag without providing the secret.")
124
+ expect {knife.run}.to exit_with_code(1)
125
+ end
126
+
93
127
  end
@@ -26,168 +26,146 @@ Chef::Knife::DataBagFromFile.load_deps
26
26
 
27
27
  describe Chef::Knife::DataBagFromFile do
28
28
  before :each do
29
- Chef::Config[:node_name] = "webmonkey.example.com"
30
- @knife = Chef::Knife::DataBagFromFile.new
31
- @rest = double("Chef::REST")
32
- @knife.stub(:rest).and_return(@rest)
33
- @stdout = StringIO.new
34
- @knife.ui.stub(:stdout).and_return(@stdout)
35
- @tmp_dir = Dir.mktmpdir
36
- @db_folder = File.join(@tmp_dir, 'data_bags', 'bag_name')
37
- FileUtils.mkdir_p(@db_folder)
38
- @db_file = Tempfile.new(["data_bag_from_file_test", ".json"], @db_folder)
39
- @db_file2 = Tempfile.new(["data_bag_from_file_test2", ".json"], @db_folder)
40
- @db_folder2 = File.join(@tmp_dir, 'data_bags', 'bag_name2')
41
- FileUtils.mkdir_p(@db_folder2)
42
- @db_file3 = Tempfile.new(["data_bag_from_file_test3", ".json"], @db_folder2)
43
- @plain_data = {
44
- "id" => "item_name",
45
- "greeting" => "hello",
46
- "nested" => { "a1" => [1, 2, 3], "a2" => { "b1" => true }}
47
- }
48
- @db_file.write(@plain_data.to_json)
49
- @db_file.flush
50
- @knife.instance_variable_set(:@name_args, ['bag_name', @db_file.path])
29
+ Chef::Platform.stub(:windows?) { false }
30
+ Chef::Config[:node_name] = "webmonkey.example.com"
31
+ FileUtils.mkdir_p([db_folder, db_folder2])
32
+ db_file.write(Chef::JSONCompat.to_json(plain_data))
33
+ db_file.flush
34
+ allow(knife).to receive(:config).and_return(config)
35
+ allow(Chef::Knife::Core::ObjectLoader).to receive(:new).and_return(loader)
51
36
  end
52
37
 
53
38
  # We have to explicitly clean up Tempfile on Windows because it said so.
54
39
  after :each do
55
- @db_file.close
56
- @db_file2.close
57
- @db_file3.close
58
- FileUtils.rm_rf(@db_folder)
59
- FileUtils.rm_rf(@db_folder2)
60
- FileUtils.remove_entry_secure @tmp_dir
40
+ db_file.close
41
+ db_file2.close
42
+ db_file3.close
43
+ FileUtils.rm_rf(db_folder)
44
+ FileUtils.rm_rf(db_folder2)
45
+ FileUtils.remove_entry_secure tmp_dir
61
46
  end
62
47
 
48
+ let(:knife) do
49
+ k = Chef::Knife::DataBagFromFile.new
50
+ allow(k).to receive(:rest).and_return(rest)
51
+ allow(k.ui).to receive(:stdout).and_return(stdout)
52
+ k
53
+ end
54
+
55
+ let(:tmp_dir) { Dir.mktmpdir }
56
+ let(:db_folder) { File.join(tmp_dir, data_bags_path, bag_name) }
57
+ let(:db_file) { Tempfile.new(["data_bag_from_file_test", ".json"], db_folder) }
58
+ let(:db_file2) { Tempfile.new(["data_bag_from_file_test2", ".json"], db_folder) }
59
+ let(:db_folder2) { File.join(tmp_dir, data_bags_path, bag_name2) }
60
+ let(:db_file3) { Tempfile.new(["data_bag_from_file_test3", ".json"], db_folder2) }
61
+
62
+ def new_bag_expects(b = bag_name, d = plain_data)
63
+ data_bag = double
64
+ expect(data_bag).to receive(:data_bag).with(b)
65
+ expect(data_bag).to receive(:raw_data=).with(d)
66
+ expect(data_bag).to receive(:save)
67
+ expect(data_bag).to receive(:data_bag)
68
+ expect(data_bag).to receive(:id)
69
+ data_bag
70
+ end
71
+
72
+ let(:loader) { double("Knife::Core::ObjectLoader") }
73
+
74
+ let(:data_bags_path) { "data_bags" }
75
+ let(:plain_data) { {
76
+ "id" => "item_name",
77
+ "greeting" => "hello",
78
+ "nested" => { "a1" => [1, 2, 3], "a2" => { "b1" => true }}
79
+ } }
80
+ let(:enc_data) { Chef::EncryptedDataBagItem.encrypt_data_bag_item(plain_data, secret) }
81
+
82
+ let(:rest) { double("Chef::REST") }
83
+ let(:stdout) { StringIO.new }
84
+
85
+ let(:bag_name) { "sudoing_admins" }
86
+ let(:bag_name2) { "sudoing_admins2" }
87
+ let(:item_name) { "ME" }
88
+
89
+ let(:secret) { "abc123SECRET" }
90
+
91
+ let(:config) { {} }
92
+
63
93
  it "loads from a file and saves" do
64
- @knife.loader.should_receive(:load_from).with("data_bags", 'bag_name', @db_file.path).and_return(@plain_data)
65
- dbag = Chef::DataBagItem.new
66
- Chef::DataBagItem.stub(:new).and_return(dbag)
67
- dbag.should_receive(:save)
68
- @knife.run
69
-
70
- dbag.data_bag.should == 'bag_name'
71
- dbag.raw_data.should == @plain_data
94
+ knife.name_args = [bag_name, db_file.path]
95
+ expect(loader).to receive(:load_from).with(data_bags_path, bag_name, db_file.path).and_return(plain_data)
96
+ expect(Chef::DataBagItem).to receive(:new).and_return(new_bag_expects)
97
+
98
+ knife.run
72
99
  end
73
100
 
74
- it "loads all from a mutiple files and saves" do
75
- @knife.name_args = [ 'bag_name', @db_file.path, @db_file2.path ]
76
- @knife.loader.should_receive(:load_from).with("data_bags", 'bag_name', @db_file.path).and_return(@plain_data)
77
- @knife.loader.should_receive(:load_from).with("data_bags", 'bag_name', @db_file2.path).and_return(@plain_data)
78
- dbag = Chef::DataBagItem.new
79
- Chef::DataBagItem.stub(:new).and_return(dbag)
80
- dbag.should_receive(:save).twice
81
- @knife.run
82
-
83
- dbag.data_bag.should == 'bag_name'
84
- dbag.raw_data.should == @plain_data
101
+ it "loads all from multiple files and saves" do
102
+ knife.name_args = [ bag_name, db_file.path, db_file2.path ]
103
+ expect(loader).to receive(:load_from).with(data_bags_path, bag_name, db_file.path).and_return(plain_data)
104
+ expect(loader).to receive(:load_from).with(data_bags_path, bag_name, db_file2.path).and_return(plain_data)
105
+ expect(Chef::DataBagItem).to receive(:new).twice.and_return(new_bag_expects, new_bag_expects)
106
+
107
+ knife.run
85
108
  end
86
109
 
87
110
  it "loads all from a folder and saves" do
88
- @knife.name_args = [ 'bag_name', @db_folder ]
89
- @knife.loader.should_receive(:load_from).with("data_bags", 'bag_name', @db_file.path).and_return(@plain_data)
90
- @knife.loader.should_receive(:load_from).with("data_bags", 'bag_name', @db_file2.path).and_return(@plain_data)
91
- dbag = Chef::DataBagItem.new
92
- Chef::DataBagItem.stub(:new).and_return(dbag)
93
- dbag.should_receive(:save).twice
94
- @knife.run
111
+ knife.name_args = [ bag_name, db_folder ]
112
+ expect(loader).to receive(:load_from).with(data_bags_path, bag_name, db_file.path).and_return(plain_data)
113
+ expect(loader).to receive(:load_from).with(data_bags_path, bag_name, db_file2.path).and_return(plain_data)
114
+ expect(Chef::DataBagItem).to receive(:new).twice.and_return(new_bag_expects, new_bag_expects)
115
+
116
+ knife.run
95
117
  end
96
118
 
97
119
  describe "loading all data bags" do
98
120
 
99
- before do
100
- @pwd = Dir.pwd
101
- Dir.chdir(@tmp_dir)
102
- end
103
-
104
- after do
105
- Dir.chdir(@pwd)
106
- end
107
-
108
121
  it "loads all data bags when -a or --all options is provided" do
109
- @knife.name_args = []
110
- @knife.stub(:config).and_return({:all => true})
111
- @knife.loader.should_receive(:load_from).with("data_bags", "bag_name", File.basename(@db_file.path)).
112
- and_return(@plain_data)
113
- @knife.loader.should_receive(:load_from).with("data_bags", "bag_name", File.basename(@db_file2.path)).
114
- and_return(@plain_data)
115
- @knife.loader.should_receive(:load_from).with("data_bags", "bag_name2", File.basename(@db_file3.path)).
116
- and_return(@plain_data)
117
- dbag = Chef::DataBagItem.new
118
- Chef::DataBagItem.stub(:new).and_return(dbag)
119
- dbag.should_receive(:save).exactly(3).times
120
- @knife.run
122
+ knife.name_args = []
123
+ config[:all] = true
124
+ expect(loader).to receive(:find_all_object_dirs).with("./#{data_bags_path}").and_return([bag_name, bag_name2])
125
+ expect(loader).to receive(:find_all_objects).with("./#{data_bags_path}/#{bag_name}").and_return([File.basename(db_file.path), File.basename(db_file2.path)])
126
+ expect(loader).to receive(:find_all_objects).with("./#{data_bags_path}/#{bag_name2}").and_return([File.basename(db_file3.path)])
127
+ expect(loader).to receive(:load_from).with(data_bags_path, bag_name, File.basename(db_file.path)).and_return(plain_data)
128
+ expect(loader).to receive(:load_from).with(data_bags_path, bag_name, File.basename(db_file2.path)).and_return(plain_data)
129
+ expect(loader).to receive(:load_from).with(data_bags_path, bag_name2, File.basename(db_file3.path)).and_return(plain_data)
130
+ expect(Chef::DataBagItem).to receive(:new).exactly(3).times.and_return(new_bag_expects, new_bag_expects, new_bag_expects(bag_name2))
131
+
132
+ knife.run
121
133
  end
122
134
 
123
135
  it "loads all data bags items when -a or --all options is provided" do
124
- @knife.name_args = ["bag_name2"]
125
- @knife.stub(:config).and_return({:all => true})
126
- @knife.loader.should_receive(:load_from).with("data_bags", "bag_name2", File.basename(@db_file3.path)).
127
- and_return(@plain_data)
128
- dbag = Chef::DataBagItem.new
129
- Chef::DataBagItem.stub(:new).and_return(dbag)
130
- dbag.should_receive(:save)
131
- @knife.run
132
- dbag.data_bag.should == 'bag_name2'
133
- dbag.raw_data.should == @plain_data
136
+ knife.name_args = [bag_name2]
137
+ config[:all] = true
138
+ expect(loader).to receive(:find_all_objects).with("./#{data_bags_path}/#{bag_name2}").and_return([File.basename(db_file3.path)])
139
+ expect(loader).to receive(:load_from).with(data_bags_path, bag_name2, File.basename(db_file3.path)).and_return(plain_data)
140
+ expect(Chef::DataBagItem).to receive(:new).and_return(new_bag_expects(bag_name2))
141
+
142
+ knife.run
134
143
  end
135
144
 
136
145
  end
137
146
 
138
147
  describe "encrypted data bag items" do
139
148
  before(:each) do
140
- @secret = "abc123SECRET"
141
- @enc_data = Chef::EncryptedDataBagItem.encrypt_data_bag_item(@plain_data,
142
- @secret)
143
-
144
- # Random IV is used each time the data bag item is encrypted, so values
145
- # will not be equal if we re-encrypt.
146
- Chef::EncryptedDataBagItem.should_receive(:encrypt_data_bag_item).and_return(@enc_data)
147
-
148
- @secret_file = Tempfile.new("encrypted_data_bag_secret_file_test")
149
- @secret_file.puts(@secret)
150
- @secret_file.flush
151
- end
152
-
153
- after do
154
- @secret_file.close
155
- @secret_file.unlink
149
+ expect(knife).to receive(:encryption_secret_provided?).and_return(true)
150
+ expect(knife).to receive(:read_secret).and_return(secret)
151
+ expect(Chef::EncryptedDataBagItem).to receive(:encrypt_data_bag_item).with(plain_data, secret).and_return(enc_data)
156
152
  end
157
153
 
158
154
  it "encrypts values when given --secret" do
159
- @knife.stub(:config).and_return({:secret => @secret})
160
-
161
- @knife.loader.should_receive(:load_from).with("data_bags", "bag_name", @db_file.path).and_return(@plain_data)
162
- dbag = Chef::DataBagItem.new
163
- Chef::DataBagItem.stub(:new).and_return(dbag)
164
- dbag.should_receive(:save)
165
- @knife.run
166
- dbag.data_bag.should == 'bag_name'
167
- dbag.raw_data.should == @enc_data
168
- end
169
-
170
- it "encrypts values when given --secret_file" do
171
- @knife.stub(:config).and_return({:secret_file => @secret_file.path})
155
+ knife.name_args = [bag_name, db_file.path]
156
+ expect(loader).to receive(:load_from).with(data_bags_path, bag_name, db_file.path).and_return(plain_data)
157
+ expect(Chef::DataBagItem).to receive(:new).and_return(new_bag_expects(bag_name, enc_data))
172
158
 
173
- @knife.loader.stub(:load_from).with("data_bags", 'bag_name', @db_file.path).and_return(@plain_data)
174
- dbag = Chef::DataBagItem.new
175
- Chef::DataBagItem.stub(:new).and_return(dbag)
176
- dbag.should_receive(:save)
177
- @knife.run
178
- dbag.data_bag.should == 'bag_name'
179
- dbag.raw_data.should == @enc_data
159
+ knife.run
180
160
  end
181
161
 
182
162
  end
183
163
 
184
164
  describe "command line parsing" do
185
165
  it "prints help if given no arguments" do
186
- @knife.instance_variable_set(:@name_args, [])
187
- lambda { @knife.run }.should raise_error(SystemExit)
188
- help_text = "knife data bag from file BAG FILE|FOLDER [FILE|FOLDER..] (options)"
189
- help_text_regex = Regexp.new("^#{Regexp.escape(help_text)}")
190
- @stdout.string.should match(help_text_regex)
166
+ knife.name_args = [bag_name]
167
+ expect {knife.run}.to exit_with_code(1)
168
+ expect(stdout.string).to start_with("knife data bag from file BAG FILE|FOLDER [FILE|FOLDER..] (options)")
191
169
  end
192
170
  end
193
171