chef 17.4.38-universal-mingw32 → 17.7.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 +5 -0
- data/chef.gemspec +3 -0
- data/lib/chef/application/base.rb +11 -1
- data/lib/chef/chef_fs/file_pattern.rb +1 -1
- data/lib/chef/chef_fs/path_utils.rb +1 -1
- data/lib/chef/client.rb +1 -2
- 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/runner.rb +47 -5
- data/lib/chef/compliance/waiver.rb +115 -0
- data/lib/chef/compliance/waiver_collection.rb +143 -0
- data/lib/chef/data_collector/run_end_message.rb +1 -1
- data/lib/chef/dsl/compliance.rb +38 -0
- data/lib/chef/dsl/reader_helpers.rb +51 -0
- data/lib/chef/dsl/reboot_pending.rb +1 -1
- data/lib/chef/dsl/recipe.rb +4 -2
- data/lib/chef/dsl/secret.rb +2 -4
- data/lib/chef/dsl/universal.rb +2 -0
- data/lib/chef/event_dispatch/base.rb +44 -2
- data/lib/chef/exceptions.rb +10 -0
- data/lib/chef/formatters/doc.rb +46 -0
- data/lib/chef/http/basic_client.rb +15 -7
- data/lib/chef/http.rb +7 -3
- data/lib/chef/provider/cron.rb +4 -1
- data/lib/chef/provider/file.rb +2 -0
- data/lib/chef/provider/git.rb +1 -1
- data/lib/chef/provider/ifconfig/debian.rb +1 -1
- data/lib/chef/provider/link.rb +2 -2
- 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 +5 -5
- data/lib/chef/provider/template.rb +1 -1
- data/lib/chef/resource/archive_file.rb +17 -14
- data/lib/chef/resource/chef_client_scheduled_task.rb +45 -2
- data/lib/chef/resource/chocolatey_config.rb +14 -14
- data/lib/chef/resource/chocolatey_feature.rb +1 -1
- data/lib/chef/resource/chocolatey_source.rb +24 -2
- data/lib/chef/resource/directory.rb +1 -1
- data/lib/chef/resource/file/verification/json.rb +50 -0
- data/lib/chef/resource/file/verification/yaml.rb +52 -0
- data/lib/chef/resource/habitat_install.rb +3 -3
- data/lib/chef/resource/inspec_input.rb +127 -0
- data/lib/chef/resource/inspec_waiver.rb +184 -0
- data/lib/chef/resource/inspec_waiver_file_entry.rb +1 -1
- data/lib/chef/resource/kernel_module.rb +27 -2
- data/lib/chef/resource/macos_userdefaults.rb +43 -128
- data/lib/chef/resource/mount.rb +1 -1
- data/lib/chef/resource/openssl_x509_certificate.rb +1 -1
- data/lib/chef/resource/powershell_package_source.rb +234 -70
- data/lib/chef/resource/registry_key.rb +36 -48
- data/lib/chef/resource/remote_file.rb +98 -2
- data/lib/chef/resource/timezone.rb +2 -2
- data/lib/chef/resource/user_ulimit.rb +1 -0
- data/lib/chef/resource/windows_auto_run.rb +1 -1
- data/lib/chef/resource/windows_dfs_namespace.rb +2 -2
- data/lib/chef/resource/windows_printer.rb +1 -1
- data/lib/chef/resource/windows_uac.rb +3 -1
- data/lib/chef/resource/windows_update_settings.rb +3 -3
- data/lib/chef/resource/windows_user_privilege.rb +1 -1
- data/lib/chef/resource.rb +1 -1
- data/lib/chef/resource_reporter.rb +1 -1
- data/lib/chef/resources.rb +2 -0
- 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 +1 -1
- data/lib/chef/secret_fetcher/azure_key_vault.rb +63 -9
- data/lib/chef/secret_fetcher/base.rb +1 -1
- data/lib/chef/secret_fetcher/hashi_vault.rb +100 -0
- data/lib/chef/secret_fetcher.rb +8 -3
- data/lib/chef/version.rb +1 -1
- data/lib/chef/win32/version.rb +2 -1
- data/spec/data/archive_file/test_archive.tar.gz +0 -0
- data/spec/functional/dsl/reboot_pending_spec.rb +3 -3
- data/spec/functional/dsl/registry_helper_spec.rb +1 -1
- data/spec/functional/resource/archive_file_spec.rb +87 -0
- data/spec/functional/resource/dsc_script_spec.rb +2 -2
- data/spec/functional/resource/group_spec.rb +5 -1
- data/spec/functional/resource/link_spec.rb +8 -0
- data/spec/functional/resource/macos_userdefaults_spec.rb +119 -0
- data/spec/functional/resource/powershell_package_source_spec.rb +5 -6
- data/spec/functional/resource/registry_spec.rb +81 -81
- data/spec/functional/win32/registry_spec.rb +8 -8
- data/spec/integration/compliance/compliance_spec.rb +60 -0
- 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/unit/compliance/input_spec.rb +104 -0
- data/spec/unit/compliance/profile_spec.rb +120 -0
- data/spec/unit/compliance/waiver_spec.rb +104 -0
- data/spec/unit/data_collector_spec.rb +24 -1
- data/spec/unit/dsl/reboot_pending_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/mixin/default_paths_spec.rb +1 -1
- data/spec/unit/mixin/securable_spec.rb +3 -3
- data/spec/unit/provider/cron_spec.rb +45 -0
- data/spec/unit/provider/link_spec.rb +13 -7
- data/spec/unit/provider/package/rubygems_spec.rb +5 -5
- data/spec/unit/provider/package/windows_spec.rb +1 -1
- data/spec/unit/provider/registry_key_spec.rb +4 -4
- data/spec/unit/provider/remote_file/http_spec.rb +10 -0
- data/spec/unit/provider/service/windows_spec.rb +5 -5
- data/spec/unit/provider/subversion_spec.rb +4 -4
- data/spec/unit/provider/template_spec.rb +2 -2
- data/spec/unit/provider/windows_env_spec.rb +1 -1
- data/spec/unit/provider/zypper_repository_spec.rb +1 -1
- 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/chocolatey_config_spec.rb +1 -1
- data/spec/unit/resource/chocolatey_feature_spec.rb +1 -1
- data/spec/unit/resource/chocolatey_source_spec.rb +1 -1
- 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/inspec_input_spec.rb +300 -0
- data/spec/unit/resource/inspec_waiver_spec.rb +312 -0
- data/spec/unit/resource/kernel_module_spec.rb +2 -1
- data/spec/unit/resource/macos_user_defaults_spec.rb +36 -96
- data/spec/unit/resource/mount_spec.rb +10 -0
- data/spec/unit/resource/powershell_package_source_spec.rb +63 -62
- data/spec/unit/resource/registry_key_spec.rb +10 -10
- data/spec/unit/resource/user_ulimit_spec.rb +14 -1
- data/spec/unit/resource/windows_auto_run_spec.rb +1 -1
- data/spec/unit/resource/windows_feature_powershell_spec.rb +1 -1
- data/spec/unit/resource/windows_firewall_rule_spec.rb +2 -2
- data/spec/unit/resource/windows_task_spec.rb +3 -3
- data/spec/unit/resource_reporter_spec.rb +2 -2
- data/spec/unit/resource_spec.rb +5 -0
- data/spec/unit/secret_fetcher/akeyless_vault_spec.rb +37 -0
- data/spec/unit/secret_fetcher/azure_key_vault_spec.rb +99 -20
- data/spec/unit/secret_fetcher/hashi_vault_spec.rb +80 -0
- data/spec/unit/util/backup_spec.rb +1 -1
- data/spec/unit/win32/registry_spec.rb +3 -3
- data/tasks/rspec.rb +2 -1
- metadata +75 -6
@@ -0,0 +1,51 @@
|
|
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
|
+
def add_libarchive_dll_directory
|
18
|
+
require "ruby_installer"
|
19
|
+
libarchive_paths = Dir.glob("{#{Gem.dir},C:/hab}/**/libarchive.dll").map { |f| File.expand_path(f) }
|
20
|
+
if libarchive_paths.empty?
|
21
|
+
$stderr.puts <<~EOL
|
22
|
+
!!!!
|
23
|
+
We couldn't find a libarchive.dll in #{Gem.dir} or C:/hab
|
24
|
+
|
25
|
+
If this is running in a CI/CD environment, this may end up causing failures
|
26
|
+
in the tests for archive_file. If this is not running in a CI/CD
|
27
|
+
environment then it may be safe to ignore this. That is especially true if
|
28
|
+
you're not using the Ruby Installer as your Ruby runtime.
|
29
|
+
!!!!
|
30
|
+
EOL
|
31
|
+
return
|
32
|
+
end
|
33
|
+
|
34
|
+
$stderr.puts "\nFound the following libarchive paths:\n\n#{libarchive_paths.map { |f| "- #{f}\n" }.join}\n\n"
|
35
|
+
libarchive_path = libarchive_paths.first
|
36
|
+
libarchive_dir = File.dirname(libarchive_path)
|
37
|
+
|
38
|
+
if defined?(RubyInstaller::Build) && RubyInstaller::Build.methods.include?(:add_dll_directory)
|
39
|
+
$stderr.puts "Adding #{libarchive_dir} as a DLL load path using RubyInstaller::Build#add_dll_directory"
|
40
|
+
RubyInstaller::Build.add_dll_directory(libarchive_dir)
|
41
|
+
elsif defined?(RubyInstaller::Runtime) && RubyInstaller::Runtime.methods.include?(:add_dll_directory)
|
42
|
+
$stderr.puts "Adding #{libarchive_dir} as a DLL load path using RubyInstaller::Runtime#add_dll_directory"
|
43
|
+
RubyInstaller::Runtime.add_dll_directory(libarchive_dir)
|
44
|
+
else
|
45
|
+
$stderr.puts "Unable to find the right namespace to call #add_dll_directory! Please raise an issue on [GitHub](https://github.com/chef/chef/issues/new/choose)."
|
46
|
+
end
|
47
|
+
rescue LoadError
|
48
|
+
$stderr.puts "Failed to load ruby_installer. Assuming Ruby Installer is not being used."
|
49
|
+
end
|
50
|
+
|
51
|
+
add_libarchive_dll_directory if RUBY_PLATFORM =~ /mswin|mingw32|windows/
|
@@ -0,0 +1,104 @@
|
|
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
|
+
require "tempfile"
|
20
|
+
|
21
|
+
describe Chef::Compliance::Input do
|
22
|
+
let(:events) { Chef::EventDispatch::Dispatcher.new }
|
23
|
+
let(:data) { { "ssh-01" => { "expiration_date" => Date.jd(2463810), "justification" => "waived, yo", "run" => false } } }
|
24
|
+
let(:path) { "/var/chef/cache/cookbooks/acme_compliance/compliance/inputs/default.yml" }
|
25
|
+
let(:cookbook_name) { "acme_compliance" }
|
26
|
+
let(:input) { Chef::Compliance::Input.new(events, data, path, cookbook_name) }
|
27
|
+
|
28
|
+
it "has a cookbook_name" do
|
29
|
+
expect(input.cookbook_name).to eql(cookbook_name)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "has a path" do
|
33
|
+
expect(input.path).to eql(path)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "has a pathname based on the path" do
|
37
|
+
expect(input.pathname).to eql("default")
|
38
|
+
end
|
39
|
+
|
40
|
+
it "is disabled" do
|
41
|
+
expect(input.enabled).to eql(false)
|
42
|
+
expect(input.enabled?).to eql(false)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "has an event handler" do
|
46
|
+
expect(input.events).to eql(events)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "can be enabled by enable!" do
|
50
|
+
input.enable!
|
51
|
+
expect(input.enabled).to eql(true)
|
52
|
+
expect(input.enabled?).to eql(true)
|
53
|
+
end
|
54
|
+
|
55
|
+
it "enabling sends an event" do
|
56
|
+
expect(events).to receive(:compliance_input_enabled).with(input)
|
57
|
+
input.enable!
|
58
|
+
end
|
59
|
+
|
60
|
+
it "can be disabled by disable!" do
|
61
|
+
input.enable!
|
62
|
+
input.disable!
|
63
|
+
expect(input.enabled).to eql(false)
|
64
|
+
expect(input.enabled?).to eql(false)
|
65
|
+
end
|
66
|
+
|
67
|
+
it "has a #inspec_data method that renders the data" do
|
68
|
+
expect(input.inspec_data).to eql(data)
|
69
|
+
end
|
70
|
+
|
71
|
+
it "doesn't render the events in the inspect output" do
|
72
|
+
expect(input.inspect).not_to include("events")
|
73
|
+
end
|
74
|
+
|
75
|
+
it "inflates objects from YAML" do
|
76
|
+
string = <<~EOH
|
77
|
+
ssh-01:
|
78
|
+
expiration_date: 2033-07-31
|
79
|
+
run: false
|
80
|
+
justification: "waived, yo"
|
81
|
+
EOH
|
82
|
+
newinput = Chef::Compliance::Input.from_yaml(events, string, path, cookbook_name)
|
83
|
+
expect(newinput.data).to eql(data)
|
84
|
+
end
|
85
|
+
|
86
|
+
it "inflates objects from files" do
|
87
|
+
string = <<~EOH
|
88
|
+
ssh-01:
|
89
|
+
expiration_date: 2033-07-31
|
90
|
+
run: false
|
91
|
+
justification: "waived, yo"
|
92
|
+
EOH
|
93
|
+
tempfile = Tempfile.new("chef-compliance-test")
|
94
|
+
tempfile.write string
|
95
|
+
tempfile.close
|
96
|
+
newinput = Chef::Compliance::Input.from_file(events, tempfile.path, cookbook_name)
|
97
|
+
expect(newinput.data).to eql(data)
|
98
|
+
end
|
99
|
+
|
100
|
+
it "inflates objects from hashes" do
|
101
|
+
newinput = Chef::Compliance::Input.from_hash(events, data, path, cookbook_name)
|
102
|
+
expect(newinput.data).to eql(data)
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,120 @@
|
|
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
|
+
require "tempfile"
|
20
|
+
|
21
|
+
describe Chef::Compliance::Profile do
|
22
|
+
let(:events) { Chef::EventDispatch::Dispatcher.new }
|
23
|
+
let(:data) { { "copyright" => "DevSec Hardening Framework Team", "copyright_email" => "hello@dev-sec.io", "license" => "Apache-2.0", "maintainer" => "DevSec Hardening Framework Team", "name" => "ssh-baseline", "summary" => "Test-suite for best-practice SSH hardening", "supports" => [{ "os-family" => "unix" }], "title" => "DevSec SSH Baseline", "version" => "2.6.4" } }
|
24
|
+
let(:path) { "/var/chef/cache/cookbooks/acme_compliance/compliance/profiles/thisdirectoryisnotthename/inspec.yml" }
|
25
|
+
let(:cookbook_name) { "acme_compliance" }
|
26
|
+
let(:profile) { Chef::Compliance::Profile.new(events, data, path, cookbook_name) }
|
27
|
+
|
28
|
+
it "has a cookbook_name" do
|
29
|
+
expect(profile.cookbook_name).to eql(cookbook_name)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "has a path" do
|
33
|
+
expect(profile.path).to eql(path)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "has a name based on the yml" do
|
37
|
+
expect(profile.name).to eql("ssh-baseline")
|
38
|
+
end
|
39
|
+
|
40
|
+
it "has a pathname based on the path" do
|
41
|
+
expect(profile.pathname).to eql("thisdirectoryisnotthename")
|
42
|
+
end
|
43
|
+
|
44
|
+
it "is disabled" do
|
45
|
+
expect(profile.enabled).to eql(false)
|
46
|
+
expect(profile.enabled?).to eql(false)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "has an event handler" do
|
50
|
+
expect(profile.events).to eql(events)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "can be enabled by enable!" do
|
54
|
+
profile.enable!
|
55
|
+
expect(profile.enabled).to eql(true)
|
56
|
+
expect(profile.enabled?).to eql(true)
|
57
|
+
end
|
58
|
+
|
59
|
+
it "enabling sends an event" do
|
60
|
+
expect(events).to receive(:compliance_profile_enabled).with(profile)
|
61
|
+
profile.enable!
|
62
|
+
end
|
63
|
+
|
64
|
+
it "can be disabled by disable!" do
|
65
|
+
profile.enable!
|
66
|
+
profile.disable!
|
67
|
+
expect(profile.enabled).to eql(false)
|
68
|
+
expect(profile.enabled?).to eql(false)
|
69
|
+
end
|
70
|
+
|
71
|
+
it "has a #inspec_data method that renders the path" do
|
72
|
+
expect(profile.inspec_data).to eql( { name: "ssh-baseline", path: "/var/chef/cache/cookbooks/acme_compliance/compliance/profiles/thisdirectoryisnotthename" } )
|
73
|
+
end
|
74
|
+
|
75
|
+
it "doesn't render the events in the inspect output" do
|
76
|
+
expect(profile.inspect).not_to include("events")
|
77
|
+
end
|
78
|
+
|
79
|
+
it "inflates objects from YAML" do
|
80
|
+
string = <<~EOH
|
81
|
+
name: ssh-baseline#{" "}
|
82
|
+
title: DevSec SSH Baseline#{" "}
|
83
|
+
maintainer: DevSec Hardening Framework Team#{" "}
|
84
|
+
copyright: DevSec Hardening Framework Team#{" "}
|
85
|
+
copyright_email: hello@dev-sec.io#{" "}
|
86
|
+
license: Apache-2.0#{" "}
|
87
|
+
summary: Test-suite for best-practice SSH hardening#{" "}
|
88
|
+
version: 2.6.4#{" "}
|
89
|
+
supports:#{" "}
|
90
|
+
- os-family: unix
|
91
|
+
EOH
|
92
|
+
newprofile = Chef::Compliance::Profile.from_yaml(events, string, path, cookbook_name)
|
93
|
+
expect(newprofile.data).to eql(data)
|
94
|
+
end
|
95
|
+
|
96
|
+
it "inflates objects from files" do
|
97
|
+
string = <<~EOH
|
98
|
+
name: ssh-baseline#{" "}
|
99
|
+
title: DevSec SSH Baseline#{" "}
|
100
|
+
maintainer: DevSec Hardening Framework Team#{" "}
|
101
|
+
copyright: DevSec Hardening Framework Team#{" "}
|
102
|
+
copyright_email: hello@dev-sec.io#{" "}
|
103
|
+
license: Apache-2.0#{" "}
|
104
|
+
summary: Test-suite for best-practice SSH hardening#{" "}
|
105
|
+
version: 2.6.4#{" "}
|
106
|
+
supports:#{" "}
|
107
|
+
- os-family: unix
|
108
|
+
EOH
|
109
|
+
tempfile = Tempfile.new("chef-compliance-test")
|
110
|
+
tempfile.write string
|
111
|
+
tempfile.close
|
112
|
+
newprofile = Chef::Compliance::Profile.from_file(events, tempfile.path, cookbook_name)
|
113
|
+
expect(newprofile.data).to eql(data)
|
114
|
+
end
|
115
|
+
|
116
|
+
it "inflates objects from hashes" do
|
117
|
+
newprofile = Chef::Compliance::Profile.from_hash(events, data, path, cookbook_name)
|
118
|
+
expect(newprofile.data).to eql(data)
|
119
|
+
end
|
120
|
+
end
|
@@ -0,0 +1,104 @@
|
|
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
|
+
require "tempfile"
|
20
|
+
|
21
|
+
describe Chef::Compliance::Waiver do
|
22
|
+
let(:events) { Chef::EventDispatch::Dispatcher.new }
|
23
|
+
let(:data) { { "ssh-01" => { "expiration_date" => Date.jd(2463810), "justification" => "waived, yo", "run" => false } } }
|
24
|
+
let(:path) { "/var/chef/cache/cookbooks/acme_compliance/compliance/waivers/default.yml" }
|
25
|
+
let(:cookbook_name) { "acme_compliance" }
|
26
|
+
let(:waiver) { Chef::Compliance::Waiver.new(events, data, path, cookbook_name) }
|
27
|
+
|
28
|
+
it "has a cookbook_name" do
|
29
|
+
expect(waiver.cookbook_name).to eql(cookbook_name)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "has a path" do
|
33
|
+
expect(waiver.path).to eql(path)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "has a pathname based on the path" do
|
37
|
+
expect(waiver.pathname).to eql("default")
|
38
|
+
end
|
39
|
+
|
40
|
+
it "is disabled" do
|
41
|
+
expect(waiver.enabled).to eql(false)
|
42
|
+
expect(waiver.enabled?).to eql(false)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "has an event handler" do
|
46
|
+
expect(waiver.events).to eql(events)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "can be enabled by enable!" do
|
50
|
+
waiver.enable!
|
51
|
+
expect(waiver.enabled).to eql(true)
|
52
|
+
expect(waiver.enabled?).to eql(true)
|
53
|
+
end
|
54
|
+
|
55
|
+
it "enabling sends an event" do
|
56
|
+
expect(events).to receive(:compliance_waiver_enabled).with(waiver)
|
57
|
+
waiver.enable!
|
58
|
+
end
|
59
|
+
|
60
|
+
it "can be disabled by disable!" do
|
61
|
+
waiver.enable!
|
62
|
+
waiver.disable!
|
63
|
+
expect(waiver.enabled).to eql(false)
|
64
|
+
expect(waiver.enabled?).to eql(false)
|
65
|
+
end
|
66
|
+
|
67
|
+
it "has a #inspec_data method that renders the data" do
|
68
|
+
expect(waiver.inspec_data).to eql(data)
|
69
|
+
end
|
70
|
+
|
71
|
+
it "doesn't render the events in the inspect output" do
|
72
|
+
expect(waiver.inspect).not_to include("events")
|
73
|
+
end
|
74
|
+
|
75
|
+
it "inflates objects from YAML" do
|
76
|
+
string = <<~EOH
|
77
|
+
ssh-01:
|
78
|
+
expiration_date: 2033-07-31
|
79
|
+
run: false
|
80
|
+
justification: "waived, yo"
|
81
|
+
EOH
|
82
|
+
newwaiver = Chef::Compliance::Waiver.from_yaml(events, string, path, cookbook_name)
|
83
|
+
expect(newwaiver.data).to eql(data)
|
84
|
+
end
|
85
|
+
|
86
|
+
it "inflates objects from files" do
|
87
|
+
string = <<~EOH
|
88
|
+
ssh-01:
|
89
|
+
expiration_date: 2033-07-31
|
90
|
+
run: false
|
91
|
+
justification: "waived, yo"
|
92
|
+
EOH
|
93
|
+
tempfile = Tempfile.new("chef-compliance-test")
|
94
|
+
tempfile.write string
|
95
|
+
tempfile.close
|
96
|
+
newwaiver = Chef::Compliance::Waiver.from_file(events, tempfile.path, cookbook_name)
|
97
|
+
expect(newwaiver.data).to eql(data)
|
98
|
+
end
|
99
|
+
|
100
|
+
it "inflates objects from hashes" do
|
101
|
+
newwaiver = Chef::Compliance::Waiver.from_hash(events, data, path, cookbook_name)
|
102
|
+
expect(newwaiver.data).to eql(data)
|
103
|
+
end
|
104
|
+
end
|
@@ -164,7 +164,7 @@ describe Chef::DataCollector do
|
|
164
164
|
"after" => after_resource&.state_for_resource_reporter || {},
|
165
165
|
"before" => before_resource&.state_for_resource_reporter || {},
|
166
166
|
"cookbook_name" => cookbook_name,
|
167
|
-
"cookbook_version" => cookbook_version
|
167
|
+
"cookbook_version" => cookbook_version&.version,
|
168
168
|
"delta" => resource_has_diff(new_resource, status) ? new_resource.diff : "",
|
169
169
|
"duration" => duration,
|
170
170
|
"id" => new_resource.identity,
|
@@ -567,6 +567,29 @@ describe Chef::DataCollector do
|
|
567
567
|
it_behaves_like "sends a converge message"
|
568
568
|
end
|
569
569
|
|
570
|
+
context "when the run contains a file resource that is up-to-date from a @recipe_files, returns nil for the version" do
|
571
|
+
let(:total_resource_count) { 1 }
|
572
|
+
let(:updated_resource_count) { 0 }
|
573
|
+
let(:cookbook_name) { "@recipe_files" }
|
574
|
+
let(:resource_record) { [ resource_record_for(new_resource, current_resource, after_resource, :create, "up-to-date", "1234") ] }
|
575
|
+
let(:status) { "success" }
|
576
|
+
let(:cookbook_version) { nil }
|
577
|
+
|
578
|
+
before do
|
579
|
+
allow(new_resource).to receive(:cookbook_version).and_call_original
|
580
|
+
events.resource_action_start(new_resource, :create)
|
581
|
+
events.resource_current_state_loaded(new_resource, :create, current_resource)
|
582
|
+
events.resource_up_to_date(new_resource, :create)
|
583
|
+
events.resource_after_state_loaded(new_resource, :create, after_resource)
|
584
|
+
new_resource.instance_variable_set(:@elapsed_time, 1.2345)
|
585
|
+
events.resource_completed(new_resource)
|
586
|
+
events.converge_complete
|
587
|
+
run_status.stop_clock
|
588
|
+
end
|
589
|
+
|
590
|
+
it_behaves_like "sends a converge message"
|
591
|
+
end
|
592
|
+
|
570
593
|
context "when the run contains a file resource that is updated" do
|
571
594
|
let(:total_resource_count) { 1 }
|
572
595
|
let(:updated_resource_count) { 1 }
|
@@ -36,7 +36,7 @@ describe Chef::DSL::RebootPending do
|
|
36
36
|
end
|
37
37
|
|
38
38
|
it 'should return true if "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\PendingFileRenameOperations" exists' do
|
39
|
-
allow(recipe).to receive(:registry_value_exists?).with(
|
39
|
+
allow(recipe).to receive(:registry_value_exists?).with("HKLM\\SYSTEM\\CurrentControlSet\\Control\\Session Manager", { name: "PendingFileRenameOperations" }).and_return(true)
|
40
40
|
expect(recipe.reboot_pending?).to be_truthy
|
41
41
|
end
|
42
42
|
|
@@ -47,6 +47,36 @@ describe "HTTP Connection" do
|
|
47
47
|
expect(Net::HTTP).to receive(:new).and_return(net_http_mock)
|
48
48
|
expect(basic_client.http_client).to eql(net_http_mock)
|
49
49
|
end
|
50
|
+
|
51
|
+
it "allows setting net-http accessor options" do
|
52
|
+
basic_client = Chef::HTTP::BasicClient.new(uri, nethttp_opts: {
|
53
|
+
"continue_timeout" => 5,
|
54
|
+
"max_retries" => 5,
|
55
|
+
"read_timeout" => 5,
|
56
|
+
"write_timeout" => 5,
|
57
|
+
"ssl_timeout" => 5,
|
58
|
+
})
|
59
|
+
expect(basic_client.http_client.continue_timeout).to eql(5)
|
60
|
+
expect(basic_client.http_client.max_retries).to eql(5)
|
61
|
+
expect(basic_client.http_client.read_timeout).to eql(5)
|
62
|
+
expect(basic_client.http_client.write_timeout).to eql(5)
|
63
|
+
expect(basic_client.http_client.ssl_timeout).to eql(5)
|
64
|
+
end
|
65
|
+
|
66
|
+
it "allows setting net-http accssor options as symbols" do
|
67
|
+
basic_client = Chef::HTTP::BasicClient.new(uri, nethttp_opts: {
|
68
|
+
continue_timeout: 5,
|
69
|
+
max_retries: 5,
|
70
|
+
read_timeout: 5,
|
71
|
+
write_timeout: 5,
|
72
|
+
ssl_timeout: 5,
|
73
|
+
})
|
74
|
+
expect(basic_client.http_client.continue_timeout).to eql(5)
|
75
|
+
expect(basic_client.http_client.max_retries).to eql(5)
|
76
|
+
expect(basic_client.http_client.read_timeout).to eql(5)
|
77
|
+
expect(basic_client.http_client.write_timeout).to eql(5)
|
78
|
+
expect(basic_client.http_client.ssl_timeout).to eql(5)
|
79
|
+
end
|
50
80
|
end
|
51
81
|
|
52
82
|
describe "#build_http_client" do
|
data/spec/unit/http_spec.rb
CHANGED
@@ -46,13 +46,19 @@ describe Chef::HTTP do
|
|
46
46
|
describe "#initialize" do
|
47
47
|
it "accepts a keepalive option and passes it to the http_client" do
|
48
48
|
http = Chef::HTTP.new(uri, keepalives: true)
|
49
|
-
expect(Chef::HTTP::BasicClient).to receive(:new).with(uri, ssl_policy: Chef::HTTP::APISSLPolicy, keepalives: true).and_call_original
|
49
|
+
expect(Chef::HTTP::BasicClient).to receive(:new).with(uri, ssl_policy: Chef::HTTP::APISSLPolicy, nethttp_opts: {}, keepalives: true).and_call_original
|
50
50
|
expect(http.http_client).to be_a_kind_of(Chef::HTTP::BasicClient)
|
51
51
|
end
|
52
52
|
|
53
53
|
it "the default is not to use keepalives" do
|
54
54
|
http = Chef::HTTP.new(uri)
|
55
|
-
expect(Chef::HTTP::BasicClient).to receive(:new).with(uri, ssl_policy: Chef::HTTP::APISSLPolicy, keepalives: false).and_call_original
|
55
|
+
expect(Chef::HTTP::BasicClient).to receive(:new).with(uri, ssl_policy: Chef::HTTP::APISSLPolicy, nethttp_opts: {}, keepalives: false).and_call_original
|
56
|
+
expect(http.http_client).to be_a_kind_of(Chef::HTTP::BasicClient)
|
57
|
+
end
|
58
|
+
|
59
|
+
it "allows setting the nethttp options hash" do
|
60
|
+
http = Chef::HTTP.new(uri, { nethttp: { "continue_timeout" => 5 } })
|
61
|
+
expect(Chef::HTTP::BasicClient).to receive(:new).with(uri, ssl_policy: Chef::HTTP::APISSLPolicy, nethttp_opts: { "continue_timeout" => 5 }, keepalives: false).and_call_original
|
56
62
|
expect(http.http_client).to be_a_kind_of(Chef::HTTP::BasicClient)
|
57
63
|
end
|
58
64
|
end
|
@@ -84,7 +84,7 @@ describe Chef::Mixin::DefaultPaths do
|
|
84
84
|
allow(Gem).to receive(:bindir).and_return(gem_bindir)
|
85
85
|
allow(RbConfig::CONFIG).to receive(:[]).with("bindir").and_return(ruby_bindir)
|
86
86
|
allow(ChefUtils).to receive(:windows?).and_return(true)
|
87
|
-
env = { "PATH" =>
|
87
|
+
env = { "PATH" => "C:\\Windows\\system32;C:\\mr\\softie" }
|
88
88
|
@default_paths.enforce_default_paths(env)
|
89
89
|
expect(env["PATH"]).to eq("#{gem_bindir};#{ruby_bindir};C:\\Windows\\system32;C:\\mr\\softie")
|
90
90
|
end
|
@@ -53,8 +53,8 @@ describe Chef::Mixin::Securable do
|
|
53
53
|
end
|
54
54
|
|
55
55
|
it "should accept group/owner names with spaces and backslashes" do
|
56
|
-
expect { @securable.group
|
57
|
-
expect { @securable.owner
|
56
|
+
expect { @securable.group "test\\ group" }.not_to raise_error
|
57
|
+
expect { @securable.owner "test\\ group" }.not_to raise_error
|
58
58
|
end
|
59
59
|
|
60
60
|
it "should accept group/owner names that are a single character or digit" do
|
@@ -186,7 +186,7 @@ describe Chef::Mixin::Securable do
|
|
186
186
|
end
|
187
187
|
|
188
188
|
it "should not accept a group name or id for group with spaces and multiple backslashes" do
|
189
|
-
expect { @securable.group
|
189
|
+
expect { @securable.group "test\\ \\group" }.to raise_error(ArgumentError)
|
190
190
|
end
|
191
191
|
|
192
192
|
it "should accept a unix file mode in string form as an octal number" do
|
@@ -392,6 +392,27 @@ describe Chef::Provider::Cron do
|
|
392
392
|
expect(cron.command).to eq("/bin/true")
|
393
393
|
end
|
394
394
|
end
|
395
|
+
|
396
|
+
context "with a matching entry with a commented crontab line" do
|
397
|
+
it "should set cron_exists" do
|
398
|
+
allow(@provider).to receive(:read_crontab).and_return(<<~CRONTAB)
|
399
|
+
0 2 * * * /some/other/command
|
400
|
+
|
401
|
+
# Chef Name: cronhole some stuff
|
402
|
+
#* * * * * /bin/true
|
403
|
+
CRONTAB
|
404
|
+
cron = @provider.load_current_resource
|
405
|
+
expect(@provider.cron_exists).to eq(true)
|
406
|
+
expect(@provider.cron_empty).to eq(false)
|
407
|
+
expect(cron.minute).to eq("*")
|
408
|
+
expect(cron.hour).to eq("*")
|
409
|
+
expect(cron.day).to eq("*")
|
410
|
+
expect(cron.month).to eq("*")
|
411
|
+
expect(cron.weekday).to eq("*")
|
412
|
+
expect(cron.time).to eq(nil)
|
413
|
+
expect(cron.property_is_set?(:command)).to eq(false)
|
414
|
+
end
|
415
|
+
end
|
395
416
|
end
|
396
417
|
|
397
418
|
describe "cron_different?" do
|
@@ -691,6 +712,30 @@ describe Chef::Provider::Cron do
|
|
691
712
|
end
|
692
713
|
end
|
693
714
|
|
715
|
+
context "when there is a crontab with a matching section with a commented crontab line in it" do
|
716
|
+
before :each do
|
717
|
+
@provider.cron_exists = true
|
718
|
+
end
|
719
|
+
|
720
|
+
it "should add the crontab to the entry" do
|
721
|
+
allow(@provider).to receive(:read_crontab).and_return(<<~CRONTAB)
|
722
|
+
0 2 * * * /some/other/command
|
723
|
+
|
724
|
+
# Chef Name: cronhole some stuff
|
725
|
+
# * * * * * /bin/true
|
726
|
+
CRONTAB
|
727
|
+
expect(@provider).to receive(:write_crontab).with(<<~ENDCRON)
|
728
|
+
0 2 * * * /some/other/command
|
729
|
+
|
730
|
+
# Chef Name: cronhole some stuff
|
731
|
+
* * * * * /bin/true
|
732
|
+
# * * * * * /bin/true
|
733
|
+
ENDCRON
|
734
|
+
@new_resource.minute "*"
|
735
|
+
@provider.run_action(:create)
|
736
|
+
end
|
737
|
+
end
|
738
|
+
|
694
739
|
context "when there is a crontab with a matching and identical section" do
|
695
740
|
context "when environment variable is not used" do
|
696
741
|
before :each do
|
@@ -125,7 +125,7 @@ describe Chef::Resource::Link do
|
|
125
125
|
|
126
126
|
describe "when the target doesn't exist" do
|
127
127
|
before do
|
128
|
-
allow(File).to receive(:
|
128
|
+
allow(File).to receive(:exist?).with("#{CHEF_SPEC_DATA}/fofile-link").and_return(false)
|
129
129
|
allow(provider.file_class).to receive(:symlink?).with("#{CHEF_SPEC_DATA}/fofile-link").and_return(false)
|
130
130
|
provider.load_current_resource
|
131
131
|
end
|
@@ -152,13 +152,16 @@ describe Chef::Resource::Link do
|
|
152
152
|
allow(stat).to receive(:mode).and_return(0755)
|
153
153
|
allow(provider.file_class).to receive(:stat).with("#{CHEF_SPEC_DATA}/fofile-link").and_return(stat)
|
154
154
|
|
155
|
-
|
155
|
+
# XXX: this might be broken? it preserves prior behavior in the specs caused by File.exist?/exists? interactions
|
156
|
+
allow(Chef::ScanAccessControl).to receive(:new).and_return(instance_double(Chef::ScanAccessControl, set_all!: nil))
|
157
|
+
|
158
|
+
allow(File).to receive(:exist?).with("#{CHEF_SPEC_DATA}/fofile-link").and_return(true)
|
156
159
|
allow(provider.file_class).to receive(:symlink?).with("#{CHEF_SPEC_DATA}/fofile-link").and_return(false)
|
157
160
|
end
|
158
161
|
|
159
162
|
describe "and the source does not exist" do
|
160
163
|
before do
|
161
|
-
|
164
|
+
expect(File).to receive(:exist?).with("#{CHEF_SPEC_DATA}/fofile").and_return(false)
|
162
165
|
provider.load_current_resource
|
163
166
|
end
|
164
167
|
|
@@ -185,7 +188,7 @@ describe Chef::Resource::Link do
|
|
185
188
|
|
186
189
|
allow(provider.file_class).to receive(:stat).with("#{CHEF_SPEC_DATA}/fofile").and_return(stat)
|
187
190
|
|
188
|
-
allow(File).to receive(:
|
191
|
+
allow(File).to receive(:exist?).with("#{CHEF_SPEC_DATA}/fofile").and_return(true)
|
189
192
|
provider.load_current_resource
|
190
193
|
end
|
191
194
|
|
@@ -212,7 +215,7 @@ describe Chef::Resource::Link do
|
|
212
215
|
|
213
216
|
allow(provider.file_class).to receive(:stat).with("#{CHEF_SPEC_DATA}/fofile").and_return(stat)
|
214
217
|
|
215
|
-
allow(File).to receive(:
|
218
|
+
allow(File).to receive(:exist?).with("#{CHEF_SPEC_DATA}/fofile").and_return(true)
|
216
219
|
provider.load_current_resource
|
217
220
|
end
|
218
221
|
|
@@ -262,6 +265,9 @@ describe Chef::Resource::Link do
|
|
262
265
|
"#{CHEF_SPEC_DATA}/fofile-link"
|
263
266
|
).and_return(stat)
|
264
267
|
|
268
|
+
# XXX: this might be broken? it preserves prior behavior in the specs caused by File.exist?/exists? interactions
|
269
|
+
allow(Chef::ScanAccessControl).to receive(:new).and_return(instance_double(Chef::ScanAccessControl, set_all!: nil))
|
270
|
+
|
265
271
|
provider.load_current_resource
|
266
272
|
end
|
267
273
|
|
@@ -336,10 +342,10 @@ describe Chef::Resource::Link do
|
|
336
342
|
"#{CHEF_SPEC_DATA}/fofile-link"
|
337
343
|
).and_return(false)
|
338
344
|
|
339
|
-
allow(File).to receive(:
|
345
|
+
allow(File).to receive(:exist?).with(
|
340
346
|
"#{CHEF_SPEC_DATA}/fofile-link"
|
341
347
|
).and_return(true)
|
342
|
-
allow(File).to receive(:
|
348
|
+
allow(File).to receive(:exist?).with(
|
343
349
|
"#{CHEF_SPEC_DATA}/fofile"
|
344
350
|
).and_return(true)
|
345
351
|
|
@@ -503,11 +503,11 @@ describe Chef::Provider::Package::Rubygems do
|
|
503
503
|
platform_mock :windows do
|
504
504
|
allow(ENV).to receive(:[]).with("PATH").and_return('C:\windows\system32;C:\windows;C:\Ruby186\bin')
|
505
505
|
allow(ENV).to receive(:[]).with("PATHEXT").and_return(nil)
|
506
|
-
allow(File).to receive(:executable?).with(
|
507
|
-
allow(File).to receive(:executable?).with(
|
508
|
-
allow(File).to receive(:executable?).with(
|
509
|
-
allow(File).to receive(:executable?).with(
|
510
|
-
allow(File).to receive(:executable?).with(
|
506
|
+
allow(File).to receive(:executable?).with("C:\\windows\\system32/gem").and_return(false)
|
507
|
+
allow(File).to receive(:executable?).with("C:\\windows/gem").and_return(false)
|
508
|
+
allow(File).to receive(:executable?).with("C:\\Ruby186\\bin/gem").and_return(true)
|
509
|
+
allow(File).to receive(:executable?).with("d:\\opscode\\chef\\bin/gem").and_return(false) # should not get here
|
510
|
+
allow(File).to receive(:executable?).with("d:\\opscode\\chef\\bin/gem").and_return(false) # should not get here
|
511
511
|
allow(File).to receive(:executable?).with("d:/opscode/chef/embedded/bin/gem").and_return(false) # should not get here
|
512
512
|
expect(provider.gem_env.gem_binary_location).to eq('C:\Ruby186\bin/gem')
|
513
513
|
end
|