puppet 6.4.5-x64-mingw32 → 6.5.0-x64-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 (329) hide show
  1. checksums.yaml +4 -4
  2. data/CODEOWNERS +10 -10
  3. data/Gemfile +6 -6
  4. data/Gemfile.lock +46 -52
  5. data/ext/build_defaults.yaml +0 -1
  6. data/ext/project_data.yaml +3 -3
  7. data/ext/regexp_nodes/regexp_nodes.rb +4 -4
  8. data/ext/solaris/smf/puppet.xml +0 -2
  9. data/ext/windows/eventlog/Rakefile +32 -0
  10. data/ext/windows/eventlog/puppetres.dll +0 -0
  11. data/ext/windows/eventlog/puppetres.mc +18 -0
  12. data/ext/windows/service/daemon.rb +8 -38
  13. data/install.rb +24 -6
  14. data/lib/puppet.rb +3 -1
  15. data/lib/puppet/application.rb +1 -1
  16. data/lib/puppet/application/agent.rb +11 -34
  17. data/lib/puppet/application/apply.rb +6 -6
  18. data/lib/puppet/application/describe.rb +9 -3
  19. data/lib/puppet/application/device.rb +4 -14
  20. data/lib/puppet/application/doc.rb +1 -1
  21. data/lib/puppet/application/lookup.rb +2 -2
  22. data/lib/puppet/application/resource.rb +4 -4
  23. data/lib/puppet/application/script.rb +2 -2
  24. data/lib/puppet/application/ssl.rb +10 -9
  25. data/lib/puppet/configurer.rb +30 -86
  26. data/lib/puppet/configurer/downloader.rb +6 -2
  27. data/lib/puppet/defaults.rb +50 -44
  28. data/lib/puppet/error.rb +14 -9
  29. data/lib/puppet/face/catalog.rb +20 -1
  30. data/lib/puppet/face/config.rb +48 -10
  31. data/lib/puppet/face/facts.rb +1 -1
  32. data/lib/puppet/face/help.rb +1 -1
  33. data/lib/puppet/face/module/list.rb +5 -5
  34. data/lib/puppet/face/module/search.rb +1 -1
  35. data/lib/puppet/face/module/uninstall.rb +1 -1
  36. data/lib/puppet/face/module/upgrade.rb +1 -1
  37. data/lib/puppet/face/parser.rb +48 -9
  38. data/lib/puppet/face/plugin.rb +2 -9
  39. data/lib/puppet/file_serving/http_metadata.rb +1 -1
  40. data/lib/puppet/file_system.rb +12 -2
  41. data/lib/puppet/file_system/file_impl.rb +6 -3
  42. data/lib/puppet/file_system/memory_file.rb +1 -1
  43. data/lib/puppet/file_system/posix.rb +2 -3
  44. data/lib/puppet/forge.rb +3 -3
  45. data/lib/puppet/functions.rb +2 -1
  46. data/lib/puppet/functions/camelcase.rb +2 -2
  47. data/lib/puppet/functions/epp.rb +4 -4
  48. data/lib/puppet/functions/find_file.rb +9 -9
  49. data/lib/puppet/functions/inline_epp.rb +5 -5
  50. data/lib/puppet/functions/regsubst.rb +6 -8
  51. data/lib/puppet/gettext/module_translations.rb +1 -1
  52. data/lib/puppet/graph/rb_tree_map.rb +2 -2
  53. data/lib/puppet/graph/simple_graph.rb +3 -4
  54. data/lib/puppet/indirector/catalog/compiler.rb +5 -11
  55. data/lib/puppet/indirector/file_bucket_file/file.rb +1 -1
  56. data/lib/puppet/indirector/hiera.rb +0 -2
  57. data/lib/puppet/indirector/resource/ral.rb +3 -1
  58. data/lib/puppet/indirector/resource/validator.rb +1 -1
  59. data/lib/puppet/interface.rb +1 -2
  60. data/lib/puppet/loaders.rb +1 -0
  61. data/lib/puppet/metatype/manager.rb +1 -1
  62. data/lib/puppet/module.rb +1 -1
  63. data/lib/puppet/module/task.rb +4 -20
  64. data/lib/puppet/module_tool/applications/installer.rb +1 -1
  65. data/lib/puppet/module_tool/applications/uninstaller.rb +3 -3
  66. data/lib/puppet/module_tool/metadata.rb +1 -1
  67. data/lib/puppet/module_tool/shared_behaviors.rb +4 -4
  68. data/lib/puppet/module_tool/tar/mini.rb +2 -12
  69. data/lib/puppet/network/http/api/indirected_routes.rb +11 -12
  70. data/lib/puppet/network/http/connection.rb +12 -10
  71. data/lib/puppet/network/http/factory.rb +11 -1
  72. data/lib/puppet/network/http/pool.rb +0 -2
  73. data/lib/puppet/network/http/site.rb +1 -1
  74. data/lib/puppet/network/resolver.rb +2 -2
  75. data/lib/puppet/node/environment.rb +2 -4
  76. data/lib/puppet/pal/pal_impl.rb +2 -2
  77. data/lib/puppet/parser/ast.rb +1 -1
  78. data/lib/puppet/parser/ast/resourceparam.rb +1 -1
  79. data/lib/puppet/parser/functions.rb +1 -1
  80. data/lib/puppet/parser/functions/epp.rb +3 -3
  81. data/lib/puppet/parser/functions/fail.rb +8 -1
  82. data/lib/puppet/parser/functions/inline_epp.rb +5 -5
  83. data/lib/puppet/parser/scope.rb +7 -8
  84. data/lib/puppet/pops/evaluator/collectors/catalog_collector.rb +1 -1
  85. data/lib/puppet/pops/evaluator/collectors/exported_collector.rb +1 -1
  86. data/lib/puppet/pops/evaluator/external_syntax_support.rb +2 -3
  87. data/lib/puppet/pops/evaluator/runtime3_support.rb +4 -4
  88. data/lib/puppet/pops/loader/null_loader.rb +60 -0
  89. data/lib/puppet/pops/loader/ruby_legacy_function_instantiator.rb +6 -4
  90. data/lib/puppet/pops/loader/task_instantiator.rb +0 -4
  91. data/lib/puppet/pops/loaders.rb +1 -1
  92. data/lib/puppet/pops/lookup/hiera_config.rb +0 -1
  93. data/lib/puppet/pops/lookup/sub_lookup.rb +1 -1
  94. data/lib/puppet/pops/merge_strategy.rb +18 -22
  95. data/lib/puppet/pops/parser/heredoc_support.rb +1 -1
  96. data/lib/puppet/pops/parser/interpolation_support.rb +4 -4
  97. data/lib/puppet/pops/parser/locator.rb +1 -1
  98. data/lib/puppet/pops/parser/pn_parser.rb +16 -17
  99. data/lib/puppet/pops/puppet_stack.rb +49 -51
  100. data/lib/puppet/pops/types/p_sensitive_type.rb +1 -1
  101. data/lib/puppet/pops/types/string_converter.rb +10 -10
  102. data/lib/puppet/pops/types/types.rb +6 -5
  103. data/lib/puppet/property.rb +1 -1
  104. data/lib/puppet/property/ensure.rb +1 -1
  105. data/lib/puppet/provider/exec.rb +2 -6
  106. data/lib/puppet/provider/file/posix.rb +0 -5
  107. data/lib/puppet/provider/nameservice.rb +3 -10
  108. data/lib/puppet/provider/nameservice/directoryservice.rb +1 -1
  109. data/lib/puppet/provider/nameservice/pw.rb +2 -2
  110. data/lib/puppet/provider/package.rb +0 -2
  111. data/lib/puppet/provider/package/apt.rb +1 -5
  112. data/lib/puppet/provider/package/dnf.rb +1 -1
  113. data/lib/puppet/provider/package/dpkg.rb +18 -34
  114. data/lib/puppet/provider/package/openbsd.rb +1 -1
  115. data/lib/puppet/provider/package/pip.rb +13 -37
  116. data/lib/puppet/provider/package/portage.rb +4 -4
  117. data/lib/puppet/provider/package/puppet_gem.rb +1 -1
  118. data/lib/puppet/provider/package/rpm.rb +18 -56
  119. data/lib/puppet/provider/package/windows/package.rb +1 -1
  120. data/lib/puppet/provider/package/yum.rb +5 -9
  121. data/lib/puppet/provider/package_targetable.rb +4 -7
  122. data/lib/puppet/provider/parsedfile.rb +1 -1
  123. data/lib/puppet/provider/service/daemontools.rb +9 -9
  124. data/lib/puppet/provider/service/launchd.rb +5 -20
  125. data/lib/puppet/provider/service/openbsd.rb +1 -1
  126. data/lib/puppet/provider/service/rcng.rb +2 -2
  127. data/lib/puppet/provider/service/runit.rb +8 -2
  128. data/lib/puppet/provider/service/systemd.rb +19 -14
  129. data/lib/puppet/provider/service/windows.rb +0 -8
  130. data/lib/puppet/provider/user/directoryservice.rb +1 -1
  131. data/lib/puppet/provider/user/hpux.rb +1 -1
  132. data/lib/puppet/provider/user/pw.rb +3 -12
  133. data/lib/puppet/provider/user/user_role_add.rb +1 -5
  134. data/lib/puppet/provider/user/useradd.rb +20 -45
  135. data/lib/puppet/provider/user/windows_adsi.rb +5 -4
  136. data/lib/puppet/reference/configuration.rb +3 -3
  137. data/lib/puppet/reference/indirection.rb +2 -2
  138. data/lib/puppet/reference/metaparameter.rb +3 -1
  139. data/lib/puppet/reference/providers.rb +3 -1
  140. data/lib/puppet/reference/type.rb +9 -3
  141. data/lib/puppet/reports.rb +1 -1
  142. data/lib/puppet/resource.rb +1 -18
  143. data/lib/puppet/resource/catalog.rb +1 -1
  144. data/lib/puppet/rest/routes.rb +30 -17
  145. data/lib/puppet/settings.rb +3 -43
  146. data/lib/puppet/settings/environment_conf.rb +0 -1
  147. data/lib/puppet/ssl/certificate_request.rb +12 -2
  148. data/lib/puppet/ssl/host.rb +2 -2
  149. data/lib/puppet/ssl/oids.rb +1 -1
  150. data/lib/puppet/ssl/ssl_provider.rb +11 -5
  151. data/lib/puppet/ssl/state_machine.rb +102 -98
  152. data/lib/puppet/test/test_helper.rb +1 -0
  153. data/lib/puppet/transaction.rb +11 -33
  154. data/lib/puppet/transaction/report.rb +1 -1
  155. data/lib/puppet/type.rb +4 -2
  156. data/lib/puppet/type/exec.rb +17 -23
  157. data/lib/puppet/type/file.rb +39 -11
  158. data/lib/puppet/type/file/data_sync.rb +1 -5
  159. data/lib/puppet/type/group.rb +2 -4
  160. data/lib/puppet/type/notify.rb +3 -4
  161. data/lib/puppet/type/package.rb +3 -20
  162. data/lib/puppet/type/schedule.rb +1 -1
  163. data/lib/puppet/type/service.rb +3 -8
  164. data/lib/puppet/type/user.rb +2 -4
  165. data/lib/puppet/util.rb +29 -39
  166. data/lib/puppet/util/command_line/trollop.rb +1 -1
  167. data/lib/puppet/util/execution.rb +3 -4
  168. data/lib/puppet/util/http_proxy.rb +19 -27
  169. data/lib/puppet/util/log.rb +2 -2
  170. data/lib/puppet/util/log/destinations.rb +2 -2
  171. data/lib/puppet/util/logging.rb +20 -32
  172. data/lib/puppet/util/metric.rb +2 -2
  173. data/lib/puppet/util/monkey_patches.rb +33 -0
  174. data/lib/puppet/util/pidlock.rb +2 -3
  175. data/lib/puppet/util/provider_features.rb +4 -2
  176. data/lib/puppet/util/rdoc.rb +1 -1
  177. data/lib/puppet/util/reference.rb +1 -1
  178. data/lib/puppet/util/resource_template.rb +1 -1
  179. data/lib/puppet/util/selinux.rb +2 -8
  180. data/lib/puppet/util/skip_tags.rb +4 -0
  181. data/lib/puppet/util/windows/adsi.rb +18 -48
  182. data/lib/puppet/util/windows/process.rb +8 -8
  183. data/lib/puppet/util/windows/registry.rb +5 -7
  184. data/lib/puppet/util/windows/security.rb +0 -2
  185. data/lib/puppet/util/windows/service.rb +4 -149
  186. data/lib/puppet/util/windows/sid.rb +0 -1
  187. data/lib/puppet/vendor.rb +1 -1
  188. data/lib/puppet/version.rb +1 -1
  189. data/lib/puppet/x509/cert_provider.rb +81 -24
  190. data/locales/puppet.pot +462 -482
  191. data/man/man5/puppet.conf.5 +43 -44
  192. data/man/man8/puppet-agent.8 +1 -1
  193. data/man/man8/puppet-apply.8 +3 -3
  194. data/man/man8/puppet-catalog.8 +31 -3
  195. data/man/man8/puppet-config.8 +1 -1
  196. data/man/man8/puppet-describe.8 +1 -1
  197. data/man/man8/puppet-device.8 +1 -1
  198. data/man/man8/puppet-doc.8 +1 -1
  199. data/man/man8/puppet-epp.8 +1 -1
  200. data/man/man8/puppet-facts.8 +1 -1
  201. data/man/man8/puppet-filebucket.8 +1 -1
  202. data/man/man8/puppet-generate.8 +1 -1
  203. data/man/man8/puppet-help.8 +1 -1
  204. data/man/man8/puppet-key.8 +1 -1
  205. data/man/man8/puppet-lookup.8 +1 -1
  206. data/man/man8/puppet-man.8 +1 -1
  207. data/man/man8/puppet-module.8 +1 -1
  208. data/man/man8/puppet-node.8 +1 -1
  209. data/man/man8/puppet-parser.8 +1 -1
  210. data/man/man8/puppet-plugin.8 +1 -1
  211. data/man/man8/puppet-report.8 +1 -1
  212. data/man/man8/puppet-resource.8 +1 -1
  213. data/man/man8/puppet-script.8 +1 -1
  214. data/man/man8/puppet-ssl.8 +1 -1
  215. data/man/man8/puppet-status.8 +1 -1
  216. data/man/man8/puppet.8 +3 -3
  217. data/spec/fixtures/ssl/127.0.0.1-key.pem +56 -56
  218. data/spec/fixtures/ssl/127.0.0.1.pem +27 -27
  219. data/spec/fixtures/ssl/bad-basic-constraints.pem +32 -32
  220. data/spec/fixtures/ssl/bad-int-basic-constraints.pem +30 -30
  221. data/spec/fixtures/ssl/ca.pem +30 -30
  222. data/spec/fixtures/ssl/crl.pem +15 -15
  223. data/spec/fixtures/ssl/ec-key.pem +18 -0
  224. data/spec/fixtures/ssl/ec.pem +40 -0
  225. data/spec/fixtures/ssl/encrypted-ec-key.pem +21 -0
  226. data/spec/fixtures/ssl/encrypted-key.pem +57 -57
  227. data/spec/fixtures/ssl/intermediate-agent-crl.pem +16 -16
  228. data/spec/fixtures/ssl/intermediate-agent.pem +33 -33
  229. data/spec/fixtures/ssl/intermediate-crl.pem +17 -17
  230. data/spec/fixtures/ssl/intermediate.pem +31 -31
  231. data/spec/fixtures/ssl/pluto-key.pem +56 -56
  232. data/spec/fixtures/ssl/pluto.pem +28 -28
  233. data/spec/fixtures/ssl/request-key.pem +56 -56
  234. data/spec/fixtures/ssl/request.pem +24 -24
  235. data/spec/fixtures/ssl/revoked-key.pem +56 -56
  236. data/spec/fixtures/ssl/revoked.pem +25 -25
  237. data/spec/fixtures/ssl/signed-key.pem +56 -56
  238. data/spec/fixtures/ssl/signed.pem +25 -25
  239. data/spec/fixtures/ssl/tampered-cert.pem +27 -27
  240. data/spec/fixtures/ssl/tampered-csr.pem +24 -24
  241. data/spec/fixtures/unit/pops/loaders/loaders/mix_4x_and_3x_functions/usee/lib/puppet/parser/functions/func_with_syntax_error.rb +9 -0
  242. data/spec/fixtures/vcr/cassettes/Puppet_Network_HTTP_Connection/when_handling_requests/_request_get/should_yield_to_the_block.yml +24 -0
  243. data/spec/fixtures/vcr/cassettes/Puppet_Network_HTTP_Connection/when_handling_requests/_request_head/should_yield_to_the_block.yml +24 -0
  244. data/spec/fixtures/vcr/cassettes/Puppet_Network_HTTP_Connection/when_handling_requests/_request_post/should_yield_to_the_block.yml +24 -0
  245. data/spec/integration/configurer_spec.rb +0 -52
  246. data/spec/integration/provider/service/init_spec.rb +1 -0
  247. data/spec/integration/provider/service/systemd_spec.rb +5 -8
  248. data/spec/integration/type/file_spec.rb +38 -28
  249. data/spec/integration/util/execution_spec.rb +0 -27
  250. data/spec/lib/puppet/certificate_factory.rb +2 -2
  251. data/spec/lib/puppet/test_ca.rb +17 -4
  252. data/spec/lib/puppet_spec/fixtures.rb +4 -0
  253. data/spec/spec_helper.rb +0 -28
  254. data/spec/unit/application/agent_spec.rb +34 -67
  255. data/spec/unit/application/device_spec.rb +1 -27
  256. data/spec/unit/application/ssl_spec.rb +60 -35
  257. data/spec/unit/configurer_spec.rb +399 -395
  258. data/spec/unit/defaults_spec.rb +4 -4
  259. data/spec/unit/face/facts_spec.rb +0 -9
  260. data/spec/unit/face/parser_spec.rb +69 -22
  261. data/spec/unit/face/plugin_spec.rb +0 -8
  262. data/spec/unit/file_system_spec.rb +30 -1
  263. data/spec/unit/forge/forge_spec.rb +3 -1
  264. data/spec/unit/forge/repository_spec.rb +3 -1
  265. data/spec/unit/indirector/catalog/compiler_spec.rb +5 -62
  266. data/spec/unit/indirector/resource/ral_spec.rb +4 -4
  267. data/spec/unit/module_tool/tar/mini_spec.rb +1 -1
  268. data/spec/unit/network/http/api/indirected_routes_spec.rb +10 -25
  269. data/spec/unit/network/http/connection_spec.rb +145 -119
  270. data/spec/unit/network/http/factory_spec.rb +5 -27
  271. data/spec/unit/parser/scope_spec.rb +0 -10
  272. data/spec/unit/pops/evaluator/evaluating_parser_spec.rb +3 -8
  273. data/spec/unit/pops/loaders/loaders_spec.rb +4 -0
  274. data/spec/unit/pops/loaders/module_loaders_spec.rb +0 -37
  275. data/spec/unit/pops/types/types_spec.rb +27 -0
  276. data/spec/unit/provider/exec_spec.rb +0 -209
  277. data/spec/unit/provider/package/aptrpm_spec.rb +1 -1
  278. data/spec/unit/provider/package/dnf_spec.rb +0 -7
  279. data/spec/unit/provider/package/dpkg_spec.rb +80 -240
  280. data/spec/unit/provider/package/pip_spec.rb +8 -61
  281. data/spec/unit/provider/package/portage_spec.rb +4 -4
  282. data/spec/unit/provider/package/rpm_spec.rb +16 -150
  283. data/spec/unit/provider/package/yum_spec.rb +0 -7
  284. data/spec/unit/provider/service/daemontools_spec.rb +0 -24
  285. data/spec/unit/provider/service/launchd_spec.rb +0 -28
  286. data/spec/unit/provider/service/runit_spec.rb +0 -24
  287. data/spec/unit/provider/service/systemd_spec.rb +25 -39
  288. data/spec/unit/provider/service/windows_spec.rb +0 -20
  289. data/spec/unit/provider/user/hpux_spec.rb +2 -2
  290. data/spec/unit/provider/user/pw_spec.rb +0 -37
  291. data/spec/unit/provider/user/useradd_spec.rb +0 -88
  292. data/spec/unit/resource_spec.rb +1 -26
  293. data/spec/unit/ssl/host_spec.rb +5 -0
  294. data/spec/unit/ssl/ssl_provider_spec.rb +36 -11
  295. data/spec/unit/ssl/state_machine_spec.rb +233 -158
  296. data/spec/unit/transaction_spec.rb +0 -64
  297. data/spec/unit/type/exec_spec.rb +12 -15
  298. data/spec/unit/type/file/content_spec.rb +3 -9
  299. data/spec/unit/type/file/source_spec.rb +4 -4
  300. data/spec/unit/type/file_spec.rb +15 -11
  301. data/spec/unit/type/package_spec.rb +0 -5
  302. data/spec/unit/type/schedule_spec.rb +1 -3
  303. data/spec/unit/type/service_spec.rb +0 -16
  304. data/spec/unit/util/execution_spec.rb +0 -16
  305. data/spec/unit/util/http_proxy_spec.rb +21 -151
  306. data/spec/unit/util/ldap/manager_spec.rb +0 -15
  307. data/spec/unit/util/log/destinations_spec.rb +3 -7
  308. data/spec/unit/util/log_spec.rb +138 -0
  309. data/spec/unit/util/logging_spec.rb +0 -200
  310. data/spec/unit/util/pidlock_spec.rb +0 -26
  311. data/spec/unit/util/skip_tags_spec.rb +14 -0
  312. data/spec/unit/util/windows/adsi_spec.rb +0 -51
  313. data/spec/unit/util/windows/service_spec.rb +0 -9
  314. data/spec/unit/util_spec.rb +10 -0
  315. data/spec/unit/x509/cert_provider_spec.rb +82 -43
  316. data/tasks/generate_cert_fixtures.rake +13 -1
  317. data/tasks/manpages.rake +0 -1
  318. metadata +28 -22
  319. data/ext/cert_inspector +0 -140
  320. data/ext/envpuppet +0 -139
  321. data/ext/envpuppet.bat +0 -14
  322. data/ext/puppet-test +0 -476
  323. data/ext/pure_ruby_dsl/dsl_test.rb +0 -7
  324. data/ext/upload_facts.rb +0 -119
  325. data/lib/puppet/provider/package/dnfmodule.rb +0 -87
  326. data/spec/fixtures/unit/provider/package/dnfmodule/dnf-module-list-installed.txt +0 -11
  327. data/spec/integration/type/notify_spec.rb +0 -46
  328. data/spec/unit/provider/package/dnfmodule_spec.rb +0 -186
  329. data/spec/unit/provider/package_targetable_spec.rb +0 -60
