puppet 7.8.0-x86-mingw32 → 7.9.0-x86-mingw32

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.

Files changed (146) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +5 -5
  3. data/Gemfile.lock +9 -9
  4. data/README.md +4 -4
  5. data/ext/project_data.yaml +1 -0
  6. data/install.rb +0 -4
  7. data/lib/puppet.rb +3 -3
  8. data/lib/puppet/application/filebucket.rb +1 -0
  9. data/lib/puppet/application/resource.rb +15 -2
  10. data/lib/puppet/application/ssl.rb +1 -0
  11. data/lib/puppet/defaults.rb +7 -0
  12. data/lib/puppet/environments.rb +10 -0
  13. data/lib/puppet/face/help/action.erb +1 -0
  14. data/lib/puppet/face/help/face.erb +1 -0
  15. data/lib/puppet/face/node/clean.rb +1 -1
  16. data/lib/puppet/file_system/file_impl.rb +1 -1
  17. data/lib/puppet/file_system/windows.rb +2 -2
  18. data/lib/puppet/forge.rb +3 -3
  19. data/lib/puppet/forge/cache.rb +1 -1
  20. data/lib/puppet/functions/empty.rb +8 -0
  21. data/lib/puppet/functions/strftime.rb +1 -0
  22. data/lib/puppet/functions/unwrap.rb +17 -2
  23. data/lib/puppet/indirector/resource/ral.rb +6 -1
  24. data/lib/puppet/interface/documentation.rb +1 -0
  25. data/lib/puppet/module_tool/applications/installer.rb +4 -0
  26. data/lib/puppet/module_tool/errors/shared.rb +17 -0
  27. data/lib/puppet/module_tool/tar/mini.rb +1 -1
  28. data/lib/puppet/pops/types/type_mismatch_describer.rb +1 -1
  29. data/lib/puppet/provider/exec/posix.rb +16 -4
  30. data/lib/puppet/provider/package/pip.rb +15 -3
  31. data/lib/puppet/provider/package/windows.rb +14 -1
  32. data/lib/puppet/provider/package/windows/exe_package.rb +30 -1
  33. data/lib/puppet/provider/package/windows/package.rb +2 -1
  34. data/lib/puppet/provider/parsedfile.rb +3 -0
  35. data/lib/puppet/resource/type_collection.rb +2 -0
  36. data/lib/puppet/settings.rb +30 -7
  37. data/lib/puppet/settings/config_file.rb +1 -8
  38. data/lib/puppet/settings/value_translator.rb +0 -1
  39. data/lib/puppet/type/exec.rb +16 -3
  40. data/lib/puppet/type/file/mode.rb +6 -0
  41. data/lib/puppet/type/tidy.rb +1 -1
  42. data/lib/puppet/type/user.rb +1 -1
  43. data/lib/puppet/util/monkey_patches.rb +2 -17
  44. data/lib/puppet/util/symbolic_file_mode.rb +29 -17
  45. data/lib/puppet/util/windows/sid.rb +3 -1
  46. data/lib/puppet/version.rb +1 -1
  47. data/lib/puppet/x509/cert_provider.rb +3 -21
  48. data/locales/puppet.pot +207 -171
  49. data/man/man5/puppet.conf.5 +2 -2
  50. data/man/man8/puppet-agent.8 +1 -1
  51. data/man/man8/puppet-apply.8 +1 -1
  52. data/man/man8/puppet-catalog.8 +9 -9
  53. data/man/man8/puppet-config.8 +1 -1
  54. data/man/man8/puppet-describe.8 +1 -1
  55. data/man/man8/puppet-device.8 +1 -1
  56. data/man/man8/puppet-doc.8 +1 -1
  57. data/man/man8/puppet-epp.8 +1 -1
  58. data/man/man8/puppet-facts.8 +7 -7
  59. data/man/man8/puppet-filebucket.8 +1 -1
  60. data/man/man8/puppet-generate.8 +1 -1
  61. data/man/man8/puppet-help.8 +1 -1
  62. data/man/man8/puppet-lookup.8 +1 -1
  63. data/man/man8/puppet-module.8 +1 -1
  64. data/man/man8/puppet-node.8 +5 -5
  65. data/man/man8/puppet-parser.8 +1 -1
  66. data/man/man8/puppet-plugin.8 +1 -1
  67. data/man/man8/puppet-report.8 +5 -5
  68. data/man/man8/puppet-resource.8 +1 -1
  69. data/man/man8/puppet-script.8 +1 -1
  70. data/man/man8/puppet-ssl.8 +1 -1
  71. data/man/man8/puppet.8 +2 -2
  72. data/spec/fixtures/ssl/127.0.0.1-key.pem +106 -106
  73. data/spec/fixtures/ssl/127.0.0.1.pem +48 -48
  74. data/spec/fixtures/ssl/bad-basic-constraints.pem +54 -54
  75. data/spec/fixtures/ssl/bad-int-basic-constraints.pem +51 -51
  76. data/spec/fixtures/ssl/ca.pem +52 -52
  77. data/spec/fixtures/ssl/crl.pem +25 -25
  78. data/spec/fixtures/ssl/ec-key-openssl.pem +8 -0
  79. data/spec/fixtures/ssl/ec-key-pk8.pem +5 -0
  80. data/spec/fixtures/ssl/ec-key.pem +11 -11
  81. data/spec/fixtures/ssl/ec.pem +32 -32
  82. data/spec/fixtures/ssl/encrypted-ec-key.pem +12 -12
  83. data/spec/fixtures/ssl/encrypted-key.pem +107 -107
  84. data/spec/fixtures/ssl/intermediate-agent-crl.pem +25 -25
  85. data/spec/fixtures/ssl/intermediate-agent.pem +54 -54
  86. data/spec/fixtures/ssl/intermediate-crl.pem +28 -28
  87. data/spec/fixtures/ssl/intermediate.pem +51 -51
  88. data/spec/fixtures/ssl/oid-key.pem +117 -0
  89. data/spec/fixtures/ssl/oid.pem +69 -0
  90. data/spec/fixtures/ssl/pluto-key.pem +106 -106
  91. data/spec/fixtures/ssl/pluto.pem +50 -50
  92. data/spec/fixtures/ssl/request-key.pem +106 -106
  93. data/spec/fixtures/ssl/request.pem +45 -45
  94. data/spec/fixtures/ssl/revoked-key.pem +106 -106
  95. data/spec/fixtures/ssl/revoked.pem +49 -49
  96. data/spec/fixtures/ssl/signed-key.pem +106 -106
  97. data/spec/fixtures/ssl/signed.pem +47 -47
  98. data/spec/fixtures/ssl/tampered-cert.pem +49 -49
  99. data/spec/fixtures/ssl/tampered-csr.pem +45 -45
  100. data/spec/fixtures/ssl/trusted_oid_mapping.yaml +5 -0
  101. data/spec/fixtures/ssl/unknown-127.0.0.1-key.pem +106 -106
  102. data/spec/fixtures/ssl/unknown-127.0.0.1.pem +48 -48
  103. data/spec/fixtures/ssl/unknown-ca-key.pem +106 -106
  104. data/spec/fixtures/ssl/unknown-ca.pem +52 -52
  105. data/spec/integration/application/filebucket_spec.rb +11 -0
  106. data/spec/integration/application/module_spec.rb +21 -0
  107. data/spec/integration/application/resource_spec.rb +35 -1
  108. data/spec/integration/application/ssl_spec.rb +20 -0
  109. data/spec/integration/defaults_spec.rb +5 -0
  110. data/spec/integration/environments/settings_interpolation_spec.rb +0 -4
  111. data/spec/integration/indirector/facts/facter_spec.rb +90 -36
  112. data/spec/integration/type/exec_spec.rb +70 -45
  113. data/spec/lib/puppet/test_ca.rb +5 -0
  114. data/spec/lib/puppet_spec/settings.rb +1 -0
  115. data/spec/unit/environments_spec.rb +35 -0
  116. data/spec/unit/file_system_spec.rb +6 -0
  117. data/spec/unit/functions/assert_type_spec.rb +1 -1
  118. data/spec/unit/functions/empty_spec.rb +10 -0
  119. data/spec/unit/functions/lookup_spec.rb +23 -0
  120. data/spec/unit/functions/unwrap_spec.rb +8 -0
  121. data/spec/unit/functions4_spec.rb +2 -2
  122. data/spec/unit/indirector/resource/ral_spec.rb +40 -75
  123. data/spec/unit/module_tool/applications/installer_spec.rb +13 -2
  124. data/spec/unit/parser/compiler_spec.rb +29 -0
  125. data/spec/unit/parser/templatewrapper_spec.rb +12 -2
  126. data/spec/unit/pops/loaders/dependency_loader_spec.rb +0 -9
  127. data/spec/unit/pops/parser/lexer2_spec.rb +0 -4
  128. data/spec/unit/provider/package/pip_spec.rb +37 -0
  129. data/spec/unit/provider/package/windows/exe_package_spec.rb +17 -0
  130. data/spec/unit/provider/parsedfile_spec.rb +10 -0
  131. data/spec/unit/resource/type_collection_spec.rb +16 -0
  132. data/spec/unit/resource/type_spec.rb +2 -2
  133. data/spec/unit/settings/config_file_spec.rb +1 -11
  134. data/spec/unit/settings/value_translator_spec.rb +4 -5
  135. data/spec/unit/settings_spec.rb +120 -79
  136. data/spec/unit/ssl/ssl_provider_spec.rb +18 -16
  137. data/spec/unit/type/exec_spec.rb +76 -29
  138. data/spec/unit/type/file/source_spec.rb +4 -4
  139. data/spec/unit/type/tidy_spec.rb +7 -0
  140. data/spec/unit/util/ldap/connection_spec.rb +10 -10
  141. data/spec/unit/util/ldap/manager_spec.rb +2 -2
  142. data/spec/unit/util/windows/sid_spec.rb +39 -4
  143. data/spec/unit/util_spec.rb +1 -3
  144. data/spec/unit/x509/cert_provider_spec.rb +9 -1
  145. data/tasks/generate_cert_fixtures.rake +10 -1
  146. metadata +16 -3
