Skip to content

Commit

Permalink
Merge pull request #386 from juliandunn/getlogin-lies
Browse files Browse the repository at this point in the history
getlogin() often lies, especially when run under "su"
  • Loading branch information
juliandunn committed Aug 15, 2014
2 parents a8bd2e0 + fec9467 commit 28dcc46
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/ohai/plugins/passwd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def fix_encoding(str)
end

unless current_user
current_user fix_encoding(Etc.getlogin)
current_user fix_encoding(Etc.getpwuid(Process.euid).name)
end
end
end
3 changes: 2 additions & 1 deletion spec/unit/plugins/passwd_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
end

it "should set the current user" do
Etc.should_receive(:getlogin).and_return('chef')
Process.should_receive(:euid).and_return('31337')
Etc.should_receive(:getpwuid).and_return(PasswdEntry.new('chef', 31337, 31337, '/home/chef', '/bin/ksh', 'Julia Child'))
@plugin.run
@plugin[:current_user].should == 'chef'
end
Expand Down

0 comments on commit 28dcc46

Please sign in to comment.