@@ -448,6 +448,10 @@ describe 'loaders' do
448
448
  function = loader.load_typed(typed_name(:function, 'good_func_load')).value
449
449
  expect(function.call(scope)).to eql(Float("3.14"))
450
450
  end
451
+
452
+ it "a function with syntax error has helpful error message" do
453
+ expect { loader.load_typed(typed_name(:function, 'func_with_syntax_error')) }.to raise_error(/syntax error, unexpected keyword_end/)
454
+ end
451
455
  end
452
456
 
453
457
  context 'when a 3x load has illegal method added' do
@@ -163,43 +163,6 @@ describe 'FileBased module loader' do
163
163
  expect(module_loader.load_typed(typed_name(:task, 'testmodule::baz'))).not_to be_nil
164
164
  expect { module_loader.load_typed(typed_name(:task, 'testmodule::qux')) }.to raise_error(/No source besides task metadata was found/)
165
165
  end
166
-
167
- it 'raises and error when `parameters` is not a hash' do
168
- metadata = { 'parameters' => 'foo' }
169
- module_dir = dir_containing('testmodule', 'tasks' => {'foo.py' => '', 'foo.json' => metadata.to_json})
170
-
171
- module_loader = Puppet::Pops::Loader::ModuleLoaders.module_loader_from(static_loader, loaders, 'testmodule', module_dir)
172
- expect{module_loader.load_typed(typed_name(:task, 'testmodule::foo'))}
173
- .to raise_error(Puppet::ParseError, /Failed to load metadata for task testmodule::foo: 'parameters' must be a hash/)
174
- end
175
-
176
- it 'raises and error when `implementations` `requirements` key is not an array' do
177
- metadata = { 'implementations' => { 'name' => 'foo.py', 'requirements' => 'foo'} }
178
- module_dir = dir_containing('testmodule', 'tasks' => {'foo.py' => '', 'foo.json' => metadata.to_json})
179
-
180
- module_loader = Puppet::Pops::Loader::ModuleLoaders.module_loader_from(static_loader, loaders, 'testmodule', module_dir)
181
- expect{module_loader.load_typed(typed_name(:task, 'testmodule::foo'))}
182
- .to raise_error(Puppet::Module::Task::InvalidMetadata,
183
- /Task metadata for task testmodule::foo does not specify implementations as an array/)
184
- end
185
-
186
- it 'raises and error when top-level `files` is not an array' do
187
- metadata = { 'files' => 'foo' }
188
- module_dir = dir_containing('testmodule', 'tasks' => {'foo.py' => '', 'foo.json' => metadata.to_json})
189
-
190
- module_loader = Puppet::Pops::Loader::ModuleLoaders.module_loader_from(static_loader, loaders, 'testmodule', module_dir)
191
- expect{module_loader.load_typed(typed_name(:task, 'testmodule::foo'))}
192
- .to raise_error(Puppet::Module::Task::InvalidMetadata, /The 'files' task metadata expects an array, got foo/)
193
- end
194
-
195
- it 'raises and error when `files` nested in `interpreters` is not an array' do
196
- metadata = { 'implementations' => [{'name' => 'foo.py', 'files' => 'foo'}] }
197
- module_dir = dir_containing('testmodule', 'tasks' => {'foo.py' => '', 'foo.json' => metadata.to_json})
198
-
199
- module_loader = Puppet::Pops::Loader::ModuleLoaders.module_loader_from(static_loader, loaders, 'testmodule', module_dir)
200
- expect{module_loader.load_typed(typed_name(:task, 'testmodule::foo'))}
201
- .to raise_error(Puppet::Module::Task::InvalidMetadata, /The 'files' task metadata expects an array, got foo/)
202
- end
203
166
  end
