puppet 5.5.6-x64-mingw32 → 5.5.7-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 (152) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +3 -1
  3. data/Gemfile.lock +12 -12
  4. data/Rakefile +9 -0
  5. data/lib/puppet/application.rb +5 -0
  6. data/lib/puppet/application/apply.rb +1 -0
  7. data/lib/puppet/application/master.rb +9 -7
  8. data/lib/puppet/application/script.rb +1 -1
  9. data/lib/puppet/defaults.rb +51 -31
  10. data/lib/puppet/etc.rb +20 -0
  11. data/lib/puppet/file_serving/fileset.rb +1 -1
  12. data/lib/puppet/functions.rb +123 -0
  13. data/lib/puppet/functions/new.rb +37 -53
  14. data/lib/puppet/functions/warning.rb +1 -1
  15. data/lib/puppet/loaders.rb +1 -0
  16. data/lib/puppet/parser/functions.rb +3 -1
  17. data/lib/puppet/parser/functions/sprintf.rb +12 -1
  18. data/lib/puppet/pops/evaluator/runtime3_converter.rb +16 -0
  19. data/lib/puppet/pops/evaluator/runtime3_support.rb +3 -4
  20. data/lib/puppet/pops/issues.rb +8 -0
  21. data/lib/puppet/pops/loader/loader.rb +2 -2
  22. data/lib/puppet/pops/loader/loader_paths.rb +3 -1
  23. data/lib/puppet/pops/loader/module_loaders.rb +1 -1
  24. data/lib/puppet/pops/loader/ruby_legacy_function_instantiator.rb +62 -0
  25. data/lib/puppet/pops/loaders.rb +5 -21
  26. data/lib/puppet/pops/parser/heredoc_support.rb +1 -2
  27. data/lib/puppet/pops/parser/lexer2.rb +1 -1
  28. data/lib/puppet/pops/validation/checker4_0.rb +31 -6
  29. data/lib/puppet/pops/validation/validator_factory_4_0.rb +1 -0
  30. data/lib/puppet/property/keyvalue.rb +70 -8
  31. data/lib/puppet/provider/aix_object.rb +483 -0
  32. data/lib/puppet/provider/exec.rb +54 -57
  33. data/lib/puppet/provider/group/aix.rb +40 -115
  34. data/lib/puppet/provider/group/pw.rb +4 -8
  35. data/lib/puppet/provider/group/windows_adsi.rb +7 -4
  36. data/lib/puppet/provider/nameservice.rb +1 -25
  37. data/lib/puppet/provider/nameservice/directoryservice.rb +5 -3
  38. data/lib/puppet/provider/package/portage.rb +2 -2
  39. data/lib/puppet/provider/package/windows.rb +2 -2
  40. data/lib/puppet/provider/package/windows/exe_package.rb +3 -10
  41. data/lib/puppet/provider/package/zypper.rb +1 -1
  42. data/lib/puppet/provider/service/launchd.rb +19 -3
  43. data/lib/puppet/provider/service/windows.rb +49 -40
  44. data/lib/puppet/provider/user/aix.rb +180 -246
  45. data/lib/puppet/provider/user/windows_adsi.rb +9 -1
  46. data/lib/puppet/resource/catalog.rb +1 -5
  47. data/lib/puppet/type/augeas.rb +1 -1
  48. data/lib/puppet/type/exec.rb +16 -14
  49. data/lib/puppet/type/file.rb +2 -2
  50. data/lib/puppet/type/file/source.rb +9 -5
  51. data/lib/puppet/type/group.rb +65 -23
  52. data/lib/puppet/type/k5login.rb +2 -2
  53. data/lib/puppet/type/notify.rb +1 -1
  54. data/lib/puppet/type/package.rb +3 -6
  55. data/lib/puppet/type/resources.rb +12 -2
  56. data/lib/puppet/type/schedule.rb +8 -1
  57. data/lib/puppet/type/selboolean.rb +2 -2
  58. data/lib/puppet/type/selmodule.rb +3 -4
  59. data/lib/puppet/type/service.rb +2 -5
  60. data/lib/puppet/type/tidy.rb +1 -1
  61. data/lib/puppet/type/user.rb +15 -20
  62. data/lib/puppet/type/yumrepo.rb +2 -2
  63. data/lib/puppet/type/zone.rb +2 -2
  64. data/lib/puppet/util.rb +7 -3
  65. data/lib/puppet/util/execution.rb +15 -1
  66. data/lib/puppet/util/posix.rb +15 -0
  67. data/lib/puppet/util/storage.rb +12 -0
  68. data/lib/puppet/util/windows.rb +4 -2
  69. data/lib/puppet/util/windows/adsi.rb +235 -205
  70. data/lib/puppet/util/windows/process.rb +23 -3
  71. data/lib/puppet/util/windows/security.rb +14 -0
  72. data/lib/puppet/util/windows/service.rb +977 -0
  73. data/lib/puppet/util/windows/user.rb +3 -5
  74. data/lib/puppet/version.rb +1 -1
  75. data/locales/ja/puppet.po +705 -374
  76. data/locales/puppet.pot +485 -261
  77. data/man/man5/puppet.conf.5 +36 -15
  78. data/man/man8/puppet-agent.8 +1 -1
  79. data/man/man8/puppet-apply.8 +1 -1
  80. data/man/man8/puppet-ca.8 +1 -1
  81. data/man/man8/puppet-catalog.8 +1 -1
  82. data/man/man8/puppet-cert.8 +1 -1
  83. data/man/man8/puppet-certificate.8 +1 -1
  84. data/man/man8/puppet-certificate_request.8 +1 -1
  85. data/man/man8/puppet-certificate_revocation_list.8 +1 -1
  86. data/man/man8/puppet-config.8 +1 -1
  87. data/man/man8/puppet-describe.8 +1 -1
  88. data/man/man8/puppet-device.8 +1 -1
  89. data/man/man8/puppet-doc.8 +1 -1
  90. data/man/man8/puppet-epp.8 +1 -1
  91. data/man/man8/puppet-facts.8 +1 -1
  92. data/man/man8/puppet-filebucket.8 +1 -1
  93. data/man/man8/puppet-generate.8 +1 -1
  94. data/man/man8/puppet-help.8 +1 -1
  95. data/man/man8/puppet-key.8 +1 -1
  96. data/man/man8/puppet-lookup.8 +1 -1
  97. data/man/man8/puppet-man.8 +1 -1
  98. data/man/man8/puppet-master.8 +1 -1
  99. data/man/man8/puppet-module.8 +1 -1
  100. data/man/man8/puppet-node.8 +1 -1
  101. data/man/man8/puppet-parser.8 +1 -1
  102. data/man/man8/puppet-plugin.8 +1 -1
  103. data/man/man8/puppet-report.8 +1 -1
  104. data/man/man8/puppet-resource.8 +1 -1
  105. data/man/man8/puppet-script.8 +1 -1
  106. data/man/man8/puppet-status.8 +1 -1
  107. data/man/man8/puppet.8 +2 -2
  108. data/spec/fixtures/unit/provider/aix_object/aix_colon_list_real_world_input.out +1 -0
  109. data/spec/fixtures/unit/provider/aix_object/aix_colon_list_real_world_output.out +1 -0
  110. data/spec/fixtures/unit/provider/user/aix/aix_passwd_file.out +32 -0
  111. data/spec/integration/parser/collection_spec.rb +4 -8
  112. data/spec/integration/provider/service/windows_spec.rb +5 -5
  113. data/spec/integration/type/file_spec.rb +6 -6
  114. data/spec/integration/util/windows/adsi_spec.rb +6 -5
  115. data/spec/integration/util/windows/security_spec.rb +10 -7
  116. data/spec/integration/util/windows/user_spec.rb +37 -17
  117. data/spec/spec_helper.rb +0 -1
  118. data/spec/unit/application/apply_spec.rb +41 -2
  119. data/spec/unit/application/master_spec.rb +7 -0
  120. data/spec/unit/application_spec.rb +21 -3
  121. data/spec/unit/defaults_spec.rb +20 -0
  122. data/spec/unit/etc_spec.rb +25 -0
  123. data/spec/unit/file_serving/fileset_spec.rb +11 -11
  124. data/spec/unit/gettext/config_spec.rb +1 -1
  125. data/spec/unit/pops/evaluator/evaluating_parser_spec.rb +6 -6
  126. data/spec/unit/pops/loaders/loaders_spec.rb +40 -7
  127. data/spec/unit/pops/parser/parse_heredoc_spec.rb +16 -0
  128. data/spec/unit/pops/validator/validator_spec.rb +129 -10
  129. data/spec/unit/property/keyvalue_spec.rb +97 -6
  130. data/spec/unit/provider/aix_object_spec.rb +805 -0
  131. data/spec/unit/provider/group/aix_spec.rb +57 -0
  132. data/spec/unit/provider/group/pw_spec.rb +0 -6
  133. data/spec/unit/provider/group/windows_adsi_spec.rb +34 -35
  134. data/spec/unit/provider/nameservice/directoryservice_spec.rb +2 -2
  135. data/spec/unit/provider/package/windows/exe_package_spec.rb +3 -3
  136. data/spec/unit/provider/package/windows_spec.rb +4 -4
  137. data/spec/unit/provider/service/launchd_spec.rb +19 -0
  138. data/spec/unit/provider/service/windows_spec.rb +71 -78
  139. data/spec/unit/provider/user/aix_spec.rb +162 -116
  140. data/spec/unit/provider/user/windows_adsi_spec.rb +4 -4
  141. data/spec/unit/resource/catalog_spec.rb +2 -2
  142. data/spec/unit/ssl/certificate_authority_spec.rb +0 -1
  143. data/spec/unit/type/group_spec.rb +111 -13
  144. data/spec/unit/type/resources_spec.rb +18 -0
  145. data/spec/unit/util/execution_spec.rb +77 -0
  146. data/spec/unit/util/posix_spec.rb +28 -0
  147. data/spec/unit/util/storage_spec.rb +107 -0
  148. data/spec/unit/util/windows/adsi_spec.rb +108 -13
  149. data/spec/unit/util/windows/service_spec.rb +669 -0
  150. metadata +17 -5
  151. data/lib/puppet/provider/aixobject.rb +0 -392
  152. data/spec/unit/provider/aixobject_spec.rb +0 -101
