summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklós Fazekas <mfazekas@szemafor.com>2020-05-01 11:26:25 +0200
committerGitHub <noreply@github.com>2020-05-01 11:26:25 +0200
commit3768f1f1a81504909df7b9ee95fdd16f6610096d (patch)
treeeb6beadf803121ad37ab389397534539e1e389fd
parent139126b08ded6fe2451c3791a1c041f378920a05 (diff)
parent07a4c1d02afec1f33582f17f637b739050da2c2b (diff)
downloadnet-ssh-3768f1f1a81504909df7b9ee95fdd16f6610096d.tar.gz
Merge pull request #762 from noda50/master
Let use Etc.getpwuid.name() instead of Etc.getlogin to adapt default …
-rw-r--r--CHANGES.txt5
-rw-r--r--lib/net/ssh.rb2
-rw-r--r--test/start/test_user_nil.rb2
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