chef 12.4.0.rc.0 → 12.4.0.rc.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (298) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +12 -1
  3. data/lib/chef/api_client.rb +130 -26
  4. data/lib/chef/application.rb +0 -1
  5. data/lib/chef/application/client.rb +8 -19
  6. data/lib/chef/audit/audit_reporter.rb +12 -7
  7. data/lib/chef/audit/logger.rb +36 -0
  8. data/lib/chef/audit/runner.rb +4 -2
  9. data/lib/chef/chef_class.rb +62 -11
  10. data/lib/chef/client.rb +587 -207
  11. data/lib/chef/config.rb +0 -1
  12. data/lib/chef/dsl/recipe.rb +45 -56
  13. data/lib/chef/dsl/resources.rb +3 -2
  14. data/lib/chef/event_dispatch/base.rb +7 -2
  15. data/lib/chef/exceptions.rb +4 -1
  16. data/lib/chef/file_content_management/deploy/mv_windows.rb +16 -6
  17. data/lib/chef/formatters/doc.rb +15 -7
  18. data/lib/chef/formatters/error_inspectors/api_error_formatting.rb +10 -7
  19. data/lib/chef/guard_interpreter/default_guard_interpreter.rb +2 -0
  20. data/lib/chef/guard_interpreter/resource_guard_interpreter.rb +4 -1
  21. data/lib/chef/http/authenticator.rb +7 -2
  22. data/lib/chef/knife.rb +16 -4
  23. data/lib/chef/knife/client_create.rb +55 -31
  24. data/lib/chef/knife/core/generic_presenter.rb +1 -1
  25. data/lib/chef/knife/core/subcommand_loader.rb +1 -1
  26. data/lib/chef/knife/osc_user_create.rb +97 -0
  27. data/lib/chef/knife/osc_user_delete.rb +51 -0
  28. data/lib/chef/knife/osc_user_edit.rb +58 -0
  29. data/lib/chef/knife/osc_user_list.rb +47 -0
  30. data/lib/chef/knife/osc_user_reregister.rb +64 -0
  31. data/lib/chef/knife/osc_user_show.rb +54 -0
  32. data/lib/chef/knife/user_create.rb +95 -36
  33. data/lib/chef/knife/user_delete.rb +52 -2
  34. data/lib/chef/knife/user_edit.rb +37 -7
  35. data/lib/chef/knife/user_list.rb +3 -0
  36. data/lib/chef/knife/user_reregister.rb +39 -8
  37. data/lib/chef/knife/user_show.rb +30 -1
  38. data/lib/chef/mixin/api_version_request_handling.rb +66 -0
  39. data/lib/chef/mixin/convert_to_class_name.rb +10 -4
  40. data/lib/chef/mixin/deprecation.rb +24 -0
  41. data/lib/chef/mixin/powershell_out.rb +98 -0
  42. data/lib/chef/mixin/provides.rb +5 -18
  43. data/lib/chef/mixin/uris.rb +11 -0
  44. data/lib/chef/mixin/windows_architecture_helper.rb +5 -2
  45. data/lib/chef/mixin/windows_env_helper.rb +11 -2
  46. data/lib/chef/node_map.rb +130 -75
  47. data/lib/chef/osc_user.rb +194 -0
  48. data/lib/chef/platform/provider_mapping.rb +2 -269
  49. data/lib/chef/platform/provider_priority_map.rb +6 -69
  50. data/lib/chef/platform/query_helpers.rb +5 -0
  51. data/lib/chef/platform/resource_priority_map.rb +12 -15
  52. data/lib/chef/policy_builder/policyfile.rb +1 -0
  53. data/lib/chef/provider.rb +19 -0
  54. data/lib/chef/provider/directory.rb +3 -0
  55. data/lib/chef/provider/dsc_resource.rb +8 -1
  56. data/lib/chef/provider/file.rb +1 -0
  57. data/lib/chef/provider/group/aix.rb +1 -0
  58. data/lib/chef/provider/group/dscl.rb +1 -1
  59. data/lib/chef/provider/group/gpasswd.rb +1 -0
  60. data/lib/chef/provider/group/groupmod.rb +1 -1
  61. data/lib/chef/provider/group/pw.rb +1 -0
  62. data/lib/chef/provider/group/suse.rb +2 -0
  63. data/lib/chef/provider/group/usermod.rb +2 -1
  64. data/lib/chef/provider/group/windows.rb +1 -1
  65. data/lib/chef/provider/ifconfig.rb +2 -0
  66. data/lib/chef/provider/ifconfig/aix.rb +1 -0
  67. data/lib/chef/provider/ifconfig/debian.rb +2 -0
  68. data/lib/chef/provider/ifconfig/redhat.rb +1 -0
  69. data/lib/chef/provider/lwrp_base.rb +4 -0
  70. data/lib/chef/provider/mount.rb +0 -1
  71. data/lib/chef/provider/mount/aix.rb +1 -0
  72. data/lib/chef/provider/mount/mount.rb +2 -0
  73. data/lib/chef/provider/mount/solaris.rb +2 -0
  74. data/lib/chef/provider/package.rb +55 -0
  75. data/lib/chef/provider/package/aix.rb +7 -7
  76. data/lib/chef/provider/package/apt.rb +3 -3
  77. data/lib/chef/provider/package/dpkg.rb +4 -4
  78. data/lib/chef/provider/package/easy_install.rb +5 -5
  79. data/lib/chef/provider/package/freebsd/base.rb +2 -2
  80. data/lib/chef/provider/package/freebsd/pkg.rb +6 -6
  81. data/lib/chef/provider/package/freebsd/pkgng.rb +5 -5
  82. data/lib/chef/provider/package/freebsd/port.rb +4 -4
  83. data/lib/chef/provider/package/homebrew.rb +2 -2
  84. data/lib/chef/provider/package/ips.rb +4 -4
  85. data/lib/chef/provider/package/macports.rb +5 -6
  86. data/lib/chef/provider/package/openbsd.rb +4 -5
  87. data/lib/chef/provider/package/pacman.rb +4 -4
  88. data/lib/chef/provider/package/portage.rb +2 -0
  89. data/lib/chef/provider/package/rpm.rb +7 -8
  90. data/lib/chef/provider/package/rubygems.rb +5 -12
  91. data/lib/chef/provider/package/smartos.rb +4 -4
  92. data/lib/chef/provider/package/solaris.rb +7 -7
  93. data/lib/chef/provider/package/windows/msi.rb +1 -1
  94. data/lib/chef/provider/package/yum.rb +4 -6
  95. data/lib/chef/provider/package/zypper.rb +16 -14
  96. data/lib/chef/provider/powershell_script.rb +129 -47
  97. data/lib/chef/provider/remote_file/content.rb +4 -1
  98. data/lib/chef/provider/remote_file/local_file.rb +10 -4
  99. data/lib/chef/provider/service.rb +44 -0
  100. data/lib/chef/provider/service/freebsd.rb +1 -1
  101. data/lib/chef/provider/service/init.rb +1 -0
  102. data/lib/chef/provider/service/macosx.rb +1 -1
  103. data/lib/chef/provider/service/windows.rb +0 -1
  104. data/lib/chef/provider/user.rb +1 -1
  105. data/lib/chef/provider/user/aix.rb +3 -2
  106. data/lib/chef/provider/user/pw.rb +1 -0
  107. data/lib/chef/provider/user/solaris.rb +2 -0
  108. data/lib/chef/provider/user/useradd.rb +1 -0
  109. data/lib/chef/provider_resolver.rb +87 -134
  110. data/lib/chef/resource.rb +274 -68
  111. data/lib/chef/resource/apt_package.rb +0 -2
  112. data/lib/chef/resource/bash.rb +0 -2
  113. data/lib/chef/resource/batch.rb +1 -1
  114. data/lib/chef/resource/bff_package.rb +0 -7
  115. data/lib/chef/resource/breakpoint.rb +3 -6
  116. data/lib/chef/resource/chef_gem.rb +0 -3
  117. data/lib/chef/resource/cookbook_file.rb +1 -3
  118. data/lib/chef/resource/cron.rb +2 -4
  119. data/lib/chef/resource/csh.rb +0 -2
  120. data/lib/chef/resource/deploy.rb +9 -6
  121. data/lib/chef/resource/deploy_revision.rb +0 -14
  122. data/lib/chef/resource/directory.rb +2 -4
  123. data/lib/chef/resource/dpkg_package.rb +0 -5
  124. data/lib/chef/resource/dsc_resource.rb +2 -3
  125. data/lib/chef/resource/dsc_script.rb +2 -3
  126. data/lib/chef/resource/easy_install_package.rb +0 -7
  127. data/lib/chef/resource/env.rb +3 -3
  128. data/lib/chef/resource/erl_call.rb +2 -5
  129. data/lib/chef/resource/execute.rb +2 -4
  130. data/lib/chef/resource/file.rb +2 -4
  131. data/lib/chef/resource/freebsd_package.rb +0 -5
  132. data/lib/chef/resource/gem_package.rb +0 -3
  133. data/lib/chef/resource/git.rb +0 -3
  134. data/lib/chef/resource/group.rb +2 -4
  135. data/lib/chef/resource/homebrew_package.rb +0 -2
  136. data/lib/chef/resource/http_request.rb +3 -4
  137. data/lib/chef/resource/ifconfig.rb +3 -4
  138. data/lib/chef/resource/ips_package.rb +2 -2
  139. data/lib/chef/resource/link.rb +3 -5
  140. data/lib/chef/resource/log.rb +2 -4
  141. data/lib/chef/resource/lwrp_base.rb +10 -61
  142. data/lib/chef/resource/macosx_service.rb +1 -2
  143. data/lib/chef/resource/macports_package.rb +0 -7
  144. data/lib/chef/resource/mdadm.rb +2 -5
  145. data/lib/chef/resource/mount.rb +2 -4
  146. data/lib/chef/resource/ohai.rb +2 -4
  147. data/lib/chef/resource/openbsd_package.rb +0 -6
  148. data/lib/chef/resource/package.rb +9 -6
  149. data/lib/chef/resource/pacman_package.rb +0 -7
  150. data/lib/chef/resource/paludis_package.rb +2 -3
  151. data/lib/chef/resource/perl.rb +0 -3
  152. data/lib/chef/resource/portage_package.rb +0 -3
  153. data/lib/chef/resource/powershell_script.rb +1 -2
  154. data/lib/chef/resource/python.rb +0 -3
  155. data/lib/chef/resource/reboot.rb +1 -3
  156. data/lib/chef/resource/registry_key.rb +3 -5
  157. data/lib/chef/resource/remote_directory.rb +3 -5
  158. data/lib/chef/resource/remote_file.rb +4 -5
  159. data/lib/chef/resource/route.rb +3 -5
  160. data/lib/chef/resource/rpm_package.rb +0 -2
  161. data/lib/chef/resource/ruby.rb +0 -4
  162. data/lib/chef/resource/ruby_block.rb +2 -4
  163. data/lib/chef/resource/scm.rb +3 -5
  164. data/lib/chef/resource/script.rb +0 -3
  165. data/lib/chef/resource/service.rb +3 -5
  166. data/lib/chef/resource/smartos_package.rb +0 -9
  167. data/lib/chef/resource/solaris_package.rb +0 -10
  168. data/lib/chef/resource/subversion.rb +1 -3
  169. data/lib/chef/resource/template.rb +0 -4
  170. data/lib/chef/resource/timestamped_deploy.rb +0 -4
  171. data/lib/chef/resource/user.rb +2 -5
  172. data/lib/chef/resource/whyrun_safe_ruby_block.rb +0 -7
  173. data/lib/chef/resource/windows_package.rb +3 -3
  174. data/lib/chef/resource/windows_script.rb +2 -2
  175. data/lib/chef/resource/windows_service.rb +3 -3
  176. data/lib/chef/resource/yum_package.rb +0 -3
  177. data/lib/chef/resource/zypper_package.rb +27 -0
  178. data/lib/chef/resource_builder.rb +7 -0
  179. data/lib/chef/resource_reporter.rb +1 -1
  180. data/lib/chef/resource_resolver.rb +108 -62
  181. data/lib/chef/resources.rb +1 -0
  182. data/lib/chef/rest.rb +1 -0
  183. data/lib/chef/server_api.rb +2 -0
  184. data/lib/chef/user.rb +193 -42
  185. data/lib/chef/util/backup.rb +9 -1
  186. data/lib/chef/util/path_helper.rb +0 -1
  187. data/lib/chef/version.rb +1 -1
  188. data/spec/functional/audit/runner_spec.rb +22 -42
  189. data/spec/functional/mixin/powershell_out_spec.rb +43 -0
  190. data/spec/functional/resource/execute_spec.rb +9 -2
  191. data/spec/functional/resource/file_spec.rb +25 -0
  192. data/spec/functional/resource/group_spec.rb +5 -0
  193. data/spec/functional/resource/link_spec.rb +5 -11
  194. data/spec/functional/resource/powershell_spec.rb +40 -5
  195. data/spec/functional/resource/user/useradd_spec.rb +10 -18
  196. data/spec/integration/recipes/lwrp_spec.rb +57 -0
  197. data/spec/integration/recipes/provider_choice.rb +2 -7
  198. data/spec/integration/recipes/recipe_dsl_spec.rb +517 -19
  199. data/spec/spec_helper.rb +1 -1
  200. data/spec/support/lib/chef/provider/openldap_includer.rb +29 -0
  201. data/spec/support/lib/chef/resource/cat.rb +0 -2
  202. data/spec/support/lib/chef/resource/one_two_three_four.rb +0 -6
  203. data/spec/support/lib/chef/resource/openldap_includer.rb +27 -0
  204. data/spec/support/lib/chef/resource/with_state.rb +0 -9
  205. data/spec/support/lib/chef/resource/zen_follower.rb +0 -6
  206. data/spec/support/lib/chef/resource/zen_master.rb +1 -6
  207. data/spec/support/shared/context/client.rb +277 -0
  208. data/spec/support/shared/examples/client.rb +53 -0
  209. data/spec/support/shared/functional/file_resource.rb +0 -4
  210. data/spec/support/shared/functional/securable_resource.rb +0 -24
  211. data/spec/support/shared/functional/securable_resource_with_reporting.rb +4 -4
  212. data/spec/support/shared/functional/windows_script.rb +1 -1
  213. data/spec/support/shared/unit/api_versioning.rb +77 -0
  214. data/spec/support/shared/unit/knife_shared.rb +40 -0
  215. data/spec/support/shared/unit/user_and_client_shared.rb +115 -0
  216. data/spec/unit/api_client_spec.rb +189 -14
  217. data/spec/unit/application/client_spec.rb +0 -5
  218. data/spec/unit/audit/audit_reporter_spec.rb +58 -14
  219. data/spec/unit/audit/logger_spec.rb +42 -0
  220. data/spec/unit/audit/runner_spec.rb +2 -2
  221. data/spec/unit/chef_fs/file_pattern_spec.rb +3 -15
  222. data/spec/unit/client_spec.rb +58 -374
  223. data/spec/unit/cookbook_spec.rb +0 -9
  224. data/spec/unit/cookbook_version_spec.rb +0 -20
  225. data/spec/unit/deprecation_spec.rb +55 -0
  226. data/spec/unit/dsl/resources_spec.rb +85 -0
  227. data/spec/unit/exceptions_spec.rb +2 -2
  228. data/spec/unit/file_content_management/deploy/mv_windows_spec.rb +60 -0
  229. data/spec/unit/formatters/doc_spec.rb +46 -0
  230. data/spec/unit/formatters/error_inspectors/api_error_formatting_spec.rb +12 -10
  231. data/spec/unit/guard_interpreter/resource_guard_interpreter_spec.rb +8 -0
  232. data/spec/unit/http/authenticator_spec.rb +11 -2
  233. data/spec/unit/knife/client_create_spec.rb +122 -51
  234. data/spec/unit/knife/core/subcommand_loader_spec.rb +19 -3
  235. data/spec/unit/knife/core/ui_spec.rb +14 -0
  236. data/spec/unit/knife/osc_user_create_spec.rb +93 -0
  237. data/spec/unit/knife/osc_user_delete_spec.rb +44 -0
  238. data/spec/unit/knife/osc_user_edit_spec.rb +52 -0
  239. data/spec/unit/knife/osc_user_list_spec.rb +37 -0
  240. data/spec/unit/knife/osc_user_reregister_spec.rb +58 -0
  241. data/spec/unit/knife/osc_user_show_spec.rb +46 -0
  242. data/spec/unit/knife/user_create_spec.rb +177 -51
  243. data/spec/unit/knife/user_delete_spec.rb +34 -8
  244. data/spec/unit/knife/user_edit_spec.rb +31 -12
  245. data/spec/unit/knife/user_list_spec.rb +7 -3
  246. data/spec/unit/knife/user_reregister_spec.rb +38 -17
  247. data/spec/unit/knife/user_show_spec.rb +35 -11
  248. data/spec/unit/knife_spec.rb +10 -4
  249. data/spec/unit/lwrp_spec.rb +228 -54
  250. data/spec/unit/mixin/api_version_request_handling_spec.rb +127 -0
  251. data/spec/unit/mixin/command_spec.rb +1 -2
  252. data/spec/unit/mixin/powershell_out_spec.rb +70 -0
  253. data/spec/unit/mixin/uris_spec.rb +23 -11
  254. data/spec/unit/node_map_spec.rb +4 -1
  255. data/spec/unit/osc_user_spec.rb +276 -0
  256. data/spec/unit/platform_spec.rb +0 -60
  257. data/spec/unit/provider/deploy_spec.rb +1 -1
  258. data/spec/unit/provider/directory_spec.rb +199 -135
  259. data/spec/unit/provider/ifconfig/debian_spec.rb +0 -10
  260. data/spec/unit/provider/package/aix_spec.rb +16 -16
  261. data/spec/unit/provider/package/dpkg_spec.rb +2 -2
  262. data/spec/unit/provider/package/freebsd/pkg_spec.rb +13 -13
  263. data/spec/unit/provider/package/freebsd/pkgng_spec.rb +9 -9
  264. data/spec/unit/provider/package/freebsd/port_spec.rb +7 -7
  265. data/spec/unit/provider/package/ips_spec.rb +22 -22
  266. data/spec/unit/provider/package/macports_spec.rb +10 -10
  267. data/spec/unit/provider/package/openbsd_spec.rb +4 -26
  268. data/spec/unit/provider/package/pacman_spec.rb +5 -5
  269. data/spec/unit/provider/package/rpm_spec.rb +14 -14
  270. data/spec/unit/provider/package/rubygems_spec.rb +10 -44
  271. data/spec/unit/provider/package/smartos_spec.rb +4 -4
  272. data/spec/unit/provider/package/solaris_spec.rb +11 -11
  273. data/spec/unit/provider/package/zypper_spec.rb +125 -90
  274. data/spec/unit/provider/package_spec.rb +34 -0
  275. data/spec/unit/provider/powershell_spec.rb +53 -11
  276. data/spec/unit/provider/remote_directory_spec.rb +2 -2
  277. data/spec/unit/provider/remote_file/local_file_spec.rb +25 -6
  278. data/spec/unit/provider/service/freebsd_service_spec.rb +0 -12
  279. data/spec/unit/provider/user_spec.rb +3 -3
  280. data/spec/unit/provider_resolver_spec.rb +463 -327
  281. data/spec/unit/recipe_spec.rb +42 -15
  282. data/spec/unit/resource/breakpoint_spec.rb +1 -1
  283. data/spec/unit/resource/erl_call_spec.rb +1 -1
  284. data/spec/unit/resource/file_spec.rb +1 -1
  285. data/spec/unit/resource/ifconfig_spec.rb +10 -6
  286. data/spec/unit/resource/remote_file_spec.rb +5 -0
  287. data/spec/unit/resource/route_spec.rb +1 -1
  288. data/spec/unit/resource/ruby_block_spec.rb +2 -2
  289. data/spec/unit/resource/template_spec.rb +1 -1
  290. data/spec/unit/resource/timestamped_deploy_spec.rb +1 -2
  291. data/spec/unit/resource/windows_service_spec.rb +1 -1
  292. data/spec/unit/resource_spec.rb +99 -13
  293. data/spec/unit/rest_spec.rb +5 -5
  294. data/spec/unit/run_context_spec.rb +41 -0
  295. data/spec/unit/runner_spec.rb +2 -2
  296. data/spec/unit/user_spec.rb +406 -93
  297. data/tasks/maintainers.rb +69 -0
  298. metadata +37 -4