@@ -1,169 +1,215 @@
1
1
  require 'spec_helper'
2
2
 
3
- provider_class = Puppet::Type.type(:user).provider(:aix)
4
-
5
- describe provider_class do
6
-
7
- let(:lsuser_all_example) do
8
- <<-OUTPUT
9
- root id=0 pgrp=system groups=system,bin,sys,security,cron,audit,lp home=/root shell=/usr/bin/bash auditclasses=general login=true su=true rlogin=true daemon=true admin=true sugroups=ALL admgroups=lolt,allstaff tpath=nosak ttys=ALL expires=0 auth1=SYSTEM auth2=NONE umask=22 registry=files SYSTEM=compat logintimes= loginretries=0 pwdwarntime=0 account_locked=false minage=0 maxage=0 maxexpired=-1 minalpha=0 minother=0 mindiff=0 maxrepeats=8 minlen=0 histexpire=0 histsize=0 pwdchecks= dictionlist= default_roles= fsize=2097151 cpu=-1 data=262144 stack=65536 core=2097151 rss=65536 nofiles=2000 time_last_login=1358465855 time_last_unsuccessful_login=1358378454 tty_last_login=ssh tty_last_unsuccessful_login=ssh host_last_login=rpm-builder.puppetlabs.lan host_last_unsuccessful_login=192.168.100.78 unsuccessful_login_count=0 roles=
10
- guest id=100 pgrp=usr groups=usr home=/home/guest login=true su=true rlogin=true daemon=true admin=false sugroups=ALL admgroups= tpath=nosak ttys=ALL expires=0 auth1=SYSTEM auth2=NONE umask=22 registry=files SYSTEM=compat logintimes= loginretries=0 pwdwarntime=0 account_locked=false minage=0 maxage=0 maxexpired=-1 minalpha=0 minother=0 mindiff=0 maxrepeats=8 minlen=0 histexpire=0 histsize=0 pwdchecks= dictionlist= default_roles= fsize=2097151 cpu=-1 data=262144 stack=65536 core=2097151 rss=65536 nofiles=2000 roles=
11
- OUTPUT
3
+ describe 'Puppet::Type::User::Provider::Aix' do
4
+ let(:provider_class) { Puppet::Type.type(:user).provider(:aix) }
5
+ let(:group_provider_class) { Puppet::Type.type(:group).provider(:aix) }
6
+
7
+ let(:resource) do
8
+ Puppet::Type.type(:user).new(
9
+ :name => 'test_aix_user',
10
+ :ensure => :present
11
+ )
12
12
  end
