chef 12.4.3-universal-mingw32 → 12.5.1-universal-mingw32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (320) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +21 -25
  3. data/Gemfile +46 -0
  4. data/README.md +4 -4
  5. data/Rakefile +4 -110
  6. data/bin/chef-service-manager +3 -1
  7. data/distro/common/html/knife_cookbook_site.html +18 -18
  8. data/distro/common/man/man1/knife-cookbook-site.1 +11 -11
  9. data/lib/chef.rb +1 -1
  10. data/lib/chef/application.rb +1 -1
  11. data/lib/chef/application/apply.rb +19 -1
  12. data/lib/chef/application/client.rb +11 -5
  13. data/lib/chef/application/knife.rb +2 -2
  14. data/lib/chef/application/solo.rb +1 -1
  15. data/lib/chef/application/windows_service_manager.rb +19 -12
  16. data/lib/chef/chef_class.rb +46 -0
  17. data/lib/chef/chef_fs/config.rb +22 -24
  18. data/lib/chef/chef_fs/data_handler/client_data_handler.rb +3 -1
  19. data/lib/chef/chef_fs/file_pattern.rb +4 -15
  20. data/lib/chef/chef_fs/file_system/acl_dir.rb +3 -4
  21. data/lib/chef/chef_fs/file_system/acls_dir.rb +5 -1
  22. data/lib/chef/chef_fs/file_system/base_fs_dir.rb +0 -5
  23. data/lib/chef/chef_fs/file_system/base_fs_object.rb +5 -2
  24. data/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbook_dir.rb +2 -9
  25. data/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbook_entry.rb +2 -9
  26. data/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbooks_dir.rb +10 -17
  27. data/lib/chef/chef_fs/file_system/chef_repository_file_system_entry.rb +1 -12
  28. data/lib/chef/chef_fs/file_system/chef_repository_file_system_root_dir.rb +15 -11
  29. data/lib/chef/chef_fs/file_system/chef_server_root_dir.rb +8 -2
  30. data/lib/chef/chef_fs/file_system/cookbook_dir.rb +4 -4
  31. data/lib/chef/chef_fs/file_system/cookbooks_acl_dir.rb +1 -1
  32. data/lib/chef/chef_fs/file_system/cookbooks_dir.rb +3 -11
  33. data/lib/chef/chef_fs/file_system/data_bags_dir.rb +3 -5
  34. data/lib/chef/chef_fs/file_system/environments_dir.rb +1 -1
  35. data/lib/chef/chef_fs/file_system/file_system_entry.rb +7 -4
  36. data/lib/chef/chef_fs/file_system/memory_dir.rb +2 -3
  37. data/lib/chef/chef_fs/file_system/multiplexed_dir.rb +15 -0
  38. data/lib/chef/chef_fs/file_system/nodes_dir.rb +1 -1
  39. data/lib/chef/chef_fs/file_system/organization_members_entry.rb +2 -2
  40. data/lib/chef/chef_fs/file_system/rest_list_dir.rb +4 -9
  41. data/lib/chef/chef_fs/knife.rb +35 -7
  42. data/lib/chef/chef_fs/path_utils.rb +65 -34
  43. data/lib/chef/client.rb +2 -3
  44. data/lib/chef/config.rb +34 -2
  45. data/lib/chef/{mixin/wstring.rb → constants.rb} +9 -13
  46. data/lib/chef/cookbook/metadata.rb +25 -3
  47. data/lib/chef/cookbook/synchronizer.rb +1 -1
  48. data/lib/chef/cookbook_site_streaming_uploader.rb +1 -1
  49. data/lib/chef/cookbook_version.rb +3 -3
  50. data/lib/chef/delayed_evaluator.rb +21 -0
  51. data/lib/chef/deprecation/mixin/template.rb +1 -2
  52. data/lib/chef/deprecation/provider/cookbook_file.rb +1 -1
  53. data/lib/chef/deprecation/provider/file.rb +1 -1
  54. data/lib/chef/deprecation/provider/remote_directory.rb +52 -0
  55. data/lib/chef/deprecation/provider/remote_file.rb +1 -2
  56. data/lib/chef/deprecation/provider/template.rb +1 -1
  57. data/lib/chef/deprecation/warnings.rb +3 -4
  58. data/lib/chef/dsl/reboot_pending.rb +3 -2
  59. data/lib/chef/dsl/recipe.rb +26 -7
  60. data/lib/chef/dsl/resources.rb +2 -2
  61. data/lib/chef/event_dispatch/base.rb +51 -22
  62. data/lib/chef/event_dispatch/dispatcher.rb +21 -6
  63. data/lib/chef/event_dispatch/dsl.rb +64 -0
  64. data/lib/chef/exceptions.rb +28 -1
  65. data/lib/chef/file_content_management/tempfile.rb +1 -1
  66. data/lib/chef/formatters/base.rb +3 -0
  67. data/lib/chef/formatters/doc.rb +56 -6
  68. data/lib/chef/formatters/error_inspectors/compile_error_inspector.rb +36 -0
  69. data/lib/chef/formatters/minimal.rb +2 -2
  70. data/lib/chef/guard_interpreter/resource_guard_interpreter.rb +3 -1
  71. data/lib/chef/http/http_request.rb +1 -1
  72. data/lib/chef/knife.rb +35 -55
  73. data/lib/chef/knife/bootstrap.rb +41 -0
  74. data/lib/chef/knife/bootstrap/chef_vault_handler.rb +1 -0
  75. data/lib/chef/knife/bootstrap/client_builder.rb +16 -0
  76. data/lib/chef/knife/bootstrap/templates/README.md +3 -4
  77. data/lib/chef/knife/bootstrap/templates/chef-full.erb +1 -1
  78. data/lib/chef/knife/cookbook_create.rb +1 -1
  79. data/lib/chef/knife/cookbook_site_download.rb +1 -1
  80. data/lib/chef/knife/cookbook_site_install.rb +1 -1
  81. data/lib/chef/knife/cookbook_site_share.rb +6 -6
  82. data/lib/chef/knife/cookbook_site_unshare.rb +2 -2
  83. data/lib/chef/knife/core/bootstrap_context.rb +12 -4
  84. data/lib/chef/knife/core/custom_manifest_loader.rb +69 -0
  85. data/lib/chef/knife/core/gem_glob_loader.rb +138 -0
  86. data/lib/chef/knife/core/hashed_command_loader.rb +80 -0
  87. data/lib/chef/knife/core/node_presenter.rb +24 -1
  88. data/lib/chef/knife/core/object_loader.rb +1 -0
  89. data/lib/chef/knife/core/subcommand_loader.rb +131 -146
  90. data/lib/chef/knife/node_run_list_remove.rb +12 -1
  91. data/lib/chef/knife/null.rb +10 -0
  92. data/lib/chef/knife/rehash.rb +62 -0
  93. data/lib/chef/knife/search.rb +3 -3
  94. data/lib/chef/knife/ssh.rb +52 -30
  95. data/lib/chef/knife/ssl_check.rb +3 -2
  96. data/lib/chef/knife/user_edit.rb +1 -2
  97. data/lib/chef/local_mode.rb +5 -0
  98. data/lib/chef/log.rb +5 -1
  99. data/lib/chef/mixin/deprecation.rb +8 -8
  100. data/lib/chef/mixin/params_validate.rb +362 -135
  101. data/lib/chef/mixin/template.rb +48 -0
  102. data/lib/chef/mixin/which.rb +1 -1
  103. data/lib/chef/mixin/wide_string.rb +72 -0
  104. data/lib/chef/mixin/windows_architecture_helper.rb +15 -39
  105. data/lib/chef/mixin/windows_env_helper.rb +4 -1
  106. data/lib/chef/monkey_patches/webrick-utils.rb +51 -0
  107. data/lib/chef/monkey_patches/win32/registry.rb +72 -0
  108. data/lib/chef/node.rb +116 -3
  109. data/lib/chef/node_map.rb +2 -2
  110. data/lib/chef/platform/handler_map.rb +0 -5
  111. data/lib/chef/platform/provider_mapping.rb +5 -6
  112. data/lib/chef/platform/query_helpers.rb +46 -4
  113. data/lib/chef/platform/rebooter.rb +1 -1
  114. data/lib/chef/platform/service_helpers.rb +30 -32
  115. data/lib/chef/policy_builder.rb +1 -8
  116. data/lib/chef/policy_builder/dynamic.rb +186 -0
  117. data/lib/chef/policy_builder/expand_node_object.rb +30 -15
  118. data/lib/chef/policy_builder/policyfile.rb +155 -18
  119. data/lib/chef/property.rb +568 -0
  120. data/lib/chef/provider.rb +222 -13
  121. data/lib/chef/provider/batch.rb +8 -0
  122. data/lib/chef/provider/deploy.rb +5 -7
  123. data/lib/chef/provider/directory.rb +14 -2
  124. data/lib/chef/provider/dsc_resource.rb +5 -9
  125. data/lib/chef/provider/group/pw.rb +1 -1
  126. data/lib/chef/provider/ifconfig.rb +2 -2
  127. data/lib/chef/provider/lwrp_base.rb +1 -75
  128. data/lib/chef/provider/mount.rb +7 -3
  129. data/lib/chef/provider/package.rb +1 -1
  130. data/lib/chef/provider/package/dpkg.rb +5 -11
  131. data/lib/chef/provider/package/rpm.rb +2 -2
  132. data/lib/chef/provider/package/rubygems.rb +1 -1
  133. data/lib/chef/provider/package/windows/msi.rb +2 -2
  134. data/lib/chef/provider/package/yum.rb +17 -5
  135. data/lib/chef/provider/powershell_script.rb +59 -23
  136. data/lib/chef/provider/registry_key.rb +5 -5
  137. data/lib/chef/provider/remote_directory.rb +190 -102
  138. data/lib/chef/provider/service.rb +12 -2
  139. data/lib/chef/provider/service/aix.rb +1 -1
  140. data/lib/chef/provider/service/debian.rb +3 -5
  141. data/lib/chef/provider/service/freebsd.rb +1 -1
  142. data/lib/chef/provider/service/gentoo.rb +3 -3
  143. data/lib/chef/provider/service/init.rb +3 -3
  144. data/lib/chef/provider/service/insserv.rb +2 -4
  145. data/lib/chef/provider/service/invokercd.rb +2 -4
  146. data/lib/chef/provider/service/macosx.rb +5 -1
  147. data/lib/chef/provider/service/openbsd.rb +2 -1
  148. data/lib/chef/provider/service/redhat.rb +52 -16
  149. data/lib/chef/provider/service/simple.rb +2 -2
  150. data/lib/chef/provider/service/systemd.rb +3 -5
  151. data/lib/chef/provider/service/upstart.rb +4 -6
  152. data/lib/chef/provider/subversion.rb +13 -7
  153. data/lib/chef/provider/template/content.rb +16 -6
  154. data/lib/chef/provider/user/solaris.rb +32 -4
  155. data/lib/chef/provider/windows_script.rb +3 -5
  156. data/lib/chef/provider_resolver.rb +2 -2
  157. data/lib/chef/recipe.rb +1 -8
  158. data/lib/chef/resource.rb +563 -90
  159. data/lib/chef/resource/action_class.rb +83 -0
  160. data/lib/chef/resource/chef_gem.rb +3 -3
  161. data/lib/chef/resource/deploy.rb +8 -2
  162. data/lib/chef/resource/dsc_script.rb +2 -0
  163. data/lib/chef/resource/file/verification.rb +7 -1
  164. data/lib/chef/resource/lwrp_base.rb +1 -7
  165. data/lib/chef/resource/registry_key.rb +1 -1
  166. data/lib/chef/resource/service.rb +10 -2
  167. data/lib/chef/resource/subversion.rb +5 -0
  168. data/lib/chef/resource/windows_script.rb +6 -2
  169. data/lib/chef/resource/yum_package.rb +10 -1
  170. data/lib/chef/resource_resolver.rb +3 -3
  171. data/lib/chef/run_context.rb +402 -83
  172. data/lib/chef/run_list/versioned_recipe_list.rb +15 -0
  173. data/lib/chef/run_lock.rb +30 -21
  174. data/lib/chef/util/powershell/ps_credential.rb +4 -0
  175. data/lib/chef/util/windows.rb +0 -32
  176. data/lib/chef/util/windows/net_group.rb +85 -106
  177. data/lib/chef/util/windows/net_use.rb +35 -71
  178. data/lib/chef/util/windows/net_user.rb +0 -1
  179. data/lib/chef/util/windows/volume.rb +19 -19
  180. data/lib/chef/version.rb +3 -3
  181. data/lib/chef/win32/api.rb +1 -0
  182. data/lib/chef/win32/api/file.rb +20 -0
  183. data/lib/chef/win32/api/net.rb +163 -43
  184. data/lib/chef/win32/api/registry.rb +51 -0
  185. data/lib/chef/win32/api/system.rb +23 -0
  186. data/lib/chef/win32/api/unicode.rb +0 -43
  187. data/lib/chef/win32/crypto.rb +2 -1
  188. data/lib/chef/win32/file.rb +28 -3
  189. data/lib/chef/win32/mutex.rb +1 -2
  190. data/lib/chef/win32/net.rb +162 -8
  191. data/lib/chef/win32/process.rb +13 -0
  192. data/lib/chef/win32/registry.rb +35 -30
  193. data/lib/chef/win32/security.rb +1 -1
  194. data/lib/chef/win32/security/token.rb +1 -1
  195. data/lib/chef/win32/system.rb +62 -0
  196. data/lib/chef/win32/unicode.rb +7 -2
  197. data/lib/chef/win32/version.rb +0 -4
  198. data/lib/chef/workstation_config_loader.rb +3 -158
  199. data/spec/data/cookbooks/openldap/templates/default/helpers.erb +14 -0
  200. data/spec/data/cookbooks/openldap/templates/default/nested_openldap_partials.erb +1 -0
  201. data/spec/data/cookbooks/openldap/templates/default/nested_partial.erb +1 -0
  202. data/spec/data/dsc_lcm.pfx +0 -0
  203. data/spec/data/run_context/cookbooks/include/recipes/default.rb +24 -0
  204. data/spec/data/run_context/cookbooks/include/recipes/includee.rb +3 -0
  205. data/spec/functional/dsl/reboot_pending_spec.rb +33 -43
  206. data/spec/functional/knife/cookbook_delete_spec.rb +17 -7
  207. data/spec/functional/knife/ssh_spec.rb +16 -0
  208. data/spec/functional/rebooter_spec.rb +1 -1
  209. data/spec/functional/resource/deploy_revision_spec.rb +1 -1
  210. data/spec/functional/resource/dsc_resource_spec.rb +2 -0
  211. data/spec/functional/resource/dsc_script_spec.rb +91 -2
  212. data/spec/functional/resource/group_spec.rb +67 -44
  213. data/spec/functional/resource/{powershell_spec.rb → powershell_script_spec.rb} +107 -18
  214. data/spec/functional/resource/windows_service_spec.rb +1 -1
  215. data/spec/functional/run_lock_spec.rb +368 -189
  216. data/spec/functional/win32/{registry_helper_spec.rb → registry_spec.rb} +16 -23
  217. data/spec/functional/win32/service_manager_spec.rb +2 -2
  218. data/spec/integration/client/client_spec.rb +51 -0
  219. data/spec/integration/knife/chef_repo_path_spec.rb +13 -11
  220. data/spec/integration/knife/download_spec.rb +4 -0
  221. data/spec/integration/knife/list_spec.rb +8 -0
  222. data/spec/integration/knife/upload_spec.rb +1 -1
  223. data/spec/integration/recipes/recipe_dsl_spec.rb +1 -16
  224. data/spec/integration/recipes/remote_directory.rb +74 -0
  225. data/spec/integration/recipes/resource_action_spec.rb +363 -0
  226. data/spec/integration/recipes/resource_converge_if_changed_spec.rb +423 -0
  227. data/spec/integration/recipes/resource_load_spec.rb +206 -0
  228. data/spec/spec_helper.rb +9 -0
  229. data/spec/support/platform_helpers.rb +13 -0
  230. data/spec/support/shared/context/win32.rb +34 -0
  231. data/spec/support/shared/functional/win32_service.rb +2 -1
  232. data/spec/support/shared/functional/windows_script.rb +63 -26
  233. data/spec/support/shared/unit/mock_shellout.rb +46 -0
  234. data/spec/support/shared/unit/provider/file.rb +10 -4
  235. data/spec/unit/application/client_spec.rb +16 -3
  236. data/spec/unit/application/knife_spec.rb +2 -2
  237. data/spec/unit/application/solo_spec.rb +4 -3
  238. data/spec/unit/chef_class_spec.rb +23 -4
  239. data/spec/unit/chef_fs/path_util_spec.rb +108 -0
  240. data/spec/unit/client_spec.rb +6 -1
  241. data/spec/unit/config_spec.rb +31 -0
  242. data/spec/unit/cookbook/metadata_spec.rb +23 -3
  243. data/spec/unit/cookbook/syntax_check_spec.rb +3 -0
  244. data/spec/unit/deprecation_spec.rb +3 -6
  245. data/spec/unit/dsl/reboot_pending_spec.rb +12 -6
  246. data/spec/unit/event_dispatch/dispatcher_spec.rb +65 -3
  247. data/spec/unit/event_dispatch/dsl_spec.rb +83 -0
  248. data/spec/unit/formatters/doc_spec.rb +32 -0
  249. data/spec/unit/formatters/error_inspectors/compile_error_inspector_spec.rb +26 -0
  250. data/spec/unit/json_compat_spec.rb +4 -3
  251. data/spec/unit/knife/bootstrap/client_builder_spec.rb +27 -0
  252. data/spec/unit/knife/bootstrap_spec.rb +55 -3
  253. data/spec/unit/knife/cookbook_site_share_spec.rb +3 -3
  254. data/spec/unit/knife/core/bootstrap_context_spec.rb +21 -4
  255. data/spec/unit/knife/core/custom_manifest_loader_spec.rb +41 -0
  256. data/spec/unit/knife/core/gem_glob_loader_spec.rb +210 -0
  257. data/spec/unit/knife/core/hashed_command_loader_spec.rb +93 -0
  258. data/spec/unit/knife/core/subcommand_loader_spec.rb +16 -192
  259. data/spec/unit/knife/node_run_list_remove_spec.rb +17 -0
  260. data/spec/unit/knife/ssl_check_spec.rb +4 -0
  261. data/spec/unit/mixin/enforce_ownership_and_permissions_spec.rb +10 -10
  262. data/spec/unit/mixin/params_validate_spec.rb +4 -2
  263. data/spec/unit/mixin/template_spec.rb +5 -1
  264. data/spec/unit/mixin/windows_architecture_helper_spec.rb +13 -8
  265. data/spec/unit/node_spec.rb +220 -0
  266. data/spec/unit/platform/query_helpers_spec.rb +146 -3
  267. data/spec/unit/policy_builder/dynamic_spec.rb +275 -0
  268. data/spec/unit/policy_builder/expand_node_object_spec.rb +37 -38
  269. data/spec/unit/policy_builder/policyfile_spec.rb +260 -46
  270. data/spec/unit/property/state_spec.rb +506 -0
  271. data/spec/unit/property/validation_spec.rb +663 -0
  272. data/spec/unit/property_spec.rb +1094 -0
  273. data/spec/unit/provider/deploy_spec.rb +5 -5
  274. data/spec/unit/provider/directory_spec.rb +35 -0
  275. data/spec/unit/provider/dsc_resource_spec.rb +3 -10
  276. data/spec/unit/provider/ifconfig_spec.rb +22 -2
  277. data/spec/unit/provider/mount/aix_spec.rb +2 -1
  278. data/spec/unit/provider/mount/mount_spec.rb +6 -0
  279. data/spec/unit/provider/mount/windows_spec.rb +14 -0
  280. data/spec/unit/provider/mount_spec.rb +12 -1
  281. data/spec/unit/provider/package/dpkg_spec.rb +8 -1
  282. data/spec/unit/provider/package/rpm_spec.rb +18 -1
  283. data/spec/unit/provider/package/rubygems_spec.rb +18 -0
  284. data/spec/unit/provider/package/yum_spec.rb +97 -24
  285. data/spec/unit/provider/powershell_script_spec.rb +106 -0
  286. data/spec/unit/provider/registry_key_spec.rb +12 -0
  287. data/spec/unit/provider/remote_directory_spec.rb +1 -2
  288. data/spec/unit/provider/service/aix_service_spec.rb +3 -3
  289. data/spec/unit/provider/service/gentoo_service_spec.rb +4 -4
  290. data/spec/unit/provider/service/macosx_spec.rb +4 -4
  291. data/spec/unit/provider/service/openbsd_service_spec.rb +10 -8
  292. data/spec/unit/provider/service/redhat_spec.rb +88 -8
  293. data/spec/unit/provider/service/upstart_service_spec.rb +11 -7
  294. data/spec/unit/provider/service/windows_spec.rb +211 -200
  295. data/spec/unit/provider/subversion_spec.rb +50 -31
  296. data/spec/unit/provider/template/content_spec.rb +93 -2
  297. data/spec/unit/provider/user/solaris_spec.rb +66 -9
  298. data/spec/unit/provider_resolver_spec.rb +707 -650
  299. data/spec/unit/provider_spec.rb +1 -3
  300. data/spec/unit/recipe_spec.rb +0 -4
  301. data/spec/unit/resource/deploy_spec.rb +7 -1
  302. data/spec/unit/resource/dsc_script_spec.rb +4 -0
  303. data/spec/unit/resource/file/verification_spec.rb +33 -5
  304. data/spec/unit/resource/{powershell_spec.rb → powershell_script_spec.rb} +17 -13
  305. data/spec/unit/resource/service_spec.rb +4 -4
  306. data/spec/unit/resource/subversion_spec.rb +4 -0
  307. data/spec/unit/resource/yum_package_spec.rb +10 -1
  308. data/spec/unit/resource_spec.rb +2 -2
  309. data/spec/unit/run_context/child_run_context_spec.rb +133 -0
  310. data/spec/unit/run_context_spec.rb +7 -0
  311. data/spec/unit/run_list/versioned_recipe_list_spec.rb +5 -0
  312. data/spec/unit/win32/registry_spec.rb +394 -0
  313. data/tasks/external_tests.rb +47 -23
  314. data/tasks/maintainers.rb +155 -14
  315. metadata +64 -53
  316. data/lib/chef/knife/bootstrap/templates/archlinux-gems.erb +0 -76
  317. data/lib/chef/knife/bootstrap/templates/chef-aix.erb +0 -72
  318. data/spec/unit/provider/powershell_spec.rb +0 -80
  319. data/spec/unit/registry_helper_spec.rb +0 -376
  320. data/spec/unit/workstation_config_loader_spec.rb +0 -283
