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.
- checksums.yaml +4 -4
- data/Rakefile +86 -7
- data/distro/common/markdown/man1/chef-shell.mkd +4 -4
- data/distro/common/markdown/man1/knife-bootstrap.mkd +1 -1
- data/distro/common/markdown/man1/knife-client.mkd +1 -1
- data/distro/common/markdown/man1/knife-configure.mkd +1 -1
- data/distro/common/markdown/man1/knife-cookbook-site.mkd +1 -1
- data/distro/common/markdown/man1/knife-cookbook.mkd +4 -4
- data/distro/common/markdown/man1/knife-data-bag.mkd +1 -1
- data/distro/common/markdown/man1/knife-environment.mkd +3 -3
- data/distro/common/markdown/man1/knife-exec.mkd +1 -1
- data/distro/common/markdown/man1/knife-index.mkd +1 -1
- data/distro/common/markdown/man1/knife-node.mkd +1 -1
- data/distro/common/markdown/man1/knife-role.mkd +3 -3
- data/distro/common/markdown/man1/knife-search.mkd +2 -2
- data/distro/common/markdown/man1/knife-ssh.mkd +1 -1
- data/distro/common/markdown/man1/knife-status.mkd +1 -1
- data/distro/common/markdown/man1/knife-tag.mkd +1 -1
- data/distro/common/markdown/man1/knife.mkd +2 -2
- data/distro/common/markdown/man8/chef-client.mkd +1 -2
- data/distro/common/markdown/man8/chef-expander.mkd +1 -2
- data/distro/common/markdown/man8/chef-expanderctl.mkd +1 -2
- data/distro/common/markdown/man8/chef-server-webui.mkd +1 -1
- data/distro/common/markdown/man8/chef-server.mkd +1 -2
- data/distro/common/markdown/man8/chef-solo.mkd +2 -2
- data/distro/common/markdown/man8/chef-solr.mkd +1 -1
- data/lib/chef/client.rb +2 -2
- data/lib/chef/config.rb +17 -709
- data/lib/chef/cookbook/metadata.rb +9 -5
- data/lib/chef/cookbook_loader.rb +1 -1
- data/lib/chef/cookbook_site_streaming_uploader.rb +2 -18
- data/lib/chef/dsl/definitions.rb +44 -0
- data/lib/chef/dsl/recipe.rb +50 -35
- data/lib/chef/dsl/resources.rb +28 -0
- data/lib/chef/event_dispatch/dispatcher.rb +2 -0
- data/lib/chef/event_loggers/windows_eventlog.rb +1 -11
- data/lib/chef/exceptions.rb +4 -0
- data/lib/chef/file_access_control/unix.rb +5 -0
- data/lib/chef/formatters/error_inspectors/api_error_formatting.rb +17 -0
- data/lib/chef/formatters/error_inspectors/compile_error_inspector.rb +21 -9
- data/lib/chef/formatters/error_inspectors/cookbook_resolve_error_inspector.rb +2 -0
- data/lib/chef/formatters/error_inspectors/cookbook_sync_error_inspector.rb +2 -0
- data/lib/chef/formatters/error_inspectors/node_load_error_inspector.rb +2 -0
- data/lib/chef/formatters/error_inspectors/registration_error_inspector.rb +4 -0
- data/lib/chef/formatters/error_inspectors/resource_failure_inspector.rb +11 -1
- data/lib/chef/formatters/error_inspectors/run_list_expansion_error_inspector.rb +2 -0
- data/lib/chef/http/authenticator.rb +3 -0
- data/lib/chef/http/basic_client.rb +10 -6
- data/lib/chef/http/json_input.rb +6 -1
- data/lib/chef/key.rb +271 -0
- data/lib/chef/knife.rb +11 -1
- data/lib/chef/knife/bootstrap.rb +6 -0
- data/lib/chef/knife/bootstrap/templates/chef-full.erb +166 -23
- data/lib/chef/knife/client_key_create.rb +67 -0
- data/lib/chef/knife/client_key_delete.rb +76 -0
- data/lib/chef/knife/client_key_edit.rb +80 -0
- data/lib/chef/knife/client_key_list.rb +69 -0
- data/lib/chef/knife/client_key_show.rb +76 -0
- data/lib/chef/knife/key_create.rb +108 -0
- data/lib/chef/knife/key_create_base.rb +50 -0
- data/lib/chef/knife/key_delete.rb +55 -0
- data/lib/chef/knife/key_edit.rb +114 -0
- data/lib/chef/knife/key_edit_base.rb +55 -0
- data/lib/chef/knife/key_list.rb +88 -0
- data/lib/chef/knife/key_list_base.rb +45 -0
- data/lib/chef/knife/key_show.rb +53 -0
- data/lib/chef/knife/ssh.rb +26 -28
- data/lib/chef/knife/user_key_create.rb +69 -0
- data/lib/chef/knife/user_key_delete.rb +76 -0
- data/lib/chef/knife/user_key_edit.rb +80 -0
- data/lib/chef/knife/user_key_list.rb +69 -0
- data/lib/chef/knife/user_key_show.rb +76 -0
- data/lib/chef/log.rb +2 -0
- data/lib/chef/log/syslog.rb +46 -0
- data/lib/chef/log/winevt.rb +99 -0
- data/lib/chef/mixin/provides.rb +8 -1
- data/lib/chef/mixin/unformatter.rb +32 -0
- data/lib/chef/mixin/uris.rb +33 -0
- data/lib/chef/mixin/wstring.rb +31 -0
- data/lib/chef/node.rb +21 -2
- data/lib/chef/platform/provider_mapping.rb +8 -4
- data/lib/chef/platform/query_helpers.rb +1 -5
- data/lib/chef/platform/service_helpers.rb +21 -21
- data/lib/chef/provider.rb +33 -0
- data/lib/chef/provider/cron/unix.rb +1 -0
- data/lib/chef/provider/file.rb +5 -3
- data/lib/chef/provider/lwrp_base.rb +76 -58
- data/lib/chef/provider/ohai.rb +1 -0
- data/lib/chef/provider/package.rb +7 -4
- data/lib/chef/provider/package/aix.rb +1 -0
- data/lib/chef/provider/package/smartos.rb +5 -5
- data/lib/chef/provider/package/windows.rb +90 -6
- data/lib/chef/provider/package/yum.rb +102 -32
- data/lib/chef/provider/reboot.rb +1 -0
- data/lib/chef/provider/registry_key.rb +2 -0
- data/lib/chef/provider/remote_file.rb +1 -0
- data/lib/chef/provider/remote_file/content.rb +5 -1
- data/lib/chef/provider/remote_file/fetcher.rb +22 -8
- data/lib/chef/provider/remote_file/network_file.rb +48 -0
- data/lib/chef/provider/service/aix.rb +13 -12
- data/lib/chef/provider_resolver.rb +87 -0
- data/lib/chef/providers.rb +1 -0
- data/lib/chef/resource.rb +67 -8
- data/lib/chef/resource/bash.rb +1 -0
- data/lib/chef/resource/bff_package.rb +1 -2
- data/lib/chef/resource/breakpoint.rb +1 -0
- data/lib/chef/resource/csh.rb +1 -0
- data/lib/chef/resource/deploy.rb +1 -0
- data/lib/chef/resource/erl_call.rb +1 -0
- data/lib/chef/resource/execute.rb +1 -0
- data/lib/chef/resource/file.rb +18 -0
- data/lib/chef/resource/http_request.rb +1 -0
- data/lib/chef/resource/ifconfig.rb +1 -2
- data/lib/chef/resource/log.rb +1 -2
- data/lib/chef/resource/lwrp_base.rb +106 -87
- data/lib/chef/resource/ohai.rb +1 -0
- data/lib/chef/resource/package.rb +1 -0
- data/lib/chef/resource/perl.rb +1 -0
- data/lib/chef/resource/portage_package.rb +1 -0
- data/lib/chef/resource/python.rb +1 -0
- data/lib/chef/resource/reboot.rb +2 -0
- data/lib/chef/resource/registry_key.rb +1 -0
- data/lib/chef/resource/remote_file.rb +1 -1
- data/lib/chef/resource/route.rb +1 -2
- data/lib/chef/resource/ruby.rb +1 -0
- data/lib/chef/resource/ruby_block.rb +1 -0
- data/lib/chef/resource/scm.rb +1 -0
- data/lib/chef/resource/script.rb +1 -0
- data/lib/chef/resource/service.rb +1 -0
- data/lib/chef/resource/subversion.rb +1 -0
- data/lib/chef/resource/whyrun_safe_ruby_block.rb +1 -0
- data/lib/chef/resource/windows_package.rb +24 -2
- data/lib/chef/resource/windows_script.rb +1 -0
- data/lib/chef/resource/yum_package.rb +1 -1
- data/lib/chef/resource_definition.rb +1 -0
- data/lib/chef/resource_reporter.rb +3 -10
- data/lib/chef/resource_resolver.rb +20 -10
- data/lib/chef/run_context.rb +1 -0
- data/lib/chef/run_list/versioned_recipe_list.rb +18 -0
- data/lib/chef/run_status.rb +2 -4
- data/lib/chef/shell.rb +1 -1
- data/lib/chef/util/path_helper.rb +3 -204
- data/lib/chef/util/windows/net_user.rb +73 -118
- data/lib/chef/version.rb +8 -4
- data/lib/chef/win32/api.rb +2 -1
- data/lib/chef/win32/api/installer.rb +1 -1
- data/lib/chef/win32/api/net.rb +115 -2
- data/lib/chef/win32/api/security.rb +24 -0
- data/lib/chef/win32/api/unicode.rb +1 -1
- data/lib/chef/win32/eventlog.rb +31 -0
- data/lib/chef/win32/net.rb +190 -0
- data/lib/chef/win32/security.rb +51 -2
- data/lib/chef/win32/security/sid.rb +17 -0
- data/spec/data/lwrp/providers/buck_passer.rb +18 -2
- data/spec/data/lwrp/providers/buck_passer_2.rb +18 -2
- data/spec/data/lwrp/providers/embedded_resource_accesses_providers_scope.rb +14 -2
- data/spec/data/lwrp_override/resources/foo.rb +5 -0
- data/spec/functional/knife/ssh_spec.rb +2 -2
- data/spec/functional/rebooter_spec.rb +1 -1
- data/spec/functional/resource/aixinit_service_spec.rb +1 -1
- data/spec/functional/resource/user/windows_spec.rb +125 -0
- data/spec/functional/shell_spec.rb +25 -10
- data/spec/functional/win32/sid_spec.rb +55 -0
- data/spec/integration/client/client_spec.rb +53 -29
- data/spec/integration/knife/deps_spec.rb +8 -14
- data/spec/integration/knife/upload_spec.rb +18 -0
- data/spec/integration/recipes/lwrp_inline_resources_spec.rb +1 -1
- data/spec/integration/recipes/provider_choice.rb +41 -0
- data/spec/integration/recipes/recipe_dsl_spec.rb +259 -0
- data/spec/spec_helper.rb +6 -1
- data/spec/support/key_helpers.rb +104 -0
- data/spec/support/lib/chef/resource/cat.rb +1 -0
- data/spec/support/lib/chef/resource/one_two_three_four.rb +2 -0
- data/spec/support/lib/chef/resource/zen_follower.rb +1 -0
- data/spec/support/lib/chef/resource/zen_master.rb +2 -0
- data/spec/support/mock/platform.rb +1 -1
- data/spec/support/pedant/Gemfile.lock +67 -0
- data/spec/support/shared/functional/securable_resource.rb +34 -12
- data/spec/support/shared/integration/integration_helper.rb +6 -5
- data/spec/support/shared/unit/provider/file.rb +31 -8
- data/spec/unit/application/client_spec.rb +2 -2
- data/spec/unit/client_spec.rb +21 -4
- data/spec/unit/cookbook/cookbook_version_loader_spec.rb +1 -1
- data/spec/unit/cookbook/metadata_spec.rb +15 -0
- data/spec/unit/cookbook/syntax_check_spec.rb +1 -1
- data/spec/unit/cookbook_loader_spec.rb +1 -1
- data/spec/unit/cookbook_site_streaming_uploader_spec.rb +0 -21
- data/spec/unit/data_bag_spec.rb +1 -1
- data/spec/unit/event_dispatch/dispatcher_spec.rb +61 -0
- data/spec/unit/formatters/error_inspectors/api_error_formatting_spec.rb +75 -0
- data/spec/unit/formatters/error_inspectors/compile_error_inspector_spec.rb +149 -112
- data/spec/unit/formatters/error_inspectors/resource_failure_inspector_spec.rb +7 -0
- data/spec/unit/guard_interpreter/resource_guard_interpreter_spec.rb +1 -1
- data/spec/unit/http/authenticator_spec.rb +69 -0
- data/spec/unit/http/basic_client_spec.rb +16 -0
- data/spec/unit/key_spec.rb +634 -0
- data/spec/unit/knife/bootstrap_spec.rb +14 -1
- data/spec/unit/knife/core/subcommand_loader_spec.rb +1 -1
- data/spec/unit/knife/core/ui_spec.rb +1 -1
- data/spec/unit/knife/data_bag_from_file_spec.rb +1 -1
- data/spec/unit/knife/environment_from_file_spec.rb +1 -1
- data/spec/unit/knife/key_create_spec.rb +224 -0
- data/spec/unit/knife/key_delete_spec.rb +135 -0
- data/spec/unit/knife/key_edit_spec.rb +267 -0
- data/spec/unit/knife/key_helper.rb +74 -0
- data/spec/unit/knife/key_list_spec.rb +216 -0
- data/spec/unit/knife/key_show_spec.rb +126 -0
- data/spec/unit/knife/ssh_spec.rb +23 -26
- data/spec/unit/knife_spec.rb +33 -1
- data/spec/unit/log/syslog_spec.rb +53 -0
- data/spec/unit/log/winevt_spec.rb +55 -0
- data/spec/unit/lwrp_spec.rb +105 -51
- data/spec/unit/mixin/path_sanity_spec.rb +2 -2
- data/spec/unit/mixin/template_spec.rb +2 -2
- data/spec/unit/mixin/unformatter_spec.rb +61 -0
- data/spec/unit/mixin/uris_spec.rb +45 -0
- data/spec/unit/platform/query_helpers_spec.rb +1 -1
- data/spec/unit/policy_builder/policyfile_spec.rb +7 -3
- data/spec/unit/provider/deploy/revision_spec.rb +1 -1
- data/spec/unit/provider/deploy_spec.rb +1 -1
- data/spec/unit/provider/directory_spec.rb +1 -1
- data/spec/unit/provider/execute_spec.rb +1 -1
- data/spec/unit/provider/package/aix_spec.rb +20 -8
- data/spec/unit/provider/package/smartos_spec.rb +50 -40
- data/spec/unit/provider/package/windows_spec.rb +104 -25
- data/spec/unit/provider/package/yum_spec.rb +111 -1
- data/spec/unit/provider/package_spec.rb +6 -0
- data/spec/unit/provider/remote_file/fetcher_spec.rb +20 -1
- data/spec/unit/provider/remote_file/network_file_spec.rb +45 -0
- data/spec/unit/provider/service/aix_service_spec.rb +26 -11
- data/spec/unit/provider/user/dscl_spec.rb +1 -1
- data/spec/unit/provider_spec.rb +20 -0
- data/spec/unit/recipe_spec.rb +1 -1
- data/spec/unit/resource/batch_spec.rb +1 -0
- data/spec/unit/resource/powershell_spec.rb +1 -0
- data/spec/unit/resource/remote_file_spec.rb +10 -0
- data/spec/unit/resource/windows_package_spec.rb +16 -2
- data/spec/unit/resource_spec.rb +40 -24
- data/spec/unit/rest_spec.rb +10 -20
- data/spec/unit/role_spec.rb +1 -1
- data/spec/unit/run_context_spec.rb +31 -0
- data/spec/unit/shell_spec.rb +4 -4
- data/tasks/external_tests.rb +29 -0
- data/tasks/rspec.rb +14 -1
- metadata +105 -28
- data/spec/unit/config_spec.rb +0 -544
- data/spec/unit/util/path_helper_spec.rb +0 -255
@@ -0,0 +1,74 @@
|
|
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
|
+
|
21
|
+
shared_examples_for "a knife key command" do
|
22
|
+
let(:stderr) { StringIO.new }
|
23
|
+
let(:params) { [] }
|
24
|
+
let(:command) do
|
25
|
+
c = described_class.new([])
|
26
|
+
c.ui.config[:disable_editing] = true
|
27
|
+
allow(c.ui).to receive(:stderr).and_return(stderr)
|
28
|
+
allow(c.ui).to receive(:stdout).and_return(stderr)
|
29
|
+
allow(c).to receive(:show_usage)
|
30
|
+
c
|
31
|
+
end
|
32
|
+
|
33
|
+
context "before apply_params! is called" do
|
34
|
+
context "when apply_params! is called with invalid args" do
|
35
|
+
it "shows the usage" do
|
36
|
+
expect(command).to receive(:show_usage)
|
37
|
+
expect { command.apply_params!(params) }.to exit_with_code(1)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "outputs the proper error" do
|
41
|
+
expect { command.apply_params!(params) }.to exit_with_code(1)
|
42
|
+
expect(stderr.string).to include(command.actor_missing_error)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "exits 1" do
|
46
|
+
expect { command.apply_params!(params) }.to exit_with_code(1)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end # before apply_params! is called
|
50
|
+
|
51
|
+
context "after apply_params! is called with valid args" do
|
52
|
+
let(:params) { ["charmander"] }
|
53
|
+
before do
|
54
|
+
command.apply_params!(params)
|
55
|
+
end
|
56
|
+
|
57
|
+
it "properly defines the actor" do
|
58
|
+
expect(command.actor).to eq("charmander")
|
59
|
+
end
|
60
|
+
end # after apply_params! is called with valid args
|
61
|
+
|
62
|
+
context "when the command is run" do
|
63
|
+
before do
|
64
|
+
allow(command).to receive(:service_object).and_return(service_object)
|
65
|
+
allow(command).to receive(:name_args).and_return(["charmander"])
|
66
|
+
end
|
67
|
+
|
68
|
+
context "when the command is successful" do
|
69
|
+
before do
|
70
|
+
expect(service_object).to receive(:run)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end # a knife key command
|
@@ -0,0 +1,216 @@
|
|
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_list'
|
21
|
+
require 'chef/knife/client_key_list'
|
22
|
+
require 'chef/knife/key_list'
|
23
|
+
require 'chef/key'
|
24
|
+
|
25
|
+
describe "key list commands that inherit knife" do
|
26
|
+
shared_examples_for "a key list command" do
|
27
|
+
let(:stderr) { StringIO.new }
|
28
|
+
let(:params) { [] }
|
29
|
+
let(:service_object) { instance_double(Chef::Knife::KeyList) }
|
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::KeyList with the correct args" do
|
47
|
+
expect(Chef::Knife::KeyList).to receive(:new).
|
48
|
+
with("charmander", command.list_method, 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 list command
|
55
|
+
|
56
|
+
describe Chef::Knife::UserKeyList do
|
57
|
+
it_should_behave_like "a key list command"
|
58
|
+
# defined in key_helpers.rb
|
59
|
+
it_should_behave_like "a knife key command" do
|
60
|
+
let(:service_object) { instance_double(Chef::Knife::KeyList) }
|
61
|
+
let(:params) { ["charmander"] }
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe Chef::Knife::ClientKeyList do
|
66
|
+
it_should_behave_like "a key list command"
|
67
|
+
# defined in key_helpers.rb
|
68
|
+
it_should_behave_like "a knife key command" do
|
69
|
+
let(:service_object) { instance_double(Chef::Knife::KeyList) }
|
70
|
+
let(:params) { ["charmander"] }
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
describe Chef::Knife::KeyList do
|
76
|
+
let(:config) { Hash.new }
|
77
|
+
let(:actor) { "charmander" }
|
78
|
+
let(:ui) { instance_double("Chef::Knife::UI") }
|
79
|
+
|
80
|
+
shared_examples_for "key list run command" do
|
81
|
+
let(:key_list_object) {
|
82
|
+
described_class.new(actor, list_method, ui, config)
|
83
|
+
}
|
84
|
+
|
85
|
+
before do
|
86
|
+
allow(Chef::Key).to receive(list_method).and_return(http_response)
|
87
|
+
allow(key_list_object).to receive(:display_info)
|
88
|
+
# simply pass the string though that colorize takes in
|
89
|
+
allow(key_list_object).to receive(:colorize).with(kind_of(String)) do |input|
|
90
|
+
input
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
context "when only_expired and only_non_expired were both passed" do
|
95
|
+
before do
|
96
|
+
key_list_object.config[:only_expired] = true
|
97
|
+
key_list_object.config[:only_non_expired] = true
|
98
|
+
end
|
99
|
+
|
100
|
+
it "raises a Chef::Exceptions::KeyCommandInputError with the proper error message" do
|
101
|
+
expect{ key_list_object.run }.to raise_error(Chef::Exceptions::KeyCommandInputError, key_list_object.expired_and_non_expired_msg)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
context "when the command is run" do
|
106
|
+
before do
|
107
|
+
key_list_object.config[:only_expired] = false
|
108
|
+
key_list_object.config[:only_non_expired] = false
|
109
|
+
key_list_object.config[:with_details] = false
|
110
|
+
end
|
111
|
+
|
112
|
+
it "calls Chef::Key with the proper list command and input" do
|
113
|
+
expect(Chef::Key).to receive(list_method).with(actor)
|
114
|
+
key_list_object.run
|
115
|
+
end
|
116
|
+
|
117
|
+
it "displays all the keys" do
|
118
|
+
expect(key_list_object).to receive(:display_info).with(/non-expired/).twice
|
119
|
+
expect(key_list_object).to receive(:display_info).with(/out-of-date/).once
|
120
|
+
key_list_object.run
|
121
|
+
end
|
122
|
+
|
123
|
+
context "when only_expired is called" do
|
124
|
+
before do
|
125
|
+
key_list_object.config[:only_expired] = true
|
126
|
+
end
|
127
|
+
|
128
|
+
it "excludes displaying non-expired keys" do
|
129
|
+
expect(key_list_object).to receive(:display_info).with(/non-expired/).exactly(0).times
|
130
|
+
key_list_object.run
|
131
|
+
end
|
132
|
+
|
133
|
+
it "displays the expired keys" do
|
134
|
+
expect(key_list_object).to receive(:display_info).with(/out-of-date/).once
|
135
|
+
key_list_object.run
|
136
|
+
end
|
137
|
+
end # when only_expired is called
|
138
|
+
|
139
|
+
context "when only_non_expired is called" do
|
140
|
+
before do
|
141
|
+
key_list_object.config[:only_non_expired] = true
|
142
|
+
end
|
143
|
+
|
144
|
+
it "excludes displaying expired keys" do
|
145
|
+
expect(key_list_object).to receive(:display_info).with(/out-of-date/).exactly(0).times
|
146
|
+
key_list_object.run
|
147
|
+
end
|
148
|
+
|
149
|
+
it "displays the non-expired keys" do
|
150
|
+
expect(key_list_object).to receive(:display_info).with(/non-expired/).twice
|
151
|
+
key_list_object.run
|
152
|
+
end
|
153
|
+
end # when only_expired is called
|
154
|
+
|
155
|
+
context "when with_details is false" do
|
156
|
+
before do
|
157
|
+
key_list_object.config[:with_details] = false
|
158
|
+
end
|
159
|
+
|
160
|
+
it "does not display the uri" do
|
161
|
+
expect(key_list_object).to receive(:display_info).with(/https/).exactly(0).times
|
162
|
+
key_list_object.run
|
163
|
+
end
|
164
|
+
|
165
|
+
it "does not display the expired status" do
|
166
|
+
expect(key_list_object).to receive(:display_info).with(/\(expired\)/).exactly(0).times
|
167
|
+
key_list_object.run
|
168
|
+
end
|
169
|
+
end # when with_details is false
|
170
|
+
|
171
|
+
context "when with_details is true" do
|
172
|
+
before do
|
173
|
+
key_list_object.config[:with_details] = true
|
174
|
+
end
|
175
|
+
|
176
|
+
it "displays the uri" do
|
177
|
+
expect(key_list_object).to receive(:display_info).with(/https/).exactly(3).times
|
178
|
+
key_list_object.run
|
179
|
+
end
|
180
|
+
|
181
|
+
it "displays the expired status" do
|
182
|
+
expect(key_list_object).to receive(:display_info).with(/\(expired\)/).once
|
183
|
+
key_list_object.run
|
184
|
+
end
|
185
|
+
end # when with_details is true
|
186
|
+
|
187
|
+
end # when the command is run
|
188
|
+
|
189
|
+
end # key list run command
|
190
|
+
|
191
|
+
context "when list_method is :list_by_user" do
|
192
|
+
it_should_behave_like "key list run command" do
|
193
|
+
let(:list_method) { :list_by_user }
|
194
|
+
let(:http_response) {
|
195
|
+
[
|
196
|
+
{"uri"=>"https://api.opscode.piab/users/charmander/keys/non-expired1", "name"=>"non-expired1", "expired"=>false},
|
197
|
+
{"uri"=>"https://api.opscode.piab/users/charmander/keys/non-expired2", "name"=>"non-expired2", "expired"=>false},
|
198
|
+
{"uri"=>"https://api.opscode.piab/users/mary/keys/out-of-date", "name"=>"out-of-date", "expired"=>true}
|
199
|
+
]
|
200
|
+
}
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
context "when list_method is :list_by_client" do
|
205
|
+
it_should_behave_like "key list run command" do
|
206
|
+
let(:list_method) { :list_by_client }
|
207
|
+
let(:http_response) {
|
208
|
+
[
|
209
|
+
{"uri"=>"https://api.opscode.piab/organizations/pokemon/clients/charmander/keys/non-expired1", "name"=>"non-expired1", "expired"=>false},
|
210
|
+
{"uri"=>"https://api.opscode.piab/organizations/pokemon/clients/charmander/keys/non-expired2", "name"=>"non-expired2", "expired"=>false},
|
211
|
+
{"uri"=>"https://api.opscode.piab/organizations/pokemon/clients/mary/keys/out-of-date", "name"=>"out-of-date", "expired"=>true}
|
212
|
+
]
|
213
|
+
}
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
@@ -0,0 +1,126 @@
|
|
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_show'
|
21
|
+
require 'chef/knife/client_key_show'
|
22
|
+
require 'chef/knife/key_show'
|
23
|
+
require 'chef/key'
|
24
|
+
|
25
|
+
describe "key show commands that inherit knife" do
|
26
|
+
shared_examples_for "a key show command" do
|
27
|
+
let(:stderr) { StringIO.new }
|
28
|
+
let(:params) { [] }
|
29
|
+
let(:service_object) { instance_double(Chef::Knife::KeyShow) }
|
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::KeyShow with the correct args" do
|
47
|
+
expect(Chef::Knife::KeyShow).to receive(:new).
|
48
|
+
with("charmander-key", "charmander", command.load_method, 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 show command
|
55
|
+
|
56
|
+
describe Chef::Knife::UserKeyShow do
|
57
|
+
it_should_behave_like "a key show 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::KeyShow) }
|
62
|
+
let(:params) { ["charmander", "charmander-key"] }
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe Chef::Knife::ClientKeyShow do
|
67
|
+
it_should_behave_like "a key show 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::KeyShow) }
|
72
|
+
let(:params) { ["charmander", "charmander-key"] }
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe Chef::Knife::KeyShow do
|
78
|
+
let(:actor) { "charmander" }
|
79
|
+
let(:keyname) { "charmander" }
|
80
|
+
let(:ui) { instance_double("Chef::Knife::UI") }
|
81
|
+
let(:expected_hash) {
|
82
|
+
{
|
83
|
+
actor_field_name => "charmander",
|
84
|
+
"name" => "charmander-key",
|
85
|
+
"public_key" => "some-public-key",
|
86
|
+
"expiration_date" => "infinity"
|
87
|
+
}
|
88
|
+
}
|
89
|
+
|
90
|
+
shared_examples_for "key show run command" do
|
91
|
+
let(:key_show_object) {
|
92
|
+
described_class.new(keyname, actor, load_method, ui)
|
93
|
+
}
|
94
|
+
|
95
|
+
before do
|
96
|
+
allow(key_show_object).to receive(:display_output)
|
97
|
+
allow(Chef::Key).to receive(load_method).and_return(Chef::Key.from_hash(expected_hash))
|
98
|
+
end
|
99
|
+
|
100
|
+
context "when the command is run" do
|
101
|
+
it "loads the key using the proper method and args" do
|
102
|
+
expect(Chef::Key).to receive(load_method).with(actor, keyname)
|
103
|
+
key_show_object.run
|
104
|
+
end
|
105
|
+
|
106
|
+
it "displays the key" do
|
107
|
+
expect(key_show_object).to receive(:display_output)
|
108
|
+
key_show_object.run
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
context "when load_method is :load_by_user" do
|
114
|
+
it_should_behave_like "key show run command" do
|
115
|
+
let(:load_method) { :load_by_user }
|
116
|
+
let(:actor_field_name) { 'user' }
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
context "when load_method is :load_by_client" do
|
121
|
+
it_should_behave_like "key show run command" do
|
122
|
+
let(:load_method) { :load_by_client }
|
123
|
+
let(:actor_field_name) { 'user' }
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
data/spec/unit/knife/ssh_spec.rb
CHANGED
@@ -28,10 +28,10 @@ describe Chef::Knife::Ssh do
|
|
28
28
|
before do
|
29
29
|
@knife = Chef::Knife::Ssh.new
|
30
30
|
@knife.merge_configs
|
31
|
-
@knife.config[:attribute] = "fqdn"
|
32
31
|
@node_foo = Chef::Node.new
|
33
32
|
@node_foo.automatic_attrs[:fqdn] = "foo.example.org"
|
34
33
|
@node_foo.automatic_attrs[:ipaddress] = "10.0.0.1"
|
34
|
+
|
35
35
|
@node_bar = Chef::Node.new
|
36
36
|
@node_bar.automatic_attrs[:fqdn] = "bar.example.org"
|
37
37
|
@node_bar.automatic_attrs[:ipaddress] = "10.0.0.2"
|
@@ -52,15 +52,15 @@ describe Chef::Knife::Ssh do
|
|
52
52
|
def self.should_return_specified_attributes
|
53
53
|
it "returns an array of the attributes specified on the command line OR config file, if only one is set" do
|
54
54
|
@knife.config[:attribute] = "ipaddress"
|
55
|
-
|
55
|
+
Chef::Config[:knife][:ssh_attribute] = "ipaddress" # this value will be in the config file
|
56
56
|
configure_query([@node_foo, @node_bar])
|
57
57
|
expect(@knife).to receive(:session_from_list).with([['10.0.0.1', nil], ['10.0.0.2', nil]])
|
58
58
|
@knife.configure_session
|
59
59
|
end
|
60
60
|
|
61
61
|
it "returns an array of the attributes specified on the command line even when a config value is set" do
|
62
|
-
|
63
|
-
@knife.config[:
|
62
|
+
Chef::Config[:knife][:ssh_attribute] = "config_file" # this value will be in the config file
|
63
|
+
@knife.config[:attribute] = "ipaddress" # this is the value of the command line via #configure_attribute
|
64
64
|
configure_query([@node_foo, @node_bar])
|
65
65
|
expect(@knife).to receive(:session_from_list).with([['10.0.0.1', nil], ['10.0.0.2', nil]])
|
66
66
|
@knife.configure_session
|
@@ -83,7 +83,6 @@ describe Chef::Knife::Ssh do
|
|
83
83
|
@node_foo.automatic_attrs[:cloud][:public_hostname] = "ec2-10-0-0-1.compute-1.amazonaws.com"
|
84
84
|
@node_bar.automatic_attrs[:cloud][:public_hostname] = "ec2-10-0-0-2.compute-1.amazonaws.com"
|
85
85
|
end
|
86
|
-
|
87
86
|
it "returns an array of cloud public hostnames" do
|
88
87
|
configure_query([@node_foo, @node_bar])
|
89
88
|
expect(@knife).to receive(:session_from_list).with([
|
@@ -150,42 +149,40 @@ describe Chef::Knife::Ssh do
|
|
150
149
|
end
|
151
150
|
end
|
152
151
|
|
153
|
-
describe "#
|
152
|
+
describe "#get_ssh_attribute" do
|
153
|
+
# Order of precedence for ssh target
|
154
|
+
# 1) command line attribute
|
155
|
+
# 2) configuration file
|
156
|
+
# 3) cloud attribute
|
157
|
+
# 4) fqdn
|
154
158
|
before do
|
155
159
|
Chef::Config[:knife][:ssh_attribute] = nil
|
156
160
|
@knife.config[:attribute] = nil
|
161
|
+
@node_foo.automatic_attrs[:cloud][:public_hostname] = "ec2-10-0-0-1.compute-1.amazonaws.com"
|
162
|
+
@node_bar.automatic_attrs[:cloud][:public_hostname] = ''
|
157
163
|
end
|
158
164
|
|
159
165
|
it "should return fqdn by default" do
|
160
|
-
@knife.
|
161
|
-
expect(@knife.config[:attribute]).to eq("fqdn")
|
166
|
+
expect(@knife.get_ssh_attribute(Chef::Node.new)).to eq("fqdn")
|
162
167
|
end
|
163
168
|
|
164
|
-
it "should return
|
165
|
-
|
166
|
-
@knife.configure_attribute
|
167
|
-
expect(@knife.config[:attribute]).to eq("config_file")
|
169
|
+
it "should return cloud.public_hostname attribute if available" do
|
170
|
+
expect(@knife.get_ssh_attribute(@node_foo)).to eq("cloud.public_hostname")
|
168
171
|
end
|
169
172
|
|
170
|
-
it "should
|
173
|
+
it "should favor to attribute_from_cli over config file and cloud" do
|
171
174
|
@knife.config[:attribute] = "command_line"
|
172
|
-
|
173
|
-
expect(@knife.
|
175
|
+
Chef::Config[:knife][:ssh_attribute] = "config_file"
|
176
|
+
expect( @knife.get_ssh_attribute(@node_foo)).to eq("command_line")
|
174
177
|
end
|
175
178
|
|
176
|
-
it "should
|
177
|
-
|
178
|
-
@knife.
|
179
|
-
expect(@knife.config[:attribute]).to eq("command_line")
|
180
|
-
expect(@knife.config[:attribute_from_cli]).to eq("command_line")
|
179
|
+
it "should favor config file over cloud and default" do
|
180
|
+
Chef::Config[:knife][:ssh_attribute] = "config_file"
|
181
|
+
expect( @knife.get_ssh_attribute(@node_foo)).to eq("config_file")
|
181
182
|
end
|
182
183
|
|
183
|
-
it "should
|
184
|
-
|
185
|
-
@knife.config[:attribute] = "command_line"
|
186
|
-
@knife.configure_attribute
|
187
|
-
expect(@knife.config[:attribute]).to eq("command_line")
|
188
|
-
expect(@knife.config[:attribute_from_cli]).to eq("command_line")
|
184
|
+
it "should return fqdn if cloud.hostname is empty" do
|
185
|
+
expect( @knife.get_ssh_attribute(@node_bar)).to eq("fqdn")
|
189
186
|
end
|
190
187
|
end
|
191
188
|
|