13
-
14
- let(:lsgroup_all_example) do
15
- <<-OUTPUT
16
- root id=0 pgrp=system groups=system,bin,sys,security,cron,audit,lp home=/root shell=/usr/bin/bash
17
- guest id=100 pgrp=usr groups=usr home=/home/guest
18
- OUTPUT
13
+ let(:provider) do
14
+ provider_class.new(resource)
19
15
  end
20
16
 
21
- before do
22
- @resource = stub('resource')
23
- @provider = provider_class.new(@resource)
17
+ describe '.pgrp_to_gid' do
18
+ it "finds the primary group's gid" do
19
+ provider.stubs(:ia_module_args).returns(['-R', 'module'])
20
+
21
+ group_provider_class.expects(:list_all)
22
+ .with(provider.ia_module_args)
23
+ .returns([{ :name => 'group', :id => 1}])
24
+
25
+ expect(provider_class.pgrp_to_gid(provider, 'group')).to eql(1)
26
+ end
24
27
  end
25
28
 
26
- it "should be able to return a group name based on a group ID" do
27
- @provider.stubs(:lsgroupscmd)
29
+ describe '.gid_to_pgrp' do
30
+ it "finds the gid's primary group" do
31
+ provider.stubs(:ia_module_args).returns(['-R', 'module'])
28
32
 
