chef 12.4.0.rc.0-universal-mingw32 → 12.4.0.rc.2-universal-mingw32

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
@@ -22,14 +22,14 @@ describe Chef::Knife::SubcommandLoader do
22
22
  let(:loader) { Chef::Knife::SubcommandLoader.new(File.join(CHEF_SPEC_DATA, 'knife-site-subcommands')) }
23
23
  let(:home) { File.join(CHEF_SPEC_DATA, 'knife-home') }
24
24
  let(:plugin_dir) { File.join(home, '.chef', 'plugins', 'knife') }
25
-
25
+
26
26
  before do
27
27
  allow(ChefConfig).to receive(:windows?) { false }
28
- Chef::Util::PathHelper.class_variable_set(:@@home_dir, home)
28
+ Chef::Util::PathHelper.class_variable_set(:@@home_dir, home)
29
29
  end
30
30
 
31
31
  after do
32
- Chef::Util::PathHelper.class_variable_set(:@@home_dir, nil)
32
+ Chef::Util::PathHelper.class_variable_set(:@@home_dir, nil)
33
33
  end
34
34
 
35
35
  it "builds a list of the core subcommand file require paths" do
@@ -106,6 +106,18 @@ describe Chef::Knife::SubcommandLoader do
106
106
  # Chef 12.0.0.rc.0 gem also:
107
107
  "/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-#{Chef::VERSION}.rc.0/lib/chef/knife/thing.rb",
108
108
 
109
+ # Test that we ignore the platform suffix when checking for different
110
+ # gem versions.
111
+ "/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-#{Chef::VERSION}-x86-mingw32/lib/chef/knife/valid.rb",
112
+ "/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-#{Chef::VERSION}-i386-mingw64/lib/chef/knife/valid-too.rb",
113
+ "/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-#{Chef::VERSION}-mswin32/lib/chef/knife/also-valid.rb",
114
+ "/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-#{Chef::VERSION}-universal-mingw32/lib/chef/knife/universal-is-valid.rb",
115
+ # ...but don't ignore the .rc / .dev parts in the case when we have
116
+ # platform suffixes
117
+ "/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-#{Chef::VERSION}.rc.0-x86-mingw32/lib/chef/knife/invalid.rb",
118
+ "/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-#{Chef::VERSION}.dev-mswin32/lib/chef/knife/invalid-too.rb",
119
+ "/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-#{Chef::VERSION}.dev.0-x86-mingw64/lib/chef/knife/still-invalid.rb",
120
+
109
121
  # This command is "extra" compared to what's in the embedded/apps/chef install:
110
122
  "/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-1.0.0/lib/chef/knife/data_bag_secret_options.rb",
111
123
  "/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-vault-2.2.4/lib/chef/knife/decrypt.rb",
@@ -133,6 +145,10 @@ describe Chef::Knife::SubcommandLoader do
133
145
  "/opt/chefdk/embedded/apps/chef/lib/chef/knife/bootstrap.rb",
134
146
  "/opt/chefdk/embedded/apps/chef/lib/chef/knife/client_bulk_delete.rb",
135
147
  "/opt/chefdk/embedded/apps/chef/lib/chef/knife/client_create.rb",
148
+ "/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-#{Chef::VERSION}-x86-mingw32/lib/chef/knife/valid.rb",
149
+ "/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-#{Chef::VERSION}-i386-mingw64/lib/chef/knife/valid-too.rb",
150
+ "/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-#{Chef::VERSION}-mswin32/lib/chef/knife/also-valid.rb",
151
+ "/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-#{Chef::VERSION}-universal-mingw32/lib/chef/knife/universal-is-valid.rb",
136
152
  "/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-vault-2.2.4/lib/chef/knife/decrypt.rb",
137
153
  "/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/knife-spork-1.4.1/lib/chef/knife/spork-bump.rb",
138
154
  "/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-foo-#{Chef::VERSION}/lib/chef/knife/chef-foo.rb",
@@ -368,6 +368,20 @@ EOM
368
368
  @ui.config[:attribute] = "keys.keys"
369
369
  expect(@ui.format_for_display(input)).to eq({ "sample-data-bag-item" => { "keys.keys" => "values" } })
370
370
  end
