puppet 4.8.2-universal-darwin → 4.9.0-universal-darwin

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of puppet might be problematic. Click here for more details.

Files changed (348) hide show
  1. checksums.yaml +15 -0
  2. data/CONTRIBUTING.md +25 -1
  3. data/Gemfile +6 -0
  4. data/Rakefile +1 -0
  5. data/ext/project_data.yaml +5 -1
  6. data/ext/windows/service/daemon.rb +2 -1
  7. data/install.rb +43 -6
  8. data/lib/hiera/puppet_function.rb +15 -17
  9. data/lib/hiera/scope.rb +12 -14
  10. data/lib/puppet/application/face_base.rb +4 -0
  11. data/lib/puppet/application/lookup.rb +4 -2
  12. data/lib/puppet/application/resource.rb +1 -1
  13. data/lib/puppet/data_providers/data_adapter.rb +6 -0
  14. data/lib/puppet/data_providers/data_function_support.rb +7 -0
  15. data/lib/puppet/data_providers/function_env_data_provider.rb +7 -0
  16. data/lib/puppet/data_providers/function_module_data_provider.rb +6 -0
  17. data/lib/puppet/data_providers/hiera_config.rb +31 -10
  18. data/lib/puppet/data_providers/hiera_env_data_provider.rb +6 -0
  19. data/lib/puppet/data_providers/hiera_interpolate.rb +2 -1
  20. data/lib/puppet/data_providers/hiera_module_data_provider.rb +6 -0
  21. data/lib/puppet/data_providers/hiera_support.rb +6 -0
  22. data/lib/puppet/data_providers/json_data_provider_factory.rb +12 -0
  23. data/lib/puppet/data_providers/yaml_data_provider_factory.rb +12 -0
  24. data/lib/puppet/data_providers.rb +6 -3
  25. data/lib/puppet/defaults.rb +25 -4
  26. data/lib/puppet/face/ca.rb +2 -0
  27. data/lib/puppet/face/certificate_request.rb +2 -0
  28. data/lib/puppet/face/certificate_revocation_list.rb +2 -0
  29. data/lib/puppet/face/file.rb +3 -0
  30. data/lib/puppet/face/help/face.erb +3 -0
  31. data/lib/puppet/face/help.rb +19 -17
  32. data/lib/puppet/face/key.rb +1 -0
  33. data/lib/puppet/face/man.rb +4 -2
  34. data/lib/puppet/face/module/generate.rb +1 -1
  35. data/lib/puppet/face/status.rb +2 -0
  36. data/lib/puppet/feature/base.rb +9 -2
  37. data/lib/puppet/feature/hocon.rb +3 -0
  38. data/lib/puppet/file_system/windows.rb +8 -0
  39. data/lib/puppet/file_system.rb +15 -3
  40. data/lib/puppet/forge/repository.rb +1 -2
  41. data/lib/puppet/forge.rb +6 -6
  42. data/lib/puppet/functions/binary_file.rb +4 -10
  43. data/lib/puppet/functions/hiera_array.rb +1 -1
  44. data/lib/puppet/functions/hiera_include.rb +1 -1
  45. data/lib/puppet/functions/hocon_data.rb +24 -0
  46. data/lib/puppet/functions/json_data.rb +18 -0
  47. data/lib/puppet/functions/yaml_data.rb +21 -0
  48. data/lib/puppet/generate/type.rb +1 -1
  49. data/lib/puppet/graph/simple_graph.rb +4 -2
  50. data/lib/puppet/indirector/file_bucket_file/file.rb +10 -2
  51. data/lib/puppet/indirector/request.rb +5 -1
  52. data/lib/puppet/interface/face_collection.rb +1 -1
  53. data/lib/puppet/interface.rb +14 -2
  54. data/lib/puppet/module.rb +14 -2
  55. data/lib/puppet/module_tool/applications/builder.rb +3 -2
  56. data/lib/puppet/module_tool/applications/installer.rb +14 -14
  57. data/lib/puppet/module_tool/applications/upgrader.rb +13 -13
  58. data/lib/puppet/module_tool/installed_modules.rb +7 -7
  59. data/lib/puppet/module_tool/local_tarball.rb +3 -3
  60. data/lib/puppet/module_tool/metadata.rb +1 -1
  61. data/lib/puppet/module_tool.rb +4 -4
  62. data/lib/puppet/network/http/connection.rb +2 -0
  63. data/lib/puppet/network/http/webrick.rb +2 -1
  64. data/lib/puppet/parser/functions/hiera.rb +14 -0
  65. data/lib/puppet/parser/functions/hiera_array.rb +14 -0
  66. data/lib/puppet/parser/functions/hiera_hash.rb +14 -0
  67. data/lib/puppet/parser/functions/hiera_include.rb +14 -0
  68. data/lib/puppet/parser/scope.rb +14 -20
  69. data/lib/puppet/plugins/data_providers/data_provider.rb +108 -17
  70. data/lib/puppet/plugins/data_providers/registry.rb +2 -36
  71. data/lib/puppet/plugins/data_providers.rb +2 -0
  72. data/lib/puppet/pops/adaptable.rb +0 -3
  73. data/lib/puppet/pops/binder/producers.rb +3 -3
  74. data/lib/puppet/pops/evaluator/access_operator.rb +4 -4
  75. data/lib/puppet/pops/evaluator/closure.rb +1 -1
  76. data/lib/puppet/pops/evaluator/compare_operator.rb +4 -4
  77. data/lib/puppet/pops/evaluator/evaluator_impl.rb +1 -1
  78. data/lib/puppet/pops/issues.rb +4 -0
  79. data/lib/puppet/pops/label_provider.rb +14 -0
  80. data/lib/puppet/pops/loader/loader_paths.rb +3 -1
  81. data/lib/puppet/pops/loader/module_loaders.rb +21 -7
  82. data/lib/puppet/pops/loader/typed_name.rb +0 -2
  83. data/lib/puppet/pops/loaders.rb +31 -12
  84. data/lib/puppet/pops/lookup/configured_data_provider.rb +87 -0
  85. data/lib/puppet/pops/lookup/context.rb +121 -71
  86. data/lib/puppet/pops/lookup/data_adapter.rb +27 -0
  87. data/lib/puppet/pops/lookup/data_dig_function_provider.rb +55 -0
  88. data/lib/puppet/pops/lookup/data_hash_function_provider.rb +111 -0
  89. data/lib/puppet/pops/lookup/data_provider.rb +102 -0
  90. data/lib/puppet/pops/lookup/environment_data_provider.rb +27 -0
  91. data/lib/puppet/pops/lookup/explainer.rb +122 -82
  92. data/lib/puppet/pops/lookup/function_provider.rb +82 -0
  93. data/lib/puppet/pops/lookup/global_data_provider.rb +49 -0
  94. data/lib/puppet/pops/lookup/hiera_config.rb +601 -0
  95. data/lib/puppet/pops/lookup/interpolation.rb +56 -35
  96. data/lib/puppet/pops/lookup/invocation.rb +179 -101
  97. data/lib/puppet/pops/lookup/location_resolver.rb +72 -0
  98. data/lib/puppet/pops/lookup/lookup_adapter.rb +451 -0
  99. data/lib/puppet/pops/lookup/lookup_key.rb +99 -0
  100. data/lib/puppet/pops/lookup/lookup_key_function_provider.rb +119 -0
  101. data/lib/puppet/pops/lookup/module_data_provider.rb +58 -0
  102. data/lib/puppet/pops/lookup/sub_lookup.rb +8 -4
  103. data/lib/puppet/pops/lookup.rb +4 -3
  104. data/lib/puppet/pops/merge_strategy.rb +120 -39
  105. data/lib/puppet/pops/parser/egrammar.ra +2 -0
  106. data/lib/puppet/pops/parser/eparser.rb +816 -808
  107. data/lib/puppet/pops/parser/locator.rb +3 -3
  108. data/lib/puppet/pops/parser/slurp_support.rb +4 -3
  109. data/lib/puppet/pops/pcore.rb +21 -12
  110. data/lib/puppet/pops/serialization/abstract_reader.rb +17 -7
  111. data/lib/puppet/pops/serialization/abstract_writer.rb +27 -12
  112. data/lib/puppet/pops/serialization/deserializer.rb +17 -4
  113. data/lib/puppet/pops/serialization/extension.rb +37 -8
  114. data/lib/puppet/pops/serialization/object.rb +14 -6
  115. data/lib/puppet/pops/serialization/rgen.rb +2 -1
  116. data/lib/puppet/pops/serialization/serializer.rb +30 -7
  117. data/lib/puppet/pops/types/implementation_registry.rb +1 -1
  118. data/lib/puppet/pops/types/p_object_type.rb +55 -12
  119. data/lib/puppet/pops/types/p_sem_ver_range_type.rb +27 -27
  120. data/lib/puppet/pops/types/p_sem_ver_type.rb +12 -12
  121. data/lib/puppet/pops/types/p_timespan_type.rb +6 -6
  122. data/lib/puppet/pops/types/p_timestamp_type.rb +2 -2
  123. data/lib/puppet/pops/types/p_type_set_type.rb +7 -16
  124. data/lib/puppet/pops/types/recursion_guard.rb +64 -20
  125. data/lib/puppet/pops/types/ruby_generator.rb +10 -0
  126. data/lib/puppet/pops/types/type_calculator.rb +23 -13
  127. data/lib/puppet/pops/types/type_factory.rb +20 -9
  128. data/lib/puppet/pops/types/type_formatter.rb +37 -17
  129. data/lib/puppet/pops/types/type_mismatch_describer.rb +7 -6
  130. data/lib/puppet/pops/types/type_parser.rb +6 -0
  131. data/lib/puppet/pops/types/types.rb +225 -132
  132. data/lib/puppet/pops/validation/checker4_0.rb +12 -2
  133. data/lib/puppet/pops/validation/validator_factory_4_0.rb +1 -0
  134. data/lib/puppet/pops/validation.rb +1 -1
  135. data/lib/puppet/pops/visitor.rb +4 -3
  136. data/lib/puppet/pops.rb +6 -9
  137. data/lib/puppet/provider/mcx/mcxcontent.rb +2 -1
  138. data/lib/puppet/provider/nameservice.rb +15 -0
  139. data/lib/puppet/provider/package/appdmg.rb +1 -1
  140. data/lib/puppet/provider/package/dnf.rb +1 -1
  141. data/lib/puppet/provider/package/pkg.rb +1 -1
  142. data/lib/puppet/provider/package/pkgdmg.rb +1 -1
  143. data/lib/puppet/provider/package/pkgng.rb +1 -1
  144. data/lib/puppet/provider/package/rpm.rb +2 -2
  145. data/lib/puppet/provider/service/smf.rb +3 -3
  146. data/lib/puppet/provider/service/systemd.rb +5 -1
  147. data/lib/puppet/provider/user/directoryservice.rb +1 -0
  148. data/lib/puppet/provider/user/user_role_add.rb +15 -0
  149. data/lib/puppet/provider/yumrepo/inifile.rb +2 -2
  150. data/lib/puppet/provider/zone/solaris.rb +4 -1
  151. data/lib/puppet/reference/indirection.rb +1 -1
  152. data/lib/puppet/resource/catalog.rb +12 -4
  153. data/lib/puppet/resource/type.rb +3 -3
  154. data/lib/puppet/resource.rb +2 -3
  155. data/lib/puppet/settings/config_file.rb +2 -1
  156. data/lib/puppet/settings/directory_setting.rb +6 -0
  157. data/lib/puppet/settings/environment_conf.rb +6 -2
  158. data/lib/puppet/settings/file_or_directory_setting.rb +6 -0
  159. data/lib/puppet/settings/file_setting.rb +10 -0
  160. data/lib/puppet/settings.rb +1 -1
  161. data/lib/puppet/ssl/certificate_authority.rb +13 -2
  162. data/lib/puppet/ssl/host.rb +23 -1
  163. data/lib/puppet/transaction/additional_resource_generator.rb +7 -0
  164. data/lib/puppet/type/user.rb +16 -3
  165. data/lib/puppet/util/execution.rb +3 -3
  166. data/lib/puppet/util/filetype.rb +11 -5
  167. data/lib/puppet/util/logging.rb +2 -1
  168. data/lib/puppet/util/network_device/config.rb +1 -1
  169. data/lib/puppet/util/plist.rb +6 -0
  170. data/lib/puppet/util/profiler/aggregate.rb +1 -1
  171. data/lib/puppet/util/rdoc/generators/puppet_generator.rb +2 -2
  172. data/lib/puppet/util/rdoc/parser/puppet_parser_core.rb +2 -1
  173. data/lib/puppet/util/windows/adsi.rb +15 -12
  174. data/lib/puppet/util.rb +1 -0
  175. data/lib/puppet/vendor/load_semantic_puppet.rb +1 -0
  176. data/lib/puppet/vendor/pathspec/lib/pathspec.rb +2 -1
  177. data/lib/puppet/vendor/require_vendored.rb +0 -1
  178. data/lib/puppet/vendor/{semantic/lib/semantic → semantic_puppet/lib/semantic_puppet}/dependency/graph.rb +2 -2
  179. data/lib/puppet/vendor/{semantic/lib/semantic → semantic_puppet/lib/semantic_puppet}/dependency/graph_node.rb +2 -2
  180. data/lib/puppet/vendor/semantic_puppet/lib/semantic_puppet/dependency/module_release.rb +58 -0
  181. data/lib/puppet/vendor/{semantic/lib/semantic → semantic_puppet/lib/semantic_puppet}/dependency/source.rb +2 -2
  182. data/lib/puppet/vendor/{semantic/lib/semantic → semantic_puppet/lib/semantic_puppet}/dependency/unsatisfiable_graph.rb +2 -2
  183. data/lib/puppet/vendor/{semantic/lib/semantic → semantic_puppet/lib/semantic_puppet}/dependency.rb +7 -7
  184. data/lib/puppet/vendor/semantic_puppet/lib/semantic_puppet/gem_version.rb +3 -0
  185. data/lib/puppet/vendor/semantic_puppet/lib/semantic_puppet/locales/config.yaml +21 -0
  186. data/lib/puppet/vendor/{semantic/lib/semantic → semantic_puppet/lib/semantic_puppet}/version.rb +48 -21
  187. data/lib/puppet/vendor/{semantic/lib/semantic → semantic_puppet/lib/semantic_puppet}/version_range.rb +15 -17
  188. data/lib/puppet/vendor/semantic_puppet/lib/semantic_puppet.rb +17 -0
  189. data/lib/puppet/version.rb +1 -1
  190. data/lib/puppet.rb +52 -0
  191. data/lib/semver.rb +19 -12
  192. data/locales/config.yaml +29 -0
  193. data/locales/puppet.pot +79 -0
  194. data/man/man5/puppet.conf.5 +1 -1
  195. data/spec/fixtures/unit/application/environments/puppet_func_provider/functions/{data.pp → environment/data.pp} +0 -0
  196. data/spec/fixtures/unit/data_providers/environments/hiera_misc/data/common.yaml +2 -0
  197. data/spec/fixtures/unit/data_providers/environments/hiera_modules/modules/two/data/common.yaml +1 -1
  198. data/spec/fixtures/unit/data_providers/environments/sample/modules/backend/hiera.yaml +5 -0
  199. data/spec/fixtures/unit/data_providers/environments/sample/modules/backend/lib/puppet/bindings/backend/default.rb +9 -0
  200. data/spec/fixtures/unit/data_providers/environments/sample/modules/backend/lib/puppet_x/backend/special_data_provider_factory.rb +23 -0
  201. data/spec/fixtures/unit/data_providers/environments/sample/modules/backend/manifests/init.pp +5 -0
  202. data/spec/fixtures/unit/data_providers/environments/sample/modules/backend/metadata.json +9 -0
  203. data/spec/fixtures/unit/data_providers/environments/sample/modules/dataprovider/lib/puppet_x/helindbe/sample_env_data.rb +1 -0
  204. data/spec/fixtures/unit/data_providers/environments/sample/modules/dataprovider/manifests/init.pp +1 -1
  205. data/spec/fixtures/unit/functions/lookup/data/common.yaml +19 -0
  206. data/spec/fixtures/unit/functions/lookup_fixture/data/common.yaml +19 -0
  207. data/spec/fixtures/unit/functions/{lookup → lookup_fixture}/environments/production/environment.conf +0 -0
  208. data/spec/fixtures/unit/functions/{lookup → lookup_fixture}/environments/production/lib/puppet/functions/environment/data.rb +0 -0
  209. data/spec/fixtures/unit/functions/{lookup → lookup_fixture}/environments/production/modules/abc/lib/puppet/bindings/abc/default.rb +0 -0
  210. data/spec/fixtures/unit/functions/{lookup → lookup_fixture}/environments/production/modules/abc/lib/puppet/functions/abc/data.rb +0 -0
  211. data/spec/fixtures/unit/functions/{lookup → lookup_fixture}/environments/production/modules/abc/manifests/init.pp +0 -0
  212. data/spec/fixtures/unit/functions/{lookup → lookup_fixture}/environments/production/modules/bad_data/lib/puppet/bindings/bad_data/default.rb +0 -0
  213. data/spec/fixtures/unit/functions/{lookup → lookup_fixture}/environments/production/modules/bad_data/lib/puppet/functions/bad_data/data.rb +0 -0
  214. data/spec/fixtures/unit/functions/{lookup → lookup_fixture}/environments/production/modules/bad_data/manifests/init.pp +0 -0
  215. data/spec/fixtures/unit/functions/{lookup → lookup_fixture}/environments/production/modules/bca/lib/puppet/bindings/bca/default.rb +0 -0
  216. data/spec/fixtures/unit/functions/{lookup → lookup_fixture}/environments/production/modules/bca/lib/puppet/functions/bca/data.rb +0 -0
  217. data/spec/fixtures/unit/functions/{lookup → lookup_fixture}/environments/production/modules/bca/manifests/init.pp +0 -0
  218. data/spec/fixtures/unit/functions/{lookup → lookup_fixture}/environments/production/modules/empty_json/data/empty.json +0 -0
  219. data/spec/fixtures/unit/functions/{lookup → lookup_fixture}/environments/production/modules/empty_json/hiera.yaml +0 -0
  220. data/spec/fixtures/unit/functions/{lookup → lookup_fixture}/environments/production/modules/empty_json/manifests/init.pp +0 -0
  221. data/spec/fixtures/unit/functions/{lookup → lookup_fixture}/environments/production/modules/empty_json/metadata.json +0 -0
  222. data/spec/fixtures/unit/functions/{lookup → lookup_fixture}/environments/production/modules/empty_key_json/data/empty_key.json +0 -0
  223. data/spec/fixtures/unit/functions/{lookup → lookup_fixture}/environments/production/modules/empty_key_json/hiera.yaml +0 -0
  224. data/spec/fixtures/unit/functions/{lookup → lookup_fixture}/environments/production/modules/empty_key_json/manifests/init.pp +0 -0
  225. data/spec/fixtures/unit/functions/{lookup → lookup_fixture}/environments/production/modules/empty_key_json/metadata.json +0 -0
  226. data/spec/fixtures/unit/functions/{lookup → lookup_fixture}/environments/production/modules/empty_key_yaml/data/empty_key.yaml +0 -0
  227. data/spec/fixtures/unit/functions/{lookup → lookup_fixture}/environments/production/modules/empty_key_yaml/hiera.yaml +0 -0
  228. data/spec/fixtures/unit/functions/{lookup → lookup_fixture}/environments/production/modules/empty_key_yaml/manifests/init.pp +0 -0
  229. data/spec/fixtures/unit/functions/{lookup → lookup_fixture}/environments/production/modules/empty_key_yaml/metadata.json +0 -0
  230. data/spec/fixtures/unit/functions/{lookup → lookup_fixture}/environments/production/modules/empty_yaml/data/empty.yaml +0 -0
  231. data/spec/fixtures/unit/functions/{lookup → lookup_fixture}/environments/production/modules/empty_yaml/hiera.yaml +0 -0
  232. data/spec/fixtures/unit/functions/{lookup → lookup_fixture}/environments/production/modules/empty_yaml/manifests/init.pp +0 -0
  233. data/spec/fixtures/unit/functions/{lookup → lookup_fixture}/environments/production/modules/empty_yaml/metadata.json +0 -0
  234. data/spec/fixtures/unit/functions/{lookup → lookup_fixture}/environments/production/modules/hieraprovider/data/first.json +0 -0
  235. data/spec/fixtures/unit/functions/{lookup → lookup_fixture}/environments/production/modules/hieraprovider/hiera.yaml +0 -0
  236. data/spec/fixtures/unit/functions/{lookup → lookup_fixture}/environments/production/modules/hieraprovider/manifests/init.pp +0 -0
  237. data/spec/fixtures/unit/functions/{lookup → lookup_fixture}/environments/production/modules/hieraprovider/metadata.json +0 -0
  238. data/spec/fixtures/unit/functions/{lookup → lookup_fixture}/environments/production/modules/meta/lib/puppet/functions/meta/data.rb +0 -0
  239. data/spec/fixtures/unit/functions/{lookup → lookup_fixture}/environments/production/modules/meta/manifests/init.pp +0 -0
  240. data/spec/fixtures/unit/functions/{lookup → lookup_fixture}/environments/production/modules/meta/metadata.json +0 -0
  241. data/spec/fixtures/unit/functions/{lookup → lookup_fixture}/environments/production/modules/metawcp/lib/puppet/bindings/metawcp/default.rb +0 -0
  242. data/spec/fixtures/unit/functions/{lookup → lookup_fixture}/environments/production/modules/metawcp/lib/puppet_x/thallgren/sample_module_data.rb +0 -0
  243. data/spec/fixtures/unit/functions/{lookup → lookup_fixture}/environments/production/modules/metawcp/manifests/init.pp +0 -0
  244. data/spec/fixtures/unit/functions/{lookup → lookup_fixture}/environments/production/modules/metawcp/metadata.json +0 -0
  245. data/spec/fixtures/unit/functions/{lookup → lookup_fixture}/environments/production/modules/no_provider/manifests/init.pp +0 -0
  246. data/spec/integration/application/apply_spec.rb +88 -2
  247. data/spec/integration/application/lookup_spec.rb +155 -0
  248. data/spec/integration/data_binding_spec.rb +5 -5
  249. data/spec/integration/defaults_spec.rb +13 -0
  250. data/spec/integration/environments/default_manifest_spec.rb +16 -16
  251. data/spec/integration/environments/setting_hooks_spec.rb +1 -1
  252. data/spec/integration/test/test_helper_spec.rb +6 -2
  253. data/spec/integration/transaction_spec.rb +74 -0
  254. data/spec/integration/util/execution_spec.rb +8 -0
  255. data/spec/lib/puppet_spec/module_tool/shared_functions.rb +2 -2
  256. data/spec/lib/puppet_spec/module_tool/stub_source.rb +1 -1
  257. data/spec/lib/puppet_spec/unindent.rb +2 -2
  258. data/spec/unit/application/face_base_spec.rb +16 -0
  259. data/spec/unit/application/lookup_spec.rb +262 -227
  260. data/spec/unit/data_providers/{sample_data_provider_spec.rb → custom_data_provider_spec.rb} +14 -16
  261. data/spec/unit/data_providers/function_data_provider_spec.rb +2 -2
  262. data/spec/unit/data_providers/hiera_data_provider_spec.rb +60 -97
  263. data/spec/unit/defaults_spec.rb +1 -1
  264. data/spec/unit/face/ca_spec.rb +10 -0
  265. data/spec/unit/face/certificate_request_spec.rb +10 -0
  266. data/spec/unit/face/certificate_revocation_list_spec.rb +10 -0
  267. data/spec/unit/face/file_spec.rb +4 -0
  268. data/spec/unit/face/help_spec.rb +17 -0
  269. data/spec/unit/face/key_spec.rb +10 -0
  270. data/spec/unit/face/status_spec.rb +10 -0
  271. data/spec/unit/file_system_spec.rb +143 -6
  272. data/spec/unit/functions/binary_file_spec.rb +1 -1
  273. data/spec/unit/functions/hiera_spec.rb +257 -47
  274. data/spec/unit/functions/lookup_fixture_spec.rb +693 -0
  275. data/spec/unit/functions/lookup_spec.rb +1319 -608
  276. data/spec/unit/functions/new_spec.rb +3 -3
  277. data/spec/unit/graph/rb_tree_map_spec.rb +1 -1
  278. data/spec/unit/graph/simple_graph_spec.rb +1 -1
  279. data/spec/unit/hiera/scope_spec.rb +4 -4
  280. data/spec/unit/indirector/request_spec.rb +9 -0
  281. data/spec/unit/interface_spec.rb +27 -0
  282. data/spec/unit/man_spec.rb +1 -1
  283. data/spec/unit/module_spec.rb +1 -1
  284. data/spec/unit/module_tool/applications/builder_spec.rb +16 -1
  285. data/spec/unit/module_tool/applications/installer_spec.rb +1 -1
  286. data/spec/unit/module_tool/applications/upgrader_spec.rb +1 -1
  287. data/spec/unit/module_tool/installed_modules_spec.rb +6 -6
  288. data/spec/unit/module_tool_spec.rb +3 -3
  289. data/spec/unit/network/http/connection_spec.rb +10 -0
  290. data/spec/unit/network/http/webrick_spec.rb +1 -1
  291. data/spec/unit/pops/evaluator/access_ops_spec.rb +2 -2
  292. data/spec/unit/pops/evaluator/runtime3_converter_spec.rb +9 -9
  293. data/spec/unit/pops/loaders/environment_loader_spec.rb +172 -0
  294. data/spec/unit/pops/lookup/context_spec.rb +45 -16
  295. data/spec/unit/pops/lookup/interpolation_spec.rb +28 -20
  296. data/spec/unit/pops/lookup/lookup_spec.rb +197 -0
  297. data/spec/unit/pops/merge_strategy_spec.rb +18 -0
  298. data/spec/unit/pops/parser/lexer2_spec.rb +16 -1
  299. data/spec/unit/pops/parser/parse_site_spec.rb +4 -0
  300. data/spec/unit/pops/serialization/packer_spec.rb +4 -23
  301. data/spec/unit/pops/serialization/serialization_spec.rb +32 -8
  302. data/spec/unit/pops/types/p_object_type_spec.rb +68 -3
  303. data/spec/unit/pops/types/p_sem_ver_type_spec.rb +4 -4
  304. data/spec/unit/pops/types/p_type_set_type_spec.rb +31 -2
  305. data/spec/unit/pops/types/type_acceptor_spec.rb +18 -17
  306. data/spec/unit/pops/types/type_calculator_spec.rb +39 -40
  307. data/spec/unit/pops/types/type_factory_spec.rb +3 -3
  308. data/spec/unit/pops/types/type_formatter_spec.rb +7 -3
  309. data/spec/unit/pops/types/type_mismatch_describer_spec.rb +13 -2
  310. data/spec/unit/pops/types/types_spec.rb +25 -2
  311. data/spec/unit/pops/validator/validator_spec.rb +60 -4
  312. data/spec/unit/provider/nameservice_spec.rb +42 -0
  313. data/spec/unit/provider/package/aptrpm_spec.rb +1 -1
  314. data/spec/unit/provider/package/pkg_spec.rb +22 -0
  315. data/spec/unit/provider/package/pkgng_spec.rb +12 -0
  316. data/spec/unit/provider/package/rpm_spec.rb +8 -8
  317. data/spec/unit/provider/service/smf_spec.rb +13 -11
  318. data/spec/unit/provider/service/systemd_spec.rb +8 -1
  319. data/spec/unit/provider/user/useradd_spec.rb +1 -0
  320. data/spec/unit/puppet_spec.rb +14 -0
  321. data/spec/unit/resource/catalog_spec.rb +15 -9
  322. data/spec/unit/resource_spec.rb +20 -17
  323. data/spec/unit/semver_spec.rb +14 -0
  324. data/spec/unit/ssl/certificate_authority_spec.rb +12 -1
  325. data/spec/unit/transaction/additional_resource_generator_spec.rb +11 -0
  326. data/spec/unit/type/user_spec.rb +32 -6
  327. data/spec/unit/util/filetype_spec.rb +3 -3
  328. data/spec/unit/util/yaml_spec.rb +1 -1
  329. data/spec/unit/util_spec.rb +10 -2
  330. data/tasks/i18n.rake +20 -0
  331. metadata +2661 -2595
  332. data/lib/puppet/data_providers/lookup_adapter.rb +0 -254
  333. data/lib/puppet/vendor/load_semantic.rb +0 -1
  334. data/lib/puppet/vendor/semantic/Gemfile +0 -20
  335. data/lib/puppet/vendor/semantic/PUPPET_README.md +0 -6
  336. data/lib/puppet/vendor/semantic/Rakefile +0 -69
  337. data/lib/puppet/vendor/semantic/lib/semantic/dependency/module_release.rb +0 -60
  338. data/lib/puppet/vendor/semantic/lib/semantic.rb +0 -7
  339. data/lib/puppet/vendor/semantic/spec/spec_helper.rb +0 -24
  340. data/lib/puppet/vendor/semantic/spec/unit/semantic/dependency/graph_node_spec.rb +0 -141
  341. data/lib/puppet/vendor/semantic/spec/unit/semantic/dependency/graph_spec.rb +0 -162
  342. data/lib/puppet/vendor/semantic/spec/unit/semantic/dependency/module_release_spec.rb +0 -143
  343. data/lib/puppet/vendor/semantic/spec/unit/semantic/dependency/source_spec.rb +0 -5
  344. data/lib/puppet/vendor/semantic/spec/unit/semantic/dependency/unsatisfiable_graph_spec.rb +0 -44
  345. data/lib/puppet/vendor/semantic/spec/unit/semantic/dependency_spec.rb +0 -383
  346. data/lib/puppet/vendor/semantic/spec/unit/semantic/version_range_spec.rb +0 -307
  347. data/lib/puppet/vendor/semantic/spec/unit/semantic/version_spec.rb +0 -608
  348. data/spec/fixtures/unit/data_providers/environments/sample/manifests/site.pp +0 -6
