net-ssh 3.2.0 → 7.2.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (210) hide show
  1. checksums.yaml +5 -5
  2. checksums.yaml.gz.sig +0 -0
  3. data/.dockerignore +6 -0
  4. data/.github/FUNDING.yml +1 -0
  5. data/.github/config/rubocop_linter_action.yml +4 -0
  6. data/.github/workflows/ci-with-docker.yml +44 -0
  7. data/.github/workflows/ci.yml +93 -0
  8. data/.github/workflows/rubocop.yml +16 -0
  9. data/.gitignore +13 -0
  10. data/.rubocop.yml +22 -0
  11. data/.rubocop_todo.yml +1081 -0
  12. data/CHANGES.txt +237 -7
  13. data/DEVELOPMENT.md +23 -0
  14. data/Dockerfile +27 -0
  15. data/Dockerfile.openssl3 +17 -0
  16. data/Gemfile +13 -0
  17. data/Gemfile.noed25519 +12 -0
  18. data/Gemfile.norbnacl +12 -0
  19. data/ISSUE_TEMPLATE.md +30 -0
  20. data/Manifest +4 -5
  21. data/README.md +298 -0
  22. data/Rakefile +125 -74
  23. data/SECURITY.md +4 -0
  24. data/appveyor.yml +58 -0
  25. data/docker-compose.yml +23 -0
  26. data/lib/net/ssh/authentication/agent.rb +279 -18
  27. data/lib/net/ssh/authentication/certificate.rb +183 -0
  28. data/lib/net/ssh/authentication/constants.rb +17 -15
  29. data/lib/net/ssh/authentication/ed25519.rb +186 -0
  30. data/lib/net/ssh/authentication/ed25519_loader.rb +31 -0
  31. data/lib/net/ssh/authentication/key_manager.rb +86 -39
  32. data/lib/net/ssh/authentication/methods/abstract.rb +67 -48
  33. data/lib/net/ssh/authentication/methods/hostbased.rb +34 -37
  34. data/lib/net/ssh/authentication/methods/keyboard_interactive.rb +13 -13
  35. data/lib/net/ssh/authentication/methods/none.rb +16 -19
  36. data/lib/net/ssh/authentication/methods/password.rb +27 -17
  37. data/lib/net/ssh/authentication/methods/publickey.rb +96 -55
  38. data/lib/net/ssh/authentication/pageant.rb +471 -367
  39. data/lib/net/ssh/authentication/pub_key_fingerprint.rb +43 -0
  40. data/lib/net/ssh/authentication/session.rb +131 -121
  41. data/lib/net/ssh/buffer.rb +399 -300
  42. data/lib/net/ssh/buffered_io.rb +154 -150
  43. data/lib/net/ssh/config.rb +308 -185
  44. data/lib/net/ssh/connection/channel.rb +635 -613
  45. data/lib/net/ssh/connection/constants.rb +29 -29
  46. data/lib/net/ssh/connection/event_loop.rb +123 -0
  47. data/lib/net/ssh/connection/keepalive.rb +55 -51
  48. data/lib/net/ssh/connection/session.rb +620 -551
  49. data/lib/net/ssh/connection/term.rb +125 -123
  50. data/lib/net/ssh/errors.rb +101 -99
  51. data/lib/net/ssh/key_factory.rb +197 -105
  52. data/lib/net/ssh/known_hosts.rb +214 -127
  53. data/lib/net/ssh/loggable.rb +50 -49
  54. data/lib/net/ssh/packet.rb +83 -79
  55. data/lib/net/ssh/prompt.rb +50 -81
  56. data/lib/net/ssh/proxy/command.rb +105 -90
  57. data/lib/net/ssh/proxy/errors.rb +12 -10
  58. data/lib/net/ssh/proxy/http.rb +82 -79
  59. data/lib/net/ssh/proxy/https.rb +50 -0
  60. data/lib/net/ssh/proxy/jump.rb +54 -0
  61. data/lib/net/ssh/proxy/socks4.rb +2 -6
  62. data/lib/net/ssh/proxy/socks5.rb +14 -17
  63. data/lib/net/ssh/service/forward.rb +370 -317
  64. data/lib/net/ssh/test/channel.rb +145 -136
  65. data/lib/net/ssh/test/extensions.rb +131 -110
  66. data/lib/net/ssh/test/kex.rb +34 -32
  67. data/lib/net/ssh/test/local_packet.rb +46 -44
  68. data/lib/net/ssh/test/packet.rb +89 -70
  69. data/lib/net/ssh/test/remote_packet.rb +32 -30
  70. data/lib/net/ssh/test/script.rb +156 -142
  71. data/lib/net/ssh/test/socket.rb +49 -48
  72. data/lib/net/ssh/test.rb +82 -77
  73. data/lib/net/ssh/transport/algorithms.rb +462 -359
  74. data/lib/net/ssh/transport/chacha20_poly1305_cipher.rb +117 -0
  75. data/lib/net/ssh/transport/chacha20_poly1305_cipher_loader.rb +17 -0
  76. data/lib/net/ssh/transport/cipher_factory.rb +122 -99
  77. data/lib/net/ssh/transport/constants.rb +32 -24
  78. data/lib/net/ssh/transport/ctr.rb +42 -22
  79. data/lib/net/ssh/transport/hmac/abstract.rb +81 -63
  80. data/lib/net/ssh/transport/hmac/md5.rb +0 -2
  81. data/lib/net/ssh/transport/hmac/md5_96.rb +0 -2
  82. data/lib/net/ssh/transport/hmac/none.rb +0 -2
  83. data/lib/net/ssh/transport/hmac/ripemd160.rb +0 -2
  84. data/lib/net/ssh/transport/hmac/sha1.rb +0 -2
  85. data/lib/net/ssh/transport/hmac/sha1_96.rb +0 -2
  86. data/lib/net/ssh/transport/hmac/sha2_256.rb +7 -11
  87. data/lib/net/ssh/transport/hmac/sha2_256_96.rb +4 -8
  88. data/lib/net/ssh/transport/hmac/sha2_256_etm.rb +12 -0
  89. data/lib/net/ssh/transport/hmac/sha2_512.rb +6 -9
  90. data/lib/net/ssh/transport/hmac/sha2_512_96.rb +4 -8
  91. data/lib/net/ssh/transport/hmac/sha2_512_etm.rb +12 -0
  92. data/lib/net/ssh/transport/hmac.rb +14 -12
  93. data/lib/net/ssh/transport/identity_cipher.rb +54 -44
  94. data/lib/net/ssh/transport/kex/abstract.rb +130 -0
  95. data/lib/net/ssh/transport/kex/abstract5656.rb +72 -0
  96. data/lib/net/ssh/transport/kex/curve25519_sha256.rb +39 -0
  97. data/lib/net/ssh/transport/kex/curve25519_sha256_loader.rb +30 -0
  98. data/lib/net/ssh/transport/kex/diffie_hellman_group14_sha1.rb +33 -40
  99. data/lib/net/ssh/transport/kex/diffie_hellman_group14_sha256.rb +11 -0
  100. data/lib/net/ssh/transport/kex/diffie_hellman_group1_sha1.rb +119 -213
  101. data/lib/net/ssh/transport/kex/diffie_hellman_group_exchange_sha1.rb +53 -61
  102. data/lib/net/ssh/transport/kex/diffie_hellman_group_exchange_sha256.rb +5 -9
  103. data/lib/net/ssh/transport/kex/ecdh_sha2_nistp256.rb +36 -90
  104. data/lib/net/ssh/transport/kex/ecdh_sha2_nistp384.rb +18 -10
  105. data/lib/net/ssh/transport/kex/ecdh_sha2_nistp521.rb +18 -10
  106. data/lib/net/ssh/transport/kex.rb +15 -12
  107. data/lib/net/ssh/transport/key_expander.rb +24 -20
  108. data/lib/net/ssh/transport/openssl.rb +161 -124
  109. data/lib/net/ssh/transport/openssl_cipher_extensions.rb +8 -0
  110. data/lib/net/ssh/transport/packet_stream.rb +246 -185
  111. data/lib/net/ssh/transport/server_version.rb +55 -56
  112. data/lib/net/ssh/transport/session.rb +306 -255
  113. data/lib/net/ssh/transport/state.rb +178 -176
  114. data/lib/net/ssh/verifiers/accept_new.rb +33 -0
  115. data/lib/net/ssh/verifiers/accept_new_or_local_tunnel.rb +33 -0
  116. data/lib/net/ssh/verifiers/always.rb +58 -0
  117. data/lib/net/ssh/verifiers/never.rb +19 -0
  118. data/lib/net/ssh/version.rb +55 -53
  119. data/lib/net/ssh.rb +111 -47
  120. data/net-ssh-public_cert.pem +18 -18
  121. data/net-ssh.gemspec +38 -205
  122. data/support/ssh_tunnel_bug.rb +5 -5
  123. data.tar.gz.sig +0 -0
  124. metadata +173 -118
  125. metadata.gz.sig +0 -0
  126. data/.travis.yml +0 -18
  127. data/README.rdoc +0 -182
  128. data/lib/net/ssh/authentication/agent/java_pageant.rb +0 -85
  129. data/lib/net/ssh/authentication/agent/socket.rb +0 -178
  130. data/lib/net/ssh/ruby_compat.rb +0 -46
  131. data/lib/net/ssh/verifiers/lenient.rb +0 -30
  132. data/lib/net/ssh/verifiers/null.rb +0 -12
  133. data/lib/net/ssh/verifiers/secure.rb +0 -52
  134. data/lib/net/ssh/verifiers/strict.rb +0 -24
  135. data/setup.rb +0 -1585
  136. data/support/arcfour_check.rb +0 -20
  137. data/test/README.txt +0 -18
  138. data/test/authentication/methods/common.rb +0 -28
  139. data/test/authentication/methods/test_abstract.rb +0 -51
  140. data/test/authentication/methods/test_hostbased.rb +0 -114
  141. data/test/authentication/methods/test_keyboard_interactive.rb +0 -121
  142. data/test/authentication/methods/test_none.rb +0 -41
  143. data/test/authentication/methods/test_password.rb +0 -95
  144. data/test/authentication/methods/test_publickey.rb +0 -148
  145. data/test/authentication/test_agent.rb +0 -232
  146. data/test/authentication/test_key_manager.rb +0 -240
  147. data/test/authentication/test_session.rb +0 -107
  148. data/test/common.rb +0 -125
  149. data/test/configs/auth_off +0 -5
  150. data/test/configs/auth_on +0 -4
  151. data/test/configs/empty +0 -0
  152. data/test/configs/eqsign +0 -3
  153. data/test/configs/exact_match +0 -8
  154. data/test/configs/host_plus +0 -10
  155. data/test/configs/multihost +0 -4
  156. data/test/configs/negative_match +0 -6
  157. data/test/configs/nohost +0 -19
  158. data/test/configs/numeric_host +0 -4
  159. data/test/configs/proxy_remote_user +0 -2
  160. data/test/configs/send_env +0 -2
  161. data/test/configs/substitutes +0 -8
  162. data/test/configs/wild_cards +0 -14
  163. data/test/connection/test_channel.rb +0 -487
  164. data/test/connection/test_session.rb +0 -564
  165. data/test/integration/README.txt +0 -17
  166. data/test/integration/Vagrantfile +0 -12
  167. data/test/integration/common.rb +0 -63
  168. data/test/integration/playbook.yml +0 -56
  169. data/test/integration/test_forward.rb +0 -637
  170. data/test/integration/test_id_rsa_keys.rb +0 -96
  171. data/test/integration/test_proxy.rb +0 -93
  172. data/test/known_hosts/github +0 -1
  173. data/test/known_hosts/github_hash +0 -1
  174. data/test/manual/test_pageant.rb +0 -37
  175. data/test/start/test_connection.rb +0 -53
  176. data/test/start/test_options.rb +0 -57
  177. data/test/start/test_transport.rb +0 -28
  178. data/test/start/test_user_nil.rb +0 -27
  179. data/test/test_all.rb +0 -12
  180. data/test/test_buffer.rb +0 -433
  181. data/test/test_buffered_io.rb +0 -63
  182. data/test/test_config.rb +0 -268
  183. data/test/test_key_factory.rb +0 -191
  184. data/test/test_known_hosts.rb +0 -66
  185. data/test/transport/hmac/test_md5.rb +0 -41
  186. data/test/transport/hmac/test_md5_96.rb +0 -27
  187. data/test/transport/hmac/test_none.rb +0 -34
  188. data/test/transport/hmac/test_ripemd160.rb +0 -36
  189. data/test/transport/hmac/test_sha1.rb +0 -36
  190. data/test/transport/hmac/test_sha1_96.rb +0 -27
  191. data/test/transport/hmac/test_sha2_256.rb +0 -37
  192. data/test/transport/hmac/test_sha2_256_96.rb +0 -27
  193. data/test/transport/hmac/test_sha2_512.rb +0 -37
  194. data/test/transport/hmac/test_sha2_512_96.rb +0 -27
  195. data/test/transport/kex/test_diffie_hellman_group14_sha1.rb +0 -13
  196. data/test/transport/kex/test_diffie_hellman_group1_sha1.rb +0 -150
  197. data/test/transport/kex/test_diffie_hellman_group_exchange_sha1.rb +0 -96
  198. data/test/transport/kex/test_diffie_hellman_group_exchange_sha256.rb +0 -19
  199. data/test/transport/kex/test_ecdh_sha2_nistp256.rb +0 -161
  200. data/test/transport/kex/test_ecdh_sha2_nistp384.rb +0 -38
  201. data/test/transport/kex/test_ecdh_sha2_nistp521.rb +0 -38
  202. data/test/transport/test_algorithms.rb +0 -328
  203. data/test/transport/test_cipher_factory.rb +0 -443
  204. data/test/transport/test_hmac.rb +0 -34
  205. data/test/transport/test_identity_cipher.rb +0 -40
  206. data/test/transport/test_packet_stream.rb +0 -1762
  207. data/test/transport/test_server_version.rb +0 -74
  208. data/test/transport/test_session.rb +0 -331
  209. data/test/transport/test_state.rb +0 -181
  210. data/test/verifiers/test_secure.rb +0 -40
