puppet 7.10.0-x64-mingw32 → 7.13.1-x64-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (192) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +3 -3
  3. data/Gemfile.lock +20 -15
  4. data/ext/project_data.yaml +1 -1
  5. data/lib/puppet/application/agent.rb +4 -0
  6. data/lib/puppet/application/apply.rb +20 -2
  7. data/lib/puppet/application/lookup.rb +72 -24
  8. data/lib/puppet/application/resource.rb +15 -13
  9. data/lib/puppet/concurrent/thread_local_singleton.rb +6 -3
  10. data/lib/puppet/configurer.rb +98 -29
  11. data/lib/puppet/confine/variable.rb +1 -1
  12. data/lib/puppet/defaults.rb +17 -3
  13. data/lib/puppet/facter_impl.rb +96 -0
  14. data/lib/puppet/file_serving/metadata.rb +3 -0
  15. data/lib/puppet/file_serving/mount/file.rb +4 -4
  16. data/lib/puppet/file_system/file_impl.rb +10 -8
  17. data/lib/puppet/file_system/jruby.rb +1 -1
  18. data/lib/puppet/file_system/path_pattern.rb +10 -15
  19. data/lib/puppet/file_system/uniquefile.rb +1 -1
  20. data/lib/puppet/file_system/windows.rb +4 -4
  21. data/lib/puppet/file_system.rb +3 -2
  22. data/lib/puppet/forge.rb +1 -1
  23. data/lib/puppet/functions/versioncmp.rb +6 -2
  24. data/lib/puppet/graph/simple_graph.rb +2 -1
  25. data/lib/puppet/http/client.rb +1 -1
  26. data/lib/puppet/http/redirector.rb +5 -0
  27. data/lib/puppet/indirector/catalog/compiler.rb +3 -3
  28. data/lib/puppet/indirector/facts/facter.rb +6 -6
  29. data/lib/puppet/indirector/indirection.rb +1 -1
  30. data/lib/puppet/module_tool/applications/uninstaller.rb +1 -1
  31. data/lib/puppet/module_tool/applications/upgrader.rb +1 -1
  32. data/lib/puppet/pal/pal_impl.rb +1 -1
  33. data/lib/puppet/parser/resource.rb +1 -1
  34. data/lib/puppet/parser/scope.rb +8 -7
  35. data/lib/puppet/parser/templatewrapper.rb +1 -0
  36. data/lib/puppet/pops/evaluator/closure.rb +7 -5
  37. data/lib/puppet/pops/evaluator/runtime3_resource_support.rb +1 -0
  38. data/lib/puppet/pops/lookup/lookup_adapter.rb +3 -2
  39. data/lib/puppet/pops/model/ast.rb +1 -0
  40. data/lib/puppet/pops/model/factory.rb +14 -13
  41. data/lib/puppet/pops/parser/code_merger.rb +4 -4
  42. data/lib/puppet/pops/parser/egrammar.ra +4 -2
  43. data/lib/puppet/pops/parser/eparser.rb +909 -894
  44. data/lib/puppet/pops/parser/lexer2.rb +69 -68
  45. data/lib/puppet/pops/parser/slurp_support.rb +1 -0
  46. data/lib/puppet/pops/serialization/to_data_converter.rb +6 -18
  47. data/lib/puppet/pops/serialization/to_stringified_converter.rb +1 -1
  48. data/lib/puppet/pops/types/type_formatter.rb +7 -6
  49. data/lib/puppet/pops/types/types.rb +1 -1
  50. data/lib/puppet/pops/validation/checker4_0.rb +7 -2
  51. data/lib/puppet/provider/aix_object.rb +1 -1
  52. data/lib/puppet/provider/group/groupadd.rb +5 -2
  53. data/lib/puppet/provider/package/pkg.rb +11 -1
  54. data/lib/puppet/provider/package/puppet_gem.rb +1 -1
  55. data/lib/puppet/provider/package/puppetserver_gem.rb +1 -1
  56. data/lib/puppet/provider/package/yum.rb +1 -1
  57. data/lib/puppet/provider/service/base.rb +1 -1
  58. data/lib/puppet/provider/service/init.rb +10 -9
  59. data/lib/puppet/provider/service/launchd.rb +1 -1
  60. data/lib/puppet/provider/service/redhat.rb +1 -1
  61. data/lib/puppet/provider/service/smf.rb +3 -3
  62. data/lib/puppet/provider/service/systemd.rb +1 -1
  63. data/lib/puppet/provider/service/upstart.rb +5 -5
  64. data/lib/puppet/provider/user/aix.rb +44 -1
  65. data/lib/puppet/provider/user/directoryservice.rb +1 -1
  66. data/lib/puppet/provider/user/useradd.rb +30 -7
  67. data/lib/puppet/provider.rb +1 -1
  68. data/lib/puppet/reference/providers.rb +2 -2
  69. data/lib/puppet/resource/catalog.rb +1 -1
  70. data/lib/puppet/resource/type_collection.rb +2 -1
  71. data/lib/puppet/resource.rb +38 -5
  72. data/lib/puppet/runtime.rb +11 -1
  73. data/lib/puppet/settings/file_setting.rb +3 -8
  74. data/lib/puppet/settings.rb +2 -2
  75. data/lib/puppet/ssl/verifier.rb +3 -1
  76. data/lib/puppet/test/test_helper.rb +4 -1
  77. data/lib/puppet/transaction/persistence.rb +22 -12
  78. data/lib/puppet/type/exec.rb +9 -1
  79. data/lib/puppet/type/file/data_sync.rb +1 -1
  80. data/lib/puppet/type/file/group.rb +8 -1
  81. data/lib/puppet/type/file/owner.rb +8 -1
  82. data/lib/puppet/type/group.rb +0 -1
  83. data/lib/puppet/type/resources.rb +1 -1
  84. data/lib/puppet/type/service.rb +8 -3
  85. data/lib/puppet/type/user.rb +40 -39
  86. data/lib/puppet/util/autoload.rb +1 -1
  87. data/lib/puppet/util/command_line.rb +1 -1
  88. data/lib/puppet/util/filetype.rb +2 -2
  89. data/lib/puppet/util/json.rb +20 -0
  90. data/lib/puppet/util/log.rb +8 -4
  91. data/lib/puppet/util/logging.rb +1 -25
  92. data/lib/puppet/util/monkey_patches.rb +26 -2
  93. data/lib/puppet/util/package.rb +25 -16
  94. data/lib/puppet/util/pidlock.rb +1 -1
  95. data/lib/puppet/util/rdoc/parser/puppet_parser_core.rb +1 -1
  96. data/lib/puppet/util/suidmanager.rb +1 -2
  97. data/lib/puppet/util/tagging.rb +1 -0
  98. data/lib/puppet/util/windows/service.rb +0 -5
  99. data/lib/puppet/util/windows/user.rb +0 -1
  100. data/lib/puppet/util/windows.rb +3 -0
  101. data/lib/puppet/util/yaml.rb +11 -0
  102. data/lib/puppet/util.rb +4 -3
  103. data/lib/puppet/version.rb +1 -1
  104. data/lib/puppet.rb +3 -6
  105. data/locales/puppet.pot +265 -239
  106. data/man/man5/puppet.conf.5 +18 -2
  107. data/man/man8/puppet-agent.8 +4 -1
  108. data/man/man8/puppet-apply.8 +1 -1
  109. data/man/man8/puppet-catalog.8 +1 -1
  110. data/man/man8/puppet-config.8 +1 -1
  111. data/man/man8/puppet-describe.8 +1 -1
  112. data/man/man8/puppet-device.8 +1 -1
  113. data/man/man8/puppet-doc.8 +1 -1
  114. data/man/man8/puppet-epp.8 +1 -1
  115. data/man/man8/puppet-facts.8 +1 -1
  116. data/man/man8/puppet-filebucket.8 +1 -1
  117. data/man/man8/puppet-generate.8 +1 -1
  118. data/man/man8/puppet-help.8 +1 -1
  119. data/man/man8/puppet-lookup.8 +9 -6
  120. data/man/man8/puppet-module.8 +1 -1
  121. data/man/man8/puppet-node.8 +1 -1
  122. data/man/man8/puppet-parser.8 +1 -1
  123. data/man/man8/puppet-plugin.8 +1 -1
  124. data/man/man8/puppet-report.8 +1 -1
  125. data/man/man8/puppet-resource.8 +1 -1
  126. data/man/man8/puppet-script.8 +1 -1
  127. data/man/man8/puppet-ssl.8 +1 -1
  128. data/man/man8/puppet.8 +2 -2
  129. data/spec/fixtures/integration/application/agent/cached_deferred_catalog.json +2 -1
  130. data/spec/fixtures/unit/forge/bacula.json +1 -1
  131. data/spec/integration/application/agent_spec.rb +44 -0
  132. data/spec/integration/application/lookup_spec.rb +29 -6
  133. data/spec/integration/configurer_spec.rb +1 -1
  134. data/spec/integration/indirector/facts/facter_spec.rb +3 -3
  135. data/spec/integration/parser/pcore_resource_spec.rb +20 -0
  136. data/spec/integration/transaction/report_spec.rb +1 -1
  137. data/spec/integration/type/file_spec.rb +2 -2
  138. data/spec/integration/type/package_spec.rb +6 -6
  139. data/spec/integration/util/rdoc/parser_spec.rb +1 -1
  140. data/spec/integration/util/windows/process_spec.rb +1 -9
  141. data/spec/shared_contexts/l10n.rb +5 -0
  142. data/spec/unit/application/apply_spec.rb +76 -56
  143. data/spec/unit/application/lookup_spec.rb +131 -10
  144. data/spec/unit/application/resource_spec.rb +29 -0
  145. data/spec/unit/concurrent/thread_local_singleton_spec.rb +39 -0
  146. data/spec/unit/configurer_spec.rb +113 -28
  147. data/spec/unit/facter_impl_spec.rb +31 -0
  148. data/spec/unit/file_bucket/dipper_spec.rb +2 -2
  149. data/spec/unit/file_system/uniquefile_spec.rb +7 -1
  150. data/spec/unit/file_system_spec.rb +41 -4
  151. data/spec/unit/forge/module_release_spec.rb +3 -3
  152. data/spec/unit/functions/lookup_spec.rb +64 -0
  153. data/spec/unit/functions/versioncmp_spec.rb +40 -4
  154. data/spec/unit/http/client_spec.rb +58 -1
  155. data/spec/unit/indirector/indirection_spec.rb +10 -3
  156. data/spec/unit/network/formats_spec.rb +6 -0
  157. data/spec/unit/pops/parser/parse_containers_spec.rb +2 -2
  158. data/spec/unit/pops/serialization/to_from_hr_spec.rb +0 -58
  159. data/spec/unit/pops/serialization/to_stringified_spec.rb +5 -0
  160. data/spec/unit/pops/types/type_calculator_spec.rb +6 -0
  161. data/spec/unit/pops/validator/validator_spec.rb +5 -0
  162. data/spec/unit/provider/package/gem_spec.rb +1 -1
  163. data/spec/unit/provider/package/pip2_spec.rb +1 -1
  164. data/spec/unit/provider/package/pip3_spec.rb +1 -1
  165. data/spec/unit/provider/package/pip_spec.rb +1 -1
  166. data/spec/unit/provider/package/pkg_spec.rb +15 -0
  167. data/spec/unit/provider/package/puppet_gem_spec.rb +1 -1
  168. data/spec/unit/provider/package/puppetserver_gem_spec.rb +1 -1
  169. data/spec/unit/provider/service/gentoo_spec.rb +6 -5
  170. data/spec/unit/provider/service/init_spec.rb +15 -9
  171. data/spec/unit/provider/service/openwrt_spec.rb +21 -29
  172. data/spec/unit/provider/service/redhat_spec.rb +3 -2
  173. data/spec/unit/provider/user/aix_spec.rb +100 -0
  174. data/spec/unit/provider/user/directoryservice_spec.rb +1 -1
  175. data/spec/unit/provider/user/useradd_spec.rb +40 -0
  176. data/spec/unit/provider_spec.rb +4 -4
  177. data/spec/unit/puppet_spec.rb +12 -4
  178. data/spec/unit/resource/catalog_spec.rb +14 -1
  179. data/spec/unit/resource_spec.rb +58 -2
  180. data/spec/unit/settings/file_setting_spec.rb +10 -7
  181. data/spec/unit/transaction/persistence_spec.rb +51 -0
  182. data/spec/unit/type/file/group_spec.rb +7 -0
  183. data/spec/unit/type/file/owner_spec.rb +7 -0
  184. data/spec/unit/type/service_spec.rb +27 -0
  185. data/spec/unit/type/user_spec.rb +0 -45
  186. data/spec/unit/type_spec.rb +2 -2
  187. data/spec/unit/util/autoload_spec.rb +25 -8
  188. data/spec/unit/util/json_spec.rb +126 -0
  189. data/spec/unit/util/logging_spec.rb +2 -0
  190. data/spec/unit/util/yaml_spec.rb +37 -13
  191. data/tasks/parallel.rake +3 -3
  192. metadata +17 -4
