puppet 6.19.0-x86-mingw32 → 6.22.1-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 (212) hide show
  1. checksums.yaml +4 -4
  2. data/CODEOWNERS +2 -16
  3. data/Gemfile +3 -1
  4. data/Gemfile.lock +50 -39
  5. data/ext/project_data.yaml +2 -2
  6. data/lib/puppet/application.rb +10 -6
  7. data/lib/puppet/application/agent.rb +1 -0
  8. data/lib/puppet/application/apply.rb +3 -2
  9. data/lib/puppet/application/device.rb +1 -0
  10. data/lib/puppet/application/filebucket.rb +2 -2
  11. data/lib/puppet/application/script.rb +1 -0
  12. data/lib/puppet/application/ssl.rb +11 -0
  13. data/lib/puppet/application_support.rb +7 -0
  14. data/lib/puppet/configurer.rb +28 -18
  15. data/lib/puppet/defaults.rb +46 -20
  16. data/lib/puppet/environments.rb +54 -55
  17. data/lib/puppet/face/config.rb +10 -0
  18. data/lib/puppet/face/epp.rb +12 -2
  19. data/lib/puppet/face/facts.rb +158 -0
  20. data/lib/puppet/ffi/posix.rb +10 -0
  21. data/lib/puppet/ffi/posix/constants.rb +14 -0
  22. data/lib/puppet/ffi/posix/functions.rb +24 -0
  23. data/lib/puppet/file_system/memory_file.rb +8 -1
  24. data/lib/puppet/file_system/windows.rb +2 -0
  25. data/lib/puppet/functions/epp.rb +1 -0
  26. data/lib/puppet/functions/inline_epp.rb +1 -0
  27. data/lib/puppet/functions/partition.rb +8 -0
  28. data/lib/puppet/indirector/fact_search.rb +60 -0
  29. data/lib/puppet/indirector/facts/facter.rb +24 -3
  30. data/lib/puppet/indirector/facts/json.rb +27 -0
  31. data/lib/puppet/indirector/facts/yaml.rb +3 -58
  32. data/lib/puppet/indirector/json.rb +5 -1
  33. data/lib/puppet/indirector/node/json.rb +8 -0
  34. data/lib/puppet/indirector/report/json.rb +34 -0
  35. data/lib/puppet/module_tool/applications/installer.rb +48 -2
  36. data/lib/puppet/module_tool/errors/shared.rb +17 -2
  37. data/lib/puppet/network/formats.rb +69 -1
  38. data/lib/puppet/network/http/factory.rb +4 -0
  39. data/lib/puppet/pal/pal_impl.rb +70 -17
  40. data/lib/puppet/parser/ast/leaf.rb +3 -2
  41. data/lib/puppet/parser/templatewrapper.rb +1 -1
  42. data/lib/puppet/pops/evaluator/deferred_resolver.rb +5 -3
  43. data/lib/puppet/pops/evaluator/evaluator_impl.rb +22 -3
  44. data/lib/puppet/pops/model/ast_transformer.rb +1 -1
  45. data/lib/puppet/property/list.rb +1 -1
  46. data/lib/puppet/provider/group/groupadd.rb +13 -8
  47. data/lib/puppet/provider/package/apt.rb +34 -2
  48. data/lib/puppet/provider/package/aptitude.rb +6 -0
  49. data/lib/puppet/provider/package/dnfmodule.rb +1 -1
  50. data/lib/puppet/provider/service/debian.rb +2 -0
  51. data/lib/puppet/provider/service/systemd.rb +1 -1
  52. data/lib/puppet/provider/user/aix.rb +2 -2
  53. data/lib/puppet/provider/user/useradd.rb +62 -8
  54. data/lib/puppet/reference/configuration.rb +6 -5
  55. data/lib/puppet/settings.rb +43 -15
  56. data/lib/puppet/settings/alias_setting.rb +37 -0
  57. data/lib/puppet/settings/base_setting.rb +26 -2
  58. data/lib/puppet/settings/environment_conf.rb +1 -0
  59. data/lib/puppet/type/package.rb +3 -3
  60. data/lib/puppet/util/autoload.rb +1 -8
  61. data/lib/puppet/util/fact_dif.rb +81 -0
  62. data/lib/puppet/util/monkey_patches.rb +7 -0
  63. data/lib/puppet/util/posix.rb +54 -5
  64. data/lib/puppet/util/rubygems.rb +5 -1
  65. data/lib/puppet/util/windows/adsi.rb +46 -0
  66. data/lib/puppet/util/windows/api_types.rb +1 -1
  67. data/lib/puppet/util/windows/principal.rb +9 -2
  68. data/lib/puppet/util/windows/service.rb +1 -1
  69. data/lib/puppet/util/windows/sid.rb +4 -2
  70. data/lib/puppet/version.rb +1 -1
  71. data/locales/puppet.pot +295 -219
  72. data/man/man5/puppet.conf.5 +15 -7
  73. data/man/man8/puppet-agent.8 +2 -2
  74. data/man/man8/puppet-apply.8 +2 -2
  75. data/man/man8/puppet-catalog.8 +1 -1
  76. data/man/man8/puppet-config.8 +1 -1
  77. data/man/man8/puppet-describe.8 +1 -1
  78. data/man/man8/puppet-device.8 +2 -2
  79. data/man/man8/puppet-doc.8 +1 -1
  80. data/man/man8/puppet-epp.8 +1 -1
  81. data/man/man8/puppet-facts.8 +90 -1
  82. data/man/man8/puppet-filebucket.8 +3 -3
  83. data/man/man8/puppet-generate.8 +1 -1
  84. data/man/man8/puppet-help.8 +1 -1
  85. data/man/man8/puppet-key.8 +1 -1
  86. data/man/man8/puppet-lookup.8 +1 -1
  87. data/man/man8/puppet-man.8 +1 -1
  88. data/man/man8/puppet-module.8 +1 -1
  89. data/man/man8/puppet-node.8 +4 -1
  90. data/man/man8/puppet-parser.8 +1 -1
  91. data/man/man8/puppet-plugin.8 +1 -1
  92. data/man/man8/puppet-report.8 +4 -1
  93. data/man/man8/puppet-resource.8 +1 -1
  94. data/man/man8/puppet-script.8 +2 -2
  95. data/man/man8/puppet-ssl.8 +5 -1
  96. data/man/man8/puppet-status.8 +1 -1
  97. data/man/man8/puppet.8 +2 -2
  98. data/spec/fixtures/integration/application/agent/cached_deferred_catalog.json +91 -0
  99. data/spec/fixtures/unit/provider/service/systemd/list_unit_files_services_vendor_preset +9 -0
  100. data/spec/fixtures/unit/provider/user/aix/aix_passwd_file.out +4 -0
  101. data/spec/integration/application/agent_spec.rb +160 -3
  102. data/spec/integration/application/apply_spec.rb +19 -0
  103. data/spec/integration/application/plugin_spec.rb +1 -1
  104. data/spec/integration/defaults_spec.rb +0 -7
  105. data/spec/integration/environments/setting_hooks_spec.rb +1 -1
  106. data/spec/integration/http/client_spec.rb +12 -0
  107. data/spec/integration/indirector/direct_file_server_spec.rb +1 -3
  108. data/spec/integration/resource/type_collection_spec.rb +2 -6
  109. data/spec/integration/transaction_spec.rb +4 -9
  110. data/spec/integration/util/windows/adsi_spec.rb +21 -1
  111. data/spec/integration/util/windows/principal_spec.rb +21 -0
  112. data/spec/integration/util/windows/registry_spec.rb +6 -10
  113. data/spec/lib/puppet_spec/settings.rb +6 -1
  114. data/spec/spec_helper.rb +12 -5
  115. data/spec/unit/agent_spec.rb +8 -6
  116. data/spec/unit/application/agent_spec.rb +0 -1
  117. data/spec/unit/application/config_spec.rb +224 -4
  118. data/spec/unit/application/facts_spec.rb +482 -3
  119. data/spec/unit/application/filebucket_spec.rb +0 -2
  120. data/spec/unit/application/ssl_spec.rb +23 -0
  121. data/spec/unit/application_spec.rb +51 -9
  122. data/spec/unit/confine/feature_spec.rb +1 -1
  123. data/spec/unit/confine_spec.rb +8 -2
  124. data/spec/unit/defaults_spec.rb +36 -1
  125. data/spec/unit/environments_spec.rb +221 -68
  126. data/spec/unit/face/config_spec.rb +27 -32
  127. data/spec/unit/face/facts_spec.rb +4 -0
  128. data/spec/unit/face/node_spec.rb +0 -11
  129. data/spec/unit/file_serving/configuration/parser_spec.rb +0 -1
  130. data/spec/unit/file_serving/metadata_spec.rb +3 -3
  131. data/spec/unit/file_serving/terminus_helper_spec.rb +11 -4
  132. data/spec/unit/file_system_spec.rb +9 -0
  133. data/spec/unit/forge/module_release_spec.rb +2 -7
  134. data/spec/unit/functions/inline_epp_spec.rb +26 -1
  135. data/spec/unit/http/service/compiler_spec.rb +49 -0
  136. data/spec/unit/http/service_spec.rb +1 -1
  137. data/spec/unit/indirector/face_spec.rb +0 -1
  138. data/spec/unit/indirector/facts/facter_spec.rb +95 -1
  139. data/spec/unit/indirector/facts/json_spec.rb +255 -0
  140. data/spec/unit/indirector/file_bucket_file/selector_spec.rb +26 -8
  141. data/spec/unit/indirector/indirection_spec.rb +8 -12
  142. data/spec/unit/indirector/key/file_spec.rb +0 -1
  143. data/spec/unit/indirector/node/json_spec.rb +33 -0
  144. data/spec/{integration/indirector/report/yaml.rb → unit/indirector/report/json_spec.rb} +13 -24
  145. data/spec/unit/indirector/report/yaml_spec.rb +72 -8
  146. data/spec/unit/indirector_spec.rb +2 -2
  147. data/spec/unit/module_tool/applications/installer_spec.rb +66 -0
  148. data/spec/unit/network/authconfig_spec.rb +0 -3
  149. data/spec/unit/network/formats_spec.rb +41 -0
  150. data/spec/unit/network/http/api/indirected_routes_spec.rb +0 -9
  151. data/spec/unit/network/http/factory_spec.rb +19 -0
  152. data/spec/unit/network/http/handler_spec.rb +0 -5
  153. data/spec/unit/parser/compiler_spec.rb +3 -19
  154. data/spec/unit/parser/resource_spec.rb +14 -8
  155. data/spec/unit/parser/templatewrapper_spec.rb +4 -3
  156. data/spec/unit/pops/evaluator/deferred_resolver_spec.rb +20 -0
  157. data/spec/unit/property_spec.rb +1 -0
  158. data/spec/unit/provider/group/groupadd_spec.rb +5 -2
  159. data/spec/unit/provider/nameservice_spec.rb +66 -65
  160. data/spec/unit/provider/package/apt_spec.rb +28 -23
  161. data/spec/unit/provider/package/aptitude_spec.rb +1 -1
  162. data/spec/unit/provider/package/base_spec.rb +6 -5
  163. data/spec/unit/provider/package/dnfmodule_spec.rb +10 -1
  164. data/spec/unit/provider/package/pacman_spec.rb +18 -12
  165. data/spec/unit/provider/package/pip_spec.rb +6 -11
  166. data/spec/unit/provider/package/pkgdmg_spec.rb +0 -4
  167. data/spec/unit/provider/service/systemd_spec.rb +11 -0
  168. data/spec/unit/provider/user/aix_spec.rb +5 -0
  169. data/spec/unit/provider/user/hpux_spec.rb +1 -1
  170. data/spec/unit/provider/user/pw_spec.rb +2 -0
  171. data/spec/unit/provider/user/useradd_spec.rb +71 -3
  172. data/spec/unit/provider_spec.rb +8 -10
  173. data/spec/unit/puppet_pal_catalog_spec.rb +45 -0
  174. data/spec/unit/resource/capability_finder_spec.rb +6 -1
  175. data/spec/unit/resource/catalog_spec.rb +1 -1
  176. data/spec/unit/resource/type_spec.rb +1 -1
  177. data/spec/unit/resource_spec.rb +11 -10
  178. data/spec/unit/settings_spec.rb +543 -228
  179. data/spec/unit/ssl/base_spec.rb +0 -1
  180. data/spec/unit/ssl/host_spec.rb +0 -5
  181. data/spec/unit/ssl/ssl_provider_spec.rb +14 -8
  182. data/spec/unit/transaction/additional_resource_generator_spec.rb +3 -7
  183. data/spec/unit/transaction/event_manager_spec.rb +14 -11
  184. data/spec/unit/transaction_spec.rb +13 -4
  185. data/spec/unit/type/file/content_spec.rb +0 -1
  186. data/spec/unit/type/file/selinux_spec.rb +0 -2
  187. data/spec/unit/type/file_spec.rb +0 -6
  188. data/spec/unit/type/group_spec.rb +13 -6
  189. data/spec/unit/type/resources_spec.rb +7 -7
  190. data/spec/unit/type/service_spec.rb +1 -1
  191. data/spec/unit/type/tidy_spec.rb +0 -1
  192. data/spec/unit/type_spec.rb +2 -2
  193. data/spec/unit/util/at_fork_spec.rb +2 -2
  194. data/spec/unit/util/autoload_spec.rb +5 -1
  195. data/spec/unit/util/backups_spec.rb +1 -2
  196. data/spec/unit/util/execution_spec.rb +15 -11
  197. data/spec/unit/util/inifile_spec.rb +6 -14
  198. data/spec/unit/util/log_spec.rb +8 -7
  199. data/spec/unit/util/logging_spec.rb +3 -3
  200. data/spec/unit/util/posix_spec.rb +363 -15
  201. data/spec/unit/util/rubygems_spec.rb +2 -2
  202. data/spec/unit/util/selinux_spec.rb +76 -52
  203. data/spec/unit/util/storage_spec.rb +3 -1
  204. data/spec/unit/util/suidmanager_spec.rb +44 -41
  205. data/spec/unit/util/windows/sid_spec.rb +6 -0
  206. data/spec/unit/util_spec.rb +13 -6
  207. metadata +31 -16
  208. data/spec/integration/application/config_spec.rb +0 -74
  209. data/spec/lib/matchers/include.rb +0 -27
  210. data/spec/lib/matchers/include_spec.rb +0 -32
  211. data/spec/unit/face/catalog_spec.rb +0 -6
  212. data/spec/unit/face/module_spec.rb +0 -3
