diff options
author | Itsuki Noda <i.noda@aist.go.jp> | 2020-05-01 18:06:08 +0900 |
---|---|---|
committer | Itsuki Noda <i.noda@aist.go.jp> | 2020-05-01 18:06:08 +0900 |
commit | 07a4c1d02afec1f33582f17f637b739050da2c2b (patch) | |
tree | eb6beadf803121ad37ab389397534539e1e389fd | |
parent | 139126b08ded6fe2451c3791a1c041f378920a05 (diff) | |
download | net-ssh-07a4c1d02afec1f33582f17f637b739050da2c2b.tar.gz |
Let use Etc.getpwuid.name() instead of Etc.getlogin to adapt default behavior of ssh.
related issue: #749.
-rw-r--r-- | CHANGES.txt | 5 | ||||
-rw-r--r-- | lib/net/ssh.rb | 2 | ||||
-rw-r--r-- | test/start/test_user_nil.rb | 2 |
3 files changed, 7 insertions, 2 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index 592dfe2..fc19d9e 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,3 +1,8 @@ + + * adapt to ssh's default bahaviors when no username is provided. + When Net::SSH.start user is nil and config has no entry + we default to Etc.getpwuid.name() instead of Etc.getlogin(). [#749] + === 6.1.0.rc1 * Make sha2-{256,512}-etm@openssh.com MAC default again [#761] diff --git a/lib/net/ssh.rb b/lib/net/ssh.rb index 9df01f0..292d6c6 100644 --- a/lib/net/ssh.rb +++ b/lib/net/ssh.rb @@ -251,7 +251,7 @@ module Net transport = Transport::Session.new(host, options) auth = Authentication::Session.new(transport, options) - user = options.fetch(:user, user) || Etc.getlogin + user = options.fetch(:user, user) || Etc.getpwuid.name if auth.authenticate("ssh-connection", user, options[:password]) connection = Connection::Session.new(transport, options) if block_given? diff --git a/test/start/test_user_nil.rb b/test/start/test_user_nil.rb index 66e4a8c..ff2cd59 100644 --- a/test/start/test_user_nil.rb +++ b/test/start/test_user_nil.rb @@ -18,7 +18,7 @@ module NetSSH end def test_start_should_use_default_user_when_nil - @authentication_session.stubs(:authenticate).with {|_next_service, user, _password| user == Etc.getlogin }.returns(true) + @authentication_session.stubs(:authenticate).with {|_next_service, user, _password| user == Etc.getpwuid.name }.returns(true) assert_nothing_raised do Net::SSH.start('localhost', nil, config: false) end |