29
- @provider.stubs(:execute).returns(lsgroup_all_example)
33
+ group_provider_class.expects(:list_all)
34
+ .with(provider.ia_module_args)
35
+ .returns([{ :name => 'group', :id => 1}])
30
36
 
31
- expect(@provider.groupname_by_id(100)).to eq('guest')
37
+ expect(provider_class.gid_to_pgrp(provider, 1)).to eql('group')
38
+ end
32
39
  end
33
40
 
34
- it "should be able to list all users" do
35
- provider_class.stubs(:command)
41
+ describe '.expires_to_expiry' do
42
+ it 'returns absent if expires is 0' do
43
+ expect(provider_class.expires_to_expiry(provider, '0')).to eql(:absent)
44
+ end
36
45
 
37
- provider_class.stubs(:execute).returns(lsuser_all_example)
46
+ it 'returns absent if the expiry attribute is not formatted properly' do
47
+ expect(provider_class.expires_to_expiry(provider, 'bad_format')).to eql(:absent)
48
+ end
38
49
 
39
- expect(provider_class.list_all).to eq(['root', 'guest'])
50
+ it 'returns the password expiration date' do
51
+ expect(provider_class.expires_to_expiry(provider, '0910122314')).to eql('2014-09-10')
52
+ end
40
53
  end
41
54
 
42
- describe "#managed_attribute_keys" do
43
- let(:existing_attributes) do
44
- { :account_locked => 'false',
45
- :admin => 'false',
46
- :login => 'true',
47
- 'su' => 'true'
48
- }
55
+ describe '.expiry_to_expires' do
56
+ it 'returns 0 if the expiry date is 0000-00-00' do
57
+ expect(provider_class.expiry_to_expires('0000-00-00')).to eql('0')
49
58
  end
50
59
 
51
- before(:each) do
52
- original_parameters = { :attributes => attribute_array }
53
- @resource.stubs(:original_parameters).returns(original_parameters)
60
+ it 'returns 0 if the expiry date is "absent"' do
61
+ expect(provider_class.expiry_to_expires('absent')).to eql('0')
54
62
  end
55
63
 
56
- describe "invoked via manifest" do
57
- let(:attribute_array) { ["rlogin=false", "login =true"] }
58
- let(:single_attribute_array) { "rlogin=false" }
64
+ it 'returns 0 if the expiry date is :absent' do
65
+ expect(provider_class.expiry_to_expires(:absent)).to eql('0')
66
+ end
59
67
 
60
- it "should return only the keys of the attribute key=value pair from manifest" do
61
- keys = @provider.managed_attribute_keys(existing_attributes)
62
- expect(keys).to be_include(:rlogin)
63
- expect(keys).to be_include(:login)
64
- expect(keys).not_to be_include(:su)
65
- end
68
+ it 'returns the expires attribute value' do
69
+ expect(provider_class.expiry_to_expires('2014-09-10')).to eql('0910000014')
70
+ end
71
+ end
66
72
 
67
- it "should strip spaces from symbols" do
68
- keys = @provider.managed_attribute_keys(existing_attributes)
69
- expect(keys).to be_include(:login)
70
- expect(keys).not_to be_include(:"login ")
71
- end
73
+ describe '.groups_attribute_to_property' do
74
+ it "reads the user's groups from the etc/groups file" do
75
+ groups = ['system', 'adm']
76
+ Puppet::Util::POSIX.stubs(:groups_of).with(resource[:name]).returns(groups)
72
77
 