204
167
 
205
168
  def typed_name(type, name)
@@ -219,6 +219,33 @@ describe 'Puppet Type System' do
219
219
  end
220
220
  end
221
221
 
222
+ context 'Regexp type' do
223
+ it 'parameterized type is assignable to base type' do
224
+ code = <<-CODE
225
+ notice(Regexp[a] < Regexp)
226
+ CODE
227
+ expect(eval_and_collect_notices(code)).to eq(['true'])
228
+ end
229
+
230
+ it 'new function creates a new regexp' do
231
+ code = <<-CODE
232
+ $r = Regexp('abc')
233
+ notice('abc' =~ $r)
234
+ notice(type($r) =~ Type[Regexp])
235
+ CODE
236
+ expect(eval_and_collect_notices(code)).to eq(['true', 'true'])
237
+ end
238
+
239
+ it 'special characters are escaped with second parameter to Regexp.new set to true' do
240
+ code = <<-CODE
241
+ $r = Regexp('.[]', true)
242
+ notice('.[]' =~ $r)
243
+ notice(String($r) == "\\.\\[\\]")
244
+ CODE
245
+ expect(eval_and_collect_notices(code)).to eq(['true', 'true'])
246
+ end
247
+ end
248
+
222
249
  context 'Iterable type' do
223
250
  it 'can be parameterized with element type' do