@@ -1,74 +0,0 @@
1
- require 'common'
2
- require 'net/ssh/transport/server_version'
3
-
4
- module Transport
5
-
6
- class TestServerVersion < Test::Unit::TestCase
7
-
8
- def test_1_99_server_version_should_be_acceptible
9
- s = subject(socket(true, "SSH-1.99-Testing_1.0\r\n"))
10
- assert s.header.empty?
11
- assert_equal "SSH-1.99-Testing_1.0", s.version
12
- end
13
-
14
- def test_2_0_server_version_should_be_acceptible
15
- s = subject(socket(true, "SSH-2.0-Testing_1.0\r\n"))
16
- assert s.header.empty?
17
- assert_equal "SSH-2.0-Testing_1.0", s.version
18
- end
19
-
20
- def test_trailing_whitespace_should_be_preserved
21
- # some servers, like Mocana, send a version string with trailing
22
- # spaces, which are significant when exchanging keys later.
23
- s = subject(socket(true, "SSH-2.0-Testing_1.0 \r\n"))
24
- assert_equal "SSH-2.0-Testing_1.0 ", s.version
25
- end
26
-
27
- def test_unacceptible_server_version_should_raise_exception
28
- assert_raises(Net::SSH::Exception) { subject(socket(false, "SSH-1.4-Testing_1.0\r\n")) }
29
- end
30
-
31
- def test_unexpected_server_close_should_raise_exception
32
- assert_raises(Net::SSH::Disconnect) { subject(socket(false, "\r\nDestination server does not have Ssh activated.\r\nContact Cisco Systems, Inc to purchase a\r\nlicense key to activate Ssh.\r\n", true)) }
33
- end
34
-
35
- def test_header_lines_should_be_accumulated
36
- s = subject(socket(true, "Welcome\r\nAnother line\r\nSSH-2.0-Testing_1.0\r\n"))
37
- assert_equal "Welcome\r\nAnother line\r\n", s.header
38
- assert_equal "SSH-2.0-Testing_1.0", s.version
39
- end
40
-
41
- def test_server_disconnect_should_raise_exception
42
- assert_raises(Net::SSH::Disconnect) { subject(socket(false, "SSH-2.0-Aborting")) }
43
- end
44
-
45
- private
46
-
47
- def socket(good, version_header, raise_eot=false)
48
- socket = mock("socket")
49
-
50
- socket.expects(:write).with("#{Net::SSH::Transport::ServerVersion::PROTO_VERSION}\r\n")
51
- socket.expects(:flush)
52
-
53
- data = version_header.split('')
54
- recv_times = data.length
55
- recv_times += 1 if data[-1] != "\n"
56
-
57
- unless raise_eot
58
-
59
- # socket.expects(:recv).with(1).times(recv_times).returns(*data).then.returns(nil)
60
- # socket.expects(:readchar).times(recv_times).returns(*data).then.returns(nil)
61
- socket.expects(:readpartial).with(1).times(recv_times).returns(*data).then.returns(nil)
62
- else
63
- socket.expects(:readpartial).with(1).times(recv_times+1).returns(*data).then.raises(EOFError, "end of file reached")
64
- end
65
-
66
- socket
67
- end
68
-
69
- def subject(socket)
70
- Net::SSH::Transport::ServerVersion.new(socket, nil)
71
- end
72
- end
73
-
74
- end
@@ -1,331 +0,0 @@
1
- require 'common'
2
- require 'net/ssh/transport/session'
3
-
4
- # mocha adds #verify to Object, which throws off the host-key-verifier part of
5
- # these tests.
6
-
7
- # can't use .include? because ruby18 uses strings and ruby19 uses symbols :/
8
- if Object.instance_methods.any? { |v| v.to_sym == :verify }
9
- Object.send(:undef_method, :verify)
10
- end
11
-
12
- module Transport
13
-
14
- class TestSession < Test::Unit::TestCase
15
- include Net::SSH::Transport::Constants
16
-
17
- def test_constructor_defaults
18
- assert_equal "net.ssh.test", session.host
19
- assert_equal 22, session.port
20
- assert_instance_of Net::SSH::Verifiers::Lenient, session.host_key_verifier
21
- end
22
-
23
- def test_paranoid_true_uses_lenient_verifier
24
- assert_instance_of Net::SSH::Verifiers::Lenient, session(:paranoid => true).host_key_verifier
25
- end
26
-
27
- def test_paranoid_very_uses_strict_verifier
28
- assert_instance_of Net::SSH::Verifiers::Strict, session(:paranoid => :very).host_key_verifier
29
- end
30
-
31
- def test_paranoid_secure_uses_secure_verifier
32
- assert_instance_of Net::SSH::Verifiers::Secure, session(:paranoid => :secure).host_key_verifier
33
- end
34
-
35
- def test_paranoid_false_uses_null_verifier
36
- assert_instance_of Net::SSH::Verifiers::Null, session(:paranoid => false).host_key_verifier
37
- end
38
-
39
- def test_unknown_paranoid_value_raises_exception_if_value_does_not_respond_to_verify
40
- assert_raises(ArgumentError) { session(:paranoid => :bogus).host_key_verifier }
41
- end
42
-
43
- def test_paranoid_value_responding_to_verify_should_pass_muster
44
- object = stub("thingy", :verify => true)
45
- assert_equal object, session(:paranoid => object).host_key_verifier
46
- end
47
-
48
- def test_host_as_string_should_return_host_and_ip_when_port_is_default
49
- session!
50
- socket.stubs(:peer_ip).returns("1.2.3.4")
51
- assert_equal "net.ssh.test,1.2.3.4", session.host_as_string
52
- end
53
-
54
- def test_host_as_string_should_return_host_and_ip_with_port_when_port_is_not_default
55
- session(:port => 1234) # force session to be instantiated
56
- socket.stubs(:peer_ip).returns("1.2.3.4")
57
- assert_equal "[net.ssh.test]:1234,[1.2.3.4]:1234", session.host_as_string
58
- end
59
-
60
- def test_host_as_string_should_return_only_host_when_host_is_ip
61
- session!(:host => "1.2.3.4")
62
- socket.stubs(:peer_ip).returns("1.2.3.4")
63
- assert_equal "1.2.3.4", session.host_as_string
64
- end
65
-
66
- def test_host_as_string_should_return_only_host_and_port_when_host_is_ip_and_port_is_not_default
67
- session!(:host => "1.2.3.4", :port => 1234)
68
- socket.stubs(:peer_ip).returns("1.2.3.4")
69
- assert_equal "[1.2.3.4]:1234", session.host_as_string
70
- end
71
-
72
- def test_host_as_string_should_return_only_host_when_proxy_command_is_set
73
- session!(:host => "1.2.3.4")
74
- socket.stubs(:peer_ip).returns(Net::SSH::Transport::PacketStream::PROXY_COMMAND_HOST_IP)
75
- assert_equal "1.2.3.4", session.host_as_string
76
- end
77
-
78
- def test_host_as_string_should_return_only_host_and_port_when_host_is_ip_and_port_is_not_default_and_proxy_command_is_set
79
- session!(:host => "1.2.3.4", :port => 1234)
80
- socket.stubs(:peer_ip).returns(Net::SSH::Transport::PacketStream::PROXY_COMMAND_HOST_IP)
81
- assert_equal "[1.2.3.4]:1234", session.host_as_string
82
- end
83
-
84
- def test_close_should_cleanup_and_close_socket
85
- session!
86
- socket.expects(:cleanup)
87
- socket.expects(:close)
88
- session.close
89
- end
90
-
91
- def test_service_request_should_return_buffer
92
- assert_equal "\005\000\000\000\004sftp", session.service_request('sftp').to_s
93
- end
94
-
95
- def test_rekey_when_kex_is_pending_should_do_nothing
96
- algorithms.stubs(:pending? => true)
97
- algorithms.expects(:rekey!).never
98
- session.rekey!
99
- end
100
-
101
- def test_rekey_when_no_kex_is_pending_should_initiate_rekey_and_block_until_it_completes
102
- algorithms.stubs(:pending? => false)
103
- algorithms.expects(:rekey!)
104
- session.expects(:wait).yields
105
- algorithms.expects(:initialized?).returns(true)
106
- session.rekey!
107
- end
108
-
109
- def test_rekey_as_needed_when_kex_is_pending_should_do_nothing
110
- session!
111
- algorithms.stubs(:pending? => true)
112
- socket.expects(:if_needs_rekey?).never
113
- session.rekey_as_needed
114
- end
115
-
116
- def test_rekey_as_needed_when_no_kex_is_pending_and_no_rekey_is_needed_should_do_nothing
117
- session!
118
- algorithms.stubs(:pending? => false)
119
- socket.stubs(:if_needs_rekey? => false)
120
- session.expects(:rekey!).never
121
- session.rekey_as_needed
122
- end
123
-
124
- def test_rekey_as_needed_when_no_kex_is_pending_and_rekey_is_needed_should_initiate_rekey_and_block
125
- session!
126
- algorithms.stubs(:pending? => false)
127
- socket.expects(:if_needs_rekey?).yields
128
- session.expects(:rekey!)
129
- session.rekey_as_needed
130
- end
131
-
132
- def test_peer_should_return_hash_of_info_about_peer
133
- session!
134
- socket.stubs(:peer_ip => "1.2.3.4")
135
- assert_equal({:ip => "1.2.3.4", :port => 22, :host => "net.ssh.test", :canonized => "net.ssh.test,1.2.3.4"}, session.peer)
136
- end
137
-
138
- def test_next_message_should_block_until_next_message_is_available
139
- session.expects(:poll_message).with(:block)
140
- session.next_message
141
- end
142
-
143
- def test_poll_message_should_query_next_packet_using_the_given_blocking_parameter
144
- session!
145
- socket.expects(:next_packet).with(:blocking_parameter).returns(nil)
146
- session.poll_message(:blocking_parameter)
147
- end
148
-
149
- def test_poll_message_should_default_to_non_blocking
150
- session!
151
- socket.expects(:next_packet).with(:nonblock).returns(nil)
152
- session.poll_message
153
- end
154
-
155
- def test_poll_message_should_silently_handle_disconnect_packets
156
- session!
157
- socket.expects(:next_packet).returns(P(:byte, DISCONNECT, :long, 1, :string, "testing", :string, ""))
158
- assert_raises(Net::SSH::Disconnect) { session.poll_message }
159
- end
160
-
161
- def test_poll_message_should_silently_handle_ignore_packets
162
- session!
163
- socket.expects(:next_packet).times(2).returns(P(:byte, IGNORE, :string, "test"), nil)
164
- assert_nil session.poll_message
165
- end
166
-
167
- def test_poll_message_should_silently_handle_unimplemented_packets
168
- session!
169
- socket.expects(:next_packet).times(2).returns(P(:byte, UNIMPLEMENTED, :long, 15), nil)
170
- assert_nil session.poll_message
171
- end
172
-
173
- def test_poll_message_should_silently_handle_debug_packets_with_always_display
174
- session!
175
- socket.expects(:next_packet).times(2).returns(P(:byte, DEBUG, :bool, true, :string, "testing", :string, ""), nil)
176
- assert_nil session.poll_message
177
- end
178
-
179
- def test_poll_message_should_silently_handle_debug_packets_without_always_display
180
- session!
181
- socket.expects(:next_packet).times(2).returns(P(:byte, DEBUG, :bool, false, :string, "testing", :string, ""), nil)
182
- assert_nil session.poll_message
183
- end
184
-
185
- def test_poll_message_should_silently_handle_kexinit_packets
186
- session!
187
- packet = P(:byte, KEXINIT, :raw, "lasdfalksdjfa;slkdfja;slkfjsdfaklsjdfa;df")
188
- socket.expects(:next_packet).times(2).returns(packet, nil)
189
- algorithms.expects(:accept_kexinit).with(packet)
190
- assert_nil session.poll_message
191
- end
192
-
193
- def test_poll_message_should_return_other_packets
194
- session!
195
- packet = P(:byte, SERVICE_ACCEPT, :string, "test")
196
- socket.expects(:next_packet).returns(packet)
197
- assert_equal packet, session.poll_message
198
- end
199
-
200
- def test_poll_message_should_enqueue_packets_when_algorithm_disallows_packet
201
- session!
202
- packet = P(:byte, SERVICE_ACCEPT, :string, "test")
203
- algorithms.stubs(:allow?).with(packet).returns(false)
204
- socket.expects(:next_packet).times(2).returns(packet, nil)
205
- assert_nil session.poll_message
206
- assert_equal [packet], session.queue
207
- end
208
-
209
- def test_poll_message_should_read_from_queue_when_next_in_queue_is_allowed_and_consume_queue_is_true
210
- session!
211
- packet = P(:byte, SERVICE_ACCEPT, :string, "test")
212
- session.push(packet)
213
- socket.expects(:next_packet).never
214
- assert_equal packet, session.poll_message
215
- assert session.queue.empty?
216
- end
217
-
218
- def test_poll_message_should_not_read_from_queue_when_next_in_queue_is_not_allowed
219
- session!
220
- packet = P(:byte, SERVICE_ACCEPT, :string, "test")
221
- algorithms.stubs(:allow?).with(packet).returns(false)
222
- session.push(packet)
223
- socket.expects(:next_packet).returns(nil)
224
- assert_nil session.poll_message
225
- assert_equal [packet], session.queue
226
- end
227
-
228
- def test_poll_message_should_not_read_from_queue_when_consume_queue_is_false
229
- session!
230
- packet = P(:byte, SERVICE_ACCEPT, :string, "test")
231
- session.push(packet)
232
- socket.expects(:next_packet).returns(nil)
233
- assert_nil session.poll_message(:nonblock, false)
234
- assert_equal [packet], session.queue
235
- end
236
-
237
- def test_wait_with_block_should_return_immediately_if_block_returns_truth
238
- session.expects(:poll_message).never
239
- session.wait { true }
240
- end
241
-
242
- def test_wait_should_not_consume_queue_on_reads
243
- n = 0
244
- session.expects(:poll_message).with(:nonblock, false).returns(nil)
245
- session.wait { (n += 1) > 1 }
246
- end
247
-
248
- def test_wait_without_block_should_return_after_first_read
249
- session.expects(:poll_message).returns(nil)
250
- session.wait
251
- end
252
-
253
- def test_wait_should_enqueue_packets
254
- session!
255
-
256
- p1 = P(:byte, SERVICE_REQUEST, :string, "test")
257
- p2 = P(:byte, SERVICE_ACCEPT, :string, "test")
258
- socket.expects(:next_packet).times(2).returns(p1, p2)
259
-
260
- n = 0
261
- session.wait { (n += 1) > 2 }
262
- assert_equal [p1, p2], session.queue
263
- end
264
-
265
- def test_push_should_enqueue_packet
266
- packet = P(:byte, SERVICE_ACCEPT, :string, "test")
267
- session.push(packet)
268
- assert_equal [packet], session.queue
269
- end
270
-
271
- def test_send_message_should_delegate_to_socket
272
- session!
273
- packet = P(:byte, SERVICE_ACCEPT, :string, "test")
274
- socket.expects(:send_packet).with(packet)
275
- session.send_message(packet)
276
- end
277
-
278
- def test_enqueue_message_should_delegate_to_socket
279
- session!
280
- packet = P(:byte, SERVICE_ACCEPT, :string, "test")
281
- socket.expects(:enqueue_packet).with(packet)
282
- session.enqueue_message(packet)
283
- end
284
-
285
- def test_configure_client_should_pass_options_to_socket_client_state
286
- session.configure_client :compression => :standard
287
- assert_equal :standard, socket.client.compression
288
- end
289
-
290
- def test_configure_server_should_pass_options_to_socket_server_state
291
- session.configure_server :compression => :standard
292
- assert_equal :standard, socket.server.compression
293
- end
294
-
295
- def test_hint_should_set_hint_on_socket
296
- assert !socket.hints[:authenticated]
297
- session.hint :authenticated
298
- assert socket.hints[:authenticated]
299
- end
300
-
301
- private
302
-
303
- def socket
304
- @socket ||= stub("socket", :hints => {})
305
- end
306
-
307
- def server_version
308
- @server_version ||= stub("server_version")
309
- end
310
-
311
- def algorithms
312
- @algorithms ||= stub("algorithms", :initialized? => true, :allow? => true, :start => true)
313
- end
314
-
315
- def session(options={})
316
- @session ||= begin
317
- host = options.delete(:host) || "net.ssh.test"
318
- Socket.stubs(:tcp).with(host, options[:port] || 22, nil, nil, { connect_timeout: options[:timeout] }).returns(socket)
319
- Net::SSH::Transport::ServerVersion.stubs(:new).returns(server_version)
320
- Net::SSH::Transport::Algorithms.stubs(:new).returns(algorithms)
321
-
322
- Net::SSH::Transport::Session.new(host, options)
323
- end
324
- end
325
-
326
- # a simple alias to make the tests more self-documenting. the bang
327
- # version makes it look more like the session is being instantiated
328
- alias session! session
329
- end
330
-
331
- end
@@ -1,181 +0,0 @@
1
- # encoding: ASCII-8BIT
2
-
3
- require 'common'
4
- require 'net/ssh/transport/state'
5
-
6
- module Transport
7
-
8
- class TestState < Test::Unit::TestCase
9
-
10
- def setup
11
- @socket = @state = @deflater = @inflater = nil
12
- end
13
-
14
- def teardown
15
- if @deflater
16
- @deflater.finish if !@deflater.finished?
17
- @deflater.close
18
- end
19
-
20
- if @inflater
21
- @inflater.finish if !@inflater.finished?
22
- @inflater.close
23
- end
24
-
25
- state.cleanup
26
- end
27
-
28
- def test_constructor_should_initialize_all_values
29
- assert_equal 0, state.sequence_number
30
- assert_equal 0, state.packets
31
- assert_equal 0, state.blocks
32
-
33
- assert_nil state.compression
34
- assert_nil state.compression_level
35
- assert_nil state.max_packets
36
- assert_nil state.max_blocks
37
- assert_nil state.rekey_limit
38
-
39
- assert_equal "identity", state.cipher.name
40
- assert_instance_of Net::SSH::Transport::HMAC::None, state.hmac
41
- end
42
-
43
- def test_increment_should_increment_counters
44
- state.increment(24)
45
- assert_equal 1, state.sequence_number
46
- assert_equal 1, state.packets
47
- assert_equal 3, state.blocks
48
- end
49
-
50
- def test_reset_should_reset_counters_and_fix_defaults_for_maximums
51
- state.increment(24)
52
- state.reset!
53
- assert_equal 1, state.sequence_number
54
- assert_equal 0, state.packets
55
- assert_equal 0, state.blocks
56
- assert_equal 2147483648, state.max_packets
57
- assert_equal 134217728, state.max_blocks
58
- end
59
-
60
- def test_set_should_set_variables_and_reset_counters
61
- state.expects(:reset!)
62
- state.set :cipher => :a, :hmac => :b, :compression => :c,
63
- :compression_level => :d, :max_packets => 500, :max_blocks => 1000,
64
- :rekey_limit => 1500
65
- assert_equal :a, state.cipher
66
- assert_equal :b, state.hmac
67
- assert_equal :c, state.compression
68
- assert_equal :d, state.compression_level
69
- assert_equal 500, state.max_packets
70
- assert_equal 1000, state.max_blocks
71
- assert_equal 1500, state.rekey_limit
72
- end
73
-
74
- def test_set_with_max_packets_should_respect_max_packets_setting
75
- state.set :max_packets => 500
76
- assert_equal 500, state.max_packets
77
- end
78
-
79
- def test_set_with_max_blocks_should_respect_max_blocks_setting
80
- state.set :max_blocks => 1000
81
- assert_equal 1000, state.max_blocks
82
- end
83
-
84
- def test_set_with_rekey_limit_should_include_rekey_limit_in_computation_of_max_blocks
85
- state.set :rekey_limit => 4000
86
- assert_equal 500, state.max_blocks
87
- end
88
-
89
- def test_compressor_defaults_to_default_zlib_compression
90
- expect = deflater.deflate("hello world")
91
- assert_equal expect, state.compressor.deflate("hello world")
92
- end
93
-
94
- def test_compressor_uses_compression_level_when_given
95
- state.set :compression_level => 1
96
- expect = deflater(1).deflate("hello world")
97
- assert_equal expect, state.compressor.deflate("hello world")
98
- end
99
-
100
- def test_compress_when_no_compression_is_active_returns_text
101
- assert_equal "hello everybody", state.compress("hello everybody")
102
- end
103
-
104
- def test_decompress_when_no_compression_is_active_returns_text
105
- assert_equal "hello everybody", state.decompress("hello everybody")
106
- end
107
-
108
- def test_compress_when_compression_is_delayed_and_no_auth_hint_is_set_should_return_text
109
- state.set :compression => :delayed
110
- assert_equal "hello everybody", state.compress("hello everybody")
111
- end
112
-
113
- def test_decompress_when_compression_is_delayed_and_no_auth_hint_is_set_should_return_text
114
- state.set :compression => :delayed
115
- assert_equal "hello everybody", state.decompress("hello everybody")
116
- end
117
-
118
- def test_compress_when_compression_is_enabled_should_return_compressed_text
119
- state.set :compression => :standard
120
- # JRuby Zlib implementation (1.4 & 1.5) does not have byte-to-byte compatibility with MRI's.
121
- # skip this test under JRuby.
122
- return if defined?(JRUBY_VERSION)
123
- assert_equal "x\234\312H\315\311\311WH-K-\252L\312O\251\004\000\000\000\377\377", state.compress("hello everybody")
124
- end
125
-
126
- def test_decompress_when_compression_is_enabled_should_return_decompressed_text
127
- state.set :compression => :standard
128
- # JRuby Zlib implementation (1.4 & 1.5) does not have byte-to-byte compatibility with MRI's.
129
- # skip this test under JRuby.
130
- return if defined?(JRUBY_VERSION)
131
- assert_equal "hello everybody", state.decompress("x\234\312H\315\311\311WH-K-\252L\312O\251\004\000\000\000\377\377")
132
- end
133
-
134
- def test_compress_when_compression_is_delayed_and_auth_hint_is_set_should_return_compressed_text
135
- socket.hints[:authenticated] = true
136
- state.set :compression => :delayed
137
- assert_equal "x\234\312H\315\311\311WH-K-\252L\312O\251\004\000\000\000\377\377", state.compress("hello everybody")
138
- end
139
-
140
- def test_decompress_when_compression_is_delayed_and_auth_hint_is_set_should_return_decompressed_text
141
- socket.hints[:authenticated] = true
142
- state.set :compression => :delayed
143
- assert_equal "hello everybody", state.decompress("x\234\312H\315\311\311WH-K-\252L\312O\251\004\000\000\000\377\377")
144
- end
145
-
146
- def test_needs_rekey_should_be_true_if_packets_exceeds_max_packets
147
- state.set :max_packets => 2
148
- state.increment(8)
149
- state.increment(8)
150
- assert !state.needs_rekey?
151
- state.increment(8)
152
- assert state.needs_rekey?
153
- end
154
-
155
- def test_needs_rekey_should_be_true_if_blocks_exceeds_max_blocks
156
- state.set :max_blocks => 10
157
- assert !state.needs_rekey?
158
- state.increment(88)
159
- assert state.needs_rekey?
160
- end
161
-
162
- private
163
-
164
- def deflater(level=Zlib::DEFAULT_COMPRESSION)
165
- @deflater ||= Zlib::Deflate.new(level)
166
- end
167
-
168
- def inflater
169
- @inflater ||= Zlib::Inflate.new(nil)
170
- end
171
-
172
- def socket
173
- @socket ||= stub("socket", :hints => {})
174
- end
175
-
176
- def state
177
- @state ||= Net::SSH::Transport::State.new(socket, :test)
178
- end
179
- end
180
-
181
- end
@@ -1,40 +0,0 @@
1
- require 'common'
2
- require 'net/ssh/verifiers/secure'
3
- require 'ostruct'
4
-
5
- class TestSecure < Test::Unit::TestCase
6
- def test_raises_unknown_key_error_if_empty
7
- secure_verifier = Net::SSH::Verifiers::Secure.new
8
- host_keys = []
9
- def host_keys.host
10
- 'foo'
11
- end
12
- assert_raises(Net::SSH::HostKeyUnknown) {
13
- secure_verifier.verify(session:OpenStruct.new(host_keys:host_keys))
14
- }
15
- end
16
-
17
- def test_passess_if_sam
18
- secure_verifier = Net::SSH::Verifiers::Secure.new
19
- key = OpenStruct.new(ssh_type:'key_type',to_blob:'keyblob')
20
- host_keys = [key]
21
- def host_keys.host
22
- 'foo'
23
- end
24
- secure_verifier.verify(session:OpenStruct.new(host_keys:host_keys), key:key)
25
- end
26
-
27
- def test_raises_mismatch_error_if_not_the_same
28
- secure_verifier = Net::SSH::Verifiers::Secure.new
29
- key_in_known_hosts = OpenStruct.new(ssh_type:'key_type',to_blob:'keyblob')
30
- key_actual = OpenStruct.new(ssh_type:'key_type',to_blob:'not keyblob')
31
-
32
- host_keys = [key_in_known_hosts]
33
- def host_keys.host
34
- 'foo'
35
- end
36
- assert_raises(Net::SSH::HostKeyMismatch) {
37
- secure_verifier.verify(session:OpenStruct.new(host_keys:host_keys), key:key_actual)
38
- }
39
- end
40
- end