diff options
| -rw-r--r-- | CHANGELOG.rdoc | 14 | ||||
| -rw-r--r-- | Rakefile | 10 | ||||
| -rw-r--r-- | endtoendtests/common.rb | 5 | ||||
| -rw-r--r-- | lib/net/ssh/buffered_io.rb | 48 | ||||
| -rw-r--r-- | lib/net/ssh/service/forward.rb | 39 | ||||
| -rw-r--r-- | test/README.txt | 42 | ||||
| -rw-r--r-- | test/manual/test_forward.rb (renamed from endtoendtests/test_forward.rb) | 23 | ||||
| -rw-r--r-- | test/test_all.rb | 1 |
8 files changed, 132 insertions, 50 deletions
diff --git a/CHANGELOG.rdoc b/CHANGELOG.rdoc index f2210c7..32c8608 100644 --- a/CHANGELOG.rdoc +++ b/CHANGELOG.rdoc @@ -1,4 +1,16 @@ + +=== 2.0.21 / ?? Mar 2010 + +* Fix for client closes a forwarded connection, but the server is reading, net-ssh terminates with IOError socket closed (http://net-ssh.lighthouseapp.com/projects/36253/tickets/7) [Miklós Fazekas] + +* Fix for client force closes (RST) a forwarded connection, but server is reading, net-ssh terminates with exception [Miklós Fazekas] + +* Fix for server closes the sending side, the on_eof is not handled. [Miklós Fazekas] + +* Removed Hanna dependency in Rakefile [Delano Mandelbaum] + + === 2.0.20 / 10 Feb 2010 * Support "ProxyCommand none" directive [Andy Lo-A-Foe] @@ -20,7 +32,9 @@ === 2.0.16 / 28 Nov 2009 * Fix for "multiple hosts are separated by whitespace" [Akinori MUSHA] + * Add support for the ProxyCommand directive [Akinori MUSHA] + * Switched from #recv(1) to #readpartial in lib/net/ssh/transport/server_version.rb, so that closed sockets are recognized [Alex Peuchert] @@ -1,10 +1,16 @@ require 'rubygems' require 'rake/clean' require 'rake/gempackagetask' -require 'hanna/rdoctask' require 'fileutils' include FileUtils - + +begin + require 'hanna/rdoctask' +rescue LoadError + require 'rake/rdoctask' +end + + task :default => :package # CONFIG ============================================================= diff --git a/endtoendtests/common.rb b/endtoendtests/common.rb deleted file mode 100644 index 6bde716..0000000 --- a/endtoendtests/common.rb +++ /dev/null @@ -1,5 +0,0 @@ -$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib" -require 'rubygems' -gem "test-unit" # http://rubyforge.org/pipermail/test-unit-tracker/2009-July/000075.html -require 'test/unit' -require 'mocha' diff --git a/lib/net/ssh/buffered_io.rb b/lib/net/ssh/buffered_io.rb index e48a8dc..9d6ea07 100644 --- a/lib/net/ssh/buffered_io.rb +++ b/lib/net/ssh/buffered_io.rb @@ -147,4 +147,52 @@ module Net; module SSH end end + + + # Fixes for two issues by Miklós Fazekas: + # + # * if client closes a forwarded connection, but the server is + # reading, net-ssh terminates with IOError socket closed. + # * if client force closes (RST) a forwarded connection, but + # server is reading, net-ssh terminates with [an exception] + # + # See: + # + # http://net-ssh.lighthouseapp.com/projects/36253/tickets/7 + # http://github.com/net-ssh/net-ssh/tree/portfwfix + # + module ForwardedBufferedIo + def fill(n=8192) + begin + super(n) + rescue Errno::ECONNRESET => e + debug { "connection was reset => shallowing exception:#{e}" } + return 0 + rescue IOError => e + if e.message =~ /closed/ then + debug { "connection was reset => shallowing exception:#{e}" } + return 0 + else + raise + end + end + end + + def send_pending + begin + super + rescue Errno::ECONNRESET => e + debug { "connection was reset => shallowing exception:#{e}" } + return 0 + rescue IOError => e + if e.message =~ /closed/ then + debug { "connection was reset => shallowing exception:#{e}" } + return 0 + else + raise + end + end + end + end + end; end diff --git a/lib/net/ssh/service/forward.rb b/lib/net/ssh/service/forward.rb index 9e37dce..fa3e4f0 100644 --- a/lib/net/ssh/service/forward.rb +++ b/lib/net/ssh/service/forward.rb @@ -193,47 +193,13 @@ module Net; module SSH; module Service end private - - module ForwardedBufferedIo - def fill(n=8192) - begin - super(n) - rescue Errno::ECONNRESET => e - debug { "connection was reset => shallowing exception:#{e}" } - return 0 - rescue IOError => e - if e.message =~ /closed/ then - debug { "connection was reset => shallowing exception:#{e}" } - return 0 - else - raise - end - end - end - - def send_pending - begin - super - rescue Errno::ECONNRESET => e - debug { "connection was reset => shallowing exception:#{e}" } - return 0 - rescue IOError => e - if e.message =~ /closed/ then - debug { "connection was reset => shallowing exception:#{e}" } - return 0 - else - raise - end - end - end - end - + # Perform setup operations that are common to all forwarded channels. # +client+ is a socket, +channel+ is the channel that was just created, # and +type+ is an arbitrary string describing the type of the channel. def prepare_client(client, channel, type) client.extend(Net::SSH::BufferedIo) - client.extend(ForwardedBufferedIo) + client.extend(Net::SSH::ForwardedBufferedIo) client.logger = logger session.listen_to(client) @@ -244,6 +210,7 @@ module Net; module SSH; module Service ch[:socket].enqueue(data) end + # Handles server close on the sending side by Miklós Fazekas channel.on_eof do |ch| debug { "eof #{type} on #{type} forwarded channel" } begin diff --git a/test/README.txt b/test/README.txt new file mode 100644 index 0000000..e97a07e --- /dev/null +++ b/test/README.txt @@ -0,0 +1,42 @@ +2010-03-16 + +RUNNING TESTS + +Run the test suite from the net-ssh directory with the following command: + + ruby -Ilib -Itest -rrubygems test/test_all.rb + +Run a single test file like this: + + ruby -Ilib -Itest -rrubygems test/transport/test_server_version.rb + + +EXPECTED RESULTS + +* Ruby 1.8: all tests pass + +* Ruby 1.9: all tests pass + +* JRuby 1.4: 96% tests pass (242 tests, 554 assertions, 0 failures, 8 errors) + + +PORT FORWARDING TESTS + + ruby -Ilib -Itest -rrubygems test/manual/test_forward.rb + +test_forward.rb must be run separately from the test suite because +it requires authorizing your public SSH keys on you localhost. + +If you already have keys you can do this: + + cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys + +If you don't have keys see: + + http://kimmo.suominen.com/docs/ssh/#ssh-keygen + +You should now be able to login to your localhost with out +bring prompted for a password: + + ssh localhost + diff --git a/endtoendtests/test_forward.rb b/test/manual/test_forward.rb index 4898f1c..46ddb25 100644 --- a/endtoendtests/test_forward.rb +++ b/test/manual/test_forward.rb @@ -1,14 +1,23 @@ +# $ ruby -Ilib -Itest -rrubygems test/test_forward.rb + +# Tests for the following patch: +# +# http://github.com/net-ssh/net-ssh/tree/portfwfix +# +# It fixes 3 issues, regarding closing forwarded ports: +# +# 1.) if client closes a forwarded connection, but the server is reading, net-ssh terminates with IOError socket closed. +# 2.) if client force closes (RST) a forwarded connection, but server is reading, net-ssh terminates with +# 3.) if server closes the sending side, the on_eof is not handled. +# +# More info: +# +# http://net-ssh.lighthouseapp.com/projects/36253/tickets/7 + require 'common' require 'net/ssh/buffer' require 'net/ssh' require 'timeout' - -# keyless ssh setup -# -# cat ~/.ssh/id_rsa.pub > ~/.ssh/authorized_keys -# to test: -# ssh localhost -# class TestForward < Test::Unit::TestCase diff --git a/test/test_all.rb b/test/test_all.rb index 47305dc..ca8d057 100644 --- a/test/test_all.rb +++ b/test/test_all.rb @@ -2,6 +2,7 @@ # $ ruby -Ilib -Itest -rrubygems test/transport/test_server_version.rb Dir.chdir(File.dirname(__FILE__)) do test_files = Dir['**/test_*.rb'] + test_files = test_files.reject { |f| f =~ /^manual/ } test_files = test_files.select { |f| f =~ Regexp.new(ENV['ONLY']) } if ENV['ONLY'] test_files = test_files.reject { |f| f =~ Regexp.new(ENV['EXCEPT']) } if ENV['EXCEPT'] test_files.each { |file| require(file) } |
