Skip to content

Commit

Permalink
don't add user to his primary group (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
deric committed Jan 14, 2017
1 parent 39d6c1d commit c4b40c3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
9 changes: 6 additions & 3 deletions lib/puppet/parser/functions/accounts_group_members.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ module Puppet::Parser::Functions
res[g]['members'] = [] unless res[g].key?('members')
res[g]['require'] = [] unless res[g].key?('require')
end
res[g]['members'] << user unless res[g]['members'].include? user
res[g]['require'] << "User[#{user}]"
unless user.nil?
res[g]['members'] << user unless res[g]['members'].include? user
res[g]['require'] << "User[#{user}]"
end
end

res = args[1].clone
Expand All @@ -37,7 +39,8 @@ module Puppet::Parser::Functions
val['manage_group'] = true unless val.key? 'manage_group'
if val['manage_group']
g = val['primary_group']
assign_helper.call(res, g, user)
# no need to assign user to his primary group
assign_helper.call(res, g, nil)
if val.key? 'gid'
res[g]['gid'] = val['gid'] # manually override GID
end
Expand Down
4 changes: 2 additions & 2 deletions spec/acceptance/users_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class {'::accounts':

describe command('getent group dalp') do
its(:exit_status) { is_expected.to eq 0 }
its(:stdout) { is_expected.to match /dalp:x:(\d+):dalp/ }
its(:stdout) { is_expected.to match /dalp:x:(\d+):/ }
end

describe user('deployer') do
Expand All @@ -72,7 +72,7 @@ class {'::accounts':

describe command('getent group deployer') do
its(:exit_status) { is_expected.to eq 0 }
its(:stdout) { is_expected.to match /deployer:x:(\d+):deployer/ }
its(:stdout) { is_expected.to match /deployer:x:(\d+):/ }
end

end
Expand Down
14 changes: 7 additions & 7 deletions spec/functions/accounts_group_members_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
'sudo' => {'members' => [:foo], 'require'=> ['User[foo]']},
'bar' => {'members' => [:john],'require'=> ['User[john]']},
'users' => {'members' => [:foo,:john], 'require'=> ['User[foo]','User[john]']},
'foo' => {'members' => [:foo], 'require' => ['User[foo]']},
'john' => {'members' => [:john], 'require' => ['User[john]']},
'foo' => {'members' => [], 'require' => []},
'john' => {'members' => [], 'require' => []},
}
)
end
Expand All @@ -50,8 +50,8 @@

is_expected.to run.with_params(users, {}).and_return(
{
'alice' => {'members' => [:alice], 'require'=> ['User[alice]']},
'bob' => {'members' => [:bob], 'require'=> ['User[bob]']},
'alice' => {'members' => [], 'require'=> []},
'bob' => {'members' => [], 'require'=> []},
'sudo' => {'members' => [:bob], 'require'=> ['User[bob]']},
'users' => {
'members' => [:alice, :bob],
Expand All @@ -62,14 +62,14 @@
end
end

describe 'extract also primary groups' do
describe 'do not extract primary groups' do
it 'finds group specified by primary_group' do
users = {
foo: { 'primary_group' => 'testgroup', 'manage_group' => true},
}

is_expected.to run.with_params(users, {}).and_return(
{'testgroup' => {'members' => [:foo], 'require' => ['User[foo]']}}
{'testgroup' => {'members' => [], 'require' => []}}
)
end

Expand All @@ -81,7 +81,7 @@
}

is_expected.to run.with_params(users, {}).and_return(
{"testgroup"=>{"members"=>[:foo], "require"=>["User[foo]"], "gid"=>123}}
{"testgroup"=>{"members"=>[], "require"=>[], "gid"=>123}}
)
end
end
Expand Down

0 comments on commit c4b40c3

Please sign in to comment.