puppet 4.3.1-x64-mingw32 → 4.3.2-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 (128) hide show
  1. checksums.yaml +4 -4
  2. data/ext/build_defaults.yaml +1 -1
  3. data/lib/hiera/scope.rb +1 -1
  4. data/lib/puppet/application/lookup.rb +41 -43
  5. data/lib/puppet/data_providers/lookup_adapter.rb +73 -26
  6. data/lib/puppet/functions/lookup.rb +126 -150
  7. data/lib/puppet/functions/match.rb +1 -0
  8. data/lib/puppet/indirector/hiera.rb +3 -1
  9. data/lib/puppet/indirector/indirection.rb +6 -2
  10. data/lib/puppet/indirector/json.rb +2 -2
  11. data/lib/puppet/module.rb +3 -2
  12. data/lib/puppet/node.rb +11 -2
  13. data/lib/puppet/parser/compiler.rb +1 -8
  14. data/lib/puppet/parser/functions/lookup.rb +128 -149
  15. data/lib/puppet/parser/functions/match.rb +1 -0
  16. data/lib/puppet/plugins/data_providers/data_provider.rb +3 -2
  17. data/lib/puppet/pops/adapters.rb +43 -0
  18. data/lib/puppet/pops/evaluator/access_operator.rb +3 -3
  19. data/lib/puppet/pops/evaluator/closure.rb +51 -51
  20. data/lib/puppet/pops/evaluator/collector_transformer.rb +16 -0
  21. data/lib/puppet/pops/evaluator/runtime3_support.rb +11 -2
  22. data/lib/puppet/pops/functions/function.rb +6 -2
  23. data/lib/puppet/pops/issues.rb +16 -0
  24. data/lib/puppet/pops/loader/puppet_function_instantiator.rb +3 -2
  25. data/lib/puppet/pops/lookup.rb +3 -0
  26. data/lib/puppet/pops/lookup/explainer.rb +73 -3
  27. data/lib/puppet/pops/lookup/invocation.rb +21 -19
  28. data/lib/puppet/pops/model/factory.rb +153 -155
  29. data/lib/puppet/pops/model/model.rb +9 -0
  30. data/lib/puppet/pops/model/model_label_provider.rb +1 -0
  31. data/lib/puppet/pops/parser/evaluating_parser.rb +3 -3
  32. data/lib/puppet/pops/parser/lexer2.rb +411 -393
  33. data/lib/puppet/pops/parser/slurp_support.rb +5 -1
  34. data/lib/puppet/pops/types/type_calculator.rb +2 -6
  35. data/lib/puppet/pops/types/types.rb +3 -9
  36. data/lib/puppet/pops/validation/checker4_0.rb +36 -12
  37. data/lib/puppet/provider/group/windows_adsi.rb +2 -2
  38. data/lib/puppet/provider/package/pip.rb +11 -1
  39. data/lib/puppet/provider/package/rpm.rb +0 -1
  40. data/lib/puppet/provider/package/yum.rb +1 -1
  41. data/lib/puppet/provider/service/debian.rb +5 -18
  42. data/lib/puppet/provider/service/init.rb +7 -0
  43. data/lib/puppet/provider/service/launchd.rb +6 -0
  44. data/lib/puppet/provider/service/systemd.rb +1 -1
  45. data/lib/puppet/provider/user/windows_adsi.rb +2 -2
  46. data/lib/puppet/provider/yumrepo/inifile.rb +6 -3
  47. data/lib/puppet/resource/type.rb +2 -1
  48. data/lib/puppet/transaction/additional_resource_generator.rb +17 -3
  49. data/lib/puppet/type/group.rb +6 -2
  50. data/lib/puppet/util/windows.rb +4 -0
  51. data/lib/puppet/util/windows/adsi.rb +61 -24
  52. data/lib/puppet/util/windows/principal.rb +181 -0
  53. data/lib/puppet/util/windows/registry.rb +21 -15
  54. data/lib/puppet/util/windows/sid.rb +42 -11
  55. data/lib/puppet/version.rb +1 -1
  56. data/spec/fixtures/unit/application/environments/production/data/common.yaml +4 -0
  57. data/spec/fixtures/unit/application/environments/production/manifests/site.pp +1 -0
  58. data/spec/fixtures/unit/application/environments/puppet_func_provider/environment.conf +1 -0
  59. data/spec/fixtures/unit/application/environments/puppet_func_provider/functions/data.pp +10 -0
  60. data/spec/fixtures/unit/application/environments/puppet_func_provider/manifests/site.pp +1 -0
  61. data/spec/fixtures/unit/data_providers/environments/hiera_module_config/data/common.yaml +4 -0
  62. data/spec/fixtures/unit/data_providers/environments/hiera_module_config/data/specific.yaml +4 -0
  63. data/spec/fixtures/unit/data_providers/environments/hiera_module_config/hiera.yaml +7 -0
  64. data/spec/fixtures/unit/data_providers/environments/hiera_modules/data/common.yaml +4 -0
  65. data/spec/fixtures/unit/data_providers/environments/hiera_modules/data/specific.yaml +4 -0
  66. data/spec/fixtures/unit/data_providers/environments/hiera_modules/environment.conf +2 -0
  67. data/spec/fixtures/unit/data_providers/environments/hiera_modules/hiera.yaml +7 -0
  68. data/spec/fixtures/unit/data_providers/environments/hiera_modules/manifests/site.pp +1 -0
  69. data/spec/fixtures/unit/data_providers/environments/hiera_modules/modules/one/data/common.yaml +6 -0
  70. data/spec/fixtures/unit/data_providers/environments/hiera_modules/modules/one/hiera.yaml +5 -0
  71. data/spec/fixtures/unit/data_providers/environments/hiera_modules/modules/one/manifests/init.pp +2 -0
  72. data/spec/fixtures/unit/data_providers/environments/hiera_modules/modules/one/metadata.json +9 -0
  73. data/spec/fixtures/unit/data_providers/environments/hiera_modules/modules/two/data/common.yaml +4 -0
  74. data/spec/fixtures/unit/data_providers/environments/hiera_modules/modules/two/hiera.yaml +5 -0
  75. data/spec/fixtures/unit/data_providers/environments/hiera_modules/modules/two/manifests/init.pp +3 -0
  76. data/spec/fixtures/unit/data_providers/environments/hiera_modules/modules/two/metadata.json +9 -0
  77. data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/modules/usee/functions/usee_puppet.pp +3 -0
  78. data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/{usee → modules/usee}/lib/puppet/functions/usee/callee.rb +0 -0
  79. data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/modules/usee/lib/puppet/functions/usee/usee_ruby.rb +6 -0
  80. data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/modules/usee/manifests/init.pp +6 -0
  81. data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/modules/usee2/lib/puppet/functions/usee2/callee.rb +5 -0
  82. data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/modules/user/functions/puppet_calling_puppet.pp +5 -0
  83. data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/modules/user/functions/puppet_calling_puppet_init.pp +5 -0
  84. data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/modules/user/functions/puppet_calling_ruby.pp +5 -0
  85. data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/{user → modules/user}/lib/puppet/functions/user/caller.rb +0 -0
  86. data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/modules/user/lib/puppet/functions/user/caller2.rb +5 -0
  87. data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/modules/user/lib/puppet/functions/user/ruby_calling_puppet.rb +5 -0
  88. data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/modules/user/lib/puppet/functions/user/ruby_calling_puppet_init.rb +5 -0
  89. data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/modules/user/lib/puppet/functions/user/ruby_calling_ruby.rb +5 -0
  90. data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/modules/user/manifests/init.pp +81 -0
  91. data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/{user → modules/user}/metadata.json +2 -1
  92. data/spec/integration/parser/collection_spec.rb +8 -0
  93. data/spec/integration/util/windows/principal_spec.rb +115 -0
  94. data/spec/{unit → integration}/util/windows/registry_spec.rb +91 -1
  95. data/spec/integration/util/windows/security_spec.rb +2 -2
  96. data/spec/unit/application/lookup_spec.rb +138 -28
  97. data/spec/unit/data_providers/hiera_data_provider_spec.rb +182 -5
  98. data/spec/unit/face/epp_face_spec.rb +2 -2
  99. data/spec/unit/functions/epp_spec.rb +6 -6
  100. data/spec/unit/functions/inline_epp_spec.rb +4 -4
  101. data/spec/unit/functions/lookup_spec.rb +30 -3
  102. data/spec/unit/functions4_spec.rb +1 -1
  103. data/spec/unit/hiera/scope_spec.rb +5 -2
  104. data/spec/unit/indirector/json_spec.rb +1 -1
  105. data/spec/unit/node_spec.rb +8 -0
  106. data/spec/unit/parser/compiler_spec.rb +0 -18
  107. data/spec/unit/pops/evaluator/access_ops_spec.rb +4 -4
  108. data/spec/unit/pops/evaluator/evaluating_parser_spec.rb +1 -1
  109. data/spec/unit/pops/loaders/loaders_spec.rb +84 -2
  110. data/spec/unit/pops/parser/lexer2_spec.rb +6 -0
  111. data/spec/unit/pops/parser/parser_rspec_helper.rb +5 -0
  112. data/spec/unit/pops/types/type_calculator_spec.rb +0 -17
  113. data/spec/unit/pops/validator/validator_spec.rb +87 -0
  114. data/spec/unit/provider/group/windows_adsi_spec.rb +8 -8
  115. data/spec/unit/provider/package/pip_spec.rb +41 -13
  116. data/spec/unit/provider/package/rpm_spec.rb +2 -25
  117. data/spec/unit/provider/package/yum_spec.rb +1 -1
  118. data/spec/unit/provider/service/debian_spec.rb +6 -24
  119. data/spec/unit/provider/service/init_spec.rb +11 -1
  120. data/spec/unit/provider/service/launchd_spec.rb +11 -0
  121. data/spec/unit/provider/service/systemd_spec.rb +18 -12
  122. data/spec/unit/provider/service/upstart_spec.rb +57 -0
  123. data/spec/unit/provider/user/windows_adsi_spec.rb +5 -5
  124. data/spec/unit/provider/yumrepo/inifile_spec.rb +16 -0
  125. data/spec/unit/resource_spec.rb +12 -2
  126. data/spec/unit/util/windows/adsi_spec.rb +44 -36
  127. data/spec/unit/util/windows/sid_spec.rb +47 -10
  128. metadata +77 -10