73
- it "should have the same count as that from the manifest" do
74
- keys = @provider.managed_attribute_keys(existing_attributes)
75
- expect(keys.size).to eq(attribute_array.size)
76
- end
78
+ actual_groups = provider_class.groups_attribute_to_property(provider, 'unused_value')
79
+ expected_groups = groups.join(',')
77
80
 
78
- it "should convert the keys to symbols" do
79
- keys = @provider.managed_attribute_keys(existing_attributes)
80
- all_symbols = keys.all? {|k| k.is_a? Symbol}
81
- expect(all_symbols).to be_truthy
82
- end
81
+ expect(actual_groups).to eql(expected_groups)
82
+ end
83
+ end
83
84
 
84
- it "should allow a single attribute to be specified" do
85
- @resource.stubs(:original_parameters).returns({ :attributes => single_attribute_array })
86
- keys = @provider.managed_attribute_keys(existing_attributes)
87
- expect(keys).to be_include(:rlogin)
85
+ describe '.groups_property_to_attribute' do
86
+ it 'raises an ArgumentError if the groups are space-separated' do
87
+ groups = "foo bar baz"
88
+ expect do
89
+ provider_class.groups_property_to_attribute(groups)
90
+ end.to raise_error do |error|
91
+ expect(error).to be_a(ArgumentError)
92
+
93
+ expect(error.message).to match(groups)
94
+ expect(error.message).to match("Groups")
88
95
  end
89
96
  end
97
+ end
90
98
 
91
- describe "invoked via RAL" do
92
- let(:attribute_array) { nil }
99
+ describe '#gid=' do
100
+ let(:value) { 'new_pgrp' }
93
101
 
94
- it "should return the keys in supplied hash" do
95
- keys = @provider.managed_attribute_keys(existing_attributes)
96
- expect(keys).not_to be_include(:rlogin)
97
- expect(keys).to be_include(:login)
98
- expect(keys).to be_include(:su)
99
- end
102
+ let(:old_pgrp) { 'old_pgrp' }
103
+ let(:cur_groups) { 'system,adm' }
104
+ before(:each) do
105
+ provider.stubs(:gid).returns(old_pgrp)
106
+ provider.stubs(:groups).returns(cur_groups)
107
+ provider.stubs(:set)
108
+ end
109
+
110
+ it 'raises a Puppet::Error if it fails to set the groups property' do
111
+ provider.stubs(:set)
112
+ .with(:groups, cur_groups)
113
+ .raises(Puppet::ExecutionFailure, 'failed to reset the groups!')
100
114
 
101
- it "should convert the keys to symbols" do
102
- keys = @provider.managed_attribute_keys(existing_attributes)
103
- all_symbols = keys.all? {|k| k.is_a? Symbol}
104
- expect(all_symbols).to be_truthy
115
+ expect { provider.gid = value }.to raise_error do |error|
116
+ expect(error).to be_a(Puppet::Error)
117
+
118
+ expect(error.message).to match('groups')
119
+ expect(error.message).to match(cur_groups)
120
+ expect(error.message).to match(old_pgrp)
121
+ expect(error.message).to match(value)
105
122
  end
106
123
  end
107
124
  end
108
125
 
109
- describe "#should_include?" do
110
- it "should exclude keys translated into something else" do
111
- managed_keys = [:rlogin]
112
- @provider.class.attribute_mapping_from.stubs(:include?).with(:rlogin).returns(true)
113
- @provider.class.stubs(:attribute_ignore).returns([])
114
- expect(@provider.should_include?(:rlogin, managed_keys)).to be_falsey
126
+ describe '#parse_password' do
127
+ def call_parse_password
128
+ File.open(my_fixture('aix_passwd_file.out')) do |f|
129
+ provider.parse_password(f)
130
+ end
115
131
  end
116
132
 
117
- it "should exclude keys explicitly ignored" do
118
- managed_keys = [:rlogin]
119
- @provider.class.attribute_mapping_from.stubs(:include?).with(:rlogin).returns(false)
120
- @provider.class.stubs(:attribute_ignore).returns([:rlogin])
121
- expect(@provider.should_include?(:rlogin, managed_keys)).to be_falsey
133
+ it "returns :absent if the user stanza doesn't exist" do
134
+ resource[:name] = 'nonexistent_user'
135
+ expect(call_parse_password).to eql(:absent)
122
136
  end