@@ -2,11 +2,12 @@
2
2
  require 'spec_helper'
3
3
  require 'puppet_spec/compiler'
4
4
 
5
- describe "when using a sample data provider from an external module" do
5
+ describe 'when using a custom data provider' do
6
6
  include PuppetSpec::Compiler
7
7
 
8
8
  # There is a fully configured 'sample' environment in fixtures at this location
9
9
  let(:environmentpath) { parent_fixture('environments') }
10
+ let(:node) { Puppet::Node.new('testnode', :facts => Puppet::Node::Facts.new("facts", {}), :environment => 'sample') }
10
11
 
11
12
  around(:each) do |example|
12
13
  # Initialize settings to get a full compile as close as possible to a real
@@ -26,27 +27,24 @@ describe "when using a sample data provider from an external module" do
26
27
  end
27
28
 
28
29
  it 'the environment data loader is used to set parameters' do
29
- node = Puppet::Node.new("testnode", :facts => Puppet::Node::Facts.new("facts", {}), :environment => 'sample')
30
- compiler = Puppet::Parser::Compiler.new(node)
31
- catalog = compiler.compile()
32
- resources_created_in_fixture = ["Notify[env data param_a is 10, env data param_b is 20, 3]"]
33
- expect(resources_in(catalog)).to include(*resources_created_in_fixture)
30
+ code = <<-PUPPET.unindent
31
+ class test($param_a = 1, $param_b = 2, $param_c = 3) {
32
+ notice("$param_a, $param_b, $param_c")
33
+ }
34
+ include test
35
+ PUPPET
36
+ expect(eval_and_collect_notices(code, node)).to eql(['env data param_a is 10, env data param_b is 20, 3'])
34
37
  end
