diff options
| author | Mark Imbriaco <mark@imbriaco.com> | 2011-08-14 13:28:37 -0400 |
|---|---|---|
| committer | Mark Imbriaco <mark@imbriaco.com> | 2011-08-14 13:28:37 -0400 |
| commit | 9b80fd31762ab99fd5ff9fe3262f0665a040e2c9 (patch) | |
| tree | f99cf1e32bd78c1bec9531335eac91d5aab57679 /test | |
| parent | cbecc7c041f0c3778cb032fd71132ab94a76e0a9 (diff) | |
| download | net-ssh-9b80fd31762ab99fd5ff9fe3262f0665a040e2c9.tar.gz | |
Add a test and a couple of assertions for the UNIX socket local forwarding.
Diffstat (limited to 'test')
| -rw-r--r-- | test/manual/test_forward.rb | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/test/manual/test_forward.rb b/test/manual/test_forward.rb index 46ddb25..34758da 100644 --- a/test/manual/test_forward.rb +++ b/test/manual/test_forward.rb @@ -18,6 +18,7 @@ require 'common' require 'net/ssh/buffer' require 'net/ssh' require 'timeout' +require 'tempfile' class TestForward < Test::Unit::TestCase @@ -120,7 +121,44 @@ class TestForward < Test::Unit::TestCase session.loop(0.1) { client_done.empty? } assert_equal "Broken pipe", "#{server_exc.pop}" unless server_exc.empty? end + + def create_local_socket(&blk) + tempfile = Tempfile.new("net_ssh_forward_test") + path = tempfile.path + tempfile.delete + yield UNIXServer.open(path) + File.delete(path) + end + def test_forward_local_unix_socket_to_remote_port + session = Net::SSH.start(*ssh_start_params) + server_exc = Queue.new + server = start_server_sending_lot_of_data(server_exc) + remote_port = server.addr[1] + client_data = nil + + create_local_socket do |local_socket| + session.forward.local(local_socket, localhost, remote_port) + client_done = Queue.new + + Thread.start do + begin + client = UNIXSocket.new(local_socket.path) + client_data = client.recv(1024) + client.close + sleep(0.2) + ensure + client_done << true + end + end + + session.loop(0.1) { client_done.empty? } + end + + assert_not_nil(client_data, "client should have received data") + assert(client_data.match(/item\d/), 'client should have received the string item') + end + def test_loop_should_not_abort_when_server_side_of_forward_is_closed session = Net::SSH.start(*ssh_start_params) server = start_server_closing_soon @@ -182,4 +220,4 @@ class TestForward < Test::Unit::TestCase assert_equal "This is a small message!", client_done.pop end end -end
\ No newline at end of file +end |