@@ -592,10 +592,6 @@ shared_examples_for "a configured file resource" do
592
592
  File.open(path, "wb") { |f| f.write(wrong_content) }
593
593
  end
594
594
 
595
- it "updates the source file content" do
596
- skip
597
- end
598
-
599
595
  it "marks the resource as updated" do
600
596
  resource.run_action(:create)
601
597
  expect(resource).to be_updated_by_last_action
@@ -163,9 +163,6 @@ shared_examples_for "a securable resource with existing target" do
163
163
  let(:desired_gid) { 1337 }
164
164
  let(:expected_gid) { 1337 }
165
165
 
166
- skip "should set an owner (Rerun specs under root)", :requires_unprivileged_user => true
167
- skip "should set a group (Rerun specs under root)", :requires_unprivileged_user => true
168
-
169
166
  describe "when setting the owner", :requires_root do
170
167
  before do
171
168
  resource.owner expected_user_name
@@ -205,11 +202,6 @@ shared_examples_for "a securable resource with existing target" do
205
202
  resource.run_action(:create)
206
203
  end
207
204
 
208
- it "should set permissions as specified" do
209
- pending("Linux does not support lchmod")
210
- expect{ File.lstat(path).mode & 007777 }.to eq(@mode_string.oct & 007777)
211
- end
212
-
213
205
  it "is marked as updated only if changes are made" do