35
38
 
36
39
  it 'the module and environment data loader is used to set parameters' do
37
- node = Puppet::Node.new("testnode", :facts => Puppet::Node::Facts.new("facts", {}), :environment => 'sample')
38
- compiler = Puppet::Parser::Compiler.new(node)
39
- catalog = compiler.compile()
40
- resources_created_in_fixture = ["Notify[module data param_a is 100, module data param_b is 200, env data param_c is 300]"]
41
- expect(resources_in(catalog)).to include(*resources_created_in_fixture)
40
+ expect(eval_and_collect_notices('include dataprovider::test', node)).to eql(['module data param_a is 100, module data param_b is 200, env data param_c is 300'])
42
41
  end
43
42
 
44
- def parent_fixture(dir_name)
45
- File.absolute_path(File.join(my_fixture_dir(), "../#{dir_name}"))
43
+ it 'the custom hiera backend in a module and the environment data loader is used to set parameters' do
44
+ expect(eval_and_collect_notices('include backend::test', node)).to eql(['module data param_a is 1000, module data param_b is 2000, env data param_c is 3000'])
46
45
  end
47
46
 
48
- def resources_in(catalog)
49
- catalog.resources.map(&:ref)
47
+ def parent_fixture(dir_name)
48
+ File.absolute_path(File.join(my_fixture_dir(), "../#{dir_name}"))
50
49
  end
