File tree Expand file tree Collapse file tree 2 files changed +17
-10
lines changed Expand file tree Collapse file tree 2 files changed +17
-10
lines changed Original file line number Diff line number Diff line change @@ -38,9 +38,9 @@ def keys_for(hostlist)
38
38
key_list = keys [ host ]
39
39
return key_list if key_list
40
40
41
- hashes . each do |( hmac , salt ) , key |
41
+ hashes . each do |( hmac , salt ) , hash_keys |
42
42
if OpenSSL ::HMAC . digest ( sha1 , salt , host ) == hmac
43
- return key
43
+ return hash_keys
44
44
end
45
45
end
46
46
end
@@ -132,9 +132,10 @@ def initialize
132
132
end
133
133
134
134
def search_for ( host , options = { } )
135
- ::Net ::SSH ::KnownHosts . hostfiles ( options ) . map do |path |
135
+ keys = ::Net ::SSH ::KnownHosts . hostfiles ( options ) . map do |path |
136
136
known_hosts_file ( path ) . keys_for ( host )
137
137
end . flatten
138
+ ::Net ::SSH ::HostKeys . new ( keys , host , self , options )
138
139
end
139
140
140
141
def add ( *args )
@@ -154,7 +155,7 @@ class Configuration
154
155
attr_writer :ssh_options
155
156
156
157
def ssh_options
157
- @ssh_options ||= { known_hosts : KnownHosts . new }
158
+ @ssh_options ||= { }
158
159
end
159
160
end
160
161
Original file line number Diff line number Diff line change @@ -54,12 +54,14 @@ def test_transfer_summarizer
54
54
end
55
55
end
56
56
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
60
61
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
63
65
end
64
66
65
67
private
@@ -68,8 +70,12 @@ def perform_known_hosts_test(hostfile)
68
70
source = File . join ( File . dirname ( __FILE__ ) , '../../known_hosts' , hostfile )
69
71
kh = Netssh ::KnownHosts . new
70
72
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
71
75
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
73
79
end
74
80
end
75
81
end
You can’t perform that action at this time.
0 commit comments