@@ -138,7 +138,7 @@ trace = true
138
138
  Puppet[:log_level] = 'info'
139
139
  allow(Puppet::FileSystem).to receive(:open).with(path, anything, anything).and_yield(StringIO.new)
140
140
  expect {
141
- subject.set('foo', 'bar')
141
+ subject.set('certname', 'bar')
142
142
  }.to output("\e[1;33mResolving settings from section 'main' in environment 'production'\e[0m\n").to_stderr
143
143
  end
144
144
 
@@ -146,19 +146,19 @@ trace = true
146
146
  Puppet[:log_level] = 'info'
147
147
  allow(Puppet::FileSystem).to receive(:open).with(path, anything, anything).and_yield(StringIO.new)
148
148
  expect {
149
- subject.set('foo', 'bar', {:section => "baz"})
149
+ subject.set('certname', 'bar', {:section => "baz"})
150
150
  }.to output("\e[1;33mResolving settings from section 'baz' in environment 'production'\e[0m\n").to_stderr
151
151
  end
152
152
 
153
153
  it "writes to the correct puppet config file" do
154
154
  expect(Puppet::FileSystem).to receive(:open).with(path, anything, anything)
155
- subject.set('foo', 'bar')
155
+ subject.set('certname', 'bar')
156
156
  end