@@ -84,6 +84,23 @@ describe Chef::Knife::NodeRunListRemove do
84
84
  expect(@node.run_list).not_to include('role[monkey]')
85
85
  expect(@node.run_list).not_to include('recipe[duck::type]')
86
86
  end
87
+
88
+ it "should warn when the thing to remove is not in the runlist" do
89
+ @node.run_list << 'role[blah]'
90
+ @node.run_list << 'recipe[duck::type]'
91
+ @knife.name_args = [ 'adam', 'role[blork]' ]
92
+ expect(@knife.ui).to receive(:warn).with("role[blork] is not in the run list")
93
+ @knife.run
94
+ end
95
+
96
+ it "should warn even more when the thing to remove is not in the runlist and unqualified" do
97
+ @node.run_list << 'role[blah]'
98
+ @node.run_list << 'recipe[duck::type]'
99
+ @knife.name_args = [ 'adam', 'blork' ]
100
+ expect(@knife.ui).to receive(:warn).with("blork is not in the run list")
101
+ expect(@knife.ui).to receive(:warn).with(/did you forget recipe\[\] or role\[\]/)
102
+ @knife.run
103
+ end
87
104
  end
88
105
  end
89
106
  end
@@ -163,6 +163,7 @@ E
163
163
  expect(ssl_check).to receive(:verify_X509).and_return(true) # X509 valid certs (no warn)