214
206
  expect(resource.updated_by_last_action?).to eq(expect_updated?)
215
207
  end
@@ -222,11 +214,6 @@ shared_examples_for "a securable resource with existing target" do
222
214
  resource.run_action(:create)
223
215
  end
224
216
 
225
- it "should set permissions in numeric form as a ruby-interpreted octal" do
226
- pending('Linux does not support lchmod')
227
- expect{ File.lstat(path).mode & 007777 }.to eq(@mode_integer & 007777)
228
- end
229
-
230
217
  it "is marked as updated only if changes are made" do
231
218
  expect(resource.updated_by_last_action?).to eq(expect_updated?)
232
219
  end
@@ -306,10 +293,6 @@ shared_examples_for "a securable resource without existing target" do
306
293
 
307
294
  include_context "diff disabled"
308
295
 
309
- context "on Unix", :unix_only do
310
- skip "if we need any securable resource tests on Unix without existing target resource."
311
- end
312
-
313
296
  context "on Windows", :windows_only do
314
297
  include_context "use Windows permissions"
315
298
 
@@ -366,13 +349,6 @@ shared_examples_for "a securable resource without existing target" do
366
349
  expect { resource.group 'Lance "The Nose" Glindenberry III' }.to raise_error(Chef::Exceptions::ValidationFailed)