157
157
 
158
158
  it "creates a config file if one does not exist" do
159
159
  allow(Puppet::FileSystem).to receive(:open).with(path, anything, anything).and_yield(StringIO.new)
160
160
  expect(Puppet::FileSystem).to receive(:touch).with(path)
161
- subject.set('foo', 'bar')
161
+ subject.set('certname', 'bar')
162
162
  end
163
163
 
164
164
  it "sets the supplied config/value in the default section (main)" do
@@ -167,8 +167,8 @@ trace = true
167
167
  manipulator = Puppet::Settings::IniFile::Manipulator.new(config)
168
168
  allow(Puppet::Settings::IniFile::Manipulator).to receive(:new).and_return(manipulator)
169
169
 
170
- expect(manipulator).to receive(:set).with("main", "foo", "bar")
171
- subject.set('foo', 'bar')
170
+ expect(manipulator).to receive(:set).with("main", "certname", "bar")
171
+ subject.set('certname', 'bar')
172
172
  end
173
173
 
174
174
  it "sets the value in the supplied section" do
@@ -177,8 +177,8 @@ trace = true
177
177
  manipulator = Puppet::Settings::IniFile::Manipulator.new(config)
178
178
  allow(Puppet::Settings::IniFile::Manipulator).to receive(:new).and_return(manipulator)
