chef 12.3.0 → 12.4.0.rc.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (247) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +86 -7
  3. data/distro/common/markdown/man1/chef-shell.mkd +4 -4
  4. data/distro/common/markdown/man1/knife-bootstrap.mkd +1 -1
  5. data/distro/common/markdown/man1/knife-client.mkd +1 -1
  6. data/distro/common/markdown/man1/knife-configure.mkd +1 -1
  7. data/distro/common/markdown/man1/knife-cookbook-site.mkd +1 -1
  8. data/distro/common/markdown/man1/knife-cookbook.mkd +4 -4
  9. data/distro/common/markdown/man1/knife-data-bag.mkd +1 -1
  10. data/distro/common/markdown/man1/knife-environment.mkd +3 -3
  11. data/distro/common/markdown/man1/knife-exec.mkd +1 -1
  12. data/distro/common/markdown/man1/knife-index.mkd +1 -1
  13. data/distro/common/markdown/man1/knife-node.mkd +1 -1
  14. data/distro/common/markdown/man1/knife-role.mkd +3 -3
  15. data/distro/common/markdown/man1/knife-search.mkd +2 -2
  16. data/distro/common/markdown/man1/knife-ssh.mkd +1 -1
  17. data/distro/common/markdown/man1/knife-status.mkd +1 -1
  18. data/distro/common/markdown/man1/knife-tag.mkd +1 -1
  19. data/distro/common/markdown/man1/knife.mkd +2 -2
  20. data/distro/common/markdown/man8/chef-client.mkd +1 -2
  21. data/distro/common/markdown/man8/chef-expander.mkd +1 -2
  22. data/distro/common/markdown/man8/chef-expanderctl.mkd +1 -2
  23. data/distro/common/markdown/man8/chef-server-webui.mkd +1 -1
  24. data/distro/common/markdown/man8/chef-server.mkd +1 -2
  25. data/distro/common/markdown/man8/chef-solo.mkd +2 -2
  26. data/distro/common/markdown/man8/chef-solr.mkd +1 -1
  27. data/lib/chef/client.rb +2 -2
  28. data/lib/chef/config.rb +17 -709
  29. data/lib/chef/cookbook/metadata.rb +9 -5
  30. data/lib/chef/cookbook_loader.rb +1 -1
  31. data/lib/chef/cookbook_site_streaming_uploader.rb +2 -18
  32. data/lib/chef/dsl/definitions.rb +44 -0
  33. data/lib/chef/dsl/recipe.rb +50 -35
  34. data/lib/chef/dsl/resources.rb +28 -0
  35. data/lib/chef/event_dispatch/dispatcher.rb +2 -0
  36. data/lib/chef/event_loggers/windows_eventlog.rb +1 -11
  37. data/lib/chef/exceptions.rb +4 -0
  38. data/lib/chef/file_access_control/unix.rb +5 -0
  39. data/lib/chef/formatters/error_inspectors/api_error_formatting.rb +17 -0
  40. data/lib/chef/formatters/error_inspectors/compile_error_inspector.rb +21 -9
  41. data/lib/chef/formatters/error_inspectors/cookbook_resolve_error_inspector.rb +2 -0
  42. data/lib/chef/formatters/error_inspectors/cookbook_sync_error_inspector.rb +2 -0
  43. data/lib/chef/formatters/error_inspectors/node_load_error_inspector.rb +2 -0
  44. data/lib/chef/formatters/error_inspectors/registration_error_inspector.rb +4 -0
  45. data/lib/chef/formatters/error_inspectors/resource_failure_inspector.rb +11 -1
  46. data/lib/chef/formatters/error_inspectors/run_list_expansion_error_inspector.rb +2 -0
  47. data/lib/chef/http/authenticator.rb +3 -0
  48. data/lib/chef/http/basic_client.rb +10 -6
  49. data/lib/chef/http/json_input.rb +6 -1
  50. data/lib/chef/key.rb +271 -0
  51. data/lib/chef/knife.rb +11 -1
  52. data/lib/chef/knife/bootstrap.rb +6 -0
  53. data/lib/chef/knife/bootstrap/templates/chef-full.erb +166 -23
  54. data/lib/chef/knife/client_key_create.rb +67 -0
  55. data/lib/chef/knife/client_key_delete.rb +76 -0
  56. data/lib/chef/knife/client_key_edit.rb +80 -0
  57. data/lib/chef/knife/client_key_list.rb +69 -0
  58. data/lib/chef/knife/client_key_show.rb +76 -0
  59. data/lib/chef/knife/key_create.rb +108 -0
  60. data/lib/chef/knife/key_create_base.rb +50 -0
  61. data/lib/chef/knife/key_delete.rb +55 -0
  62. data/lib/chef/knife/key_edit.rb +114 -0
  63. data/lib/chef/knife/key_edit_base.rb +55 -0
  64. data/lib/chef/knife/key_list.rb +88 -0
  65. data/lib/chef/knife/key_list_base.rb +45 -0
  66. data/lib/chef/knife/key_show.rb +53 -0
  67. data/lib/chef/knife/ssh.rb +26 -28
  68. data/lib/chef/knife/user_key_create.rb +69 -0
  69. data/lib/chef/knife/user_key_delete.rb +76 -0
  70. data/lib/chef/knife/user_key_edit.rb +80 -0
  71. data/lib/chef/knife/user_key_list.rb +69 -0
  72. data/lib/chef/knife/user_key_show.rb +76 -0
  73. data/lib/chef/log.rb +2 -0
  74. data/lib/chef/log/syslog.rb +46 -0
  75. data/lib/chef/log/winevt.rb +99 -0
  76. data/lib/chef/mixin/provides.rb +8 -1
  77. data/lib/chef/mixin/unformatter.rb +32 -0
  78. data/lib/chef/mixin/uris.rb +33 -0
  79. data/lib/chef/mixin/wstring.rb +31 -0
  80. data/lib/chef/node.rb +21 -2
  81. data/lib/chef/platform/provider_mapping.rb +8 -4
  82. data/lib/chef/platform/query_helpers.rb +1 -5
  83. data/lib/chef/platform/service_helpers.rb +21 -21
  84. data/lib/chef/provider.rb +33 -0
  85. data/lib/chef/provider/cron/unix.rb +1 -0
  86. data/lib/chef/provider/file.rb +5 -3
  87. data/lib/chef/provider/lwrp_base.rb +76 -58
  88. data/lib/chef/provider/ohai.rb +1 -0
  89. data/lib/chef/provider/package.rb +7 -4
  90. data/lib/chef/provider/package/aix.rb +1 -0
  91. data/lib/chef/provider/package/smartos.rb +5 -5
  92. data/lib/chef/provider/package/windows.rb +90 -6
  93. data/lib/chef/provider/package/yum.rb +102 -32
  94. data/lib/chef/provider/reboot.rb +1 -0
  95. data/lib/chef/provider/registry_key.rb +2 -0
  96. data/lib/chef/provider/remote_file.rb +1 -0
  97. data/lib/chef/provider/remote_file/content.rb +5 -1
  98. data/lib/chef/provider/remote_file/fetcher.rb +22 -8
  99. data/lib/chef/provider/remote_file/network_file.rb +48 -0
  100. data/lib/chef/provider/service/aix.rb +13 -12
  101. data/lib/chef/provider_resolver.rb +87 -0
  102. data/lib/chef/providers.rb +1 -0
  103. data/lib/chef/resource.rb +67 -8
  104. data/lib/chef/resource/bash.rb +1 -0
  105. data/lib/chef/resource/bff_package.rb +1 -2
  106. data/lib/chef/resource/breakpoint.rb +1 -0
  107. data/lib/chef/resource/csh.rb +1 -0
  108. data/lib/chef/resource/deploy.rb +1 -0
  109. data/lib/chef/resource/erl_call.rb +1 -0
  110. data/lib/chef/resource/execute.rb +1 -0
  111. data/lib/chef/resource/file.rb +18 -0
  112. data/lib/chef/resource/http_request.rb +1 -0
  113. data/lib/chef/resource/ifconfig.rb +1 -2
  114. data/lib/chef/resource/log.rb +1 -2
  115. data/lib/chef/resource/lwrp_base.rb +106 -87
  116. data/lib/chef/resource/ohai.rb +1 -0
  117. data/lib/chef/resource/package.rb +1 -0
  118. data/lib/chef/resource/perl.rb +1 -0
  119. data/lib/chef/resource/portage_package.rb +1 -0
  120. data/lib/chef/resource/python.rb +1 -0
  121. data/lib/chef/resource/reboot.rb +2 -0
  122. data/lib/chef/resource/registry_key.rb +1 -0
  123. data/lib/chef/resource/remote_file.rb +1 -1
  124. data/lib/chef/resource/route.rb +1 -2
  125. data/lib/chef/resource/ruby.rb +1 -0
  126. data/lib/chef/resource/ruby_block.rb +1 -0
  127. data/lib/chef/resource/scm.rb +1 -0
  128. data/lib/chef/resource/script.rb +1 -0
  129. data/lib/chef/resource/service.rb +1 -0
  130. data/lib/chef/resource/subversion.rb +1 -0
  131. data/lib/chef/resource/whyrun_safe_ruby_block.rb +1 -0
  132. data/lib/chef/resource/windows_package.rb +24 -2
  133. data/lib/chef/resource/windows_script.rb +1 -0
  134. data/lib/chef/resource/yum_package.rb +1 -1
  135. data/lib/chef/resource_definition.rb +1 -0
  136. data/lib/chef/resource_reporter.rb +3 -10
  137. data/lib/chef/resource_resolver.rb +20 -10
  138. data/lib/chef/run_context.rb +1 -0
  139. data/lib/chef/run_list/versioned_recipe_list.rb +18 -0
  140. data/lib/chef/run_status.rb +2 -4
  141. data/lib/chef/shell.rb +1 -1
  142. data/lib/chef/util/path_helper.rb +3 -204
  143. data/lib/chef/util/windows/net_user.rb +73 -118
  144. data/lib/chef/version.rb +8 -4
  145. data/lib/chef/win32/api.rb +2 -1
  146. data/lib/chef/win32/api/installer.rb +1 -1
  147. data/lib/chef/win32/api/net.rb +115 -2
  148. data/lib/chef/win32/api/security.rb +24 -0
  149. data/lib/chef/win32/api/unicode.rb +1 -1
  150. data/lib/chef/win32/eventlog.rb +31 -0
  151. data/lib/chef/win32/net.rb +190 -0
  152. data/lib/chef/win32/security.rb +51 -2
  153. data/lib/chef/win32/security/sid.rb +17 -0
  154. data/spec/data/lwrp/providers/buck_passer.rb +18 -2
  155. data/spec/data/lwrp/providers/buck_passer_2.rb +18 -2
  156. data/spec/data/lwrp/providers/embedded_resource_accesses_providers_scope.rb +14 -2
  157. data/spec/data/lwrp_override/resources/foo.rb +5 -0
  158. data/spec/functional/knife/ssh_spec.rb +2 -2
  159. data/spec/functional/rebooter_spec.rb +1 -1
  160. data/spec/functional/resource/aixinit_service_spec.rb +1 -1
  161. data/spec/functional/resource/user/windows_spec.rb +125 -0
  162. data/spec/functional/shell_spec.rb +25 -10
  163. data/spec/functional/win32/sid_spec.rb +55 -0
  164. data/spec/integration/client/client_spec.rb +53 -29
  165. data/spec/integration/knife/deps_spec.rb +8 -14
  166. data/spec/integration/knife/upload_spec.rb +18 -0
  167. data/spec/integration/recipes/lwrp_inline_resources_spec.rb +1 -1
  168. data/spec/integration/recipes/provider_choice.rb +41 -0
  169. data/spec/integration/recipes/recipe_dsl_spec.rb +259 -0
  170. data/spec/spec_helper.rb +6 -1
  171. data/spec/support/key_helpers.rb +104 -0
  172. data/spec/support/lib/chef/resource/cat.rb +1 -0
  173. data/spec/support/lib/chef/resource/one_two_three_four.rb +2 -0
  174. data/spec/support/lib/chef/resource/zen_follower.rb +1 -0
  175. data/spec/support/lib/chef/resource/zen_master.rb +2 -0
  176. data/spec/support/mock/platform.rb +1 -1
  177. data/spec/support/pedant/Gemfile.lock +67 -0
  178. data/spec/support/shared/functional/securable_resource.rb +34 -12
  179. data/spec/support/shared/integration/integration_helper.rb +6 -5
  180. data/spec/support/shared/unit/provider/file.rb +31 -8
  181. data/spec/unit/application/client_spec.rb +2 -2
  182. data/spec/unit/client_spec.rb +21 -4
  183. data/spec/unit/cookbook/cookbook_version_loader_spec.rb +1 -1
  184. data/spec/unit/cookbook/metadata_spec.rb +15 -0
  185. data/spec/unit/cookbook/syntax_check_spec.rb +1 -1
  186. data/spec/unit/cookbook_loader_spec.rb +1 -1
  187. data/spec/unit/cookbook_site_streaming_uploader_spec.rb +0 -21
  188. data/spec/unit/data_bag_spec.rb +1 -1
  189. data/spec/unit/event_dispatch/dispatcher_spec.rb +61 -0
  190. data/spec/unit/formatters/error_inspectors/api_error_formatting_spec.rb +75 -0
  191. data/spec/unit/formatters/error_inspectors/compile_error_inspector_spec.rb +149 -112
  192. data/spec/unit/formatters/error_inspectors/resource_failure_inspector_spec.rb +7 -0
  193. data/spec/unit/guard_interpreter/resource_guard_interpreter_spec.rb +1 -1
  194. data/spec/unit/http/authenticator_spec.rb +69 -0
  195. data/spec/unit/http/basic_client_spec.rb +16 -0
  196. data/spec/unit/key_spec.rb +634 -0
  197. data/spec/unit/knife/bootstrap_spec.rb +14 -1
  198. data/spec/unit/knife/core/subcommand_loader_spec.rb +1 -1
  199. data/spec/unit/knife/core/ui_spec.rb +1 -1
  200. data/spec/unit/knife/data_bag_from_file_spec.rb +1 -1
  201. data/spec/unit/knife/environment_from_file_spec.rb +1 -1
  202. data/spec/unit/knife/key_create_spec.rb +224 -0
  203. data/spec/unit/knife/key_delete_spec.rb +135 -0
  204. data/spec/unit/knife/key_edit_spec.rb +267 -0
  205. data/spec/unit/knife/key_helper.rb +74 -0
  206. data/spec/unit/knife/key_list_spec.rb +216 -0
  207. data/spec/unit/knife/key_show_spec.rb +126 -0
  208. data/spec/unit/knife/ssh_spec.rb +23 -26
  209. data/spec/unit/knife_spec.rb +33 -1
  210. data/spec/unit/log/syslog_spec.rb +53 -0
  211. data/spec/unit/log/winevt_spec.rb +55 -0
  212. data/spec/unit/lwrp_spec.rb +105 -51
  213. data/spec/unit/mixin/path_sanity_spec.rb +2 -2
  214. data/spec/unit/mixin/template_spec.rb +2 -2
  215. data/spec/unit/mixin/unformatter_spec.rb +61 -0
  216. data/spec/unit/mixin/uris_spec.rb +45 -0
  217. data/spec/unit/platform/query_helpers_spec.rb +1 -1
  218. data/spec/unit/policy_builder/policyfile_spec.rb +7 -3
  219. data/spec/unit/provider/deploy/revision_spec.rb +1 -1
  220. data/spec/unit/provider/deploy_spec.rb +1 -1
  221. data/spec/unit/provider/directory_spec.rb +1 -1
  222. data/spec/unit/provider/execute_spec.rb +1 -1
  223. data/spec/unit/provider/package/aix_spec.rb +20 -8
  224. data/spec/unit/provider/package/smartos_spec.rb +50 -40
  225. data/spec/unit/provider/package/windows_spec.rb +104 -25
  226. data/spec/unit/provider/package/yum_spec.rb +111 -1
  227. data/spec/unit/provider/package_spec.rb +6 -0
  228. data/spec/unit/provider/remote_file/fetcher_spec.rb +20 -1
  229. data/spec/unit/provider/remote_file/network_file_spec.rb +45 -0
  230. data/spec/unit/provider/service/aix_service_spec.rb +26 -11
  231. data/spec/unit/provider/user/dscl_spec.rb +1 -1
  232. data/spec/unit/provider_spec.rb +20 -0
  233. data/spec/unit/recipe_spec.rb +1 -1
  234. data/spec/unit/resource/batch_spec.rb +1 -0
  235. data/spec/unit/resource/powershell_spec.rb +1 -0
  236. data/spec/unit/resource/remote_file_spec.rb +10 -0
  237. data/spec/unit/resource/windows_package_spec.rb +16 -2
  238. data/spec/unit/resource_spec.rb +40 -24
  239. data/spec/unit/rest_spec.rb +10 -20
  240. data/spec/unit/role_spec.rb +1 -1
  241. data/spec/unit/run_context_spec.rb +31 -0
  242. data/spec/unit/shell_spec.rb +4 -4
  243. data/tasks/external_tests.rb +29 -0
  244. data/tasks/rspec.rb +14 -1
  245. metadata +105 -28
  246. data/spec/unit/config_spec.rb +0 -544
  247. data/spec/unit/util/path_helper_spec.rb +0 -255