123
137
 
124
- it "should exclude keys not specified in manifest" do
125
- managed_keys = [:su]
126
- @provider.class.attribute_mapping_from.stubs(:include?).with(:rlogin).returns(false)
127
- @provider.class.stubs(:attribute_ignore).returns([])
128
- expect(@provider.should_include?(:rlogin, managed_keys)).to be_falsey
138
+ it "returns absent if the user does not have a password" do
139
+ resource[:name] = 'no_password_user'
140
+ expect(call_parse_password).to eql(:absent)
129
141
  end
130
142
 
131
- it "should include keys specified in manifest if not translated or ignored" do
132
- managed_keys = [:rlogin]
133
- @provider.class.attribute_mapping_from.stubs(:include?).with(:rlogin).returns(false)
134
- @provider.class.stubs(:attribute_ignore).returns([])
135
- expect(@provider.should_include?(:rlogin, managed_keys)).to be_truthy
143
+ it "returns the user's password" do
144
+ expect(call_parse_password).to eql('some_password')
136
145
  end
137
146
  end
138
- describe "when handling passwords" do
139
- let(:passwd_without_spaces) do
140
- # from http://pic.dhe.ibm.com/infocenter/aix/v7r1/index.jsp?topic=%2Fcom.ibm.aix.files%2Fdoc%2Faixfiles%2Fpasswd_security.htm
141
- <<-OUTPUT
142
- smith:
143
- password = MGURSj.F056Dj
144
- lastupdate = 623078865
145
- flags = ADMIN,NOCHECK
146
- OUTPUT
147
+
148
+ # TODO: If we move from using Mocha to rspec's mocks,
149
+ # or a better and more robust mocking library, we should
150
+ # remove #parse_password and copy over its tests to here.
151
+ describe '#password' do
152
+ end
153
+
154
+ describe '#password=' do
155
+ let(:mock_tempfile) do
156
+ mock_tempfile_obj = mock()
157
+ mock_tempfile_obj.stubs(:<<)
158
+ mock_tempfile_obj.stubs(:close)
159
+ mock_tempfile_obj.stubs(:delete)
160
+ mock_tempfile_obj.stubs(:path).returns('tempfile_path')
161
+
162
+ Tempfile.stubs(:new)
163
+ .with("puppet_#{provider.name}_pw", :encoding => Encoding::ASCII)
164
+ .returns(mock_tempfile_obj)
165
+
166
+ mock_tempfile_obj
167
+ end
168
+ let(:cmd) do
169
+ [provider.class.command(:chpasswd), *provider.ia_module_args, '-e', '-c']
170
+ end
171
+ let(:execute_options) do
172
+ {
173
+ :failonfail => false,
174
+ :combine => true,
175
+ :stdinfile => mock_tempfile.path
176
+ }
147
177
  end
148
178
 
149
- let(:passwd_with_spaces) do
150
- # add trailing space to the password
151
- passwd_without_spaces.gsub(/password = (.*)/, 'password = \1 ')
179
+ it 'raises a Puppet::Error if chpasswd fails' do
180
+ provider.stubs(:execute).with(cmd, execute_options).returns("failed to change passwd!")
181
+ expect { provider.password = 'foo' }.to raise_error do |error|
182
+ expect(error).to be_a(Puppet::Error)
183
+ expect(error.message).to match("failed to change passwd!")
184
+ end
185
+ end
186
+
187
+ it "changes the user's password" do
188
+ provider.expects(:execute).with(cmd, execute_options).returns("")
189
+ provider.password = 'foo'
152
190
  end
153
191
 
192
+ it "closes and deletes the tempfile" do
193
+ provider.stubs(:execute).with(cmd, execute_options).returns("")
154
194
 
155
- it "should be able to read the hashed password" do
156
- @provider.stubs(:open_security_passwd).returns(StringIO.new(passwd_without_spaces))
157
- @resource.stubs(:[]).returns('smith')
195
+ mock_tempfile.expects(:close).times(2)
196
+ mock_tempfile.expects(:delete)
158
197
 
159
- expect(@provider.password).to eq('MGURSj.F056Dj')
198
+ provider.password = 'foo'
160
199
  end