51
-
52
50
  end
@@ -90,7 +90,7 @@ describe "when using function data provider" do
90
90
  env_loader.add_entry(:function, 'environment::data', f.new(compiler.topscope, env_loader), nil)
91
91
  expect do
92
92
  compiler.compile()
93
- end.to raise_error(/Expected 'environment::data' function to return a Hash/)
93
+ end.to raise_error(/Value returned from deprecated API function "environment::data" has wrong type/)
94
94
  end
95
95
 
96
96
  it 'raises an error if the module data function does not return a hash' do
@@ -109,7 +109,7 @@ describe "when using function data provider" do
109
109
  module_loader.add_entry(:function, 'abc::data', f.new(compiler.topscope, module_loader), nil)
110
110
  expect do
111
111
  compiler.compile()
112
- end.to raise_error(/Expected 'abc::data' function to return a Hash/)
112
+ end.to raise_error(/Value returned from deprecated API function "abc::data" has wrong type/)
113
113
  end
114
114
 
115
115
  def parent_fixture(dir_name)
@@ -35,6 +35,7 @@ describe "when using a hiera data provider" do
35
35
  Puppet[:code] = code if code
36
36
  node = Puppet::Node.new("testnode", :facts => facts, :environment => environment)
37
37
  compiler = Puppet::Parser::Compiler.new(node)