371
+
372
+ it "should return the name attribute" do
373
+ allow_any_instance_of(Chef::Node).to receive(:name).and_return("chef.localdomain")
374
+ input = Chef::Node.new
375
+ @ui.config[:attribute] = "name"
376
+ expect(@ui.format_for_display(input)).to eq( {"chef.localdomain"=>{"name"=>"chef.localdomain"} })
377
+ end
378
+
379
+ it "returns nil when given an attribute path that isn't a name or attribute" do
380
+ input = { "keys" => {"keys" => "values"}, "hi" => "ho", "id" => "sample-data-bag-item" }
381
+ non_existing_path = "nope.nada.nothingtoseehere"
382
+ @ui.config[:attribute] = non_existing_path
383
+ expect(@ui.format_for_display(input)).to eq({ "sample-data-bag-item" => { non_existing_path => nil } })
384
+ end
371
385
  end
372
386
 
373
387
  describe "with --run-list passed" do
@@ -0,0 +1,93 @@
1
+ #
2
+ # Author:: Steven Danna (<steve@opscode.com>)
3
+ # Copyright:: Copyright (c) 2012 Opscode, 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 'spec_helper'
20
+
21
+ Chef::Knife::OscUserCreate.load_deps
22
+
23
+ # DEPRECATION NOTE
24
+ # This code only remains to support users still operating with
25
+ # Open Source Chef Server 11 and should be removed once support
26
+ # for OSC 11 ends. New development should occur in user_create_spec.rb.
27
+
28
+ describe Chef::Knife::OscUserCreate do
29
+ before(:each) do
30
+ @knife = Chef::Knife::OscUserCreate.new
31
+
32
+ @stdout = StringIO.new
33
+ @stderr = StringIO.new
34
+ allow(@knife.ui).to receive(:stdout).and_return(@stdout)
35
+ allow(@knife.ui).to receive(:stderr).and_return(@stderr)
36
+
37
+ @knife.name_args = [ 'a_user' ]
38
+ @knife.config[:user_password] = "foobar"
39
+ @user = Chef::OscUser.new
40
+ @user.name "a_user"
41
+ @user_with_private_key = Chef::OscUser.new
42
+ @user_with_private_key.name "a_user"
43
+ @user_with_private_key.private_key 'private_key'
44
+ allow(@user).to receive(:create).and_return(@user_with_private_key)
45
+ allow(Chef::OscUser).to receive(:new).and_return(@user)
46
+ allow(Chef::OscUser).to receive(:from_hash).and_return(@user)
47
+ allow(@knife).to receive(:edit_data).and_return(@user.to_hash)
48
+ end
49
+
50
+ it "creates a new user" do
51
+ expect(Chef::OscUser).to receive(:new).and_return(@user)
52
+ expect(@user).to receive(:create)
53
+ @knife.run
54
+ expect(@stderr.string).to match /created user.+a_user/i
55
+ end
56
+
57
+ it "sets the password" do
58
+ @knife.config[:user_password] = "a_password"
59
+ expect(@user).to receive(:password).with("a_password")
60
+ @knife.run
61
+ end
62
+
63
+ it "exits with an error if password is blank" do
64
+ @knife.config[:user_password] = ''
65
+ expect { @knife.run }.to raise_error SystemExit
66
+ expect(@stderr.string).to match /You must specify a non-blank password/
67
+ end
68
+
69
+ it "sets the user name" do
70
+ expect(@user).to receive(:name).with("a_user")
71
+ @knife.run
72
+ end
73
+
74
+ it "sets the public key if given" do
75
+ @knife.config[:user_key] = "/a/filename"
76
+ allow(File).to receive(:read).with(File.expand_path("/a/filename")).and_return("a_key")
77
+ expect(@user).to receive(:public_key).with("a_key")
78
+ @knife.run
79
+ end
80
+
81
+ it "allows you to edit the data" do
82
+ expect(@knife).to receive(:edit_data).with(@user)
83
+ @knife.run
84
+ end
85
+
86
+ it "writes the private key to a file when --file is specified" do
87
+ @knife.config[:file] = "/tmp/a_file"
88
+ filehandle = double("filehandle")
89
+ expect(filehandle).to receive(:print).with('private_key')
90
+ expect(File).to receive(:open).with("/tmp/a_file", "w").and_yield(filehandle)
91
+ @knife.run
92
+ end
93
+ end
@@ -0,0 +1,44 @@
1
+ #
2
+ # Author:: Steven Danna (<steve@opscode.com>)
3
+ # Copyright:: Copyright (c) 2012 Opscode, 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 'spec_helper'
20
+
21
+ # DEPRECATION NOTE
22
+ # This code only remains to support users still operating with
23
+ # Open Source Chef Server 11 and should be removed once support
24
+ # for OSC 11 ends. New development should occur in user_delete_spec.rb.
25
+
26
+ describe Chef::Knife::OscUserDelete do
27
+ before(:each) do
28
+ Chef::Knife::OscUserDelete.load_deps
29
+ @knife = Chef::Knife::OscUserDelete.new
30
+ @knife.name_args = [ 'my_user' ]
31
+ end
32
+
33
+ it 'deletes the user' do
34
+ expect(@knife).to receive(:delete_object).with(Chef::OscUser, 'my_user')
35
+ @knife.run
36
+ end
37
+
38
+ it 'prints usage and exits when a user name is not provided' do
39
+ @knife.name_args = []
40
+ expect(@knife).to receive(:show_usage)
41
+ expect(@knife.ui).to receive(:fatal)
42
+ expect { @knife.run }.to raise_error(SystemExit)
43
+ end
44
+ end
@@ -0,0 +1,52 @@
1
+ #
2
+ # Author:: Steven Danna (<steve@opscode.com>)
3
+ # Copyright:: Copyright (c) 2012 Opscode, 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 'spec_helper'
20
+
21
+ # DEPRECATION NOTE
22
+ # This code only remains to support users still operating with
23
+ # Open Source Chef Server 11 and should be removed once support
24
+ # for OSC 11 ends. New development should occur in user_edit_spec.rb.
25
+
26
+ describe Chef::Knife::OscUserEdit do
27
+ before(:each) do
28
+ @stderr = StringIO.new
29
+ @stdout = StringIO.new
30
+
31
+ Chef::Knife::OscUserEdit.load_deps
32
+ @knife = Chef::Knife::OscUserEdit.new
33
+ allow(@knife.ui).to receive(:stderr).and_return(@stderr)
34
+ allow(@knife.ui).to receive(:stdout).and_return(@stdout)
35
+ @knife.name_args = [ 'my_user' ]
36
+ @knife.config[:disable_editing] = true
37
+ end
38
+
39
+ it 'loads and edits the user' do
40
+ data = { :name => "my_user" }
41
+ allow(Chef::OscUser).to receive(:load).with("my_user").and_return(data)
42
+ expect(@knife).to receive(:edit_data).with(data).and_return(data)
43
+ @knife.run
44
+ end
45
+
46
+ it 'prints usage and exits when a user name is not provided' do
47
+ @knife.name_args = []
48
+ expect(@knife).to receive(:show_usage)
49
+ expect(@knife.ui).to receive(:fatal)
50
+ expect { @knife.run }.to raise_error(SystemExit)
51
+ end
52
+ end
@@ -0,0 +1,37 @@
1
+ #
2
+ # Author:: Steven Danna
3
+ # Copyright:: Copyright (c) 2012 Opscode, 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 'spec_helper'
20
+
21
+ # DEPRECATION NOTE
22
+ # This code only remains to support users still operating with
23
+ # Open Source Chef Server 11 and should be removed once support
24
+ # for OSC 11 ends. New development should occur in user_list_spec.rb.
25
+
26
+ describe Chef::Knife::OscUserList do
27
+ before(:each) do
28
+ Chef::Knife::OscUserList.load_deps
29
+ @knife = Chef::Knife::OscUserList.new
30
+ end
31
+
32
+ it 'lists the users' do
33
+ expect(Chef::OscUser).to receive(:list)
34
+ expect(@knife).to receive(:format_list_for_display)
35
+ @knife.run
36
+ end
37
+ end
@@ -0,0 +1,58 @@
1
+ #
2
+ # Author:: Steven Danna (<steve@opscode.com>)
3
+ # Copyright:: Copyright (c) 2012 Opscode, 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 'spec_helper'
20
+
21
+ # DEPRECATION NOTE
22
+ # This code only remains to support users still operating with
23
+ # Open Source Chef Server 11 and should be removed once support
24
+ # for OSC 11 ends. New development should occur in user_reregister_spec.rb.
25
+
26
+ describe Chef::Knife::OscUserReregister do
27
+ before(:each) do
28
+ Chef::Knife::OscUserReregister.load_deps
29
+ @knife = Chef::Knife::OscUserReregister.new
30
+ @knife.name_args = [ 'a_user' ]
31
+ @user_mock = double('user_mock', :private_key => "private_key")
32
+ allow(Chef::OscUser).to receive(:load).and_return(@user_mock)
33
+ @stdout = StringIO.new
34
+ allow(@knife.ui).to receive(:stdout).and_return(@stdout)
35
+ end
36
+
37
+ it 'prints usage and exits when a user name is not provided' do
38
+ @knife.name_args = []
39
+ expect(@knife).to receive(:show_usage)
40
+ expect(@knife.ui).to receive(:fatal)
41
+ expect { @knife.run }.to raise_error(SystemExit)
42
+ end
43
+
44
+ it 'reregisters the user and prints the key' do
45
+ expect(@user_mock).to receive(:reregister).and_return(@user_mock)
46
+ @knife.run
47
+ expect(@stdout.string).to match( /private_key/ )
48
+ end
49
+
50
+ it 'writes the private key to a file when --file is specified' do
51
+ expect(@user_mock).to receive(:reregister).and_return(@user_mock)
52
+ @knife.config[:file] = '/tmp/a_file'
53
+ filehandle = StringIO.new
54
+ expect(File).to receive(:open).with('/tmp/a_file', 'w').and_yield(filehandle)
55
+ @knife.run
56
+ expect(filehandle.string).to eq("private_key")
57
+ end
58
+ end
@@ -0,0 +1,46 @@
1
+ #
2
+ # Author:: Steven Danna (<steve@opscode.com>)
3
+ # Copyright:: Copyright (c) 2012 Opscode, 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 'spec_helper'
20
+
21
+ # DEPRECATION NOTE
22
+ # This code only remains to support users still operating with
23
+ # Open Source Chef Server 11 and should be removed once support
24
+ # for OSC 11 ends. New development should occur user_show_spec.rb.
25
+
26
+ describe Chef::Knife::OscUserShow do
27
+ before(:each) do
28
+ Chef::Knife::OscUserShow.load_deps
29
+ @knife = Chef::Knife::OscUserShow.new
30
+ @knife.name_args = [ 'my_user' ]
31
+ @user_mock = double('user_mock')
32
+ end
33
+
34
+ it 'loads and displays the user' do
35
+ expect(Chef::OscUser).to receive(:load).with('my_user').and_return(@user_mock)
36
+ expect(@knife).to receive(:format_for_display).with(@user_mock)
37
+ @knife.run
38
+ end
39
+
40
+ it 'prints usage and exits when a user name is not provided' do
41
+ @knife.name_args = []
42
+ expect(@knife).to receive(:show_usage)
43
+ expect(@knife.ui).to receive(:fatal)
44
+ expect { @knife.run }.to raise_error(SystemExit)
45
+ end
46
+ end
@@ -1,6 +1,7 @@
1
1
  #