367
350
  end
368
351
 
369
- it "sets group when group is specified with a \\" do
370
- pending("Need to find a group containing a backslash that is on most peoples' machines")
371
- resource.group "#{ENV['COMPUTERNAME']}\\Administrators"
372
- resource.run_action(:create)
373
- expect{ descriptor.group }.to eq(SID.Everyone)
374
- end
375
-
376
352
  it "leaves group alone if group is not specified and resource already exists" do
377
353
  arbitrary_non_default_group = SID.Everyone
378
354
  expect(arbitrary_non_default_group).not_to eq(SID.default_security_object_group)
@@ -279,14 +279,14 @@ shared_examples_for "a securable resource with reporting" do
279
279
  end
280
280
 
281
281
  it "has empty values for file metadata in 'current_resource'" do
282
- pending "windows reporting not yet fully supported"
282
+ skip "windows reporting not yet fully supported"
283
283
  expect(current_resource.owner).to be_nil
284
284
  expect(current_resource.expanded_rights).to be_nil
285
285
  end
286
286
 
287
287
  context "and no security metadata is specified in new_resource" do
288
288
  before do
289
- pending "windows reporting not yet fully supported"
289
+ skip "windows reporting not yet fully supported"
290
290
  end
291
291
 
292
292
  it "sets the metadata values on the new_resource as strings after creating" do