@@ -126,6 +126,17 @@ describe "puppet filebucket", unless: Puppet::Util::Platform.jruby? do
126
126
  end
127
127
  end
128
128
 
129
+ it "lists the local filebucket even if the environment doesn't exist locally" do
130
+ Puppet[:environment] = 'doesnotexist'
131
+ Puppet::FileSystem.mkpath(Puppet[:clientbucketdir])
132
+
133
+ filebucket.command_line.args = ['backup', '--local', backup_file]
134
+ expect {
135
+ result = filebucket.run
136
+ expect(result).to eq([backup_file])
137
+ }.to output(/Computing checksum on file/).to_stdout
138
+ end
139
+
129
140
  context 'diff', unless: Puppet::Util::Platform.windows? || Puppet::Util::Platform.jruby? do
130
141
  context 'using a remote bucket' do
131
142
  it 'outputs a diff between a local and remote file' do
@@ -65,4 +65,25 @@ describe 'puppet module', unless: Puppet::Util::Platform.jruby? do
65
65
  .and output(%r{Unable to verify the SSL certificate}).to_stderr
66
66
  end
67
67
  end
68
+
69
+ it 'prints the complete URL it tried to connect to' do
70
+ response_proc = -> (req, res) { res.status = 404 }
71
+
72
+ # create a temp cacert bundle
73
+ ssl_file = tmpfile('systemstore')
74
+ File.write(ssl_file, server.ca_cert)
75
+
76
+ Puppet::Util.withenv("SSL_CERT_FILE" => ssl_file) do
77
+ server.start_server(response_proc: response_proc) do |port|
78
+ Puppet[:module_repository] = "https://127.0.0.1:#{port}/bogus_test/puppet"
79
+
80
+ expect {
81
+ app.command_line.args = ['install', 'puppetlabs-bacula']
82
+ app.run
83
+ }.to exit_with(1)
84
+ .and output(%r{Notice: Downloading from https://127.0.0.1:#{port}}).to_stdout
85
+ .and output(%r{https://127.0.0.1:#{port}/bogus_test/puppet/v3/releases}).to_stderr
86
+ end
87
+ end
88
+ end
68
89
  end
@@ -6,7 +6,41 @@ describe "puppet resource", unless: Puppet::Util::Platform.jruby? do
6
6
 
7
7
  let(:resource) { Puppet::Application[:resource] }
8
8
 
9
- describe "when handling file and tidy types" do
9
+ context 'when given an invalid environment' do
10
+ before { Puppet[:environment] = 'badenv' }
11
+
12
+ it 'falls back to the default environment' do
13
+ Puppet[:log_level] = 'debug'
14
+
15
+ expect {
16
+ resource.run
17
+ }.to exit_with(1)
18
+ .and output(/Debug: Specified environment 'badenv' does not exist on the filesystem, defaulting to 'production'/).to_stdout
19
+ .and output(/Error: Could not run: You must specify the type to display/).to_stderr
20
+ end
21
+
22
+ it 'lists resources' do
23
+ resource.command_line.args = ['file', Puppet[:confdir]]
24
+
25
+ expect {
26
+ resource.run
27
+ }.to output(/file { '#{Puppet[:confdir]}':/).to_stdout
28
+ end
29
+
30
+ it 'lists types from the default environment' do
31
+ modulepath = File.join(Puppet[:codedir], 'modules', 'test', 'lib', 'puppet', 'type')
32
+ FileUtils.mkdir_p(modulepath)
33
+ File.write(File.join(modulepath, 'test.rb'), 'Puppet::Type.newtype(:test)')
34
+ resource.command_line.args = ['--types']
35
+
36
+ expect {
37
+ resource.run
38
+ }.to exit_with(0).and output(/test/).to_stdout
39
+ end
40
+ end
41
+
42
+
43
+ context 'when handling file and tidy types' do
10
44
  let!(:dir) { dir_containing('testdir', 'testfile' => 'contents') }
11
45
 
12
46
  it 'does not raise when generating file resources' do
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe "puppet ssl", unless: Puppet::Util::Platform.jruby? do
4
+ context "print" do
5
+ it 'translates custom oids to their long name' do
6
+ basedir = File.expand_path("#{__FILE__}/../../../fixtures/ssl")
7
+ # registering custom oids changes global state, so shell out
8
+ output =
9
+ %x{puppet ssl show \
10
+ --certname oid \
11
+ --localcacert #{basedir}/ca.pem \
12
+ --hostcrl #{basedir}/crl.pem \
13
+ --hostprivkey #{basedir}/oid-key.pem \
14
+ --hostcert #{basedir}/oid.pem \
15
+ --trusted_oid_mapping_file #{basedir}/trusted_oid_mapping.yaml 2>&1
16
+ }
17
+ expect(output).to match(/Long name:/)
18
+ end
19
+ end
20
+ end
@@ -48,6 +48,11 @@ describe "Puppet defaults" do
48
48
  it "should fail if the certname is not downcased" do
49
49
  expect { Puppet.settings[:certname] = "Host.Domain.Com" }.to raise_error(ArgumentError)
50
50
  end
51
+
52
+ it 'can set it to a value containing all digits' do
53
+ Puppet.settings[:certname] = "000000000180"
54
+ expect(Puppet.settings[:certname]).to eq("000000000180")
55
+ end
51
56
  end
52
57
 
53
58
  describe "when setting :node_name_value" do
@@ -9,10 +9,6 @@ describe "interpolating $environment" do
9
9
  let(:confdir) { Puppet[:confdir] }
10
10
  let(:cmdline_args) { ['--confdir', confdir, '--vardir', Puppet[:vardir], '--hiera_config', Puppet[:hiera_config]] }
11
11
 
12
- before(:each) do
13
- FileUtils.mkdir_p(confdir)
14
- end
15
-
16
12
  shared_examples_for "a setting that does not interpolate $environment" do
17
13
 
18
14
  before(:each) do
@@ -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
- it "adds the puppetversion fact" do
70
- allow(Facter).to receive(:reset)
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
- it "the agent_specified_environment fact is nil when not set" do
78
- expect do
79
- compile_to_catalog('notify { $::agent_specified_environment: }',
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
- Puppet.initialize_settings
91
- cat = compile_to_catalog('notify { $::agent_specified_environment: }',
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
- expect(cat.resource("Notify[bar]")).to be
94
- end
84
+ end.to raise_error(Puppet::PreformattedError)
85
+ end
95
86
 
96
- it "adds the agent_specified_environment fact when set via command-line" do
97
- Puppet.initialize_settings(['--environment', 'bar'])
98
- cat = compile_to_catalog('notify { $::agent_specified_environment: }',
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
- expect(cat.resource("Notify[bar]")).to be
101
- end
97
+ end.to raise_error(Puppet::PreformattedError)
98
+ end
102
99
 
103
- it "adds the agent_specified_environment fact, preferring cli, when set in puppet.conf and via command-line" do
104
- FileUtils.mkdir_p(Puppet[:confdir])
105
- File.open(File.join(Puppet[:confdir], 'puppet.conf'), 'w') do |f|
106
- f.puts("environment=bar")
107
- end
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
- Puppet.initialize_settings(['--environment', 'baz'])
110
- cat = compile_to_catalog('notify { $::agent_specified_environment: }',
111
- Puppet::Node.indirection.find('foo'))
112
- expect(cat.resource("Notify[baz]")).to be
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
- it "should execute the command" do
17
- exec = described_class.new :command => command, :path => ENV['PATH']
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
- catalog.add_resource exec
20
- catalog.apply
19
+ catalog.add_resource exec
20
+ catalog.apply
21
21
 
22
- expect(File.read(path)).to eq('foo')
23
- end
22
+ expect(File.read(path)).to eq('foo')
23
+ end
24
24
 
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
- )
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
- catalog.add_resource exec
33
- catalog.apply
32
+ catalog.add_resource exec
33
+ catalog.apply
34
34
 
35
- expect(Puppet::FileSystem.exist?(path)).to be_falsey
36
- end
35
+ expect(Puppet::FileSystem.exist?(path)).to be_falsey
36
+ end
37
37
 
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
- )
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
- catalog.add_resource exec
46
- catalog.apply
45
+ catalog.add_resource exec
46
+ catalog.apply
47
47
 
48
- expect(File.read(path)).to eq('foo')
49
- end
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
- 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
- )
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
- catalog.add_resource exec
59
- catalog.apply
71
+ catalog.add_resource exec
72
+ catalog.apply
60
73
 
61
- expect(File.read(path)).to eq('foo')
74
+ expect(Puppet::FileSystem.exist?(path)).to be_falsey
75
+ end
62
76
  end
63
77
 
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
- )
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
- catalog.add_resource exec
72
- catalog.apply
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
- expect(Puppet::FileSystem.exist?(path)).to be_falsey
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
@@ -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
@@ -21,6 +21,7 @@ module PuppetSpec::Settings
21
21
  end.freeze
22
22
 
23
23
  def set_puppet_conf(confdir, settings)
24
+ FileUtils.mkdir_p(confdir)
24
25
  write_file(File.join(confdir, "puppet.conf"), settings)
25
26
  end
26
27
 
@@ -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