200
+ end
201
+
202
+ describe '#create' do
203
+ it 'should create the user' do
204
+ provider.resource.stubs(:should).with(anything).returns(nil)
205
+ provider.resource.stubs(:should).with(:groups).returns('g1,g2')
206
+ provider.resource.stubs(:should).with(:password).returns('password')
161
207
 
162
- it "should be able to read the hashed password, even with trailing spaces" do
163
- @provider.stubs(:open_security_passwd).returns(StringIO.new(passwd_with_spaces))
164
- @resource.stubs(:[]).returns('smith')
208
+ provider.expects(:execute)
209
+ provider.expects(:groups=).with('g1,g2')
210
+ provider.expects(:password=).with('password')
165
211
 
166
- expect(@provider.password).to eq('MGURSj.F056Dj')
212
+ provider.create
167
213
  end
168
214
  end
169
215
  end
@@ -218,6 +218,9 @@ describe Puppet::Type.type(:user).provider(:windows_adsi), :if => Puppet.feature
218
218
  end
219
219
 
220
220
  it "should set a user's password" do
221
+ provider.user.expects(:disabled?).returns(false)
222
+ provider.user.expects(:locked_out?).returns(false)
223
+ provider.user.expects(:expired?).returns(false)
221
224
  provider.user.expects(:password=).with('plaintextbad')
222
225
 
223
226
  provider.password = "plaintextbad"
@@ -259,10 +262,7 @@ describe Puppet::Type.type(:user).provider(:windows_adsi), :if => Puppet.feature
259
262
  connection.expects(:Put).with('UserFlags', true)
260
263
  connection.expects(:SetInfo).raises( WIN32OLERuntimeError.new("(in OLE method `SetInfo': )\n OLE error code:8007089A in Active Directory\n The specified username is invalid.\r\n\n HRESULT error code:0x80020009\n Exception occurred."))
261
264
 
262
- expect{ provider.create }.to raise_error(
263
- Puppet::Error,
264
- /not able to create\/delete domain users/
265
- )
265
+ expect{ provider.create }.to raise_error(Puppet::Error)
266
266
  end
267
267
  end
268
268
 
@@ -48,8 +48,8 @@ describe Puppet::Resource::Catalog, "when compiling" do
48
48
  catalog.add_resource(res, res2, res3, res4, comp_res)
49
49
  catalog.write_resource_file
50
50
  expect(File.readlines(resourcefile).map(&:chomp)).to match_array([
51
- "file[#{File.expand_path('/tmp/sam')}]",
52
- "exec[#{File.expand_path('/bin/rm')} -rf /]"
51
+ "file[#{res.title.downcase}]",
52
+ "exec[#{res2.title.downcase}]"
53
53
  ])
54
54
  end
55
55
 
@@ -943,7 +943,6 @@ describe Puppet::SSL::CertificateAuthority do
943
943
  end
944
944
 
945
945
  it "should be deprecated" do
946
- Puppet.expects(:deprecation_warning).with(regexp_matches(/Accessing 'cacert' as a setting is deprecated/))
947
946
  Puppet.expects(:deprecation_warning).with(regexp_matches(/certificate_is_alive\? is deprecated/))
948
947
  @ca.certificate_is_alive?(@cert)
949
948
  end
@@ -2,8 +2,21 @@
2
2
  require 'spec_helper'
3
3
 
4
4
  describe Puppet::Type.type(:group) do
5
- before do
5
+ let(:mock_group_provider) do
6
+ described_class.provide(:mock_group_provider) do
7
+ has_features :manages_members
8
+ mk_resource_methods
9
+ def create; end
10
+ def delete; end
11
+ def exists?; get(:ensure) != :absent; end
12
+ def flush; end
13
+ def self.instances; []; end
14
+ end
15
+ end
16
+
17
+ before(:each) do
6
18
  @class = Puppet::Type.type(:group)
19
+ described_class.stubs(:defaultprovider).returns mock_group_provider
7
20
  end
8
21
 
9
22
  it "should have a system_groups feature" do
@@ -70,23 +83,108 @@ describe Puppet::Type.type(:group) do
70
83
  expect(type.exists?).to eq(true)
71
84
  end
72
85
 
