File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ def create
3030 if resource [ :admin ] == :true
3131 make_user_admin ( )
3232 end
33- if !resource [ :tags ] . nil ?
33+ if ! resource [ :tags ] . empty ?
3434 set_user_tags ( resource [ :tags ] )
3535 end
3636 end
@@ -67,7 +67,12 @@ def exists?
6767
6868
6969 def tags
70- get_user_tags . entries . sort
70+ tags = get_user_tags
71+ # do not expose the administrator tag for admins
72+ if resource [ :admin ] == :true
73+ tags . delete ( 'administrator' )
74+ end
75+ tags . entries . sort
7176 end
7277
7378
Original file line number Diff line number Diff line change @@ -32,17 +32,48 @@ def change_to_s(current, desired)
3232 end
3333
3434 newproperty ( :admin ) do
35- desc 'rather or not user should be an admin'
35+ desc 'whether or not user should be an admin'
3636 newvalues ( /true|false/ )
3737 munge do |value |
38- # converting to_s incase its a boolean
38+ # converting to_s in case its a boolean
3939 value . to_s . to_sym
4040 end
4141 defaultto :false
4242 end
4343
4444 newproperty ( :tags , :array_matching => :all ) do
4545 desc 'additional tags for the user'
46+ validate do |value |
47+ unless value =~ /^\S +$/
48+ raise ArgumentError , "Invalid tag: #{ value . inspect } "
49+ end
50+
51+ if value == "administrator"
52+ raise ArgumentError , "must use admin property instead of administrator tag"
53+ end
54+ end
55+ defaultto [ ]
56+
57+ def insync? ( is )
58+ self . is_to_s ( is ) == self . should_to_s
59+ end
60+
61+ def is_to_s ( currentvalue = @is )
62+ if currentvalue
63+ "[#{ currentvalue . sort . join ( ', ' ) } ]"
64+ else
65+ '[]'
66+ end
67+ end
68+
69+ def should_to_s ( newvalue = @should )
70+ if newvalue
71+ "[#{ newvalue . sort . join ( ', ' ) } ]"
72+ else
73+ '[]'
74+ end
75+ end
76+
4677 end
4778
4879 validate do
Original file line number Diff line number Diff line change 194194 @provider . create
195195 end
196196
197+ it 'should not return the administrator tag in tags for admins' do
198+ @resource [ :tags ] = [ ]
199+ @resource [ :admin ] = true
200+ @provider . expects ( :rabbitmqctl ) . with ( '-q' , 'list_users' ) . returns <<-EOT
201+ foo [administrator]
202+ EOT
203+ @provider . tags . should == [ ]
204+ end
205+
206+ it 'should return the administrator tag for non-admins' do
207+ # this should not happen though.
208+ @resource [ :tags ] = [ ]
209+ @resource [ :admin ] = :false
210+ @provider . expects ( :rabbitmqctl ) . with ( '-q' , 'list_users' ) . returns <<-EOT
211+ foo [administrator]
212+ EOT
213+ @provider . tags . should == [ "administrator" ]
214+ end
197215end
Original file line number Diff line number Diff line change 3939 @user [ :admin ] = 'yes'
4040 } . to raise_error ( Puppet ::Error , /Invalid value/ )
4141 end
42+ it 'should not accept tags with spaces' do
43+ expect {
44+ @user [ :tags ] = [ 'policy maker' ]
45+ } . to raise_error ( Puppet ::Error , /Invalid tag/ )
46+ end
47+ it 'should not accept the administrator tag' do
48+ expect {
49+ @user [ :tags ] = [ 'administrator' ]
50+ } . to raise_error ( Puppet ::Error , /must use admin property/ )
51+ end
4252end
You can’t perform that action at this time.
0 commit comments