summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Lail <lail@squareup.com>2022-03-02 09:15:35 -0600
committerBob Lail <lail@squareup.com>2022-03-04 16:46:08 -0600
commita24c285d219d2709b48b7d941e364770ddcc6846 (patch)
tree020dd29396d7849bb4e177bcd068247d55e08798
parent74919ef69344164bd55e2dfc7ee2a360b6c718c6 (diff)
downloadnet-ssh-a24c285d219d2709b48b7d941e364770ddcc6846.tar.gz
Support `~` in the path to the SSH agent's unix socket
-rw-r--r--lib/net/ssh/authentication/agent.rb4
-rw-r--r--test/authentication/test_agent.rb5
2 files changed, 7 insertions, 2 deletions
diff --git a/lib/net/ssh/authentication/agent.rb b/lib/net/ssh/authentication/agent.rb
index d6e5d9f..15c75ea 100644
--- a/lib/net/ssh/authentication/agent.rb
+++ b/lib/net/ssh/authentication/agent.rb
@@ -85,9 +85,9 @@ module Net
if agent_socket_factory
agent_socket_factory.call
elsif identity_agent
- unix_socket_class.open(identity_agent)
+ unix_socket_class.open(File.expand_path(identity_agent))
elsif ENV['SSH_AUTH_SOCK'] && unix_socket_class
- unix_socket_class.open(ENV['SSH_AUTH_SOCK'])
+ unix_socket_class.open(File.expand_path(ENV['SSH_AUTH_SOCK']))
elsif Gem.win_platform? && RUBY_ENGINE != "jruby"
Pageant::Socket.open
else
diff --git a/test/authentication/test_agent.rb b/test/authentication/test_agent.rb
index 81ca477..717550e 100644
--- a/test/authentication/test_agent.rb
+++ b/test/authentication/test_agent.rb
@@ -50,6 +50,11 @@ module Authentication
agent(false).connect!
end
+ def test_connect_should_expand_path_to_identity_agent
+ factory.expects(:open).with("#{Dir.home}/path/to/ssh.agent.sock").returns(socket)
+ agent(false).connect! nil, "~/path/to/ssh.agent.sock"
+ end
+
def test_connect_should_use_agent_socket_factory_instead_of_factory
assert_equal agent.connect!, socket
assert_equal agent.connect!(agent_socket_factory), "/foo/bar.sock"