@@ -0,0 +1,4 @@
1
+ ---
2
+ lookup_options:
3
+ roles::devco::packages:
4
+ merge: unique
@@ -0,0 +1,5 @@
1
+ ---
2
+ :version: 4
3
+ :hierarchy:
4
+ - :name: "common"
5
+ :backend: yaml
@@ -0,0 +1,9 @@
1
+ {
2
+ "name": "example/two",
3
+ "version": "0.0.2",
4
+ "source": "git@github.com/example/example-two.git",
5
+ "dependencies": [],
6
+ "author": "Bob the Builder",
7
+ "license": "Apache-2.0",
8
+ "data_provider": "hiera"
9
+ }
@@ -0,0 +1,3 @@
1
+ function usee::usee_puppet() {
2
+ "I'm the function usee::usee_puppet()"
3
+ }
@@ -0,0 +1,6 @@
1
+ Puppet::Functions.create_function(:'usee::usee_ruby') do
2
+ def usee_ruby()
3
+ "I'm the function usee::usee_ruby()"
4
+ end
5
+ end
6
+
@@ -0,0 +1,6 @@
1
+ function usee_puppet_init() {
2
+ "I'm the function usee::usee_puppet_init()"
3
+ }
4
+
5
+ class usee {
6
+ }
@@ -0,0 +1,5 @@
1
+ Puppet::Functions.create_function(:'usee2::callee') do
2
+ def callee(value)
3
+ "usee2::callee() was told '#{value}'"
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ function user::puppet_calling_puppet () {
2
+ usee::usee_puppet()
3
+ }
4
+
5
+
@@ -0,0 +1,5 @@
1
+ function user::puppet_calling_puppet_init () {
2
+ usee_puppet_init()
3
+ }
4
+
5
+
@@ -0,0 +1,5 @@
1
+ Puppet::Functions.create_function(:'user::caller2') do
2
+ def caller2()
3
+ call_function('usee2::callee', 'passed value') + " + I am user::caller2()"
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ Puppet::Functions.create_function(:'user::ruby_calling_puppet') do
2
+ def ruby_calling_puppet()
3
+ call_function('usee::usee_puppet')
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ Puppet::Functions.create_function(:'user::ruby_calling_puppet_init') do
2
+ def ruby_calling_puppet_init()
3
+ call_function('usee_puppet_init')
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ Puppet::Functions.create_function(:'user::ruby_calling_ruby') do
2
+ def ruby_calling_ruby()
3
+ call_function('usee::usee_ruby')
4
+ end
5
+ end
@@ -0,0 +1,81 @@
1
+ function puppet_init_calling_puppet() {
2
+ usee::usee_puppet()
3
+ }
4
+
5
+ function puppet_init_calling_puppet_init() {
6
+ usee_puppet_init()
7
+ }
8
+
9
+ function puppet_init_calling_ruby() {
10
+ usee::usee_ruby()
11
+ }
12
+
13
+ class user {
14
+ case $::case_number {
15
+ 1: {
16
+ # Call a puppet function that resides in usee/functions directly from init.pp
17
+ #
18
+ notify { 'case_1': message => usee::usee_puppet() }
19
+ }
20
+ 2: {
21
+ # Call a puppet function that resides in usee/manifests/init.pp directly from init.pp
22
+ #
23
+ include usee
24
+ notify { 'case_2': message => usee_puppet_init() }
25
+ }
26
+ 3: {
27
+ # Call a ruby function that resides in usee directly from init.pp
28
+ #
29
+ notify { 'case_3': message => usee::usee_ruby() }
30
+ }
31
+ 4: {
32
+ # Call a puppet function that resides in usee/functions from a puppet function under functions
33
+ #
34
+ notify { 'case_4': message => user::puppet_calling_puppet() }
35
+ }
36
+ 5: {
37
+ # Call a puppet function that resides in usee/manifests/init.pp from a puppet function under functions
38
+ #
39
+ include usee
40
+ notify { 'case_5': message => user::puppet_calling_puppet_init() }
41
+ }
42
+ 6: {
43
+ # Call a ruby function that resides in usee from a puppet function under functions
44
+ #
45
+ notify { 'case_6': message => user::puppet_calling_ruby() }
46
+ }
47
+ 7: {
48
+ # Call a puppet function that resides in usee/functions from a puppet function in init.pp
49
+ #
50
+ notify { 'case_7': message => puppet_init_calling_puppet() }
51
+ }
52
+ 8: {
53
+ # Call a puppet function that resides in usee/manifests/init.pp from a puppet function in init.pp
54
+ #
55
+ include usee
56
+ notify { 'case_8': message => puppet_init_calling_puppet_init() }
57
+ }
58
+ 9: {
59
+ # Call a ruby function that resides in usee from a puppet function in init.pp
60
+ #
61
+ notify { 'case_9': message => puppet_init_calling_ruby() }
62
+ }
63
+ 10: {
64
+ # Call a puppet function that resides in usee/functions from a ruby function in this module
65
+ #
66
+ notify { 'case_10': message => user::ruby_calling_puppet() }
67
+ }
68
+ 11: {
69
+ # Call a puppet function that resides in usee/manifests/init.pp from a ruby function in this module
70
+ #
71
+ include usee
72
+ notify { 'case_11': message => user::ruby_calling_puppet_init() }
73
+ }
74
+ 12: {
75
+ # Call a ruby function that resides in usee from a ruby function in this module
76
+ #
77
+ notify { 'case_12': message => user::ruby_calling_ruby() }
78
+ }
79
+ }
80
+ }
81
+
@@ -5,5 +5,6 @@
5
5
  "license": "",
