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

Use env vars instead of Etc module for local user lookup #293

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
3 changes: 1 addition & 2 deletions lib/sshkit/host.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require 'ostruct'
require 'etc'

module SSHKit

Expand All @@ -26,7 +25,7 @@ def initialize(host_string_or_options_hash)
if host_string_or_options_hash == :local
@local = true
@hostname = "localhost"
@user = Etc.getpwuid.name
@user = ENV['USER'] || ENV['LOGNAME'] || ENV['USERNAME']
elsif !host_string_or_options_hash.is_a?(Hash)
suitable_parsers = [
SimpleHostParser,
Expand Down
6 changes: 3 additions & 3 deletions test/unit/test_host.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require 'helper'
require 'etc'

module SSHKit

Expand Down Expand Up @@ -46,8 +45,9 @@ def test_host_local
h = Host.new :local
assert h.local?
assert_nil h.port
assert_equal Etc.getpwuid.name, h.username
assert_equal 'localhost', h.hostname
username_candidates = ENV['USER'] || ENV['LOGNAME'] || ENV['USERNAME']
assert_equal username_candidates, h.username
assert_equal 'localhost', h.hostname
end

def test_does_not_confuse_ipv6_hosts_with_port_specification
Expand Down