chef 17.2.29-universal-mingw32 → 17.5.22-universal-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +6 -5
- data/chef.gemspec +3 -0
- data/lib/chef/application/base.rb +11 -1
- data/lib/chef/application.rb +3 -1
- data/lib/chef/client.rb +2 -3
- data/lib/chef/compliance/default_attributes.rb +5 -3
- data/lib/chef/compliance/input.rb +115 -0
- data/lib/chef/compliance/input_collection.rb +139 -0
- data/lib/chef/compliance/profile.rb +122 -0
- data/lib/chef/compliance/profile_collection.rb +109 -0
- data/lib/chef/compliance/reporter/automate.rb +1 -1
- data/lib/chef/compliance/runner.rb +62 -6
- data/lib/chef/compliance/waiver.rb +115 -0
- data/lib/chef/compliance/waiver_collection.rb +143 -0
- data/lib/chef/data_bag.rb +1 -2
- data/lib/chef/data_bag_item.rb +1 -2
- data/lib/chef/deprecated.rb +10 -4
- data/lib/chef/dsl/compliance.rb +38 -0
- data/lib/chef/dsl/reader_helpers.rb +51 -0
- data/lib/chef/dsl/recipe.rb +4 -2
- data/lib/chef/dsl/render_helpers.rb +44 -0
- data/lib/chef/dsl/secret.rb +62 -0
- data/lib/chef/dsl/toml.rb +116 -0
- data/lib/chef/dsl/universal.rb +7 -0
- data/lib/chef/dsl.rb +1 -0
- data/lib/chef/event_dispatch/base.rb +44 -2
- data/lib/chef/exceptions.rb +20 -0
- data/lib/chef/formatters/doc.rb +60 -13
- data/lib/chef/formatters/error_mapper.rb +2 -2
- data/lib/chef/formatters/minimal.rb +6 -5
- data/lib/chef/handler/slow_report.rb +1 -1
- data/lib/chef/http/basic_client.rb +15 -7
- data/lib/chef/http.rb +12 -8
- data/lib/chef/json_compat.rb +1 -1
- data/lib/chef/policy_builder/policyfile.rb +88 -45
- data/lib/chef/provider/execute.rb +1 -1
- data/lib/chef/provider/file.rb +4 -2
- data/lib/chef/provider/group/dscl.rb +1 -1
- data/lib/chef/provider/launchd.rb +6 -6
- data/lib/chef/provider/link.rb +2 -2
- data/lib/chef/provider/lwrp_base.rb +1 -1
- data/lib/chef/provider/package/habitat.rb +168 -0
- data/lib/chef/provider/package/powershell.rb +5 -0
- data/lib/chef/provider/registry_key.rb +3 -2
- data/lib/chef/provider/remote_file/http.rb +1 -1
- data/lib/chef/provider/subversion.rb +4 -4
- data/lib/chef/provider/support/yum_repo.erb +1 -1
- data/lib/chef/provider/systemd_unit.rb +17 -16
- data/lib/chef/provider/template.rb +1 -1
- data/lib/chef/provider/user/mac.rb +3 -3
- data/lib/chef/provider/yum_repository.rb +27 -43
- data/lib/chef/provider/zypper_repository.rb +3 -3
- data/lib/chef/provider.rb +26 -1
- data/lib/chef/provider_resolver.rb +8 -2
- data/lib/chef/providers.rb +1 -0
- data/lib/chef/resource/archive_file.rb +17 -14
- data/lib/chef/resource/chef_client_config.rb +7 -2
- data/lib/chef/resource/chef_client_cron.rb +1 -1
- data/lib/chef/resource/chef_client_launchd.rb +1 -1
- data/lib/chef/resource/chef_client_scheduled_task.rb +46 -3
- data/lib/chef/resource/chef_client_systemd_timer.rb +1 -1
- data/lib/chef/resource/chef_client_trusted_certificate.rb +2 -2
- data/lib/chef/resource/chef_vault_secret.rb +2 -2
- data/lib/chef/resource/chocolatey_config.rb +13 -13
- data/lib/chef/resource/dsc_resource.rb +1 -1
- data/lib/chef/resource/execute.rb +5 -5
- data/lib/chef/resource/file/verification/json.rb +50 -0
- data/lib/chef/resource/file/verification/yaml.rb +52 -0
- data/lib/chef/resource/gem_package.rb +2 -1
- data/lib/chef/resource/habitat/_habitat_shared.rb +28 -0
- data/lib/chef/resource/habitat/habitat_package.rb +129 -0
- data/lib/chef/resource/habitat/habitat_sup.rb +329 -0
- data/lib/chef/resource/habitat/habitat_sup_systemd.rb +67 -0
- data/lib/chef/resource/habitat/habitat_sup_windows.rb +90 -0
- data/lib/chef/resource/habitat_config.rb +107 -0
- data/lib/chef/resource/habitat_install.rb +247 -0
- data/lib/chef/resource/habitat_service.rb +451 -0
- data/lib/chef/resource/habitat_user_toml.rb +92 -0
- data/lib/chef/resource/homebrew_cask.rb +1 -1
- data/lib/chef/resource/inspec_input.rb +128 -0
- data/lib/chef/resource/inspec_waiver.rb +185 -0
- data/lib/chef/resource/inspec_waiver_file_entry.rb +2 -2
- data/lib/chef/resource/launchd.rb +3 -3
- data/lib/chef/resource/lwrp_base.rb +1 -1
- data/lib/chef/resource/mount.rb +1 -1
- data/lib/chef/resource/registry_key.rb +36 -48
- data/lib/chef/resource/remote_file.rb +99 -3
- data/lib/chef/resource/rhsm_subscription.rb +5 -5
- data/lib/chef/resource/ruby_block.rb +100 -0
- data/lib/chef/resource/scm/subversion.rb +1 -1
- data/lib/chef/resource/support/HabService.dll.config.erb +19 -0
- data/lib/chef/resource/support/client.erb +8 -1
- data/lib/chef/resource/support/sup.toml.erb +179 -0
- data/lib/chef/resource/sysctl.rb +2 -2
- data/lib/chef/resource/systemd_unit.rb +3 -3
- data/lib/chef/resource/timezone.rb +2 -2
- data/lib/chef/resource/user_ulimit.rb +1 -0
- data/lib/chef/resource/windows_defender.rb +163 -0
- data/lib/chef/resource/windows_defender_exclusion.rb +125 -0
- data/lib/chef/resource/windows_printer.rb +78 -44
- data/lib/chef/resource/windows_printer_port.rb +1 -1
- data/lib/chef/resource/windows_uac.rb +3 -1
- data/lib/chef/resource/windows_update_settings.rb +259 -0
- data/lib/chef/resource/windows_user_privilege.rb +1 -1
- data/lib/chef/resource/yum_package.rb +1 -5
- data/lib/chef/resource.rb +13 -17
- data/lib/chef/resource_inspector.rb +6 -2
- data/lib/chef/resources.rb +14 -1
- data/lib/chef/run_context/cookbook_compiler.rb +112 -28
- data/lib/chef/run_context.rb +31 -1
- data/lib/chef/secret_fetcher/akeyless_vault.rb +57 -0
- data/lib/chef/secret_fetcher/aws_secrets_manager.rb +65 -0
- data/lib/chef/secret_fetcher/azure_key_vault.rb +78 -0
- data/lib/chef/secret_fetcher/base.rb +76 -0
- data/lib/chef/secret_fetcher/example.rb +46 -0
- data/lib/chef/secret_fetcher/hashi_vault.rb +100 -0
- data/lib/chef/secret_fetcher.rb +61 -0
- data/lib/chef/version.rb +1 -1
- data/spec/data/archive_file/test_archive.tar.gz +0 -0
- data/spec/functional/mixin/from_file_spec.rb +1 -1
- data/spec/functional/resource/archive_file_spec.rb +87 -0
- data/spec/functional/resource/group_spec.rb +5 -1
- data/spec/functional/resource/link_spec.rb +8 -0
- data/spec/integration/compliance/compliance_spec.rb +61 -0
- data/spec/integration/recipes/recipe_dsl_spec.rb +1 -1
- data/spec/integration/recipes/resource_action_spec.rb +6 -6
- data/spec/spec_helper.rb +3 -0
- data/spec/support/platform_helpers.rb +4 -0
- data/spec/support/ruby_installer.rb +51 -0
- data/spec/support/shared/unit/provider/file.rb +2 -8
- data/spec/unit/compliance/input_spec.rb +104 -0
- data/spec/unit/compliance/profile_spec.rb +120 -0
- data/spec/unit/compliance/runner_spec.rb +46 -2
- data/spec/unit/compliance/waiver_spec.rb +104 -0
- data/spec/unit/data_bag_item_spec.rb +2 -2
- data/spec/unit/data_bag_spec.rb +1 -1
- data/spec/unit/dsl/render_helpers_spec.rb +102 -0
- data/spec/unit/dsl/secret_spec.rb +71 -0
- data/spec/unit/formatters/doc_spec.rb +1 -1
- data/spec/unit/http/basic_client_spec.rb +30 -0
- data/spec/unit/http_spec.rb +8 -2
- data/spec/unit/policy_builder/dynamic_spec.rb +0 -5
- data/spec/unit/policy_builder/policyfile_spec.rb +144 -56
- data/spec/unit/provider/apt_update_spec.rb +3 -1
- data/spec/unit/provider/link_spec.rb +13 -7
- data/spec/unit/provider/mount/aix_spec.rb +1 -1
- data/spec/unit/provider/package/powershell_spec.rb +74 -12
- data/spec/unit/provider/remote_file/http_spec.rb +10 -0
- data/spec/unit/provider/template_spec.rb +2 -2
- data/spec/unit/provider_spec.rb +23 -0
- data/spec/unit/resource/archive_file_spec.rb +414 -3
- data/spec/unit/resource/chef_client_scheduled_task_spec.rb +69 -0
- data/spec/unit/resource/file/verification/json_spec.rb +72 -0
- data/spec/unit/resource/file/verification/yaml_spec.rb +67 -0
- data/spec/unit/resource/homebrew_cask_spec.rb +29 -11
- data/spec/unit/resource/inspec_input_spec.rb +300 -0
- data/spec/unit/resource/inspec_waiver_spec.rb +312 -0
- data/spec/unit/resource/mount_spec.rb +10 -0
- data/spec/unit/resource/rhsm_subscription_spec.rb +50 -3
- data/spec/unit/resource/systemd_unit_spec.rb +1 -1
- data/spec/unit/resource/user_ulimit_spec.rb +14 -1
- data/spec/unit/resource/windows_defender_exclusion_spec.rb +62 -0
- data/spec/unit/resource/windows_defender_spec.rb +71 -0
- data/spec/unit/resource/windows_update_settings_spec.rb +64 -0
- data/spec/unit/resource_spec.rb +19 -8
- data/spec/unit/secret_fetcher/akeyless_vault_spec.rb +37 -0
- data/spec/unit/secret_fetcher/aws_secrets_manager_spec.rb +70 -0
- data/spec/unit/secret_fetcher/azure_key_vault_spec.rb +70 -0
- data/spec/unit/secret_fetcher/hashi_vault_spec.rb +80 -0
- data/spec/unit/secret_fetcher_spec.rb +82 -0
- data/tasks/rspec.rb +2 -1
- metadata +106 -7
@@ -18,15 +18,24 @@
|
|
18
18
|
require "spec_helper"
|
19
19
|
|
20
20
|
describe Chef::Resource::RhsmSubscription do
|
21
|
-
let(:
|
22
|
-
let(:
|
21
|
+
let(:event_dispatch) { Chef::EventDispatch::Dispatcher.new }
|
22
|
+
let(:node) { Chef::Node.new }
|
23
|
+
let(:run_context) { Chef::RunContext.new(node, {}, event_dispatch) }
|
24
|
+
|
25
|
+
let(:pool_id) { "8a8dd78c766232550226b46e59404aba" }
|
26
|
+
let(:resource) { Chef::Resource::RhsmSubscription.new(pool_id, run_context) }
|
27
|
+
let(:provider) { resource.provider_for_action(Array(resource.action).first) }
|
28
|
+
|
29
|
+
before do
|
30
|
+
allow(resource).to receive(:provider_for_action).with(:attach).and_return(provider)
|
31
|
+
end
|
23
32
|
|
24
33
|
it "has a resource name of :rhsm_subscription" do
|
25
34
|
expect(resource.resource_name).to eql(:rhsm_subscription)
|
26
35
|
end
|
27
36
|
|
28
37
|
it "the pool_id property is the name_property" do
|
29
|
-
expect(resource.pool_id).to eql(
|
38
|
+
expect(resource.pool_id).to eql(pool_id)
|
30
39
|
end
|
31
40
|
|
32
41
|
it "sets the default action as :attach" do
|
@@ -38,6 +47,44 @@ describe Chef::Resource::RhsmSubscription do
|
|
38
47
|
expect { resource.action :remove }.not_to raise_error
|
39
48
|
end
|
40
49
|
|
50
|
+
describe "#action_attach" do
|
51
|
+
let(:yum_package_double) { instance_double("Chef::Resource::YumPackage") }
|
52
|
+
let(:so_double) { instance_double("Mixlib::ShellOut", stdout: "Successfully attached a subscription for: My Subscription", exitstatus: 0, error?: false) }
|
53
|
+
|
54
|
+
before do
|
55
|
+
allow(provider).to receive(:shell_out!).with("subscription-manager attach --pool=#{resource.pool_id}").and_return(so_double)
|
56
|
+
allow(provider).to receive(:build_resource).with(:package, "rhsm_subscription-#{pool_id}-flush_cache").and_return(yum_package_double)
|
57
|
+
allow(yum_package_double).to receive(:run_action).with(:flush_cache)
|
58
|
+
end
|
59
|
+
|
60
|
+
context "when already attached to pool" do
|
61
|
+
before do
|
62
|
+
allow(provider).to receive(:subscription_attached?).with(resource.pool_id).and_return(true)
|
63
|
+
end
|
64
|
+
|
65
|
+
it "does not attach to pool" do
|
66
|
+
expect(provider).not_to receive(:shell_out!)
|
67
|
+
resource.run_action(:attach)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context "when not attached to pool" do
|
72
|
+
before do
|
73
|
+
allow(provider).to receive(:subscription_attached?).with(resource.pool_id).and_return(false)
|
74
|
+
end
|
75
|
+
|
76
|
+
it "attaches to pool" do
|
77
|
+
expect(provider).to receive(:shell_out!).with("subscription-manager attach --pool=#{resource.pool_id}")
|
78
|
+
resource.run_action(:attach)
|
79
|
+
end
|
80
|
+
|
81
|
+
it "flushes package provider cache" do
|
82
|
+
expect(yum_package_double).to receive(:run_action).with(:flush_cache)
|
83
|
+
resource.run_action(:attach)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
41
88
|
describe "#subscription_attached?" do
|
42
89
|
let(:cmd) { double("cmd") }
|
43
90
|
let(:output) { "Pool ID: pool123" }
|
@@ -20,7 +20,7 @@ require "spec_helper"
|
|
20
20
|
|
21
21
|
describe Chef::Resource::SystemdUnit do
|
22
22
|
let(:resource) { Chef::Resource::SystemdUnit.new("sysstat-collect.timer") }
|
23
|
-
let(:unit_content_string) { "[Unit]\nDescription
|
23
|
+
let(:unit_content_string) { "[Unit]\nDescription=Run system activity accounting tool every 10 minutes\nDocumentation=foo\nDocumentation=bar\n\n[Timer]\nOnCalendar=*:00/10\n\n[Install]\nWantedBy=sysstat.service\n" }
|
24
24
|
let(:unit_content_hash) do
|
25
25
|
{
|
26
26
|
"Unit" => {
|
@@ -17,7 +17,6 @@
|
|
17
17
|
#
|
18
18
|
|
19
19
|
require "spec_helper"
|
20
|
-
|
21
20
|
describe Chef::Resource::UserUlimit do
|
22
21
|
let(:node) { Chef::Node.new }
|
23
22
|
let(:events) { Chef::EventDispatch::Dispatcher.new }
|
@@ -50,4 +49,18 @@ describe Chef::Resource::UserUlimit do
|
|
50
49
|
expect { resource.action :create }.not_to raise_error
|
51
50
|
expect { resource.action :delete }.not_to raise_error
|
52
51
|
end
|
52
|
+
|
53
|
+
describe "sensitive attribute" do
|
54
|
+
context "should be insensitive by default" do
|
55
|
+
it { expect(resource.sensitive).to(be_falsey) }
|
56
|
+
end
|
57
|
+
|
58
|
+
context "when set" do
|
59
|
+
before { resource.sensitive(true) }
|
60
|
+
|
61
|
+
it "should be set on the resource" do
|
62
|
+
expect(resource.sensitive).to(be_truthy)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
53
66
|
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: Copyright (c) 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
|
+
|
20
|
+
describe Chef::Resource::WindowsDefenderExclusion do
|
21
|
+
let(:resource) { Chef::Resource::WindowsDefenderExclusion.new("fakey_fakerton") }
|
22
|
+
|
23
|
+
it "sets resource name as :windows_defender_exclusion" do
|
24
|
+
expect(resource.resource_name).to eql(:windows_defender_exclusion)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "sets the default action as :add" do
|
28
|
+
expect(resource.action).to eql([:add])
|
29
|
+
end
|
30
|
+
|
31
|
+
it "supports :add, :remove actions" do
|
32
|
+
expect { resource.action :add }.not_to raise_error
|
33
|
+
expect { resource.action :remove }.not_to raise_error
|
34
|
+
end
|
35
|
+
|
36
|
+
it "paths property defaults to []" do
|
37
|
+
expect(resource.paths).to eql([])
|
38
|
+
end
|
39
|
+
|
40
|
+
it "paths coerces strings to arrays" do
|
41
|
+
resource.paths "foo,bar"
|
42
|
+
expect(resource.paths).to eq(%w{foo bar})
|
43
|
+
end
|
44
|
+
|
45
|
+
it "extensions property defaults to []" do
|
46
|
+
expect(resource.extensions).to eql([])
|
47
|
+
end
|
48
|
+
|
49
|
+
it "extensions coerces strings to arrays" do
|
50
|
+
resource.extensions "foo,bar"
|
51
|
+
expect(resource.extensions).to eq(%w{foo bar})
|
52
|
+
end
|
53
|
+
|
54
|
+
it "process_paths property defaults to []" do
|
55
|
+
expect(resource.process_paths).to eql([])
|
56
|
+
end
|
57
|
+
|
58
|
+
it "process_paths coerces strings to arrays" do
|
59
|
+
resource.process_paths "foo,bar"
|
60
|
+
expect(resource.process_paths).to eq(%w{foo bar})
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: Copyright (c) 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
|
+
|
20
|
+
describe Chef::Resource::WindowsDefender do
|
21
|
+
let(:resource) { Chef::Resource::WindowsDefender.new("fakey_fakerton") }
|
22
|
+
|
23
|
+
it "sets resource name as :windows_defender" do
|
24
|
+
expect(resource.resource_name).to eql(:windows_defender)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "sets the default action as :enable" do
|
28
|
+
expect(resource.action).to eql([:enable])
|
29
|
+
end
|
30
|
+
|
31
|
+
it "supports :enable, :disable actions" do
|
32
|
+
expect { resource.action :enable }.not_to raise_error
|
33
|
+
expect { resource.action :disable }.not_to raise_error
|
34
|
+
end
|
35
|
+
|
36
|
+
it "realtime_protection property defaults to true" do
|
37
|
+
expect(resource.realtime_protection).to eql(true)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "intrusion_protection_system property defaults to true" do
|
41
|
+
expect(resource.intrusion_protection_system).to eql(true)
|
42
|
+
end
|
43
|
+
|
44
|
+
it "lock_ui property defaults to true" do
|
45
|
+
expect(resource.lock_ui).to eql(false)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "scan_archives property defaults to true" do
|
49
|
+
expect(resource.scan_archives).to eql(true)
|
50
|
+
end
|
51
|
+
|
52
|
+
it "scan_scripts property defaults to true" do
|
53
|
+
expect(resource.scan_scripts).to eql(false)
|
54
|
+
end
|
55
|
+
|
56
|
+
it "scan_email property defaults to true" do
|
57
|
+
expect(resource.scan_email).to eql(false)
|
58
|
+
end
|
59
|
+
|
60
|
+
it "scan_removable_drives property defaults to true" do
|
61
|
+
expect(resource.scan_removable_drives).to eql(false)
|
62
|
+
end
|
63
|
+
|
64
|
+
it "scan_network_files property defaults to true" do
|
65
|
+
expect(resource.scan_network_files).to eql(false)
|
66
|
+
end
|
67
|
+
|
68
|
+
it "scan_mapped_drives property defaults to true" do
|
69
|
+
expect(resource.scan_mapped_drives).to eql(true)
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: Copyright (c) Chef Software Inc.
|
3
|
+
# Author:: Tim Smith (tsmith@chef.io)
|
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::Resource::WindowsUpdateSettings do
|
22
|
+
let(:resource) { Chef::Resource::WindowsUpdateSettings.new("foobar") }
|
23
|
+
|
24
|
+
it "sets resource name as :windows_update_settings" do
|
25
|
+
expect(resource.resource_name).to eql(:windows_update_settings)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "sets the default action as :set" do
|
29
|
+
expect(resource.action).to eql([:set])
|
30
|
+
end
|
31
|
+
|
32
|
+
it "supports :set and legacy :enable actions" do
|
33
|
+
expect { resource.action :set }.not_to raise_error
|
34
|
+
expect { resource.action :enable }.not_to raise_error
|
35
|
+
end
|
36
|
+
|
37
|
+
it "raises an error if scheduled_install_day isn't a validate day" do
|
38
|
+
expect { resource.scheduled_install_day "Saturday" }.not_to raise_error
|
39
|
+
expect { resource.scheduled_install_day "Sunday" }.not_to raise_error
|
40
|
+
expect { resource.scheduled_install_day "Extraday" }.to raise_error(ArgumentError)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "raises an error if automatic_update_option isn't a validate option" do
|
44
|
+
expect { resource.automatic_update_option 2 }.not_to raise_error
|
45
|
+
expect { resource.automatic_update_option :notify }.not_to raise_error
|
46
|
+
expect { resource.automatic_update_option :nope }.to raise_error(ArgumentError)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "coerces legacy Integer value in automatic_update_option to friendly symbol" do
|
50
|
+
resource.automatic_update_option 2
|
51
|
+
expect(resource.automatic_update_option).to eql(:notify)
|
52
|
+
end
|
53
|
+
|
54
|
+
it "raises an error if scheduled_install_hour isn't a 24 hour clock hour" do
|
55
|
+
expect { resource.scheduled_install_hour 2 }.not_to raise_error
|
56
|
+
expect { resource.scheduled_install_hour 0 }.to raise_error(ArgumentError)
|
57
|
+
expect { resource.scheduled_install_hour 25 }.to raise_error(ArgumentError)
|
58
|
+
end
|
59
|
+
|
60
|
+
it "raises an error if custom_detection_frequency isn't a valid frequency" do
|
61
|
+
expect { resource.custom_detection_frequency 0 }.not_to raise_error
|
62
|
+
expect { resource.custom_detection_frequency 23 }.to raise_error(ArgumentError)
|
63
|
+
end
|
64
|
+
end
|
data/spec/unit/resource_spec.rb
CHANGED
@@ -1172,21 +1172,23 @@ describe Chef::Resource do
|
|
1172
1172
|
action :base_action3, description: "unmodified base action 3 desc" do; end
|
1173
1173
|
end
|
1174
1174
|
|
1175
|
+
let(:resource_inst) { TestResource.new("TestResource", nil) }
|
1176
|
+
|
1175
1177
|
it "returns nil when no description was provided for the action" do
|
1176
|
-
expect(
|
1178
|
+
expect(resource_inst.action_description(:base_action0)).to eql(nil)
|
1177
1179
|
end
|
1178
1180
|
|
1179
1181
|
context "when action definition is a string" do
|
1180
1182
|
it "returns the description whether a symbol or string is used to look it up" do
|
1181
|
-
expect(
|
1182
|
-
expect(
|
1183
|
+
expect(resource_inst.action_description("string_action")).to eql("a string test")
|
1184
|
+
expect(resource_inst.action_description(:string_action)).to eql("a string test")
|
1183
1185
|
end
|
1184
1186
|
end
|
1185
1187
|
|
1186
1188
|
context "when action definition is a symbol" do
|
1187
1189
|
it "returns the description whether a symbol or string is used to look up" do
|
1188
|
-
expect(
|
1189
|
-
expect(
|
1190
|
+
expect(resource_inst.action_description("symbol_action")).to eql("a symbol test")
|
1191
|
+
expect(resource_inst.action_description(:symbol_action)).to eql("a symbol test")
|
1190
1192
|
end
|
1191
1193
|
end
|
1192
1194
|
|
@@ -1196,14 +1198,23 @@ describe Chef::Resource do
|
|
1196
1198
|
action :base_action3 do; end
|
1197
1199
|
end
|
1198
1200
|
|
1201
|
+
class TestResourceChild2 < TestResource
|
1202
|
+
# We should never see this description
|
1203
|
+
action :base_action2, description: "if you see this in an error, TestResourceChild was polluted with this description" do; end
|
1204
|
+
end
|
1205
|
+
let(:resource_inst) { TestResourceChild.new("TestResource", nil) }
|
1206
|
+
|
1199
1207
|
it "returns original description when a described action is not overridden in child resource" do
|
1200
|
-
expect(
|
1208
|
+
expect(resource_inst.action_description(:base_action1)).to eq "unmodified base action 1 desc"
|
1201
1209
|
end
|
1202
1210
|
it "returns original description when the child resource overrides an inherited action but NOT its description" do
|
1203
|
-
expect(
|
1211
|
+
expect(resource_inst.action_description(:base_action3)).to eq "unmodified base action 3 desc"
|
1212
|
+
end
|
1213
|
+
it "returns new description when the child resource overrides an inherited action and its description" do
|
1214
|
+
expect(resource_inst.action_description(:base_action2)).to eq "modified base action 2 desc"
|
1204
1215
|
end
|
1205
1216
|
it "returns new description when the child resource overrides an inherited action and its description" do
|
1206
|
-
expect(
|
1217
|
+
expect(resource_inst.action_description(:base_action2)).to eq "modified base action 2 desc"
|
1207
1218
|
end
|
1208
1219
|
end
|
1209
1220
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Marc Paradise <marc@chef.io>
|
3
|
+
# Copyright:: Copyright (c) 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_relative "../../spec_helper"
|
20
|
+
require "chef/secret_fetcher/akeyless_vault"
|
21
|
+
|
22
|
+
describe Chef::SecretFetcher::AKeylessVault do
|
23
|
+
let(:node) { {} }
|
24
|
+
let(:run_context) { double("run_context", node: node) }
|
25
|
+
|
26
|
+
context "when validating provided AKeyless Vault configuration" do
|
27
|
+
it "raises ConfigurationInvalid when :secret_access_key is not provided" do
|
28
|
+
fetcher = Chef::SecretFetcher::AKeylessVault.new( { access_id: "provided" }, run_context)
|
29
|
+
expect { fetcher.validate! }.to raise_error(Chef::Exceptions::Secret::ConfigurationInvalid, /:secret_access_key/)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "raises ConfigurationInvalid when :access_key_id is not provided" do
|
33
|
+
fetcher = Chef::SecretFetcher::AKeylessVault.new( { access_key: "provided" }, run_context)
|
34
|
+
expect { fetcher.validate! }.to raise_error(Chef::Exceptions::Secret::ConfigurationInvalid, /:access_key_id/)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Marc Paradise <marc@chef.io>
|
3
|
+
# Copyright:: Copyright (c) Chef Software Inc.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
#
|
19
|
+
|
20
|
+
require_relative "../../spec_helper"
|
21
|
+
require "chef/secret_fetcher/aws_secrets_manager"
|
22
|
+
|
23
|
+
describe Chef::SecretFetcher::AWSSecretsManager do
|
24
|
+
let(:node) { {} }
|
25
|
+
let(:aws_global_config) { {} }
|
26
|
+
let(:fetcher_config) { {} }
|
27
|
+
let(:run_context) { double("run_context", node: node) }
|
28
|
+
let(:fetcher) {
|
29
|
+
Chef::SecretFetcher::AWSSecretsManager.new( fetcher_config, run_context )
|
30
|
+
}
|
31
|
+
|
32
|
+
before do
|
33
|
+
allow(Aws).to receive(:config).and_return(aws_global_config)
|
34
|
+
end
|
35
|
+
|
36
|
+
context "when region is provided" do
|
37
|
+
let(:fetcher_config) { { region: "region-from-caller" } }
|
38
|
+
it "uses the provided region" do
|
39
|
+
fetcher.validate!
|
40
|
+
expect(fetcher.config[:region]).to eq "region-from-caller"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context "when region is not provided" do
|
45
|
+
context "and no region exists in AWS config or node attributes" do
|
46
|
+
it "raises a ConfigurationInvalid error" do
|
47
|
+
expect { fetcher.validate! }.to raise_error Chef::Exceptions::Secret::ConfigurationInvalid
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context "and region exists in AWS config and node attributes" do
|
52
|
+
let(:aws_global_config) { { region: "region-from-aws-global-config" } }
|
53
|
+
let(:node) { { "ec2" => { "region" => "region-from-ohai-data" } } }
|
54
|
+
it "uses the region from AWS config" do
|
55
|
+
fetcher.validate!
|
56
|
+
expect(fetcher.config[:region]).to eq "region-from-aws-global-config"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context "and region exists only in node attributes" do
|
61
|
+
let(:node) { { "ec2" => { "region" => "region-from-ohai-data" } } }
|
62
|
+
it "uses the region from AWS config" do
|
63
|
+
fetcher.validate!
|
64
|
+
expect(fetcher.config[:region]).to eq "region-from-ohai-data"
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
|
2
|
+
#
|
3
|
+
# Author:: Marc Paradise <marc@chef.io>
|
4
|
+
# Copyright:: Copyright (c) Chef Software Inc.
|
5
|
+
# License:: Apache License, Version 2.0
|
6
|
+
#
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
# you may not use this file except in compliance with the License.
|
9
|
+
# You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
# See the License for the specific language governing permissions and
|
17
|
+
# limitations under the License.
|
18
|
+
#
|
19
|
+
|
20
|
+
require_relative "../../spec_helper"
|
21
|
+
require "chef/secret_fetcher"
|
22
|
+
require "chef/secret_fetcher/azure_key_vault"
|
23
|
+
|
24
|
+
describe Chef::SecretFetcher::AzureKeyVault do
|
25
|
+
let(:config) { { vault: "my_vault" } }
|
26
|
+
let(:fetcher) { Chef::SecretFetcher::AzureKeyVault.new(config, nil) }
|
27
|
+
|
28
|
+
context "when performing a fetch" do
|
29
|
+
let(:body) { '{ "value" : "my secret value" }' }
|
30
|
+
let(:response_mock) { double("response", body: body) }
|
31
|
+
let(:http_mock) { double("http", :get => response_mock, :use_ssl= => nil) }
|
32
|
+
|
33
|
+
before do
|
34
|
+
allow(fetcher).to receive(:fetch_token).and_return "a token"
|
35
|
+
allow(Net::HTTP).to receive(:new).and_return(http_mock)
|
36
|
+
end
|
37
|
+
|
38
|
+
context "and vault name is only provided in the secret name" do
|
39
|
+
let(:body) { '{ "value" : "my secret value" }' }
|
40
|
+
let(:config) { {} }
|
41
|
+
it "fetches the value" do
|
42
|
+
expect(fetcher.fetch("my_vault/value")).to eq "my secret value"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context "and vault name is not provided in the secret name" do
|
47
|
+
context "and vault name is not provided in config" do
|
48
|
+
let(:config) { {} }
|
49
|
+
it "raises a ConfigurationInvalid exception" do
|
50
|
+
expect { fetcher.fetch("value") }.to raise_error(Chef::Exceptions::Secret::ConfigurationInvalid)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context "and vault name is provided in config" do
|
55
|
+
let(:config) { { vault: "my_vault" } }
|
56
|
+
it "fetches the value" do
|
57
|
+
expect(fetcher.fetch("value")).to eq "my secret value"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
context "and an error response is received in the body" do
|
62
|
+
let(:config) { { vault: "my_vault" } }
|
63
|
+
let(:body) { '{ "error" : { "code" : 404, "message" : "secret not found" } }' }
|
64
|
+
it "raises FetchFailed" do
|
65
|
+
expect { fetcher.fetch("value") }.to raise_error(Chef::Exceptions::Secret::FetchFailed)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
@@ -0,0 +1,80 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Marc Paradise <marc@chef.io>
|
3
|
+
# Copyright:: Copyright (c) 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_relative "../../spec_helper"
|
20
|
+
require "chef/secret_fetcher/hashi_vault"
|
21
|
+
|
22
|
+
describe Chef::SecretFetcher::HashiVault do
|
23
|
+
let(:node) { {} }
|
24
|
+
let(:run_context) { double("run_context", node: node) }
|
25
|
+
|
26
|
+
context "when validating provided HashiVault configuration" do
|
27
|
+
it "raises ConfigurationInvalid when the :auth_method is not valid" do
|
28
|
+
fetcher = Chef::SecretFetcher::HashiVault.new( { auth_method: :invalid, vault_addr: "https://vault.example.com:8200" }, run_context)
|
29
|
+
expect { fetcher.validate! }.to raise_error(Chef::Exceptions::Secret::ConfigurationInvalid, /:auth_method/)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "raises ConfigurationInvalid when the vault_addr is not provided" do
|
33
|
+
fetcher = Chef::SecretFetcher::HashiVault.new( { auth_method: :iam_role, role_name: "example-role" }, run_context)
|
34
|
+
expect { fetcher.validate! }.to raise_error(Chef::Exceptions::Secret::ConfigurationInvalid)
|
35
|
+
end
|
36
|
+
|
37
|
+
context "and using auth_method: :iam_role" do
|
38
|
+
it "raises ConfigurationInvalid when the role_name is not provided" do
|
39
|
+
fetcher = Chef::SecretFetcher::HashiVault.new( { auth_method: :iam_role, vault_addr: "https://vault.example.com:8200" }, run_context)
|
40
|
+
expect { fetcher.validate! }.to raise_error(Chef::Exceptions::Secret::ConfigurationInvalid)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "obtains a token via AWS IAM auth to allow the gem to do its own validations when all required config is provided" do
|
44
|
+
fetcher = Chef::SecretFetcher::HashiVault.new( { auth_method: :iam_role, vault_addr: "https://vault.example.com:8200", role_name: "example-role" }, run_context)
|
45
|
+
allow(Aws::InstanceProfileCredentials).to receive(:new).and_return instance_double(Aws::InstanceProfileCredentials)
|
46
|
+
auth_double = instance_double(Vault::Authenticate)
|
47
|
+
expect(auth_double).to receive(:aws_iam)
|
48
|
+
allow(Vault).to receive(:auth).and_return(auth_double)
|
49
|
+
fetcher.validate!
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context "and using auth_method: :token" do
|
54
|
+
it "raises ConfigurationInvalid when no token is provided" do
|
55
|
+
fetcher = Chef::SecretFetcher::HashiVault.new( { auth_method: :token, vault_addr: "https://vault.example.com:8200" }, run_context)
|
56
|
+
expect { fetcher.validate! }.to raise_error(Chef::Exceptions::Secret::ConfigurationInvalid)
|
57
|
+
end
|
58
|
+
|
59
|
+
it "authenticates using the token during validation when all configuration is correct" do
|
60
|
+
fetcher = Chef::SecretFetcher::HashiVault.new( { auth_method: :token, token: "t.1234abcd", vault_addr: "https://vault.example.com:8200" }, run_context)
|
61
|
+
auth = instance_double(Vault::Authenticate)
|
62
|
+
auth_double = instance_double(Vault::Authenticate)
|
63
|
+
expect(auth_double).to receive(:token)
|
64
|
+
allow(Vault).to receive(:auth).and_return(auth_double)
|
65
|
+
fetcher.validate!
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
context "when fetching a secret from Hashi Vault" do
|
71
|
+
it "raises an FetchFailed message when no secret is returned due to invalid engine path" do
|
72
|
+
fetcher = Chef::SecretFetcher::HashiVault.new( { auth_method: :invalid, vault_addr: "https://vault.example.com:8200" }, run_context)
|
73
|
+
logical_double = instance_double(Vault::Logical)
|
74
|
+
expect(logical_double).to receive(:read).and_return nil
|
75
|
+
expect(Vault).to receive(:logical).and_return(logical_double)
|
76
|
+
expect { fetcher.do_fetch("anything", nil) }.to raise_error(Chef::Exceptions::Secret::FetchFailed)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|