179
179
 
180
- expect(manipulator).to receive(:set).with("baz", "foo", "bar")
181
- subject.set('foo', 'bar', {:section => "baz"})
180
+ expect(manipulator).to receive(:set).with("baz", "certname", "bar")
181
+ subject.set('certname', 'bar', {:section => "baz"})
182
182
  end
183
183
 
184
184
  it "does not duplicate an existing default section when a section is not specified" do
@@ -190,53 +190,48 @@ trace = true
190
190
  myfile = StringIO.new(contents)
191
191
  allow(Puppet::FileSystem).to receive(:open).with(path, anything, anything).and_yield(myfile)
192
192
 
193
- subject.set('foo', 'bar')
193
+ subject.set('certname', 'bar')
194
194
 
195
- expect(myfile.string).to match(/foo = bar/)
195
+ expect(myfile.string).to match(/certname = bar/)
196
196
  expect(myfile.string).not_to match(/main.*main/)
197
197
  end
198
198
 
199
199
  it "opens the file with UTF-8 encoding" do
200
200
  expect(Puppet::FileSystem).to receive(:open).with(path, nil, 'r+:UTF-8')
201
- subject.set('foo', 'bar')
201
+ subject.set('certname', 'bar')
202
202
  end
203
203
 
204
204
  it "sets settings into the [server] section when setting [master] section settings" do
205
- initial_contents = <<-CONFIG
206
- [master]
207
- setting = old_setting_value
208
- untouched_setting = value
205
+ initial_contents = <<~CONFIG
206
+ [master]
207
+ node_terminus = none
208
+ reports = log
209
209
  CONFIG
210
210
 
211
211
  myinitialfile = StringIO.new(initial_contents)
212
212
  allow(Puppet::FileSystem).to receive(:open).with(path, anything, anything).and_yield(myinitialfile)
213
213
 
214
214
  expect {
215
- subject.set('setting', 'new_setting_value', {:section => 'master'})
216
- }.to output("Deleted setting from 'master': 'setting = old_setting_value', and adding it to 'server' section\n").to_stdout
217
- modified_content = <<-CONFIG
218
- [master]
219
- untouched_setting = value
220
- [server]
221
- setting = new_setting_value
222
- CONFIG
215
+ subject.set('node_terminus', 'exec', {:section => 'master'})
216
+ }.to output("Deleted setting from 'master': 'node_terminus = none', and adding it to 'server' section\n").to_stdout
223
217
 
