chef 18.3.0 → 18.4.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 +2 -2
- data/chef.gemspec +3 -3
- data/lib/chef/chef_fs/file_pattern.rb +1 -1
- data/lib/chef/chef_fs/path_utils.rb +7 -9
- data/lib/chef/cookbook/synchronizer.rb +2 -3
- data/lib/chef/delayed_evaluator.rb +4 -0
- data/lib/chef/file_access_control/windows.rb +4 -1
- data/lib/chef/guard_interpreter/resource_guard_interpreter.rb +2 -0
- data/lib/chef/mixin/homebrew_user.rb +6 -3
- data/lib/chef/monkey_patches/net-http.rb +5 -5
- data/lib/chef/node/attribute_collections.rb +2 -1
- data/lib/chef/node/immutable_collections.rb +2 -1
- data/lib/chef/node/mixin/state_tracking_array.rb +41 -0
- data/lib/chef/node.rb +22 -0
- data/lib/chef/provider/package/apt.rb +11 -2
- data/lib/chef/provider/package/chocolatey.rb +228 -24
- data/lib/chef/provider/package/zypper.rb +5 -0
- data/lib/chef/provider/powershell_script.rb +96 -6
- data/lib/chef/provider/service/systemd.rb +23 -8
- data/lib/chef/provider/service/windows.rb +1 -0
- data/lib/chef/provider/service.rb +14 -0
- data/lib/chef/provider/user.rb +5 -1
- data/lib/chef/recipe.rb +3 -11
- data/lib/chef/resource/_rest_resource.rb +1 -1
- data/lib/chef/resource/apt_package.rb +19 -0
- data/lib/chef/resource/apt_repository.rb +2 -1
- data/lib/chef/resource/chef_client_systemd_timer.rb +1 -1
- data/lib/chef/resource/chocolatey_installer.rb +207 -0
- data/lib/chef/resource/chocolatey_package.rb +8 -0
- data/lib/chef/resource/homebrew_package.rb +1 -1
- data/lib/chef/resource/locale.rb +5 -2
- data/lib/chef/resource/macos_pkg.rb +111 -0
- data/lib/chef/resource/powershell_script.rb +5 -1
- data/lib/chef/resource/service.rb +3 -0
- data/lib/chef/resource/sudo.rb +37 -2
- data/lib/chef/resource/support/ulimit.erb +40 -0
- data/lib/chef/resource/user_ulimit.rb +38 -0
- data/lib/chef/resources.rb +2 -0
- data/lib/chef/version.rb +1 -1
- data/spec/data/trusted_certs/example.crt +29 -20
- data/spec/data/trusted_certs/example_no_cn.crt +30 -34
- data/spec/functional/resource/chocolatey_package_spec.rb +2 -2
- data/spec/functional/resource/zypper_package_spec.rb +10 -0
- data/spec/unit/compliance/reporter/chef_server_automate_spec.rb +1 -1
- data/spec/unit/delayed_evaluator_spec.rb +35 -0
- data/spec/unit/node_spec.rb +6 -0
- data/spec/unit/provider/package/apt_spec.rb +18 -13
- data/spec/unit/provider/package/chocolatey_spec.rb +40 -12
- data/spec/unit/provider/powershell_script_spec.rb +100 -4
- data/spec/unit/provider/service/systemd_service_spec.rb +1 -0
- data/spec/unit/provider/user/linux_spec.rb +10 -0
- data/spec/unit/resource/chef_client_systemd_timer_spec.rb +1 -1
- data/spec/unit/resource/chocolatey_installer_spec.rb +151 -0
- data/spec/unit/resource/macos_pkg_spec.rb +38 -0
- data/spec/unit/resource/powershell_script_spec.rb +2 -2
- metadata +24 -12
data/lib/chef/resources.rb
CHANGED
@@ -39,6 +39,7 @@ require_relative "resource/chef_sleep"
|
|
39
39
|
require_relative "resource/chef_vault_secret"
|
40
40
|
require_relative "resource/chocolatey_config"
|
41
41
|
require_relative "resource/chocolatey_feature"
|
42
|
+
require_relative "resource/chocolatey_installer"
|
42
43
|
require_relative "resource/chocolatey_package"
|
43
44
|
require_relative "resource/chocolatey_source"
|
44
45
|
require_relative "resource/cron/cron"
|
@@ -83,6 +84,7 @@ require_relative "resource/link"
|
|
83
84
|
require_relative "resource/locale"
|
84
85
|
require_relative "resource/log"
|
85
86
|
require_relative "resource/macports_package"
|
87
|
+
require_relative "resource/macos_pkg"
|
86
88
|
require_relative "resource/macos_userdefaults"
|
87
89
|
require_relative "resource/mdadm"
|
88
90
|
require_relative "resource/mount"
|
data/lib/chef/version.rb
CHANGED
@@ -1,22 +1,31 @@
|
|
1
1
|
-----BEGIN CERTI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qhukgvg81l0hAJLzE5cCdqu
|
22
|
+
8UTR3N+uvwVq0SnP5fuNoyBfcL52NeCaQZMO8N4IEd1VDjwu1XXxav+AbWwaT4Yo
|
23
|
+
OPDWIGGjkCtf2xZsXWFQ0xW+68bZvD6hN9yKp+W2bu1UFqcKCiY/Klhol+2t3eLX
|
24
|
+
xP/fM4nMo6iMZhY4FQCWI/NKbuFPwzHLtrrBURCoX50+fvekOdfRHq771mJvzZKE
|
25
|
+
AAIKAvYoYdFfeuaX5N9/UNjMhZ92mw1IIsdbmsCxvHrWsrczmXeP3u1lvxQnkjWL
|
26
|
+
vg3Zpdv2a0vpYx6nSunko0XA7qnoE+0gdP/uRhMaGiE9QCu3KdZji62gKHuxgc+u
|
27
|
+
/i23kmyqOTC36o/a725eb6fMnGFVSxQ0DXlPSPQnJ2tsGMAM37fxoPfF9IamrmdD
|
28
|
+
Q0Usia+XzBckD0sSG8j50x2of9NS3vFFgWM1Cas55XWzlkDGbIJMlrKOj01bUYNq
|
29
|
+
ltmMfavmpMPA86p8QHRmWlQhtgu+OK/8RxmGtQdtBi8Gdk3mNMkokSQCVcDWvNhX
|
30
|
+
pVFCGya51orBgbWqxbAsIeiv7Pl85edXm8KolJ389xkXqFvX31hme5KnyBhCcRrv
|
31
|
+
EZbXRhY3O58t7SlKWVCnx/JmEkJcRJtZaEReF1LbBayExYNnj/sD
|
36
32
|
-----END CERTIFICATE-----
|
@@ -24,7 +24,7 @@ describe Chef::Resource::ChocolateyPackage, :windows_only, :choco_installed do
|
|
24
24
|
let(:package_name) { "test-A" }
|
25
25
|
let(:package_source) { File.join(CHEF_SPEC_ASSETS, "chocolatey_feed") }
|
26
26
|
let(:package_list) do
|
27
|
-
if
|
27
|
+
if provider.query_command == "list"
|
28
28
|
# using result of query_command because that indicates which "search" command to use
|
29
29
|
# which coincides with the package list output
|
30
30
|
proc { shell_out!("choco search -lo #{Array(package_name).join(" ")}").stdout.chomp }
|
@@ -63,7 +63,7 @@ describe Chef::Resource::ChocolateyPackage, :windows_only, :choco_installed do
|
|
63
63
|
end
|
64
64
|
|
65
65
|
after(:each) do
|
66
|
-
|
66
|
+
provider.instance_variable_set(:@get_choco_version, nil)
|
67
67
|
end
|
68
68
|
|
69
69
|
context "installing a package" do
|
@@ -189,6 +189,15 @@ describe Chef::Resource::ZypperPackage, :requires_root, :suse_only do
|
|
189
189
|
expect(zypper_package.updated_by_last_action?).to be true
|
190
190
|
expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^package chef_rpm is not installed$")
|
191
191
|
end
|
192
|
+
|
193
|
+
context "Package doesn't exist" do
|
194
|
+
let(:package_name) { "nonexistent_repo" }
|
195
|
+
it "does nothing if the package is not installed" do
|
196
|
+
zypper_package.run_action(:remove)
|
197
|
+
expect(zypper_package.updated_by_last_action?).to be false
|
198
|
+
end
|
199
|
+
|
200
|
+
end
|
192
201
|
end
|
193
202
|
|
194
203
|
context "with no available version" do
|
@@ -259,6 +268,7 @@ describe Chef::Resource::ZypperPackage, :requires_root, :suse_only do
|
|
259
268
|
expect(shell_out("zypper locks | grep chef_rpm_provides").stdout.chomp).not_to match("chef_rpm_provides")
|
260
269
|
end
|
261
270
|
end
|
271
|
+
|
262
272
|
def remove_package
|
263
273
|
pkg_to_remove = Chef::Resource::ZypperPackage.new(package_name, run_context)
|
264
274
|
pkg_to_remove.run_action(:remove)
|
@@ -170,7 +170,7 @@ describe Chef::Compliance::Reporter::ChefServerAutomate do
|
|
170
170
|
"X-Ops-Userid" => "spec-node",
|
171
171
|
"X-Remote-Request-Id" => /.+/,
|
172
172
|
}
|
173
|
-
).to_return(status: 200)
|
173
|
+
).to_return(status: 200, body: "OK")
|
174
174
|
|
175
175
|
expect(reporter.send_report(inspec_report)).to eq(true)
|
176
176
|
|
@@ -0,0 +1,35 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: Copyright (c) Progress Software Inc.
|
3
|
+
# License:: Apache License, Version 2.0
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
|
18
|
+
require "spec_helper"
|
19
|
+
|
20
|
+
describe Chef::DelayedEvaluator do
|
21
|
+
let(:magic) { "This is magic!" }
|
22
|
+
let(:de) { Chef::DelayedEvaluator.new { magic } }
|
23
|
+
|
24
|
+
describe "#inspect" do
|
25
|
+
it "inspects the result rather than the Proc" do
|
26
|
+
expect(de.inspect).to eq("lazy { (evaluates to) #{magic.inspect} }")
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "#call" do
|
31
|
+
it "evaluates correctly" do
|
32
|
+
expect(de.call).to eq(magic)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/spec/unit/node_spec.rb
CHANGED
@@ -303,6 +303,12 @@ describe Chef::Node do
|
|
303
303
|
expect(node["tags"]).to eq(%w{one two three four})
|
304
304
|
end
|
305
305
|
|
306
|
+
it "should let you use untag as a convince method for the tags attribute" do
|
307
|
+
node.normal["tags"] = %w{one two three four}
|
308
|
+
node.untag("three", "four")
|
309
|
+
expect(node["tags"]).to eq(%w{one two})
|
310
|
+
end
|
311
|
+
|
306
312
|
it "normal_unless sets a value even if default or override attrs are set" do
|
307
313
|
node.default[:decontamination] = true
|
308
314
|
node.override[:decontamination] = false
|
@@ -63,11 +63,16 @@ describe Chef::Provider::Package::Apt do
|
|
63
63
|
allow(@provider).to receive(:shell_out).with("dpkg", "--compare-versions", "1.0.1ubuntu2", "eq", "1.1.0").and_return(so2)
|
64
64
|
end
|
65
65
|
|
66
|
+
def get_pkg_name_str(name)
|
67
|
+
# Package name with or without anchors attached to it based on the flag.
|
68
|
+
@new_resource.anchor_package_regex ? "^#{name}$" : name
|
69
|
+
end
|
70
|
+
|
66
71
|
describe "when loading current resource" do
|
67
72
|
|
68
73
|
it "should create a current resource with the name of the new_resource" do
|
69
74
|
expect(@provider).to receive(:shell_out_compacted!).with(
|
70
|
-
"apt-cache", "policy", @new_resource.package_name,
|
75
|
+
"apt-cache", "policy", get_pkg_name_str(@new_resource.package_name),
|
71
76
|
env: { "DEBIAN_FRONTEND" => "noninteractive" },
|
72
77
|
timeout: @timeout
|
73
78
|
).and_return(@shell_out)
|
@@ -107,7 +112,7 @@ describe Chef::Provider::Package::Apt do
|
|
107
112
|
POLICY_STDOUT
|
108
113
|
policy = double(stdout: policy_out, exitstatus: 0)
|
109
114
|
expect(@provider).to receive(:shell_out_compacted!).with(
|
110
|
-
"apt-cache", "policy", "conic-smarms",
|
115
|
+
"apt-cache", "policy", get_pkg_name_str("conic-smarms"),
|
111
116
|
env: { "DEBIAN_FRONTEND" => "noninteractive" },
|
112
117
|
timeout: @timeout
|
113
118
|
).and_return(policy)
|
@@ -116,7 +121,7 @@ describe Chef::Provider::Package::Apt do
|
|
116
121
|
SHOWPKG_STDOUT
|
117
122
|
showpkg = double(stdout: showpkg_out, exitstatus: 0)
|
118
123
|
expect(@provider).to receive(:shell_out_compacted!).with(
|
119
|
-
"apt-cache", "showpkg", "conic-smarms",
|
124
|
+
"apt-cache", "showpkg", get_pkg_name_str("conic-smarms"),
|
120
125
|
env: { "DEBIAN_FRONTEND" => "noninteractive" },
|
121
126
|
timeout: @timeout
|
122
127
|
).and_return(showpkg)
|
@@ -135,7 +140,7 @@ describe Chef::Provider::Package::Apt do
|
|
135
140
|
VPKG_STDOUT
|
136
141
|
virtual_package = double(stdout: virtual_package_out, exitstatus: 0)
|
137
142
|
expect(@provider).to receive(:shell_out_compacted!).with(
|
138
|
-
"apt-cache", "policy", "libmysqlclient15-dev",
|
143
|
+
"apt-cache", "policy", get_pkg_name_str("libmysqlclient15-dev"),
|
139
144
|
env: { "DEBIAN_FRONTEND" => "noninteractive" },
|
140
145
|
timeout: @timeout
|
141
146
|
).and_return(virtual_package)
|
@@ -159,7 +164,7 @@ describe Chef::Provider::Package::Apt do
|
|
159
164
|
SHOWPKG_STDOUT
|
160
165
|
showpkg = double(stdout: showpkg_out, exitstatus: 0)
|
161
166
|
expect(@provider).to receive(:shell_out_compacted!).with(
|
162
|
-
"apt-cache", "showpkg", "libmysqlclient15-dev",
|
167
|
+
"apt-cache", "showpkg", get_pkg_name_str("libmysqlclient15-dev"),
|
163
168
|
env: { "DEBIAN_FRONTEND" => "noninteractive" },
|
164
169
|
timeout: @timeout
|
165
170
|
).and_return(showpkg)
|
@@ -178,7 +183,7 @@ describe Chef::Provider::Package::Apt do
|
|
178
183
|
RPKG_STDOUT
|
179
184
|
real_package = double(stdout: real_package_out, exitstatus: 0)
|
180
185
|
expect(@provider).to receive(:shell_out_compacted!).with(
|
181
|
-
"apt-cache", "policy", "libmysqlclient-dev",
|
186
|
+
"apt-cache", "policy", get_pkg_name_str("libmysqlclient-dev"),
|
182
187
|
env: { "DEBIAN_FRONTEND" => "noninteractive" },
|
183
188
|
timeout: @timeout
|
184
189
|
).and_return(real_package)
|
@@ -195,7 +200,7 @@ describe Chef::Provider::Package::Apt do
|
|
195
200
|
VPKG_STDOUT
|
196
201
|
virtual_package = double(stdout: virtual_package_out, exitstatus: 0)
|
197
202
|
expect(@provider).to receive(:shell_out_compacted!).with(
|
198
|
-
"apt-cache", "policy", "mp3-decoder",
|
203
|
+
"apt-cache", "policy", get_pkg_name_str("mp3-decoder"),
|
199
204
|
env: { "DEBIAN_FRONTEND" => "noninteractive" },
|
200
205
|
timeout: @timeout
|
201
206
|
).and_return(virtual_package)
|
@@ -222,7 +227,7 @@ describe Chef::Provider::Package::Apt do
|
|
222
227
|
SHOWPKG_STDOUT
|
223
228
|
showpkg = double(stdout: showpkg_out, exitstatus: 0)
|
224
229
|
expect(@provider).to receive(:shell_out_compacted!).with(
|
225
|
-
"apt-cache", "showpkg", "mp3-decoder",
|
230
|
+
"apt-cache", "showpkg", get_pkg_name_str("mp3-decoder"),
|
226
231
|
env: { "DEBIAN_FRONTEND" => "noninteractive" },
|
227
232
|
timeout: @timeout
|
228
233
|
).and_return(showpkg)
|
@@ -236,7 +241,7 @@ describe Chef::Provider::Package::Apt do
|
|
236
241
|
@new_resource.default_release("lenny-backports")
|
237
242
|
@new_resource.provider(nil)
|
238
243
|
expect(@provider).to receive(:shell_out_compacted!).with(
|
239
|
-
"apt-cache", "-o", "APT::Default-Release=lenny-backports", "policy", "irssi",
|
244
|
+
"apt-cache", "-o", "APT::Default-Release=lenny-backports", "policy", get_pkg_name_str("irssi"),
|
240
245
|
env: { "DEBIAN_FRONTEND" => "noninteractive" },
|
241
246
|
timeout: @timeout
|
242
247
|
).and_return(@shell_out)
|
@@ -246,7 +251,7 @@ describe Chef::Provider::Package::Apt do
|
|
246
251
|
it "raises an exception if a source is specified (CHEF-5113)" do
|
247
252
|
@new_resource.source "pluto"
|
248
253
|
expect(@provider).to receive(:shell_out_compacted!).with(
|
249
|
-
"apt-cache", "policy", @new_resource.package_name,
|
254
|
+
"apt-cache", "policy", get_pkg_name_str(@new_resource.package_name),
|
250
255
|
env: { "DEBIAN_FRONTEND" => "noninteractive" } ,
|
251
256
|
timeout: @timeout
|
252
257
|
).and_return(@shell_out)
|
@@ -277,7 +282,7 @@ describe Chef::Provider::Package::Apt do
|
|
277
282
|
RPKG_STDOUT
|
278
283
|
real_package = double(stdout: real_package_out, exitstatus: 0)
|
279
284
|
expect(@provider).to receive(:shell_out_compacted!).with(
|
280
|
-
"apt-cache", "policy", "libmysqlclient-dev",
|
285
|
+
"apt-cache", "policy", get_pkg_name_str("libmysqlclient-dev"),
|
281
286
|
env: { "DEBIAN_FRONTEND" => "noninteractive" },
|
282
287
|
timeout: @timeout
|
283
288
|
).and_return(real_package)
|
@@ -307,12 +312,12 @@ describe Chef::Provider::Package::Apt do
|
|
307
312
|
RPKG_STDOUT
|
308
313
|
real_package = double(stdout: real_package_out, exitstatus: 0)
|
309
314
|
expect(@provider).to receive(:shell_out_compacted!).with(
|
310
|
-
"apt-cache", "policy", @new_resource.package_name,
|
315
|
+
"apt-cache", "policy", get_pkg_name_str(@new_resource.package_name),
|
311
316
|
env: { "DEBIAN_FRONTEND" => "noninteractive" } ,
|
312
317
|
timeout: @timeout
|
313
318
|
).and_return(real_package)
|
314
319
|
expect(@provider).to receive(:shell_out_compacted!).with(
|
315
|
-
"apt-cache", "showpkg", @new_resource.package_name,
|
320
|
+
"apt-cache", "showpkg", get_pkg_name_str(@new_resource.package_name),
|
316
321
|
env: { "DEBIAN_FRONTEND" => "noninteractive" } ,
|
317
322
|
timeout: @timeout
|
318
323
|
).and_return(real_package)
|
@@ -47,13 +47,20 @@ describe Chef::Provider::Package::Chocolatey, :windows_only do
|
|
47
47
|
allow(provider).to receive(:choco_exe).and_return(choco_exe)
|
48
48
|
local_list_obj = double(stdout: local_list_stdout)
|
49
49
|
allow(provider).to receive(:shell_out_compacted!).with(choco_exe, "list", "-l", "-r", { returns: [0, 2], timeout: timeout }).and_return(local_list_obj)
|
50
|
+
allow(provider).to receive(:powershell_exec!).with("#{choco_exe} --version").and_return(double(result: "2.1.0"))
|
51
|
+
# Mock the local file system choco queries
|
52
|
+
allow(provider).to receive(:get_local_pkg_dirs).and_return(%w{chocolatey ConEmu})
|
53
|
+
allow(provider).to receive(:fetch_package_versions_local).and_return({ "chocolatey" => "0.9.9.11", "conemu" => "15.10.25.0" })
|
50
54
|
end
|
51
55
|
|
52
56
|
after(:each) do
|
53
|
-
|
57
|
+
provider.instance_variable_set(:@get_choco_version, nil)
|
54
58
|
end
|
55
59
|
|
56
60
|
def allow_remote_list(package_names, args = nil)
|
61
|
+
# Ensure that when we set this, we invalidate any cache since we're changing
|
62
|
+
# the returned data on purpose
|
63
|
+
provider.invalidate_cache
|
57
64
|
remote_list_stdout = <<~EOF
|
58
65
|
Chocolatey v0.9.9.11
|
59
66
|
chocolatey|0.9.9.11
|
@@ -63,12 +70,10 @@ describe Chef::Provider::Package::Chocolatey, :windows_only do
|
|
63
70
|
munin-node|1.6.1.20130823
|
64
71
|
EOF
|
65
72
|
remote_list_obj = double(stdout: remote_list_stdout)
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
allow(provider).to receive(:shell_out_compacted!).with(choco_exe, described_class.query_command, "-r", pkg, { returns: [0, 2], timeout: timeout }).and_return(remote_list_obj)
|
71
|
-
end
|
73
|
+
if args
|
74
|
+
allow(provider).to receive(:shell_out_compacted!).with(choco_exe, provider.query_command, "-r", *(package_names.sort + args), { returns: [0, 2], timeout: timeout }).and_return(remote_list_obj)
|
75
|
+
else
|
76
|
+
allow(provider).to receive(:shell_out_compacted!).with(choco_exe, provider.query_command, "-r", *(package_names.sort), { returns: [0, 2], timeout: timeout }).and_return(remote_list_obj)
|
72
77
|
end
|
73
78
|
end
|
74
79
|
|
@@ -84,16 +89,23 @@ describe Chef::Provider::Package::Chocolatey, :windows_only do
|
|
84
89
|
|
85
90
|
describe "choco searches change with the version" do
|
86
91
|
it "Choco V1 uses List" do
|
87
|
-
allow(
|
92
|
+
allow(provider).to receive(:powershell_exec!).with("#{choco_exe} --version").and_return(double(result: "1.4.0"))
|
88
93
|
expect(provider.query_command).to eql("list")
|
89
94
|
end
|
90
95
|
|
91
96
|
it "Choco V2 uses Search" do
|
92
|
-
allow(
|
97
|
+
allow(provider).to receive(:powershell_exec!).with("#{choco_exe} --version").and_return(double(result: "2.1.0"))
|
93
98
|
expect(provider.query_command).to eql("search")
|
94
99
|
end
|
95
100
|
end
|
96
101
|
|
102
|
+
describe "bulk_query changes the search behaviour" do
|
103
|
+
it "should respect bulk_query when getting working out what to search" do
|
104
|
+
new_resource.bulk_query(true)
|
105
|
+
expect(provider.collect_package_requests).to eql(["*"])
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
97
109
|
describe "#candidate_version" do
|
98
110
|
it "should set the candidate_version to the latest version when not pinning" do
|
99
111
|
allow_remote_list(["git"])
|
@@ -137,6 +149,13 @@ describe Chef::Provider::Package::Chocolatey, :windows_only do
|
|
137
149
|
end
|
138
150
|
end
|
139
151
|
|
152
|
+
describe "the query cache should be invalidated if the config is clean" do
|
153
|
+
it "should return false to cache_is_valid? by default" do
|
154
|
+
provider.invalidate_cache
|
155
|
+
expect(provider.cache_is_valid?).to eql(false)
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
140
159
|
describe "#load_current_resource" do
|
141
160
|
it "should return a current_resource" do
|
142
161
|
expect(provider.load_current_resource).to be_kind_of(Chef::Resource::ChocolateyPackage)
|
@@ -147,7 +166,16 @@ describe Chef::Provider::Package::Chocolatey, :windows_only do
|
|
147
166
|
expect(provider.current_resource.package_name).to eql(["git"])
|
148
167
|
end
|
149
168
|
|
150
|
-
it "should load and downcase names in the installed_packages hash" do
|
169
|
+
it "should load and downcase names in the installed_packages hash (with disk provider)" do
|
170
|
+
new_resource.use_choco_list(false)
|
171
|
+
provider.load_current_resource
|
172
|
+
expect(provider.send(:installed_packages)).to eql(
|
173
|
+
{ "chocolatey" => "0.9.9.11", "conemu" => "15.10.25.0" }
|
174
|
+
)
|
175
|
+
end
|
176
|
+
|
177
|
+
it "should load and downcase names in the installed_packages hash (with choco list provider)" do
|
178
|
+
new_resource.use_choco_list(true)
|
151
179
|
provider.load_current_resource
|
152
180
|
expect(provider.send(:installed_packages)).to eql(
|
153
181
|
{ "chocolatey" => "0.9.9.11", "conemu" => "15.10.25.0" }
|
@@ -166,7 +194,7 @@ describe Chef::Provider::Package::Chocolatey, :windows_only do
|
|
166
194
|
new_resource.package_name("package-does-not-exist")
|
167
195
|
new_resource.returns([0])
|
168
196
|
allow(provider).to receive(:shell_out_compacted!)
|
169
|
-
.with(choco_exe,
|
197
|
+
.with(choco_exe, provider.query_command, "-r", new_resource.package_name.first, { returns: new_resource.returns, timeout: timeout })
|
170
198
|
.and_raise(Mixlib::ShellOut::ShellCommandFailed, "Expected process to exit with [0], but received '2'")
|
171
199
|
expect { provider.send(:available_packages) }.to raise_error(Mixlib::ShellOut::ShellCommandFailed, "Expected process to exit with [0], but received '2'")
|
172
200
|
end
|
@@ -524,7 +552,7 @@ describe "behavior when Chocolatey is not installed" do
|
|
524
552
|
end
|
525
553
|
|
526
554
|
let(:error_regex) do
|
527
|
-
/Could not locate.*
|
555
|
+
/Could not locate.*installer.*resource.*PowerShell.*GetEnvironmentVariable/m
|
528
556
|
end
|
529
557
|
|
530
558
|
context "#choco_exe" do
|
@@ -17,10 +17,14 @@
|
|
17
17
|
#
|
18
18
|
|
19
19
|
require "spec_helper"
|
20
|
-
describe Chef::Provider::PowershellScript, "action_run" do
|
20
|
+
describe Chef::Provider::PowershellScript, "action_run", windows_only: true do
|
21
21
|
let(:events) { Chef::EventDispatch::Dispatcher.new }
|
22
22
|
|
23
|
-
let(:run_context) {
|
23
|
+
let(:run_context) {
|
24
|
+
@node = Chef::Node.new
|
25
|
+
@node.consume_external_attrs(OHAI_SYSTEM.data.dup, {})
|
26
|
+
Chef::RunContext.new(@node, {}, events)
|
27
|
+
}
|
24
28
|
|
25
29
|
let(:new_resource) do
|
26
30
|
Chef::Resource::PowershellScript.new("run some powershell code", run_context)
|
@@ -44,7 +48,7 @@ describe Chef::Provider::PowershellScript, "action_run" do
|
|
44
48
|
"C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe" -NoLogo -NonInteractive -NoProfile -ExecutionPolicy Bypass -InputFormat None -InputFormat Fabulous -File "C:\\Temp\\Script.ps1"
|
45
49
|
CMD
|
46
50
|
|
47
|
-
expect(provider.command).to eq(expected)
|
51
|
+
expect(provider.send(:command)).to eq(expected)
|
48
52
|
end
|
49
53
|
|
50
54
|
it "uses pwsh when given the pwsh interpreter" do
|
@@ -55,7 +59,99 @@ describe Chef::Provider::PowershellScript, "action_run" do
|
|
55
59
|
"pwsh" -NoLogo -NonInteractive -NoProfile -ExecutionPolicy Bypass -InputFormat None -File "C:\\Temp\\Script.ps1"
|
56
60
|
CMD
|
57
61
|
|
58
|
-
expect(provider.command).to eq(expected)
|
62
|
+
expect(provider.send(:command)).to eq(expected)
|
63
|
+
end
|
64
|
+
|
65
|
+
it "returns the script specific to the inline interpreter when using use_inline_interpreter" do
|
66
|
+
new_resource.code = "test script"
|
67
|
+
new_resource.use_inline_powershell = true
|
68
|
+
# This is a string that is ONLY in the use_inline_interpreter version of this
|
69
|
+
expect(provider.send(:powershell_wrapper_script)).to include("$interpolatedexitcode = $")
|
70
|
+
end
|
71
|
+
|
72
|
+
it "returns the script specific to the normal interpreter when not using use_inline_interpreter" do
|
73
|
+
new_resource.code = "test script"
|
74
|
+
new_resource.use_inline_powershell = false
|
75
|
+
# This is a string that is ONLY in the non use_inline_interpreter version of this
|
76
|
+
expect(provider.send(:powershell_wrapper_script)).to include("new-variable -name interpolatedexitcode -visibility private")
|
77
|
+
end
|
78
|
+
|
79
|
+
it "Correctly returns for $True for regular powershell" do
|
80
|
+
new_resource.code = "$True"
|
81
|
+
new_resource.use_inline_powershell = false
|
82
|
+
new_resource.convert_boolean_return = true
|
83
|
+
expect(provider.run_action(:run)).to eq(nil)
|
84
|
+
end
|
85
|
+
|
86
|
+
it "Correctly returns for $True for inline powershell with convert_boolean_return" do
|
87
|
+
new_resource.code = "$True"
|
88
|
+
new_resource.use_inline_powershell = true
|
89
|
+
new_resource.convert_boolean_return = true
|
90
|
+
expect(provider.run_action(:run)).to eq(nil)
|
91
|
+
end
|
92
|
+
|
93
|
+
it "Correctly throws exception for $False for regular powershell" do
|
94
|
+
new_resource.code = "$False"
|
95
|
+
new_resource.use_inline_powershell = false
|
96
|
+
new_resource.convert_boolean_return = true
|
97
|
+
expect { provider.run_action(:run) }.to raise_error(an_instance_of(Mixlib::ShellOut::ShellCommandFailed))
|
98
|
+
end
|
99
|
+
|
100
|
+
it "Correctly throws exception for $False for inline powershell" do
|
101
|
+
new_resource.code = "$False"
|
102
|
+
new_resource.use_inline_powershell = true
|
103
|
+
new_resource.convert_boolean_return = true
|
104
|
+
expect { provider.run_action(:run) }.to raise_error(an_instance_of(ChefPowerShell::PowerShellExceptions::PowerShellCommandFailed))
|
105
|
+
end
|
106
|
+
|
107
|
+
it "return 1 fails correctly for non-inline" do
|
108
|
+
new_resource.code = "return 1"
|
109
|
+
new_resource.use_inline_powershell = false
|
110
|
+
expect { provider.run_action(:run) }.to raise_error(an_instance_of(Mixlib::ShellOut::ShellCommandFailed))
|
111
|
+
end
|
112
|
+
|
113
|
+
it "return 1 fails correctly for inline" do
|
114
|
+
new_resource.code = "return 1"
|
115
|
+
new_resource.use_inline_powershell = true
|
116
|
+
expect { provider.run_action(:run) }.to raise_error(an_instance_of(ChefPowerShell::PowerShellExceptions::PowerShellCommandFailed))
|
117
|
+
end
|
118
|
+
|
119
|
+
it "return 1 is valid when returns includes 1 for non-inline" do
|
120
|
+
new_resource.code = "return 1"
|
121
|
+
new_resource.use_inline_powershell = false
|
122
|
+
new_resource.returns = [1]
|
123
|
+
expect(provider.run_action(:run)).to eq(nil)
|
124
|
+
end
|
125
|
+
it "return 1 is valid when returns includes 1 for inline" do
|
126
|
+
new_resource.code = "return 1"
|
127
|
+
new_resource.use_inline_powershell = true
|
128
|
+
new_resource.returns = [1]
|
129
|
+
expect(provider.run_action(:run)).to eq(nil)
|
130
|
+
end
|
131
|
+
|
132
|
+
it "bad powershell exceptions for non-inline" do
|
133
|
+
new_resource.code = "xyzzy"
|
134
|
+
new_resource.use_inline_powershell = false
|
135
|
+
expect { provider.run_action(:run) }.to raise_error(an_instance_of(Mixlib::ShellOut::ShellCommandFailed))
|
136
|
+
end
|
137
|
+
|
138
|
+
it "bad powershell exceptions for inline" do
|
139
|
+
new_resource.code = "xyzzy"
|
140
|
+
new_resource.use_inline_powershell = true
|
141
|
+
expect { provider.run_action(:run) }.to raise_error(an_instance_of(ChefPowerShell::PowerShellExceptions::PowerShellCommandFailed))
|
142
|
+
end
|
143
|
+
|
144
|
+
it "uses powershell for inline by default" do
|
145
|
+
new_resource.code = "$host.version.major -lt 7"
|
146
|
+
new_resource.use_inline_powershell = true
|
147
|
+
expect(provider.run_action(:run)).to eq(nil)
|
148
|
+
end
|
149
|
+
|
150
|
+
it "uses pwsh for inline when asked" do
|
151
|
+
new_resource.code = "$host.version.major -ge 7"
|
152
|
+
new_resource.use_inline_powershell = true
|
153
|
+
new_resource.interpreter = "pwsh"
|
154
|
+
expect(provider.run_action(:run)).to eq(nil)
|
59
155
|
end
|
60
156
|
end
|
61
157
|
end
|
@@ -56,6 +56,7 @@ describe Chef::Provider::Service::Systemd do
|
|
56
56
|
allow(provider).to receive(:is_active?).and_return(false)
|
57
57
|
allow(provider).to receive(:is_enabled?).and_return(false)
|
58
58
|
allow(provider).to receive(:is_masked?).and_return(false)
|
59
|
+
allow(provider).to receive(:is_static?).and_return(false)
|
59
60
|
allow(provider).to receive(:is_indirect?).and_return(false)
|
60
61
|
end
|
61
62
|
|
@@ -136,6 +136,7 @@ describe Chef::Provider::User::Linux, linux_only: true do
|
|
136
136
|
"home" => ["/home/notarealuser", "/Users/notarealuser"],
|
137
137
|
"shell" => ["/usr/bin/zsh", "/bin/bash"],
|
138
138
|
"password" => %w{abcd 12345},
|
139
|
+
"sensitive" => [true],
|
139
140
|
}
|
140
141
|
end
|
141
142
|
|
@@ -147,6 +148,15 @@ describe Chef::Provider::User::Linux, linux_only: true do
|
|
147
148
|
end
|
148
149
|
end
|
149
150
|
|
151
|
+
it "should show a blank for password if sensitive set to true" do
|
152
|
+
@new_resource.password mapping["password"][0]
|
153
|
+
@current_resource.password mapping["password"][1]
|
154
|
+
@new_resource.sensitive true
|
155
|
+
@current_resource.sensitive true
|
156
|
+
provider.compare_user
|
157
|
+
expect(provider.change_desc).to eql(["change password from ******** to ********"])
|
158
|
+
end
|
159
|
+
|
150
160
|
%w{uid gid}.each do |property|
|
151
161
|
it "should return false if string #{property} matches fixnum" do
|
152
162
|
@new_resource.send(property, "100")
|