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
@@ -0,0 +1,100 @@
|
|
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 "base"
|
20
|
+
require "aws-sdk-core" # Support for aws instance profile auth
|
21
|
+
require "vault"
|
22
|
+
class Chef
|
23
|
+
class SecretFetcher
|
24
|
+
# == Chef::SecretFetcher::HashiVault
|
25
|
+
# A fetcher that fetches a secret from Hashi Vault.
|
26
|
+
#
|
27
|
+
# Does not yet support fetching with version when a versioned key store is in use.
|
28
|
+
# In this initial iteration the only supported authentication is IAM role-based
|
29
|
+
#
|
30
|
+
# Required config:
|
31
|
+
# :auth_method - one of :iam_role, :token. default: :iam_role
|
32
|
+
# :vault_addr - the address of a running Vault instance, eg https://vault.example.com:8200
|
33
|
+
#
|
34
|
+
# For `:token` auth: `:token` - a Vault token valid for authentication.
|
35
|
+
#
|
36
|
+
# For `:iam_role`: `:role_name` - the name of the role in Vault that was created
|
37
|
+
# to support authentication via IAM. See the Vault documentation for details[1].
|
38
|
+
# A Terraform example is also available[2]
|
39
|
+
#
|
40
|
+
#
|
41
|
+
# [1] https://www.vaultproject.io/docs/auth/aws#recommended-vault-iam-policy
|
42
|
+
# [2] https://registry.terraform.io/modules/hashicorp/vault/aws/latest/examples/vault-iam-auth
|
43
|
+
# an IAM principal ARN bound to it.
|
44
|
+
#
|
45
|
+
# Optional config
|
46
|
+
# :namespace - the namespace under which secrets are kept. Only supported in with Vault Enterprise
|
47
|
+
#
|
48
|
+
# @example
|
49
|
+
#
|
50
|
+
# fetcher = SecretFetcher.for_service(:hashi_vault, { role_name: "testing-role", vault_addr: https://localhost:8200}, run_context )
|
51
|
+
# fetcher.fetch("secretkey1")
|
52
|
+
#
|
53
|
+
# @example
|
54
|
+
#
|
55
|
+
# fetcher = SecretFetcher.for_service(:hashi_vault, { auth_method: :token, token: "s.1234abcdef", vault_addr: https://localhost:8200}, run_context )
|
56
|
+
# fetcher.fetch("secretkey1")
|
57
|
+
SUPPORTED_AUTH_TYPES = %i{iam_role token}.freeze
|
58
|
+
class HashiVault < Base
|
59
|
+
|
60
|
+
# Validate and authenticate the current session using the configured auth strategy and parameters
|
61
|
+
def validate!
|
62
|
+
if config[:vault_addr].nil?
|
63
|
+
raise Chef::Exceptions::Secret::ConfigurationInvalid.new("You must provide the Vault address in the configuration as :vault_addr")
|
64
|
+
end
|
65
|
+
|
66
|
+
Vault.address = config[:vault_addr]
|
67
|
+
Vault.namespace = config[:namespace] unless config[:namespace].nil?
|
68
|
+
|
69
|
+
case config[:auth_method]
|
70
|
+
when :token
|
71
|
+
if config[:token].nil?
|
72
|
+
raise Chef::Exceptions::Secret::ConfigurationInvalid.new("You must provide the token in the configuration as :token")
|
73
|
+
end
|
74
|
+
|
75
|
+
Vault.auth.token(config[:token])
|
76
|
+
when :iam_role, nil
|
77
|
+
if config[:role_name].nil?
|
78
|
+
raise Chef::Exceptions::Secret::ConfigurationInvalid.new("You must provide the authenticating Vault role name in the configuration as :role_name")
|
79
|
+
end
|
80
|
+
|
81
|
+
Vault.auth.aws_iam(config[:role_name], Aws::InstanceProfileCredentials.new)
|
82
|
+
else
|
83
|
+
raise Chef::Exceptions::Secret::ConfigurationInvalid.new("Invalid :auth_method provided. You gave #{config[:auth_method]}, expected one of :#{SUPPORTED_AUTH_TYPES.join(", :")} ")
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
# @param identifier [String] Identifier of the secret to be fetched, which should
|
88
|
+
# be the full path of that secret, eg 'secret/example'
|
89
|
+
# @param _version [String] not used in this implementation
|
90
|
+
# @return [Hash] containing key/value pairs stored at the location given in 'identifier'
|
91
|
+
def do_fetch(identifier, _version)
|
92
|
+
result = Vault.logical.read(identifier)
|
93
|
+
raise Chef::Exceptions::Secret::FetchFailed.new("No secret found at #{identifier}. Check to ensure that there is a secrets engine configured for that path") if result.nil?
|
94
|
+
|
95
|
+
result.data
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
@@ -0,0 +1,61 @@
|
|
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 "exceptions"
|
20
|
+
|
21
|
+
class Chef
|
22
|
+
class SecretFetcher
|
23
|
+
|
24
|
+
SECRET_FETCHERS = %i{example aws_secrets_manager azure_key_vault hashi_vault akeyless_vault}.freeze
|
25
|
+
|
26
|
+
# Returns a configured and validated instance
|
27
|
+
# of a [Chef::SecretFetcher::Base] for the given
|
28
|
+
# service and configuration.
|
29
|
+
#
|
30
|
+
# @param service [Symbol] the identifier for the service that will support this request. Must be in
|
31
|
+
# SECRET_FETCHERS
|
32
|
+
# @param config [Hash] configuration that the secrets service requires
|
33
|
+
# @param run_context [Chef::RunContext] the run context this is being invoked from
|
34
|
+
def self.for_service(service, config, run_context)
|
35
|
+
fetcher = case service
|
36
|
+
when :example
|
37
|
+
require_relative "secret_fetcher/example"
|
38
|
+
Chef::SecretFetcher::Example.new(config, run_context)
|
39
|
+
when :aws_secrets_manager
|
40
|
+
require_relative "secret_fetcher/aws_secrets_manager"
|
41
|
+
Chef::SecretFetcher::AWSSecretsManager.new(config, run_context)
|
42
|
+
when :azure_key_vault
|
43
|
+
require_relative "secret_fetcher/azure_key_vault"
|
44
|
+
Chef::SecretFetcher::AzureKeyVault.new(config, run_context)
|
45
|
+
when :hashi_vault
|
46
|
+
require_relative "secret_fetcher/hashi_vault"
|
47
|
+
Chef::SecretFetcher::HashiVault.new(config, run_context)
|
48
|
+
when :akeyless_vault
|
49
|
+
require_relative "secret_fetcher/akeyless_vault"
|
50
|
+
Chef::SecretFetcher::AKeylessVault.new(config, run_context)
|
51
|
+
when nil, ""
|
52
|
+
raise Chef::Exceptions::Secret::MissingFetcher.new(SECRET_FETCHERS)
|
53
|
+
else
|
54
|
+
raise Chef::Exceptions::Secret::InvalidFetcherService.new("Unsupported secret service: '#{service}'", SECRET_FETCHERS)
|
55
|
+
end
|
56
|
+
fetcher.validate!
|
57
|
+
fetcher
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
data/lib/chef/version.rb
CHANGED
Binary file
|
@@ -0,0 +1,87 @@
|
|
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 "tmpdir"
|
20
|
+
|
21
|
+
# Exclude this test on platforms where ffi-libarchive loading is broken
|
22
|
+
describe Chef::Resource::ArchiveFile, :libarchive_loading_broken do
|
23
|
+
include RecipeDSLHelper
|
24
|
+
|
25
|
+
let(:tmp_path) { Dir.mktmpdir }
|
26
|
+
let(:extract_destination) { "#{tmp_path}/extract_here" }
|
27
|
+
let(:test_archive_path) { File.expand_path("archive_file/test_archive.tar.gz", CHEF_SPEC_DATA) }
|
28
|
+
|
29
|
+
after do
|
30
|
+
FileUtils.remove_entry_secure(extract_destination) if File.exist?(extract_destination)
|
31
|
+
end
|
32
|
+
|
33
|
+
context "when strip_components is 0" do
|
34
|
+
it "extracts archive to destination" do
|
35
|
+
af = archive_file test_archive_path do
|
36
|
+
destination extract_destination
|
37
|
+
end
|
38
|
+
af.should_be_updated
|
39
|
+
|
40
|
+
expect(af.strip_components).to eq(0) # Validate defaults haven't changed here
|
41
|
+
expect(Dir.glob("#{extract_destination}/**/*").length).to eq(4)
|
42
|
+
expect(Dir.exist?("#{extract_destination}/folder-1")).to eq(true)
|
43
|
+
expect(File.exist?("#{extract_destination}/folder-1/file-1.txt")).to eq(true)
|
44
|
+
expect(Dir.exist?("#{extract_destination}/folder-1/folder-2")).to eq(true)
|
45
|
+
expect(File.exist?("#{extract_destination}/folder-1/folder-2/file-2.txt")).to eq(true)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context "when strip_components is 1" do
|
50
|
+
it "extracts archive to destination, with 1 component stripped" do
|
51
|
+
archive_file test_archive_path do
|
52
|
+
destination extract_destination
|
53
|
+
strip_components 1
|
54
|
+
end.should_be_updated
|
55
|
+
|
56
|
+
expect(Dir.exist?("#{extract_destination}/folder-1")).to eq(false)
|
57
|
+
expect(File.exist?("#{extract_destination}/folder-1/file-1.txt")).to eq(false)
|
58
|
+
expect(Dir.exist?("#{extract_destination}/folder-1/folder-2")).to eq(false)
|
59
|
+
expect(File.exist?("#{extract_destination}/folder-1/folder-2/file-2.txt")).to eq(false)
|
60
|
+
|
61
|
+
expect(Dir.glob("#{extract_destination}/**/*").length).to eq(3)
|
62
|
+
expect(File.exist?("#{extract_destination}/file-1.txt")).to eq(true)
|
63
|
+
expect(Dir.exist?("#{extract_destination}/folder-2")).to eq(true)
|
64
|
+
expect(File.exist?("#{extract_destination}/folder-2/file-2.txt")).to eq(true)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context "when strip_components is 2" do
|
69
|
+
it "extracts archive to destination, with 2 components stripped" do
|
70
|
+
archive_file test_archive_path do
|
71
|
+
destination extract_destination
|
72
|
+
strip_components 2
|
73
|
+
end.should_be_updated
|
74
|
+
|
75
|
+
expect(Dir.exist?("#{extract_destination}/folder-1")).to eq(false)
|
76
|
+
expect(File.exist?("#{extract_destination}/folder-1/file-1.txt")).to eq(false)
|
77
|
+
expect(Dir.exist?("#{extract_destination}/folder-1/folder-2")).to eq(false)
|
78
|
+
expect(File.exist?("#{extract_destination}/folder-1/folder-2/file-2.txt")).to eq(false)
|
79
|
+
expect(File.exist?("#{extract_destination}/file-1.txt")).to eq(false)
|
80
|
+
expect(Dir.exist?("#{extract_destination}/folder-2")).to eq(false)
|
81
|
+
expect(File.exist?("#{extract_destination}/folder-2/file-2.txt")).to eq(false)
|
82
|
+
|
83
|
+
expect(Dir.glob("#{extract_destination}/**/*").length).to eq(1)
|
84
|
+
expect(File.exist?("#{extract_destination}/file-2.txt")).to eq(true)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -44,6 +44,10 @@ describe Chef::Resource::Group, :requires_root_or_running_windows do
|
|
44
44
|
members.shift # Get rid of GroupMembership: string
|
45
45
|
members.include?(user)
|
46
46
|
else
|
47
|
+
# TODO For some reason our temporary AIX 7.2 system does not correctly report group membership immediately after changes have been made.
|
48
|
+
# Adding a 2 second delay for this platform is enough to get correct results.
|
49
|
+
# We hope to remove this delay after we get more permanent AIX 7.2 systems in our CI pipeline. reference: https://github.com/chef/release-engineering/issues/1617
|
50
|
+
sleep 2 if aix? && (ohai[:platform_version] == "7.2")
|
47
51
|
Etc.getgrnam(group_name).mem.include?(user)
|
48
52
|
end
|
49
53
|
end
|
@@ -181,7 +185,7 @@ describe Chef::Resource::Group, :requires_root_or_running_windows do
|
|
181
185
|
|
182
186
|
describe "when the users exist" do
|
183
187
|
before do
|
184
|
-
high_uid =
|
188
|
+
high_uid = 40000
|
185
189
|
(spec_members).each do |member|
|
186
190
|
remove_user(member)
|
187
191
|
create_user(member, high_uid)
|
@@ -345,9 +345,17 @@ describe Chef::Resource::Link do
|
|
345
345
|
let(:test_user) { "test-link-user" }
|
346
346
|
before do
|
347
347
|
user(test_user).run_action(:create)
|
348
|
+
# TODO For some reason our temporary AIX 7.2 system does not correctly report user existence immediately after changes have been made.
|
349
|
+
# Adding a 2 second delay for this platform is enough to get correct results.
|
350
|
+
# We hope to remove this delay after we get more permanent AIX 7.2 systems in our CI pipeline. reference: https://github.com/chef/release-engineering/issues/1617
|
351
|
+
sleep 2 if aix? && (ohai[:platform_version] == "7.2")
|
348
352
|
end
|
349
353
|
after do
|
350
354
|
user(test_user).run_action(:remove)
|
355
|
+
# TODO For some reason our temporary AIX 7.2 system does not correctly report user existence immediately after changes have been made.
|
356
|
+
# Adding a 2 second delay for this platform is enough to get correct results.
|
357
|
+
# We hope to remove this delay after we get more permanent AIX 7.2 systems in our CI pipeline. reference: https://github.com/chef/release-engineering/issues/1617
|
358
|
+
sleep 2 if aix? && (ohai[:platform_version] == "7.2")
|
351
359
|
end
|
352
360
|
before(:each) do
|
353
361
|
resource.owner(test_user)
|
@@ -47,6 +47,7 @@ describe "chef-client with compliance phase" do
|
|
47
47
|
{
|
48
48
|
"audit": {
|
49
49
|
"compliance_phase": true,
|
50
|
+
"reporter": "json-file",
|
50
51
|
"json_file": {
|
51
52
|
"location": "#{report_file}"
|
52
53
|
},
|
@@ -79,4 +80,64 @@ describe "chef-client with compliance phase" do
|
|
79
80
|
expect(result["status"]).to eq("passed")
|
80
81
|
end
|
81
82
|
end
|
83
|
+
|
84
|
+
when_the_repository "has a compliance segment" do
|
85
|
+
let(:report_file) { path_to("report_file.json") }
|
86
|
+
|
87
|
+
before do
|
88
|
+
directory "cookbooks/x" do
|
89
|
+
directory "compliance" do
|
90
|
+
directory "profiles/my_profile" do
|
91
|
+
file "inspec.yml", <<~FILE
|
92
|
+
---
|
93
|
+
name: my-profile
|
94
|
+
FILE
|
95
|
+
|
96
|
+
directory "controls" do
|
97
|
+
file "my_control.rb", <<~FILE
|
98
|
+
control "my control" do
|
99
|
+
describe Dir.home do
|
100
|
+
it { should be_kind_of String }
|
101
|
+
end
|
102
|
+
end
|
103
|
+
FILE
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
file "attributes/default.rb", <<~FILE
|
108
|
+
default['audit']['reporter'] = "json-file"
|
109
|
+
default['audit']['json_file'] = {
|
110
|
+
"location" => "#{report_file}"
|
111
|
+
}
|
112
|
+
FILE
|
113
|
+
file "recipes/default.rb", <<~FILE
|
114
|
+
include_profile ".*::.*"
|
115
|
+
FILE
|
116
|
+
end
|
117
|
+
file "config/client.rb", <<~EOM
|
118
|
+
local_mode true
|
119
|
+
cookbook_path "#{path_to("cookbooks")}"
|
120
|
+
log_level :warn
|
121
|
+
EOM
|
122
|
+
end
|
123
|
+
|
124
|
+
it "should complete with success" do
|
125
|
+
result = shell_out!("#{chef_client} -c \"#{path_to("config/client.rb")}\" -r 'recipe[x]'", cwd: chef_dir)
|
126
|
+
result.error!
|
127
|
+
|
128
|
+
inspec_report = JSON.parse(File.read(report_file))
|
129
|
+
expect(inspec_report["profiles"].length).to eq(1)
|
130
|
+
|
131
|
+
profile = inspec_report["profiles"].first
|
132
|
+
expect(profile["name"]).to eq("my-profile")
|
133
|
+
expect(profile["controls"].length).to eq(1)
|
134
|
+
|
135
|
+
control = profile["controls"].first
|
136
|
+
expect(control["id"]).to eq("my control")
|
137
|
+
expect(control["results"].length).to eq(1)
|
138
|
+
|
139
|
+
result = control["results"].first
|
140
|
+
expect(result["status"]).to eq("passed")
|
141
|
+
end
|
142
|
+
end
|
82
143
|
end
|
@@ -9,7 +9,7 @@ class NoActionJackson < Chef::Resource
|
|
9
9
|
@foo
|
10
10
|
end
|
11
11
|
|
12
|
-
class <<self
|
12
|
+
class << self
|
13
13
|
attr_accessor :action_was
|
14
14
|
end
|
15
15
|
end
|
@@ -17,7 +17,7 @@ end
|
|
17
17
|
class WeirdActionJackson < Chef::Resource
|
18
18
|
provides :weird_action_jackson
|
19
19
|
|
20
|
-
class <<self
|
20
|
+
class << self
|
21
21
|
attr_accessor :action_was
|
22
22
|
end
|
23
23
|
|
@@ -176,7 +176,7 @@ module ResourceActionSpec
|
|
176
176
|
@blarghle
|
177
177
|
end
|
178
178
|
|
179
|
-
class <<self
|
179
|
+
class << self
|
180
180
|
attr_accessor :ran_action
|
181
181
|
attr_accessor :succeeded
|
182
182
|
attr_accessor :ruby_block_converged
|
@@ -284,7 +284,7 @@ module ResourceActionSpec
|
|
284
284
|
@bar = "#{value}alope" if value
|
285
285
|
@bar
|
286
286
|
end
|
287
|
-
class <<self
|
287
|
+
class << self
|
288
288
|
attr_accessor :load_current_resource_ran
|
289
289
|
attr_accessor :jackalope_ran
|
290
290
|
end
|
@@ -354,8 +354,8 @@ module ResourceActionSpec
|
|
354
354
|
end
|
355
355
|
|
356
356
|
it "allows overridden action to have a description separate from the action defined in the base resource" do
|
357
|
-
expect(ActionJackson.action_description(:test1)).to eql "Original description"
|
358
|
-
expect(ActionJackalope.action_description(:test1)).to eql "An old action with a new description"
|
357
|
+
expect(ActionJackson.new("ActionJackson", nil).action_description(:test1)).to eql "Original description"
|
358
|
+
expect(ActionJackalope.new("ActionJackalope", nil).action_description(:test1)).to eql "An old action with a new description"
|
359
359
|
end
|
360
360
|
|
361
361
|
it "non-overridden actions run and can access overridden and non-overridden variables (but not necessarily new ones)" do
|
data/spec/spec_helper.rb
CHANGED
@@ -68,6 +68,7 @@ end
|
|
68
68
|
require "spec/support/local_gems" if File.exist?(File.join(File.dirname(__FILE__), "support", "local_gems.rb"))
|
69
69
|
|
70
70
|
# Explicitly require spec helpers that need to load first
|
71
|
+
require "spec/support/ruby_installer"
|
71
72
|
require "spec/support/platform_helpers"
|
72
73
|
require "spec/support/shared/unit/mock_shellout"
|
73
74
|
|
@@ -186,6 +187,8 @@ RSpec.configure do |config|
|
|
186
187
|
config.filter_run_excluding not_rhel7: true if rhel7?
|
187
188
|
config.filter_run_excluding not_intel_64bit: true if intel_64bit?
|
188
189
|
|
190
|
+
config.filter_run_excluding libarchive_loading_broken: true if aix? || amazon_linux? || rhel7?
|
191
|
+
|
189
192
|
# these let us use chef: ">= 13" or ruby: "~> 2.0.0" or any other Gem::Dependency-style constraint
|
190
193
|
config.filter_run_excluding chef: DependencyProc.with(Chef::VERSION)
|
191
194
|
config.filter_run_excluding ruby: DependencyProc.with(RUBY_VERSION)
|
@@ -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/
|
@@ -43,7 +43,6 @@ end
|
|
43
43
|
def setup_normal_file
|
44
44
|
[ resource_path, normalized_path, windows_path].each do |path|
|
45
45
|
allow(File).to receive(:file?).with(path).and_return(true)
|
46
|
-
allow(File).to receive(:exists?).with(path).and_return(true)
|
47
46
|
allow(File).to receive(:exist?).with(path).and_return(true)
|
48
47
|
allow(File).to receive(:directory?).with(path).and_return(false)
|
49
48
|
allow(File).to receive(:writable?).with(path).and_return(true)
|
@@ -57,7 +56,6 @@ def setup_missing_file
|
|
57
56
|
[ resource_path, normalized_path, windows_path].each do |path|
|
58
57
|
allow(File).to receive(:file?).with(path).and_return(false)
|
59
58
|
allow(File).to receive(:realpath?).with(path).and_return(resource_path)
|
60
|
-
allow(File).to receive(:exists?).with(path).and_return(false)
|
61
59
|
allow(File).to receive(:exist?).with(path).and_return(false)
|
62
60
|
allow(File).to receive(:directory?).with(path).and_return(false)
|
63
61
|
allow(File).to receive(:writable?).with(path).and_return(false)
|
@@ -70,7 +68,6 @@ def setup_symlink
|
|
70
68
|
[ resource_path, normalized_path, windows_path].each do |path|
|
71
69
|
allow(File).to receive(:file?).with(path).and_return(true)
|
72
70
|
allow(File).to receive(:realpath?).with(path).and_return(normalized_path)
|
73
|
-
allow(File).to receive(:exists?).with(path).and_return(true)
|
74
71
|
allow(File).to receive(:exist?).with(path).and_return(true)
|
75
72
|
allow(File).to receive(:directory?).with(path).and_return(false)
|
76
73
|
allow(File).to receive(:writable?).with(path).and_return(true)
|
@@ -84,7 +81,6 @@ def setup_unwritable_file
|
|
84
81
|
[ resource_path, normalized_path, windows_path].each do |path|
|
85
82
|
allow(File).to receive(:file?).with(path).and_return(false)
|
86
83
|
allow(File).to receive(:realpath?).with(path).and_raise(Errno::ENOENT)
|
87
|
-
allow(File).to receive(:exists?).with(path).and_return(true)
|
88
84
|
allow(File).to receive(:exist?).with(path).and_return(true)
|
89
85
|
allow(File).to receive(:directory?).with(path).and_return(false)
|
90
86
|
allow(File).to receive(:writable?).with(path).and_return(false)
|
@@ -97,7 +93,6 @@ def setup_missing_enclosing_directory
|
|
97
93
|
[ resource_path, normalized_path, windows_path].each do |path|
|
98
94
|
allow(File).to receive(:file?).with(path).and_return(false)
|
99
95
|
allow(File).to receive(:realpath?).with(path).and_raise(Errno::ENOENT)
|
100
|
-
allow(File).to receive(:exists?).with(path).and_return(false)
|
101
96
|
allow(File).to receive(:exist?).with(path).and_return(false)
|
102
97
|
allow(File).to receive(:directory?).with(path).and_return(false)
|
103
98
|
allow(File).to receive(:writable?).with(path).and_return(false)
|
@@ -138,7 +133,6 @@ shared_examples_for Chef::Provider::File do
|
|
138
133
|
before(:each) do
|
139
134
|
allow(content).to receive(:tempfile).and_return(tempfile)
|
140
135
|
allow(File).to receive(:exist?).with(tempfile.path).and_call_original
|
141
|
-
allow(File).to receive(:exists?).with(tempfile.path).and_call_original
|
142
136
|
end
|
143
137
|
|
144
138
|
after do
|
@@ -547,7 +541,7 @@ shared_examples_for Chef::Provider::File do
|
|
547
541
|
provider.load_current_resource
|
548
542
|
tempfile = double("Tempfile", path: "/tmp/foo-bar-baz")
|
549
543
|
allow(content).to receive(:tempfile).and_return(tempfile)
|
550
|
-
expect(File).to receive(:
|
544
|
+
expect(File).to receive(:exist?).with("/tmp/foo-bar-baz").and_return(true)
|
551
545
|
expect(tempfile).to receive(:close).once
|
552
546
|
expect(tempfile).to receive(:unlink).once
|
553
547
|
end
|
@@ -630,7 +624,7 @@ shared_examples_for Chef::Provider::File do
|
|
630
624
|
it "raises an exception when the content object returns a tempfile that does not exist" do
|
631
625
|
tempfile = double("Tempfile", path: "/tmp/foo-bar-baz")
|
632
626
|
expect(provider.send(:content)).to receive(:tempfile).at_least(:once).and_return(tempfile)
|
633
|
-
expect(File).to receive(:
|
627
|
+
expect(File).to receive(:exist?).with("/tmp/foo-bar-baz").and_return(false)
|
634
628
|
expect { provider.send(:do_contents_changes) }.to raise_error(RuntimeError)
|
635
629
|
end
|
636
630
|
end
|