38
+ compiler.topscope['domain'] = 'example.com'
38
39
  block_given? ? compiler.compile { |catalog| yield(compiler); catalog } : compiler.compile
39
40
  end
40
41
 
@@ -170,7 +171,12 @@ describe "when using a hiera data provider" do
170
171
  it 'traps endless interpolate recursion' do
171
172
  expect do
172
173
  compile_and_get_notifications('hiera_misc', '$r1 = "%{r2}" $r2 = "%{r1}" notify{lookup(recursive):}')
173
- end.to raise_error(Puppet::DataBinding::RecursiveLookupError, /detected in \[recursive, r1, r2\]/)
174
+ end.to raise_error(Puppet::DataBinding::RecursiveLookupError, /detected in \[recursive, scope:r1, scope:r2\]/)
175
+ end
176
+
177
+ it 'does not consider use of same key in the lookup and scope namespaces as recursion' do
178
+ resources = compile_and_get_notifications('hiera_misc', 'notify{lookup(domain):}')
179
+ expect(resources).to include('-- example.com --')
174
180
  end
175
181
 
176
182
  it 'traps bad alias declarations' do
@@ -196,21 +202,14 @@ describe "when using a hiera data provider" do
196
202
  compile('hiera_misc', '$target_scope = "with scope"') do |compiler|
197
203
  lookup_invocation = Puppet::Pops::Lookup::Invocation.new(compiler.topscope, {}, {}, true)
198
204
  value = Puppet::Pops::Lookup.lookup('km_scope', nil, nil, nil, nil, lookup_invocation)
199
- expect(lookup_invocation.explainer.to_s).to eq(<<EOS)
200
- Merge strategy first
201
- Data Binding "hiera"
202
- No such key: "km_scope"
203
- Data Provider "Hiera Data Provider, version 4"
204
- ConfigurationPath "#{environmentpath}/hiera_misc/hiera.yaml"
205
- Data Provider "common"
205
+ expect(lookup_invocation.explainer.explain).to include(<<-EOS)
206
206
  Path "#{environmentpath}/hiera_misc/data/common.yaml"
207
- Original path: "common"
207
+ Original path: "common.yaml"
208
208
  Interpolation on "Value from interpolation %{scope("target_scope")}"
209
209
  Global Scope
210
210
  Found key: "target_scope" value: "with scope"
211
211
  Found key: "km_scope" value: "Value from interpolation with scope"
212
- Merged result: "Value from interpolation with scope"
213
- EOS
212
+ EOS
214
213
  end
215
214
  end
216
215
 
@@ -218,49 +217,7 @@ EOS
218
217
  compile('hiera_misc', '$target_scope = "with scope"') do |compiler|