@@ -2,6 +2,8 @@ require 'spec_helper'
2
2
  require 'puppet/configurer'
3
3
 
4
4
  describe Puppet::Configurer do
5
+ include PuppetSpec::Files
6
+
5
7
  before do
6
8
  Puppet[:server] = "puppetmaster"
7
9
  Puppet[:report] = true
@@ -10,6 +12,17 @@ describe Puppet::Configurer do
10
12
  allow_any_instance_of(described_class).to(
11
13
  receive(:valid_server_environment?).and_return(true)
12
14
  )
15
+
16
+ Puppet[:lastrunfile] = file_containing('last_run_summary.yaml', <<~SUMMARY)
17
+ ---
18
+ version:
19
+ config: 1624882680
20
+ puppet: #{Puppet.version}
21
+ application:
22
+ initial_environment: #{Puppet[:environment]}
23
+ converged_environment: #{Puppet[:environment]}
24
+ run_mode: agent
25
+ SUMMARY
13
26
  end
14
27
 
15
28
  let(:node_name) { Puppet[:node_name_value] }
@@ -191,7 +204,7 @@ describe Puppet::Configurer do
191
204
  }
192
205
  Puppet::Node::Facts.indirection.save(facts)
193
206
 
194
- expect(Puppet).to receive(:warning).with(/Payload with the current size of: '[1-9]*' exceeds the payload size limit: [1-9]*/)
207
+ expect(Puppet).to receive(:warning).with(/Payload with the current size of: '\d*' exceeds the payload size limit: \d*/)
195
208
  configurer.run