6
6
  "source": "",
7
7
  "version": "1.0.0",
8
- "dependencies": [{ "name": "test/usee" }]
8
+ "dependencies": [
9
+ ]
9
10
  }
@@ -95,6 +95,14 @@ describe 'collectors' do
95
95
  MANIFEST
96
96
  end
97
97
 
98
+ it "matches with resource references" do
99
+ expect_the_message_to_be(["wanted"], <<-MANIFEST)
100
+ @notify { "foobar": }
101
+ @notify { "testing": require => Notify["foobar"], message => "wanted" }
102
+ Notify <| require == Notify["foobar"] |>
103
+ MANIFEST
104
+ end
105
+
98
106
  it "allows criteria to be combined with 'and'" do
99
107
  expect_the_message_to_be(["the message"], <<-MANIFEST)
100
108
  @notify { "testing": message => "the message" }
@@ -0,0 +1,115 @@
1
+ #!/usr/bin/env ruby
2
+ require 'spec_helper'
3
+ require 'puppet/util/windows'
4
+
5
+ describe Puppet::Util::Windows::SID::Principal, :if => Puppet.features.microsoft_windows? do
6
+
7
+ let (:system_bytes) { [1, 1, 0, 0, 0, 0, 0, 5, 18, 0, 0, 0] }
8
+ let (:administrator_bytes) { [1, 2, 0, 0, 0, 0, 0, 5, 32, 0, 0, 0, 32, 2, 0, 0] }
9
+
10
+ describe ".lookup_account_name" do
11
+ it "should create an instance from a well-known account name" do
12
+ principal = Puppet::Util::Windows::SID::Principal.lookup_account_name('SYSTEM')
13
+ expect(principal.account).to eq('SYSTEM')
14
+ expect(principal.sid_bytes).to eq(system_bytes)
15
+ expect(principal.sid).to eq('S-1-5-18')
16
+ expect(principal.domain).to eq('NT AUTHORITY')
17
+ expect(principal.domain_account).to eq('NT AUTHORITY\\SYSTEM')
18
+ expect(principal.account_type).to eq(:SidTypeWellKnownGroup)
19
+ end
20
+
21
+ it "should create an instance from a well-known account prefixed with NT AUTHORITY" do
22
+ principal = Puppet::Util::Windows::SID::Principal.lookup_account_name('NT AUTHORITY\\SYSTEM')
23
+ expect(principal.account).to eq('SYSTEM')
24
+ expect(principal.sid_bytes).to eq(system_bytes)
25
+ expect(principal.sid).to eq('S-1-5-18')
26
+ expect(principal.domain).to eq('NT AUTHORITY')
27
+ expect(principal.domain_account).to eq('NT AUTHORITY\\SYSTEM')
28
+ expect(principal.account_type).to eq(:SidTypeWellKnownGroup)
29
+ end
30
+
31
+ it "should create an instance from a local account prefixed with hostname" do
32
+ current_user_name = Puppet::Util::Windows::ADSI::User.current_user_name
33
+ running_as_system = (current_user_name == 'SYSTEM')
34
+ username = running_as_system ? 'Administrator' : current_user_name
35
+
36
+ user_exists = Puppet::Util::Windows::ADSI::User.exists?(".\\#{username}")
37
+
38
+ # when running as SYSTEM (in Jenkins CI), then Administrator should be used
39
+ # otherwise running in AppVeyor there is no Administrator and a the current local user can be used
40
+ skip if (running_as_system && !user_exists)
41
+
42
+ hostname = Socket.gethostname
43
+
44
+ principal = Puppet::Util::Windows::SID::Principal.lookup_account_name("#{hostname}\\#{username}")
45
+ expect(principal.account).to match(/^#{Regexp.quote(username)}$/i)
46
+ # skip SID and bytes in this case since the most interesting thing here is domain_account
47
+ expect(principal.domain).to match(/^#{Regexp.quote(hostname)}$/i)
48
+ expect(principal.domain_account).to match(/^#{Regexp.quote(hostname)}\\#{Regexp.quote(username)}$/i)
49
+ expect(principal.account_type).to eq(:SidTypeUser)
50
+ end
51
+
52
+ it "should create an instance from a well-known group alias" do
53
+ principal = Puppet::Util::Windows::SID::Principal.lookup_account_name('Administrators')
54
+ expect(principal.account).to eq('Administrators')
55
+ expect(principal.sid_bytes).to eq(administrator_bytes)
56
+ expect(principal.sid).to eq('S-1-5-32-544')
57
+ expect(principal.domain).to eq('BUILTIN')
58
+ expect(principal.domain_account).to eq('BUILTIN\\Administrators')
59
+ expect(principal.account_type).to eq(:SidTypeAlias)
60
+ end
61
+
62
+ it "should raise an error when trying to lookup an account that doesn't exist" do
63
+ principal = Puppet::Util::Windows::SID::Principal
64
+ expect {
65
+ principal.lookup_account_name('ConanTheBarbarian')
66
+ }.to raise_error(Puppet::Util::Windows::Error, /Failed to call LookupAccountNameW/)
67
+ end
68
+ end
69
+
70
+ describe ".lookup_account_sid" do
71
+ it "should create an instance from a well-known account SID" do
72
+ principal = Puppet::Util::Windows::SID::Principal.lookup_account_sid(system_bytes)
73
+ expect(principal.account).to eq('SYSTEM')
74
+ expect(principal.sid_bytes).to eq(system_bytes)
75
+ expect(principal.sid).to eq('S-1-5-18')
76
+ expect(principal.domain).to eq('NT AUTHORITY')
77
+ expect(principal.domain_account).to eq('NT AUTHORITY\\SYSTEM')
78
+
79
+ # Windows API LookupAccountSid behaves differently if current user is SYSTEM
80
+ # even though LookupAccountName does not demonstrate same behavior
81
+ if Puppet::Util::Windows::ADSI::User.current_user_name != 'SYSTEM'
82
+ account_type = :SidTypeWellKnownGroup
83
+ else
84
+ account_type = :SidTypeUser
85
+ end
86
+
87
+ expect(principal.account_type).to eq(account_type)
88
+ end
89
+
90
+ it "should create an instance from a well-known group SID" do
91
+ principal = Puppet::Util::Windows::SID::Principal.lookup_account_sid(administrator_bytes)
92
+ expect(principal.account).to eq('Administrators')
93
+ expect(principal.sid_bytes).to eq(administrator_bytes)
94
+ expect(principal.sid).to eq('S-1-5-32-544')
95
+ expect(principal.domain).to eq('BUILTIN')
96
+ expect(principal.domain_account).to eq('BUILTIN\\Administrators')
97
+ expect(principal.account_type).to eq(:SidTypeAlias)
98
+ end
99
+
100
+ it "should raise an error when trying to lookup completely invalid SID bytes" do
101
+ principal = Puppet::Util::Windows::SID::Principal
102
+ expect {
103
+ principal.lookup_account_sid([])
104
+ }.to raise_error(Puppet::Util::Windows::Error, /Failed to call LookupAccountSidW: The parameter is incorrect/)
105
+ end
106
+
107
+ it "should raise an error when trying to lookup a valid SID that doesn't have a matching account" do
108
+ principal = Puppet::Util::Windows::SID::Principal
109
+ expect {
110
+ # S-1-1-1 which is not a valid account
111
+ principal.lookup_account_sid([1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0])
112
+ }.to raise_error(Puppet::Util::Windows::Error, /Failed to call LookupAccountSidW: No mapping between account names and security IDs was done/)
113
+ end
114
+ end
115
+ end
@@ -2,10 +2,30 @@
2
2
  require 'spec_helper'
3
3
  require 'puppet/util/windows'
4
4
 
5
- describe Puppet::Util::Windows::Registry, :if => Puppet::Util::Platform.windows? do
5
+ if Puppet::Util::Platform.windows?
6
+ describe Puppet::Util::Windows::Registry do
6
7
  subject do
7
8
  class TestRegistry
8
9
  include Puppet::Util::Windows::Registry
10
+ extend FFI::Library
11
+
12
+ ffi_lib :advapi32
13
+ attach_function :RegSetValueExW,
14
+ [:handle, :pointer, :dword, :dword, :pointer, :dword], :win32_long
15
+
16
+ def write_corrupt_dword(reg, valuename)
17
+ # Normally DWORDs contain 4 bytes. This bad data only has 2
18
+ bad_data = [0, 0]
19
+ FFI::Pointer.from_string_to_wide_string(valuename) do |name_ptr|
20
+ FFI::MemoryPointer.new(:uchar, bad_data.length) do |data_ptr|
21
+ data_ptr.write_array_of_uchar(bad_data)
22
+ if RegSetValueExW(reg.hkey, name_ptr, 0,
23
+ Win32::Registry::REG_DWORD, data_ptr, data_ptr.size) != 0
24
+ raise Puppet::Util::Windows::Error.new("Failed to write registry value")
25
+ end
26
+ end
27
+ end
28
+ end
9
29
  end
10
30
 
11
31
  TestRegistry.new
@@ -163,5 +183,75 @@ describe Puppet::Util::Windows::Registry, :if => Puppet::Util::Platform.windows?
163
183
  end
164
184
  end
165
185
  end
186
+
187
+ context "when reading values" do
188
+ let (:hklm) { Win32::Registry::HKEY_LOCAL_MACHINE }
189
+ let (:puppet_key) { "SOFTWARE\\Puppet Labs"}
190
+ let (:subkey_name) { "PuppetRegistryTest" }
191
+ let (:value_name) { SecureRandom.uuid }
192
+
193
+ after(:each) do
194
+ hklm.open(puppet_key, Win32::Registry::KEY_ALL_ACCESS) do |reg|
195
+ subject.delete_key(reg, subkey_name)
196
+ end
197
+ end
198
+
199
+ [
200
+ {:name => 'REG_SZ', :type => Win32::Registry::REG_SZ, :value => 'reg sz string'},
201
+ {:name => 'REG_EXPAND_SZ', :type => Win32::Registry::REG_EXPAND_SZ, :value => 'reg expand string'},
202
+ {:name => 'REG_MULTI_SZ', :type => Win32::Registry::REG_MULTI_SZ, :value => ['string1', 'string2']},
203
+ {:name => 'REG_BINARY', :type => Win32::Registry::REG_BINARY, :value => 'abinarystring'},
204
+ {:name => 'REG_DWORD', :type => Win32::Registry::REG_DWORD, :value => 0xFFFFFFFF},
205
+ {:name => 'REG_DWORD_BIG_ENDIAN', :type => Win32::Registry::REG_DWORD_BIG_ENDIAN, :value => 0xFFFF},
206
+ {:name => 'REG_QWORD', :type => Win32::Registry::REG_QWORD, :value => 0xFFFFFFFFFFFFFFFF},
207
+ ].each do |pair|
208
+ it "should return #{pair[:name]} values" do
209
+ hklm.create("#{puppet_key}\\#{subkey_name}", Win32::Registry::KEY_ALL_ACCESS) do |reg|
210
+ reg.write(value_name, pair[:type], pair[:value])
211
+ end
212
+
213
+ hklm.open("#{puppet_key}\\#{subkey_name}", Win32::Registry::KEY_READ) do |reg|
214
+ vals = subject.values(reg)
215
+
216
+ expect(vals).to have_key(value_name)
217
+ subject.each_value(reg) do |subkey, type, data|
218
+ expect(type).to eq(pair[:type])
219
+ end
220
+
221
+ written = vals[value_name]
222
+ expect(written).to eq(pair[:value])
223
+ end
224
+ end
225
+ end
226
+ end
227
+
228
+ context "when reading corrupt values" do
229
+ let (:hklm) { Win32::Registry::HKEY_LOCAL_MACHINE }
230
+ let (:puppet_key) { "SOFTWARE\\Puppet Labs"}
231
+ let (:subkey_name) { "PuppetRegistryTest" }
232
+ let (:value_name) { SecureRandom.uuid }
233
+
234
+ before(:each) do
235
+ hklm.create("#{puppet_key}\\#{subkey_name}", Win32::Registry::KEY_ALL_ACCESS) do |reg_key|
236
+ subject.write_corrupt_dword(reg_key, value_name)
237
+ end
238
+ end
239
+
240
+ after(:each) do
241
+ hklm.open(puppet_key, Win32::Registry::KEY_ALL_ACCESS) do |reg_key|
242
+ subject.delete_key(reg_key, subkey_name)
243
+ end
244
+ end
245
+
246
+ it "should return nil for a corrupt DWORD" do
247
+ hklm.open("#{puppet_key}\\#{subkey_name}", Win32::Registry::KEY_ALL_ACCESS) do |reg_key|
248
+ vals = subject.values(reg_key)
249
+
250
+ expect(vals).to have_key(value_name)
251
+ expect(vals[value_name]).to be_nil
252
+ end
253
+ end
254
+ end
166
255
  end
167
256
  end
257
+ end
@@ -478,7 +478,7 @@ describe "Puppet::Util::Windows::Security", :if => Puppet.features.microsoft_win
478
478
  user = Puppet::Util::Windows::ADSI::User.create("puppet#{rand(10000)}")
479
479
  user.commit
480
480
  begin
481
- sid = Puppet::Util::Windows::ADSI::User.new(user.name).sid.to_s
481
+ sid = Puppet::Util::Windows::ADSI::User.new(user.name).sid.sid
482
482
  winsec.set_owner(sid, path)
483
483
  winsec.set_mode(WindowsSecurityTester::S_IRWXU, path)
484
484
  ensure
@@ -494,7 +494,7 @@ describe "Puppet::Util::Windows::Security", :if => Puppet.features.microsoft_win
494
494
  group = Puppet::Util::Windows::ADSI::Group.create("puppet#{rand(10000)}")
495
495
  group.commit
496
496
  begin
497
- sid = Puppet::Util::Windows::ADSI::Group.new(group.name).sid.to_s
497
+ sid = Puppet::Util::Windows::ADSI::Group.new(group.name).sid.sid
498
498
  winsec.set_group(sid, path)
499
499
  winsec.set_mode(WindowsSecurityTester::S_IRWXG, path)
500
500
  ensure