chef 12.0.3-x86-mingw32 → 12.1.0.rc.0-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (653) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +4 -1
  3. data/README.md +42 -18
  4. data/distro/common/html/_sources/ctl_chef_client.txt +1 -1
  5. data/distro/common/html/_sources/ctl_chef_server.txt +53 -35
  6. data/distro/common/html/_sources/ctl_chef_solo.txt +1 -1
  7. data/distro/common/html/_sources/knife_bootstrap.txt +1 -1
  8. data/distro/common/html/_sources/knife_cookbook_site.txt +1 -1
  9. data/distro/common/html/_sources/knife_data_bag.txt +4 -4
  10. data/distro/common/html/_sources/knife_status.txt +1 -1
  11. data/distro/common/html/_static/searchtools.js +1 -1
  12. data/distro/common/html/ctl_chef_client.html +55 -7
  13. data/distro/common/html/ctl_chef_server.html +84 -41
  14. data/distro/common/html/ctl_chef_shell.html +45 -1
  15. data/distro/common/html/ctl_chef_solo.html +51 -5
  16. data/distro/common/html/index.html +2 -2
  17. data/distro/common/html/knife.html +1 -1
  18. data/distro/common/html/knife_bootstrap.html +30 -10
  19. data/distro/common/html/knife_cookbook_site.html +2 -0
  20. data/distro/common/html/knife_data_bag.html +4 -4
  21. data/distro/common/html/knife_node.html +2 -2
  22. data/distro/common/html/knife_raw.html +1 -1
  23. data/distro/common/html/knife_role.html +1 -1
  24. data/distro/common/html/knife_search.html +3 -3
  25. data/distro/common/html/knife_status.html +4 -0
  26. data/distro/common/html/searchindex.js +1 -1
  27. data/distro/common/man/man1/chef-shell.1 +72 -1
  28. data/distro/common/man/man1/knife-bootstrap.1 +71 -63
  29. data/distro/common/man/man1/knife-client.1 +1 -1
  30. data/distro/common/man/man1/knife-configure.1 +1 -1
  31. data/distro/common/man/man1/knife-cookbook-site.1 +4 -1
  32. data/distro/common/man/man1/knife-cookbook.1 +1 -1
  33. data/distro/common/man/man1/knife-data-bag.1 +5 -5
  34. data/distro/common/man/man1/knife-delete.1 +1 -1
  35. data/distro/common/man/man1/knife-deps.1 +1 -1
  36. data/distro/common/man/man1/knife-diff.1 +1 -1
  37. data/distro/common/man/man1/knife-download.1 +1 -1
  38. data/distro/common/man/man1/knife-edit.1 +1 -1
  39. data/distro/common/man/man1/knife-environment.1 +1 -1
  40. data/distro/common/man/man1/knife-exec.1 +1 -1
  41. data/distro/common/man/man1/knife-index-rebuild.1 +1 -1
  42. data/distro/common/man/man1/knife-list.1 +1 -1
  43. data/distro/common/man/man1/knife-node.1 +3 -3
  44. data/distro/common/man/man1/knife-raw.1 +2 -2
  45. data/distro/common/man/man1/knife-recipe-list.1 +1 -1
  46. data/distro/common/man/man1/knife-role.1 +2 -2
  47. data/distro/common/man/man1/knife-search.1 +4 -4
  48. data/distro/common/man/man1/knife-serve.1 +1 -1
  49. data/distro/common/man/man1/knife-show.1 +1 -1
  50. data/distro/common/man/man1/knife-ssh.1 +1 -1
  51. data/distro/common/man/man1/knife-ssl-check.1 +1 -1
  52. data/distro/common/man/man1/knife-ssl-fetch.1 +1 -1
  53. data/distro/common/man/man1/knife-status.1 +1 -1
  54. data/distro/common/man/man1/knife-tag.1 +1 -1
  55. data/distro/common/man/man1/knife-upload.1 +1 -1
  56. data/distro/common/man/man1/knife-user.1 +1 -1
  57. data/distro/common/man/man1/knife-xargs.1 +1 -1
  58. data/distro/common/man/man1/knife.1 +1 -1
  59. data/distro/common/man/man8/chef-apply.8 +86 -0
  60. data/distro/common/man/man8/chef-client.8 +76 -5
  61. data/distro/common/man/man8/chef-solo.8 +79 -6
  62. data/distro/common/markdown/man1/knife-bootstrap.mkd +1 -1
  63. data/distro/common/markdown/man1/knife-cookbook-site.mkd +1 -1
  64. data/distro/common/markdown/man1/knife-data-bag.mkd +1 -1
  65. data/distro/common/markdown/man1/knife-environment.mkd +1 -1
  66. data/distro/common/markdown/man1/knife.mkd +1 -1
  67. data/lib/chef.rb +0 -7
  68. data/lib/chef/api_client.rb +10 -2
  69. data/lib/chef/api_client/registration.rb +7 -9
  70. data/lib/chef/application.rb +28 -12
  71. data/lib/chef/application/apply.rb +17 -1
  72. data/lib/chef/application/client.rb +74 -6
  73. data/lib/chef/application/knife.rb +1 -2
  74. data/lib/chef/application/solo.rb +30 -0
  75. data/lib/chef/application/windows_service.rb +1 -0
  76. data/lib/chef/application/windows_service_manager.rb +8 -2
  77. data/lib/chef/applications.rb +0 -1
  78. data/lib/chef/audit/audit_event_proxy.rb +93 -0
  79. data/lib/chef/audit/audit_reporter.rb +169 -0
  80. data/lib/chef/audit/control_group_data.rb +140 -0
  81. data/lib/chef/audit/rspec_formatter.rb +37 -0
  82. data/lib/chef/audit/runner.rb +178 -0
  83. data/lib/chef/chef_fs/chef_fs_data_store.rb +11 -2
  84. data/lib/chef/chef_fs/config.rb +25 -4
  85. data/lib/chef/chef_fs/data_handler/policy_data_handler.rb +15 -0
  86. data/lib/chef/chef_fs/data_handler/user_data_handler.rb +1 -0
  87. data/lib/chef/chef_fs/file_system.rb +1 -1
  88. data/lib/chef/chef_fs/file_system/base_fs_dir.rb +5 -0
  89. data/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbook_entry.rb +3 -2
  90. data/lib/chef/{shef/ext.rb → chef_fs/file_system/chef_repository_file_system_policies_dir.rb} +22 -3
  91. data/lib/chef/chef_fs/file_system/chef_repository_file_system_root_dir.rb +4 -0
  92. data/lib/chef/client.rb +81 -52
  93. data/lib/chef/config.rb +35 -3
  94. data/lib/chef/cookbook/metadata.rb +3 -3
  95. data/lib/chef/cookbook_manifest.rb +275 -0
  96. data/lib/chef/cookbook_site_streaming_uploader.rb +24 -23
  97. data/lib/chef/cookbook_uploader.rb +11 -2
  98. data/lib/chef/cookbook_version.rb +71 -194
  99. data/lib/chef/data_bag.rb +5 -2
  100. data/lib/chef/data_bag_item.rb +6 -3
  101. data/lib/chef/deprecation/warnings.rb +5 -4
  102. data/lib/chef/dsl/audit.rb +51 -0
  103. data/lib/chef/dsl/include_recipe.rb +2 -3
  104. data/lib/chef/dsl/reboot_pending.rb +1 -1
  105. data/lib/chef/dsl/recipe.rb +49 -31
  106. data/lib/chef/encrypted_data_bag_item/assertions.rb +0 -3
  107. data/lib/chef/environment.rb +5 -2
  108. data/lib/chef/event_dispatch/base.rb +36 -1
  109. data/lib/chef/event_dispatch/dispatcher.rb +3 -5
  110. data/lib/chef/exceptions.rb +61 -2
  111. data/lib/chef/file_access_control/unix.rb +12 -0
  112. data/lib/chef/file_access_control/windows.rb +14 -0
  113. data/lib/chef/formatters/doc.rb +47 -1
  114. data/{spec/unit/monkey_patches/string_spec.rb → lib/chef/guard_interpreter.rb} +11 -16
  115. data/lib/chef/guard_interpreter/resource_guard_interpreter.rb +3 -2
  116. data/lib/chef/http.rb +1 -2
  117. data/lib/chef/knife.rb +5 -3
  118. data/lib/chef/knife/bootstrap.rb +84 -15
  119. data/lib/chef/knife/bootstrap/chef_vault_handler.rb +165 -0
  120. data/lib/chef/knife/bootstrap/client_builder.rb +190 -0
  121. data/lib/chef/knife/bootstrap/{README.md → templates/README.md} +0 -0
  122. data/lib/chef/knife/bootstrap/{archlinux-gems.erb → templates/archlinux-gems.erb} +9 -0
  123. data/lib/chef/knife/bootstrap/{chef-aix.erb → templates/chef-aix.erb} +9 -0
  124. data/lib/chef/knife/bootstrap/{chef-full.erb → templates/chef-full.erb} +10 -1
  125. data/lib/chef/knife/client_create.rb +8 -7
  126. data/lib/chef/knife/cookbook_site_download.rb +1 -1
  127. data/lib/chef/knife/cookbook_site_install.rb +1 -1
  128. data/lib/chef/knife/cookbook_site_list.rb +1 -1
  129. data/lib/chef/knife/cookbook_site_search.rb +1 -1
  130. data/lib/chef/knife/cookbook_site_share.rb +39 -28
  131. data/lib/chef/knife/cookbook_site_show.rb +3 -3
  132. data/lib/chef/knife/cookbook_site_unshare.rb +1 -1
  133. data/lib/chef/knife/cookbook_test.rb +1 -0
  134. data/lib/chef/knife/cookbook_upload.rb +13 -8
  135. data/lib/chef/knife/core/bootstrap_context.rb +14 -3
  136. data/lib/chef/knife/core/generic_presenter.rb +5 -2
  137. data/lib/chef/knife/core/object_loader.rb +1 -1
  138. data/lib/chef/knife/core/subcommand_loader.rb +24 -0
  139. data/lib/chef/knife/core/ui.rb +9 -1
  140. data/lib/chef/knife/node_run_list_remove.rb +11 -3
  141. data/lib/chef/knife/raw.rb +14 -3
  142. data/lib/chef/knife/role_env_run_list_add.rb +86 -0
  143. data/lib/chef/knife/role_env_run_list_clear.rb +55 -0
  144. data/lib/chef/knife/role_env_run_list_remove.rb +57 -0
  145. data/lib/chef/knife/role_env_run_list_replace.rb +59 -0
  146. data/lib/chef/knife/role_env_run_list_set.rb +70 -0
  147. data/lib/chef/knife/role_run_list_add.rb +86 -0
  148. data/lib/chef/knife/role_run_list_clear.rb +55 -0
  149. data/lib/chef/knife/role_run_list_remove.rb +57 -0
  150. data/lib/chef/knife/role_run_list_replace.rb +59 -0
  151. data/lib/chef/knife/role_run_list_set.rb +70 -0
  152. data/lib/chef/knife/search.rb +4 -4
  153. data/lib/chef/knife/serve.rb +3 -0
  154. data/lib/chef/knife/ssh.rb +1 -1
  155. data/lib/chef/knife/ssl_check.rb +2 -2
  156. data/lib/chef/knife/ssl_fetch.rb +14 -1
  157. data/lib/chef/log.rb +10 -1
  158. data/lib/chef/mixin/command.rb +1 -1
  159. data/lib/chef/mixin/command/windows.rb +1 -5
  160. data/lib/chef/mixin/get_source_from_package.rb +1 -0
  161. data/lib/chef/mixin/params_validate.rb +2 -2
  162. data/lib/chef/mixin/securable.rb +1 -7
  163. data/lib/chef/mixin/shell_out.rb +7 -1
  164. data/lib/chef/mixin/template.rb +2 -14
  165. data/lib/chef/mixin/why_run.rb +1 -1
  166. data/lib/chef/monkey_patches/net_http.rb +4 -0
  167. data/lib/chef/monologger.rb +0 -2
  168. data/lib/chef/node.rb +5 -2
  169. data/lib/chef/node/attribute.rb +11 -9
  170. data/lib/chef/node/attribute_collections.rb +8 -12
  171. data/lib/chef/node/immutable_collections.rb +4 -10
  172. data/lib/chef/org.rb +148 -0
  173. data/lib/chef/platform/provider_mapping.rb +3 -2
  174. data/lib/chef/platform/provider_priority_map.rb +2 -0
  175. data/lib/chef/platform/query_helpers.rb +0 -3
  176. data/lib/chef/policy_builder/policyfile.rb +51 -8
  177. data/lib/chef/provider/deploy.rb +1 -2
  178. data/lib/chef/provider/directory.rb +3 -3
  179. data/lib/chef/provider/dsc_script.rb +13 -7
  180. data/lib/chef/provider/env.rb +8 -8
  181. data/lib/chef/provider/execute.rb +55 -36
  182. data/lib/chef/provider/file.rb +8 -0
  183. data/lib/chef/provider/group.rb +2 -0
  184. data/lib/chef/provider/group/dscl.rb +3 -4
  185. data/lib/chef/provider/ifconfig.rb +25 -25
  186. data/lib/chef/provider/ifconfig/aix.rb +25 -27
  187. data/lib/chef/provider/lwrp_base.rb +1 -1
  188. data/lib/chef/provider/mount.rb +2 -2
  189. data/lib/chef/provider/mount/mount.rb +3 -4
  190. data/lib/chef/provider/mount/solaris.rb +1 -1
  191. data/lib/chef/provider/package.rb +297 -48
  192. data/lib/chef/provider/package/aix.rb +25 -30
  193. data/lib/chef/provider/package/apt.rb +63 -19
  194. data/lib/chef/provider/package/dpkg.rb +15 -16
  195. data/lib/chef/provider/package/macports.rb +7 -7
  196. data/lib/chef/provider/package/openbsd.rb +107 -0
  197. data/lib/chef/provider/package/pacman.rb +13 -15
  198. data/lib/chef/provider/package/portage.rb +3 -4
  199. data/lib/chef/provider/package/rpm.rb +28 -17
  200. data/lib/chef/provider/package/rubygems.rb +9 -9
  201. data/lib/chef/provider/package/solaris.rb +17 -21
  202. data/lib/chef/provider/package/windows/msi.rb +1 -1
  203. data/lib/chef/provider/package/yum-dump.py +2 -2
  204. data/lib/chef/provider/package/yum.rb +117 -51
  205. data/lib/chef/provider/package/zypper.rb +17 -18
  206. data/lib/chef/provider/powershell_script.rb +4 -4
  207. data/lib/chef/provider/registry_key.rb +2 -2
  208. data/lib/chef/provider/remote_directory.rb +1 -1
  209. data/lib/chef/provider/script.rb +25 -16
  210. data/lib/chef/provider/service.rb +1 -1
  211. data/lib/chef/provider/service/freebsd.rb +1 -1
  212. data/lib/chef/provider/service/openbsd.rb +216 -0
  213. data/lib/chef/provider/service/upstart.rb +1 -1
  214. data/lib/chef/provider/service/windows.rb +99 -1
  215. data/lib/chef/provider/user.rb +1 -1
  216. data/lib/chef/provider/user/dscl.rb +19 -4
  217. data/lib/chef/providers.rb +2 -0
  218. data/lib/chef/recipe.rb +11 -5
  219. data/lib/chef/request_id.rb +1 -1
  220. data/lib/chef/resource.rb +839 -444
  221. data/lib/chef/resource/chef_gem.rb +20 -3
  222. data/lib/chef/resource/conditional.rb +3 -14
  223. data/lib/chef/resource/dsc_script.rb +14 -0
  224. data/lib/chef/resource/execute.rb +14 -7
  225. data/lib/chef/resource/file.rb +14 -0
  226. data/lib/chef/resource/file/verification.rb +122 -0
  227. data/lib/chef/resource/ips_package.rb +1 -1
  228. data/lib/chef/resource/lwrp_base.rb +2 -11
  229. data/lib/chef/resource/macports_package.rb +2 -1
  230. data/lib/chef/resource/openbsd_package.rb +51 -0
  231. data/lib/chef/resource/package.rb +2 -2
  232. data/lib/chef/resource/paludis_package.rb +1 -1
  233. data/lib/chef/resource/reboot.rb +1 -1
  234. data/lib/chef/resource/remote_file.rb +1 -0
  235. data/lib/chef/resource/rpm_package.rb +9 -0
  236. data/lib/chef/resource/script.rb +11 -0
  237. data/lib/chef/resource/template.rb +2 -3
  238. data/lib/chef/resource/windows_package.rb +1 -1
  239. data/lib/chef/resource/windows_service.rb +18 -0
  240. data/lib/chef/resource_builder.rb +137 -0
  241. data/lib/chef/resource_definition.rb +1 -1
  242. data/lib/chef/resource_reporter.rb +1 -1
  243. data/lib/chef/resources.rb +1 -0
  244. data/lib/chef/role.rb +17 -4
  245. data/lib/chef/run_context.rb +10 -6
  246. data/lib/chef/search/query.rb +66 -87
  247. data/lib/chef/shell/ext.rb +2 -2
  248. data/lib/chef/util/diff.rb +1 -4
  249. data/lib/chef/util/dsc/configuration_generator.rb +30 -6
  250. data/lib/chef/util/dsc/lcm_output_parser.rb +7 -3
  251. data/lib/chef/util/dsc/local_configuration_manager.rb +8 -8
  252. data/lib/chef/util/file_edit.rb +2 -2
  253. data/lib/chef/util/path_helper.rb +1 -4
  254. data/lib/chef/util/windows/net_use.rb +3 -3
  255. data/lib/chef/version.rb +1 -1
  256. data/lib/chef/win32/api.rb +1 -0
  257. data/lib/chef/win32/api/security.rb +26 -0
  258. data/lib/chef/win32/file.rb +21 -0
  259. data/lib/chef/win32/security.rb +46 -0
  260. data/lib/chef/win32/security/token.rb +8 -0
  261. data/lib/chef/win32/version.rb +0 -4
  262. data/spec/data/recipes.tgz +0 -0
  263. data/spec/functional/application_spec.rb +1 -1
  264. data/spec/functional/audit/rspec_formatter_spec.rb +54 -0
  265. data/spec/functional/audit/runner_spec.rb +137 -0
  266. data/spec/functional/dsl/reboot_pending_spec.rb +10 -10
  267. data/spec/functional/dsl/registry_helper_spec.rb +6 -6
  268. data/spec/functional/event_loggers/windows_eventlog_spec.rb +5 -5
  269. data/spec/functional/file_content_management/deploy_strategies_spec.rb +12 -21
  270. data/spec/functional/http/simple_spec.rb +1 -1
  271. data/spec/functional/knife/cookbook_delete_spec.rb +24 -24
  272. data/spec/functional/knife/exec_spec.rb +2 -4
  273. data/spec/functional/knife/smoke_test.rb +1 -1
  274. data/spec/functional/knife/ssh_spec.rb +23 -23
  275. data/spec/functional/provider/remote_file/cache_control_data_spec.rb +8 -8
  276. data/spec/functional/provider/whyrun_safe_ruby_block_spec.rb +2 -2
  277. data/spec/functional/rebooter_spec.rb +1 -1
  278. data/spec/functional/resource/aix_service_spec.rb +3 -0
  279. data/spec/functional/resource/aixinit_service_spec.rb +3 -3
  280. data/spec/functional/resource/bash_spec.rb +88 -0
  281. data/spec/functional/resource/deploy_revision_spec.rb +99 -100
  282. data/spec/functional/resource/env_spec.rb +3 -3
  283. data/spec/functional/resource/execute_spec.rb +97 -63
  284. data/spec/functional/resource/file_spec.rb +7 -7
  285. data/spec/functional/resource/git_spec.rb +13 -13
  286. data/spec/functional/resource/group_spec.rb +28 -25
  287. data/spec/functional/resource/ifconfig_spec.rb +2 -2
  288. data/spec/functional/resource/link_spec.rb +77 -78
  289. data/spec/functional/resource/mount_spec.rb +5 -5
  290. data/spec/functional/resource/ohai_spec.rb +1 -1
  291. data/spec/functional/resource/package_spec.rb +22 -22
  292. data/spec/functional/resource/powershell_spec.rb +57 -42
  293. data/spec/functional/resource/reboot_spec.rb +2 -2
  294. data/spec/functional/resource/registry_spec.rb +91 -91
  295. data/spec/functional/resource/remote_directory_spec.rb +19 -19
  296. data/spec/functional/resource/remote_file_spec.rb +18 -18
  297. data/spec/functional/resource/template_spec.rb +4 -4
  298. data/spec/functional/resource/user/dscl_spec.rb +4 -4
  299. data/spec/functional/resource/user/useradd_spec.rb +64 -51
  300. data/spec/functional/resource/windows_service_spec.rb +98 -0
  301. data/spec/functional/run_lock_spec.rb +9 -9
  302. data/spec/functional/shell_spec.rb +3 -3
  303. data/spec/functional/tiny_server_spec.rb +12 -12
  304. data/spec/functional/util/path_helper_spec.rb +1 -1
  305. data/spec/functional/version_spec.rb +1 -1
  306. data/spec/functional/win32/registry_helper_spec.rb +125 -125
  307. data/spec/functional/win32/security_spec.rb +65 -2
  308. data/spec/functional/win32/service_manager_spec.rb +30 -84
  309. data/spec/functional/win32/versions_spec.rb +6 -6
  310. data/spec/integration/client/client_spec.rb +102 -9
  311. data/spec/integration/knife/chef_fs_data_store_spec.rb +12 -8
  312. data/spec/integration/knife/common_options_spec.rb +3 -3
  313. data/spec/integration/knife/cookbook_api_ipv6_spec.rb +2 -2
  314. data/spec/integration/knife/deps_spec.rb +4 -4
  315. data/spec/integration/knife/diff_spec.rb +6 -6
  316. data/spec/integration/knife/download_spec.rb +6 -6
  317. data/spec/integration/knife/list_spec.rb +2 -2
  318. data/spec/integration/knife/raw_spec.rb +5 -5
  319. data/spec/integration/knife/serve_spec.rb +3 -3
  320. data/spec/integration/knife/show_spec.rb +3 -3
  321. data/spec/integration/knife/upload_spec.rb +18 -18
  322. data/spec/integration/recipes/lwrp_inline_resources_spec.rb +1 -1
  323. data/spec/integration/solo/solo_spec.rb +11 -12
  324. data/spec/spec_helper.rb +27 -15
  325. data/spec/stress/win32/file_spec.rb +4 -4
  326. data/spec/stress/win32/security_spec.rb +4 -4
  327. data/spec/support/chef_helpers.rb +3 -3
  328. data/spec/support/matchers/leak.rb +2 -2
  329. data/spec/support/mock/platform.rb +1 -1
  330. data/spec/support/pedant/Gemfile +3 -0
  331. data/spec/support/pedant/pedant_config.rb +9 -2
  332. data/spec/support/pedant/run_pedant.rb +15 -16
  333. data/spec/support/platform_helpers.rb +8 -12
  334. data/spec/support/shared/functional/directory_resource.rb +13 -13
  335. data/spec/support/shared/functional/file_resource.rb +83 -83
  336. data/spec/support/shared/functional/http.rb +1 -1
  337. data/spec/support/shared/functional/securable_resource.rb +64 -64
  338. data/spec/support/shared/functional/securable_resource_with_reporting.rb +43 -41
  339. data/spec/support/shared/functional/win32_service.rb +60 -0
  340. data/spec/support/shared/functional/windows_script.rb +8 -8
  341. data/spec/support/shared/integration/knife_support.rb +8 -5
  342. data/spec/support/shared/matchers/exit_with_code.rb +6 -2
  343. data/spec/support/shared/unit/api_error_inspector.rb +8 -8
  344. data/spec/support/shared/unit/execute_resource.rb +24 -20
  345. data/spec/support/shared/unit/file_system_support.rb +2 -2
  346. data/spec/support/shared/unit/platform_introspector.rb +21 -21
  347. data/spec/support/shared/unit/provider/file.rb +239 -210
  348. data/spec/support/shared/unit/provider/useradd_based_user_provider.rb +69 -69
  349. data/spec/support/shared/unit/script_resource.rb +40 -32
  350. data/spec/support/shared/unit/windows_script_resource.rb +8 -8
  351. data/spec/unit/api_client/registration_spec.rb +47 -47
  352. data/spec/unit/api_client_spec.rb +107 -69
  353. data/spec/unit/application/apply_spec.rb +31 -15
  354. data/spec/unit/application/client_spec.rb +146 -45
  355. data/spec/unit/application/knife_spec.rb +31 -31
  356. data/spec/unit/application/solo_spec.rb +59 -43
  357. data/spec/unit/application_spec.rb +109 -74
  358. data/spec/unit/audit/audit_event_proxy_spec.rb +311 -0
  359. data/spec/unit/audit/audit_reporter_spec.rb +393 -0
  360. data/spec/unit/audit/control_group_data_spec.rb +478 -0
  361. data/{lib/chef/monkey_patches/file.rb → spec/unit/audit/rspec_formatter_spec.rb} +11 -8
  362. data/spec/unit/audit/runner_spec.rb +135 -0
  363. data/spec/unit/chef_fs/config_spec.rb +52 -0
  364. data/spec/unit/chef_fs/diff_spec.rb +12 -12
  365. data/spec/unit/chef_fs/file_pattern_spec.rb +276 -277
  366. data/spec/unit/chef_fs/file_system/operation_failed_error_spec.rb +6 -6
  367. data/spec/unit/chef_fs/file_system_spec.rb +26 -13
  368. data/spec/unit/chef_fs/parallelizer.rb +87 -87
  369. data/spec/unit/chef_spec.rb +1 -1
  370. data/spec/unit/client_spec.rb +263 -97
  371. data/spec/unit/config_fetcher_spec.rb +13 -13
  372. data/spec/unit/config_spec.rb +105 -66
  373. data/spec/unit/cookbook/chefignore_spec.rb +6 -6
  374. data/spec/unit/cookbook/cookbook_version_loader_spec.rb +3 -3
  375. data/spec/unit/cookbook/metadata_spec.rb +149 -149
  376. data/spec/unit/cookbook/syntax_check_spec.rb +36 -31
  377. data/spec/unit/cookbook_loader_spec.rb +62 -58
  378. data/spec/unit/cookbook_manifest_spec.rb +141 -468
  379. data/spec/unit/cookbook_site_streaming_uploader_spec.rb +27 -27
  380. data/spec/unit/cookbook_spec.rb +15 -15
  381. data/spec/unit/cookbook_uploader_spec.rb +37 -3
  382. data/spec/unit/cookbook_version_file_specificity_spec.rb +554 -0
  383. data/spec/unit/cookbook_version_spec.rb +98 -240
  384. data/spec/unit/daemon_spec.rb +31 -31
  385. data/spec/unit/data_bag_item_spec.rb +121 -89
  386. data/spec/unit/data_bag_spec.rb +35 -35
  387. data/spec/unit/deprecation_spec.rb +27 -14
  388. data/spec/unit/digester_spec.rb +3 -3
  389. data/spec/unit/dsl/audit_spec.rb +43 -0
  390. data/spec/unit/dsl/data_query_spec.rb +1 -1
  391. data/spec/unit/dsl/platform_introspection_spec.rb +14 -14
  392. data/spec/unit/dsl/reboot_pending_spec.rb +18 -18
  393. data/spec/unit/dsl/regsitry_helper_spec.rb +6 -6
  394. data/spec/unit/encrypted_data_bag_item_spec.rb +58 -82
  395. data/spec/unit/environment_spec.rb +105 -105
  396. data/spec/unit/exceptions_spec.rb +47 -1
  397. data/spec/unit/file_access_control_spec.rb +62 -56
  398. data/spec/unit/file_cache_spec.rb +11 -11
  399. data/spec/unit/file_content_management/deploy/cp_spec.rb +2 -2
  400. data/spec/unit/file_content_management/deploy/mv_unix_spec.rb +10 -10
  401. data/spec/unit/file_content_management/deploy/mv_windows_spec.rb +23 -23
  402. data/spec/unit/formatters/error_inspectors/compile_error_inspector_spec.rb +14 -14
  403. data/spec/unit/formatters/error_inspectors/cookbook_resolve_error_inspector_spec.rb +12 -12
  404. data/spec/unit/formatters/error_inspectors/cookbook_sync_error_inspector_spec.rb +1 -1
  405. data/spec/unit/formatters/error_inspectors/resource_failure_inspector_spec.rb +16 -16
  406. data/spec/unit/formatters/error_inspectors/run_list_expansion_error_inspector_spec.rb +4 -4
  407. data/spec/unit/guard_interpreter/resource_guard_interpreter_spec.rb +103 -13
  408. data/spec/unit/guard_interpreter_spec.rb +41 -0
  409. data/spec/unit/handler/json_file_spec.rb +10 -10
  410. data/spec/unit/handler_spec.rb +39 -39
  411. data/spec/unit/http/basic_client_spec.rb +3 -3
  412. data/spec/unit/http/http_request_spec.rb +10 -10
  413. data/spec/unit/http/simple_spec.rb +3 -3
  414. data/spec/unit/http/ssl_policies_spec.rb +15 -15
  415. data/spec/unit/http/validate_content_length_spec.rb +18 -13
  416. data/spec/unit/http_spec.rb +16 -9
  417. data/spec/unit/knife/bootstrap/chef_vault_handler_spec.rb +153 -0
  418. data/spec/unit/knife/bootstrap/client_builder_spec.rb +178 -0
  419. data/spec/unit/knife/bootstrap_spec.rb +144 -91
  420. data/spec/unit/knife/client_bulk_delete_spec.rb +24 -24
  421. data/spec/unit/knife/client_create_spec.rb +57 -43
  422. data/spec/unit/knife/client_delete_spec.rb +15 -15
  423. data/spec/unit/knife/client_edit_spec.rb +4 -4
  424. data/spec/unit/knife/client_list_spec.rb +2 -2
  425. data/spec/unit/knife/client_reregister_spec.rb +9 -9
  426. data/spec/unit/knife/configure_client_spec.rb +20 -20
  427. data/spec/unit/knife/configure_spec.rb +85 -85
  428. data/spec/unit/knife/cookbook_bulk_delete_spec.rb +15 -15
  429. data/spec/unit/knife/cookbook_create_spec.rb +59 -59
  430. data/spec/unit/knife/cookbook_delete_spec.rb +49 -49
  431. data/spec/unit/knife/cookbook_download_spec.rb +56 -56
  432. data/spec/unit/knife/cookbook_list_spec.rb +9 -9
  433. data/spec/unit/knife/cookbook_metadata_from_file_spec.rb +8 -8
  434. data/spec/unit/knife/cookbook_metadata_spec.rb +44 -44
  435. data/spec/unit/knife/cookbook_show_spec.rb +29 -29
  436. data/spec/unit/knife/cookbook_site_download_spec.rb +26 -26
  437. data/spec/unit/knife/cookbook_site_install_spec.rb +5 -1
  438. data/spec/unit/knife/cookbook_site_share_spec.rb +68 -59
  439. data/spec/unit/knife/cookbook_site_unshare_spec.rb +15 -15
  440. data/spec/unit/knife/cookbook_test_spec.rb +16 -16
  441. data/spec/unit/knife/cookbook_upload_spec.rb +105 -71
  442. data/spec/unit/knife/core/bootstrap_context_spec.rb +37 -22
  443. data/spec/unit/knife/core/cookbook_scm_repo_spec.rb +36 -36
  444. data/spec/unit/knife/core/object_loader_spec.rb +3 -3
  445. data/spec/unit/knife/core/subcommand_loader_spec.rb +107 -33
  446. data/spec/unit/knife/core/ui_spec.rb +84 -72
  447. data/spec/unit/knife/data_bag_from_file_spec.rb +1 -1
  448. data/spec/unit/knife/environment_compare_spec.rb +12 -12
  449. data/spec/unit/knife/environment_create_spec.rb +16 -16
  450. data/spec/unit/knife/environment_delete_spec.rb +14 -14
  451. data/spec/unit/knife/environment_edit_spec.rb +15 -15
  452. data/spec/unit/knife/environment_from_file_spec.rb +17 -17
  453. data/spec/unit/knife/environment_list_spec.rb +7 -7
  454. data/spec/unit/knife/environment_show_spec.rb +10 -10
  455. data/spec/unit/knife/index_rebuild_spec.rb +17 -17
  456. data/spec/unit/knife/knife_help.rb +24 -24
  457. data/spec/unit/knife/node_bulk_delete_spec.rb +14 -14
  458. data/spec/unit/knife/node_delete_spec.rb +11 -11
  459. data/spec/unit/knife/node_edit_spec.rb +17 -17
  460. data/spec/unit/knife/node_environment_set_spec.rb +12 -12
  461. data/spec/unit/knife/node_from_file_spec.rb +8 -8
  462. data/spec/unit/knife/node_list_spec.rb +9 -9
  463. data/spec/unit/knife/node_run_list_add_spec.rb +29 -29
  464. data/spec/unit/knife/node_run_list_remove_spec.rb +28 -13
  465. data/spec/unit/knife/node_run_list_set_spec.rb +27 -27
  466. data/spec/unit/knife/raw_spec.rb +43 -0
  467. data/spec/unit/knife/role_bulk_delete_spec.rb +12 -12
  468. data/spec/unit/knife/role_create_spec.rb +12 -12
  469. data/spec/unit/knife/role_delete_spec.rb +10 -10
  470. data/spec/unit/knife/role_edit_spec.rb +13 -13
  471. data/spec/unit/knife/role_env_run_list_add_spec.rb +217 -0
  472. data/spec/unit/knife/role_env_run_list_clear_spec.rb +100 -0
  473. data/spec/unit/knife/role_env_run_list_remove_spec.rb +108 -0
  474. data/spec/unit/knife/role_env_run_list_replace_spec.rb +108 -0
  475. data/spec/unit/knife/role_env_run_list_set_spec.rb +102 -0
  476. data/spec/unit/knife/role_from_file_spec.rb +10 -10
  477. data/spec/unit/knife/role_list_spec.rb +7 -7
  478. data/spec/unit/knife/role_run_list_add_spec.rb +179 -0
  479. data/spec/unit/knife/role_run_list_clear_spec.rb +90 -0
  480. data/spec/unit/knife/role_run_list_remove_spec.rb +98 -0
  481. data/spec/unit/knife/role_run_list_replace_spec.rb +101 -0
  482. data/spec/unit/knife/role_run_list_set_spec.rb +92 -0
  483. data/spec/unit/knife/ssh_spec.rb +66 -66
  484. data/spec/unit/knife/ssl_check_spec.rb +27 -27
  485. data/spec/unit/knife/ssl_fetch_spec.rb +45 -12
  486. data/spec/unit/knife/status_spec.rb +5 -5
  487. data/spec/unit/knife/tag_create_spec.rb +5 -5
  488. data/spec/unit/knife/tag_delete_spec.rb +6 -6
  489. data/spec/unit/knife/tag_list_spec.rb +4 -4
  490. data/spec/unit/knife/user_create_spec.rb +18 -18
  491. data/spec/unit/knife/user_delete_spec.rb +4 -4
  492. data/spec/unit/knife/user_edit_spec.rb +7 -7
  493. data/spec/unit/knife/user_list_spec.rb +2 -2
  494. data/spec/unit/knife/user_reregister_spec.rb +10 -10
  495. data/spec/unit/knife/user_show_spec.rb +5 -5
  496. data/spec/unit/knife_spec.rb +36 -36
  497. data/spec/unit/lwrp_spec.rb +63 -39
  498. data/spec/unit/mash_spec.rb +6 -6
  499. data/spec/unit/mixin/checksum_spec.rb +2 -2
  500. data/spec/unit/mixin/command_spec.rb +13 -13
  501. data/spec/unit/mixin/convert_to_class_name_spec.rb +6 -6
  502. data/spec/unit/mixin/deep_merge_spec.rb +49 -49
  503. data/spec/unit/mixin/deprecation_spec.rb +5 -5
  504. data/spec/unit/mixin/enforce_ownership_and_permissions_spec.rb +14 -14
  505. data/spec/unit/mixin/homebrew_user_spec.rb +3 -3
  506. data/spec/unit/mixin/params_validate_spec.rb +71 -71
  507. data/spec/unit/mixin/path_sanity_spec.rb +14 -14
  508. data/spec/unit/mixin/securable_spec.rb +177 -177
  509. data/spec/unit/mixin/shell_out_spec.rb +56 -27
  510. data/spec/unit/mixin/template_spec.rb +31 -31
  511. data/spec/unit/mixin/windows_architecture_helper_spec.rb +5 -5
  512. data/spec/unit/mixin/xml_escape_spec.rb +7 -7
  513. data/spec/unit/monkey_patches/uri_spec.rb +1 -1
  514. data/spec/unit/monologger_spec.rb +3 -3
  515. data/spec/unit/node/attribute_spec.rb +185 -136
  516. data/spec/unit/node/immutable_collections_spec.rb +22 -22
  517. data/spec/unit/node_spec.rb +210 -179
  518. data/spec/unit/org_spec.rb +196 -0
  519. data/spec/unit/platform/query_helpers_spec.rb +5 -5
  520. data/spec/unit/platform_spec.rb +46 -46
  521. data/spec/unit/policy_builder/expand_node_object_spec.rb +17 -18
  522. data/spec/unit/policy_builder/policyfile_spec.rb +159 -71
  523. data/spec/unit/provider/directory_spec.rb +5 -5
  524. data/spec/unit/provider/dsc_script_spec.rb +6 -6
  525. data/spec/unit/provider/env_spec.rb +27 -14
  526. data/spec/unit/provider/execute_spec.rb +139 -68
  527. data/spec/unit/provider/file/content_spec.rb +8 -8
  528. data/spec/unit/provider/git_spec.rb +10 -5
  529. data/spec/unit/provider/group/dscl_spec.rb +8 -11
  530. data/spec/unit/provider/group_spec.rb +13 -13
  531. data/spec/unit/provider/ifconfig/aix_spec.rb +3 -2
  532. data/spec/unit/provider/ifconfig/debian_spec.rb +19 -19
  533. data/spec/unit/provider/ifconfig_spec.rb +2 -2
  534. data/spec/unit/provider/mdadm_spec.rb +2 -2
  535. data/spec/unit/provider/mount/aix_spec.rb +5 -5
  536. data/spec/unit/provider/mount/mount_spec.rb +22 -22
  537. data/spec/unit/provider/mount/solaris_spec.rb +20 -20
  538. data/spec/unit/provider/package/aix_spec.rb +23 -22
  539. data/spec/unit/provider/package/apt_spec.rb +23 -4
  540. data/spec/unit/provider/package/dpkg_spec.rb +14 -15
  541. data/spec/unit/provider/package/freebsd/pkgng_spec.rb +1 -1
  542. data/spec/unit/provider/package/freebsd/port_spec.rb +1 -1
  543. data/spec/unit/provider/package/ips_spec.rb +1 -2
  544. data/spec/unit/provider/package/macports_spec.rb +14 -14
  545. data/spec/unit/provider/package/openbsd_spec.rb +66 -0
  546. data/spec/unit/provider/package/pacman_spec.rb +15 -14
  547. data/spec/unit/provider/package/portage_spec.rb +11 -11
  548. data/spec/unit/provider/package/rpm_spec.rb +132 -84
  549. data/spec/unit/provider/package/rubygems_spec.rb +54 -25
  550. data/spec/unit/provider/package/solaris_spec.rb +22 -25
  551. data/spec/unit/provider/package/yum_spec.rb +237 -36
  552. data/spec/unit/provider/package/zypper_spec.rb +9 -12
  553. data/spec/unit/provider/package_spec.rb +276 -2
  554. data/spec/unit/provider/package_spec.rbe +0 -0
  555. data/spec/unit/provider/remote_directory_spec.rb +25 -25
  556. data/spec/unit/provider/remote_file/ftp_spec.rb +3 -3
  557. data/spec/unit/provider/route_spec.rb +3 -3
  558. data/spec/unit/provider/script_spec.rb +61 -43
  559. data/spec/unit/provider/service/aix_service_spec.rb +5 -5
  560. data/spec/unit/provider/service/arch_service_spec.rb +5 -5
  561. data/spec/unit/provider/service/debian_service_spec.rb +8 -8
  562. data/spec/unit/provider/service/freebsd_service_spec.rb +16 -2
  563. data/spec/unit/provider/service/gentoo_service_spec.rb +8 -8
  564. data/spec/unit/provider/service/init_service_spec.rb +5 -5
  565. data/spec/unit/provider/service/insserv_service_spec.rb +2 -2
  566. data/spec/unit/provider/service/invokercd_service_spec.rb +5 -5
  567. data/spec/unit/provider/service/macosx_spec.rb +7 -7
  568. data/spec/unit/provider/service/openbsd_service_spec.rb +543 -0
  569. data/spec/unit/provider/service/redhat_spec.rb +4 -4
  570. data/spec/unit/provider/service/simple_service_spec.rb +2 -2
  571. data/spec/unit/provider/service/solaris_smf_service_spec.rb +14 -14
  572. data/spec/unit/provider/service/systemd_service_spec.rb +15 -7
  573. data/spec/unit/provider/service/upstart_service_spec.rb +4 -4
  574. data/spec/unit/provider/service/windows_spec.rb +119 -25
  575. data/spec/unit/provider/service_spec.rb +1 -1
  576. data/spec/unit/provider/user/dscl_spec.rb +38 -30
  577. data/spec/unit/provider/user_spec.rb +1 -1
  578. data/spec/unit/provider_resolver_spec.rb +7 -7
  579. data/spec/unit/provider_spec.rb +23 -23
  580. data/spec/unit/recipe_spec.rb +194 -83
  581. data/spec/unit/registry_helper_spec.rb +143 -143
  582. data/spec/unit/resource/chef_gem_spec.rb +117 -3
  583. data/spec/unit/resource/conditional_action_not_nothing_spec.rb +2 -2
  584. data/spec/unit/resource/conditional_spec.rb +56 -15
  585. data/spec/unit/resource/deploy_spec.rb +2 -2
  586. data/spec/unit/resource/dsc_script_spec.rb +32 -0
  587. data/spec/unit/resource/execute_spec.rb +4 -0
  588. data/spec/unit/resource/file/verification_spec.rb +111 -0
  589. data/spec/unit/resource/file_spec.rb +14 -0
  590. data/spec/unit/resource/openbsd_package_spec.rb +49 -0
  591. data/spec/unit/resource/remote_file_spec.rb +12 -12
  592. data/spec/unit/resource/resource_notification_spec.rb +18 -18
  593. data/spec/unit/resource/rpm_package_spec.rb +12 -0
  594. data/spec/unit/resource/scm_spec.rb +4 -4
  595. data/spec/unit/resource/script_spec.rb +3 -5
  596. data/spec/unit/resource/subversion_spec.rb +1 -1
  597. data/spec/unit/resource_builder_spec.rb +1 -0
  598. data/spec/unit/resource_collection/resource_list_spec.rb +2 -2
  599. data/spec/unit/resource_collection/resource_set_spec.rb +3 -3
  600. data/spec/unit/resource_collection/stepable_iterator_spec.rb +24 -24
  601. data/spec/unit/resource_collection_spec.rb +52 -52
  602. data/spec/unit/resource_definition_spec.rb +1 -1
  603. data/spec/unit/resource_reporter_spec.rb +118 -118
  604. data/spec/unit/resource_spec.rb +131 -125
  605. data/spec/unit/rest/auth_credentials_spec.rb +73 -73
  606. data/spec/unit/rest_spec.rb +12 -12
  607. data/spec/unit/role_spec.rb +85 -84
  608. data/spec/unit/run_context/cookbook_compiler_spec.rb +18 -18
  609. data/spec/unit/run_context_spec.rb +39 -68
  610. data/spec/unit/run_list/run_list_expansion_spec.rb +21 -21
  611. data/spec/unit/run_list/run_list_item_spec.rb +28 -28
  612. data/spec/unit/run_list/versioned_recipe_list_spec.rb +14 -14
  613. data/spec/unit/run_list_spec.rb +55 -55
  614. data/spec/unit/run_lock_spec.rb +14 -14
  615. data/spec/unit/run_status_spec.rb +24 -24
  616. data/spec/unit/scan_access_control_spec.rb +23 -23
  617. data/spec/unit/search/query_spec.rb +54 -66
  618. data/spec/unit/shell/model_wrapper_spec.rb +13 -13
  619. data/spec/unit/shell/shell_ext_spec.rb +32 -32
  620. data/spec/unit/shell/shell_session_spec.rb +24 -24
  621. data/spec/unit/shell_out_spec.rb +4 -4
  622. data/spec/unit/shell_spec.rb +27 -27
  623. data/spec/unit/user_spec.rb +50 -50
  624. data/spec/unit/util/backup_spec.rb +32 -32
  625. data/spec/unit/util/diff_spec.rb +31 -31
  626. data/spec/unit/util/dsc/configuration_generator_spec.rb +38 -16
  627. data/spec/unit/util/dsc/lcm_output_parser_spec.rb +21 -26
  628. data/spec/unit/util/dsc/local_configuration_manager_spec.rb +10 -10
  629. data/spec/unit/util/editor_spec.rb +10 -10
  630. data/spec/unit/util/file_edit_spec.rb +10 -10
  631. data/spec/unit/util/path_helper_spec.rb +38 -46
  632. data/spec/unit/util/powershell/cmdlet_spec.rb +9 -9
  633. data/spec/unit/util/selinux_spec.rb +30 -30
  634. data/spec/unit/util/threaded_job_queue_spec.rb +6 -6
  635. data/spec/unit/version/platform_spec.rb +5 -5
  636. data/spec/unit/version_class_spec.rb +15 -15
  637. data/spec/unit/version_constraint/platform_spec.rb +7 -7
  638. data/spec/unit/version_constraint_spec.rb +43 -43
  639. data/spec/unit/windows_service_spec.rb +15 -15
  640. data/spec/unit/workstation_config_loader_spec.rb +2 -2
  641. data/tasks/rspec.rb +16 -18
  642. metadata +126 -49
  643. data/bin/shef +0 -35
  644. data/lib/chef/application/agent.rb +0 -18
  645. data/lib/chef/monkey_patches/fileutils.rb +0 -65
  646. data/lib/chef/monkey_patches/numeric.rb +0 -15
  647. data/lib/chef/monkey_patches/object.rb +0 -9
  648. data/lib/chef/monkey_patches/pathname.rb +0 -32
  649. data/lib/chef/monkey_patches/regexp.rb +0 -34
  650. data/lib/chef/monkey_patches/securerandom.rb +0 -44
  651. data/lib/chef/monkey_patches/string.rb +0 -49
  652. data/lib/chef/monkey_patches/tempfile.rb +0 -64
  653. data/lib/chef/monkey_patches/uri.rb +0 -70