@@ -23,7 +23,7 @@ require 'net/ssh'
23
23
 
24
24
  describe Chef::Knife::Bootstrap do
25
25
  before do
26
- allow(Chef::Platform).to receive(:windows?) { false }
26
+ allow(ChefConfig).to receive(:windows?) { false }
27
27
  end
28
28
  let(:knife) do
29
29
  Chef::Log.logger = Logger.new(StringIO.new)
@@ -531,6 +531,7 @@ describe Chef::Knife::Bootstrap do
531
531
  describe "when running the bootstrap" do
532
532
  let(:knife_ssh) do
533
533
  knife.name_args = ["foo.example.com"]
534
+ knife.config[:chef_node_name] = "foo.example.com"
534
535
  knife.config[:ssh_user] = "rooty"
535
536
  knife.config[:identity_file] = "~/.ssh/me.rsa"
536
537
  allow(knife).to receive(:render_template).and_return("")
@@ -590,6 +591,12 @@ describe Chef::Knife::Bootstrap do
590
591
  expect(knife.chef_vault_handler).not_to receive(:run).with(node_name: knife.config[:chef_node_name])
591
592
  knife.run
592
593
  end
594
+
595
+ it "raises an exception if the config[:chef_node_name] is not present" do
596
+ knife.config[:chef_node_name] = nil
597
+
598
+ expect { knife.run }.to raise_error(SystemExit)
599
+ end
593
600
  end