164
164
  expect(ssl_socket).to receive(:connect) # no error
165
165
  expect(ssl_socket).to receive(:post_connection_check).with("foo.example.com") # no error
166
+ expect(ssl_socket).to receive(:hostname=).with("foo.example.com") # no error
166
167
  end
167
168
 
168
169
  it "prints a success message" do
@@ -197,6 +198,7 @@ E
197
198
  expect(ssl_socket).to receive(:post_connection_check).
198
199
  with("foo.example.com").
199
200
  and_raise(OpenSSL::SSL::SSLError)
201
+ expect(ssl_socket).to receive(:hostname=).with("foo.example.com") # no error
200
202
  expect(ssl_socket_for_debug).to receive(:connect)
201
203
  expect(ssl_socket_for_debug).to receive(:peer_cert).and_return(self_signed_crt)
202
204
  end
@@ -215,6 +217,8 @@ E
215
217
  expect(ssl_check).to receive(:verify_X509).and_return(true) # X509 valid certs
216
218
  expect(ssl_socket).to receive(:connect).
217
219
  and_raise(OpenSSL::SSL::SSLError)
220
+ expect(ssl_socket).to receive(:hostname=).
221
+ with("foo.example.com") # no error
218
222
  expect(ssl_socket_for_debug).to receive(:connect)