@@ -0,0 +1,311 @@
1
+ #
2
+ # Author:: Tyler Ball (<tball@chef.io>)
3
+ # Author:: Claire McQuin (<claire@getchef.com>)
4
+ #
5
+ # Copyright:: Copyright (c) 2014 Chef Software, Inc.
6
+ # License:: Apache License, Version 2.0
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ # See the License for the specific language governing permissions and
18
+ # limitations under the License.
19
+ #
20
+
21
+ require 'spec_helper'
22
+ require 'chef/audit/audit_event_proxy'
23
+
24
+ describe Chef::Audit::AuditEventProxy do
25
+
26
+ let(:stdout) { StringIO.new }
27
+ let(:events) { double("Chef::Events") }
28
+ let(:audit_event_proxy) { Chef::Audit::AuditEventProxy.new(stdout) }
29
+
30
+ before do
31
+ Chef::Audit::AuditEventProxy.events = events
32
+ end
33
+
34
+ describe "#example_group_started" do
35
+
36
+ let(:description) { "poots" }
37
+ let(:group) { double("ExampleGroup", :parent_groups => parents,
38
+ :description => description) }
39
+ let(:notification) { double("Notification", :group => group) }
40
+
41
+ context "when notified from a top-level example group" do
42
+
43
+ let(:parents) { [double("ExampleGroup")] }
44
+
45
+ it "notifies control_group_started event" do
46
+ expect(Chef::Log).to receive(:debug).
47
+ with("Entered \`control_group\` block named poots")
48
+ expect(events).to receive(:control_group_started).
49
+ with(description)
50
+ audit_event_proxy.example_group_started(notification)
51
+ end
52
+ end
53
+
54
+ context "when notified from an inner-level example group" do
55
+
56
+ let(:parents) { [double("ExampleGroup"), double("OuterExampleGroup")] }
57
+
58
+ it "does nothing" do
59
+ expect(events).to_not receive(:control_group_started)
60
+ audit_event_proxy.example_group_started(notification)
61
+ end
62
+ end
63
+ end
64
+
65
+ describe "#stop" do
66
+
67
+ let(:examples) { [] }
68
+ let(:notification) { double("Notification", :examples => examples) }
69
+ let(:exception) { nil }
70
+ let(:example) { double("Example", :exception => exception) }
71
+ let(:control_group_name) { "audit test" }
72
+ let(:control_data) { double("ControlData") }
73
+
74
+ before do
75
+ allow(Chef::Log).to receive(:info) # silence messages to output stream
76
+ end
77
+
78
+ it "sends a message that audits completed" do
79
+ expect(Chef::Log).to receive(:info).with("Successfully executed all \`control_group\` blocks and contained examples")
80
+ audit_event_proxy.stop(notification)
81
+ end
82
+
83
+ context "when an example succeeded" do
84
+
85
+ let(:examples) { [example] }
86
+ let(:excpetion) { nil }
87
+
88
+ before do
89
+ allow(audit_event_proxy).to receive(:build_control_from).
90
+ with(example).
91
+ and_return([control_group_name, control_data])
92
+ end
93
+
94
+ it "notifies events" do
95
+ expect(events).to receive(:control_example_success).
96
+ with(control_group_name, control_data)
97
+ audit_event_proxy.stop(notification)
98
+ end
99
+ end
100
+
101
+ context "when an example failed" do
102
+
103
+ let(:examples) { [example] }
104
+ let(:exception) { double("ExpectationNotMet") }
105
+
106
+ before do
107
+ allow(audit_event_proxy).to receive(:build_control_from).
108
+ with(example).
109
+ and_return([control_group_name, control_data])
110
+ end
111
+
112
+ it "notifies events" do
113
+ expect(events).to receive(:control_example_failure).
114
+ with(control_group_name, control_data, exception)
115
+ audit_event_proxy.stop(notification)
116
+ end
117
+ end
118
+
119
+ describe "#build_control_from" do
120
+
121
+ let(:examples) { [example] }
122
+
123
+ let(:example) { double("Example", :metadata => metadata,
124
+ :description => example_description,
125
+ :full_description => full_description, :exception => nil) }
126
+
127
+ let(:metadata) {
128
+ {
129
+ :described_class => described_class,
130
+ :example_group => example_group,
131
+ :line_number => line
132
+ }
133
+ }
134
+
135
+ let(:example_group) {
136
+ {
137
+ :description => group_description,
138
+ :parent_example_group => parent_group
139
+ }
140
+ }
141
+
142
+ let(:parent_group) {
143
+ {
144
+ :description => control_group_name,
145
+ :parent_example_group => nil
146
+ }
147
+ }
148
+
149
+ let(:line) { 27 }
150
+
151
+ let(:control_data) {
152
+ {
153
+ :name => example_description,
154
+ :desc => full_description,
155
+ :resource_type => resource_type,
156
+ :resource_name => resource_name,
157
+ :context => context,
158
+ :line_number => line
159
+ }
160
+ }
161
+
162
+ shared_examples "built control" do
163
+
164
+ before do
165
+ if described_class
166
+ allow(described_class).to receive(:instance_variable_get).
167
+ with(:@name).
168
+ and_return(resource_name)
169
+ allow(described_class.class).to receive(:name).
170
+ and_return(described_class.class)
171
+ end
172
+ end
173
+
174
+ it "returns the controls block name and example metadata for reporting" do
175
+ expect(events).to receive(:control_example_success).
176
+ with(control_group_name, control_data)
177
+ audit_event_proxy.stop(notification)
178
+ end
179
+ end
180
+
181
+ describe "a top-level example" do
182
+ # controls "port 111" do
183
+ # it "has nobody listening" do
184
+ # expect(port("111")).to_not be_listening
185
+ # end
186
+ # end
187
+
188
+ # Description parts
189
+ let(:group_description) { "port 111" }
190
+ let(:example_description) { "has nobody listening" }
191
+ let(:full_description) { group_description + " " + example_description }
192
+
193
+ # Metadata fields
194
+ let(:described_class) { nil }
195
+
196
+ # Example group (metadata[:example_group]) fields
197
+ let(:parent_group) { nil }
198
+
199
+ # Expected returns
200
+ let(:control_group_name) { group_description }
201
+
202
+ # Control data fields
203
+ let(:resource_type) { nil }
204
+ let(:resource_name) { nil }
205
+ let(:context) { [] }
206
+
207
+ include_examples "built control"
208
+ end
209
+
210
+ describe "an example with an implicit subject" do
211
+ # controls "application ports" do
212
+ # control port(111) do
213
+ # it { is_expected.to_not be_listening }
214
+ # end
215
+ # end
216
+
217
+ # Description parts
218
+ let(:control_group_name) { "application ports" }
219
+ let(:group_description) { "#{resource_type} #{resource_name}" }
220
+ let(:example_description) { "should not be listening" }
221
+ let(:full_description) { [control_group_name, group_description,
222
+ example_description].join(" ") }
223
+
224
+ # Metadata fields
225
+ let(:described_class) { double("Serverspec::Type::Port",
226
+ :class => "Serverspec::Type::Port", :name => resource_name) }
227
+
228
+ # Control data fields
229
+ let(:resource_type) { "Port" }
230
+ let(:resource_name) { "111" }
231
+ let(:context) { [] }
232
+
233
+ include_examples "built control"
234
+ end
235
+
236
+ describe "an example in a nested context" do
237
+ # controls "application ports" do
238
+ # control "port 111" do
239
+ # it "is not listening" do
240
+ # expect(port(111)).to_not be_listening
241
+ # end
242
+ # end
243
+ # end
244
+
245
+ # Description parts
246
+ let(:control_group_name) { "application ports" }
247
+ let(:group_description) { "port 111" }
248
+ let(:example_description) { "is not listening" }
249
+ let(:full_description) { [control_group_name, group_description,
250
+ example_description].join(" ") }
251
+
252
+ # Metadata fields
253
+ let(:described_class) { nil }
254
+
255
+ # Control data fields
256
+ let(:resource_type) { nil }
257
+ let(:resource_name) { nil }
258
+ let(:context) { [group_description] }
259
+
260
+ include_examples "built control"
261
+ end
262
+
263
+ describe "an example in a nested context including Serverspec" do
264
+ # controls "application directory" do
265
+ # control file("/tmp/audit") do
266
+ # describe file("/tmp/audit/test_file") do
267
+ # it "is a file" do
268
+ # expect(subject).to be_file
269
+ # end
270
+ # end
271
+ # end
272
+ # end
273
+
274
+ # Description parts
275
+ let(:control_group_name) { "application directory" }
276
+ let(:outer_group_description) { "File \"tmp/audit\"" }
277
+ let(:group_description) { "#{resource_type} #{resource_name}" }
278
+ let(:example_description) { "is a file" }
279
+ let(:full_description) { [control_group_name, outer_group_description,
280
+ group_description, example_description].join(" ") }
281
+
282
+ # Metadata parts
283
+ let(:described_class) { double("Serverspec::Type::File",
284
+ :class => "Serverspec::Type::File", :name => resource_name) }
285
+
286
+ # Example group parts
287
+ let(:parent_group) {
288
+ {
289
+ :description => outer_group_description,
290
+ :parent_example_group => control_group
291
+ }
292
+ }
293
+
294
+ let(:control_group) {
295
+ {
296
+ :description => control_group_name,
297
+ :parent_example_group => nil
298
+ }
299
+ }
300
+
301
+ # Control data parts
302
+ let(:resource_type) { "File" }
303
+ let(:resource_name) { "/tmp/audit/test_file" }
304
+ let(:context) { [outer_group_description] }
305
+
306
+ include_examples "built control"
307
+ end
308
+ end
309
+ end
310
+
311
+ end
@@ -0,0 +1,393 @@
1
+ #
2
+ # Author:: Tyler Ball (<tball@chef.io>)
3
+ # Author:: Claire McQuin (<claire@getchef.com>)
4
+ #
5
+ # Copyright:: Copyright (c) 2014 Chef Software, Inc.
6
+ # License:: Apache License, Version 2.0
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ # See the License for the specific language governing permissions and
18
+ # limitations under the License.
19
+ #
20
+
21
+ require 'spec_helper'
22
+
23
+ describe Chef::Audit::AuditReporter do
24
+
25
+ let(:rest) { double("rest") }
26
+ let(:reporter) { described_class.new(rest) }
27
+ let(:node) { double("node", :name => "sofreshsoclean") }
28
+ let(:run_id) { 0 }
29
+ let(:start_time) { Time.new(2014, 12, 3, 9, 31, 05, "-08:00") }
30
+ let(:end_time) { Time.new(2014, 12, 3, 9, 36, 14, "-08:00") }
31
+ let(:run_status) { instance_double(Chef::RunStatus, :node => node, :run_id => run_id,
32
+ :start_time => start_time, :end_time => end_time) }
33
+
34
+ describe "#audit_phase_start" do
35
+
36
+ it "notifies audit phase start to debug log" do
37
+ expect(Chef::Log).to receive(:debug).with(/Audit Reporter starting/)
38
+ reporter.audit_phase_start(run_status)
39
+ end
40
+
41
+ it "initializes an AuditData object" do
42
+ expect(Chef::Audit::AuditData).to receive(:new).with(run_status.node.name, run_status.run_id)
43
+ reporter.audit_phase_start(run_status)
44
+ end
45
+
46
+ it "saves the run status" do
47
+ reporter.audit_phase_start(run_status)
48
+ expect(reporter.instance_variable_get(:@run_status)).to eq run_status
49
+ end
50
+ end
51
+
52
+ describe "#run_completed" do
53
+
54
+ let(:audit_data) { Chef::Audit::AuditData.new(node.name, run_id) }
55
+ let(:run_data) { audit_data.to_hash }
56
+
57
+ before do
58
+ allow(reporter).to receive(:auditing_enabled?).and_return(true)
59
+ allow(reporter).to receive(:run_status).and_return(run_status)
60
+ allow(rest).to receive(:create_url).and_return(true)
61
+ allow(rest).to receive(:post).and_return(true)
62
+ allow(reporter).to receive(:audit_data).and_return(audit_data)
63
+ allow(reporter).to receive(:run_status).and_return(run_status)
64
+ allow(audit_data).to receive(:to_hash).and_return(run_data)
65
+ end
66
+
67
+ describe "a successful run with auditing enabled" do
68
+ it "sets run start and end times" do
69
+ iso_start_time = "2014-12-03T17:31:05Z"
70
+ iso_end_time = "2014-12-03T17:36:14Z"
71
+
72
+ reporter.run_completed(node)
73
+ expect(audit_data.start_time).to eq iso_start_time
74
+ expect(audit_data.end_time).to eq iso_end_time
75
+ end
76
+
77
+ it "posts audit data to server endpoint" do
78
+ endpoint = "api.opscode.us/orgname/controls"
79
+ headers = {
80
+ 'X-Ops-Audit-Report-Protocol-Version' => Chef::Audit::AuditReporter::PROTOCOL_VERSION
81
+ }
82
+
83
+ expect(rest).to receive(:create_url).
84
+ with("controls").
85
+ and_return(endpoint)
86
+ expect(rest).to receive(:post).
87
+ with(endpoint, run_data, headers)
88
+ reporter.run_completed(node)
89
+ end
90
+
91
+ context "when unable to post to server" do
92
+
93
+ let(:error) do
94
+ e = StandardError.new
95
+ e.set_backtrace(caller)
96
+ e
97
+ end
98
+
99
+ before do
100
+ expect(rest).to receive(:post).and_raise(error)
101
+ allow(error).to receive(:respond_to?).and_call_original
102
+ end
103
+
104
+ context "the error is an http error" do
105
+
106
+ let(:response) { double("response", :code => code) }
107
+
108
+ before do
109
+ expect(Chef::Log).to receive(:debug).with(/Sending audit report/)
110
+ expect(Chef::Log).to receive(:debug).with(/Audit Report/)
111
+ allow(error).to receive(:response).and_return(response)
112
+ expect(error).to receive(:respond_to?).with(:response).and_return(true)
113
+ end
114
+
115
+ context "when the code is 404" do
116
+
117
+ let(:code) { "404" }
118
+
119
+ it "logs that the server doesn't support audit reporting" do
120
+ expect(Chef::Log).to receive(:debug).with(/Server doesn't support audit reporting/)
121
+ reporter.run_completed(node)
122
+ end
123
+ end
124
+
125
+ shared_examples "non-404 error code" do
126
+
127
+ it "saves the error report" do
128
+ expect(Chef::FileCache).to receive(:store).
129
+ with("failed-audit-data.json", an_instance_of(String), 0640).
130
+ and_return(true)
131
+ expect(Chef::FileCache).to receive(:load).
132
+ with("failed-audit-data.json", false).
133
+ and_return(true)
134
+ expect(Chef::Log).to receive(:error).with(/Failed to post audit report to server/)
135
+ reporter.run_completed(node)
136
+ end
137
+
138
+ end
139
+
140
+ context "when the code is not 404" do
141
+ include_examples "non-404 error code" do
142
+ let(:code) { "505" }
143
+ end
144
+ end
145
+
146
+ context "when there is no code" do
147
+ include_examples "non-404 error code" do
148
+ let(:code) { nil }
149
+ end
150
+ end
151
+
152
+ end
153
+
154
+ context "the error is not an http error" do
155
+
156
+ it "logs the error" do
157
+ expect(error).to receive(:respond_to?).with(:response).and_return(false)
158
+ expect(Chef::Log).to receive(:error).with(/Failed to post audit report to server/)
159
+ reporter.run_completed(node)
160
+ end
161
+
162
+ end
163
+
164
+ context "when reporting url fatals are enabled" do
165
+
166
+ before do
167
+ allow(Chef::Config).to receive(:[]).
168
+ with(:enable_reporting_url_fatals).
169
+ and_return(true)
170
+ end
171
+
172
+ it "raises the error" do
173
+ expect(error).to receive(:respond_to?).with(:response).and_return(false)
174
+ allow(Chef::Log).to receive(:error).and_return(true)
175
+ expect(Chef::Log).to receive(:error).with(/Reporting fatals enabled. Aborting run./)
176
+ expect{ reporter.run_completed(node) }.to raise_error(error)
177
+ end
178
+
179
+ end
180
+ end
181
+ end
182
+
183
+ context "when auditing is not enabled" do
184
+
185
+ before do
186
+ allow(Chef::Log).to receive(:debug)
187
+ end
188
+
189
+ it "doesn't send reports" do
190
+ expect(reporter).to receive(:auditing_enabled?).and_return(false)
191
+ expect(Chef::Log).to receive(:debug).with("Audit Reports are disabled. Skipping sending reports.")
192
+ reporter.run_completed(node)
193
+ end
194
+
195
+ end
196
+
197
+ context "when the run fails before audits" do
198
+
199
+ before do
200
+ allow(Chef::Log).to receive(:debug)
201
+ end
202
+
203
+ it "doesn't send reports" do
204
+ expect(reporter).to receive(:auditing_enabled?).and_return(true)
205
+ expect(reporter).to receive(:run_status).and_return(nil)
206
+ expect(Chef::Log).to receive(:debug).with("Run failed before audits were initialized, not sending audit report to server")
207
+ reporter.run_completed(node)
208
+ end
209
+
210
+ end
211
+ end
212
+
213
+ describe "#run_failed" do
214
+
215
+ let(:audit_data) { Chef::Audit::AuditData.new(node.name, run_id) }
216
+ let(:run_data) { audit_data.to_hash }
217
+
218
+ let(:error) { double("AuditError", :class => "Chef::Exception::AuditError",
219
+ :message => "Well that certainly didn't work",
220
+ :backtrace => ["line 0", "line 1", "line 2"]) }
221
+
222
+ before do
223
+ allow(reporter).to receive(:auditing_enabled?).and_return(true)
224
+ allow(reporter).to receive(:run_status).and_return(run_status)
225
+ allow(reporter).to receive(:audit_data).and_return(audit_data)
226
+ allow(audit_data).to receive(:to_hash).and_return(run_data)
227
+ end
228
+
229
+ it "adds the error information to the reported data" do
230
+ expect(rest).to receive(:create_url)
231
+ expect(rest).to receive(:post)
232
+ reporter.run_failed(error)
233
+ expect(run_data).to have_key(:error)
234
+ expect(run_data[:error]).to eq "Chef::Exception::AuditError: Well that certainly didn't work\n" +
235
+ "line 0\nline 1\nline 2"
236
+ end
237
+
238
+ end
239
+
240
+ shared_context "audit data" do
241
+
242
+ let(:control_group_foo) { instance_double(Chef::Audit::ControlGroupData,
243
+ :metadata => double("foo metadata")) }
244
+ let(:control_group_bar) { instance_double(Chef::Audit::ControlGroupData,
245
+ :metadata => double("bar metadata")) }
246
+
247
+ let(:ordered_control_groups) {
248
+ {
249
+ "foo" => control_group_foo,
250
+ "bar" => control_group_bar
251
+ }
252
+ }
253
+
254
+ let(:audit_data) { instance_double(Chef::Audit::AuditData,
255
+ :add_control_group => true) }
256
+
257
+ let(:run_context) { instance_double(Chef::RunContext,
258
+ :audits => ordered_control_groups) }
259
+
260
+ before do
261
+ allow(reporter).to receive(:ordered_control_groups).and_return(ordered_control_groups)
262
+ allow(reporter).to receive(:audit_data).and_return(audit_data)
263
+ allow(reporter).to receive(:run_status).and_return(run_status)
264
+ allow(run_status).to receive(:run_context).and_return(run_context)
265
+ end
266
+ end
267
+
268
+ describe "#audit_phase_complete" do
269
+ include_context "audit data"
270
+
271
+ it "notifies audit phase finished to debug log" do
272
+ expect(Chef::Log).to receive(:debug).with(/Audit Reporter completed/)
273
+ reporter.audit_phase_complete
274
+ end
275
+
276
+ it "collects audit data" do
277
+ ordered_control_groups.each do |_name, group|
278
+ expect(audit_data).to receive(:add_control_group).with(group)
279
+ end
280
+ reporter.audit_phase_complete
281
+ end
282
+ end
283
+
284
+ describe "#audit_phase_failed" do
285
+ include_context "audit data"
286
+
287
+ let(:error) { double("Exception") }
288
+
289
+ it "notifies audit phase failed to debug log" do
290
+ expect(Chef::Log).to receive(:debug).with(/Audit Reporter failed/)
291
+ reporter.audit_phase_failed(error)
292
+ end
293
+
294
+ it "collects audit data" do
295
+ ordered_control_groups.each do |_name, group|
296
+ expect(audit_data).to receive(:add_control_group).with(group)
297
+ end
298
+ reporter.audit_phase_failed(error)
299
+ end
300
+ end
301
+
302
+ describe "#control_group_started" do
303
+ include_context "audit data"
304
+
305
+ let(:name) { "bat" }
306
+ let(:control_group) { instance_double(Chef::Audit::ControlGroupData,
307
+ :metadata => double("metadata")) }
308
+
309
+ before do
310
+ allow(Chef::Audit::ControlGroupData).to receive(:new).
311
+ with(name, control_group.metadata).
312
+ and_return(control_group)
313
+ end
314
+
315
+ it "stores the control group" do
316
+ expect(ordered_control_groups).to receive(:has_key?).with(name).and_return(false)
317
+ allow(run_context.audits).to receive(:[]).with(name).and_return(control_group)
318
+ expect(ordered_control_groups).to receive(:store).
319
+ with(name, control_group).
320
+ and_call_original
321
+ reporter.control_group_started(name)
322
+ # stubbed :has_key? above, which is used by the have_key matcher,
323
+ # so instead we check the response to Hash's #key? because luckily
324
+ # #key? does not call #has_key?
325
+ expect(ordered_control_groups.key?(name)).to be true
326
+ expect(ordered_control_groups[name]).to eq control_group
327
+ end
328
+
329
+ context "when a control group with the same name has been seen" do
330
+ it "raises an exception" do
331
+ expect(ordered_control_groups).to receive(:has_key?).with(name).and_return(true)
332
+ expect{ reporter.control_group_started(name) }.to raise_error(Chef::Exceptions::AuditControlGroupDuplicate)
333
+ end
334
+ end
335
+ end
336
+
337
+ describe "#control_example_success" do
338
+ include_context "audit data"
339
+
340
+ let(:name) { "foo" }
341
+ let(:example_data) { double("example data") }
342
+
343
+ it "notifies the control group the example succeeded" do
344
+ expect(control_group_foo).to receive(:example_success).with(example_data)
345
+ reporter.control_example_success(name, example_data)
346
+ end
347
+ end
348
+
349
+ describe "#control_example_failure" do
350
+ include_context "audit data"
351
+
352
+ let(:name) { "bar" }
353
+ let(:example_data) { double("example data") }
354
+ let(:error) { double("Exception", :message => "oopsie") }
355
+
356
+ it "notifies the control group the example failed" do
357
+ expect(control_group_bar).to receive(:example_failure).
358
+ with(example_data, error.message)
359
+ reporter.control_example_failure(name, example_data, error)
360
+ end
361
+ end
362
+
363
+ describe "#auditing_enabled?" do
364
+ shared_examples "enabled?" do |true_or_false|
365
+
366
+ it "returns #{true_or_false}" do
367
+ expect(Chef::Config).to receive(:[]).
368
+ with(:audit_mode).
369
+ and_return(audit_setting)
370
+ expect(reporter.auditing_enabled?).to be true_or_false
371
+ end
372
+ end
373
+
374
+ context "when auditing is disabled" do
375
+ include_examples "enabled?", false do
376
+ let(:audit_setting) { :disabled }
377
+ end
378
+ end
379
+
380
+ context "when auditing in audit-only mode" do
381
+ include_examples "enabled?", true do
382
+ let(:audit_setting) { :audit_only }
383
+ end
384
+ end
385
+
386
+ context "when auditing is enabled" do
387
+ include_examples "enabled?", true do
388
+ let(:audit_setting) { :enabled }
389
+ end
390
+ end
391
+ end
392
+
393
+ end