594
601
 
595
602
  context "when the validation key is not present" do
@@ -604,6 +611,12 @@ describe Chef::Knife::Bootstrap do
604
611
  expect(knife.chef_vault_handler).to receive(:run).with(node_name: knife.config[:chef_node_name])
605
612
  knife.run
606
613
  end
614
+
615
+ it "raises an exception if the config[:chef_node_name] is not present" do
616
+ knife.config[:chef_node_name] = nil
617
+
618
+ expect { knife.run }.to raise_error(SystemExit)
619
+ end
607
620
  end
608
621
 
609
622
  context "when the validation_key is nil" do
@@ -24,7 +24,7 @@ describe Chef::Knife::SubcommandLoader do
24
24
  let(:plugin_dir) { File.join(home, '.chef', 'plugins', 'knife') }
25
25
 
26
26
  before do
27
- allow(Chef::Platform).to receive(:windows?) { false }
27
+ allow(ChefConfig).to receive(:windows?) { false }
28
28
  Chef::Util::PathHelper.class_variable_set(:@@home_dir, home)
29
29
  end
30
30
 
@@ -420,7 +420,7 @@ EOM
420
420
  before(:each) do
421
421
  stdout = double('StringIO', :tty? => true)
422
422
  allow(@ui).to receive(:stdout).and_return(stdout)