@@ -322,7 +322,7 @@ shared_examples_for "a securable resource with reporting" do
322
322
  let(:expected_user_name) { 'domain\user' }
323
323
 
324
324
  before do
325
- pending "windows reporting not yet fully supported"
325
+ skip "windows reporting not yet fully supported"
326
326
  resource.owner(expected_user_name)
327
327
  resource.run_action(:create)
328
328
  end
@@ -336,7 +336,7 @@ shared_examples_for "a securable resource with reporting" do
336
336
 
337
337
  context "when the target file exists" do
338
338
  before do
339
- pending "windows reporting not yet fully supported"
339
+ skip "windows reporting not yet fully supported"
340
340
  FileUtils.touch(resource.path)
341
341
  resource.action(:create)
342
342
  end
@@ -114,7 +114,7 @@ shared_context Chef::Resource::WindowsScript do
114
114
 
115
115
  describe "when the run action is invoked on Windows" do
116
116
  it "executes the script code" do
117
- resource.code("@whoami > #{script_output_path}")
117
+ resource.code("whoami > #{script_output_path}")
118
118
  resource.returns(0)
119
119
  resource.run_action(:run)
120
120
  end
@@ -0,0 +1,77 @@
1
+ #
2
+ # Author:: Tyler Cloke (<tyler@chef.io>)
3
+ # Copyright:: Copyright (c) 2015 Chef Software, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require "chef/exceptions"
20
+
21
+ shared_examples_for "version handling" do
22
+ let(:response_406) { OpenStruct.new(:code => '406') }
23
+ let(:exception_406) { Net::HTTPServerException.new("406 Not Acceptable", response_406) }
24
+
25
+ before do
26
+ allow(rest_v1).to receive(http_verb).and_raise(exception_406)
27
+ end
28
+
29
+ context "when the server does not support the min or max server API version that Chef::User supports" do
30
+ before do
31
+ allow(object).to receive(:server_client_api_version_intersection).and_return([])
32
+ end
33
+
34
+ it "raises the original exception" do
35
+ expect{ object.send(method) }.to raise_error(exception_406)
36
+ end
37
+ end # when the server does not support the min or max server API version that Chef::User supports
38
+ end # version handling
39
+
40
+ shared_examples_for "user and client reregister" do
41
+ let(:response_406) { OpenStruct.new(:code => '406') }
42
+ let(:exception_406) { Net::HTTPServerException.new("406 Not Acceptable", response_406) }
43
+ let(:generic_exception) { Exception.new }
44
+ let(:min_version) { "2" }
45
+ let(:max_version) { "5" }
46
+ let(:return_hash_406) {
47
+ {
48
+ "min_version" => min_version,
49
+ "max_version" => max_version,
50
+ "request_version" => "30"
51
+ }
52
+ }
53
+
54
+ context "when V0 is not supported by the server" do
55
+ context "when the exception is 406 and returns x-ops-server-api-version header" do
56
+ before do
57
+ allow(rest_v0).to receive(:put).and_raise(exception_406)
58
+ allow(response_406).to receive(:[]).with('x-ops-server-api-version').and_return(Chef::JSONCompat.to_json(return_hash_406))
59
+ end
60
+
61
+ it "raises an error about only V0 being supported" do
62
+ expect(object).to receive(:reregister_only_v0_supported_error_msg).with(max_version, min_version)
63
+ expect{ object.reregister }.to raise_error(Chef::Exceptions::OnlyApiVersion0SupportedForAction)
64
+ end
65
+
66
+ end
67
+ context "when the exception is not versioning related" do
68
+ before do
69
+ allow(rest_v0).to receive(:put).and_raise(generic_exception)
70
+ end
71
+
72
+ it "raises the original error" do
73
+ expect{ object.reregister }.to raise_error(generic_exception)
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,40 @@
1
+ #
2
+ # Author:: Tyler Cloke (<tyler@chef.io>)
3
+ # Copyright:: Copyright (c) 2015 Chef Software, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+
20
+ shared_examples_for "mandatory field missing" do
21
+ context "when field is nil" do
22
+ before do
23
+ knife.name_args = name_args
24
+ end
25
+
26
+ it "exits 1" do
27
+ expect { knife.run }.to raise_error(SystemExit)
28
+ end
29
+
30
+ it "prints the usage" do
31
+ expect(knife).to receive(:show_usage)
32
+ expect { knife.run }.to raise_error(SystemExit)
33
+ end
34
+
35
+ it "prints a relevant error message" do
36
+ expect { knife.run }.to raise_error(SystemExit)
37
+ expect(stderr.string).to match /You must specify a #{fieldname}/
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,115 @@
1
+ #
2
+ # Author:: Tyler Cloke (<tyler@chef.io>)
3
+ # Copyright:: Copyright (c) 2015 Chef Software, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ shared_examples_for "user or client create" do
20
+
21
+ context "when server API V1 is valid on the Chef Server receiving the request" do
22
+
23
+ it "creates a new object via the API" do
24
+ expect(rest_v1).to receive(:post).with(url, payload).and_return({})
25
+ object.create
26
+ end
27
+
28
+ it "creates a new object via the API with a public_key when it exists" do
29
+ object.public_key "some_public_key"
30
+ expect(rest_v1).to receive(:post).with(url, payload.merge({:public_key => "some_public_key"})).and_return({})
31
+ object.create
32
+ end
33
+
34
+ context "raise error when create_key and public_key are both set" do
35
+
36
+ before do
37
+ object.public_key "key"
38
+ object.create_key true
39
+ end
40
+
41
+ it "rasies the proper error" do
42
+ expect { object.create }.to raise_error(error)
43
+ end
44
+ end
45
+
46
+ context "when create_key == true" do
47
+ before do
48
+ object.create_key true
49
+ end
50
+
51
+ it "creates a new object via the API with create_key" do
52
+ expect(rest_v1).to receive(:post).with(url, payload.merge({:create_key => true})).and_return({})
53
+ object.create
54
+ end
55
+ end
56
+
57
+ context "when chef_key is returned by the server" do
58
+ let(:chef_key) {
59
+ {
60
+ "chef_key" => {
61
+ "public_key" => "some_public_key"
62
+ }
63
+ }
64
+ }
65
+
66
+ it "puts the public key into the objectr returned by create" do
67
+ expect(rest_v1).to receive(:post).with(url, payload).and_return(payload.merge(chef_key))
68
+ new_object = object.create
69
+ expect(new_object.public_key).to eq("some_public_key")
70
+ end
71
+
72
+ context "when private_key is returned in chef_key" do
73
+ let(:chef_key) {
74
+ {
75
+ "chef_key" => {
76
+ "public_key" => "some_public_key",
77
+ "private_key" => "some_private_key"
78
+ }
79
+ }
80
+ }
81
+
82
+ it "puts the private key into the object returned by create" do
83
+ expect(rest_v1).to receive(:post).with(url, payload).and_return(payload.merge(chef_key))
84
+ new_object = object.create
85
+ expect(new_object.private_key).to eq("some_private_key")
86
+ end
87
+ end
88
+ end # when chef_key is returned by the server
89
+
90
+ end # when server API V1 is valid on the Chef Server receiving the request
91
+
92
+ context "when server API V1 is not valid on the Chef Server receiving the request" do
93
+
94
+ context "when the server supports API V0" do
95
+ before do
96
+ allow(object).to receive(:server_client_api_version_intersection).and_return([0])
97
+ allow(rest_v1).to receive(:post).and_raise(exception_406)
98
+ end
99
+
100
+ it "creates a new object via the API" do
101
+ expect(rest_v0).to receive(:post).with(url, payload).and_return({})
102
+ object.create
103
+ end
104
+
105
+ it "creates a new object via the API with a public_key when it exists" do
106
+ object.public_key "some_public_key"
107
+ expect(rest_v0).to receive(:post).with(url, payload.merge({:public_key => "some_public_key"})).and_return({})
108
+ object.create
109
+ end
110
+
111
+ end # when the server supports API V0
112
+ end # when server API V1 is not valid on the Chef Server receiving the request
113
+
114
+ end # user or client create
115
+
@@ -53,6 +53,20 @@ describe Chef::ApiClient do
53
53
  expect { @client.admin(Hash.new) }.to raise_error(ArgumentError)