224
251
  code = <<-CODE
@@ -1,12 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'puppet/provider/exec'
3
- require 'puppet_spec/compiler'
4
- require 'puppet_spec/files'
5
3
 
6
4
  describe Puppet::Provider::Exec do
7
- include PuppetSpec::Compiler
8
- include PuppetSpec::Files
9
-
10
5
  describe "#extractexe" do
11
6
  it "should return the first element of an array" do
12
7
  expect(subject.extractexe(['one', 'two'])).to eq('one')
@@ -36,208 +31,4 @@ describe Puppet::Provider::Exec do
36
31
  end
37
32
  end
38
33
  end
39
-
40
- context "when handling sensitive data" do
41
- before :each do
42
- Puppet[:log_level] = 'debug'
43
- end
44
-
45
- let(:supersecret) { 'supersecret' }
46
- let(:path) do
47
- if Puppet::Util::Platform.windows?
48
- # The `apply_compiled_manifest` helper doesn't add the `path` fact, so
49
- # we can't reference that in our manifest. Windows PATHs can contain
50
- # double quotes and trailing backslashes, which confuse HEREDOC
51
- # interpolation below. So sanitize it:
52
- ENV['PATH'].split(File::PATH_SEPARATOR).map do |dir|
53
- dir.gsub(/"/, '\"').gsub(/\\$/, '')
54
- end.join(File::PATH_SEPARATOR)
55
- else
56
- ENV['PATH']
57
- end
58
- end
59
-
60
- def ruby_exit_0
61
- "ruby -e 'exit 0'"
62
- end
63
-
64
- def echo_from_ruby_exit_0(message)
65
- # Escape double quotes due to HEREDOC interpolation below
66
- "ruby -e 'puts \"#{message}\"; exit 0'".gsub(/"/, '\"')
67
- end
68
-
69
- def echo_from_ruby_exit_1(message)
70
- # Escape double quotes due to HEREDOC interpolation below
71
- "ruby -e 'puts \"#{message}\"; exit 1'".gsub(/"/, '\"')
72
- end
73
-
74
- context "when validating the command" do
75
- it "redacts the arguments if the command is relative" do
76
- expect {
77
- apply_compiled_manifest(<<-MANIFEST)
78
- exec { 'echo':
79
- command => Sensitive.new('echo #{supersecret}')
80
- }
81
- MANIFEST
82
- }.to raise_error do |err|
83
- expect(err).to be_a(Puppet::Error)
84
- expect(err.message).to match(/'echo' is not qualified and no path was specified. Please qualify the command or specify a path./)
85
- expect(err.message).to_not match(/#{supersecret}/)
86
- end
87
- end
88
-
89
- it "redacts the arguments if the command is a directory" do
90
- dir = tmpdir('exec')
91
- apply_compiled_manifest(<<-MANIFEST)
92
- exec { 'echo':
93
- command => Sensitive.new('#{dir} #{supersecret}'),
94
- }
95
- MANIFEST
96
- expect(@logs).to include(an_object_having_attributes(level: :err, message: /'#{dir}' is a directory, not a file/))
97
- expect(@logs).to_not include(an_object_having_attributes(message: /#{supersecret}/))
98
- end
99
-
100
- it "redacts the arguments if the command isn't executable" do
101
- file = tmpfile('exec')
102
- Puppet::FileSystem.touch(file)
103
- Puppet::FileSystem.chmod(0644, file)
104
-
105
- apply_compiled_manifest(<<-MANIFEST)
106
- exec { 'echo':
107
- command => Sensitive.new('#{file} #{supersecret}'),
108
- }
109
- MANIFEST
110
- # Execute permission works differently on Windows, but execute will fail since the
111
- # file doesn't have a valid extension and isn't a valid executable. The raised error
112
- # will be Errno::EIO, which is not useful. The Windows execute code needs to raise
113
- # Puppet::Util::Windows::Error so the Win32 error message is preserved.
114
- pending("PUP-3561 Needs to raise a meaningful Puppet::Error") if Puppet::Util::Platform.windows?
115
- expect(@logs).to include(an_object_having_attributes(level: :err, message: /'#{file}' is not executable/))
116
- expect(@logs).to_not include(an_object_having_attributes(message: /#{supersecret}/))
117
- end
118
-
119
- it "redacts the arguments if the relative command cannot be resolved using the path parameter" do
120
- file = File.basename(tmpfile('exec'))
121
- dir = tmpdir('exec')
122
-
123
- apply_compiled_manifest(<<-MANIFEST)
124
- exec { 'echo':
125
- command => Sensitive.new('#{file} #{supersecret}'),
126
- path => "#{dir}",
127
- }
128
- MANIFEST
129
- expect(@logs).to include(an_object_having_attributes(level: :err, message: /Could not find command '#{file}'/))
130
- expect(@logs).to_not include(an_object_having_attributes(message: /#{supersecret}/))
131
- end
132
- end
133
-
134
- it "redacts the command on success", unless: Puppet::Util::Platform.jruby? do
135
- command = echo_from_ruby_exit_0(supersecret)
136
-
137
- apply_compiled_manifest(<<-MANIFEST)
138
- exec { 'true':
139
- command => Sensitive.new("#{command}"),
140
- path => "#{path}",
141
- }
142
- MANIFEST
143
- expect(@logs).to include(an_object_having_attributes(level: :debug, message: "Executing '[redacted]'", source: /Exec\[true\]/))
144
- expect(@logs).to include(an_object_having_attributes(level: :debug, message: "Executing: '[redacted]'", source: "Puppet"))
145
- expect(@logs).to include(an_object_having_attributes(level: :notice, message: "executed successfully"))
146
- expect(@logs).to_not include(an_object_having_attributes(message: /#{supersecret}/))
147
- end
148
-
149
- it "redacts the command on failure", unless: Puppet::Util::Platform.jruby? do
150
- command = echo_from_ruby_exit_1(supersecret)
151
-
152
- apply_compiled_manifest(<<-MANIFEST)
153
- exec { 'false':
154
- command => Sensitive.new("#{command}"),
155
- path => "#{path}",
156
- }
157
- MANIFEST
158
- expect(@logs).to include(an_object_having_attributes(level: :debug, message: "Executing '[redacted]'", source: /Exec\[false\]/))
159
- expect(@logs).to include(an_object_having_attributes(level: :debug, message: "Executing: '[redacted]'", source: "Puppet"))
160
- expect(@logs).to include(an_object_having_attributes(level: :err, message: "[command redacted] returned 1 instead of one of [0]"))
161
- expect(@logs).to_not include(an_object_having_attributes(message: /#{supersecret}/))
162
- end
163
-
164
- context "when handling checks", unless: Puppet::Util::Platform.jruby? do
165
- let(:onlyifsecret) { "onlyifsecret" }
166
- let(:unlesssecret) { "unlesssecret" }
167
-
168
- it "redacts command and onlyif outputs" do
169
- onlyif = echo_from_ruby_exit_0(onlyifsecret)
170
-
171
- apply_compiled_manifest(<<-MANIFEST)
172
- exec { 'true':
173
- command => Sensitive.new("#{ruby_exit_0}"),
174
- onlyif => Sensitive.new("#{onlyif}"),
175
- path => "#{path}",
176
- }
177
- MANIFEST
178
- expect(@logs).to include(an_object_having_attributes(level: :debug, message: "Executing check '[redacted]'"))
179
- expect(@logs).to include(an_object_having_attributes(level: :debug, message: "Executing '[redacted]'", source: /Exec\[true\]/))
180
- expect(@logs).to include(an_object_having_attributes(level: :debug, message: "Executing: '[redacted]'", source: "Puppet"))
181
- expect(@logs).to include(an_object_having_attributes(level: :debug, message: "[output redacted]"))
182
- expect(@logs).to include(an_object_having_attributes(level: :notice, message: "executed successfully"))
183
- expect(@logs).to_not include(an_object_having_attributes(message: /#{onlyifsecret}/))
184
- end
185
-
186
- it "redacts the command that would have been executed but didn't due to onlyif" do
187
- command = echo_from_ruby_exit_0(supersecret)
188
- onlyif = echo_from_ruby_exit_1(onlyifsecret)
189
-
190
- apply_compiled_manifest(<<-MANIFEST)
191
- exec { 'true':
192
- command => Sensitive.new("#{command}"),
193
- onlyif => Sensitive.new("#{onlyif}"),
194
- path => "#{path}",
195
- }
196
- MANIFEST
197
- expect(@logs).to include(an_object_having_attributes(level: :debug, message: "Executing check '[redacted]'"))
198
- expect(@logs).to include(an_object_having_attributes(level: :debug, message: "Executing: '[redacted]'", source: "Puppet"))
199
- expect(@logs).to include(an_object_having_attributes(level: :debug, message: "[output redacted]"))
200
- expect(@logs).to include(an_object_having_attributes(level: :debug, message: "'[command redacted]' won't be executed because of failed check 'onlyif'"))
201
- expect(@logs).to_not include(an_object_having_attributes(message: /#{supersecret}/))
202
- expect(@logs).to_not include(an_object_having_attributes(message: /#{onlyifsecret}/))
203
- end
204
-
205
- it "redacts command and unless outputs" do
206
- unlesscmd = echo_from_ruby_exit_1(unlesssecret)
207
-
208
- apply_compiled_manifest(<<-MANIFEST)
209
- exec { 'true':
210
- command => Sensitive.new("#{ruby_exit_0}"),
211
- unless => Sensitive.new("#{unlesscmd}"),
212
- path => "#{path}",
213
- }
214
- MANIFEST
215
- expect(@logs).to include(an_object_having_attributes(level: :debug, message: "Executing check '[redacted]'"))
216
- expect(@logs).to include(an_object_having_attributes(level: :debug, message: "Executing '[redacted]'", source: /Exec\[true\]/))
217
- expect(@logs).to include(an_object_having_attributes(level: :debug, message: "Executing: '[redacted]'", source: "Puppet"))
218
- expect(@logs).to include(an_object_having_attributes(level: :debug, message: "[output redacted]"))
219
- expect(@logs).to include(an_object_having_attributes(level: :notice, message: "executed successfully"))
220
- expect(@logs).to_not include(an_object_having_attributes(message: /#{unlesssecret}/))
221
- end
222
-
223
- it "redacts the command that would have been executed but didn't due to unless" do
224
- command = echo_from_ruby_exit_0(supersecret)
225
- unlesscmd = echo_from_ruby_exit_0(unlesssecret)
226
-
227
- apply_compiled_manifest(<<-MANIFEST)
228
- exec { 'true':
229
- command => Sensitive.new("#{command}"),
230
- unless => Sensitive.new("#{unlesscmd}"),
231
- path => "#{path}",
232
- }
233
- MANIFEST
234
- expect(@logs).to include(an_object_having_attributes(level: :debug, message: "Executing check '[redacted]'"))
235
- expect(@logs).to include(an_object_having_attributes(level: :debug, message: "Executing: '[redacted]'", source: "Puppet"))
236
- expect(@logs).to include(an_object_having_attributes(level: :debug, message: "[output redacted]"))
237
- expect(@logs).to include(an_object_having_attributes(level: :debug, message: "'[command redacted]' won't be executed because of failed check 'unless'"))
238
- expect(@logs).to_not include(an_object_having_attributes(message: /#{supersecret}/))
239
- expect(@logs).to_not include(an_object_having_attributes(message: /#{unlesssecret}/))
240
- end
241
- end
242
- end
243
34
  end
@@ -16,7 +16,7 @@ describe Puppet::Type.type(:package).provider(:aptrpm) do
16
16
  end
17
17
 
18
18
  def rpm_args
19
- ['-q', 'faff', '--nosignature', '--nodigest', '--qf', "%{NAME} %|EPOCH?{%{EPOCH}}:{0}| %{VERSION} %{RELEASE} %{ARCH}\\n"]
19
+ ['-q', 'faff', '--nosignature', '--nodigest', '--qf', "'%{NAME} %|EPOCH?{%{EPOCH}}:{0}| %{VERSION} %{RELEASE} %{ARCH}\\n'"]
20
20
  end
21
21
 
22
22
  it "should report purged packages" do
@@ -44,12 +44,5 @@ describe Puppet::Type.type(:package).provider(:dnf) do
44
44
  end
45
45
  end
46
46
 
47
- describe 'provider features' do
48
- it { is_expected.to be_versionable }
49
- it { is_expected.to be_install_options }
50
- it { is_expected.to be_virtual_packages }
51
- it { is_expected.to be_install_only }
52
- end
53
-
54
47
  it_behaves_like 'RHEL package provider', described_class, 'dnf'
55
48
  end
@@ -1,20 +1,18 @@
1
1
  require 'spec_helper'
2
2
  require 'stringio'
3
3
 
4
- describe Puppet::Type.type(:package).provider(:dpkg), unless: Puppet::Util::Platform.jruby? do
4
+ describe Puppet::Type.type(:package).provider(:dpkg) do
5
5
  let(:bash_version) { '4.2-5ubuntu3' }
6
6
  let(:bash_installed_output) { "install ok installed bash #{bash_version}\n" }
7
7
  let(:bash_installed_io) { StringIO.new(bash_installed_output) }
8
8
  let(:vim_installed_output) { "install ok installed vim 2:7.3.547-6ubuntu5\n" }
9
9
  let(:all_installed_io) { StringIO.new([bash_installed_output, vim_installed_output].join) }
10
10
  let(:args) { ['-W', '--showformat', %Q{'${Status} ${Package} ${Version}\\n'}] }
11
- let(:args_with_provides) { ['/bin/dpkg-query','-W', '--showformat', %Q{'${Status} ${Package} ${Version} [${Provides}]\\n'}]}
12
11
  let(:execute_options) do
13
12
  {:failonfail => true, :combine => true, :custom_environment => {}}
14
13
  end
15
- let(:resource_name) { 'python' }
14
+ let(:resource_name) { 'package' }
16
15
  let(:resource) { double('resource', :[] => resource_name) }
17
- let(:dpkg_query_result) { 'install ok installed python 2.7.13' }
18
16
  let(:provider) { described_class.new(resource) }
19
17
 
20
18
  it "has documentation" do
@@ -70,247 +68,105 @@ describe Puppet::Type.type(:package).provider(:dpkg), unless: Puppet::Util::Plat
70
68
  expect(Puppet::Util::Execution).to receive(:execute).with(query_args, execute_options).and_return(Puppet::Util::Execution::ProcessOutput.new(output, 0))
71
69
  end
72
70
 
73
- def dpkg_query_execution_with_multiple_args_returns(output, *args)
74
- args.each do |arg|
75
- allow(Puppet::Util::Execution).to receive(:execute).with(arg, execute_options).and_return(Puppet::Util::Execution::ProcessOutput.new(output, 0))
76
- end
77
- end
78
-
79
71
  before do
80
72
  allow(Puppet::Util).to receive(:which).with('/usr/bin/dpkg-query').and_return(dpkgquery_path)
81
73
  end
82
74
 
83
75
  it "considers the package purged if dpkg-query fails" do
84
- allow(resource).to receive(:allow_virtual?).and_return(false)
85
76
  allow(Puppet::Util::Execution).to receive(:execute).with(query_args, execute_options).and_raise(Puppet::ExecutionFailure.new("eh"))
86
77
 
87
78
  expect(provider.query[:ensure]).to eq(:purged)
88
79
  end
89
80
 
90
- context "allow_virtual true" do
91
- before do
92
- allow(resource).to receive(:allow_virtual?).and_return(true)
93
- end
81
+ it "returns a hash of the found package status for an installed package" do
82
+ dpkg_query_execution_returns(bash_installed_output)
94
83
 
95
- context "virtual_packages" do
96
- let(:query_output) { 'install ok installed python 2.7.13 [python-ctypes, python-email, python-importlib, python-profiler, python-wsgiref, python-gold]' }
97
- let(:virtual_packages_query_args) do
98
- result = args_with_provides.dup
99
- result.push(resource_name)
100
- end
101
-
102
- it "considers the package purged if dpkg-query fails" do
103
- allow(Puppet::Util::Execution).to receive(:execute).with(args_with_provides, execute_options).and_raise(Puppet::ExecutionFailure.new("eh"))
104
- expect(provider.query[:ensure]).to eq(:purged)
105
- end
106
-
107
- it "returns a hash of the found package status for an installed package" do
108
- dpkg_query_execution_with_multiple_args_returns(query_output, args_with_provides,virtual_packages_query_args)
109
- dpkg_query_execution_with_multiple_args_returns(dpkg_query_result, args, query_args)
110
- expect(provider.query).to eq(:ensure => "2.7.13", :error => "ok", :desired => "install", :name => "python", :status => "installed", :provider => :dpkg)
111
- end
112
-
113
- it "considers the package absent if the dpkg-query result cannot be interpreted" do
114
- dpkg_query_execution_with_multiple_args_returns('some-bad-data',args_with_provides,virtual_packages_query_args)
115
- dpkg_query_execution_with_multiple_args_returns('some-bad-data', args, query_args)
116
- expect(provider.query[:ensure]).to eq(:absent)
117
- end
118
-
119
- it "fails if an error is discovered" do
120
- dpkg_query_execution_with_multiple_args_returns(query_output.gsub("ok","error"),args_with_provides,virtual_packages_query_args)
121
- dpkg_query_execution_with_multiple_args_returns(dpkg_query_result.gsub("ok","error"), args, query_args)
122
- expect { provider.query }.to raise_error(Puppet::Error, /Package python, version 2.7.13 is in error state: error/)
123
- end
124
-
125
- it "considers the package purged if it is marked 'not-installed" do
126
- not_installed_query = query_output.gsub("installed", "not-installed").delete!('2.7.13')
127
- dpkg_query_execution_with_multiple_args_returns(not_installed_query, args_with_provides,virtual_packages_query_args)
128
- dpkg_query_execution_with_multiple_args_returns(dpkg_query_result.gsub("installed", "not-installed").delete!('2.7.13'), args, query_args)
129
- expect(provider.query[:ensure]).to eq(:purged)
130
- end
131
-
132
- it "considers the package absent if it is marked 'config-files'" do
133
- dpkg_query_execution_with_multiple_args_returns(query_output.gsub("installed","config-files"),args_with_provides,virtual_packages_query_args)
134
- dpkg_query_execution_with_multiple_args_returns(dpkg_query_result.gsub("installed","config-files"), args, query_args)
135
- expect(provider.query[:ensure]).to eq(:absent)
136
- end
137
-
138
- it "considers the package absent if it is marked 'half-installed'" do
139
- dpkg_query_execution_with_multiple_args_returns(query_output.gsub("installed","half-installed"),args_with_provides,virtual_packages_query_args)
140
- dpkg_query_execution_with_multiple_args_returns(dpkg_query_result.gsub("installed","half-installed"), args, query_args)
141
- expect(provider.query[:ensure]).to eq(:absent)
142
- end
143
-
144
- it "considers the package absent if it is marked 'unpacked'" do
145
- dpkg_query_execution_with_multiple_args_returns(query_output.gsub("installed","unpacked"),args_with_provides,virtual_packages_query_args)
146
- dpkg_query_execution_with_multiple_args_returns(dpkg_query_result.gsub("installed","unpacked"), args, query_args)
147
- expect(provider.query[:ensure]).to eq(:absent)
148
- end
149
-
150
- it "considers the package absent if it is marked 'half-configured'" do
151
- dpkg_query_execution_with_multiple_args_returns(query_output.gsub("installed","half-configured"),args_with_provides,virtual_packages_query_args)
152
- dpkg_query_execution_with_multiple_args_returns(dpkg_query_result.gsub("installed","half-configured"), args, query_args)
153
- expect(provider.query[:ensure]).to eq(:absent)
154
- end
155
-
156
- it "considers the package held if its state is 'hold'" do
157
- dpkg_query_execution_with_multiple_args_returns(query_output.gsub("install","hold"),args_with_provides,virtual_packages_query_args)
158
- dpkg_query_execution_with_multiple_args_returns(dpkg_query_result.gsub("install","hold"), args, query_args)
159
- expect(provider.query[:ensure]).to eq(:held)
160
- end
161
-
162
- context "regex check for query search" do
163
- let(:resource_name) { 'python-email' }
164
- let(:resource) { instance_double('Puppet::Type::Package') }
165
- before do
166
- allow(resource).to receive(:[]).with(:name).and_return(resource_name)
167
- allow(resource).to receive(:[]=)
168
- end
169
-
170
- it "checks if virtual package regex for query is correctand phisical package is installed" do
171
- dpkg_query_execution_with_multiple_args_returns(query_output,args_with_provides,virtual_packages_query_args)
172
- dpkg_query_execution_with_multiple_args_returns(dpkg_query_result, args, query_args)
173
- expect(provider.query).to match({:desired=>"install", :ensure=>"2.7.13", :error=>"ok", :name=>"python", :provider=>:dpkg, :status=>"installed"})
174
- end
175
-
176
- context "regex check with no partial matching" do
177
- let(:resource_name) { 'python-em' }
178
-
179
- it "checks if virtual package regex for query is correct and regext dosen't make partial matching" do
180
- expect(provider).to receive(:dpkgquery).with('-W', '--showformat', %Q{'${Status} ${Package} ${Version} [${Provides}]\\n'}).and_return(query_output)
181
- expect(provider).to receive(:dpkgquery).with('-W', '--showformat', %Q{'${Status} ${Package} ${Version}\\n'}, resource_name).and_return("#{dpkg_query_result} #{resource_name}")
182
-
183
- provider.query
184
- end
185
-
186
- context "regex check with special characters" do
187
- let(:resource_name) { 'g++' }
188
-
189
- it "checks if virtual package regex for query is correct and regext dosen't make partial matching" do
190
- expect(Puppet).to_not receive(:info).with(/is virtual/)
191
- expect(provider).to receive(:dpkgquery).with('-W', '--showformat', %Q{'${Status} ${Package} ${Version} [${Provides}]\\n'}).and_return(query_output)
192
- expect(provider).to receive(:dpkgquery).with('-W', '--showformat', %Q{'${Status} ${Package} ${Version}\\n'}, resource_name).and_return("#{dpkg_query_result} #{resource_name}")
193
-
194
- provider.query
195
- end
196
- end
197
- end
198
- end
199
- end
84
+ expect(provider.query).to eq({:ensure => "4.2-5ubuntu3", :error => "ok", :desired => "install", :name => "bash", :status => "installed", :provider => :dpkg})
200
85
  end
201
86
 
202
- context "allow_virtual false" do
203
- before do
204
- allow(resource).to receive(:allow_virtual?).and_return(false)
205
- end
87
+ it "considers the package absent if the dpkg-query result cannot be interpreted" do
88
+ dpkg_query_execution_returns('some-bad-data')
206
89
 
207
- it "returns a hash of the found package status for an installed package" do
208
- dpkg_query_execution_returns(bash_installed_output)
90
+ expect(provider.query[:ensure]).to eq(:absent)
91
+ end
209
92
 
210
- expect(provider.query).to eq({:ensure => "4.2-5ubuntu3", :error => "ok", :desired => "install", :name => "bash", :status => "installed", :provider => :dpkg})
211
- end
93
+ it "fails if an error is discovered" do
94
+ dpkg_query_execution_returns(bash_installed_output.gsub("ok","error"))
212
95
 
213
- it "considers the package absent if the dpkg-query result cannot be interpreted" do
214
- allow(resource).to receive(:allow_virtual?).and_return(false)
215
- dpkg_query_execution_returns('some-bad-data')
216
- expect(provider.query[:ensure]).to eq(:absent)
217
- end
96
+ expect { provider.query }.to raise_error(Puppet::Error)
97
+ end
218
98
 
219
- it "fails if an error is discovered" do
220
- dpkg_query_execution_returns(bash_installed_output.gsub("ok","error"))
221
- expect { provider.query }.to raise_error(Puppet::Error)
222
- end
99
+ it "considers the package purged if it is marked 'not-installed'" do
100
+ not_installed_bash = bash_installed_output.gsub("installed", "not-installed")
101
+ not_installed_bash.gsub!(bash_version, "")
102
+ dpkg_query_execution_returns(not_installed_bash)
223
103
 
224
- it "considers the package purged if it is marked 'not-installed'" do
225
- not_installed_bash = bash_installed_output.gsub("installed", "not-installed")
226
- not_installed_bash.gsub!(bash_version, "")
227
- dpkg_query_execution_returns(not_installed_bash)
104
+ expect(provider.query[:ensure]).to eq(:purged)
105
+ end
228
106
 
229
- expect(provider.query[:ensure]).to eq(:purged)
230
- end
107
+ it "considers the package absent if it is marked 'config-files'" do
108
+ dpkg_query_execution_returns(bash_installed_output.gsub("installed","config-files"))
109
+ expect(provider.query[:ensure]).to eq(:absent)
110
+ end
231
111
 
232
- it "considers the package absent if it is marked 'config-files'" do
233
- dpkg_query_execution_returns(bash_installed_output.gsub("installed","config-files"))
234
- expect(provider.query[:ensure]).to eq(:absent)
235
- end
112
+ it "considers the package absent if it is marked 'half-installed'" do
113
+ dpkg_query_execution_returns(bash_installed_output.gsub("installed","half-installed"))
114
+ expect(provider.query[:ensure]).to eq(:absent)
115
+ end
236
116
 
237
- it "considers the package absent if it is marked 'half-installed'" do
238
- dpkg_query_execution_returns(bash_installed_output.gsub("installed","half-installed"))
239
- expect(provider.query[:ensure]).to eq(:absent)
117
+ it "considers the package absent if it is marked 'unpacked'" do
118
+ dpkg_query_execution_returns(bash_installed_output.gsub("installed","unpacked"))
119
+ expect(provider.query[:ensure]).to eq(:absent)
120
+ end
121
+
122
+ it "considers the package absent if it is marked 'half-configured'" do
123
+ dpkg_query_execution_returns(bash_installed_output.gsub("installed","half-configured"))
124
+ expect(provider.query[:ensure]).to eq(:absent)
125
+ end
126
+
127
+ it "considers the package held if its state is 'hold'" do
128
+ dpkg_query_execution_returns(bash_installed_output.gsub("install","hold"))
129
+ expect(provider.query[:ensure]).to eq(:held)
130
+ end
131
+
132
+ context "parsing tests" do
133
+ let(:resource_name) { 'name' }
134
+ let(:package_hash) do
135
+ {
136
+ :desired => 'desired',
137
+ :error => 'ok',
138
+ :status => 'status',
139
+ :name => resource_name,
140
+ :ensure => 'ensure',
141
+ :provider => :dpkg,
142
+ }
240
143
  end
144
+ let(:package_not_found_hash) do
145
+ {:ensure => :purged, :status => 'missing', :name => resource_name, :error => 'ok'}
146
+ end
147
+
148
+ def parser_test(dpkg_output_string, gold_hash, number_of_debug_logs = 0)
149
+ dpkg_query_execution_returns(dpkg_output_string)
150
+ expect(Puppet).not_to receive(:warning)
151
+ expect(Puppet).to receive(:debug).exactly(number_of_debug_logs).times
241
152
 
242
- it "considers the package absent if it is marked 'unpacked'" do
243
- dpkg_query_execution_returns(bash_installed_output.gsub("installed","unpacked"))
244
- expect(provider.query[:ensure]).to eq(:absent)
153
+ expect(provider.query).to eq(gold_hash)
245
154
  end
246
155
 
247
- it "considers the package absent if it is marked 'half-configured'" do
248
- dpkg_query_execution_returns(bash_installed_output.gsub("installed","half-configured"))
249
- expect(provider.query[:ensure]).to eq(:absent)
156
+ it "parses properly even if optional ensure field is missing" do
157
+ no_ensure = 'desired ok status name '
158
+ parser_test(no_ensure, package_hash.merge(:ensure => ''))
250
159
  end
251
160
 
252
- it "considers the package held if its state is 'hold'" do
253
- dpkg_query_execution_returns(bash_installed_output.gsub("install","hold"))
254
- expect(provider.query[:ensure]).to eq(:held)
161
+ it "provides debug logging of unparsable lines" do
162
+ parser_test('an unexpected dpkg msg with an exit code of 0', package_not_found_hash.merge(:ensure => :absent), 1)
255
163
  end
256
164
 
257
- context "parsing tests" do
258
- let(:resource_name) { 'name' }
259
- let(:package_hash) do
260
- {
261
- :desired => 'desired',
262
- :error => 'ok',
263
- :status => 'status',
264
- :name => resource_name,
265
- :ensure => 'ensure',
266
- :provider => :dpkg,
267
- }
268
- end
269
-
270
- let(:package_not_found_hash) do
271
- {:ensure => :purged, :status => 'missing', :name => resource_name, :error => 'ok'}
272
- end
273
-
274
- let(:output) {'an unexpected dpkg msg with an exit code of 0'}
275
-
276
- def parser_test(dpkg_output_string, gold_hash, number_of_debug_logs = 0)
277
- dpkg_query_execution_returns(dpkg_output_string)
278
- expect(Puppet).not_to receive(:warning)
279
- expect(Puppet).to receive(:debug).exactly(number_of_debug_logs).times
280
-
281
- expect(provider.query).to eq(gold_hash)
282
- end
283
-
284
- it "parses properly even if optional ensure field is missing" do
285
- no_ensure = 'desired ok status name '
286
- parser_test(no_ensure, package_hash.merge(:ensure => ''))
287
- end
288
-
289
- it "provides debug logging of unparsable lines with allow_virtual enabled" do
290
- allow(resource).to receive(:allow_virtual?).and_return(true)
291
- dpkg_query_execution_with_multiple_args_returns(output, args_with_provides, query_args)
292
- expect(Puppet).not_to receive(:warning)
293
- expect(Puppet).to receive(:debug).exactly(1).times
294
- expect(provider.query).to eq(package_not_found_hash.merge(:ensure => :absent))
295
- end
296
-
297
- it "provides debug logging of unparsable lines" do
298
- parser_test('an unexpected dpkg msg with an exit code of 0', package_not_found_hash.merge(:ensure => :absent), 1)
299
- end
300
-
301
- it "does not log if execution returns with non-zero exit code with allow_virtual enabled" do
302
- allow(resource).to receive(:allow_virtual?).and_return(true)
303
- expect(Puppet::Util::Execution).to receive(:execute).with(args_with_provides, execute_options).and_raise(Puppet::ExecutionFailure.new("failed"))
304
- expect(Puppet).not_to receive(:debug)
305
- expect(provider.query).to eq(package_not_found_hash)
306
- end
307
-
308
- it "does not log if execution returns with non-zero exit code" do
309
- expect(Puppet::Util::Execution).to receive(:execute).with(query_args, execute_options).and_raise(Puppet::ExecutionFailure.new("failed"))
310
- expect(Puppet).not_to receive(:debug)
311
-
312
- expect(provider.query).to eq(package_not_found_hash)
313
- end
165
+ it "does not log if execution returns with non-zero exit code" do
166
+ expect(Puppet::Util::Execution).to receive(:execute).with(query_args, execute_options).and_raise(Puppet::ExecutionFailure.new("failed"))
167
+ expect(Puppet).not_to receive(:debug)
168
+
169
+ expect(provider.query).to eq(package_not_found_hash)
314
170
  end
315
171
  end
316
172
  end
@@ -362,10 +218,11 @@ describe Puppet::Type.type(:package).provider(:dpkg), unless: Puppet::Util::Plat
362
218
 
363
219
  before do
364
220
  allow(tempfile).to receive(:write)
365
- allow(Tempfile).to receive(:new).and_return(tempfile)
221
+ allow(Tempfile).to receive(:open).and_yield(tempfile)
366
222
  end
367
223
 
368
224
  it "installs first if package is not present and ensure holding" do
225
+
369
226
  allow(provider).to receive(:execute)
370
227
  allow(provider).to receive(:package_not_installed?).and_return(true)
371
228
  expect(provider).to receive(:install).once
@@ -401,8 +258,8 @@ describe Puppet::Type.type(:package).provider(:dpkg), unless: Puppet::Util::Plat
401
258
 
402
259
  context "when determining latest available version" do
403
260
  it "returns the version found by dpkg-deb" do
404
- expect(resource).to receive(:[]).with(:source).and_return("python")
405
- expect(provider).to receive(:dpkg_deb).with('--show', "python").and_return("package\t1.0")
261
+ expect(resource).to receive(:[]).with(:source).and_return("myfile")
262
+ expect(provider).to receive(:dpkg_deb).with(any_args, "myfile").and_return("package\t1.0")
406
263
  expect(provider.latest).to eq("1.0")
407
264
  end
408
265
 
@@ -430,26 +287,9 @@ describe Puppet::Type.type(:package).provider(:dpkg), unless: Puppet::Util::Plat
430
287
  provider.purge
431
288
  end
432
289
 
433
- context "package_not_installed?" do
434
- context "allow_virtual false" do
435
- before do
436
- allow(resource).to receive(:allow_virtual?).and_return(false)
437
- end
438
-
439
- it "returns true if package is not found" do
440
- expect(provider).to receive(:dpkgquery).with("-W", "--showformat", "'${Status} ${Package} ${Version}\\n'", resource_name).and_raise(Puppet::ExecutionFailure.new("eh"))
441
- expect(provider.package_not_installed?).to eq(true)
442
- end
443
-
444
- it "returns true if package is not installed" do
445
- expect(provider).to receive(:dpkgquery).with("-W", "--showformat", "'${Status} ${Package} ${Version}\\n'", resource_name).and_return("unknown ok not-installed #{resource_name}")
446
- expect(provider.package_not_installed?).to eq(true)
447
- end
448
-
449
- it "returns false if package is installed" do
450
- expect(provider).to receive(:dpkgquery).with("-W", "--showformat", "'${Status} ${Package} ${Version}\\n'", resource_name).and_return("install ok installed resource_name 1.2.3")
451
- expect(provider.package_not_installed?).to eq(false)
452
- end
453
- end
290
+ it "raises error if package name is nil" do
291
+ expect {provider.package_not_installed?(nil)}.to raise_error(ArgumentError,"Package name is nil or empty")
292
+ expect {provider.package_not_installed?("")}.to raise_error(ArgumentError,"Package name is nil or empty")
454
293
  end
455
294
  end
295
+