423
- allow(Chef::Platform).to receive(:windows?) { true }
423
+ allow(ChefConfig).to receive(:windows?) { true }
424
424
  Chef::Config.reset
425
425
  end
426
426
 
@@ -26,7 +26,7 @@ Chef::Knife::DataBagFromFile.load_deps
26
26
 
27
27
  describe Chef::Knife::DataBagFromFile do
28
28
  before :each do
29
- allow(Chef::Platform).to receive(:windows?) { false }
29
+ allow(ChefConfig).to receive(:windows?) { false }
30
30
  Chef::Config[:node_name] = "webmonkey.example.com"
31
31
  FileUtils.mkdir_p([db_folder, db_folder2])
32
32
  db_file.write(Chef::JSONCompat.to_json(plain_data))
@@ -23,7 +23,7 @@ Chef::Knife::EnvironmentFromFile.load_deps
23
23
 
24
24
  describe Chef::Knife::EnvironmentFromFile do
25
25
  before(:each) do
26
- allow(Chef::Platform).to receive(:windows?) { false }
26
+ allow(ChefConfig).to receive(:windows?) { false }
27
27
  @knife = Chef::Knife::EnvironmentFromFile.new
28
28
  @stdout = StringIO.new
29
29
  allow(@knife.ui).to receive(:stdout).and_return(@stdout)
