diff options
author | Miklós Fazekas <mfazekas@szemafor.com> | 2023-02-27 11:50:03 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-27 11:50:03 +0100 |
commit | 09f2c4067e0800213af877873ea5d6ac399cf732 (patch) | |
tree | 98656849c788b8e417525209aa13d8bdfc6a4815 | |
parent | c09ac4846eb48694ee6aa41d3798c056a28bc231 (diff) | |
parent | e570e277165ef5ffe2f6eac058629d33ae8a3f18 (diff) | |
download | net-ssh-09f2c4067e0800213af877873ea5d6ac399cf732.tar.gz |
Merge pull request #902 from net-ssh/mfazekas/add-test-for-conn-timeout
test: added integration test for connection timeout
-rw-r--r-- | test/integration/test_handshake_timeout.rb | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/test/integration/test_handshake_timeout.rb b/test/integration/test_handshake_timeout.rb new file mode 100644 index 0000000..c297377 --- /dev/null +++ b/test/integration/test_handshake_timeout.rb @@ -0,0 +1,32 @@ +require_relative 'common' +require 'net/ssh' + +class TestHandshakeTimeout < NetSSHTest + include IntegrationTestHelpers + + def with_non_responding_server(&block) + port = "4444" + pipe = IO.popen("/bin/nc -l -k -p #{port}") + begin + yield(port) + ensure + Process.kill("TERM", pipe.pid) + end + end + + def nc_port_open?(port) + Socket.tcp("localhost", port, connect_timeout: 1) { true } rescue false # rubocop:disable Style/RescueModifier + end + + def test_error_exitstatus + with_non_responding_server do |port| + sleep(0.1) until nc_port_open?(port.to_i) + + assert_raises(Net::SSH::ConnectionTimeout, 'timeout during server version negotiating') do + Net::SSH.start("localhost", "net_ssh_1", password: 'foopwd', port: port, timeout: 1) do |ssh| + ssh.exec! "exit 42" + end + end + end + end +end |