224
- mymodifiedfile = StringIO.new(modified_content)
225
- expect(myinitialfile.string).to match(mymodifiedfile.string)
218
+ expect(myinitialfile.string).to match(<<~CONFIG)
219
+ [master]
220
+ reports = log
221
+ [server]
222
+ node_terminus = exec
223
+ CONFIG
226
224
  end
227
225
 
228
226
  it "setting [master] section settings, sets settings into [server] section instead" do
229
227
  myinitialfile = StringIO.new("")
230
228
  allow(Puppet::FileSystem).to receive(:open).with(path, anything, anything).and_yield(myinitialfile)
231
- subject.set('setting_name', 'value', {:section => 'master'})
229
+ subject.set('node_terminus', 'exec', {:section => 'master'})
232
230
 
233
- expected_content = <<-CONFIG
234
- [server]
235
- setting_name = value
231
+ expect(myinitialfile.string).to match(<<~CONFIG)
232
+ [server]
233
+ node_terminus = exec
236
234
  CONFIG
237
-
238
- myexpectedfile = StringIO.new(expected_content)
239
- expect(myinitialfile.string).to match(myexpectedfile.string)
240
235
  end
241
236
  end
242
237
 
@@ -71,4 +71,8 @@ CONF
71
71
  log.message =~ /Uploading facts for '.*' to 'puppet\.server\.test'/}
72
72
  end
73
73
  end
74
+
75
+ describe "#show" do
76
+ it { is_expected.to be_action :show }
77
+ end
74
78
  end
@@ -15,13 +15,6 @@ describe Puppet::Face[:node, '0.0.1'] do
15
15
  end
16
16
 
17
17
  describe 'when running #clean' do
18
- before :each do
19
- allow(Puppet::Node::Facts.indirection).to receive(:terminus_class=)
20
- allow(Puppet::Node::Facts.indirection).to receive(:cache_class=)
21
- allow(Puppet::Node).to receive(:terminus_class=)
22
- allow(Puppet::Node).to receive(:cache_class=)
23
- end
24
-
25
18
  it 'should invoke #cleanup' do
26
19
  expect(subject).to receive(:cleanup).with('hostname')
27
20
  subject.clean('hostname')
@@ -30,10 +23,6 @@ describe Puppet::Face[:node, '0.0.1'] do
30
23
 
31
24
  describe "clean action" do
32
25
  before :each do
33
- allow(Puppet::Node::Facts.indirection).to receive(:terminus_class=)
34
- allow(Puppet::Node::Facts.indirection).to receive(:cache_class=)
35
- allow(Puppet::Node).to receive(:terminus_class=)
36
- allow(Puppet::Node).to receive(:cache_class=)
37
26
  allow(subject).to receive(:cleanup)
38
27
  end
39
28
 
@@ -87,7 +87,6 @@ describe Puppet::FileServing::Configuration::Parser do
87
87
  before do
88
88
  @mount = double('testmount', :name => "one", :validate => true)
89
89
  expect(Puppet::FileServing::Mount::File).to receive(:new).with("one").and_return(@mount)
90
- allow(@parser).to receive(:add_modules_mount)
91
90
  end
92
91
 
93
92
  it "should set the mount path to the path attribute from that section" do
@@ -266,9 +266,9 @@ describe Puppet::FileServing::Metadata, :uses_checksums => true do
266
266
  path = tmpfile('bar')
267
267
  FileUtils.touch(path)
268
268
 
269
- allow(Puppet::Util::Windows::Security).to receive(:get_owner).with(path, :use).and_raise(invalid_error)
270
- allow(Puppet::Util::Windows::Security).to receive(:get_group).with(path, :use).and_raise(invalid_error)
271
- allow(Puppet::Util::Windows::Security).to receive(:get_mode).with(path, :use).and_raise(invalid_error)
269
+ allow(Puppet::Util::Windows::Security).to receive(:get_owner).with(path).and_raise(invalid_error)
270
+ allow(Puppet::Util::Windows::Security).to receive(:get_group).with(path).and_raise(invalid_error)
271
+ allow(Puppet::Util::Windows::Security).to receive(:get_mode).with(path).and_raise(invalid_error)
272
272
 
273
273
  stat = Puppet::FileSystem.stat(path)
274
274
 
@@ -2,13 +2,20 @@ require 'spec_helper'
2
2
 
3
3
  require 'puppet/file_serving/terminus_helper'
4
4
 
5
+ class Puppet::FileServing::TestHelper
6
+ include Puppet::FileServing::TerminusHelper
7
+
8
+ attr_reader :model
9
+
10
+ def initialize(model)
11
+ @model = model
12
+ end
13
+ end
14
+
5
15
  describe Puppet::FileServing::TerminusHelper do
6
16
  before do
7
- @helper = Object.new
8
- @helper.extend(Puppet::FileServing::TerminusHelper)
9
-
10
17
  @model = double('model')