2
- # Author:: Steven Danna (<steve@opscode.com>)
3
- # Copyright:: Copyright (c) 2012 Opscode, Inc.
2
+ # Author:: Steven Danna (<steve@chef.io>)
3
+ # Author:: Tyler Cloke (<tyler@chef.io>)
4
+ # Copyright:: Copyright (c) 2012, 2015 Chef Software, Inc.
4
5
  # License:: Apache License, Version 2.0
5
6
  #
6
7
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -21,68 +22,193 @@ require 'spec_helper'
21
22
  Chef::Knife::UserCreate.load_deps
22
23
 
23
24
  describe Chef::Knife::UserCreate do
25
+ let(:knife) { Chef::Knife::UserCreate.new }
26
+
27
+ let(:stderr) {
28
+ StringIO.new
29
+ }
30
+
31
+ let(:stdout) {
32
+ StringIO.new
33
+ }
34
+
24
35
  before(:each) do
25
- @knife = Chef::Knife::UserCreate.new
26
-
27
- @stdout = StringIO.new
28
- @stderr = StringIO.new
29
- allow(@knife.ui).to receive(:stdout).and_return(@stdout)
30
- allow(@knife.ui).to receive(:stderr).and_return(@stderr)
31
-
32
- @knife.name_args = [ 'a_user' ]
33
- @knife.config[:user_password] = "foobar"
34
- @user = Chef::User.new
35
- @user.name "a_user"
36
- @user_with_private_key = Chef::User.new
37
- @user_with_private_key.name "a_user"
38
- @user_with_private_key.private_key 'private_key'
39
- allow(@user).to receive(:create).and_return(@user_with_private_key)
40
- allow(Chef::User).to receive(:new).and_return(@user)
41
- allow(Chef::User).to receive(:from_hash).and_return(@user)
42
- allow(@knife).to receive(:edit_data).and_return(@user.to_hash)
36
+ allow(knife.ui).to receive(:stdout).and_return(stdout)
37
+ allow(knife.ui).to receive(:stderr).and_return(stderr)
38
+ allow(knife.ui).to receive(:warn)
43
39
  end
