puppet 6.23.0-universal-darwin → 6.24.0-universal-darwin
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of puppet might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CONTRIBUTING.md +5 -5
- data/Gemfile.lock +8 -8
- data/README.md +4 -4
- data/ext/project_data.yaml +1 -0
- data/lib/puppet/application/filebucket.rb +1 -0
- data/lib/puppet/application/resource.rb +15 -2
- data/lib/puppet/application/ssl.rb +1 -0
- data/lib/puppet/environments.rb +10 -0
- data/lib/puppet/face/help/action.erb +1 -0
- data/lib/puppet/face/help/face.erb +1 -0
- data/lib/puppet/face/node/clean.rb +11 -0
- data/lib/puppet/file_system/file_impl.rb +1 -1
- data/lib/puppet/file_system/windows.rb +2 -2
- data/lib/puppet/forge.rb +3 -3
- data/lib/puppet/functions/empty.rb +8 -0
- data/lib/puppet/functions/strftime.rb +1 -0
- data/lib/puppet/functions/unwrap.rb +17 -2
- data/lib/puppet/indirector/resource/ral.rb +6 -1
- data/lib/puppet/interface/documentation.rb +1 -0
- data/lib/puppet/module_tool/applications/installer.rb +4 -0
- data/lib/puppet/module_tool/errors/shared.rb +17 -0
- data/lib/puppet/pops/types/type_mismatch_describer.rb +1 -1
- data/lib/puppet/provider/exec/posix.rb +16 -4
- data/lib/puppet/provider/package/pip.rb +15 -3
- data/lib/puppet/provider/parsedfile.rb +3 -0
- data/lib/puppet/settings.rb +30 -7
- data/lib/puppet/type/exec.rb +16 -3
- data/lib/puppet/type/file/mode.rb +6 -0
- data/lib/puppet/type/tidy.rb +1 -1
- data/lib/puppet/util/symbolic_file_mode.rb +29 -17
- data/lib/puppet/util/windows/sid.rb +3 -1
- data/lib/puppet/version.rb +1 -1
- data/lib/puppet.rb +3 -3
- data/locales/puppet.pot +154 -134
- data/man/man5/puppet.conf.5 +2 -2
- data/man/man8/puppet-agent.8 +1 -1
- data/man/man8/puppet-apply.8 +1 -1
- data/man/man8/puppet-catalog.8 +9 -9
- data/man/man8/puppet-config.8 +1 -1
- data/man/man8/puppet-describe.8 +1 -1
- data/man/man8/puppet-device.8 +1 -1
- data/man/man8/puppet-doc.8 +1 -1
- data/man/man8/puppet-epp.8 +1 -1
- data/man/man8/puppet-facts.8 +8 -8
- data/man/man8/puppet-filebucket.8 +1 -1
- data/man/man8/puppet-generate.8 +1 -1
- data/man/man8/puppet-help.8 +1 -1
- data/man/man8/puppet-key.8 +7 -7
- data/man/man8/puppet-lookup.8 +1 -1
- data/man/man8/puppet-man.8 +1 -1
- data/man/man8/puppet-module.8 +1 -1
- data/man/man8/puppet-node.8 +5 -5
- data/man/man8/puppet-parser.8 +1 -1
- data/man/man8/puppet-plugin.8 +1 -1
- data/man/man8/puppet-report.8 +5 -5
- data/man/man8/puppet-resource.8 +1 -1
- data/man/man8/puppet-script.8 +1 -1
- data/man/man8/puppet-ssl.8 +1 -1
- data/man/man8/puppet-status.8 +4 -4
- data/man/man8/puppet.8 +2 -2
- data/spec/fixtures/ssl/127.0.0.1-key.pem +106 -106
- data/spec/fixtures/ssl/127.0.0.1.pem +48 -48
- data/spec/fixtures/ssl/bad-basic-constraints.pem +54 -54
- data/spec/fixtures/ssl/bad-int-basic-constraints.pem +51 -51
- data/spec/fixtures/ssl/ca.pem +52 -52
- data/spec/fixtures/ssl/crl.pem +25 -25
- data/spec/fixtures/ssl/ec-key.pem +11 -11
- data/spec/fixtures/ssl/ec.pem +32 -32
- data/spec/fixtures/ssl/encrypted-ec-key.pem +12 -12
- data/spec/fixtures/ssl/encrypted-key.pem +107 -107
- data/spec/fixtures/ssl/intermediate-agent-crl.pem +25 -25
- data/spec/fixtures/ssl/intermediate-agent.pem +54 -54
- data/spec/fixtures/ssl/intermediate-crl.pem +28 -28
- data/spec/fixtures/ssl/intermediate.pem +51 -51
- data/spec/fixtures/ssl/oid-key.pem +117 -0
- data/spec/fixtures/ssl/oid.pem +69 -0
- data/spec/fixtures/ssl/pluto-key.pem +106 -106
- data/spec/fixtures/ssl/pluto.pem +50 -50
- data/spec/fixtures/ssl/request-key.pem +106 -106
- data/spec/fixtures/ssl/request.pem +45 -45
- data/spec/fixtures/ssl/revoked-key.pem +106 -106
- data/spec/fixtures/ssl/revoked.pem +49 -49
- data/spec/fixtures/ssl/signed-key.pem +106 -106
- data/spec/fixtures/ssl/signed.pem +47 -47
- data/spec/fixtures/ssl/tampered-cert.pem +49 -49
- data/spec/fixtures/ssl/tampered-csr.pem +45 -45
- data/spec/fixtures/ssl/trusted_oid_mapping.yaml +5 -0
- data/spec/fixtures/ssl/unknown-127.0.0.1-key.pem +106 -106
- data/spec/fixtures/ssl/unknown-127.0.0.1.pem +48 -48
- data/spec/fixtures/ssl/unknown-ca-key.pem +106 -106
- data/spec/fixtures/ssl/unknown-ca.pem +52 -52
- data/spec/integration/application/filebucket_spec.rb +11 -0
- data/spec/integration/application/module_spec.rb +21 -0
- data/spec/integration/application/resource_spec.rb +35 -1
- data/spec/integration/application/ssl_spec.rb +20 -0
- data/spec/integration/environments/settings_interpolation_spec.rb +0 -4
- data/spec/integration/indirector/facts/facter_spec.rb +90 -36
- data/spec/integration/type/exec_spec.rb +70 -45
- data/spec/lib/puppet/test_ca.rb +5 -0
- data/spec/lib/puppet_spec/settings.rb +1 -0
- data/spec/unit/environments_spec.rb +35 -0
- data/spec/unit/file_system_spec.rb +6 -0
- data/spec/unit/functions/assert_type_spec.rb +1 -1
- data/spec/unit/functions/empty_spec.rb +10 -0
- data/spec/unit/functions/unwrap_spec.rb +8 -0
- data/spec/unit/functions4_spec.rb +2 -2
- data/spec/unit/indirector/resource/ral_spec.rb +40 -75
- data/spec/unit/module_tool/applications/installer_spec.rb +12 -0
- data/spec/unit/parser/templatewrapper_spec.rb +12 -2
- data/spec/unit/provider/package/pip_spec.rb +37 -0
- data/spec/unit/provider/parsedfile_spec.rb +10 -0
- data/spec/unit/settings_spec.rb +97 -56
- data/spec/unit/type/exec_spec.rb +76 -29
- data/spec/unit/type/file/source_spec.rb +4 -4
- data/spec/unit/type/tidy_spec.rb +7 -0
- data/spec/unit/util/windows/sid_spec.rb +39 -4
- data/tasks/generate_cert_fixtures.rake +10 -1
- metadata +12 -3
@@ -6,6 +6,7 @@ require 'puppet/indirector/facts/facter'
|
|
6
6
|
describe Puppet::Node::Facts::Facter do
|
7
7
|
include PuppetSpec::Files
|
8
8
|
include PuppetSpec::Compiler
|
9
|
+
include PuppetSpec::Settings
|
9
10
|
|
10
11
|
before :each do
|
11
12
|
Puppet::Node::Facts.indirection.terminus_class = :facter
|
@@ -66,49 +67,102 @@ describe Puppet::Node::Facts::Facter do
|
|
66
67
|
end
|
67
68
|
end
|
68
69
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
cat = compile_to_catalog('notify { $::puppetversion: }',
|
73
|
-
Puppet::Node.indirection.find('foo'))
|
74
|
-
expect(cat.resource("Notify[#{Puppet.version.to_s}]")).to be
|
75
|
-
end
|
70
|
+
context "adding facts" do
|
71
|
+
it "adds the puppetversion fact" do
|
72
|
+
allow(Facter).to receive(:reset)
|
76
73
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
Puppet::Node.indirection.find('foo'))
|
81
|
-
end.to raise_error(Puppet::PreformattedError)
|
82
|
-
end
|
83
|
-
|
84
|
-
it "adds the agent_specified_environment fact when set in puppet.conf" do
|
85
|
-
FileUtils.mkdir_p(Puppet[:confdir])
|
86
|
-
File.open(File.join(Puppet[:confdir], 'puppet.conf'), 'w') do |f|
|
87
|
-
f.puts("environment=bar")
|
74
|
+
cat = compile_to_catalog('notify { $::puppetversion: }',
|
75
|
+
Puppet::Node.indirection.find('foo'))
|
76
|
+
expect(cat.resource("Notify[#{Puppet.version.to_s}]")).to be
|
88
77
|
end
|
89
78
|
|
90
|
-
|
91
|
-
|
79
|
+
context "when adding the agent_specified_environment fact" do
|
80
|
+
it "does not add the fact if the agent environment is not set" do
|
81
|
+
expect do
|
82
|
+
compile_to_catalog('notify { $::agent_specified_environment: }',
|
92
83
|
Puppet::Node.indirection.find('foo'))
|
93
|
-
|
94
|
-
|
84
|
+
end.to raise_error(Puppet::PreformattedError)
|
85
|
+
end
|
95
86
|
|
96
|
-
|
97
|
-
|
98
|
-
|
87
|
+
it "does not add the fact if the agent environment is set in sections other than agent or main" do
|
88
|
+
set_puppet_conf(Puppet[:confdir], <<~CONF)
|
89
|
+
[user]
|
90
|
+
environment=bar
|
91
|
+
CONF
|
92
|
+
|
93
|
+
Puppet.initialize_settings
|
94
|
+
expect do
|
95
|
+
compile_to_catalog('notify { $::agent_specified_environment: }',
|
99
96
|
Puppet::Node.indirection.find('foo'))
|
100
|
-
|
101
|
-
|
97
|
+
end.to raise_error(Puppet::PreformattedError)
|
98
|
+
end
|
102
99
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
100
|
+
it "adds the agent_specified_environment fact when set in the agent section in puppet.conf" do
|
101
|
+
set_puppet_conf(Puppet[:confdir], <<~CONF)
|
102
|
+
[agent]
|
103
|
+
environment=bar
|
104
|
+
CONF
|
108
105
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
106
|
+
Puppet.initialize_settings
|
107
|
+
cat = compile_to_catalog('notify { $::agent_specified_environment: }',
|
108
|
+
Puppet::Node.indirection.find('foo'))
|
109
|
+
expect(cat.resource("Notify[bar]")).to be
|
110
|
+
end
|
111
|
+
|
112
|
+
it "prefers agent_specified_environment from main if set in section other than agent" do
|
113
|
+
set_puppet_conf(Puppet[:confdir], <<~CONF)
|
114
|
+
[main]
|
115
|
+
environment=baz
|
116
|
+
|
117
|
+
[user]
|
118
|
+
environment=bar
|
119
|
+
CONF
|
120
|
+
|
121
|
+
Puppet.initialize_settings
|
122
|
+
cat = compile_to_catalog('notify { $::agent_specified_environment: }',
|
123
|
+
Puppet::Node.indirection.find('foo'))
|
124
|
+
expect(cat.resource("Notify[baz]")).to be
|
125
|
+
end
|
126
|
+
|
127
|
+
it "prefers agent_specified_environment from agent if set in multiple sections" do
|
128
|
+
set_puppet_conf(Puppet[:confdir], <<~CONF)
|
129
|
+
[main]
|
130
|
+
environment=baz
|
131
|
+
|
132
|
+
[agent]
|
133
|
+
environment=bar
|
134
|
+
CONF
|
135
|
+
|
136
|
+
Puppet.initialize_settings
|
137
|
+
cat = compile_to_catalog('notify { $::agent_specified_environment: }',
|
138
|
+
Puppet::Node.indirection.find('foo'))
|
139
|
+
expect(cat.resource("Notify[bar]")).to be
|
140
|
+
end
|
141
|
+
|
142
|
+
it "adds the agent_specified_environment fact when set in puppet.conf" do
|
143
|
+
set_puppet_conf(Puppet[:confdir], 'environment=bar')
|
144
|
+
|
145
|
+
Puppet.initialize_settings
|
146
|
+
cat = compile_to_catalog('notify { $::agent_specified_environment: }',
|
147
|
+
Puppet::Node.indirection.find('foo'))
|
148
|
+
expect(cat.resource("Notify[bar]")).to be
|
149
|
+
end
|
150
|
+
|
151
|
+
it "adds the agent_specified_environment fact when set via command-line" do
|
152
|
+
Puppet.initialize_settings(['--environment', 'bar'])
|
153
|
+
cat = compile_to_catalog('notify { $::agent_specified_environment: }',
|
154
|
+
Puppet::Node.indirection.find('foo'))
|
155
|
+
expect(cat.resource("Notify[bar]")).to be
|
156
|
+
end
|
157
|
+
|
158
|
+
it "adds the agent_specified_environment fact, preferring cli, when set in puppet.conf and via command-line" do
|
159
|
+
set_puppet_conf(Puppet[:confdir], 'environment=bar')
|
160
|
+
|
161
|
+
Puppet.initialize_settings(['--environment', 'baz'])
|
162
|
+
cat = compile_to_catalog('notify { $::agent_specified_environment: }',
|
163
|
+
Puppet::Node.indirection.find('foo'))
|
164
|
+
expect(cat.resource("Notify[baz]")).to be
|
165
|
+
end
|
166
|
+
end
|
113
167
|
end
|
114
168
|
end
|
@@ -7,70 +7,95 @@ describe Puppet::Type.type(:exec), unless: Puppet::Util::Platform.jruby? do
|
|
7
7
|
|
8
8
|
let(:catalog) { Puppet::Resource::Catalog.new }
|
9
9
|
let(:path) { tmpfile('exec_provider') }
|
10
|
-
let(:command) { "ruby -e 'File.open(\"#{path}\", \"w\") { |f| f.print \"foo\" }'" }
|
11
10
|
|
12
11
|
before :each do
|
13
12
|
catalog.host_config = false
|
14
13
|
end
|
15
14
|
|
16
|
-
|
17
|
-
|
15
|
+
shared_examples_for 'a valid exec resource' do
|
16
|
+
it "should execute the command" do
|
17
|
+
exec = described_class.new :command => command, :path => ENV['PATH']
|
18
18
|
|
19
|
-
|
20
|
-
|
19
|
+
catalog.add_resource exec
|
20
|
+
catalog.apply
|
21
21
|
|
22
|
-
|
23
|
-
|
22
|
+
expect(File.read(path)).to eq('foo')
|
23
|
+
end
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
25
|
+
it "should not execute the command if onlyif returns non-zero" do
|
26
|
+
exec = described_class.new(
|
27
|
+
:command => command,
|
28
|
+
:onlyif => "ruby -e 'exit 44'",
|
29
|
+
:path => ENV['PATH']
|
30
|
+
)
|
31
31
|
|
32
|
-
|
33
|
-
|
32
|
+
catalog.add_resource exec
|
33
|
+
catalog.apply
|
34
34
|
|
35
|
-
|
36
|
-
|
35
|
+
expect(Puppet::FileSystem.exist?(path)).to be_falsey
|
36
|
+
end
|
37
37
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
38
|
+
it "should execute the command if onlyif returns zero" do
|
39
|
+
exec = described_class.new(
|
40
|
+
:command => command,
|
41
|
+
:onlyif => "ruby -e 'exit 0'",
|
42
|
+
:path => ENV['PATH']
|
43
|
+
)
|
44
44
|
|
45
|
-
|
46
|
-
|
45
|
+
catalog.add_resource exec
|
46
|
+
catalog.apply
|
47
47
|
|
48
|
-
|
49
|
-
|
48
|
+
expect(File.read(path)).to eq('foo')
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should execute the command if unless returns non-zero" do
|
52
|
+
exec = described_class.new(
|
53
|
+
:command => command,
|
54
|
+
:unless => "ruby -e 'exit 45'",
|
55
|
+
:path => ENV['PATH']
|
56
|
+
)
|
57
|
+
|
58
|
+
catalog.add_resource exec
|
59
|
+
catalog.apply
|
60
|
+
|
61
|
+
expect(File.read(path)).to eq('foo')
|
62
|
+
end
|
50
63
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
64
|
+
it "should not execute the command if unless returns zero" do
|
65
|
+
exec = described_class.new(
|
66
|
+
:command => command,
|
67
|
+
:unless => "ruby -e 'exit 0'",
|
68
|
+
:path => ENV['PATH']
|
69
|
+
)
|
57
70
|
|
58
|
-
|
59
|
-
|
71
|
+
catalog.add_resource exec
|
72
|
+
catalog.apply
|
60
73
|
|
61
|
-
|
74
|
+
expect(Puppet::FileSystem.exist?(path)).to be_falsey
|
75
|
+
end
|
62
76
|
end
|
63
77
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
78
|
+
context 'when command is a string' do
|
79
|
+
let(:command) { "ruby -e 'File.open(\"#{path}\", \"w\") { |f| f.print \"foo\" }'" }
|
80
|
+
|
81
|
+
it_behaves_like 'a valid exec resource'
|
82
|
+
end
|
83
|
+
|
84
|
+
context 'when command is an array' do
|
85
|
+
let(:command) { ['ruby', '-e', "File.open(\"#{path}\", \"w\") { |f| f.print \"foo\" }"] }
|
86
|
+
|
87
|
+
it_behaves_like 'a valid exec resource'
|
88
|
+
|
89
|
+
context 'when is invalid' do
|
90
|
+
let(:command) { [ "ruby -e 'puts 1'" ] }
|
70
91
|
|
71
|
-
|
72
|
-
|
92
|
+
it 'logs error' do
|
93
|
+
exec = described_class.new :command => command, :path => ENV['PATH']
|
94
|
+
catalog.add_resource exec
|
95
|
+
logs = catalog.apply.report.logs
|
73
96
|
|
74
|
-
|
97
|
+
expect(logs[0].message).to eql("Could not find command 'ruby -e 'puts 1''")
|
98
|
+
end
|
99
|
+
end
|
75
100
|
end
|
76
101
|
end
|
data/spec/lib/puppet/test_ca.rb
CHANGED
@@ -46,6 +46,11 @@ module Puppet
|
|
46
46
|
ext = ef.create_extension(["subjectAltName", opts[:subject_alt_names], false])
|
47
47
|
cert.add_extension(ext)
|
48
48
|
end
|
49
|
+
if exts = opts[:extensions]
|
50
|
+
exts.each do |e|
|
51
|
+
cert.add_extension(OpenSSL::X509::Extension.new(*e))
|
52
|
+
end
|
53
|
+
end
|
49
54
|
cert.sign(issuer_key, @digest)
|
50
55
|
{ private_key: key, cert: cert }
|
51
56
|
end
|
@@ -5,6 +5,14 @@ require 'puppet/file_system'
|
|
5
5
|
describe Puppet::Environments do
|
6
6
|
FS = Puppet::FileSystem
|
7
7
|
|
8
|
+
module FsRemove
|
9
|
+
def remove
|
10
|
+
@properties[:directory?] = false
|
11
|
+
@properties[:exist?] = false
|
12
|
+
@properties[:executable?] = false
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
8
16
|
before(:each) do
|
9
17
|
Puppet.settings.initialize_global_settings
|
10
18
|
Puppet[:environment_timeout] = "unlimited"
|
@@ -607,6 +615,33 @@ config_version=$vardir/random/scripts
|
|
607
615
|
cached.get(:cached)
|
608
616
|
end
|
609
617
|
|
618
|
+
it "does not list deleted environments" do
|
619
|
+
env3 = FS::MemoryFile.a_directory("env3", [
|
620
|
+
FS::MemoryFile.a_regular_file_containing("environment.conf", '')
|
621
|
+
])
|
622
|
+
|
623
|
+
envdir = FS::MemoryFile.a_directory(File.expand_path("envdir"), [
|
624
|
+
FS::MemoryFile.a_directory("env1", [
|
625
|
+
FS::MemoryFile.a_regular_file_containing("environment.conf", '')
|
626
|
+
]),
|
627
|
+
FS::MemoryFile.a_directory("env2", [
|
628
|
+
FS::MemoryFile.a_regular_file_containing("environment.conf", '')
|
629
|
+
]),
|
630
|
+
env3
|
631
|
+
])
|
632
|
+
|
633
|
+
loader_from(:filesystem => [envdir], :directory => envdir) do |loader|
|
634
|
+
cached = Puppet::Environments::Cached.new(loader)
|
635
|
+
cached.get(:env1)
|
636
|
+
cached.get(:env2)
|
637
|
+
cached.get(:env3)
|
638
|
+
env3.extend(FsRemove).remove
|
639
|
+
|
640
|
+
expect(cached.list).to contain_exactly(environment(:env1),environment(:env2))
|
641
|
+
expect(cached.get(:env3)).to be_nil
|
642
|
+
end
|
643
|
+
end
|
644
|
+
|
610
645
|
it "returns nil if env not found" do
|
611
646
|
cached_loader_from(:filesystem => [directory_tree], :directory => directory_tree.children.first) do |loader|
|
612
647
|
expect(loader.get(:doesnotexist)).to be_nil
|
@@ -290,6 +290,12 @@ describe "Puppet::FileSystem" do
|
|
290
290
|
expect(Puppet::FileSystem.read_preserve_line_endings(file)).to eq("file content \r\nsecond line \n")
|
291
291
|
end
|
292
292
|
end
|
293
|
+
|
294
|
+
it "should ignore leading BOM" do
|
295
|
+
with_file_content("\uFEFFfile content \n") do |file|
|
296
|
+
expect(Puppet::FileSystem.read_preserve_line_endings(file)).to eq("file content \n")
|
297
|
+
end
|
298
|
+
end
|
293
299
|
end
|
294
300
|
|
295
301
|
context "read without an encoding specified" do
|
@@ -28,7 +28,7 @@ describe 'the assert_type function' do
|
|
28
28
|
it 'checks that first argument is a type' do
|
29
29
|
expect do
|
30
30
|
func.call({}, 10, 10)
|
31
|
-
end.to raise_error(ArgumentError, "'assert_type' expects one of:
|
31
|
+
end.to raise_error(ArgumentError, "The function 'assert_type' was called with arguments it does not accept. It expects one of:
|
32
32
|
(Type type, Any value, Callable[Type, Type] block?)
|
33
33
|
rejected: parameter 'type' expects a Type value, got Integer
|
34
34
|
(String type_string, Any value, Callable[Type, Type] block?)
|
@@ -56,6 +56,16 @@ describe 'the empty function' do
|
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
|
+
context 'for a sensitive string it' do
|
60
|
+
it 'returns true when empty' do
|
61
|
+
expect(compile_to_catalog("notify { String(empty(Sensitive(''))): }")).to have_resource('Notify[true]')
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'returns false when not empty' do
|
65
|
+
expect(compile_to_catalog("notify { String(empty(Sensitive(' '))): }")).to have_resource('Notify[false]')
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
59
69
|
context 'for a binary it' do
|
60
70
|
it 'returns true when empty' do
|
61
71
|
expect(compile_to_catalog("notify { String(empty(Binary(''))): }")).to have_resource('Notify[true]')
|
@@ -15,6 +15,14 @@ describe 'the unwrap function' do
|
|
15
15
|
expect(eval_and_collect_notices(code)).to eq(['unwrapped value is 12345'])
|
16
16
|
end
|
17
17
|
|
18
|
+
it 'just returns a non-sensitive value' do
|
19
|
+
code = <<-CODE
|
20
|
+
$non_sensitive = "12345"
|
21
|
+
notice("value is still ${non_sensitive.unwrap}")
|
22
|
+
CODE
|
23
|
+
expect(eval_and_collect_notices(code)).to eq(['value is still 12345'])
|
24
|
+
end
|
25
|
+
|
18
26
|
it 'unwraps a sensitive value when given a code block' do
|
19
27
|
code = <<-CODE
|
20
28
|
$sensitive = Sensitive.new("12345")
|
@@ -160,7 +160,7 @@ describe 'the 4x function api' do
|
|
160
160
|
expect(func.is_a?(Puppet::Functions::Function)).to be_truthy
|
161
161
|
expect do
|
162
162
|
func.call({}, 3, 10, 3, "4")
|
163
|
-
end.to raise_error(ArgumentError, "'min' expects one of:
|
163
|
+
end.to raise_error(ArgumentError, "The function 'min' was called with arguments it does not accept. It expects one of:
|
164
164
|
(Numeric x, Numeric y, Numeric a?, Numeric b?, Numeric c*)
|
165
165
|
rejected: parameter 'b' expects a Numeric value, got String
|
166
166
|
(String x, String y, String a+)
|
@@ -231,7 +231,7 @@ describe 'the 4x function api' do
|
|
231
231
|
expect(func.is_a?(Puppet::Functions::Function)).to be_truthy
|
232
232
|
expect do
|
233
233
|
func.call({}, 10, '20')
|
234
|
-
end.to raise_error(ArgumentError, "'min' expects one of:
|
234
|
+
end.to raise_error(ArgumentError, "The function 'min' was called with arguments it does not accept. It expects one of:
|
235
235
|
(Numeric a, Numeric b)
|
236
236
|
rejected: parameter 'b' expects a Numeric value, got String
|
237
237
|
(String s1, String s2)
|
@@ -1,120 +1,85 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'puppet/indirector/resource/ral'
|
3
3
|
|
4
|
-
describe
|
4
|
+
describe Puppet::Resource::Ral do
|
5
|
+
let(:my_instance) { Puppet::Type.type(:user).new(:name => "root") }
|
6
|
+
let(:wrong_instance) { Puppet::Type.type(:user).new(:name => "bob")}
|
7
|
+
|
8
|
+
def stub_retrieve(*instances)
|
9
|
+
instances.each do |i|
|
10
|
+
allow(i).to receive(:retrieve).and_return(Puppet::Resource.new(i, nil))
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
before do
|
15
|
+
described_class.indirection.terminus_class = :ral
|
16
|
+
|
17
|
+
# make sure we don't try to retrieve current state
|
18
|
+
allow_any_instance_of(Puppet::Type.type(:user)).to receive(:retrieve).never
|
19
|
+
stub_retrieve(my_instance, wrong_instance)
|
20
|
+
end
|
21
|
+
|
5
22
|
it "disallows remote requests" do
|
6
23
|
expect(Puppet::Resource::Ral.new.allow_remote_requests?).to eq(false)
|
7
24
|
end
|
8
25
|
|
9
26
|
describe "find" do
|
10
|
-
before do
|
11
|
-
@request = double('request', :key => "user/root")
|
12
|
-
end
|
13
|
-
|
14
27
|
it "should find an existing instance" do
|
15
|
-
|
28
|
+
allow(Puppet::Type.type(:user)).to receive(:instances).and_return([ wrong_instance, my_instance, wrong_instance ])
|
16
29
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
expect(Puppet::Type.type(:user)).to receive(:instances).and_return([ wrong_instance, my_instance, wrong_instance ])
|
21
|
-
expect(Puppet::Resource::Ral.new.find(@request)).to eq(my_resource)
|
30
|
+
actual_resource = described_class.indirection.find('user/root')
|
31
|
+
expect(actual_resource.name).to eq('User/root')
|
22
32
|
end
|
23
33
|
|
24
34
|
it "should produce Puppet::Error instead of ArgumentError" do
|
25
|
-
|
26
|
-
expect{Puppet::Resource::Ral.new.find(@bad_request)}.to raise_error(Puppet::Error)
|
35
|
+
expect{described_class.indirection.find('thiswill/causeanerror')}.to raise_error(Puppet::Error)
|
27
36
|
end
|
28
37
|
|
29
38
|
it "if there is no instance, it should create one" do
|
30
|
-
|
31
|
-
root = double("Root User")
|
32
|
-
root_resource = double("Root Resource")
|
33
|
-
|
34
|
-
expect(Puppet::Type.type(:user)).to receive(:instances).and_return([ wrong_instance, wrong_instance ])
|
35
|
-
expect(Puppet::Type.type(:user)).to receive(:new).with(hash_including(name: "root")).and_return(root)
|
36
|
-
expect(root).to receive(:to_resource).and_return(root_resource)
|
37
|
-
|
38
|
-
result = Puppet::Resource::Ral.new.find(@request)
|
39
|
+
allow(Puppet::Type.type(:user)).to receive(:instances).and_return([wrong_instance])
|
39
40
|
|
40
|
-
expect(
|
41
|
+
expect(Puppet::Type.type(:user)).to receive(:new).with(hash_including(name: "root")).and_return(my_instance)
|
42
|
+
expect(described_class.indirection.find('user/root')).to be
|
41
43
|
end
|
42
44
|
end
|
43
45
|
|
44
46
|
describe "search" do
|
45
|
-
before do
|
46
|
-
@request = double('request', :key => "user/", :options => {})
|
47
|
-
end
|
48
|
-
|
49
47
|
it "should convert ral resources into regular resources" do
|
50
|
-
|
51
|
-
my_instance = double("my user", :name => "root", :to_resource => my_resource)
|
48
|
+
allow(Puppet::Type.type(:user)).to receive(:instances).and_return([ my_instance ])
|
52
49
|
|
53
|
-
|
54
|
-
expect(
|
50
|
+
actual = described_class.indirection.search('user')
|
51
|
+
expect(actual).to contain_exactly(an_instance_of(Puppet::Resource))
|
55
52
|
end
|
56
53
|
|
57
54
|
it "should filter results by name if there's a name in the key" do
|
58
|
-
|
59
|
-
allow(my_resource).to receive(:to_resource).and_return(my_resource)
|
60
|
-
allow(my_resource).to receive(:[]).with(:name).and_return("root")
|
61
|
-
|
62
|
-
wrong_resource = double("wrong resource")
|
63
|
-
allow(wrong_resource).to receive(:to_resource).and_return(wrong_resource)
|
64
|
-
allow(wrong_resource).to receive(:[]).with(:name).and_return("bad")
|
55
|
+
allow(Puppet::Type.type(:user)).to receive(:instances).and_return([ my_instance, wrong_instance ])
|
65
56
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
@request = double('request', :key => "user/root", :options => {})
|
70
|
-
|
71
|
-
expect(Puppet::Type.type(:user)).to receive(:instances).and_return([ my_instance, wrong_instance ])
|
72
|
-
expect(Puppet::Resource::Ral.new.search(@request)).to eq([my_resource])
|
57
|
+
actual = described_class.indirection.search('user/root')
|
58
|
+
expect(actual).to contain_exactly(an_object_having_attributes(name: 'User/root'))
|
73
59
|
end
|
74
60
|
|
75
61
|
it "should filter results by query parameters" do
|
76
|
-
|
77
|
-
allow(wrong_resource).to receive(:to_resource).and_return(wrong_resource)
|
78
|
-
allow(wrong_resource).to receive(:[]).with(:name).and_return("root")
|
79
|
-
|
80
|
-
my_resource = double("wrong resource", title: "wrong resource")
|
81
|
-
allow(my_resource).to receive(:to_resource).and_return(my_resource)
|
82
|
-
allow(my_resource).to receive(:[]).with(:name).and_return("bob")
|
62
|
+
allow(Puppet::Type.type(:user)).to receive(:instances).and_return([ my_instance, wrong_instance ])
|
83
63
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
@request = double('request', :key => "user/", :options => {:name => "bob"})
|
88
|
-
|
89
|
-
expect(Puppet::Type.type(:user)).to receive(:instances).and_return([ my_instance, wrong_instance ])
|
90
|
-
expect(Puppet::Resource::Ral.new.search(@request)).to eq([my_resource])
|
64
|
+
actual = described_class.indirection.search('user', name: 'bob')
|
65
|
+
expect(actual).to contain_exactly(an_object_having_attributes(name: 'User/bob'))
|
91
66
|
end
|
92
67
|
|
93
68
|
it "should return sorted results" do
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
b_resource = double("bob resource")
|
99
|
-
allow(b_resource).to receive(:to_resource).and_return(b_resource)
|
100
|
-
allow(b_resource).to receive(:title).and_return("bob")
|
101
|
-
|
102
|
-
a_instance = double("alice user", :to_resource => a_resource)
|
103
|
-
b_instance = double("bob user", :to_resource => b_resource)
|
104
|
-
|
105
|
-
@request = double('request', :key => "user/", :options => {})
|
69
|
+
a_instance = Puppet::Type.type(:user).new(:name => "alice")
|
70
|
+
b_instance = Puppet::Type.type(:user).new(:name => "bob")
|
71
|
+
stub_retrieve(a_instance, b_instance)
|
72
|
+
allow(Puppet::Type.type(:user)).to receive(:instances).and_return([ b_instance, a_instance ])
|
106
73
|
|
107
|
-
expect(
|
108
|
-
expect(Puppet::Resource::Ral.new.search(@request)).to eq([a_resource, b_resource])
|
74
|
+
expect(described_class.indirection.search('user').map(&:title)).to eq(['alice', 'bob'])
|
109
75
|
end
|
110
76
|
end
|
111
77
|
|
112
78
|
describe "save" do
|
113
79
|
it "returns a report covering the application of the given resource to the system" do
|
114
80
|
resource = Puppet::Resource.new(:notify, "the title")
|
115
|
-
ral = Puppet::Resource::Ral.new
|
116
81
|
|
117
|
-
applied_resource, report =
|
82
|
+
applied_resource, report = described_class.indirection.save(resource, nil, environment: Puppet::Node::Environment.remote(:testing))
|
118
83
|
|
119
84
|
expect(applied_resource.title).to eq("the title")
|
120
85
|
expect(report.environment).to eq("testing")
|
@@ -66,6 +66,18 @@ describe Puppet::ModuleTool::Applications::Installer, :unless => RUBY_PLATFORM =
|
|
66
66
|
graph_should_include 'pmtacceptance-stdlib', nil => v('4.1.0')
|
67
67
|
end
|
68
68
|
|
69
|
+
it 'reports a meaningful error if the name is invalid' do
|
70
|
+
app = installer('ntp', install_dir, options)
|
71
|
+
results = app.run
|
72
|
+
expect(results).to include :result => :failure
|
73
|
+
expect(results[:error][:oneline]).to eq("Could not install 'ntp', did you mean 'puppetlabs-ntp'?")
|
74
|
+
expect(results[:error][:multiline]).to eq(<<~END.chomp)
|
75
|
+
Could not install module 'ntp'
|
76
|
+
The name 'ntp' is invalid
|
77
|
+
Did you mean `puppet module install puppetlabs-ntp`?
|
78
|
+
END
|
79
|
+
end
|
80
|
+
|
69
81
|
context 'with a tarball file' do
|
70
82
|
let(:module) { fixtures('stdlib.tgz') }
|
71
83
|
|
@@ -2,6 +2,8 @@ require 'spec_helper'
|
|
2
2
|
require 'puppet/parser/templatewrapper'
|
3
3
|
|
4
4
|
describe Puppet::Parser::TemplateWrapper do
|
5
|
+
include PuppetSpec::Files
|
6
|
+
|
5
7
|
let(:known_resource_types) { Puppet::Resource::TypeCollection.new("env") }
|
6
8
|
let(:scope) do
|
7
9
|
compiler = Puppet::Parser::Compiler.new(Puppet::Node.new("mynode"))
|
@@ -41,6 +43,13 @@ describe Puppet::Parser::TemplateWrapper do
|
|
41
43
|
expect(tw.result).to eq(full_file_name)
|
42
44
|
end
|
43
45
|
|
46
|
+
it "ignores a leading BOM" do
|
47
|
+
full_file_name = given_a_template_file("bom_template", "\uFEFF<%= file %>")
|
48
|
+
|
49
|
+
tw.file = "bom_template"
|
50
|
+
expect(tw.result).to eq(full_file_name)
|
51
|
+
end
|
52
|
+
|
44
53
|
it "evaluates a given string as a template" do
|
45
54
|
expect(tw.result("template contents")).to eql("template contents")
|
46
55
|
end
|
@@ -90,11 +99,12 @@ describe Puppet::Parser::TemplateWrapper do
|
|
90
99
|
end
|
91
100
|
|
92
101
|
def given_a_template_file(name, contents)
|
93
|
-
full_name = "
|
102
|
+
full_name = tmpfile("template_#{name}")
|
103
|
+
File.binwrite(full_name, contents)
|
104
|
+
|
94
105
|
allow(Puppet::Parser::Files).to receive(:find_template).
|
95
106
|
with(name, anything()).
|
96
107
|
and_return(full_name)
|
97
|
-
allow(Puppet::FileSystem).to receive(:read_preserve_line_endings).with(full_name).and_return(contents)
|
98
108
|
|
99
109
|
full_name
|
100
110
|
end
|