196
209
  end
197
210
 
@@ -583,7 +596,7 @@ describe Puppet::Configurer do
583
596
  it "should save the report if reporting is enabled" do
584
597
  Puppet.settings[:report] = true
585
598
 
586
- expect(Puppet::Transaction::Report.indirection).to receive(:save).with(report, nil, instance_of(Hash))
599
+ expect(Puppet::Transaction::Report.indirection).to receive(:save).with(report, nil, instance_of(Hash)).twice
587
600
  configurer.send_report(report)
588
601
  end
589
602
 
@@ -611,12 +624,22 @@ describe Puppet::Configurer do
611
624
  it "should log but not fail if saving the report fails" do
612
625
  Puppet.settings[:report] = true
613
626
 
614
- expect(Puppet::Transaction::Report.indirection).to receive(:save).and_raise("whatever")
627
+ expect(Puppet::Transaction::Report.indirection).to receive(:save).with(report, nil, hash_including(ignore_cache: true)).and_raise("whatever")
628
+ expect(Puppet::Transaction::Report.indirection).to receive(:save).with(report, nil, hash_including(ignore_terminus: true))
615
629
 
616
630
  configurer.send_report(report)
617
631
 
618
632
  expect(@logs).to include(an_object_having_attributes(level: :err, message: 'Could not send report: whatever'))
619
633
  end