219
223
  expect(ssl_socket_for_debug).to receive(:peer_cert).and_return(self_signed_crt)
220
224
  end
@@ -49,12 +49,12 @@ describe Chef::Mixin::EnforceOwnershipAndPermissions do
49
49
  allow_any_instance_of(Chef::FileAccessControl).to receive(:uid_from_resource).and_return(0)
50
50
  allow_any_instance_of(Chef::FileAccessControl).to receive(:requires_changes?).and_return(false)
51
51
  allow_any_instance_of(Chef::FileAccessControl).to receive(:define_resource_requirements)
52
+ allow_any_instance_of(Chef::FileAccessControl).to receive(:describe_changes)
53
+
54
+ passwd_struct = OpenStruct.new(:name => "root", :passwd => "x",
55
+ :uid => 0, :gid => 0, :dir => '/root',
56
+ :shell => '/bin/bash')
52
57
 
53
- passwd_struct = if windows?
54
- Struct::Passwd.new("root", "x", 0, 0, "/root", "/bin/bash")
55
- else
56
- Struct::Passwd.new("root", "x", 0, 0, "root", "/root", "/bin/bash")
57
- end
58
58
  group_struct = OpenStruct.new(:name => "root", :passwd => "x", :gid => 0)
59
59
  allow(Etc).to receive(:getpwuid).and_return(passwd_struct)