44
40
 
45
- it "creates a new user" do
46
- expect(Chef::User).to receive(:new).and_return(@user)
47
- expect(@user).to receive(:create)
48
- @knife.run
49
- expect(@stderr.string).to match /created user.+a_user/i
50
- end
41
+ # delete this once OSC11 support is gone
42
+ context "when only one name_arg is passed" do
43
+ before do
44
+ knife.name_args = ['some_user']
45
+ allow(knife).to receive(:run_osc_11_user_create).and_raise(SystemExit)
46
+ end
47
+
48
+ it "displays the osc warning" do
49
+ expect(knife.ui).to receive(:warn).with(knife.osc_11_warning)
50
+ expect{ knife.run }.to raise_error(SystemExit)
51
+ end
52
+
53
+ it "calls knife osc_user create" do
54
+ expect(knife).to receive(:run_osc_11_user_create)
55
+ expect{ knife.run }.to raise_error(SystemExit)
56
+ end
51
57
 
52
- it "sets the password" do
53
- @knife.config[:user_password] = "a_password"
54
- expect(@user).to receive(:password).with("a_password")
55
- @knife.run
56
58
  end
57
59
 
58
- it "exits with an error if password is blank" do
59
- @knife.config[:user_password] = ''
60
- expect { @knife.run }.to raise_error SystemExit
61
- expect(@stderr.string).to match /You must specify a non-blank password/
60
+ context "when USERNAME isn't specified" do
61
+ # from spec/support/shared/unit/knife_shared.rb
62
+ it_should_behave_like "mandatory field missing" do
63
+ let(:name_args) { [] }
64
+ let(:fieldname) { 'username' }
65
+ end
62
66
  end
