chef 18.5.0 → 18.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +8 -3
- data/chef-universal-mingw-ucrt.gemspec +1 -1
- data/chef.gemspec +2 -2
- data/lib/chef/application/client.rb +0 -12
- data/lib/chef/client.rb +1 -10
- data/lib/chef/compliance/runner.rb +0 -10
- data/lib/chef/cookbook/remote_file_vendor.rb +3 -2
- data/lib/chef/cookbook/synchronizer.rb +0 -5
- data/lib/chef/exceptions.rb +1 -1
- data/lib/chef/file_access_control/unix.rb +9 -9
- data/lib/chef/file_content_management/deploy.rb +1 -4
- data/lib/chef/mixin/file_class.rb +1 -3
- data/lib/chef/mixin/get_source_from_package.rb +1 -1
- data/lib/chef/mixin/{homebrew_user.rb → homebrew.rb} +13 -16
- data/lib/chef/mixin/openssl_helper.rb +1 -12
- data/lib/chef/provider/cookbook_file.rb +1 -1
- data/lib/chef/provider/cron.rb +1 -1
- data/lib/chef/provider/directory.rb +15 -15
- data/lib/chef/provider/file.rb +29 -42
- data/lib/chef/provider/git.rb +8 -8
- data/lib/chef/provider/group/aix.rb +1 -1
- data/lib/chef/provider/group/dscl.rb +1 -1
- data/lib/chef/provider/group/gpasswd.rb +2 -2
- data/lib/chef/provider/group/groupadd.rb +1 -1
- data/lib/chef/provider/group/groupmod.rb +2 -2
- data/lib/chef/provider/group/pw.rb +2 -2
- data/lib/chef/provider/group/solaris.rb +2 -2
- data/lib/chef/provider/group/usermod.rb +2 -2
- data/lib/chef/provider/group.rb +1 -1
- data/lib/chef/provider/http_request.rb +3 -2
- data/lib/chef/provider/ifconfig/aix.rb +1 -1
- data/lib/chef/provider/ifconfig/debian.rb +3 -3
- data/lib/chef/provider/ifconfig/redhat.rb +1 -1
- data/lib/chef/provider/ifconfig.rb +1 -1
- data/lib/chef/provider/link.rb +10 -10
- data/lib/chef/provider/mount/aix.rb +4 -4
- data/lib/chef/provider/mount/linux.rb +4 -4
- data/lib/chef/provider/mount/mount.rb +11 -11
- data/lib/chef/provider/package/apt.rb +11 -2
- data/lib/chef/provider/package/bff.rb +3 -3
- data/lib/chef/provider/package/chocolatey.rb +2 -2
- data/lib/chef/provider/package/dpkg.rb +3 -3
- data/lib/chef/provider/package/freebsd/base.rb +1 -1
- data/lib/chef/provider/package/habitat.rb +3 -5
- data/lib/chef/provider/package/homebrew.rb +6 -9
- data/lib/chef/provider/package/ips.rb +2 -2
- data/lib/chef/provider/package/openbsd.rb +2 -3
- data/lib/chef/provider/package/pacman.rb +4 -4
- data/lib/chef/provider/package/paludis.rb +2 -2
- data/lib/chef/provider/package/portage.rb +1 -1
- data/lib/chef/provider/package/rpm.rb +2 -2
- data/lib/chef/provider/package/rubygems.rb +4 -0
- data/lib/chef/provider/package/smartos.rb +2 -2
- data/lib/chef/provider/package/snap.rb +1 -1
- data/lib/chef/provider/package/solaris.rb +4 -4
- data/lib/chef/provider/package/zypper.rb +4 -4
- data/lib/chef/provider/package.rb +1 -1
- data/lib/chef/provider/remote_directory.rb +5 -5
- data/lib/chef/provider/remote_file/http.rb +3 -2
- data/lib/chef/provider/remote_file.rb +1 -1
- data/lib/chef/provider/route.rb +9 -9
- data/lib/chef/provider/service/aix.rb +1 -1
- data/lib/chef/provider/service/aixinit.rb +4 -4
- data/lib/chef/provider/service/arch.rb +6 -6
- data/lib/chef/provider/service/debian.rb +5 -5
- data/lib/chef/provider/service/freebsd.rb +7 -7
- data/lib/chef/provider/service/gentoo.rb +5 -5
- data/lib/chef/provider/service/init.rb +2 -2
- data/lib/chef/provider/service/insserv.rb +2 -2
- data/lib/chef/provider/service/invokercd.rb +1 -1
- data/lib/chef/provider/service/openbsd.rb +7 -7
- data/lib/chef/provider/service/redhat.rb +3 -3
- data/lib/chef/provider/service/solaris.rb +2 -2
- data/lib/chef/provider/service/systemd.rb +2 -2
- data/lib/chef/provider/service/upstart.rb +2 -2
- data/lib/chef/provider/subversion.rb +8 -8
- data/lib/chef/provider/systemd_unit.rb +3 -3
- data/lib/chef/provider/template.rb +1 -1
- data/lib/chef/provider/user/aix.rb +3 -3
- data/lib/chef/provider/user/linux.rb +2 -7
- data/lib/chef/provider/user/pw.rb +3 -3
- data/lib/chef/provider/user/solaris.rb +7 -7
- data/lib/chef/provider/user/windows.rb +5 -0
- data/lib/chef/provider/user.rb +8 -7
- data/lib/chef/provider/yum_repository.rb +3 -1
- data/lib/chef/provider/zypper_repository.rb +1 -1
- data/lib/chef/providers.rb +0 -1
- data/lib/chef/resource/alternatives.rb +2 -2
- data/lib/chef/resource/apt_preference.rb +1 -1
- data/lib/chef/resource/apt_repository.rb +9 -7
- data/lib/chef/resource/apt_update.rb +3 -3
- data/lib/chef/resource/bff_package.rb +1 -1
- data/lib/chef/resource/chef_client_config.rb +3 -2
- data/lib/chef/resource/chef_sleep.rb +1 -1
- data/lib/chef/resource/cookbook_file.rb +1 -1
- data/lib/chef/resource/cron/cron.rb +1 -1
- data/lib/chef/resource/cron/cron_d.rb +1 -1
- data/lib/chef/resource/cron_access.rb +1 -1
- data/lib/chef/resource/directory.rb +1 -1
- data/lib/chef/resource/dpkg_package.rb +1 -1
- data/lib/chef/resource/file/verification/json.rb +1 -1
- data/lib/chef/resource/file/verification/systemd_unit.rb +1 -1
- data/lib/chef/resource/file/verification/yaml.rb +1 -1
- data/lib/chef/resource/file.rb +1 -1
- data/lib/chef/resource/freebsd_package.rb +2 -2
- data/lib/chef/resource/group.rb +1 -1
- data/lib/chef/resource/habitat/habitat_package.rb +1 -1
- data/lib/chef/resource/habitat/habitat_sup.rb +9 -9
- data/lib/chef/resource/habitat/habitat_sup_systemd.rb +2 -2
- data/lib/chef/resource/habitat_install.rb +3 -3
- data/lib/chef/resource/homebrew_cask.rb +19 -30
- data/lib/chef/resource/homebrew_tap.rb +32 -17
- data/lib/chef/resource/homebrew_update.rb +4 -4
- data/lib/chef/resource/hostname.rb +10 -11
- data/lib/chef/resource/http_request.rb +1 -1
- data/lib/chef/resource/ifconfig.rb +1 -1
- data/lib/chef/resource/inspec_input.rb +1 -3
- data/lib/chef/resource/inspec_waiver.rb +1 -1
- data/lib/chef/resource/inspec_waiver_file_entry.rb +1 -1
- data/lib/chef/resource/ips_package.rb +2 -2
- data/lib/chef/resource/kernel_module.rb +2 -2
- data/lib/chef/resource/link.rb +1 -1
- data/lib/chef/resource/locale.rb +2 -2
- data/lib/chef/resource/mount.rb +1 -1
- data/lib/chef/resource/notify_group.rb +1 -1
- data/lib/chef/resource/ohai.rb +1 -1
- data/lib/chef/resource/ohai_hint.rb +1 -1
- data/lib/chef/resource/openbsd_package.rb +2 -2
- data/lib/chef/resource/package.rb +1 -1
- data/lib/chef/resource/pacman_package.rb +1 -1
- data/lib/chef/resource/paludis_package.rb +1 -1
- data/lib/chef/resource/portage_package.rb +1 -1
- data/lib/chef/resource/reboot.rb +1 -1
- data/lib/chef/resource/remote_directory.rb +1 -1
- data/lib/chef/resource/remote_file.rb +1 -1
- data/lib/chef/resource/rhsm_errata.rb +1 -1
- data/lib/chef/resource/rhsm_errata_level.rb +1 -1
- data/lib/chef/resource/rhsm_register.rb +1 -1
- data/lib/chef/resource/rhsm_repo.rb +4 -3
- data/lib/chef/resource/rhsm_subscription.rb +9 -8
- data/lib/chef/resource/route.rb +1 -1
- data/lib/chef/resource/rpm_package.rb +1 -1
- data/lib/chef/resource/scm/git.rb +1 -1
- data/lib/chef/resource/scm/subversion.rb +1 -1
- data/lib/chef/resource/selinux/common_helpers.rb +1 -1
- data/lib/chef/resource/selinux_boolean.rb +1 -1
- data/lib/chef/resource/selinux_fcontext.rb +3 -3
- data/lib/chef/resource/selinux_install.rb +1 -1
- data/lib/chef/resource/selinux_login.rb +1 -1
- data/lib/chef/resource/selinux_module.rb +5 -5
- data/lib/chef/resource/selinux_permissive.rb +2 -2
- data/lib/chef/resource/selinux_port.rb +2 -2
- data/lib/chef/resource/selinux_state.rb +2 -2
- data/lib/chef/resource/selinux_user.rb +1 -1
- data/lib/chef/resource/smartos_package.rb +2 -2
- data/lib/chef/resource/snap_package.rb +1 -1
- data/lib/chef/resource/solaris_package.rb +1 -1
- data/lib/chef/resource/ssh_known_hosts_entry.rb +1 -1
- data/lib/chef/resource/sudo.rb +5 -5
- data/lib/chef/resource/support/client.erb +3 -2
- data/lib/chef/resource/swap_file.rb +6 -6
- data/lib/chef/resource/sysctl.rb +5 -5
- data/lib/chef/resource/systemd_unit.rb +1 -1
- data/lib/chef/resource/template.rb +1 -1
- data/lib/chef/resource/timezone.rb +5 -5
- data/lib/chef/resource/user/aix_user.rb +2 -2
- data/lib/chef/resource/user/linux_user.rb +2 -2
- data/lib/chef/resource/user/pw_user.rb +2 -2
- data/lib/chef/resource/user/solaris_user.rb +2 -2
- data/lib/chef/resource/user_ulimit.rb +1 -1
- data/lib/chef/resource/yum_repository.rb +1 -1
- data/lib/chef/resource/zypper_package.rb +2 -2
- data/lib/chef/resource/zypper_repository.rb +2 -2
- data/lib/chef/resource_inspector.rb +25 -7
- data/lib/chef/run_lock.rb +0 -3
- data/lib/chef/scan_access_control.rb +6 -6
- data/lib/chef/util/backup.rb +1 -1
- data/lib/chef/util/diff.rb +1 -14
- data/lib/chef/util/file_edit.rb +4 -4
- data/lib/chef/version.rb +1 -1
- data/lib/chef/win32/registry.rb +5 -0
- data/lib/chef/win32/security.rb +9 -0
- data/lib/chef.rb +0 -2
- data/spec/functional/resource/cookbook_file_spec.rb +1 -1
- data/spec/integration/client/open_ssl_spec.rb +1 -1
- data/spec/spec_helper.rb +1 -0
- data/spec/support/chef_helpers.rb +2 -2
- data/spec/support/platform_helpers.rb +8 -0
- data/spec/support/shared/functional/file_resource.rb +3 -3
- data/spec/unit/mixin/homebrew_spec.rb +118 -0
- data/spec/unit/provider/apt_repository_spec.rb +1 -1
- data/spec/unit/provider/package/chocolatey_spec.rb +1 -1
- data/spec/unit/provider/package/homebrew_spec.rb +4 -1
- data/spec/unit/provider/route_spec.rb +4 -6
- data/spec/unit/provider/user/windows_spec.rb +1 -0
- data/spec/unit/resource/rhsm_repo_spec.rb +0 -1
- data/spec/unit/resource/rhsm_subscription_spec.rb +0 -2
- data/spec/unit/resource_inspector_spec.rb +36 -0
- metadata +20 -28
- data/lib/chef/file_content_management/deploy/target_io.rb +0 -29
- data/lib/chef/provider/.gitkeep +0 -0
- data/lib/chef/provider/package/snap_tm.rb +0 -79
- data/lib/chef/resource/.gitkeep +0 -0
- data/lib/chef/target_io/dir.rb +0 -12
- data/lib/chef/target_io/etc.rb +0 -16
- data/lib/chef/target_io/file.rb +0 -12
- data/lib/chef/target_io/fileutils.rb +0 -12
- data/lib/chef/target_io/http.rb +0 -22
- data/lib/chef/target_io/io.rb +0 -12
- data/lib/chef/target_io/shadow.rb +0 -44
- data/lib/chef/target_io/train/dir.rb +0 -69
- data/lib/chef/target_io/train/etc.rb +0 -112
- data/lib/chef/target_io/train/file.rb +0 -219
- data/lib/chef/target_io/train/fileutils.rb +0 -220
- data/lib/chef/target_io/train/http.rb +0 -117
- data/lib/chef/target_io/train/io.rb +0 -13
- data/lib/chef/target_io/train/shadow.rb +0 -52
- data/lib/chef/target_io/train_compat.rb +0 -7
- data/lib/chef/target_io.rb +0 -9
- data/spec/unit/mixin/homebrew_user_spec.rb +0 -119
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
# require_relative "../mixin/which"
|
|
2
|
-
|
|
3
|
-
module TargetIO
|
|
4
|
-
module TrainCompat
|
|
5
|
-
class HTTP
|
|
6
|
-
attr_reader :last_response
|
|
7
|
-
|
|
8
|
-
def initialize(url, options = {})
|
|
9
|
-
@url = url.is_a?(URI) ? url.to_s : url
|
|
10
|
-
@options = options
|
|
11
|
-
@last_response = ""
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
# Send an HTTP HEAD request to the path
|
|
15
|
-
#
|
|
16
|
-
# === Parameters
|
|
17
|
-
# path:: path part of the request URL
|
|
18
|
-
def head(path, headers = {})
|
|
19
|
-
request(:HEAD, path, headers)
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
# Send an HTTP GET request to the path
|
|
23
|
-
#
|
|
24
|
-
# === Parameters
|
|
25
|
-
# path:: The path to GET
|
|
26
|
-
def get(path, headers = {})
|
|
27
|
-
request(:GET, path, headers)
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
# Send an HTTP PUT request to the path
|
|
31
|
-
#
|
|
32
|
-
# === Parameters
|
|
33
|
-
# path:: path part of the request URL
|
|
34
|
-
def put(path, json, headers = {})
|
|
35
|
-
request(:PUT, path, headers, json)
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
# Send an HTTP POST request to the path
|
|
39
|
-
#
|
|
40
|
-
# === Parameters
|
|
41
|
-
# path:: path part of the request URL
|
|
42
|
-
def post(path, json, headers = {})
|
|
43
|
-
request(:POST, path, headers, json)
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
# Send an HTTP DELETE request to the path
|
|
47
|
-
#
|
|
48
|
-
# === Parameters
|
|
49
|
-
# path:: path part of the request URL
|
|
50
|
-
def delete(path, headers = {})
|
|
51
|
-
request(:DELETE, path, headers)
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
# Used inside Chef::Provider::RemoteFile::HTTPS
|
|
55
|
-
def streaming_request(path, headers = {}, tempfile = nil)
|
|
56
|
-
content = get(path, headers)
|
|
57
|
-
@last_response = content
|
|
58
|
-
|
|
59
|
-
tempfile.write(content)
|
|
60
|
-
tempfile.close
|
|
61
|
-
|
|
62
|
-
tempfile
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
def request(method, path, headers = {}, data = false)
|
|
66
|
-
cmd = nil
|
|
67
|
-
path = path.is_a?(URI) ? path.to_s : path
|
|
68
|
-
headers.merge!(@options[:headers] || {})
|
|
69
|
-
|
|
70
|
-
SUPPORTED_COMMANDS.each do |command_name|
|
|
71
|
-
executable = which(command_name).chop
|
|
72
|
-
next if !executable || executable.empty?
|
|
73
|
-
|
|
74
|
-
# There are different ways to call (constructor, argument, combination of both)
|
|
75
|
-
full_url = if path.start_with?("http")
|
|
76
|
-
path
|
|
77
|
-
elsif path.empty? || @url.end_with?(path)
|
|
78
|
-
@url
|
|
79
|
-
else
|
|
80
|
-
File.join(@url, path)
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
cmd = send(command_name.to_sym, executable, method.to_s.upcase, full_url, headers, data)
|
|
84
|
-
break
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
raise "Target needs one of #{SUPPORTED_COMMANDS.join("/")} for HTTP requests to work" unless cmd
|
|
88
|
-
|
|
89
|
-
connection = Chef.run_context&.transport_connection
|
|
90
|
-
connection.run_command(cmd).stdout
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
SUPPORTED_COMMANDS = %w{curl wget}.freeze
|
|
94
|
-
|
|
95
|
-
# Sending data is not yet supported
|
|
96
|
-
def curl(cmd, method, url, headers, _data)
|
|
97
|
-
cmd += headers.map { |name, value| " --header '#{name}: #{value}'" }.join
|
|
98
|
-
cmd += " --request #{method} "
|
|
99
|
-
cmd += url
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
# Sending data is not yet supported
|
|
103
|
-
def wget(cmd, method, url, headers, _data)
|
|
104
|
-
cmd += headers.map { |name, value| " --header '#{name}: #{value}'" }.join
|
|
105
|
-
cmd += " --method #{method}"
|
|
106
|
-
cmd += " --output-document=- "
|
|
107
|
-
cmd += url
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
# extend Chef::Mixin::Which
|
|
111
|
-
def which(cmd)
|
|
112
|
-
connection = Chef.run_context&.transport_connection
|
|
113
|
-
connection.run_command("which #{cmd}").stdout
|
|
114
|
-
end
|
|
115
|
-
end
|
|
116
|
-
end
|
|
117
|
-
end
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
module TargetIO
|
|
2
|
-
module TrainCompat
|
|
3
|
-
module Shadow
|
|
4
|
-
# @see https://www.rubydoc.info/gems/ruby-shadow/2.5.0
|
|
5
|
-
class Passwd
|
|
6
|
-
class << self
|
|
7
|
-
def getspnam(name)
|
|
8
|
-
content = ::TargetIO::File.read("/etc/shadow")
|
|
9
|
-
entries = __parse_shadow(content)
|
|
10
|
-
data = entries.detect { |entry| entry["name"] == name }
|
|
11
|
-
return ::TargetIO::Shadow::Entry.new unless data
|
|
12
|
-
|
|
13
|
-
::TargetIO::Shadow::Entry.new(
|
|
14
|
-
data["sp_namp"],
|
|
15
|
-
data["sp_pwdp"],
|
|
16
|
-
data["sp_lstchg"],
|
|
17
|
-
data["sp_min"],
|
|
18
|
-
data["sp_max"],
|
|
19
|
-
data["sp_warn"],
|
|
20
|
-
data["sp_inact"],
|
|
21
|
-
data["sp_expire"],
|
|
22
|
-
data["sp_loginclass"]
|
|
23
|
-
)
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def __parse_shadow(content)
|
|
27
|
-
content.to_s.split("\n").map do |line|
|
|
28
|
-
next if line[0] == "#"
|
|
29
|
-
|
|
30
|
-
__parse_shadow_line(line)
|
|
31
|
-
end.compact
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
def __parse_shadow_line(line)
|
|
35
|
-
x = line.split(":")
|
|
36
|
-
{
|
|
37
|
-
# rubocop:disable Layout/AlignHash
|
|
38
|
-
"sp_namp" => x.at(0),
|
|
39
|
-
"sp_pwdp" => x.at(1),
|
|
40
|
-
"sp_lstchg" => x.at(2),
|
|
41
|
-
"sp_min" => x.at(3),
|
|
42
|
-
"sp_max" => x.at(4),
|
|
43
|
-
"sp_warn" => x.at(5),
|
|
44
|
-
"sp_inact" => x.at(6),
|
|
45
|
-
"sp_expire" => x.at(7),
|
|
46
|
-
}
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
end
|
data/lib/chef/target_io.rb
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
require_relative "target_io/dir"
|
|
2
|
-
require_relative "target_io/etc"
|
|
3
|
-
require_relative "target_io/file"
|
|
4
|
-
require_relative "target_io/fileutils"
|
|
5
|
-
require_relative "target_io/http"
|
|
6
|
-
require_relative "target_io/io"
|
|
7
|
-
require_relative "target_io/shadow"
|
|
8
|
-
|
|
9
|
-
require_relative "target_io/train_compat"
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
#
|
|
2
|
-
# Author:: Joshua Timberman (<joshua@chef.io>)
|
|
3
|
-
#
|
|
4
|
-
# Copyright:: Copyright (c) Chef Software Inc.
|
|
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
|
-
require "spec_helper"
|
|
19
|
-
require "chef/mixin/homebrew_user"
|
|
20
|
-
|
|
21
|
-
class ExampleHomebrewUser
|
|
22
|
-
include Chef::Mixin::HomebrewUser
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
describe Chef::Mixin::HomebrewUser do
|
|
26
|
-
let(:homebrew_user) { ExampleHomebrewUser.new }
|
|
27
|
-
let(:node) { Chef::Node.new }
|
|
28
|
-
|
|
29
|
-
describe "when the homebrew user is provided" do
|
|
30
|
-
let(:uid) { 1001 }
|
|
31
|
-
let(:user) { "foo" }
|
|
32
|
-
|
|
33
|
-
it "returns the homebrew user without looking at the file when uid is provided" do
|
|
34
|
-
expect(File).to receive(:exist?).exactly(0).times
|
|
35
|
-
expect(homebrew_user.find_homebrew_uid(uid)).to eq(uid)
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
it "returns the homebrew user without looking at the file when name is provided" do
|
|
39
|
-
expect(File).to receive(:exist?).exactly(0).times
|
|
40
|
-
allow(Etc).to receive_message_chain(:getpwnam, :uid).and_return(uid)
|
|
41
|
-
expect(homebrew_user.find_homebrew_uid(user)).to eq(uid)
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
shared_examples "successfully find executable" do
|
|
47
|
-
let(:user) { nil }
|
|
48
|
-
let(:brew_owner) { 2001 }
|
|
49
|
-
let(:default_brew_path) { "/usr/local/bin/brew" }
|
|
50
|
-
let(:default_brew_path_arm) { "/opt/homebrew/bin/brew" }
|
|
51
|
-
let(:default_brew_path_linux) { "/home/linuxbrew/.linuxbrew/bin/brew" }
|
|
52
|
-
let(:stat_double) do
|
|
53
|
-
d = double
|
|
54
|
-
expect(d).to receive(:uid).and_return(brew_owner)
|
|
55
|
-
d
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
context "debug statement prints owner name" do
|
|
59
|
-
|
|
60
|
-
before do
|
|
61
|
-
expect(Etc).to receive(:getpwuid).with(brew_owner).and_return(OpenStruct.new(name: "name"))
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
def false_unless_specific_value(object, method, value)
|
|
65
|
-
allow(object).to receive(method).and_return(false)
|
|
66
|
-
allow(object).to receive(method).with(value).and_return(true)
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
it "returns the owner of the brew executable when it is at a default location for x86_64 machines" do
|
|
70
|
-
false_unless_specific_value(File, :exist?, default_brew_path)
|
|
71
|
-
false_unless_specific_value(File, :executable?, default_brew_path)
|
|
72
|
-
allow(File).to receive(:stat).with(default_brew_path).and_return(stat_double)
|
|
73
|
-
expect(homebrew_user.find_homebrew_uid(user)).to eq(brew_owner)
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
it "returns the owner of the brew executable when it is at a default location for arm machines" do
|
|
77
|
-
false_unless_specific_value(File, :exist?, default_brew_path_arm)
|
|
78
|
-
false_unless_specific_value(File, :executable?, default_brew_path_arm)
|
|
79
|
-
allow(File).to receive(:stat).with(default_brew_path_arm).and_return(stat_double)
|
|
80
|
-
expect(homebrew_user.find_homebrew_uid(user)).to eq(brew_owner)
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
it "returns the owner of the brew executable when it is at a default location for linux machines" do
|
|
84
|
-
false_unless_specific_value(File, :exist?, default_brew_path_linux)
|
|
85
|
-
false_unless_specific_value(File, :executable?, default_brew_path_linux)
|
|
86
|
-
allow(File).to receive(:stat).with(default_brew_path_linux).and_return(stat_double)
|
|
87
|
-
expect(homebrew_user.find_homebrew_uid(user)).to eq(brew_owner)
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
it "returns the owner of the brew executable when it is not at a default location" do
|
|
91
|
-
allow_any_instance_of(ExampleHomebrewUser).to receive(:which).and_return("/foo")
|
|
92
|
-
false_unless_specific_value(File, :exist?, "/foo")
|
|
93
|
-
false_unless_specific_value(File, :executable?, "/foo")
|
|
94
|
-
allow(homebrew_user).to receive_message_chain(:shell_out, :stdout, :strip).and_return("/foo")
|
|
95
|
-
allow(File).to receive(:stat).with("/foo").and_return(stat_double)
|
|
96
|
-
expect(homebrew_user.find_homebrew_uid(user)).to eq(brew_owner)
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
end
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
describe "when the homebrew user is not provided" do
|
|
103
|
-
|
|
104
|
-
it "raises an error if no executable is found" do
|
|
105
|
-
expect(File).to receive(:exist?).and_return(nil).at_least(:once)
|
|
106
|
-
expect { homebrew_user.find_homebrew_uid(user) }.to raise_error(Chef::Exceptions::CannotDetermineHomebrewOwner)
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
include_examples "successfully find executable"
|
|
110
|
-
|
|
111
|
-
context "the executable is owned by root" do
|
|
112
|
-
include_examples "successfully find executable" do
|
|
113
|
-
let(:brew_owner) { 0 }
|
|
114
|
-
end
|
|
115
|
-
end
|
|
116
|
-
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
end
|