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

Add windows user SID as 'UID' in user resource. Fix #960 #982

Merged
merged 3 commits into from
Aug 26, 2016
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
16 changes: 8 additions & 8 deletions lib/resources/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ def identity(username)
ConvertTo-Json
EOH

cmd = inspec.script(script)
cmd = inspec.powershell(script)

# cannot rely on exit code for now, successful command returns exit code 1
# return nil if cmd.exit_status != 0, try to parse json
Expand All @@ -448,18 +448,18 @@ def identity(username)
return nil
end

user = params['User']['Caption'] unless params['User'].nil?
groups = params['Groups']
user_hash = params['User'] || {}
group_hashes = params['Groups'] || []
# if groups is no array, generate one
groups = [groups] if !groups.is_a?(Array)
groups = groups.map { |grp| grp['Caption'] } unless params['Groups'].nil?
group_hashes = [group_hashes] unless group_hashes.is_a?(Array)
group_names = group_hashes.map { |grp| grp['Caption'] }

{
uid: nil,
user: user,
uid: user_hash['SID'],
user: user_hash['Caption'],
gid: nil,
group: nil,
groups: groups,
groups: group_names,
}
end

Expand Down
2 changes: 2 additions & 0 deletions test/integration/default/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@
if os.windows?
describe user(userinfo[:name]) do
it { should exist }
# should return the SID of the user
its('uid') { should_not eq nil}
end
else
describe user(userinfo[:name]) do
Expand Down
1 change: 1 addition & 0 deletions test/unit/resources/user_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@

it 'read user on Windows' do
resource = MockLoader.new(:windows).load_resource('user', 'example/Administrator')
_(resource.uid).wont_be_nil
_(resource.exists?).must_equal true
_(resource.group).must_equal nil
_(resource.groups).must_equal ['WIN-K0AKLED332V\\Administrators', 'EXAMPLE\\Domain Admins']
Expand Down