63
67
 
64
- it "sets the user name" do
65
- expect(@user).to receive(:name).with("a_user")
66
- @knife.run
68
+ # uncomment once OSC11 support is gone,
69
+ # pending doesn't work for shared_examples_for by default
70
+ #
71
+ # context "when DISPLAY_NAME isn't specified" do
72
+ # # from spec/support/shared/unit/knife_shared.rb
73
+ # it_should_behave_like "mandatory field missing" do
74
+ # let(:name_args) { ['some_user'] }
75
+ # let(:fieldname) { 'display name' }
76
+ # end
77
+ # end
78
+
79
+ context "when FIRST_NAME isn't specified" do
80
+ # from spec/support/shared/unit/knife_shared.rb
81
+ it_should_behave_like "mandatory field missing" do
82
+ let(:name_args) { ['some_user', 'some_display_name'] }
83
+ let(:fieldname) { 'first name' }
84
+ end
67
85
  end
68
86
 
69
- it "sets the public key if given" do
70
- @knife.config[:user_key] = "/a/filename"
71
- allow(File).to receive(:read).with(File.expand_path("/a/filename")).and_return("a_key")
72
- expect(@user).to receive(:public_key).with("a_key")
73
- @knife.run
87
+ context "when LAST_NAME isn't specified" do
88
+ # from spec/support/shared/unit/knife_shared.rb
89
+ it_should_behave_like "mandatory field missing" do
90
+ let(:name_args) { ['some_user', 'some_display_name', 'some_first_name'] }
91
+ let(:fieldname) { 'last name' }
92
+ end
74
93
  end
75
94
 
76
- it "allows you to edit the data" do
77
- expect(@knife).to receive(:edit_data).with(@user)
78
- @knife.run
95
+ context "when EMAIL isn't specified" do
96
+ # from spec/support/shared/unit/knife_shared.rb
97
+ it_should_behave_like "mandatory field missing" do
98
+ let(:name_args) { ['some_user', 'some_display_name', 'some_first_name', 'some_last_name'] }
99
+ let(:fieldname) { 'email' }
100
+ end
79
101
  end
80
102
 