54
54
  end
55
55
 
56
+ it "has an create_key flag attribute" do
57
+ @client.create_key(true)
58
+ expect(@client.create_key).to be_truthy
59
+ end
60
+
61
+ it "create_key defaults to false" do
62
+ expect(@client.create_key).to be_falsey
63
+ end
64
+
65
+ it "allows only boolean values for the create_key flag" do
66
+ expect { @client.create_key(false) }.not_to raise_error
67
+ expect { @client.create_key(Hash.new) }.to raise_error(ArgumentError)
68
+ end
69
+
56
70
  it "has a 'validator' flag attribute" do
57
71
  @client.validator(true)
58
72
  expect(@client.validator).to be_truthy
@@ -115,6 +129,12 @@ describe Chef::ApiClient do
115
129
  expect(@json).to include(%q{"validator":false})
116
130
  end
117
131
 
132
+ it "includes the 'create_key' flag when present" do
133
+ @client.create_key(true)
134
+ @json = @client.to_json
135
+ expect(@json).to include(%q{"create_key":true})
136
+ end
137
+
118
138
  it "includes the private key when present" do
119
139
  @client.private_key("monkeypants")
120
140
  expect(@client.to_json).to include(%q{"private_key":"monkeypants"})
@@ -131,7 +151,7 @@ describe Chef::ApiClient do
131
151
 