73
- describe "should delegate :members implementation to the provider:" do
86
+ describe "when managing members" do
87
+ def stub_property(resource_hash)
88
+ described_class.new(resource_hash).property(:members)
89
+ end
90
+
91
+ describe "validation" do
92
+ it "raises an error for a non-String value" do
93
+ expect {
94
+ described_class.new(:name => 'foo', :members => true)
95
+ }.to raise_error(Puppet::Error)
96
+ end
97
+
98
+ it "raises an error for an array value containing a non-String element" do
99
+ expect {
100
+ described_class.new(:name => 'foo', :members => [ true, 'foo' ])
101
+ }.to raise_error(Puppet::Error)
102
+ end
103
+
104
+ it "raises an error when the members are specified as UIDs instead of usernames" do
105
+ expect {
106
+ described_class.new(:name => 'foo', :members => [ '123', '456' ])
107
+ }.to raise_error(Puppet::Error)
108
+ end
109
+
110
+ it "raises an error when an empty string is passed for a member's username" do
111
+ expect {
112
+ described_class.new(:name => 'foo', :members => [ 'foo', '' ])
113
+ }.to raise_error(Puppet::Error)
114
+ end
115
+
116
+ it "passes for a single member" do
117
+ expect {
118
+ described_class.new(:name => 'foo', :members => 'foo')
119
+ }.to_not raise_error
120
+ end
121
+
122
+ it "passes for a member whose username has a number" do
123
+ expect {
124
+ described_class.new(:name => 'foo', :members => 'foo123')
125
+ }.to_not raise_error
126
+ end
127
+
128
+ it "passes for an array of members" do
129
+ expect {
130
+ described_class.new(:name => 'foo', :members => [ 'foo', 'bar' ])
131
+ }.to_not raise_error
132
+ end
74
133
 
75
- let (:provider) { @class.provide(:testing) { has_features :manages_members } }
76
- let (:provider_instance) { provider.new }
77
- let (:type) { @class.new(:name => "group", :provider => provider_instance, :members => ['user1']) }
134
+ it "passes for a comma-separated list of members" do
135
+ expect {
136
+ described_class.new(:name => 'foo', :members => 'foo,bar')
137
+ }.to_not raise_error
138
+ end
139
+ end
78
140
 
79
- it "insync? calls members_insync?" do
80
- provider_instance.expects(:members_insync?).with(['user1'], ['user1']).returns true
81
- expect(type.property(:members).insync?(['user1'])).to be_truthy
141
+ describe "#inclusive?" do
142
+ it "returns false when auth_membership == false" do
143
+ members_property = stub_property(
144
+ :name => 'foo',
145
+ :auth_membership => false,
146
+ :members => []
147
+ )
148
+
149
+ expect(members_property.inclusive?).to be false
150
+ end
151
+
152
+ it "returns true when auth_membership == true" do
153
+ members_property = stub_property(
154
+ :name => 'foo',
155
+ :auth_membership => true,
156
+ :members => []
157
+ )
158
+
159
+ expect(members_property.inclusive?).to be true
160
+ end
82
161
  end
83
162
 
84
- it "is_to_s and should_to_s call members_to_s" do
85
- provider_instance.expects(:members_to_s).with(['user2', 'user1']).returns "user2 (), user1 ()"
86
- provider_instance.expects(:members_to_s).with(['user1']).returns "user1 ()"
163
+ describe "#should= munging the @should instance variable" do
164
+ def should_var_of(property)
165
+ property.instance_variable_get(:@should)
166
+ end
87
167
 
88
- expect(type.property(:members).is_to_s('user1')).to eq('user1 ()')
89
- expect(type.property(:members).should_to_s('user2,user1')).to eq('user2 (), user1 ()')
168
+ it "leaves a single member as-is" do
169
+ members_property = stub_property(:name => 'foo', :members => [])
170
+ members_property.should = 'foo'
171
+
172
+ expect(should_var_of(members_property)).to eql([ 'foo' ])
173
+ end
174
+
175
+ it "leaves an array of members as-is" do
176
+ members_property = stub_property(:name => 'foo', :members => [])
177
+ members_property.should = [ 'foo', 'bar' ]
178
+
179
+ expect(should_var_of(members_property)).to eql(['foo', 'bar'])
180
+ end
181
+
182
+ it "munges a comma-separated list of members into an array" do
183
+ members_property = stub_property(:name => 'foo', :members => [])
184
+ members_property.should = 'foo,bar'
185
+
186
+ expect(should_var_of(members_property)).to eql(['foo', 'bar'])
187
+ end
90
188
  end
91
189
  end
92
190
  end