11
- allow(@helper).to receive(:model).and_return(@model)
18
+ @helper = Puppet::FileServing::TestHelper.new(@model)
12
19
 
13
20
  @request = double('request', :key => "url", :options => {})
14
21
 
@@ -999,6 +999,15 @@ describe "Puppet::FileSystem" do
999
999
  Puppet::FileSystem.replace_file(dest, 0755) { |_| }
1000
1000
  }.to raise_error(ArgumentError, /Only modes 0644, 0640, 0660, and 0440 are allowed/)
1001
1001
  end
1002
+
1003
+ it 'falls back to fully qualified user name when sid retrieval fails' do
1004
+ current_user_sid = Puppet::Util::Windows::SID.name_to_sid(Puppet::Util::Windows::ADSI::User.current_user_name)
1005
+ allow(Puppet::Util::Windows::SID).to receive(:name_to_sid).with(Puppet::Util::Windows::ADSI::User.current_user_name).and_return(nil, current_user_sid)
1006
+ allow(Puppet::Util::Windows::SID).to receive(:name_to_sid).with(Puppet::Util::Windows::ADSI::User.current_sam_compatible_user_name).and_call_original
1007
+
1008
+ Puppet::FileSystem.replace_file(dest, 0644) { |f| f.write(content) }
1009
+ expects_public_file(dest)
1010
+ end
1002
1011
  end
1003
1012
  end
1004
1013
 
@@ -22,13 +22,8 @@ describe Puppet::Forge::ModuleRelease do
22
22
  let(:uri) { " "}
23
23
  let(:release) { Puppet::Forge::ModuleRelease.new(ssl_repository, JSON.parse(release_json)) }
24
24
 
25
- let(:mock_file) {
26
- mock_io = StringIO.new
27
- allow(mock_io).to receive(:path).and_return('/dev/null')
28
- mock_io
29
- }
30
-
31
- let(:mock_dir) { '/tmp' }
25
+ let(:mock_file) { double('file', path: '/dev/null') }
26
+ let(:mock_dir) { tmpdir('dir') }
32
27
 
33
28
  let(:destination) { tmpfile('forge_module_release') }
34
29
 
@@ -1,8 +1,10 @@
1
-
2
1
  require 'spec_helper'
3
2
 
3
+ require 'puppet_spec/compiler'
4
+
4
5
  describe "the inline_epp function" do
5
6
  include PuppetSpec::Files
7
+ include PuppetSpec::Compiler
6
8
 
7
9
  let :node do Puppet::Node.new('localhost') end
8
10
  let :compiler do Puppet::Parser::Compiler.new(node) end
@@ -73,6 +75,29 @@ describe "the inline_epp function" do
73
75
  expect(eval_template("string was: <%= $string %>")).to eq("string was: the string value")
74
76
  end
75
77
 
78
+ context "when using Sensitive" do
79
+ it "returns an unwrapped sensitive value as a String" do
80
+ expect(eval_and_collect_notices(<<~END)).to eq(["opensesame"])
81
+ notice(inline_epp("<%= Sensitive('opensesame').unwrap %>"))
82
+ END
83
+ end
84
+
85
+ it "rewraps a sensitive value" do
86
+ # note entire result is redacted, not just sensitive part
87
+ expect(eval_and_collect_notices(<<~END)).to eq(["Sensitive [value redacted]"])
88
+ notice(inline_epp("This is sensitive <%= Sensitive('opensesame') %>"))
89
+ END
90
+ end
91
+
92
+ it "can be double wrapped" do
93
+ catalog = compile_to_catalog(<<~END)
94
+ notify { 'title':
95
+ message => Sensitive(inline_epp("<%= Sensitive('opensesame') %>"))
96
+ }
97
+ END
98
+ expect(catalog.resource(:notify, 'title')['message']).to eq('opensesame')
99
+ end
100
+ end
76
101
 
77
102
  def eval_template_with_args(content, args_hash)
78
103
  epp_function.call(scope, content, args_hash)
@@ -131,6 +131,26 @@ describe Puppet::HTTP::Service::Compiler do
131
131
  subject.post_catalog(certname, environment: 'production', facts: facts, checksum_type: %w[sha256 sha384])
132
132
  end
133
133
 
134
+ it 'does not accept msgpack by default' do
135
+ stub_request(:post, uri)
136
+ .with(headers: {'Accept' => 'application/vnd.puppet.rich+json, application/json, text/pson'})
137
+ .to_return(**catalog_response)
138
+
139
+ allow(Puppet.features).to receive(:msgpack?).and_return(false)
140
+
141
+ subject.post_catalog(certname, environment: environment, facts: facts)
142
+ end
143
+
144
+ it 'accepts msgpack & rich_json_msgpack if the gem is present' do
145
+ stub_request(:post, uri)
146
+ .with(headers: {'Accept' => 'application/vnd.puppet.rich+json, application/json, application/vnd.puppet.rich+msgpack, application/x-msgpack, text/pson'})
147
+ .to_return(**catalog_response)
148
+
149
+ allow(Puppet.features).to receive(:msgpack?).and_return(true)
150
+
151
+ subject.post_catalog(certname, environment: environment, facts: facts)
152
+ end
153
+
134
154
  it 'returns a deserialized catalog' do
