Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix: user resources support for group with whitespace #258

Merged
merged 3 commits into from
Nov 24, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions lib/resources/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,7 @@ def identity(username)

# parse words
params = SimpleConfig.new(
cmd.stdout.chomp,
line_separator: ' ',
parse_id_entries(cmd.stdout.chomp),
assignment_re: /^\s*([^=]*?)\s*=\s*(.*?)\s*$/,
group_re: nil,
multiple_values: false,
Expand All @@ -210,6 +209,17 @@ def identity(username)
groups: parse_value(params['groups']).values,
}
end

# splits the results of id into seperate lines
def parse_id_entries(raw)
data = []
until (index = raw.index(/\)\s{1}/)).nil?
data.push(raw[0, index+1]) # inclue closing )
raw = raw[index+2, raw.length-index-2]
end
data.push(raw) if !raw.nil?
data.join("\n")
end
end

class LinuxUser < UnixUser
Expand Down
4 changes: 4 additions & 0 deletions test/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ def md.directory?
'id root' => cmd.call('id-root'),
'getent passwd root' => cmd.call('getent-passwd-root'),
'chage -l root' => cmd.call('chage-l-root'),
# user information for ldap test
'id jfolmer' => cmd.call('id-jfolmer'),
'getent passwd jfolmer' => cmd.call('getent-passwd-jfolmer'),
'chage -l jfolmer' => cmd.call('chage-l-root'),
# user info for mac
'id chartmann' => cmd.call('id-chartmann'),
'dscl -q . -read /Users/chartmann NFSHomeDirectory PrimaryGroupID RecordName UniqueID UserShell' => cmd.call('dscl'),
Expand Down
1 change: 1 addition & 0 deletions test/unit/mock/cmd/getent-passwd-jfolmer
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
jfolmer:x:0:0:jfolmer:/jfolmer:/bin/bash
1 change: 1 addition & 0 deletions test/unit/mock/cmd/id-jfolmer
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid=201105(jfolmer) gid=200513(domain users) groups=200513(domain users),200512(domain admins),200572(denied rodc password replication group)
13 changes: 13 additions & 0 deletions test/unit/resources/user_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,19 @@
_(resource.warndays).must_equal 7
end

# ubuntu 14.04 test with ldap user
it 'read user on ubuntu' do
resource = MockLoader.new(:ubuntu1404).load_resource('user', 'jfolmer')
_(resource.exists?).must_equal true
_(resource.group).must_equal 'domain users'
_(resource.groups).must_equal ['domain users', 'domain admins', 'denied rodc password replication group']
_(resource.home).must_equal '/jfolmer'
_(resource.shell).must_equal '/bin/bash'
_(resource.mindays).must_equal 0
_(resource.maxdays).must_equal 99999
_(resource.warndays).must_equal 7
end

# serverspec compatibility tests (do not test matcher)
it 'verify serverspec compatibility' do
resource = MockLoader.new(:ubuntu1404).load_resource('user', 'root')
Expand Down