132
152
  describe "when deserializing from JSON (string) using ApiClient#from_json" do
133
153
  let(:client_string) do
134
- "{\"name\":\"black\",\"public_key\":\"crowes\",\"private_key\":\"monkeypants\",\"admin\":true,\"validator\":true}"
154
+ "{\"name\":\"black\",\"public_key\":\"crowes\",\"private_key\":\"monkeypants\",\"admin\":true,\"validator\":true,\"create_key\":true}"
135
155
  end
136
156
 
137
157
  let(:client) do
@@ -158,6 +178,10 @@ describe Chef::ApiClient do
158
178
  expect(client.admin).to be_truthy
159
179
  end
160
180
 
181
+ it "preserves the create_key status" do
182
+ expect(client.create_key).to be_truthy
183
+ end
184
+
161
185
  it "preserves the 'validator' status" do
162
186
  expect(client.validator).to be_truthy
163
187
  end
@@ -175,6 +199,7 @@ describe Chef::ApiClient do
175
199
  "private_key" => "monkeypants",
176
200
  "admin" => true,
177
201
  "validator" => true,
202
+ "create_key" => true,
178
203
  "json_class" => "Chef::ApiClient"
179
204
  }
180
205
  end
@@ -199,6 +224,10 @@ describe Chef::ApiClient do
199
224
  expect(client.admin).to be_truthy
200
225
  end
201
226
 
227
+ it "preserves the create_key status" do
228
+ expect(client.create_key).to be_truthy
229
+ end
230
+
202
231
  it "preserves the 'validator' status" do
203
232
  expect(client.validator).to be_truthy
204
233
  end
@@ -214,14 +243,16 @@ describe Chef::ApiClient do
214
243
 
215
244
  before(:each) do
216
245
  client = {
217
- "name" => "black",
218
- "clientname" => "black",
219
- "public_key" => "crowes",
220
- "private_key" => "monkeypants",
221
- "admin" => true,
222
- "validator" => true,
223
- "json_class" => "Chef::ApiClient"
246
+ "name" => "black",
247
+ "clientname" => "black",
248
+ "public_key" => "crowes",
249
+ "private_key" => "monkeypants",
250
+ "admin" => true,
251
+ "create_key" => true,
252
+ "validator" => true,
253
+ "json_class" => "Chef::ApiClient"
224
254
  }
255
+
225
256
  @http_client = double("Chef::REST mock")
226
257
  allow(Chef::REST).to receive(:new).and_return(@http_client)
227
258
  expect(@http_client).to receive(:get).with("clients/black").and_return(client)
@@ -244,6 +275,10 @@ describe Chef::ApiClient do
244
275
  expect(@client.admin).to be_a_kind_of(TrueClass)
245
276
  end
246
277
 
278
+ it "preserves the create_key status" do
279
+ expect(@client.create_key).to be_a_kind_of(TrueClass)
280
+ end
281
+
247
282
  it "preserves the 'validator' status" do
248
283
  expect(@client.validator).to be_a_kind_of(TrueClass)
249
284
  end
@@ -297,24 +332,34 @@ describe Chef::ApiClient do
297
332
  end
298
333
 
299
334
  context "and the client exists" do
335
+ let(:chef_rest_v0_mock) { double('chef rest root v0 object') }
336
+ let(:payload) {
337
+ {:name => "lost-my-key", :admin => false, :validator => false, :private_key => true}
338
+ }
339
+
300
340
  before do
301
341
  @api_client_without_key = Chef::ApiClient.new
302
342
  @api_client_without_key.name("lost-my-key")
303
- expect(@http_client).to receive(:get).with("clients/lost-my-key").and_return(@api_client_without_key)
304
- end
343
+ allow(@api_client_without_key).to receive(:chef_rest_v0).and_return(chef_rest_v0_mock)
344
+ #allow(@api_client_with_key).to receive(:http_api).and_return(_api_mock)
305
345
 
346
+ allow(chef_rest_v0_mock).to receive(:put).with("clients/lost-my-key", payload).and_return(@api_client_with_key)
347
+ allow(chef_rest_v0_mock).to receive(:get).with("clients/lost-my-key").and_return(@api_client_without_key)
348
+ allow(@http_client).to receive(:get).with("clients/lost-my-key").and_return(@api_client_without_key)
349
+ end
306
350
 
307
351
  context "and the client exists on a Chef 11-like server" do
308
352
  before do
309
353
  @api_client_with_key = Chef::ApiClient.new
310
354
  @api_client_with_key.name("lost-my-key")
311
355
  @api_client_with_key.private_key("the new private key")
312
- expect(@http_client).to receive(:put).
313
- with("clients/lost-my-key", :name => "lost-my-key", :admin => false, :validator => false, :private_key => true).
314
- and_return(@api_client_with_key)
356
+ allow(@api_client_with_key).to receive(:chef_rest_v0).and_return(chef_rest_v0_mock)
315
357
  end
316
358
 
317
359
  it "returns an ApiClient with a private key" do