219
218
  lookup_invocation = Puppet::Pops::Lookup::Invocation.new(compiler.topscope, {}, {}, true)
220
219
  value = Puppet::Pops::Lookup.lookup('one::loptsm_test::hash', nil, nil, nil, nil, lookup_invocation)
221
- expect(lookup_invocation.explainer.to_s).to eq(<<EOS)
222
- Using merge options from "lookup_options" hash
223
- Merge strategy deep
224
- Data Binding "hiera"
225
- No such key: "one::loptsm_test::hash"
226
- Data Provider "Hiera Data Provider, version 4"
227
- ConfigurationPath "#{environmentpath}/hiera_misc/hiera.yaml"
228
- Data Provider "common"
229
- Path "#{environmentpath}/hiera_misc/data/common.yaml"
230
- Original path: "common"
231
- Found key: "one::loptsm_test::hash" value: {
232
- "a" => "A",
233
- "b" => "B",
234
- "m" => {
235
- "ma" => "MA",
236
- "mb" => "MB"
237
- }
238
- }
239
- Module "one" using Data Provider "Hiera Data Provider, version 4"
240
- ConfigurationPath "#{environmentpath}/hiera_misc/modules/one/hiera.yaml"
241
- Data Provider "common"
242
- Path "#{environmentpath}/hiera_misc/modules/one/data/common.yaml"
243
- Original path: "common"
244
- Found key: "one::loptsm_test::hash" value: {
245
- "a" => "A",
246
- "c" => "C",
247
- "m" => {
248
- "ma" => "MA",
249
- "mc" => "MC",
250
- "mb" => "MB"
251
- }
252
- }
253
- Merged result: {
254
- "a" => "A",
255
- "c" => "C",
256
- "m" => {
257
- "ma" => "MA",
258
- "mc" => "MC",
259
- "mb" => "MB"
260
- },
261
- "b" => "B"
262
- }
263
- EOS
220
+ expect(lookup_invocation.explainer.explain).to include("Using merge options from \"lookup_options\" hash")
264
221
  end
265
222
  end
266
223
 
@@ -268,31 +225,41 @@ EOS
268
225
  compile('hiera_misc', '$target_scope = "with scope"') do |compiler|
269
226
  lookup_invocation = Puppet::Pops::Lookup::Invocation.new(compiler.topscope, {}, {}, Puppet::Pops::Lookup::Explainer.new(true))
270
227
  value = Puppet::Pops::Lookup.lookup('one::loptsm_test::hash', nil, nil, nil, nil, lookup_invocation)
271
- expect(lookup_invocation.explainer.to_s).to eq(<<EOS)
228
+ expect(lookup_invocation.explainer.explain).to eq(<<EOS)
272
229
  Searching for "lookup_options"