135
155
  stub_request(:post, uri)
136
156
  .to_return(**catalog_response)
@@ -140,6 +160,35 @@ describe Puppet::HTTP::Service::Compiler do
140
160
  expect(cat.name).to eq(certname)
141
161
  end
142
162
 
163
+ it 'deserializes the catalog from msgpack', if: Puppet.features.msgpack? do
164
+ body = catalog.to_msgpack
165
+ formatter = Puppet::Network::FormatHandler.format(:msgpack)
166
+ catalog_response = { body: body, headers: {'Content-Type' => formatter.mime }}
167
+
168
+ stub_request(:post, uri)
169
+ .to_return(**catalog_response)
170
+
171
+ _, cat = subject.post_catalog(certname, environment: 'production', facts: facts)
172
+ expect(cat).to be_a(Puppet::Resource::Catalog)
173
+ expect(cat.name).to eq(certname)
174
+ end
175
+
176
+ it 'deserializes the catalog from rich msgpack', if: Puppet.features.msgpack? do
177
+ body = Puppet.override(rich_data: true) do
178
+ catalog.to_msgpack
179
+ end
180
+
181
+ formatter = Puppet::Network::FormatHandler.format(:rich_data_msgpack)
182
+ catalog_response = { body: body, headers: {'Content-Type' => formatter.mime }}
183
+
184
+ stub_request(:post, uri)
185
+ .to_return(**catalog_response)
186
+
187
+ _, cat = subject.post_catalog(certname, environment: 'production', facts: facts)
188
+ expect(cat).to be_a(Puppet::Resource::Catalog)
189
+ expect(cat.name).to eq(certname)
190
+ end
191
+
143
192
  it 'returns the request response' do
144
193
  stub_request(:post, uri)
145
194
  .to_return(**catalog_response)
@@ -137,7 +137,7 @@ describe Puppet::HTTP::Service do
137
137
  catalog_mimes = if Puppet.features.msgpack?
138
138
  %w[application/vnd.puppet.rich+json application/json application/vnd.puppet.rich+msgpack application/x-msgpack text/pson]
139
139
  else
140
- %w[application/vnd.puppet.rich+json application/json application/vnd.puppet.rich+msgpack text/pson]
140
+ %w[application/vnd.puppet.rich+json application/json text/pson]
141
141
  end
142
142
  expect(service.mime_types(Puppet::Resource::Catalog)).to eq(catalog_mimes)
143
143
  end
@@ -33,7 +33,6 @@ describe Puppet::Indirector::Face do
33
33
  describe "as an instance" do
34
34
  it "should be able to determine its indirection" do
35
35
  # Loading actions here can get, um, complicated
36
- allow(Puppet::Face).to receive(:load_actions)
37
36
  expect(Puppet::Indirector::Face.new(:catalog, '0.0.1').indirection).to equal(Puppet::Resource::Catalog.indirection)
38
37
  end
39
38
  end
@@ -22,13 +22,13 @@ describe Puppet::Node::Facts::Facter do
22
22
  end
23
23
 
24
24
  before :each do
25
- allow(Puppet::Node::Facts::Facter).to receive(:reload_facter)
26
25
  @facter = Puppet::Node::Facts::Facter.new
27
26
  allow(Facter).to receive(:to_hash).and_return({})
28
27
  @name = "me"
29
28
  @request = double('request', :key => @name)
30
29
  @environment = double('environment')
31
30
  allow(@request).to receive(:environment).and_return(@environment)
31
+ allow(@request).to receive(:options).and_return({})
32
32
  allow(@request.environment).to receive(:modules).and_return([])
33
33
  allow(@request.environment).to receive(:modulepath).and_return([])
34
34
  end
@@ -105,6 +105,7 @@ describe Puppet::Node::Facts::Facter do
105
105
  expect(FileTest).to receive(:directory?).with(factpath1).and_return(true)
106
106
  expect(FileTest).to receive(:directory?).with(factpath2).and_return(true)
107
107
  allow(@request.environment).to receive(:modulepath).and_return([modulepath])
108
+ allow(@request).to receive(:options).and_return({})
108
109
  expect(Dir).to receive(:glob).with("#{modulepath}/*/lib/facter").and_return([modulelibfacter])
109
110
  expect(Dir).to receive(:glob).with("#{modulepath}/*/plugins/facter").and_return([modulepluginsfacter])
110
111
 
@@ -150,4 +151,97 @@ describe Puppet::Node::Facts::Facter do
150
151
  Puppet::Node::Facts::Facter.setup_external_search_paths @request
151
152
  end
152
153
  end