360
+ expect(chef_rest_v0_mock).to receive(:put).with("clients/lost-my-key", payload).
361
+ and_return(@api_client_with_key)
362
+
318
363
  response = Chef::ApiClient.reregister("lost-my-key")
319
364
  # no sane == method for ApiClient :'(
320
365
  expect(response).to eq(@api_client_without_key)
@@ -327,7 +372,7 @@ describe Chef::ApiClient do
327
372
  context "and the client exists on a Chef 10-like server" do
328
373
  before do
329
374
  @api_client_with_key = {"name" => "lost-my-key", "private_key" => "the new private key"}
330
- expect(@http_client).to receive(:put).
375
+ expect(chef_rest_v0_mock).to receive(:put).
331
376
  with("clients/lost-my-key", :name => "lost-my-key", :admin => false, :validator => false, :private_key => true).
332
377
  and_return(@api_client_with_key)
333
378
  end
@@ -345,4 +390,134 @@ describe Chef::ApiClient do
345
390
 
346
391
  end
347
392
  end
393
+
394
+ describe "Versioned API Interactions" do
395
+ let(:response_406) { OpenStruct.new(:code => '406') }
396
+ let(:exception_406) { Net::HTTPServerException.new("406 Not Acceptable", response_406) }
397
+ let(:payload) {
398
+ {
399
+ :name => "some_name",
400
+ :validator => true,
401
+ :admin => true
402
+ }
403
+ }
404
+
405
+ before do
406
+ @client = Chef::ApiClient.new
407
+ allow(@client).to receive(:chef_rest_v0).and_return(double('chef rest root v0 object'))
408
+ allow(@client).to receive(:chef_rest_v1).and_return(double('chef rest root v1 object'))
409
+ @client.name "some_name"
410
+ @client.validator true
411
+ @client.admin true
412
+ end
413
+
414
+ describe "create" do
415
+
416
+ # from spec/support/shared/unit/user_and_client_shared.rb
417
+ it_should_behave_like "user or client create" do
418
+ let(:object) { @client }
419
+ let(:error) { Chef::Exceptions::InvalidClientAttribute }
420
+ let(:rest_v0) { @client.chef_rest_v0 }
421
+ let(:rest_v1) { @client.chef_rest_v1 }
422
+ let(:url) { "clients" }
423
+ end
424
+
425
+ context "when API V1 is not supported by the server" do
426
+ # from spec/support/shared/unit/api_versioning.rb
427
+ it_should_behave_like "version handling" do
428
+ let(:object) { @client }
429
+ let(:method) { :create }
430
+ let(:http_verb) { :post }
431
+ let(:rest_v1) { @client.chef_rest_v1 }
432
+ end
433
+ end
434
+
435
+ end # create
436
+
437
+ describe "update" do
438
+ context "when a valid client is defined" do
439
+
440
+ shared_examples_for "client updating" do
441
+ it "updates the client" do
442
+ expect(rest). to receive(:put).with("clients/some_name", payload)
443
+ @client.update
444
+ end
445
+
446
+ context "when only the name field exists" do
447
+
448
+ before do
449
+ # needed since there is no way to set to nil via code
450
+ @client.instance_variable_set(:@validator, nil)
451
+ @client.instance_variable_set(:@admin, nil)
452
+ end
453
+
454
+ after do
455
+ @client.validator true
456
+ @client.admin true
457
+ end
458
+
459
+ it "updates the client with only the name" do
460
+ expect(rest). to receive(:put).with("clients/some_name", {:name => "some_name"})
461
+ @client.update
462
+ end
463
+ end
464
+
465
+ end
466
+
467
+ context "when API V1 is supported by the server" do
468
+
469
+ it_should_behave_like "client updating" do
470
+ let(:rest) { @client.chef_rest_v1 }
471
+ end
472
+
473
+ end # when API V1 is supported by the server
474
+
475
+ context "when API V1 is not supported by the server" do
476
+ context "when no version is supported" do
477
+ # from spec/support/shared/unit/api_versioning.rb
478
+ it_should_behave_like "version handling" do
479
+ let(:object) { @client }
480
+ let(:method) { :create }
481
+ let(:http_verb) { :post }
482
+ let(:rest_v1) { @client.chef_rest_v1 }
483
+ end
484
+ end # when no version is supported
485
+
486
+ context "when API V0 is supported" do
487
+
488
+ before do
489
+ allow(@client.chef_rest_v1).to receive(:put).and_raise(exception_406)
490
+ allow(@client).to receive(:server_client_api_version_intersection).and_return([0])
491
+ end
492
+
493
+ it_should_behave_like "client updating" do
494
+ let(:rest) { @client.chef_rest_v0 }
495
+ end
496
+
497
+ end
498
+
499
+ end # when API V1 is not supported by the server
500
+ end # when a valid client is defined
501
+ end # update
502
+
503
+ # DEPRECATION
504
+ # This can be removed after API V0 support is gone
505
+ describe "reregister" do
506
+ context "when server API V0 is valid on the Chef Server receiving the request" do
507
+ it "creates a new object via the API" do
508
+ expect(@client.chef_rest_v0).to receive(:put).with("clients/#{@client.name}", payload.merge({:private_key => true})).and_return({})
509
+ @client.reregister
510
+ end
511
+ end # when server API V0 is valid on the Chef Server receiving the request
512
+
513
+ context "when server API V0 is not supported by the Chef Server" do
514
+ # from spec/support/shared/unit/api_versioning.rb
515
+ it_should_behave_like "user and client reregister" do
516
+ let(:object) { @client }
517
+ let(:rest_v0) { @client.chef_rest_v0 }
518
+ end
519
+ end # when server API V0 is not supported by the Chef Server
520
+ end # reregister
521
+
522
+ end
348
523
  end