273
- Merge strategy hash
274
- Data Binding "hiera"
275
- No such key: "lookup_options"
276
- Data Provider "Hiera Data Provider, version 4"
277
- ConfigurationPath "#{environmentpath}/hiera_misc/hiera.yaml"
278
- Data Provider "common"
279
- Path "#{environmentpath}/hiera_misc/data/common.yaml"
280
- Original path: "common"
281
- Found key: "lookup_options" value: {
282
- "one::lopts_test::hash" => {
283
- "merge" => "deep"
284
- }
230
+ Global Data Provider (hiera configuration version 5)
231
+ No such key: "lookup_options"
232
+ Environment Data Provider (hiera configuration version 5)
233
+ Hierarchy entry "Common"
234
+ Path "#{environmentpath}/hiera_misc/data/common.yaml"
235
+ Original path: "common.yaml"
236
+ Found key: "lookup_options" value: {
237
+ "one::lopts_test::hash" => {
238
+ "merge" => "deep"
285
239
  }
286
- Module "one" using Data Provider "Hiera Data Provider, version 4"
287
- ConfigurationPath "#{environmentpath}/hiera_misc/modules/one/hiera.yaml"
288
- Data Provider "common"
289
- Path "#{environmentpath}/hiera_misc/modules/one/data/common.yaml"
290
- Original path: "common"
291
- Found key: "lookup_options" value: {
292
- "one::loptsm_test::hash" => {
293
- "merge" => "deep"
294
- }
240
+ }
241
+ Module "one" Data Provider (hiera configuration version 5)
242
+ Hierarchy entry "Common"
243
+ Path "#{environmentpath}/hiera_misc/modules/one/data/common.yaml"
244
+ Original path: "common.yaml"
245
+ Found key: "lookup_options" value: {
246
+ "one::loptsm_test::hash" => {
247
+ "merge" => "deep"
295
248
  }
249
+ }
250
+ Merge strategy hash
251
+ Global and Environment
252
+ Found key: "lookup_options" value: {
253
+ "one::lopts_test::hash" => {
254
+ "merge" => "deep"
255
+ }
256
+ }
257
+ Module one
258
+ Found key: "lookup_options" value: {
259
+ "one::loptsm_test::hash" => {
260
+ "merge" => "deep"
261
+ }
262
+ }
296
263
  Merged result: {
297
264
  "one::loptsm_test::hash" => {
298
265
  "merge" => "deep"
@@ -301,15 +268,15 @@ Searching for "lookup_options"
301
268
  "merge" => "deep"
302
269
  }
303
270
  }
271
+ Using merge options from "lookup_options" hash
304
272
  Searching for "one::loptsm_test::hash"
305
273
  Merge strategy deep
306
- Data Binding "hiera"
274
+ Global Data Provider (hiera configuration version 5)
307
275
  No such key: "one::loptsm_test::hash"
308
- Data Provider "Hiera Data Provider, version 4"
309
- ConfigurationPath "#{environmentpath}/hiera_misc/hiera.yaml"
310
- Data Provider "common"
276
+ Environment Data Provider (hiera configuration version 5)
277
+ Hierarchy entry "Common"
311
278
  Path "#{environmentpath}/hiera_misc/data/common.yaml"
312
- Original path: "common"
279
+ Original path: "common.yaml"
313
280
  Found key: "one::loptsm_test::hash" value: {
314
281
  "a" => "A",
315
282
  "b" => "B",
@@ -318,18 +285,16 @@ Searching for "one::loptsm_test::hash"
318
285
  "mb" => "MB"
319
286
  }
320
287
  }
321
- Module "one" using Data Provider "Hiera Data Provider, version 4"
322
- ConfigurationPath "#{environmentpath}/hiera_misc/modules/one/hiera.yaml"
323
- Data Provider "common"
288
+ Module "one" Data Provider (hiera configuration version 5)
289
+ Hierarchy entry "Common"
324
290
  Path "#{environmentpath}/hiera_misc/modules/one/data/common.yaml"
325
- Original path: "common"
291
+ Original path: "common.yaml"
326
292
  Found key: "one::loptsm_test::hash" value: {
327
293
  "a" => "A",
328
294
  "c" => "C",
329
295
  "m" => {
330
296
  "ma" => "MA",
331
- "mc" => "MC",
332
- "mb" => "MB"
297
+ "mc" => "MC"
333
298
  }
334
299
  }
335
300
  Merged result: {
@@ -350,25 +315,23 @@ EOS
350
315
  compile('hiera_misc', '$target_scope = "with scope"') do |compiler|
351
316
  lookup_invocation = Puppet::Pops::Lookup::Invocation.new(compiler.topscope, {}, {}, Puppet::Pops::Lookup::Explainer.new(true, true))
352
317
  value = Puppet::Pops::Lookup.lookup('one::loptsm_test::hash', nil, nil, nil, nil, lookup_invocation)
353
- expect(lookup_invocation.explainer.to_s).to eq(<<EOS)
318
+ expect(lookup_invocation.explainer.explain).to eq(<<EOS)
354
319
  Merge strategy hash
355
- Data Binding "hiera"
320
+ Global Data Provider (hiera configuration version 5)
356
321
  No such key: "lookup_options"
357
- Data Provider "Hiera Data Provider, version 4"
358
- ConfigurationPath "#{environmentpath}/hiera_misc/hiera.yaml"
359
- Data Provider "common"
322
+ Environment Data Provider (hiera configuration version 5)
323
+ Hierarchy entry "Common"
360
324
  Path "#{environmentpath}/hiera_misc/data/common.yaml"
361
- Original path: "common"
325
+ Original path: "common.yaml"
362
326
  Found key: "lookup_options" value: {
363
327
  "one::lopts_test::hash" => {
364
328
  "merge" => "deep"
365
329
  }
366
330
  }
367
- Module "one" using Data Provider "Hiera Data Provider, version 4"
368
- ConfigurationPath "#{environmentpath}/hiera_misc/modules/one/hiera.yaml"
369
- Data Provider "common"
331
+ Module "one" Data Provider (hiera configuration version 5)
332
+ Hierarchy entry "Common"
370
333
  Path "#{environmentpath}/hiera_misc/modules/one/data/common.yaml"
371
- Original path: "common"
334
+ Original path: "common.yaml"
372
335
  Found key: "lookup_options" value: {
373
336
  "one::loptsm_test::hash" => {
374
337
  "merge" => "deep"
@@ -104,7 +104,7 @@ describe "Defaults" do
104
104
  expect(Puppet.settings[:supported_checksum_types]).to eq(['sha256', 'md5lite', 'mtime'])
105
105
  end
106
106
  end
107
-
107
+
108
108
  describe 'server vs server_list' do
109
109
  it 'should warn when both settings are set in code' do
110
110
  Puppet.expects(:deprecation_warning).with('Attempted to set both server and server_list. Server setting will not be used.', :SERVER_DUPLICATION)
@@ -0,0 +1,10 @@
1
+ #! /usr/bin/env ruby
2
+ require 'spec_helper'
3
+ require 'puppet/face'
4
+
5
+ describe Puppet::Face[:ca, '0.1.0'] do
6
+ it "should be deprecated" do
7
+ expect(subject.deprecated?).to be_truthy
8
+ end
9
+ end
10
+
@@ -0,0 +1,10 @@
1
+ #! /usr/bin/env ruby
2
+ require 'spec_helper'
3
+ require 'puppet/face'
4
+
5
+ describe Puppet::Face[:certificate_request, '0.0.1'] do
6
+ it "should be deprecated" do
7
+ expect(subject.deprecated?).to be_truthy
8
+ end
9
+ end
10
+
@@ -0,0 +1,10 @@
1
+ #! /usr/bin/env ruby
2
+ require 'spec_helper'
3
+ require 'puppet/face'
4
+
5
+ describe Puppet::Face[:certificate_revocation_list, '0.0.1'] do
6
+ it "should be deprecated" do
7
+ expect(subject.deprecated?).to be_truthy
8
+ end
9
+ end
10
+
@@ -7,4 +7,8 @@ describe Puppet::Face[:file, '0.0.1'] do
7
7
  it { is_expected.to be_action action }
8
8
  it { is_expected.to respond_to action }
9
9
  end
10
+
11
+ it "should be deprecated" do
12
+ expect(subject.deprecated?).to be_truthy
13
+ end
10
14
  end
@@ -141,6 +141,23 @@ describe Puppet::Face[:help, '0.0.1'] do
141
141
  end
142
142
  end
143
143
 
144
+ context "deprecated faces" do
145
+ it "prints a deprecation warning for deprecated faces" do
146
+ Puppet::Face[:module, :current].stubs(:deprecated?).returns(true)
147
+ expect(Puppet::Face[:help, :current].help(:module)).to match(/Warning: 'puppet module' is deprecated/)
148
+ end
149
+ end
150
+
151
+ context "#all_application_summaries" do
152
+ it "appends a deprecation warning for deprecated faces" do
153
+ # Stub the module face as deprecated
154
+ Puppet::Face[:module, :current].expects(:deprecated?).returns(true)
155
+ result = Puppet::Face[:help, :current].all_application_summaries.each do |appname,summary|
156
+ expect(summary).to match(/Deprecated/) if appname == 'module'
157
+ end
158
+ end
159
+ end
160
+
144
161
  context "#legacy_applications" do
145
162
  subject { Puppet::Face[:help, :current].legacy_applications }
146
163
 
@@ -0,0 +1,10 @@
1
+ #! /usr/bin/env ruby
2
+ require 'spec_helper'
3
+ require 'puppet/face'
4
+
5
+ describe Puppet::Face[:key, '0.0.1'] do
6
+ it "should be deprecated" do
7
+ expect(subject.deprecated?).to be_truthy
8
+ end
9
+ end
10
+
@@ -0,0 +1,10 @@
1
+ #! /usr/bin/env ruby
2
+ require 'spec_helper'
3
+ require 'puppet/face'
4
+
5
+ describe Puppet::Face[:status, '0.0.1'] do
6
+ it "should be deprecated" do
7
+ expect(subject.deprecated?).to be_truthy
8
+ end
9
+ end
10
+
@@ -5,6 +5,13 @@ require 'puppet/util/platform'
5
5
  describe "Puppet::FileSystem" do
6
6
  include PuppetSpec::Files
7
7
 
8
+ # different UTF-8 widths
9
+ # 1-byte A
10
+ # 2-byte ۿ - http://www.fileformat.info/info/unicode/char/06ff/index.htm - 0xDB 0xBF / 219 191
11
+ # 3-byte ᚠ - http://www.fileformat.info/info/unicode/char/16A0/index.htm - 0xE1 0x9A 0xA0 / 225 154 160
12
+ # 4-byte 𠜎 - http://www.fileformat.info/info/unicode/char/2070E/index.htm - 0xF0 0xA0 0x9C 0x8E / 240 160 156 142
13
+ let (:mixed_utf8) { "A\u06FF\u16A0\u{2070E}" } # Aۿᚠ𠜎
14
+
8
15
  def with_file_content(content)
9
16
  path = tmpfile('file-system')
10
17
  file = File.new(path, 'wb')
@@ -17,6 +24,106 @@ describe "Puppet::FileSystem" do
17
24
  file.close
18
25
  end
19
26
 
27
+ SYSTEM_SID_BYTES = [1, 1, 0, 0, 0, 0, 0, 5, 18, 0, 0, 0]
28
+
29
+ def is_current_user_system?
30
+ SYSTEM_SID_BYTES == Puppet::Util::Windows::ADSI::User.current_user_sid.sid_bytes
31
+ end
32
+
33
+ context "#open" do
34
+ it "uses the same default mode as File.open, when specifying a nil mode (umask used on non-Windows)" do
35
+ file = tmpfile('file_to_update')
36
+ expect(Puppet::FileSystem.exist?(file)).to be_falsey
37
+
38
+ Puppet::FileSystem.open(file, nil, 'a') { |fh| fh.write('') }
39
+
40
+ expected_perms = Puppet::Util::Platform.windows? ?
41
+ # default Windows mode based on temp file storage for SYSTEM user or regular user
42
+ # for Jenkins or other services running as SYSTEM writing to c:\windows\temp
43
+ # the permissions will typically be SYSTEM(F) / Administrators(F) which is 770
44
+ # but sometimes there are extra users like IIS_IUSRS granted rights which adds the "extra ace" 2
45
+ # for local Administrators writing to their own temp folders under c:\users\USER
46
+ # they will have (F) for themselves, and Users will not have a permission, hence 700
47
+ (is_current_user_system? ? ['770', '2000770'] : '2000700') :
48
+ # or for *nix determine expected mode via bitwise AND complement of umask
49
+ (0100000 | 0666 & ~File.umask).to_s(8)
50
+ expect([expected_perms].flatten).to include(Puppet::FileSystem.stat(file).mode.to_s(8))
51
+
52
+ default_file = tmpfile('file_to_update2')
53
+ expect(Puppet::FileSystem.exist?(default_file)).to be_falsey
54
+
55
+ File.open(default_file, 'a') { |fh| fh.write('') }
56
+
57
+ # which matches the behavior of File.open
58
+ expect(Puppet::FileSystem.stat(file).mode).to eq(Puppet::FileSystem.stat(default_file).mode)
59
+ end
60
+
61
+ it "can accept an octal mode integer" do
62
+ file = tmpfile('file_to_update')
63
+ # NOTE: 777 here returns 755, but due to Ruby?
64
+ Puppet::FileSystem.open(file, 0444, 'a') { |fh| fh.write('') }
65
+
66
+ # Behavior may change in the future on Windows, to *actually* change perms
67
+ # but for now, setting a mode doesn't touch them
68
+ expected_perms = Puppet::Util::Platform.windows? ?
69
+ (is_current_user_system? ? ['770', '2000770'] : '2000700') :
70
+ '100444'
71
+ expect([expected_perms].flatten).to include(Puppet::FileSystem.stat(file).mode.to_s(8))
72
+
73
+ expected_ruby_mode = Puppet::Util::Platform.windows? ?
74
+ # The Windows behavior has been changed to ignore the mode specified by open
75
+ # given it's unlikely a caller expects Windows file attributes to be set
76
+ # therefore mode is explicitly not managed (until PUP-6959 is fixed)
77
+ #
78
+ # In default Ruby on Windows a mode controls file attribute setting
79
+ # (like archive, read-only, etc)
80
+ # The GetFileInformationByHandle API returns an attributes value that is
81
+ # a bitmask of Windows File Attribute Constants at
82
+ # https://msdn.microsoft.com/en-us/library/windows/desktop/gg258117(v=vs.85).aspx
83
+ '100644' :
84
+ # On other platforms, the mode should be what was set by octal 0444
85
+ '100444'
86
+
87
+ expect(File.stat(file).mode.to_s(8)).to eq(expected_ruby_mode)
88
+ end
89
+
90
+ it "cannot accept a mode string" do
91
+ file = tmpfile('file_to_update')
92
+ expect {
93
+ Puppet::FileSystem.open(file, "444", 'a') { |fh| fh.write('') }
94
+ }.to raise_error(TypeError)
95
+ end
96
+
97
+ it "opens, creates ands allows updating of a new file, using by default, the external system encoding" do
98
+ begin
99
+ original_encoding = Encoding.default_external
100
+
101
+ # this must be set through Ruby API and cannot be mocked - it sets internal state used by File.open
102
+ # pick a bizarre encoding unlikely to be used in any real tests
103
+ Encoding.default_external = Encoding::CP737
104
+
105
+ file = tmpfile('file_to_update')
106
+
107
+ # test writing a UTF-8 string when Default external encoding is something different
108
+ Puppet::FileSystem.open(file, 0660, 'w') do |fh|
109
+ # note Ruby behavior which has no external_encoding, but implicitly uses Encoding.default_external
110
+ expect(fh.external_encoding).to be_nil
111
+ # write a UTF-8 string to this file
112
+ fh.write(mixed_utf8)
113
+ end
114
+
115
+ # prove that Ruby implicitly converts read strings back to Encoding.default_external
116
+ # and that it did that in the previous write
117
+ written = Puppet::FileSystem.read(file)
118
+ expect(written.encoding).to eq(Encoding.default_external)
119
+ expect(written).to eq(mixed_utf8.force_encoding(Encoding.default_external))
120
+ ensure
121
+ # carefully roll back to the previous
122
+ Encoding.default_external = original_encoding
123
+ end
124
+ end
125
+ end
126
+
20
127
  context "#exclusive_open" do
21
128
  it "opens ands allows updating of an existing file" do
22
129
  file = file_containing("file_to_update", "the contents")
@@ -31,14 +138,33 @@ describe "Puppet::FileSystem" do
31
138
  expect(Puppet::FileSystem.read(file)).to eq("updated the contents")
32
139
  end
33
140
 
34
- it "opens, creates ands allows updating of a new file" do
35
- file = tmpfile("file_to_update")
141
+ it "opens, creates ands allows updating of a new file, using by default, the external system encoding" do
142
+ begin
143
+ original_encoding = Encoding.default_external
36
144
 
37
- Puppet::FileSystem.exclusive_open(file, 0660, 'w') do |fh|
38
- fh.write("updated new file")
39
- end
145
+ # this must be set through Ruby API and cannot be mocked - it sets internal state used by File.open
146
+ # pick a bizarre encoding unlikely to be used in any real tests
147
+ Encoding.default_external = Encoding::CP737
148
+
149
+ file = tmpfile('file_to_update')
40
150
 
41
- expect(Puppet::FileSystem.read(file)).to eq("updated new file")
151
+ # test writing a UTF-8 string when Default external encoding is something different
152
+ Puppet::FileSystem.exclusive_open(file, 0660, 'w') do |fh|
153
+ # note Ruby behavior which has no external_encoding, but implicitly uses Encoding.default_external
154
+ expect(fh.external_encoding).to be_nil
155
+ # write a UTF-8 string to this file
156
+ fh.write(mixed_utf8)
157
+ end
158
+
159
+ # prove that Ruby implicitly converts read strings back to Encoding.default_external
160
+ # and that it did that in the previous write
161
+ written = Puppet::FileSystem.read(file)
162
+ expect(written.encoding).to eq(Encoding.default_external)
163
+ expect(written).to eq(mixed_utf8.force_encoding(Encoding.default_external))
164
+ ensure
165
+ # carefully roll back to the previous
166
+ Encoding.default_external = original_encoding
167
+ end
42
168
  end
43
169
 
44
170
  it "excludes other processes from updating at the same time", :unless => Puppet::Util::Platform.windows? do
@@ -134,6 +260,17 @@ describe "Puppet::FileSystem" do
134
260
  end
135
261
  end
136
262
 
263
+ context "read without an encoding specified" do
264
+ it "returns strings as Encoding.default_external" do
265
+ temp_file = file_containing('test.txt', 'hello world')
266
+
267
+ contents = Puppet::FileSystem.read(temp_file)
268
+
269
+ expect(contents.encoding).to eq(Encoding.default_external)
270
+ expect(contents).to eq('hello world')
271
+ end
272
+ end
273
+
137
274
  context "read should allow an encoding to be specified" do
138
275
  # First line of Rune version of Rune poem at http://www.columbia.edu/~fdc/utf8/
139
276
  # characters chosen since they will not parse on Windows with codepage 437 or 1252
@@ -28,7 +28,7 @@ describe 'the binary_file function' do
28
28
  with_file_content('one') do |one|
29
29
  compile_to_catalog("notify { binary_file('#{one}/nope'):}")
30
30
  end
31
- end.to raise_error(/The given file '.*' does not exist/)
31
+ end.to raise_error(/The given file '.+\/nope' does not exist/)
32
32
  end
33
33
 
34
34
  it 'reads an existing file in a module' do