81
- it "writes the private key to a file when --file is specified" do
82
- @knife.config[:file] = "/tmp/a_file"
83
- filehandle = double("filehandle")
84
- expect(filehandle).to receive(:print).with('private_key')
85
- expect(File).to receive(:open).with("/tmp/a_file", "w").and_yield(filehandle)
86
- @knife.run
103
+ context "when PASSWORD isn't specified" do
104
+ # from spec/support/shared/unit/knife_shared.rb
105
+ it_should_behave_like "mandatory field missing" do
106
+ let(:name_args) { ['some_user', 'some_display_name', 'some_first_name', 'some_last_name', 'some_email'] }
107
+ let(:fieldname) { 'password' }
108
+ end
87
109
  end
110
+
111
+ context "when all mandatory fields are validly specified" do
112
+ before do
113
+ knife.name_args = ['some_user', 'some_display_name', 'some_first_name', 'some_last_name', 'some_email', 'some_password']
114
+ allow(knife).to receive(:edit_data).and_return(knife.user.to_hash)
115
+ allow(knife).to receive(:create_user_from_hash).and_return(knife.user)
116
+ end
117
+
118
+ before(:each) do
119
+ # reset the user field every run
120
+ knife.user_field = nil
121
+ end
122
+
123
+ it "sets all the mandatory fields" do
124
+ knife.run
125
+ expect(knife.user.username).to eq('some_user')
126
+ expect(knife.user.display_name).to eq('some_display_name')
127
+ expect(knife.user.first_name).to eq('some_first_name')
128
+ expect(knife.user.last_name).to eq('some_last_name')
129
+ expect(knife.user.email).to eq('some_email')
130
+ expect(knife.user.password).to eq('some_password')
131
+ end
132
+
133
+ context "when user_key and prevent_keygen are passed" do
134
+ before do
135
+ knife.config[:user_key] = "some_key"
136
+ knife.config[:prevent_keygen] = true
137
+ end
138
+ it "prints the usage" do
139
+ expect(knife).to receive(:show_usage)
140
+ expect { knife.run }.to raise_error(SystemExit)
141
+ end
142
+
143
+ it "prints a relevant error message" do
144
+ expect { knife.run }.to raise_error(SystemExit)
145
+ expect(stderr.string).to match /You cannot pass --user-key and --prevent-keygen/
146
+ end
147
+ end
148
+
149
+ context "when --prevent-keygen is passed" do
150
+ before do
151
+ knife.config[:prevent_keygen] = true
152
+ end
153
+
154
+ it "does not set user.create_key" do
155
+ knife.run
156
+ expect(knife.user.create_key).to be_falsey
157
+ end
158
+ end
159
+
160
+ context "when --prevent-keygen is not passed" do
161
+ it "sets user.create_key to true" do
162
+ knife.run
163
+ expect(knife.user.create_key).to be_truthy
164
+ end
165
+ end
166
+
167
+ context "when --user-key is passed" do
168
+ before do
169
+ knife.config[:user_key] = 'some_key'
170
+ allow(File).to receive(:read).and_return('some_key')
171
+ allow(File).to receive(:expand_path)
172
+ end
173
+
174
+ it "sets user.public_key" do
175
+ knife.run
176
+ expect(knife.user.public_key).to eq('some_key')
177
+ end
178
+ end
179
+
180
+ context "when --user-key is not passed" do
181
+ it "does not set user.public_key" do
182
+ knife.run
183
+ expect(knife.user.public_key).to be_nil
184
+ end
185
+ end
186
+
187
+ context "when a private_key is returned" do
188
+ before do
189
+ allow(knife).to receive(:create_user_from_hash).and_return(Chef::User.from_hash(knife.user.to_hash.merge({"private_key" => "some_private_key"})))
190
+ end
191
+
192
+ context "when --file is passed" do
193
+ before do
194
+ knife.config[:file] = '/some/path'
195
+ end
196
+
197
+ it "creates a new file of the path passed" do
198
+ filehandle = double('filehandle')
199
+ expect(filehandle).to receive(:print).with('some_private_key')
200
+ expect(File).to receive(:open).with('/some/path', 'w').and_yield(filehandle)
201
+ knife.run
202
+ end
203
+ end
204
+
205
+ context "when --file is not passed" do
206
+ it "prints the private key to stdout" do
207
+ expect(knife.ui).to receive(:msg).with('some_private_key')
208
+ knife.run
209
+ end
210
+ end
211
+ end
212
+
213
+ end # when all mandatory fields are validly specified
88
214
  end