60
60
  allow(Etc).to receive(:getgrgid).and_return(group_struct)
@@ -73,12 +73,12 @@ describe Chef::Mixin::EnforceOwnershipAndPermissions do
73
73
  before do
74
74
  allow_any_instance_of(Chef::FileAccessControl).to receive(:requires_changes?).and_return(true)
75
75
  allow_any_instance_of(Chef::FileAccessControl).to receive(:uid_from_resource).and_return(0)
76
+ allow_any_instance_of(Chef::FileAccessControl).to receive(:describe_changes)
77
+
78
+ passwd_struct = OpenStruct.new(:name => "root", :passwd => "x",
79
+ :uid => 0, :gid => 0, :dir => '/root',
80
+ :shell => '/bin/bash')
76
81
 
77
- passwd_struct = if windows?
78
- Struct::Passwd.new("root", "x", 0, 0, "/root", "/bin/bash")
79
- else
80
- Struct::Passwd.new("root", "x", 0, 0, "root", "/root", "/bin/bash")
81
- end
82
82
  group_struct = OpenStruct.new(:name => "root", :passwd => "x", :gid => 0)
83
83
  allow(Etc).to receive(:getpwuid).and_return(passwd_struct)
84
84
  allow(Etc).to receive(:getgrgid).and_return(group_struct)
@@ -21,6 +21,8 @@ require 'spec_helper'
21
21
  class TinyClass
22
22
  include Chef::Mixin::ParamsValidate
23
23
 
24
+ attr_reader :name
25
+
24
26
  def music(is_good=true)
25
27
  is_good
26
28
  end
@@ -331,11 +333,11 @@ describe Chef::Mixin::ParamsValidate do
331
333
  it "asserts that a value returns false from a predicate method" do
332
334
  expect do
333
335
  @vo.validate({:not_blank => "should pass"},
334
- {:not_blank => {:cannot_be => :nil, :cannot_be => :empty}})
336
+ {:not_blank => {:cannot_be => [ :nil, :empty ]}})
335
337
  end.not_to raise_error
336
338
  expect do
337
339
  @vo.validate({:not_blank => ""},
338
- {:not_blank => {:cannot_be => :nil, :cannot_be => :empty}})
340
+ {:not_blank => {:cannot_be => [ :nil, :empty ]}})
339
341
  end.to raise_error(Chef::Exceptions::ValidationFailed)
340
342
  end
341
343
 
@@ -150,6 +150,11 @@ describe Chef::Mixin::Template, "render_template" do
150
150
  output == "before {super secret is candy} after"
151
151
  end
152
152
 
153
+ it "should pass the template finder to the partials" do
154
+ output = @template_context.render_template_from_string("before {<%= render 'nested_openldap_partials.erb', :variables => {:hello => 'Hello World!' } %>} after")
155
+ output == "before {Hello World!} after"
156
+ end
157
+
153
158
  it "should pass variables to partials" do
154
159
  output = @template_context.render_template_from_string("before {<%= render 'openldap_variable_stuff.conf.erb', :variables => {:secret => 'whatever' } %>} after")
155
160
  expect(output).to eq("before {super secret is whatever} after")
@@ -266,4 +271,3 @@ describe Chef::Mixin::Template, "render_template" do
266
271
  end
267
272
  end
268
273
  end
269
-
@@ -60,23 +60,28 @@ describe Chef::Mixin::WindowsArchitectureHelper do
60
60
  end
61
61
  end
62
62
 
63
- it "returns true for each supported desired architecture for all nodes with each valid architecture passed to node_supports_windows_architecture" do
64
- enumerate_architecture_node_combinations(true)
63
+ it "returns true only for supported desired architecture passed to node_supports_windows_architecture" do
64
+ with_node_architecture_combinations do | node, desired_arch |
65
+ expect(node_supports_windows_architecture?(node, desired_arch)).to be true if (node_windows_architecture(node) == :x86_64 || desired_arch == :i386 )
66
+ expect(node_supports_windows_architecture?(node, desired_arch)).to be false if (node_windows_architecture(node) == :i386 && desired_arch == :x86_64 )
67
+ end
65
68
  end
66
69
 
67
- it "returns false for each unsupported desired architecture for all nodes with each valid architecture passed to node_supports_windows_architecture?" do
68
- enumerate_architecture_node_combinations(true)
70
+ it "returns true only when forced_32bit_override_required? has 64-bit node architecture and 32-bit desired architecture" do
71
+ with_node_architecture_combinations do | node, desired_arch |
72
+ expect(forced_32bit_override_required?(node, desired_arch)).to be true if ((node_windows_architecture(node) == :x86_64) && (desired_arch == :i386) && !is_i386_process_on_x86_64_windows?)
73
+ expect(forced_32bit_override_required?(node, desired_arch)).to be false if ! ((node_windows_architecture(node) == :x86_64) && (desired_arch == :i386))
74
+ end
69
75
  end
70
76
 
71
- def enumerate_architecture_node_combinations(only_valid_combinations)
77
+ def with_node_architecture_combinations
72
78
  @valid_architectures.each do | node_architecture |
73
79
  new_node = Chef::Node.new
74
80
  new_node.default["kernel"] = Hash.new
75
81
  new_node.default["kernel"][:machine] = node_architecture.to_s
76
82
 
