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.
- checksums.yaml +4 -4
- data/Rakefile +12 -1
- data/lib/chef/api_client.rb +130 -26
- data/lib/chef/application.rb +0 -1
- data/lib/chef/application/client.rb +8 -19
- data/lib/chef/audit/audit_reporter.rb +12 -7
- data/lib/chef/audit/logger.rb +36 -0
- data/lib/chef/audit/runner.rb +4 -2
- data/lib/chef/chef_class.rb +62 -11
- data/lib/chef/client.rb +587 -207
- data/lib/chef/config.rb +0 -1
- data/lib/chef/dsl/recipe.rb +45 -56
- data/lib/chef/dsl/resources.rb +3 -2
- data/lib/chef/event_dispatch/base.rb +7 -2
- data/lib/chef/exceptions.rb +4 -1
- data/lib/chef/file_content_management/deploy/mv_windows.rb +16 -6
- data/lib/chef/formatters/doc.rb +15 -7
- data/lib/chef/formatters/error_inspectors/api_error_formatting.rb +10 -7
- data/lib/chef/guard_interpreter/default_guard_interpreter.rb +2 -0
- data/lib/chef/guard_interpreter/resource_guard_interpreter.rb +4 -1
- data/lib/chef/http/authenticator.rb +7 -2
- data/lib/chef/knife.rb +16 -4
- data/lib/chef/knife/client_create.rb +55 -31
- data/lib/chef/knife/core/generic_presenter.rb +1 -1
- data/lib/chef/knife/core/subcommand_loader.rb +1 -1
- data/lib/chef/knife/osc_user_create.rb +97 -0
- data/lib/chef/knife/osc_user_delete.rb +51 -0
- data/lib/chef/knife/osc_user_edit.rb +58 -0
- data/lib/chef/knife/osc_user_list.rb +47 -0
- data/lib/chef/knife/osc_user_reregister.rb +64 -0
- data/lib/chef/knife/osc_user_show.rb +54 -0
- data/lib/chef/knife/user_create.rb +95 -36
- data/lib/chef/knife/user_delete.rb +52 -2
- data/lib/chef/knife/user_edit.rb +37 -7
- data/lib/chef/knife/user_list.rb +3 -0
- data/lib/chef/knife/user_reregister.rb +39 -8
- data/lib/chef/knife/user_show.rb +30 -1
- data/lib/chef/mixin/api_version_request_handling.rb +66 -0
- data/lib/chef/mixin/convert_to_class_name.rb +10 -4
- data/lib/chef/mixin/deprecation.rb +24 -0
- data/lib/chef/mixin/powershell_out.rb +98 -0
- data/lib/chef/mixin/provides.rb +5 -18
- data/lib/chef/mixin/uris.rb +11 -0
- data/lib/chef/mixin/windows_architecture_helper.rb +5 -2
- data/lib/chef/mixin/windows_env_helper.rb +11 -2
- data/lib/chef/node_map.rb +130 -75
- data/lib/chef/osc_user.rb +194 -0
- data/lib/chef/platform/provider_mapping.rb +2 -269
- data/lib/chef/platform/provider_priority_map.rb +6 -69
- data/lib/chef/platform/query_helpers.rb +5 -0
- data/lib/chef/platform/resource_priority_map.rb +12 -15
- data/lib/chef/policy_builder/policyfile.rb +1 -0
- data/lib/chef/provider.rb +19 -0
- data/lib/chef/provider/directory.rb +3 -0
- data/lib/chef/provider/dsc_resource.rb +8 -1
- data/lib/chef/provider/file.rb +1 -0
- data/lib/chef/provider/group/aix.rb +1 -0
- data/lib/chef/provider/group/dscl.rb +1 -1
- data/lib/chef/provider/group/gpasswd.rb +1 -0
- data/lib/chef/provider/group/groupmod.rb +1 -1
- data/lib/chef/provider/group/pw.rb +1 -0
- data/lib/chef/provider/group/suse.rb +2 -0
- data/lib/chef/provider/group/usermod.rb +2 -1
- data/lib/chef/provider/group/windows.rb +1 -1
- data/lib/chef/provider/ifconfig.rb +2 -0
- data/lib/chef/provider/ifconfig/aix.rb +1 -0
- data/lib/chef/provider/ifconfig/debian.rb +2 -0
- data/lib/chef/provider/ifconfig/redhat.rb +1 -0
- data/lib/chef/provider/lwrp_base.rb +4 -0
- data/lib/chef/provider/mount.rb +0 -1
- data/lib/chef/provider/mount/aix.rb +1 -0
- data/lib/chef/provider/mount/mount.rb +2 -0
- data/lib/chef/provider/mount/solaris.rb +2 -0
- data/lib/chef/provider/package.rb +55 -0
- data/lib/chef/provider/package/aix.rb +7 -7
- data/lib/chef/provider/package/apt.rb +3 -3
- data/lib/chef/provider/package/dpkg.rb +4 -4
- data/lib/chef/provider/package/easy_install.rb +5 -5
- data/lib/chef/provider/package/freebsd/base.rb +2 -2
- data/lib/chef/provider/package/freebsd/pkg.rb +6 -6
- data/lib/chef/provider/package/freebsd/pkgng.rb +5 -5
- data/lib/chef/provider/package/freebsd/port.rb +4 -4
- data/lib/chef/provider/package/homebrew.rb +2 -2
- data/lib/chef/provider/package/ips.rb +4 -4
- data/lib/chef/provider/package/macports.rb +5 -6
- data/lib/chef/provider/package/openbsd.rb +4 -5
- data/lib/chef/provider/package/pacman.rb +4 -4
- data/lib/chef/provider/package/portage.rb +2 -0
- data/lib/chef/provider/package/rpm.rb +7 -8
- data/lib/chef/provider/package/rubygems.rb +5 -12
- data/lib/chef/provider/package/smartos.rb +4 -4
- data/lib/chef/provider/package/solaris.rb +7 -7
- data/lib/chef/provider/package/windows/msi.rb +1 -1
- data/lib/chef/provider/package/yum.rb +4 -6
- data/lib/chef/provider/package/zypper.rb +16 -14
- data/lib/chef/provider/powershell_script.rb +129 -47
- data/lib/chef/provider/remote_file/content.rb +4 -1
- data/lib/chef/provider/remote_file/local_file.rb +10 -4
- data/lib/chef/provider/service.rb +44 -0
- data/lib/chef/provider/service/freebsd.rb +1 -1
- data/lib/chef/provider/service/init.rb +1 -0
- data/lib/chef/provider/service/macosx.rb +1 -1
- data/lib/chef/provider/service/windows.rb +0 -1
- data/lib/chef/provider/user.rb +1 -1
- data/lib/chef/provider/user/aix.rb +3 -2
- data/lib/chef/provider/user/pw.rb +1 -0
- data/lib/chef/provider/user/solaris.rb +2 -0
- data/lib/chef/provider/user/useradd.rb +1 -0
- data/lib/chef/provider_resolver.rb +87 -134
- data/lib/chef/resource.rb +274 -68
- data/lib/chef/resource/apt_package.rb +0 -2
- data/lib/chef/resource/bash.rb +0 -2
- data/lib/chef/resource/batch.rb +1 -1
- data/lib/chef/resource/bff_package.rb +0 -7
- data/lib/chef/resource/breakpoint.rb +3 -6
- data/lib/chef/resource/chef_gem.rb +0 -3
- data/lib/chef/resource/cookbook_file.rb +1 -3
- data/lib/chef/resource/cron.rb +2 -4
- data/lib/chef/resource/csh.rb +0 -2
- data/lib/chef/resource/deploy.rb +9 -6
- data/lib/chef/resource/deploy_revision.rb +0 -14
- data/lib/chef/resource/directory.rb +2 -4
- data/lib/chef/resource/dpkg_package.rb +0 -5
- data/lib/chef/resource/dsc_resource.rb +2 -3
- data/lib/chef/resource/dsc_script.rb +2 -3
- data/lib/chef/resource/easy_install_package.rb +0 -7
- data/lib/chef/resource/env.rb +3 -3
- data/lib/chef/resource/erl_call.rb +2 -5
- data/lib/chef/resource/execute.rb +2 -4
- data/lib/chef/resource/file.rb +2 -4
- data/lib/chef/resource/freebsd_package.rb +0 -5
- data/lib/chef/resource/gem_package.rb +0 -3
- data/lib/chef/resource/git.rb +0 -3
- data/lib/chef/resource/group.rb +2 -4
- data/lib/chef/resource/homebrew_package.rb +0 -2
- data/lib/chef/resource/http_request.rb +3 -4
- data/lib/chef/resource/ifconfig.rb +3 -4
- data/lib/chef/resource/ips_package.rb +2 -2
- data/lib/chef/resource/link.rb +3 -5
- data/lib/chef/resource/log.rb +2 -4
- data/lib/chef/resource/lwrp_base.rb +10 -61
- data/lib/chef/resource/macosx_service.rb +1 -2
- data/lib/chef/resource/macports_package.rb +0 -7
- data/lib/chef/resource/mdadm.rb +2 -5
- data/lib/chef/resource/mount.rb +2 -4
- data/lib/chef/resource/ohai.rb +2 -4
- data/lib/chef/resource/openbsd_package.rb +0 -6
- data/lib/chef/resource/package.rb +9 -6
- data/lib/chef/resource/pacman_package.rb +0 -7
- data/lib/chef/resource/paludis_package.rb +2 -3
- data/lib/chef/resource/perl.rb +0 -3
- data/lib/chef/resource/portage_package.rb +0 -3
- data/lib/chef/resource/powershell_script.rb +1 -2
- data/lib/chef/resource/python.rb +0 -3
- data/lib/chef/resource/reboot.rb +1 -3
- data/lib/chef/resource/registry_key.rb +3 -5
- data/lib/chef/resource/remote_directory.rb +3 -5
- data/lib/chef/resource/remote_file.rb +4 -5
- data/lib/chef/resource/route.rb +3 -5
- data/lib/chef/resource/rpm_package.rb +0 -2
- data/lib/chef/resource/ruby.rb +0 -4
- data/lib/chef/resource/ruby_block.rb +2 -4
- data/lib/chef/resource/scm.rb +3 -5
- data/lib/chef/resource/script.rb +0 -3
- data/lib/chef/resource/service.rb +3 -5
- data/lib/chef/resource/smartos_package.rb +0 -9
- data/lib/chef/resource/solaris_package.rb +0 -10
- data/lib/chef/resource/subversion.rb +1 -3
- data/lib/chef/resource/template.rb +0 -4
- data/lib/chef/resource/timestamped_deploy.rb +0 -4
- data/lib/chef/resource/user.rb +2 -5
- data/lib/chef/resource/whyrun_safe_ruby_block.rb +0 -7
- data/lib/chef/resource/windows_package.rb +3 -3
- data/lib/chef/resource/windows_script.rb +2 -2
- data/lib/chef/resource/windows_service.rb +3 -3
- data/lib/chef/resource/yum_package.rb +0 -3
- data/lib/chef/resource/zypper_package.rb +27 -0
- data/lib/chef/resource_builder.rb +7 -0
- data/lib/chef/resource_reporter.rb +1 -1
- data/lib/chef/resource_resolver.rb +108 -62
- data/lib/chef/resources.rb +1 -0
- data/lib/chef/rest.rb +1 -0
- data/lib/chef/server_api.rb +2 -0
- data/lib/chef/user.rb +193 -42
- data/lib/chef/util/backup.rb +9 -1
- data/lib/chef/util/path_helper.rb +0 -1
- data/lib/chef/version.rb +1 -1
- data/spec/functional/audit/runner_spec.rb +22 -42
- data/spec/functional/mixin/powershell_out_spec.rb +43 -0
- data/spec/functional/resource/execute_spec.rb +9 -2
- data/spec/functional/resource/file_spec.rb +25 -0
- data/spec/functional/resource/group_spec.rb +5 -0
- data/spec/functional/resource/link_spec.rb +5 -11
- data/spec/functional/resource/powershell_spec.rb +40 -5
- data/spec/functional/resource/user/useradd_spec.rb +10 -18
- data/spec/integration/recipes/lwrp_spec.rb +57 -0
- data/spec/integration/recipes/provider_choice.rb +2 -7
- data/spec/integration/recipes/recipe_dsl_spec.rb +517 -19
- data/spec/spec_helper.rb +1 -1
- data/spec/support/lib/chef/provider/openldap_includer.rb +29 -0
- data/spec/support/lib/chef/resource/cat.rb +0 -2
- data/spec/support/lib/chef/resource/one_two_three_four.rb +0 -6
- data/spec/support/lib/chef/resource/openldap_includer.rb +27 -0
- data/spec/support/lib/chef/resource/with_state.rb +0 -9
- data/spec/support/lib/chef/resource/zen_follower.rb +0 -6
- data/spec/support/lib/chef/resource/zen_master.rb +1 -6
- data/spec/support/shared/context/client.rb +277 -0
- data/spec/support/shared/examples/client.rb +53 -0
- data/spec/support/shared/functional/file_resource.rb +0 -4
- data/spec/support/shared/functional/securable_resource.rb +0 -24
- data/spec/support/shared/functional/securable_resource_with_reporting.rb +4 -4
- data/spec/support/shared/functional/windows_script.rb +1 -1
- data/spec/support/shared/unit/api_versioning.rb +77 -0
- data/spec/support/shared/unit/knife_shared.rb +40 -0
- data/spec/support/shared/unit/user_and_client_shared.rb +115 -0
- data/spec/unit/api_client_spec.rb +189 -14
- data/spec/unit/application/client_spec.rb +0 -5
- data/spec/unit/audit/audit_reporter_spec.rb +58 -14
- data/spec/unit/audit/logger_spec.rb +42 -0
- data/spec/unit/audit/runner_spec.rb +2 -2
- data/spec/unit/chef_fs/file_pattern_spec.rb +3 -15
- data/spec/unit/client_spec.rb +58 -374
- data/spec/unit/cookbook_spec.rb +0 -9
- data/spec/unit/cookbook_version_spec.rb +0 -20
- data/spec/unit/deprecation_spec.rb +55 -0
- data/spec/unit/dsl/resources_spec.rb +85 -0
- data/spec/unit/exceptions_spec.rb +2 -2
- data/spec/unit/file_content_management/deploy/mv_windows_spec.rb +60 -0
- data/spec/unit/formatters/doc_spec.rb +46 -0
- data/spec/unit/formatters/error_inspectors/api_error_formatting_spec.rb +12 -10
- data/spec/unit/guard_interpreter/resource_guard_interpreter_spec.rb +8 -0
- data/spec/unit/http/authenticator_spec.rb +11 -2
- data/spec/unit/knife/client_create_spec.rb +122 -51
- data/spec/unit/knife/core/subcommand_loader_spec.rb +19 -3
- data/spec/unit/knife/core/ui_spec.rb +14 -0
- data/spec/unit/knife/osc_user_create_spec.rb +93 -0
- data/spec/unit/knife/osc_user_delete_spec.rb +44 -0
- data/spec/unit/knife/osc_user_edit_spec.rb +52 -0
- data/spec/unit/knife/osc_user_list_spec.rb +37 -0
- data/spec/unit/knife/osc_user_reregister_spec.rb +58 -0
- data/spec/unit/knife/osc_user_show_spec.rb +46 -0
- data/spec/unit/knife/user_create_spec.rb +177 -51
- data/spec/unit/knife/user_delete_spec.rb +34 -8
- data/spec/unit/knife/user_edit_spec.rb +31 -12
- data/spec/unit/knife/user_list_spec.rb +7 -3
- data/spec/unit/knife/user_reregister_spec.rb +38 -17
- data/spec/unit/knife/user_show_spec.rb +35 -11
- data/spec/unit/knife_spec.rb +10 -4
- data/spec/unit/lwrp_spec.rb +228 -54
- data/spec/unit/mixin/api_version_request_handling_spec.rb +127 -0
- data/spec/unit/mixin/command_spec.rb +1 -2
- data/spec/unit/mixin/powershell_out_spec.rb +70 -0
- data/spec/unit/mixin/uris_spec.rb +23 -11
- data/spec/unit/node_map_spec.rb +4 -1
- data/spec/unit/osc_user_spec.rb +276 -0
- data/spec/unit/platform_spec.rb +0 -60
- data/spec/unit/provider/deploy_spec.rb +1 -1
- data/spec/unit/provider/directory_spec.rb +199 -135
- data/spec/unit/provider/ifconfig/debian_spec.rb +0 -10
- data/spec/unit/provider/package/aix_spec.rb +16 -16
- data/spec/unit/provider/package/dpkg_spec.rb +2 -2
- data/spec/unit/provider/package/freebsd/pkg_spec.rb +13 -13
- data/spec/unit/provider/package/freebsd/pkgng_spec.rb +9 -9
- data/spec/unit/provider/package/freebsd/port_spec.rb +7 -7
- data/spec/unit/provider/package/ips_spec.rb +22 -22
- data/spec/unit/provider/package/macports_spec.rb +10 -10
- data/spec/unit/provider/package/openbsd_spec.rb +4 -26
- data/spec/unit/provider/package/pacman_spec.rb +5 -5
- data/spec/unit/provider/package/rpm_spec.rb +14 -14
- data/spec/unit/provider/package/rubygems_spec.rb +10 -44
- data/spec/unit/provider/package/smartos_spec.rb +4 -4
- data/spec/unit/provider/package/solaris_spec.rb +11 -11
- data/spec/unit/provider/package/zypper_spec.rb +125 -90
- data/spec/unit/provider/package_spec.rb +34 -0
- data/spec/unit/provider/powershell_spec.rb +53 -11
- data/spec/unit/provider/remote_directory_spec.rb +2 -2
- data/spec/unit/provider/remote_file/local_file_spec.rb +25 -6
- data/spec/unit/provider/service/freebsd_service_spec.rb +0 -12
- data/spec/unit/provider/user_spec.rb +3 -3
- data/spec/unit/provider_resolver_spec.rb +463 -327
- data/spec/unit/recipe_spec.rb +42 -15
- data/spec/unit/resource/breakpoint_spec.rb +1 -1
- data/spec/unit/resource/erl_call_spec.rb +1 -1
- data/spec/unit/resource/file_spec.rb +1 -1
- data/spec/unit/resource/ifconfig_spec.rb +10 -6
- data/spec/unit/resource/remote_file_spec.rb +5 -0
- data/spec/unit/resource/route_spec.rb +1 -1
- data/spec/unit/resource/ruby_block_spec.rb +2 -2
- data/spec/unit/resource/template_spec.rb +1 -1
- data/spec/unit/resource/timestamped_deploy_spec.rb +1 -2
- data/spec/unit/resource/windows_service_spec.rb +1 -1
- data/spec/unit/resource_spec.rb +99 -13
- data/spec/unit/rest_spec.rb +5 -5
- data/spec/unit/run_context_spec.rb +41 -0
- data/spec/unit/runner_spec.rb +2 -2
- data/spec/unit/user_spec.rb +406 -93
- data/tasks/maintainers.rb +69 -0
- metadata +37 -4
@@ -0,0 +1,127 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Tyler Cloke (tyler@chef.io)
|
3
|
+
# Copyright:: Copyright 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
|
+
describe Chef::Mixin::ApiVersionRequestHandling do
|
22
|
+
let(:dummy_class) { Class.new { include Chef::Mixin::ApiVersionRequestHandling } }
|
23
|
+
let(:object) { dummy_class.new }
|
24
|
+
|
25
|
+
describe ".server_client_api_version_intersection" do
|
26
|
+
let(:default_supported_client_versions) { [0,1,2] }
|
27
|
+
|
28
|
+
|
29
|
+
context "when the response code is not 406" do
|
30
|
+
let(:response) { OpenStruct.new(:code => '405') }
|
31
|
+
let(:exception) { Net::HTTPServerException.new("405 Something Else", response) }
|
32
|
+
|
33
|
+
it "returns nil" do
|
34
|
+
expect(object.server_client_api_version_intersection(exception, default_supported_client_versions)).
|
35
|
+
to be_nil
|
36
|
+
end
|
37
|
+
|
38
|
+
end # when the response code is not 406
|
39
|
+
|
40
|
+
context "when the response code is 406" do
|
41
|
+
let(:response) { OpenStruct.new(:code => '406') }
|
42
|
+
let(:exception) { Net::HTTPServerException.new("406 Not Acceptable", response) }
|
43
|
+
|
44
|
+
context "when x-ops-server-api-version header does not exist" do
|
45
|
+
it "returns nil" do
|
46
|
+
expect(object.server_client_api_version_intersection(exception, default_supported_client_versions)).
|
47
|
+
to be_nil
|
48
|
+
end
|
49
|
+
end # when x-ops-server-api-version header does not exist
|
50
|
+
|
51
|
+
context "when x-ops-server-api-version header exists" do
|
52
|
+
let(:min_server_version) { 2 }
|
53
|
+
let(:max_server_version) { 4 }
|
54
|
+
let(:return_hash) {
|
55
|
+
{
|
56
|
+
"min_version" => min_server_version,
|
57
|
+
"max_version" => max_server_version
|
58
|
+
}
|
59
|
+
}
|
60
|
+
|
61
|
+
before(:each) do
|
62
|
+
allow(response).to receive(:[]).with('x-ops-server-api-version').and_return(Chef::JSONCompat.to_json(return_hash))
|
63
|
+
end
|
64
|
+
|
65
|
+
context "when there is no intersection between client and server versions" do
|
66
|
+
shared_examples_for "no intersection between client and server versions" do
|
67
|
+
it "return an array" do
|
68
|
+
expect(object.server_client_api_version_intersection(exception, supported_client_versions)).
|
69
|
+
to be_a_kind_of(Array)
|
70
|
+
end
|
71
|
+
|
72
|
+
it "returns an empty array" do
|
73
|
+
expect(object.server_client_api_version_intersection(exception, supported_client_versions).length).
|
74
|
+
to eq(0)
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
context "when all the versions are higher than the max" do
|
80
|
+
it_should_behave_like "no intersection between client and server versions" do
|
81
|
+
let(:supported_client_versions) { [5,6,7] }
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
context "when all the versions are lower than the min" do
|
86
|
+
it_should_behave_like "no intersection between client and server versions" do
|
87
|
+
let(:supported_client_versions) { [0,1] }
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
end # when there is no intersection between client and server versions
|
92
|
+
|
93
|
+
context "when there is an intersection between client and server versions" do
|
94
|
+
context "when multiple versions intersect" do
|
95
|
+
let(:supported_client_versions) { [1,2,3,4,5] }
|
96
|
+
|
97
|
+
it "includes all of the intersection" do
|
98
|
+
expect(object.server_client_api_version_intersection(exception, supported_client_versions)).
|
99
|
+
to eq([2,3,4])
|
100
|
+
end
|
101
|
+
end # when multiple versions intersect
|
102
|
+
|
103
|
+
context "when only the min client version intersects" do
|
104
|
+
let(:supported_client_versions) { [0,1,2] }
|
105
|
+
|
106
|
+
it "includes the intersection" do
|
107
|
+
expect(object.server_client_api_version_intersection(exception, supported_client_versions)).
|
108
|
+
to eq([2])
|
109
|
+
end
|
110
|
+
end # when only the min client version intersects
|
111
|
+
|
112
|
+
context "when only the max client version intersects" do
|
113
|
+
let(:supported_client_versions) { [4,5,6] }
|
114
|
+
|
115
|
+
it "includes the intersection" do
|
116
|
+
expect(object.server_client_api_version_intersection(exception, supported_client_versions)).
|
117
|
+
to eq([4])
|
118
|
+
end
|
119
|
+
end # when only the max client version intersects
|
120
|
+
|
121
|
+
end # when there is an intersection between client and server versions
|
122
|
+
|
123
|
+
end # when x-ops-server-api-version header exists
|
124
|
+
end # when the response code is 406
|
125
|
+
|
126
|
+
end # .server_client_api_version_intersection
|
127
|
+
end # Chef::Mixin::ApiVersionRequestHandling
|
@@ -22,7 +22,7 @@ describe Chef::Mixin::Command, :volatile do
|
|
22
22
|
|
23
23
|
if windows?
|
24
24
|
|
25
|
-
|
25
|
+
skip("TODO MOVE: this is a platform specific integration test.")
|
26
26
|
|
27
27
|
else
|
28
28
|
|
@@ -61,7 +61,6 @@ describe Chef::Mixin::Command, :volatile do
|
|
61
61
|
|
62
62
|
it "returns immediately after the first child process exits" do
|
63
63
|
expect {Timeout.timeout(10) do
|
64
|
-
pid, stdin,stdout,stderr = nil,nil,nil,nil
|
65
64
|
evil_forker="exit if fork; 10.times { sleep 1}"
|
66
65
|
popen4("ruby -e '#{evil_forker}'") do |pid,stdin,stdout,stderr|
|
67
66
|
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: Copyright (c) 2015 Chef Software, Inc.
|
3
|
+
# License:: Apache License, Version 2.0
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
|
18
|
+
require 'spec_helper'
|
19
|
+
require 'chef/mixin/powershell_out'
|
20
|
+
|
21
|
+
describe Chef::Mixin::PowershellOut do
|
22
|
+
let(:shell_out_class) { Class.new { include Chef::Mixin::PowershellOut } }
|
23
|
+
subject(:object) { shell_out_class.new }
|
24
|
+
let(:architecture) { "something" }
|
25
|
+
let(:flags) {
|
26
|
+
"-NoLogo -NonInteractive -NoProfile -ExecutionPolicy Unrestricted -InputFormat None"
|
27
|
+
}
|
28
|
+
|
29
|
+
describe "#powershell_out" do
|
30
|
+
it "runs a command and returns the shell_out object" do
|
31
|
+
ret = double("Mixlib::ShellOut")
|
32
|
+
expect(object).to receive(:shell_out).with(
|
33
|
+
"powershell.exe #{flags} -Command \"Get-Process\"",
|
34
|
+
{}
|
35
|
+
).and_return(ret)
|
36
|
+
expect(object.powershell_out("Get-Process")).to eql(ret)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "passes options" do
|
40
|
+
ret = double("Mixlib::ShellOut")
|
41
|
+
expect(object).to receive(:shell_out).with(
|
42
|
+
"powershell.exe #{flags} -Command \"Get-Process\"",
|
43
|
+
timeout: 600
|
44
|
+
).and_return(ret)
|
45
|
+
expect(object.powershell_out("Get-Process", timeout: 600)).to eql(ret)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "#powershell_out!" do
|
50
|
+
it "runs a command and returns the shell_out object" do
|
51
|
+
mixlib_shellout = double("Mixlib::ShellOut")
|
52
|
+
expect(object).to receive(:shell_out).with(
|
53
|
+
"powershell.exe #{flags} -Command \"Get-Process\"",
|
54
|
+
{}
|
55
|
+
).and_return(mixlib_shellout)
|
56
|
+
expect(mixlib_shellout).to receive(:error!)
|
57
|
+
expect(object.powershell_out!("Get-Process")).to eql(mixlib_shellout)
|
58
|
+
end
|
59
|
+
|
60
|
+
it "passes options" do
|
61
|
+
mixlib_shellout = double("Mixlib::ShellOut")
|
62
|
+
expect(object).to receive(:shell_out).with(
|
63
|
+
"powershell.exe #{flags} -Command \"Get-Process\"",
|
64
|
+
timeout: 600
|
65
|
+
).and_return(mixlib_shellout)
|
66
|
+
expect(mixlib_shellout).to receive(:error!)
|
67
|
+
expect(object.powershell_out!("Get-Process", timeout: 600)).to eql(mixlib_shellout)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -26,20 +26,32 @@ end
|
|
26
26
|
describe Chef::Mixin::Uris do
|
27
27
|
let (:uris) { Chef::UrisTest.new }
|
28
28
|
|
29
|
-
|
30
|
-
|
29
|
+
describe "#uri_scheme?" do
|
30
|
+
it "matches 'scheme://foo.com'" do
|
31
|
+
expect(uris.uri_scheme?('scheme://foo.com')).to eq(true)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "does not match 'c:/foo.com'" do
|
35
|
+
expect(uris.uri_scheme?('c:/foo.com')).to eq(false)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "does not match '/usr/bin/foo.com'" do
|
39
|
+
expect(uris.uri_scheme?('/usr/bin/foo.com')).to eq(false)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "does not match 'c:/foo.com://bar.com'" do
|
43
|
+
expect(uris.uri_scheme?('c:/foo.com://bar.com')).to eq(false)
|
44
|
+
end
|
31
45
|
end
|
32
46
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
it "does not match '/usr/bin/foo.com'" do
|
38
|
-
expect(uris.uri_scheme?('/usr/bin/foo.com')).to eq(false)
|
39
|
-
end
|
47
|
+
describe "#as_uri" do
|
48
|
+
it "parses a file scheme uri with spaces" do
|
49
|
+
expect{ uris.as_uri("file:///c:/foo bar.txt") }.not_to raise_exception
|
50
|
+
end
|
40
51
|
|
41
|
-
|
42
|
-
|
52
|
+
it "returns a URI object" do
|
53
|
+
expect( uris.as_uri("file:///c:/foo bar.txt") ).to be_a(URI)
|
54
|
+
end
|
43
55
|
end
|
44
56
|
|
45
57
|
end
|
data/spec/unit/node_map_spec.rb
CHANGED
@@ -134,6 +134,10 @@ describe Chef::NodeMap do
|
|
134
134
|
end
|
135
135
|
|
136
136
|
describe "resource back-compat testing" do
|
137
|
+
before :each do
|
138
|
+
Chef::Config[:treat_deprecation_warnings_as_errors] = false
|
139
|
+
end
|
140
|
+
|
137
141
|
it "should handle :on_platforms => :all" do
|
138
142
|
node_map.set(:chef_gem, :foo, :on_platforms => :all)
|
139
143
|
allow(node).to receive(:[]).with(:platform).and_return("windows")
|
@@ -152,4 +156,3 @@ describe Chef::NodeMap do
|
|
152
156
|
end
|
153
157
|
|
154
158
|
end
|
155
|
-
|
@@ -0,0 +1,276 @@
|
|
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
|
+
# DEPRECATION NOTE
|
20
|
+
# This code only remains to support users still operating with
|
21
|
+
# Open Source Chef Server 11 and should be removed once support
|
22
|
+
# for OSC 11 ends. New development should occur in user_spec.rb.
|
23
|
+
|
24
|
+
require 'spec_helper'
|
25
|
+
|
26
|
+
require 'chef/osc_user'
|
27
|
+
require 'tempfile'
|
28
|
+
|
29
|
+
describe Chef::OscUser do
|
30
|
+
before(:each) do
|
31
|
+
@user = Chef::OscUser.new
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "initialize" do
|
35
|
+
it "should be a Chef::OscUser" do
|
36
|
+
expect(@user).to be_a_kind_of(Chef::OscUser)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "name" do
|
41
|
+
it "should let you set the name to a string" do
|
42
|
+
expect(@user.name("ops_master")).to eq("ops_master")
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should return the current name" do
|
46
|
+
@user.name "ops_master"
|
47
|
+
expect(@user.name).to eq("ops_master")
|
48
|
+
end
|
49
|
+
|
50
|
+
# It is not feasible to check all invalid characters. Here are a few
|
51
|
+
# that we probably care about.
|
52
|
+
it "should not accept invalid characters" do
|
53
|
+
# capital letters
|
54
|
+
expect { @user.name "Bar" }.to raise_error(ArgumentError)
|
55
|
+
# slashes
|
56
|
+
expect { @user.name "foo/bar" }.to raise_error(ArgumentError)
|
57
|
+
# ?
|
58
|
+
expect { @user.name "foo?" }.to raise_error(ArgumentError)
|
59
|
+
# &
|
60
|
+
expect { @user.name "foo&" }.to raise_error(ArgumentError)
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
it "should not accept spaces" do
|
65
|
+
expect { @user.name "ops master" }.to raise_error(ArgumentError)
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should throw an ArgumentError if you feed it anything but a string" do
|
69
|
+
expect { @user.name Hash.new }.to raise_error(ArgumentError)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe "admin" do
|
74
|
+
it "should let you set the admin bit" do
|
75
|
+
expect(@user.admin(true)).to eq(true)
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should return the current admin value" do
|
79
|
+
@user.admin true
|
80
|
+
expect(@user.admin).to eq(true)
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should default to false" do
|
84
|
+
expect(@user.admin).to eq(false)
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should throw an ArgumentError if you feed it anything but true or false" do
|
88
|
+
expect { @user.name Hash.new }.to raise_error(ArgumentError)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe "public_key" do
|
93
|
+
it "should let you set the public key" do
|
94
|
+
expect(@user.public_key("super public")).to eq("super public")
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should return the current public key" do
|
98
|
+
@user.public_key("super public")
|
99
|
+
expect(@user.public_key).to eq("super public")
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should throw an ArgumentError if you feed it something lame" do
|
103
|
+
expect { @user.public_key Hash.new }.to raise_error(ArgumentError)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
describe "private_key" do
|
108
|
+
it "should let you set the private key" do
|
109
|
+
expect(@user.private_key("super private")).to eq("super private")
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should return the private key" do
|
113
|
+
@user.private_key("super private")
|
114
|
+
expect(@user.private_key).to eq("super private")
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should throw an ArgumentError if you feed it something lame" do
|
118
|
+
expect { @user.private_key Hash.new }.to raise_error(ArgumentError)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
describe "when serializing to JSON" do
|
123
|
+
before(:each) do
|
124
|
+
@user.name("black")
|
125
|
+
@user.public_key("crowes")
|
126
|
+
@json = @user.to_json
|
127
|
+
end
|
128
|
+
|
129
|
+
it "serializes as a JSON object" do
|
130
|
+
expect(@json).to match(/^\{.+\}$/)
|
131
|
+
end
|
132
|
+
|
133
|
+
it "includes the name value" do
|
134
|
+
expect(@json).to include(%q{"name":"black"})
|
135
|
+
end
|
136
|
+
|
137
|
+
it "includes the public key value" do
|
138
|
+
expect(@json).to include(%{"public_key":"crowes"})
|
139
|
+
end
|
140
|
+
|
141
|
+
it "includes the 'admin' flag" do
|
142
|
+
expect(@json).to include(%q{"admin":false})
|
143
|
+
end
|
144
|
+
|
145
|
+
it "includes the private key when present" do
|
146
|
+
@user.private_key("monkeypants")
|
147
|
+
expect(@user.to_json).to include(%q{"private_key":"monkeypants"})
|
148
|
+
end
|
149
|
+
|
150
|
+
it "does not include the private key if not present" do
|
151
|
+
expect(@json).not_to include("private_key")
|
152
|
+
end
|
153
|
+
|
154
|
+
it "includes the password if present" do
|
155
|
+
@user.password "password"
|
156
|
+
expect(@user.to_json).to include(%q{"password":"password"})
|
157
|
+
end
|
158
|
+
|
159
|
+
it "does not include the password if not present" do
|
160
|
+
expect(@json).not_to include("password")
|
161
|
+
end
|
162
|
+
|
163
|
+
include_examples "to_json equalivent to Chef::JSONCompat.to_json" do
|
164
|
+
let(:jsonable) { @user }
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
describe "when deserializing from JSON" do
|
169
|
+
before(:each) do
|
170
|
+
user = { "name" => "mr_spinks",
|
171
|
+
"public_key" => "turtles",
|
172
|
+
"private_key" => "pandas",
|
173
|
+
"password" => "password",
|
174
|
+
"admin" => true }
|
175
|
+
@user = Chef::OscUser.from_json(Chef::JSONCompat.to_json(user))
|
176
|
+
end
|
177
|
+
|
178
|
+
it "should deserialize to a Chef::OscUser object" do
|
179
|
+
expect(@user).to be_a_kind_of(Chef::OscUser)
|
180
|
+
end
|
181
|
+
|
182
|
+
it "preserves the name" do
|
183
|
+
expect(@user.name).to eq("mr_spinks")
|
184
|
+
end
|
185
|
+
|
186
|
+
it "preserves the public key" do
|
187
|
+
expect(@user.public_key).to eq("turtles")
|
188
|
+
end
|
189
|
+
|
190
|
+
it "preserves the admin status" do
|
191
|
+
expect(@user.admin).to be_truthy
|
192
|
+
end
|
193
|
+
|
194
|
+
it "includes the private key if present" do
|
195
|
+
expect(@user.private_key).to eq("pandas")
|
196
|
+
end
|
197
|
+
|
198
|
+
it "includes the password if present" do
|
199
|
+
expect(@user.password).to eq("password")
|
200
|
+
end
|
201
|
+
|
202
|
+
end
|
203
|
+
|
204
|
+
describe "API Interactions" do
|
205
|
+
before (:each) do
|
206
|
+
@user = Chef::OscUser.new
|
207
|
+
@user.name "foobar"
|
208
|
+
@http_client = double("Chef::REST mock")
|
209
|
+
allow(Chef::REST).to receive(:new).and_return(@http_client)
|
210
|
+
end
|
211
|
+
|
212
|
+
describe "list" do
|
213
|
+
before(:each) do
|
214
|
+
Chef::Config[:chef_server_url] = "http://www.example.com"
|
215
|
+
@osc_response = { "admin" => "http://www.example.com/users/admin"}
|
216
|
+
@ohc_response = [ { "user" => { "username" => "admin" }} ]
|
217
|
+
allow(Chef::OscUser).to receive(:load).with("admin").and_return(@user)
|
218
|
+
@osc_inflated_response = { "admin" => @user }
|
219
|
+
end
|
220
|
+
|
221
|
+
it "lists all clients on an OSC server" do
|
222
|
+
allow(@http_client).to receive(:get_rest).with("users").and_return(@osc_response)
|
223
|
+
expect(Chef::OscUser.list).to eq(@osc_response)
|
224
|
+
end
|
225
|
+
|
226
|
+
it "inflate all clients on an OSC server" do
|
227
|
+
allow(@http_client).to receive(:get_rest).with("users").and_return(@osc_response)
|
228
|
+
expect(Chef::OscUser.list(true)).to eq(@osc_inflated_response)
|
229
|
+
end
|
230
|
+
|
231
|
+
it "lists all clients on an OHC/OPC server" do
|
232
|
+
allow(@http_client).to receive(:get_rest).with("users").and_return(@ohc_response)
|
233
|
+
# We expect that Chef::OscUser.list will give a consistent response
|
234
|
+
# so OHC API responses should be transformed to OSC-style output.
|
235
|
+
expect(Chef::OscUser.list).to eq(@osc_response)
|
236
|
+
end
|
237
|
+
|
238
|
+
it "inflate all clients on an OHC/OPC server" do
|
239
|
+
allow(@http_client).to receive(:get_rest).with("users").and_return(@ohc_response)
|
240
|
+
expect(Chef::OscUser.list(true)).to eq(@osc_inflated_response)
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
describe "create" do
|
245
|
+
it "creates a new user via the API" do
|
246
|
+
@user.password "password"
|
247
|
+
expect(@http_client).to receive(:post_rest).with("users", {:name => "foobar", :admin => false, :password => "password"}).and_return({})
|
248
|
+
@user.create
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
252
|
+
describe "read" do
|
253
|
+
it "loads a named user from the API" do
|
254
|
+
expect(@http_client).to receive(:get_rest).with("users/foobar").and_return({"name" => "foobar", "admin" => true, "public_key" => "pubkey"})
|
255
|
+
user = Chef::OscUser.load("foobar")
|
256
|
+
expect(user.name).to eq("foobar")
|
257
|
+
expect(user.admin).to eq(true)
|
258
|
+
expect(user.public_key).to eq("pubkey")
|
259
|
+
end
|
260
|
+
end
|
261
|
+
|
262
|
+
describe "update" do
|
263
|
+
it "updates an existing user on via the API" do
|
264
|
+
expect(@http_client).to receive(:put_rest).with("users/foobar", {:name => "foobar", :admin => false}).and_return({})
|
265
|
+
@user.update
|
266
|
+
end
|
267
|
+
end
|
268
|
+
|
269
|
+
describe "destroy" do
|
270
|
+
it "deletes the specified user via the API" do
|
271
|
+
expect(@http_client).to receive(:delete_rest).with("users/foobar")
|
272
|
+
@user.destroy
|
273
|
+
end
|
274
|
+
end
|
275
|
+
end
|
276
|
+
end
|