154
+
155
+ describe 'when :resolve_options is true' do
156
+ let(:options) { { resolve_options: true, user_query: ["os", "timezone"], show_legacy: true } }
157
+ let(:facts) { Puppet::Node::Facts.new("foo") }
158
+
159
+ before :each do
160
+ allow(@request).to receive(:options).and_return(options)
161
+ allow(Puppet::Node::Facts).to receive(:new).and_return(facts)
162
+ allow(facts).to receive(:add_local_facts)
163
+ end
164
+
165
+ it 'should call Facter.resolve method' do
166
+ expect(Facter).to receive(:resolve).with("os timezone --show-legacy")
167
+ @facter.find(@request)
168
+ end
169
+
170
+ it 'should NOT add local facts' do
171
+ expect(facts).not_to receive(:add_local_facts)
172
+
173
+ @facter.find(@request)
174
+ end
175
+
176
+ describe 'when Facter version is lower than 4.0.40' do
177
+ before :each do
178
+ allow(Facter).to receive(:respond_to?).and_return(false)
179
+ allow(Facter).to receive(:respond_to?).with(:resolve).and_return(false)
180
+ end
181
+
182
+ it 'raises an error' do
183
+ expect { @facter.find(@request) }.to raise_error(Puppet::Error, "puppet facts show requires version 4.0.40 or greater of Facter.")
184
+ end
185
+ end
186
+
187
+ describe 'when setting up external search paths' do
188
+ let(:options) { { resolve_options: true, user_query: ["os", "timezone"], external_dir: 'some/dir' } }
189
+ let(:pluginfactdest) { File.expand_path 'plugin/dest' }
190
+ let(:modulepath) { File.expand_path 'module/foo' }
191
+ let(:modulefactsd) { File.expand_path 'module/foo/facts.d' }
192
+
193
+ before :each do
194
+ expect(FileTest).to receive(:directory?).with(pluginfactdest).and_return(true)
195
+ mod = Puppet::Module.new('foo', modulepath, @request.environment)
196
+ allow(@request.environment).to receive(:modules).and_return([mod])
197
+ Puppet[:pluginfactdest] = pluginfactdest
198
+ end
199
+
200
+ it 'should skip files' do
201
+ expect(File).to receive(:directory?).with(modulefactsd).and_return(false)
202
+ expect(Facter).to receive(:search_external).with([pluginfactdest, options[:external_dir]])
203
+ Puppet::Node::Facts::Facter.setup_external_search_paths @request
204
+ end
205
+
206
+ it 'should add directories' do
207
+ expect(File).to receive(:directory?).with(modulefactsd).and_return(true)
208
+ expect(Facter).to receive(:search_external).with([modulefactsd, pluginfactdest, options[:external_dir]])
209
+ Puppet::Node::Facts::Facter.setup_external_search_paths @request
210
+ end
211
+ end
212
+
213
+ describe 'when setting up search paths' do
214
+ let(:factpath1) { File.expand_path 'one' }
215
+ let(:factpath2) { File.expand_path 'two' }
216
+ let(:factpath) { [factpath1, factpath2].join(File::PATH_SEPARATOR) }
217
+ let(:modulepath) { File.expand_path 'module/foo' }
218
+ let(:modulelibfacter) { File.expand_path 'module/foo/lib/facter' }
219
+ let(:modulepluginsfacter) { File.expand_path 'module/foo/plugins/facter' }
220
+ let(:options) { { resolve_options: true, custom_dir: 'some/dir' } }
221
+
222
+ before :each do
223
+ expect(FileTest).to receive(:directory?).with(factpath1).and_return(true)
224
+ expect(FileTest).to receive(:directory?).with(factpath2).and_return(true)
225
+ allow(@request.environment).to receive(:modulepath).and_return([modulepath])
226
+ expect(Dir).to receive(:glob).with("#{modulepath}/*/lib/facter").and_return([modulelibfacter])
227
+ expect(Dir).to receive(:glob).with("#{modulepath}/*/plugins/facter").and_return([modulepluginsfacter])
228
+
229
+ Puppet[:factpath] = factpath
230
+ end
231
+
232
+ it 'should skip files' do
233
+ expect(FileTest).to receive(:directory?).with(modulelibfacter).and_return(false)
234
+ expect(FileTest).to receive(:directory?).with(modulepluginsfacter).and_return(false)
235
+ expect(Facter).to receive(:search).with(factpath1, factpath2, options[:custom_dir])
236
+ Puppet::Node::Facts::Facter.setup_search_paths @request
237
+ end
238
+
239
+ it 'should add directories' do
240
+ expect(FileTest).to receive(:directory?).with(modulelibfacter).and_return(true)
241
+ expect(FileTest).to receive(:directory?).with(modulepluginsfacter).and_return(false)
242
+ expect(Facter).to receive(:search).with(modulelibfacter, factpath1, factpath2, options[:custom_dir])
243
+ Puppet::Node::Facts::Facter.setup_search_paths @request
244
+ end
245
+ end
246
+ end
153
247
  end