77
- @valid_architectures.each do | supported_architecture |
78
- expect(node_supports_windows_architecture?(new_node, supported_architecture)).to eq(true) if only_valid_combinations && (supported_architecture != :x86_64 && node_architecture != :i386 )
79
- expect(node_supports_windows_architecture?(new_node, supported_architecture)).to eq(false) if ! only_valid_combinations && (supported_architecture == :x86_64 && node_architecture == :i386 )
83
+ @valid_architectures.each do | architecture |
84
+ yield new_node, architecture if block_given?
80
85
  end
81
86
  end
82
87
  end
@@ -127,6 +127,78 @@ describe Chef::Node do
127
127
  end
128
128
  end
129
129
 
130
+ describe "policy_name" do
131
+
132
+ it "defaults to nil" do
133
+ expect(node.policy_name).to be_nil
134
+ end
135
+
136
+ it "sets policy_name with a regular setter" do
137
+ node.policy_name = "example-policy"
138
+ expect(node.policy_name).to eq("example-policy")
139
+ end
140
+
141
+ it "allows policy_name with every valid character" do
142
+ expect { node.policy_name = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqurstuvwxyz0123456789-_:.' }.to_not raise_error
143
+ end
144
+
145
+ it "sets policy_name when given an argument" do
146
+ node.policy_name("example-policy")
147
+ expect(node.policy_name).to eq("example-policy")
148
+ end
149
+
150
+ it "sets policy_name to nil when given nil" do
151
+ node.policy_name = "example-policy"
152
+ node.policy_name = nil
153
+ expect(node.policy_name).to be_nil
154
+ end
155
+
156
+ it "disallows non-strings" do
157
+ expect { node.policy_name(Hash.new) }.to raise_error(Chef::Exceptions::ValidationFailed)
158
+ expect { node.policy_name(42) }.to raise_error(Chef::Exceptions::ValidationFailed)
159
+ end
160
+
161
+ it "cannot be blank" do
162
+ expect { node.policy_name("")}.to raise_error(Chef::Exceptions::ValidationFailed)
163
+ end
164
+ end
165
+
166
+ describe "policy_group" do
167
+
168
+ it "defaults to nil" do
169
+ expect(node.policy_group).to be_nil
170
+ end
171
+
172
+ it "sets policy_group with a regular setter" do
173
+ node.policy_group = "staging"
174
+ expect(node.policy_group).to eq("staging")
175
+ end
176
+
177
+ it "allows policy_group with every valid character" do
178
+ expect { node.policy_group = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqurstuvwxyz0123456789-_:.' }.to_not raise_error
179
+ end
180
+
181
+ it "sets an environment with chef_environment(something)" do
182
+ node.policy_group("staging")
183
+ expect(node.policy_group).to eq("staging")
184
+ end
185
+
186
+ it "sets policy_group to nil when given nil" do
187
+ node.policy_group = "staging"
188
+ node.policy_group = nil
189
+ expect(node.policy_group).to be_nil
190
+ end
191
+
192
+ it "disallows non-strings" do
193
+ expect { node.policy_group(Hash.new) }.to raise_error(Chef::Exceptions::ValidationFailed)
194
+ expect { node.policy_group(42) }.to raise_error(Chef::Exceptions::ValidationFailed)
195
+ end
196
+
197
+ it "cannot be blank" do
198
+ expect { node.policy_group("")}.to raise_error(Chef::Exceptions::ValidationFailed)
199
+ end
200
+ end
201
+
130
202
  describe "attributes" do
131
203
  it "should have attributes" do
132
204
  expect(node.attribute).to be_a_kind_of(Hash)
@@ -672,6 +744,13 @@ describe Chef::Node do
672
744
  expect(node.run_list).to eq([ "role[base]", "recipe[chef::server]" ])
673
745
  end
674
746
 
747
+ it "sets the node chef_environment" do
748
+ attrs = { "chef_environment" => "foo_environment", "bar" => "baz" }
749
+ expect(node.consume_chef_environment(attrs)).to eq({ "bar" => "baz" })
750
+ expect(node.chef_environment).to eq("foo_environment")
751
+ expect(node['chef_environment']).to be nil
752
+ end
753
+
675
754
  it "should overwrites the run list with the run list it consumes" do
676
755
  node.consume_run_list "recipes" => [ "one", "two" ]
677
756
  node.consume_run_list "recipes" => [ "three" ]
@@ -1106,6 +1185,43 @@ describe Chef::Node do
1106
1185
  expect(serialized_node.run_list).to eq(node.run_list)
1107
1186
  end
1108
1187
 
1188
+ context "when policyfile attributes are not present" do
1189
+
1190
+ it "does not have a policy_name key in the json" do
1191
+ expect(node.for_json.keys).to_not include("policy_name")
1192
+ end
1193
+
1194
+ it "does not have a policy_group key in the json" do
1195
+ expect(node.for_json.keys).to_not include("policy_name")
1196
+ end
1197
+ end
1198
+
1199
+ context "when policyfile attributes are present" do
1200
+
1201
+ before do
1202
+ node.policy_name = "my-application"
1203
+ node.policy_group = "staging"
1204
+ end
1205
+
1206
+ it "includes policy_name key in the json" do
1207
+ expect(node.for_json).to have_key("policy_name")
1208
+ expect(node.for_json["policy_name"]).to eq("my-application")
1209
+ end
1210
+
1211
+ it "includes a policy_group key in the json" do
1212
+ expect(node.for_json).to have_key("policy_group")
1213
+ expect(node.for_json["policy_group"]).to eq("staging")
1214
+ end
1215
+
1216
+ it "parses policyfile attributes from JSON" do
1217
+ round_tripped_node = Chef::Node.json_create(node.for_json)
1218
+
1219
+ expect(round_tripped_node.policy_name).to eq("my-application")
1220
+ expect(round_tripped_node.policy_group).to eq("staging")
1221
+ end
1222
+
1223
+ end
1224
+
1109
1225
  include_examples "to_json equivalent to Chef::JSONCompat.to_json" do
1110
1226
  let(:jsonable) {
1111
1227
  node.from_file(File.expand_path("nodes/test.example.com.rb", CHEF_SPEC_DATA))
@@ -1301,6 +1417,110 @@ describe Chef::Node do
1301
1417
  node.save
1302
1418
  end
1303
1419
  end
1420
+
1421
+ context "when policyfile attributes are present" do
1422
+
1423
+ before do
1424
+ node.name("example-node")
1425
+ node.policy_name = "my-application"
1426
+ node.policy_group = "staging"
1427
+ end
1428
+
1429
+ context "and the server supports policyfile attributes in node JSON" do
1430
+
1431
+ it "creates the object normally" do
1432
+ expect(@rest).to receive(:post_rest).with("nodes", node.for_json)
1433
+ node.create
1434
+ end
1435
+
1436
+ it "saves the node object normally" do
1437
+ expect(@rest).to receive(:put_rest).with("nodes/example-node", node.for_json)
1438
+ node.save
1439
+ end
1440
+ end
1441
+
1442
+ # Chef Server before 12.3
1443
+ context "and the Chef Server does not support policyfile attributes in node JSON" do
1444
+
1445
+ let(:response_body) { %q[{"error":["Invalid key policy_name in request body"]}] }
1446
+
1447
+ let(:response) do
1448
+ Net::HTTPResponse.send(:response_class, "400").new("1.0", "400", "Bad Request").tap do |r|
1449
+ allow(r).to receive(:body).and_return(response_body)
1450
+ end
1451
+ end
1452
+
1453
+ let(:http_exception) do
1454
+ begin
1455
+ response.error!
1456
+ rescue => e
1457
+ e
1458
+ end
1459
+ end
1460
+
1461
+ let(:trimmed_node) do
1462
+ node.for_json.tap do |j|
1463
+ j.delete("policy_name")
1464
+ j.delete("policy_group")
1465
+ end
1466
+
1467
+ end
1468
+
1469
+ context "on Chef Client 13 and later" do
1470
+
1471
+ # Though we normally attempt to provide compatibility with chef
1472
+ # server one major version back, policyfiles were beta when we
1473
+ # added the policyfile attributes to the node JSON, therefore
1474
+ # policyfile users need to be on 12.3 minimum when upgrading Chef
1475
+ # Client to 13+
1476
+ it "lets the 400 pass through", :chef_gte_13_only do
1477
+ expect { node.save }.to raise_error(http_exception)
1478
+ end
1479
+
1480
+ end
1481
+
1482
+ context "when the node exists" do
1483
+
1484
+ it "falls back to saving without policyfile attributes" do
1485
+ expect(@rest).to receive(:put_rest).with("nodes/example-node", node.for_json).and_raise(http_exception)
1486
+ expect(@rest).to receive(:put_rest).with("nodes/example-node", trimmed_node).and_return(@node)
1487
+ expect { node.save }.to_not raise_error
1488
+ end
1489
+
1490
+ end
1491
+
1492
+ context "when the node doesn't exist" do
1493
+
1494
+ let(:response_404) do
1495
+ Net::HTTPResponse.send(:response_class, "404").new("1.0", "404", "Not Found")
1496
+ end
1497
+
1498
+ let(:http_exception_404) do
1499
+ begin
1500
+ response_404.error!
1501
+ rescue => e
1502
+ e
1503
+ end
1504
+ end
1505
+
1506
+ it "falls back to saving without policyfile attributes" do
1507
+ expect(@rest).to receive(:put_rest).with("nodes/example-node", node.for_json).and_raise(http_exception)
1508
+ expect(@rest).to receive(:put_rest).with("nodes/example-node", trimmed_node).and_raise(http_exception_404)
1509
+ expect(@rest).to receive(:post_rest).with("nodes", trimmed_node).and_return(@node)
1510
+ node.save
1511
+ end
1512
+
1513
+ it "creates the node without policyfile attributes" do
1514
+ expect(@rest).to receive(:post_rest).with("nodes", node.for_json).and_raise(http_exception)
1515
+ expect(@rest).to receive(:post_rest).with("nodes", trimmed_node).and_return(@node)
1516
+ node.create
1517
+ end
1518
+ end
1519
+
1520
+ end
1521
+
1522
+ end
1523
+
1304
1524
  end
1305
1525
  end
1306
1526
 
@@ -21,7 +21,7 @@ require 'spec_helper'
21
21
  describe "Chef::Platform#windows_server_2003?" do
22
22
  it "returns false early when not on windows" do
23
23
  allow(ChefConfig).to receive(:windows?).and_return(false)
24
- expect(Chef::Platform).not_to receive(:require)
24
+ expect(Chef::Platform).not_to receive(:require)
25
25
  expect(Chef::Platform.windows_server_2003?).to be_falsey
26
26
  end
27
27
 
@@ -31,7 +31,127 @@ describe "Chef::Platform#windows_server_2003?" do
31
31
  end
32
32
  end
33
33
 
34
- describe 'Chef::Platform#supports_dsc?' do
34
+ describe "Chef::Platform#windows_nano_server?" do
35
+ include_context "Win32"
36
+
37
+ let(:key) { "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Server\\ServerLevels" }
38
+ let(:key_query_value) { 0x0001 }
39
+ let(:access) { key_query_value | 0x0100 }
40
+ let(:hive) { double("Win32::Registry::HKEY_LOCAL_MACHINE") }
41
+ let(:registry) { double("Win32::Registry") }
42
+
43
+ before(:all) do
44
+ Win32::Registry = Class.new
45
+ Win32::Registry::Error = Class.new(RuntimeError)
46
+ end
47
+
48
+ before do
49
+ Win32::Registry::HKEY_LOCAL_MACHINE = hive
50
+ Win32::Registry::KEY_QUERY_VALUE = key_query_value
51
+ end
52
+
53
+ after do
54
+ Win32::Registry.send(:remove_const, 'HKEY_LOCAL_MACHINE') if defined?(Win32::Registry::HKEY_LOCAL_MACHINE)
55
+ Win32::Registry.send(:remove_const, 'KEY_QUERY_VALUE') if defined?(Win32::Registry::KEY_QUERY_VALUE)
56
+ end
57
+
58
+ it "returns false early when not on windows" do
59
+ allow(ChefConfig).to receive(:windows?).and_return(false)
60
+ expect(Chef::Platform).to_not receive(:require)
61
+ expect(Chef::Platform.windows_nano_server?).to be false
62
+ end
63
+
64
+ it "returns true when the registry value is 1" do
65
+ allow(ChefConfig).to receive(:windows?).and_return(true)
66
+ allow(Chef::Platform).to receive(:require).with('win32/registry')
67
+ expect(Win32::Registry::HKEY_LOCAL_MACHINE).to receive(:open).
68
+ with(key, access).
69
+ and_yield(registry)
70
+ expect(registry).to receive(:[]).with("NanoServer").and_return(1)
71
+ expect(Chef::Platform.windows_nano_server?).to be true
72
+ end
73
+
74
+ it "returns false when the registry value is not 1" do
75
+ allow(ChefConfig).to receive(:windows?).and_return(true)
76
+ allow(Chef::Platform).to receive(:require).with('win32/registry')
77
+ expect(Win32::Registry::HKEY_LOCAL_MACHINE).to receive(:open).
78
+ with(key, access).
79
+ and_yield(registry)
80
+ expect(registry).to receive(:[]).with("NanoServer").and_return(0)
81
+ expect(Chef::Platform.windows_nano_server?).to be false
82
+ end
83
+
84
+ it "returns false when the registry value does not exist" do
85
+ allow(ChefConfig).to receive(:windows?).and_return(true)
86
+ allow(Chef::Platform).to receive(:require).with('win32/registry')
87
+ expect(Win32::Registry::HKEY_LOCAL_MACHINE).to receive(:open).
88
+ with(key, access).
89
+ and_yield(registry)
90
+ expect(registry).to receive(:[]).with("NanoServer").
91
+ and_raise(Win32::Registry::Error, "The system cannot find the file specified.")
92
+ expect(Chef::Platform.windows_nano_server?).to be false
93
+ end
94
+
95
+ it "returns false when the registry key does not exist" do
96
+ allow(ChefConfig).to receive(:windows?).and_return(true)
97
+ allow(Chef::Platform).to receive(:require).with('win32/registry')
98
+ expect(Win32::Registry::HKEY_LOCAL_MACHINE).to receive(:open).
99
+ with(key, access).
100
+ and_raise(Win32::Registry::Error, "The system cannot find the file specified.")
101
+ expect(Chef::Platform.windows_nano_server?).to be false
102
+ end
103
+ end
104
+
105
+ describe "Chef::Platform#supports_msi?" do
106
+ include_context "Win32" # clear and restore Win32:: namespace
107
+
108
+ let(:key) { "System\\CurrentControlSet\\Services\\msiserver" }
109
+ let(:key_query_value) { 0x0001 }
110
+ let(:access) { key_query_value }
111
+ let(:hive) { double("Win32::Registry::HKEY_LOCAL_MACHINE") }
112
+ let(:registry) { double("Win32::Registry") }
113
+
114
+ before(:all) do
115
+ Win32::Registry = Class.new
116
+ Win32::Registry::Error = Class.new(RuntimeError)
117
+ end
118
+
119
+ before do
120
+ Win32::Registry::HKEY_LOCAL_MACHINE = hive
121
+ Win32::Registry::KEY_QUERY_VALUE = key_query_value
122
+ end
123
+
124
+ after do
125
+ Win32::Registry.send(:remove_const, 'HKEY_LOCAL_MACHINE') if defined?(Win32::Registry::HKEY_LOCAL_MACHINE)
126
+ Win32::Registry.send(:remove_const, 'KEY_QUERY_VALUE') if defined?(Win32::Registry::KEY_QUERY_VALUE)
127
+ end
128
+
129
+ it "returns false early when not on windows" do
130
+ allow(ChefConfig).to receive(:windows?).and_return(false)
131
+ expect(Chef::Platform).to_not receive(:require)
132
+ expect(Chef::Platform.supports_msi?).to be false
133
+ end
134
+
135
+ it "returns true when the registry key exists" do
136
+ allow(ChefConfig).to receive(:windows?).and_return(true)
137
+ allow(Chef::Platform).to receive(:require).with('win32/registry')
138
+ expect(Win32::Registry::HKEY_LOCAL_MACHINE).to receive(:open).
139
+ with(key, access).
140
+ and_yield(registry)
141
+ expect(Chef::Platform.supports_msi?).to be true
142
+ end
143
+
144
+ it "returns false when the registry key does not exist" do
145
+ allow(ChefConfig).to receive(:windows?).and_return(true)
146
+ allow(Chef::Platform).to receive(:require).with('win32/registry')
147
+ expect(Win32::Registry::HKEY_LOCAL_MACHINE).to receive(:open).
148
+ with(key, access).
149
+ and_raise(Win32::Registry::Error, "The system cannot find the file specified.")
150
+ expect(Chef::Platform.supports_msi?).to be false
151
+ end
152
+ end
153
+
154
+ describe 'Chef::Platform#supports_dsc?' do
35
155
  it 'returns false if powershell is not present' do
36
156
  node = Chef::Node.new
37
157
  expect(Chef::Platform.supports_dsc?(node)).to be_falsey
@@ -54,7 +174,7 @@ describe 'Chef::Platform#supports_dsc?' do
54
174
  end
55
175
  end
56
176
 
57
- describe 'Chef::Platform#supports_dsc_invoke_resource?' do
177
+ describe 'Chef::Platform#supports_dsc_invoke_resource?' do
58
178
  it 'returns false if powershell is not present' do
59
179
  node = Chef::Node.new
60
180
  expect(Chef::Platform.supports_dsc_invoke_resource?(node)).to be_falsey
@@ -75,3 +195,26 @@ describe 'Chef::Platform#supports_dsc_invoke_resource?' do
75
195
  end
76
196
  end
77
197
 
198
+ describe 'Chef::Platform#dsc_refresh_mode_disabled?' do
199
+ let(:node) { instance_double('Chef::Node') }
200
+ let(:cmdlet) { instance_double('Chef::Util::Powershell::Cmdlet') }
201
+ let(:cmdlet_result) { instance_double('Chef::Util::Powershell::CmdletResult')}
202
+
203
+ it "returns true when RefreshMode is Disabled" do
204
+ expect(Chef::Util::Powershell::Cmdlet).to receive(:new).
205
+ with(node, "Get-DscLocalConfigurationManager", :object).
206
+ and_return(cmdlet)
207
+ expect(cmdlet).to receive(:run!).and_return(cmdlet_result)
208
+ expect(cmdlet_result).to receive(:return_value).and_return({ 'RefreshMode' => 'Disabled' })
209
+ expect(Chef::Platform.dsc_refresh_mode_disabled?(node)).to be true
210
+ end
211
+
212
+ it "returns false when RefreshMode is not Disabled" do
213
+ expect(Chef::Util::Powershell::Cmdlet).to receive(:new).
214
+ with(node, "Get-DscLocalConfigurationManager", :object).
215
+ and_return(cmdlet)
216
+ expect(cmdlet).to receive(:run!).and_return(cmdlet_result)
217
+ expect(cmdlet_result).to receive(:return_value).and_return({ 'RefreshMode' => 'LaLaLa' })
218
+ expect(Chef::Platform.dsc_refresh_mode_disabled?(node)).to be false
219
+ end
220
+ end