Skip to content

Commit 25510e4

Browse files
committed
Respect the new interface defined by Net::SSH 3.1
1 parent 3f660a4 commit 25510e4

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

lib/sshkit/backends/netssh.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ def keys_for(hostlist)
3838
key_list = keys[host]
3939
return key_list if key_list
4040

41-
hashes.each do |(hmac, salt), key|
41+
hashes.each do |(hmac, salt), hash_keys|
4242
if OpenSSL::HMAC.digest(sha1, salt, host) == hmac
43-
return key
43+
return hash_keys
4444
end
4545
end
4646
end
@@ -132,9 +132,10 @@ def initialize
132132
end
133133

134134
def search_for(host, options = {})
135-
::Net::SSH::KnownHosts.hostfiles(options).map do |path|
135+
keys = ::Net::SSH::KnownHosts.hostfiles(options).map do |path|
136136
known_hosts_file(path).keys_for(host)
137137
end.flatten
138+
::Net::SSH::HostKeys.new(keys, host, self, options)
138139
end
139140

140141
def add(*args)
@@ -154,7 +155,7 @@ class Configuration
154155
attr_writer :ssh_options
155156

156157
def ssh_options
157-
@ssh_options ||= {known_hosts: KnownHosts.new}
158+
@ssh_options ||= {}
158159
end
159160
end
160161

test/unit/backends/test_netssh.rb

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,14 @@ def test_transfer_summarizer
5454
end
5555
end
5656

57-
def test_known_hosts_for_when_all_hosts_are_recognized
58-
perform_known_hosts_test("github")
59-
end
57+
if Net::SSH::Version::CURRENT >= Net::SSH::Version[3, 1, 0]
58+
def test_known_hosts_for_when_all_hosts_are_recognized
59+
perform_known_hosts_test("github")
60+
end
6061

61-
def test_known_hosts_for_when_an_host_hash_is_recognized
62-
perform_known_hosts_test("github_hash")
62+
def test_known_hosts_for_when_an_host_hash_is_recognized
63+
perform_known_hosts_test("github_hash")
64+
end
6365
end
6466

6567
private
@@ -68,8 +70,12 @@ def perform_known_hosts_test(hostfile)
6870
source = File.join(File.dirname(__FILE__), '../../known_hosts', hostfile)
6971
kh = Netssh::KnownHosts.new
7072
keys = kh.search_for('github.com', user_known_hosts_file: source, global_known_hosts_file: Tempfile.new('sshkit-test').path)
73+
74+
assert_instance_of ::Net::SSH::HostKeys, keys
7175
assert_equal(1, keys.count)
72-
assert_equal("ssh-rsa", keys[0].ssh_type)
76+
keys.each do |key|
77+
assert_equal("ssh-rsa", key.ssh_type)
78+
end
7379
end
7480
end
7581
end

0 commit comments

Comments
 (0)