634
+
635
+ it "should save the cached report if fails to send the report" do
636
+ allow(Puppet::Transaction::Report.indirection).to receive(:save).with(report, nil, hash_including(ignore_terminus: true)).and_call_original
637
+ allow(Puppet::Transaction::Report.indirection).to receive(:save).with(report, nil, hash_including(ignore_cache: true)).and_raise("whatever")
638
+
639
+ expect(File).to_not be_exist(Puppet[:lastrunfile])
640
+ configurer.send_report(report)
641
+ expect(File.read(Puppet[:lastrunfile])).to match(/puppet: #{Puppet::PUPPETVERSION}/)
642
+ end
620
643
  end
621
644
 
622
645
  describe "when saving the summary report file" do
@@ -856,7 +879,7 @@ describe Puppet::Configurer do
856
879
  expect(configurer.run).to be_nil
857
880
  end
858
881
 
859
- it "should proceed with the cached catalog if its environment matchs the local environment" do
882
+ it "should proceed with the cached catalog if its environment matches the local environment" do
860
883
  expects_cached_catalog_only(catalog)
861
884
 
862
885
  expect(configurer.run).to eq(0)
@@ -1212,7 +1235,6 @@ describe Puppet::Configurer do
1212
1235
  end
1213
1236
 
1214
1237
  describe "when selecting an environment" do
1215
- include PuppetSpec::Files
1216
1238
  include PuppetSpec::Settings
1217
1239
 
1218
1240
  describe "when the last used environment is available" do
@@ -1229,6 +1251,9 @@ describe Puppet::Configurer do
1229
1251
  converged_environment: #{last_server_specified_environment}
1230
1252
  run_mode: agent
1231
1253
  SUMMARY
1254
+
1255
+ expect(Puppet::Node.indirection).not_to receive(:find)
1256
+ .with(anything, hash_including(:ignore_cache => true, :fail_on_404 => true))
1232
1257
  end
1233
1258
 
1234
1259
  it "prefers the environment set via cli" do
@@ -1238,26 +1263,27 @@ describe Puppet::Configurer do
1238
1263
  expect(configurer.environment).to eq('usethis')
1239
1264
  end
1240
1265
 
1241
- it "prefers the environment set via config" do
1266
+ it "prefers the environment set via lastrunfile over config" do
1242
1267
  FileUtils.mkdir_p(Puppet[:confdir])
1243
1268
  set_puppet_conf(Puppet[:confdir], <<~CONF)
1244
1269
  [main]
1245
1270
  environment = usethis
1271
+ lastrunfile = #{Puppet[:lastrunfile]}
1246
1272
  CONF
1247
1273
 
1248
1274
  Puppet.initialize_settings
1249
1275
  configurer.run
1250
1276
 
1251
- expect(configurer.environment).to eq('usethis')
1277
+ expect(configurer.environment).to eq(last_server_specified_environment)
1252
1278
  end
1253
1279
 
1254
- it "uses environment from Puppet[:environment] if given a catalog" do
1280
+ it "uses the environment from Puppet[:environment] if given a catalog" do
1255
1281
  configurer.run(catalog: catalog)
1256
1282
 
1257
1283
  expect(configurer.environment).to eq(Puppet[:environment])
1258
1284
  end
1259
1285
 
1260
- it "uses environment from Puppet[:environment] if use_cached_catalog = true" do
1286
+ it "uses the environment from Puppet[:environment] if use_cached_catalog = true" do
1261
1287
  Puppet[:use_cached_catalog] = true
1262
1288
  expects_cached_catalog_only(catalog)
1263
1289
  configurer.run
@@ -1272,14 +1298,28 @@ describe Puppet::Configurer do
1272
1298
  expect(configurer.environment).to eq(last_server_specified_environment)
1273
1299
  end
1274
1300
 
1275
- it "uses environment from Puppet[:environment] if strict_environment_mode is set" do
1301
+ it "pushes the converged environment found in lastrunfile over the existing context" do
1302
+ initial_env = Puppet::Node::Environment.remote('production')
1303
+ Puppet.push_context(
1304
+ current_environment: initial_env,
1305
+ loaders: Puppet::Pops::Loaders.new(initial_env, true))
1306
+
1307
+ expect(Puppet).to receive(:push_context).with(
1308
+ hash_including(:current_environment, :loaders),
1309
+ "Local node environment #{last_server_specified_environment} for configurer transaction"
1310
+ ).once.and_call_original
1311
+
1312
+ configurer.run
1313
+ end
1314
+
1315
+ it "uses the environment from Puppet[:environment] if strict_environment_mode is set" do
1276
1316
  Puppet[:strict_environment_mode] = true
1277
1317
  configurer.run
1278
1318
 
1279
1319
  expect(configurer.environment).to eq(Puppet[:environment])
1280
1320
  end
1281
1321
 
1282
- it "uses environment from Puppet[:environment] if initial_environment is the same as converged_environment" do
1322
+ it "uses the environment from Puppet[:environment] if initial_environment is the same as converged_environment" do
1283
1323
  Puppet[:lastrunfile] = file_containing('last_run_summary.yaml', <<~SUMMARY)
1284
1324
  ---
1285
1325
  version:
@@ -1294,41 +1334,86 @@ describe Puppet::Configurer do
1294
1334
 
1295
1335
  expect(configurer.environment).to eq(Puppet[:environment])
1296
1336
  end
1337
+ end
1338
+ end
1339
+
1340
+ describe "when the last used environment is not available" do
1341
+ describe "when the node request succeeds" do
1342
+ let(:node_environment) { Puppet::Node::Environment.remote(:salam) }
1343
+ let(:node) { Puppet::Node.new(Puppet[:node_name_value]) }
1344
+ let(:last_server_specified_environment) { 'development' }
1297
1345
 
1298
- it "uses environment from Puppet[:environment] if the run mode doesn't match" do
1346
+ before do
1347
+ node.environment = node_environment
1348
+
1349
+ allow(Puppet::Node.indirection).to receive(:find)
1350
+ allow(Puppet::Node.indirection).to receive(:find)
1351
+ .with(anything, hash_including(:ignore_cache => true, :fail_on_404 => true))
1352
+ .and_return(node)
1353
+ end
1354
+
1355
+ it "uses the environment from the node request if the run mode doesn't match" do
1299
1356
  Puppet[:lastrunfile] = file_containing('last_run_summary.yaml', <<~SUMMARY)
1300
- ---
1301
- version:
1302
- config: 1624882680
1303
- puppet: 6.24.0
1304
- application:
1305
- initial_environment: #{Puppet[:environment]}
1306
- converged_environment: #{last_server_specified_environment}
1307
- run_mode: user
1357
+ ---
1358
+ version:
1359
+ config: 1624882680
1360
+ puppet: 6.24.0
1361
+ application:
1362
+ initial_environment: #{Puppet[:environment]}
1363
+ converged_environment: #{last_server_specified_environment}
1364
+ run_mode: user
1308
1365
  SUMMARY
1309
1366
  configurer.run
1310
1367
 
1311
- expect(configurer.environment).to eq(Puppet[:environment])
1368
+ expect(configurer.environment).to eq(node_environment.name.to_s)
1312
1369
  end
1313
1370
 
1314
- it "uses environment from Puppet[:environment] if lastrunfile is invalid YAML" do
1371
+ it "uses the environment from the node request if lastrunfile does not contain the expected keys" do
1315
1372
  Puppet[:lastrunfile] = file_containing('last_run_summary.yaml', <<~SUMMARY)
1316
- Key: 'this is my very very very ' +
1317
- 'long string'
1373
+ ---
1374
+ version:
1375
+ config: 1624882680
1376
+ puppet: 6.24.0
1318
1377
  SUMMARY
1319
1378
  configurer.run
1320
1379
 
1321
- expect(configurer.environment).to eq(Puppet[:environment])
1380
+ expect(configurer.environment).to eq(node_environment.name.to_s)
1381
+ end
1382
+
1383
+ it "uses the environment from the node request if lastrunfile is invalid YAML" do
1384
+ Puppet[:lastrunfile] = file_containing('last_run_summary.yaml', <<~SUMMARY)
1385
+ Key: 'this is my very very very ' +
1386
+ 'long string'
1387
+ SUMMARY
1388
+ configurer.run
1389
+
1390
+ expect(configurer.environment).to eq(node_environment.name.to_s)
1322
1391
  end
1323
1392
 
1324
- it "uses environment from Puppet[:environment] if lastrunfile exists but is empty" do
1393
+ it "uses the environment from the node request if lastrunfile exists but is empty" do
1325
1394
  Puppet[:lastrunfile] = file_containing('last_run_summary.yaml', '')
1326
1395
  configurer.run
1327
1396
 
1328
- expect(configurer.environment).to eq(Puppet[:environment])
1397
+ expect(configurer.environment).to eq(node_environment.name.to_s)
1398
+ end
1399
+
1400
+ it "uses the environment from the node request if the last used one cannot be found" do
1401
+ Puppet[:lastrunfile] = tmpfile('last_run_summary.yaml')
1402
+ configurer.run
1403
+
1404
+ expect(configurer.environment).to eq(node_environment.name.to_s)
1405
+ end
1406
+ end
1407
+
1408
+ describe "when the node request fails" do
1409
+ before do
1410
+ allow(Puppet::Node.indirection).to receive(:find).and_call_original
1411
+ allow(Puppet::Node.indirection).to receive(:find)
1412
+ .with(anything, hash_including(:ignore_cache => true, :fail_on_404 => true))
1413
+ .and_raise(Puppet::Error)
1329
1414
  end
1330
1415
 
1331
- it "uses environment from Puppet[:environment] if the last used one cannot be found" do
1416
+ it "uses the environment from Puppet[:environment] if the last used one cannot be found" do
1332
1417
  Puppet[:lastrunfile] = tmpfile('last_run_summary.yaml')
1333
1418
  configurer.run
1334
1419
 
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Puppet::FacterImpl' do
4
+ subject(:facter_impl) { Puppet::FacterImpl.new }
5
+
6
+ it { is_expected.to respond_to(:value) }
7
+ it { is_expected.to respond_to(:add) }
8
+
9
+ describe '.value' do
10
+ let(:method_name) { :value }
11
+
12
+ before { allow(Facter).to receive(method_name) }
13
+
14
+ it 'delegates to Facter API' do
15
+ facter_impl.value('test_fact')
16
+ expect(Facter).to have_received(method_name).with('test_fact')
17
+ end
18
+ end
19
+
20
+ describe '.add' do
21
+ let(:block) { Proc.new { setcode 'test' } }
22
+ let(:method_name) { :add }
23
+
24
+ before { allow(Facter).to receive(method_name) }
25
+
26
+ it 'delegates to Facter API' do
27
+ facter_impl.add('test_fact', &block)
28
+ expect(Facter).to have_received(method_name).with('test_fact', &block)
29
+ end
30
+ end
31
+ end
@@ -104,8 +104,8 @@ describe Puppet::FileBucket::Dipper, :uses_checksums => true do
104
104
  # Diff without the context
105
105
  # Lines we need to see match 'Content' instead of trimming diff output filter out
106
106
  # surrounding noise...or hard code the check values
107
- if Facter.value(:osfamily) == 'Solaris' &&
108
- Puppet::Util::Package.versioncmp(Facter.value(:operatingsystemrelease), '11.0') >= 0
107
+ if Puppet.runtime[:facter].value(:osfamily) == 'Solaris' &&
108
+ Puppet::Util::Package.versioncmp(Puppet.runtime[:facter].value(:operatingsystemrelease), '11.0') >= 0
109
109
  # Use gdiff on Solaris
110
110
  diff12 = Puppet::Util::Execution.execute("gdiff -uN #{file1} #{file2}| grep Content")
111
111
  diff21 = Puppet::Util::Execution.execute("gdiff -uN #{file2} #{file1}| grep Content")
@@ -80,7 +80,7 @@ describe Puppet::FileSystem::Uniquefile do
80
80
  lock = File.join(dir, 'path', 'to', 'lock')
81
81
 
82
82
  expect {
83
- Puppet::FileSystem::Uniquefile.open_tmp(lock) { |tmp| }
83
+ Puppet::FileSystem::Uniquefile.new('foo', lock) { |tmp| }
84
84
  }.to raise_error(Errno::ENOENT, %r{No such file or directory - A directory component in .* does not exist or is a dangling symbolic link})
85
85
  end
86
86
 
@@ -102,6 +102,12 @@ describe Puppet::FileSystem::Uniquefile do
102
102
  expect(filename).to eq(temp_rune_utf8)
103
103
  end
104
104
 
105
+ it "preserves tilde characters" do
106
+ Puppet::FileSystem::Uniquefile.open_tmp('~foo') do |file|
107
+ expect(File.basename(file.path)).to start_with('~foo')
108
+ end
109
+ end
110
+
105
111
  context "Ruby 1.9.3 Tempfile tests" do
106
112
  # the remaining tests in this file are ported directly from the ruby 1.9.3 source,
107
113
  # since most of this file was ported from there
@@ -296,6 +296,13 @@ describe "Puppet::FileSystem" do
296
296
  expect(Puppet::FileSystem.read_preserve_line_endings(file)).to eq("file content \n")
297
297
  end
298
298
  end
299
+
300
+ it "should not warn about misusage of BOM with non-UTF encoding" do
301
+ allow(Encoding).to receive(:default_external).and_return(Encoding::US_ASCII)
302
+ with_file_content("file content \n") do |file|
303
+ expect{ Puppet::FileSystem.read_preserve_line_endings(file) }.not_to output(/BOM with non-UTF encoding US-ASCII is nonsense/).to_stderr
304
+ end
305
+ end
299
306
  end
300
307
 
301
308
  context "read without an encoding specified" do
@@ -977,11 +984,12 @@ describe "Puppet::FileSystem" do
977
984
  end
978
985
 
979
986
  it 'preserves file ownership' do
980
- allow(Puppet::FileSystem).to receive(:lstat)
981
- .with(Puppet::FileSystem.pathname(dest))
982
- .and_return(double(uid: 1, gid: 2))
987
+ FileUtils.touch(dest)
988
+ allow(File).to receive(:lstat).and_call_original
989
+ allow(File).to receive(:lstat).with(Pathname.new(dest)).and_return(double(uid: 1, gid: 2, 'directory?': false))
983
990
 
984
- expect(FileUtils).to receive(:chown).with(1, 2, /#{dest}/)
991
+ allow(File).to receive(:chown).and_call_original
992
+ expect(FileUtils).to receive(:chown).with(1, 2, any_args)
985
993
 
986
994
  Puppet::FileSystem.replace_file(dest, 0644) { |f| f.write(content) }
987
995
  end
@@ -1156,4 +1164,33 @@ describe "Puppet::FileSystem" do
1156
1164
  expect(File.mtime(dest)).to be_within(1).of(tomorrow)
1157
1165
  end
1158
1166
  end
1167
+
1168
+ context '#chmod' do
1169
+ let(:dest) { tmpfile('abs_file') }
1170
+
1171
+ it "changes the mode given an absolute string" do
1172
+ Puppet::FileSystem.touch(dest)
1173
+ Puppet::FileSystem.chmod(0644, dest)
1174
+ expect(File.stat(dest).mode & 0777).to eq(0644)
1175
+ end
1176
+
1177
+ it "returns true if given an absolute pathname" do
1178
+ Puppet::FileSystem.touch(dest)
1179
+ Puppet::FileSystem.chmod(0644, Pathname.new(dest))
1180
+ expect(File.stat(dest).mode & 0777).to eq(0644)
1181
+ end
1182
+
1183
+ it "raises if the file doesn't exist" do
1184
+ klass = Puppet::Util::Platform.windows? ? Puppet::Error : Errno::ENOENT
1185
+ expect {
1186
+ Puppet::FileSystem.chmod(0644, dest)
1187
+ }.to raise_error(klass)
1188
+ end
1189
+
1190
+ it "raises ArgumentError if dest is invalid" do
1191
+ expect {
1192
+ Puppet::FileSystem.chmod(0644, nil)
1193
+ }.to raise_error(ArgumentError, /expected Pathname, got: 'NilClass'/)
1194
+ end
1195
+ end
1159
1196
  end
@@ -90,7 +90,7 @@ describe Puppet::Forge::ModuleRelease do
90
90
  "checksums": { },
91
91
  "version": "#{module_version}",
92
92
  "description": "Standard Library for Puppet Modules",
93
- "source": "git://github.com/puppetlabs/puppetlabs-stdlib.git",
93
+ "source": "https://github.com/puppetlabs/puppetlabs-stdlib",
94
94
  "project_page": "https://github.com/puppetlabs/puppetlabs-stdlib",
95
95
  "summary": "Puppet Module Standard Library",
96
96
  "dependencies": [
@@ -204,7 +204,7 @@ describe Puppet::Forge::ModuleRelease do
204
204
  "checksums": { },
205
205
  "version": "#{module_version}",
206
206
  "description": "Standard Library for Puppet Modules",
207
- "source": "git://github.com/puppetlabs/puppetlabs-stdlib.git",
207
+ "source": "https://github.com/puppetlabs/puppetlabs-stdlib",
208
208
  "project_page": "https://github.com/puppetlabs/puppetlabs-stdlib",
209
209
  "summary": "Puppet Module Standard Library",
210
210
  "author": "#{module_author}",
@@ -279,7 +279,7 @@ describe Puppet::Forge::ModuleRelease do
279
279
  "checksums": { },
280
280
  "version": "#{module_version}",
281
281
  "description": "Standard Library for Puppet Modules",
282
- "source": "git://github.com/puppetlabs/puppetlabs-stdlib.git",
282
+ "source": "https://github.com/puppetlabs/puppetlabs-stdlib",
283
283
  "project_page": "https://github.com/puppetlabs/puppetlabs-stdlib",
284
284
  "summary": "Puppet Module Standard Library",
285
285
  "dependencies": [
@@ -870,6 +870,46 @@ describe "The lookup function" do
870
870
  end
871
871
  end
872
872
 
873
+ context 'with lookup_options' do
874
+ let(:environment_files) do
875
+ {
876
+ env_name => {
877
+ 'hiera.yaml' => <<-YAML.unindent,
878
+ ---
879
+ version: 5
880
+ YAML
881
+ 'data' => {
882
+ 'common.yaml' => common_yaml
883
+ }
884
+ }
885
+ }
886
+ end
887
+
888
+ context 'that are empty' do
889
+ let(:common_yaml) { <<-YAML.unindent }
890
+ lookup_options:
891
+ a: b
892
+ YAML
893
+
894
+ it 'ignores empty options' do
895
+ expect(lookup('a')).to eq("b")
896
+ end
897
+ end
898
+
899
+ context 'that contains a legal yaml hash with unexpected types' do
900
+ let(:common_yaml) { <<-YAML.unindent }
901
+ lookup_options:
902
+ :invalid_symbol
903
+ YAML
904
+
905
+ it 'fails lookup and reports a type mismatch' do
906
+ expect {
907
+ lookup('a')
908
+ }.to raise_error(Puppet::DataBinding::LookupError, /has wrong type, expects Puppet::LookupValue, got Runtime\[ruby, 'Symbol'\]/)
909
+ end
910
+ end
911
+ end
912
+
873
913
  context 'with lookup_options configured using patterns' do
874
914
  let(:mod_common) {
875
915
  <<-YAML.unindent
@@ -1019,6 +1059,30 @@ describe "The lookup function" do
1019
1059
  })
1020
1060
  end
1021
1061
 
1062
+ context 'and lookup_options is empty' do
1063
+ let(:mod_common) { <<-YAML.unindent }
1064
+ lookup_options:
1065
+ mod::a: b
1066
+ YAML
1067
+
1068
+ it 'ignores empty options' do
1069
+ expect(lookup('mod::a')).to eq("b")
1070
+ end
1071
+ end
1072
+
1073
+ context 'and lookup_options contains a legal hash with unexpected types' do
1074
+ let(:mod_common) { <<-YAML.unindent }
1075
+ lookup_options:
1076
+ :invalid_symbol
1077
+ YAML
1078
+
1079
+ it 'fails lookup and reports a type mismatch' do
1080
+ expect {
1081
+ lookup('mod::a')
1082
+ }.to raise_error(Puppet::DataBinding::LookupError, /has wrong type, expects Puppet::LookupValue, got Runtime\[ruby, 'Symbol'\]/)
1083
+ end
1084
+ end
1085
+
1022
1086
  context 'and patterns in module are not limited to module keys' do
1023
1087
  let(:mod_common) {
1024
1088
  <<-YAML.unindent
@@ -19,16 +19,52 @@ describe "the versioncmp function" do
19
19
  let(:type_parser) { Puppet::Pops::Types::TypeParser.singleton }
20
20
 
21
21
  it 'should raise an Error if there is less than 2 arguments' do
22
- expect { versioncmp('a,b') }.to raise_error(/expects 2 arguments, got 1/)
22
+ expect { versioncmp('a,b') }.to raise_error(/expects between 2 and 3 arguments, got 1/)
23
23
  end
24
24
 
25
- it 'should raise an Error if there is more than 2 arguments' do
26
- expect { versioncmp('a,b','foo', 'bar') }.to raise_error(/expects 2 arguments, got 3/)
25
+ it 'should raise an Error if there is more than 3 arguments' do
26
+ expect { versioncmp('a,b','foo', false, 'bar') }.to raise_error(/expects between 2 and 3 arguments, got 4/)
27
27
  end
28
28
 
29
29
  it "should call Puppet::Util::Package.versioncmp (included in scope)" do
30
- expect(Puppet::Util::Package).to receive(:versioncmp).with('1.2', '1.3').and_return(-1)
30
+ expect(Puppet::Util::Package).to receive(:versioncmp).with('1.2', '1.3', false).and_return(-1)
31
31
 
32
32
  expect(versioncmp('1.2', '1.3')).to eq(-1)
33
33
  end
34
+
35
+ context "when ignore_trailing_zeroes is true" do
36
+ it "should equate versions with 2 elements and dots but with unnecessary zero" do
37
+ expect(versioncmp("10.1.0", "10.1", true)).to eq(0)
38
+ end
39
+
40
+ it "should equate versions with 1 element and dot but with unnecessary zero" do
41
+ expect(versioncmp("11.0", "11", true)).to eq(0)
42
+ end
43
+
44
+ it "should equate versions with 1 element and dot but with unnecessary zeros" do
45
+ expect(versioncmp("11.00", "11", true)).to eq(0)
46
+ end
47
+
48
+ it "should equate versions with dots and iregular zeroes" do
49
+ expect(versioncmp("11.0.00", "11", true)).to eq(0)
50
+ end
51
+
52
+ it "should equate versions with dashes" do
53
+ expect(versioncmp("10.1-0", "10.1.0-0", true)).to eq(0)
54
+ end
55
+
56
+ it "should compare versions with dashes after normalization" do
57
+ expect(versioncmp("10.1-1", "10.1.0-0", true)).to eq(1)
58
+ end
59
+
60
+ it "should not normalize versions if zeros are not trailing" do
61
+ expect(versioncmp("1.1", "1.0.1", true)).to eq(1)
62
+ end
63
+ end
64
+
65
+ context "when ignore_trailing_zeroes is false" do
66
+ it "should not equate versions if zeros are not trailing" do
67
+ expect(versioncmp("1.1", "1.0.1")).to eq(1)
68
+ end
69
+ end
34
70
  end
@@ -597,11 +597,68 @@ describe Puppet::HTTP::Client do
597
597
  expect(response).to be_success
598
598
  end
599
599
 
600
- it "preserves basic authorization" do
600
+ it "does not preserve basic authorization when redirecting to different hosts" do
601
+ stub_request(:get, start_url).with(basic_auth: credentials).to_return(redirect_to(url: other_host))
602
+ stub_request(:get, other_host).to_return(status: 200)
603
+
604
+ client.get(start_url, options: {basic_auth: {user: 'user', password: 'pass'}})
605
+ expect(a_request(:get, other_host).
606
+ with{ |req| !req.headers.key?('Authorization')}).to have_been_made
607
+ end
608
+
609
+ it "does preserve basic authorization when redirecting to the same hosts" do
610
+ stub_request(:get, start_url).with(basic_auth: credentials).to_return(redirect_to(url: bar_url))
611
+ stub_request(:get, bar_url).with(basic_auth: credentials).to_return(status: 200)
612
+
613
+ client.get(start_url, options: {basic_auth: {user: 'user', password: 'pass'}})
614
+ expect(a_request(:get, bar_url).
615
+ with{ |req| req.headers.key?('Authorization')}).to have_been_made
616
+ end
617
+
618
+ it "does not preserve cookie header when redirecting to different hosts" do
619
+ headers = { 'Cookie' => 'TEST_COOKIE'}
620
+
621
+ stub_request(:get, start_url).with(headers: headers).to_return(redirect_to(url: other_host))
622
+ stub_request(:get, other_host).to_return(status: 200)
623
+
624
+ client.get(start_url, headers: headers)
625
+ expect(a_request(:get, other_host).
626
+ with{ |req| !req.headers.key?('Cookie')}).to have_been_made
627
+ end
628
+
629
+ it "does preserve cookie header when redirecting to the same hosts" do
630
+ headers = { 'Cookie' => 'TEST_COOKIE'}
631
+
632
+ stub_request(:get, start_url).with(headers: headers).to_return(redirect_to(url: bar_url))
633
+ stub_request(:get, bar_url).with(headers: headers).to_return(status: 200)
634
+
635
+ client.get(start_url, headers: headers)
636
+ expect(a_request(:get, bar_url).
637
+ with{ |req| req.headers.key?('Cookie')}).to have_been_made
638
+ end
639
+
640
+ it "does preserves cookie header and basic authentication when Puppet[:location_trusted] is true redirecting to different hosts" do
641
+ headers = { 'cookie' => 'TEST_COOKIE'}
642
+ Puppet[:location_trusted] = true
643
+
644
+ stub_request(:get, start_url).with(headers: headers, basic_auth: credentials).to_return(redirect_to(url: other_host))
645
+ stub_request(:get, other_host).with(headers: headers, basic_auth: credentials).to_return(status: 200)
646
+
647
+ client.get(start_url, headers: headers, options: {basic_auth: {user: 'user', password: 'pass'}})
648
+ expect(a_request(:get, other_host).
649
+ with{ |req| req.headers.key?('Authorization') && req.headers.key?('Cookie')}).to have_been_made
650
+ end
651
+
652
+ it "treats hosts as case-insensitive" do
653
+ start_url = URI("https://www.EXAmple.com:8140/Start")
654
+ bar_url = "https://www.example.com:8140/bar"
655
+
601
656
  stub_request(:get, start_url).with(basic_auth: credentials).to_return(redirect_to(url: bar_url))
602
657
  stub_request(:get, bar_url).with(basic_auth: credentials).to_return(status: 200)
603
658
 
604
659
  client.get(start_url, options: {basic_auth: {user: 'user', password: 'pass'}})
660
+ expect(a_request(:get, bar_url).
661
+ with{ |req| req.headers.key?('Authorization')}).to have_been_made
605
662
  end
606
663
 
607
664
  it "redirects given a relative location" do
@@ -499,7 +499,7 @@ describe Puppet::Indirector::Indirection do
499
499
  end
500
500
 
501
501
  it "should return the result of saving to the terminus" do
502
- request = double('request', :instance => @instance, :node => nil, :ignore_cache_save? => false)
502
+ request = double('request', :instance => @instance, :node => nil, :ignore_cache_save? => false, :ignore_terminus? => false)
503
503
 
504
504
  expect(@indirection).to receive(:request).and_return(request)
505
505
 
@@ -509,7 +509,7 @@ describe Puppet::Indirector::Indirection do
509
509
  end
510
510
 
511
511
  it "should use a request to save the object to the cache" do
512
- request = double('request', :instance => @instance, :node => nil, :ignore_cache_save? => false)
512
+ request = double('request', :instance => @instance, :node => nil, :ignore_cache_save? => false, :ignore_terminus? => false)
513
513
 
514
514
  expect(@indirection).to receive(:request).and_return(request)
515
515
 
@@ -519,7 +519,7 @@ describe Puppet::Indirector::Indirection do
519
519
  end
520
520
 
521
521
  it "should not save to the cache if the normal save fails" do
522
- request = double('request', :instance => @instance, :node => nil)
522
+ request = double('request', :instance => @instance, :node => nil, :ignore_terminus? => false)
523
523
 
524
524
  expect(@indirection).to receive(:request).and_return(request)
525
525
 
@@ -534,6 +534,13 @@ describe Puppet::Indirector::Indirection do
534
534
 
535
535
  @indirection.save(@instance, '/my/key', :ignore_cache_save => true)
536
536
  end
537
+
538
+ it "should only save to the cache if the request specifies not to use the terminus" do
539
+ expect(@terminus).not_to receive(:save)
540
+ expect(@cache).to receive(:save)
541
+
542
+ @indirection.save(@instance, "/my/key", :ignore_terminus => true)
543
+ end
537
544
  end
538
545
  end
539
546