@@ -0,0 +1,224 @@
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 'spec_helper'
20
+ require 'chef/knife/user_key_create'
21
+ require 'chef/knife/client_key_create'
22
+ require 'chef/knife/key_create'
23
+ require 'chef/key'
24
+
25
+ describe "key create commands that inherit knife" do
26
+ shared_examples_for "a key create command" do
27
+ let(:stderr) { StringIO.new }
28
+ let(:params) { [] }
29
+ let(:service_object) { instance_double(Chef::Knife::KeyCreate) }
30
+ let(:command) do
31
+ c = described_class.new([])
32
+ c.ui.config[:disable_editing] = true
33
+ allow(c.ui).to receive(:stderr).and_return(stderr)
34
+ allow(c.ui).to receive(:stdout).and_return(stderr)
35
+ allow(c).to receive(:show_usage)
36
+ c
37
+ end
38
+
39
+ context "after apply_params! is called with valid args" do
40
+ let(:params) { ["charmander"] }
41
+ before do
42
+ command.apply_params!(params)
43
+ end
44
+
45
+ context "when the service object is called" do
46
+ it "creates a new instance of Chef::Knife::KeyCreate with the correct args" do
47
+ expect(Chef::Knife::KeyCreate).to receive(:new).
48
+ with("charmander", command.actor_field_name, command.ui, command.config).
49
+ and_return(service_object)
50
+ command.service_object
51
+ end
52
+ end # when the service object is called
53
+ end # after apply_params! is called with valid args
54
+ end # a key create command
55
+
56
+ describe Chef::Knife::UserKeyCreate do
57
+ it_should_behave_like "a key create command"
58
+ # defined in key_helper.rb
59
+ it_should_behave_like "a knife key command" do
60
+ let(:service_object) { instance_double(Chef::Knife::KeyCreate) }
61
+ let(:params) { ["charmander"] }
62
+ end
63
+ end
64
+
65
+ describe Chef::Knife::ClientKeyCreate do
66
+ it_should_behave_like "a key create command"
67
+ # defined in key_helper.rb
68
+ it_should_behave_like "a knife key command" do
69
+ let(:service_object) { instance_double(Chef::Knife::KeyCreate) }
70
+ let(:params) { ["charmander"] }
71
+ end
72
+ end
73
+ end
74
+
75
+ describe Chef::Knife::KeyCreate do
76
+ let(:public_key) {
77
+ "-----BEGIN PUBLIC KEY-----
78
+ MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvPo+oNPB7uuNkws0fC02
79
+ KxSwdyqPLu0fhI1pOweNKAZeEIiEz2PkybathHWy8snSXGNxsITkf3eyvIIKa8OZ
80
+ WrlqpI3yv/5DOP8HTMCxnFuMJQtDwMcevlqebX4bCxcByuBpNYDcAHjjfLGSfMjn
81
+ E5lZpgYWwnpic4kSjYcL9ORK9nYvlWV9P/kCYmRhIjB4AhtpWRiOfY/TKi3P2LxT
82
+ IjSmiN/ihHtlhV/VSnBJ5PzT/lRknlrJ4kACoz7Pq9jv+aAx5ft/xE9yDa2DYs0q
83
+ Tfuc9dUYsFjptWYrV6pfEQ+bgo1OGBXORBFcFL+2D7u9JYquKrMgosznHoEkQNLo
84
+ 0wIDAQAB
85
+ -----END PUBLIC KEY-----"
86
+ }
87
+ let(:config) { Hash.new }
88
+ let(:actor) { "charmander" }
89
+ let(:ui) { instance_double("Chef::Knife::UI") }
90
+
91
+ shared_examples_for "key create run command" do
92
+ let(:key_create_object) {
93
+ described_class.new(actor, actor_field_name, ui, config)
94
+ }
95
+
96
+ context "when public_key and key_name weren't passed" do
97
+ it "raises a Chef::Exceptions::KeyCommandInputError with the proper error message" do
98
+ expect{ key_create_object.run }.to raise_error(Chef::Exceptions::KeyCommandInputError, key_create_object.public_key_or_key_name_error_msg)
99
+ end
100
+ end
101
+
102
+ context "when the command is run" do
103
+ let(:expected_hash) {
104
+ {
105
+ actor_field_name => "charmander"
106
+ }
107
+ }
108
+
109
+ before do
110
+ allow(File).to receive(:read).and_return(public_key)
111
+ allow(File).to receive(:expand_path)
112
+
113
+ allow(key_create_object).to receive(:output_private_key_to_file)
114
+ allow(key_create_object).to receive(:display_private_key)
115
+ allow(key_create_object).to receive(:edit_data).and_return(expected_hash)
116
+ allow(key_create_object).to receive(:create_key_from_hash).and_return(Chef::Key.from_hash(expected_hash))
117
+ allow(key_create_object).to receive(:display_info)
118
+ end
119
+
120
+ context "when a valid hash is passed" do
121
+ let(:key_name) { "charmander-key" }
122
+ let(:valid_expiration_date) { "2020-12-24T21:00:00Z" }
123
+ let(:expected_hash) {
124
+ {
125
+ actor_field_name => "charmander",
126
+ "public_key" => public_key,
127
+ "expiration_date" => valid_expiration_date,
128
+ "key_name" => key_name
129
+ }
130
+ }
131
+ before do
132
+ key_create_object.config[:public_key] = "public_key_path"
133
+ key_create_object.config[:expiration_Date] = valid_expiration_date,
134
+ key_create_object.config[:key_name] = key_name
135
+ end
136
+
137
+ it "creates the proper hash" do
138
+ expect(key_create_object).to receive(:create_key_from_hash).with(expected_hash)
139
+ key_create_object.run
140
+ end
141
+ end
142
+
143
+ context "when public_key is passed" do
144
+ let(:expected_hash) {
145
+ {
146
+ actor_field_name => "charmander",
147
+ "public_key" => public_key
148
+ }
149
+ }
150
+ before do
151
+ key_create_object.config[:public_key] = "public_key_path"
152
+ end
153
+
154
+ it "calls File.expand_path with the public_key input" do
155
+ expect(File).to receive(:expand_path).with("public_key_path")
156
+ key_create_object.run
157
+ end
158
+ end # when public_key is passed
159
+
160
+ context "when public_key isn't passed and key_name is" do
161
+ let(:expected_hash) {
162
+ {
163
+ actor_field_name => "charmander",
164
+ "name" => "charmander-key",
165
+ "create_key" => true
166
+ }
167
+ }
168
+ before do
169
+ key_create_object.config[:key_name] = "charmander-key"
170
+ end
171
+
172
+ it "should set create_key to true" do
173
+ expect(key_create_object).to receive(:create_key_from_hash).with(expected_hash)
174
+ key_create_object.run
175
+ end
176
+ end
177
+
178
+ context "when the server returns a private key" do
179
+ let(:expected_hash) {
180
+ {
181
+ actor_field_name => "charmander",
182
+ "public_key" => public_key,
183
+ "private_key" => "super_private"
184
+ }
185
+ }
186
+
187
+ before do
188
+ key_create_object.config[:public_key] = "public_key_path"
189
+ end
190
+
191
+ context "when file is not passed" do
192
+ it "calls display_private_key with the private_key" do
193
+ expect(key_create_object).to receive(:display_private_key).with("super_private")
194
+ key_create_object.run
195
+ end
196
+ end
197
+
198
+ context "when file is passed" do
199
+ before do
200
+ key_create_object.config[:file] = "/fake/file"
201
+ end
202
+
203
+ it "calls output_private_key_to_file with the private_key" do
204
+ expect(key_create_object).to receive(:output_private_key_to_file).with("super_private")
205
+ key_create_object.run
206
+ end
207
+ end
208
+ end # when the server returns a private key
209
+ end # when the command is run
210
+ end #key create run command"
211
+
212
+ context "when actor_field_name is 'user'" do
213
+ it_should_behave_like "key create run command" do
214
+ let(:actor_field_name) { "user" }
215
+ end
216
+ end
217
+
218
+ context "when actor_field_name is 'client'" do
219
+ it_should_behave_like "key create run command" do
220
+ let(:actor_field_name) { "client" }
221
+ end
222
+ end
223
+ end
224
+
@@ -0,0 +1,135 @@
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 'spec_helper'
20
+ require 'chef/knife/user_key_delete'
21
+ require 'chef/knife/client_key_delete'
22
+ require 'chef/knife/key_delete'
23
+ require 'chef/key'
24
+
25
+ describe "key delete commands that inherit knife" do
26
+ shared_examples_for "a key delete command" do
27
+ let(:stderr) { StringIO.new }
28
+ let(:params) { [] }
29
+ let(:service_object) { instance_double(Chef::Knife::KeyDelete) }
30
+ let(:command) do
31
+ c = described_class.new([])
32
+ c.ui.config[:disable_editing] = true
33
+ allow(c.ui).to receive(:stderr).and_return(stderr)
34
+ allow(c.ui).to receive(:stdout).and_return(stderr)
35
+ allow(c).to receive(:show_usage)
36
+ c
37
+ end
38
+
39
+ context "after apply_params! is called with valid args" do
40
+ let(:params) { ["charmander", "charmander-key"] }
41
+ before do
42
+ command.apply_params!(params)
43
+ end
44
+
45
+ context "when the service object is called" do
46
+ it "creates a new instance of Chef::Knife::KeyDelete with the correct args" do
47
+ expect(Chef::Knife::KeyDelete).to receive(:new).
48
+ with("charmander-key", "charmander", command.actor_field_name, command.ui).
49
+ and_return(service_object)
50
+ command.service_object
51
+ end
52
+ end # when the service object is called
53
+ end # after apply_params! is called with valid args
54
+ end # a key delete command
55
+
56
+ describe Chef::Knife::UserKeyDelete do
57
+ it_should_behave_like "a key delete command"
58
+ # defined in key_helpers.rb
59
+ it_should_behave_like "a knife key command with a keyname as the second arg"
60
+ it_should_behave_like "a knife key command" do
61
+ let(:service_object) { instance_double(Chef::Knife::KeyDelete) }
62
+ let(:params) { ["charmander", "charmander-key"] }
63
+ end
64
+ end
65
+
66
+ describe Chef::Knife::ClientKeyDelete do
67
+ it_should_behave_like "a key delete command"
68
+ # defined in key_helpers.rb
69
+ it_should_behave_like "a knife key command with a keyname as the second arg"
70
+ it_should_behave_like "a knife key command" do
71
+ let(:service_object) { instance_double(Chef::Knife::KeyDelete) }
72
+ let(:params) { ["charmander", "charmander-key"] }
73
+ end
74
+ end
75
+ end
76
+
77
+ describe Chef::Knife::KeyDelete do
78
+ let(:actor) { "charmander" }
79
+ let(:keyname) { "charmander-key" }
80
+ let(:ui) { instance_double("Chef::Knife::UI") }
81
+
82
+ shared_examples_for "key delete run command" do
83
+ let(:key_delete_object) {
84
+ described_class.new(keyname, actor, actor_field_name, ui)
85
+ }
86
+
87
+ before do
88
+ allow_any_instance_of(Chef::Key).to receive(:destroy)
89
+ allow(key_delete_object).to receive(:print_destroyed)
90
+ allow(key_delete_object).to receive(:confirm!)
91
+ end
92
+
93
+ context "when the command is run" do
94
+ it "calls Chef::Key.new with the proper input" do
95
+ expect(Chef::Key).to receive(:new).with(actor, actor_field_name).and_call_original
96
+ key_delete_object.run
97
+ end
98
+
99
+ it "calls name on the Chef::Key instance with the proper input" do
100
+ expect_any_instance_of(Chef::Key).to receive(:name).with(keyname)
101
+ key_delete_object.run
102
+ end
103
+
104
+ it "calls destroy on the Chef::Key instance" do
105
+ expect_any_instance_of(Chef::Key).to receive(:destroy).once
106
+ key_delete_object.run
107
+ end
108
+
109
+ it "calls confirm!" do
110
+ expect(key_delete_object).to receive(:confirm!)
111
+ key_delete_object.run
112
+ end
113
+
114
+ it "calls print_destroyed" do
115
+ expect(key_delete_object).to receive(:print_destroyed)
116
+ key_delete_object.run
117
+ end
118
+ end # when the command is run
119
+
120
+
121
+ end # key delete run command
122
+
123
+ context "when actor_field_name is 'user'" do
124
+ it_should_behave_like "key delete run command" do
125
+ let(:actor_field_name) { "user" }
126
+ end
127
+ end
128
+
129
+ context "when actor_field_name is 'client'" do
130
+ it_should_behave_like "key delete run command" do
131
+ let(:actor_field_name) { "client" }
132
+ end
133
+ end
134
+ end
135
+
@@ -0,0 +1,267 @@
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 'spec_helper'
20
+ require 'chef/knife/user_key_edit'
21
+ require 'chef/knife/client_key_edit'
22
+ require 'chef/knife/key_edit'
23
+ require 'chef/key'
24
+
25
+ describe "key edit commands that inherit knife" do
26
+ shared_examples_for "a key edit command" do
27
+ let(:stderr) { StringIO.new }
28
+ let(:params) { [] }
29
+ let(:service_object) { instance_double(Chef::Knife::KeyEdit) }
30
+ let(:command) do
31
+ c = described_class.new([])
32
+ c.ui.config[:disable_editing] = true
33
+ allow(c.ui).to receive(:stderr).and_return(stderr)
34
+ allow(c.ui).to receive(:stdout).and_return(stderr)
35
+ allow(c).to receive(:show_usage)
36
+ c
37
+ end
38
+
39
+ context "after apply_params! is called with valid args" do
40
+ let(:params) { ["charmander", "charmander-key"] }
41
+ before do
42
+ command.apply_params!(params)
43
+ end
44
+
45
+ context "when the service object is called" do
46
+ it "creates a new instance of Chef::Knife::KeyEdit with the correct args" do
47
+ expect(Chef::Knife::KeyEdit).to receive(:new).
48
+ with("charmander-key", "charmander", command.actor_field_name, command.ui, command.config).
49
+ and_return(service_object)
50
+ command.service_object
51
+ end
52
+ end # when the service object is called
53
+ end # after apply_params! is called with valid args
54
+ end # a key edit command
55
+
56
+ describe Chef::Knife::UserKeyEdit do
57
+ it_should_behave_like "a key edit command"
58
+ # defined in key_helpers.rb
59
+ it_should_behave_like "a knife key command with a keyname as the second arg"
60
+ it_should_behave_like "a knife key command" do
61
+ let(:service_object) { instance_double(Chef::Knife::KeyEdit) }
62
+ let(:params) { ["charmander", "charmander-key"] }
63
+ end
64
+ end
65
+
66
+ describe Chef::Knife::ClientKeyEdit do
67
+ it_should_behave_like "a key edit command"
68
+ # defined in key_helpers.rb
69
+ it_should_behave_like "a knife key command with a keyname as the second arg"
70
+ it_should_behave_like "a knife key command" do
71
+ let(:service_object) { instance_double(Chef::Knife::KeyEdit) }
72
+ let(:params) { ["charmander", "charmander-key"] }
73
+ end
74
+ end
75
+ end
76
+
77
+ describe Chef::Knife::KeyEdit do
78
+ let(:public_key) {
79
+ "-----BEGIN PUBLIC KEY-----
80
+ MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvPo+oNPB7uuNkws0fC02
81
+ KxSwdyqPLu0fhI1pOweNKAZeEIiEz2PkybathHWy8snSXGNxsITkf3eyvIIKa8OZ
82
+ WrlqpI3yv/5DOP8HTMCxnFuMJQtDwMcevlqebX4bCxcByuBpNYDcAHjjfLGSfMjn
83
+ E5lZpgYWwnpic4kSjYcL9ORK9nYvlWV9P/kCYmRhIjB4AhtpWRiOfY/TKi3P2LxT
84
+ IjSmiN/ihHtlhV/VSnBJ5PzT/lRknlrJ4kACoz7Pq9jv+aAx5ft/xE9yDa2DYs0q
85
+ Tfuc9dUYsFjptWYrV6pfEQ+bgo1OGBXORBFcFL+2D7u9JYquKrMgosznHoEkQNLo
86
+ 0wIDAQAB
87
+ -----END PUBLIC KEY-----"
88
+ }
89
+ let(:config) { Hash.new }
90
+ let(:actor) { "charmander" }
91
+ let(:keyname) { "charmander-key" }
92
+ let(:ui) { instance_double("Chef::Knife::UI") }
93
+
94
+ shared_examples_for "key edit run command" do
95
+ let(:key_edit_object) {
96
+ described_class.new(keyname, actor, actor_field_name, ui, config)
97
+ }
98
+
99
+ context "when the command is run" do
100
+ let(:expected_hash) {
101
+ {
102
+ actor_field_name => "charmander"
103
+ }
104
+ }
105
+ let(:new_keyname) { "charizard-key" }
106
+
107
+ before do
108
+ allow(File).to receive(:read).and_return(public_key)
109
+ allow(File).to receive(:expand_path)
110
+
111
+ allow(key_edit_object).to receive(:output_private_key_to_file)
112
+ allow(key_edit_object).to receive(:display_private_key)
113
+ allow(key_edit_object).to receive(:edit_data).and_return(expected_hash)
114
+ allow(key_edit_object).to receive(:display_info)
115
+ end
116
+
117
+
118
+ context "when public_key and create_key are passed" do
119
+ before do
120
+ key_edit_object.config[:public_key] = "public_key_path"
121
+ key_edit_object.config[:create_key] = true
122
+ end
123
+
124
+ it "raises a Chef::Exceptions::KeyCommandInputError with the proper error message" do
125
+ expect{ key_edit_object.run }.to raise_error(Chef::Exceptions::KeyCommandInputError, key_edit_object.public_key_and_create_key_error_msg)
126
+ end
127
+ end
128
+
129
+ context "when key_name is passed" do
130
+ let(:expected_hash) {
131
+ {
132
+ actor_field_name => "charmander",
133
+ "name" => new_keyname
134
+ }
135
+ }
136
+ before do
137
+ key_edit_object.config[:key_name] = new_keyname
138
+ allow_any_instance_of(Chef::Key).to receive(:update)
139
+ end
140
+
141
+ it "update_key_from_hash gets passed a hash with new key name" do
142
+ expect(key_edit_object).to receive(:update_key_from_hash).with(expected_hash).and_return(Chef::Key.from_hash(expected_hash))
143
+ key_edit_object.run
144
+ end
145
+
146
+ it "Chef::Key.update is passed a string containing the original keyname" do
147
+ expect_any_instance_of(Chef::Key).to receive(:update).with(/#{keyname}/).and_return(Chef::Key.from_hash(expected_hash))
148
+ key_edit_object.run
149
+ end
150
+
151
+ it "Chef::Key.update is not passed a string containing the new keyname" do
152
+ expect_any_instance_of(Chef::Key).not_to receive(:update).with(/#{new_keyname}/)
153
+ allow_any_instance_of(Chef::Key).to receive(:update).and_return(Chef::Key.from_hash(expected_hash))
154
+ key_edit_object.run
155
+ end
156
+ end
157
+
158
+ context "when public_key, key_name, and expiration_date are passed" do
159
+ let(:expected_hash) {
160
+ {
161
+ actor_field_name => "charmander",
162
+ "public_key" => public_key,
163
+ "name" => new_keyname,
164
+ "expiration_date" => "infinity"
165
+ }
166
+ }
167
+ before do
168
+ key_edit_object.config[:public_key] = "this-public-key"
169
+ key_edit_object.config[:key_name] = new_keyname
170
+ key_edit_object.config[:expiration_date] = "infinity"
171
+ allow(key_edit_object).to receive(:update_key_from_hash).and_return(Chef::Key.from_hash(expected_hash))
172
+ end
173
+
174
+ it "passes the right hash to update_key_from_hash" do
175
+ expect(key_edit_object).to receive(:update_key_from_hash).with(expected_hash)
176
+ key_edit_object.run
177
+ end
178
+ end
179
+
180
+ context "when create_key is passed" do
181
+ let(:expected_hash) {
182
+ {
183
+ actor_field_name => "charmander",
184
+ "create_key" => true
185
+ }
186
+ }
187
+
188
+ before do
189
+ key_edit_object.config[:create_key] = true
190
+ allow(key_edit_object).to receive(:update_key_from_hash).and_return(Chef::Key.from_hash(expected_hash))
191
+ end
192
+
193
+ it "passes the right hash to update_key_from_hash" do
194
+ expect(key_edit_object).to receive(:update_key_from_hash).with(expected_hash)
195
+ key_edit_object.run
196
+ end
197
+ end
198
+
199
+ context "when public_key is passed" do
200
+ let(:expected_hash) {
201
+ {
202
+ actor_field_name => "charmander",
203
+ "public_key" => public_key
204
+ }
205
+ }
206
+ before do
207
+ allow(key_edit_object).to receive(:update_key_from_hash).and_return(Chef::Key.from_hash(expected_hash))
208
+ key_edit_object.config[:public_key] = "public_key_path"
209
+ end
210
+
211
+ it "calls File.expand_path with the public_key input" do
212
+ expect(File).to receive(:expand_path).with("public_key_path")
213
+ key_edit_object.run
214
+ end
215
+ end # when public_key is passed
216
+
217
+ context "when the server returns a private key" do
218
+ let(:expected_hash) {
219
+ {
220
+ actor_field_name => "charmander",
221
+ "public_key" => public_key,
222
+ "private_key" => "super_private"
223
+ }
224
+ }
225
+
226
+ before do
227
+ allow(key_edit_object).to receive(:update_key_from_hash).and_return(Chef::Key.from_hash(expected_hash))
228
+ key_edit_object.config[:public_key] = "public_key_path"
229
+ end
230
+
231
+ context "when file is not passed" do
232
+ it "calls display_private_key with the private_key" do
233
+ expect(key_edit_object).to receive(:display_private_key).with("super_private")
234
+ key_edit_object.run
235
+ end
236
+ end
237
+
238
+ context "when file is passed" do
239
+ before do
240
+ key_edit_object.config[:file] = "/fake/file"
241
+ end
242
+
243
+ it "calls output_private_key_to_file with the private_key" do
244
+ expect(key_edit_object).to receive(:output_private_key_to_file).with("super_private")
245
+ key_edit_object.run
246
+ end
247
+ end
248
+ end # when the server returns a private key
249
+
250
+ end # when the command is run
251
+
252
+
253
+
254
+ end # key edit run command
255
+
256
+ context "when actor_field_name is 'user'" do
257
+ it_should_behave_like "key edit run command" do
258
+ let(:actor_field_name) { "user" }
259
+ end
260
+ end
261
+
262
+ context "when actor_field_name is 'client'" do
263
+ it_should_behave_like "key edit run command" do
264
+ let(:actor_field_name) { "client" }
265
+ end
266
+ end
267
+ end