Hello community, here is the log from the commit of package rubygem-net-ssh for openSUSE:Factory checked in at 2016-03-29 10:00:18 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/rubygem-net-ssh (Old) and /work/SRC/openSUSE:Factory/.rubygem-net-ssh.new (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "rubygem-net-ssh" Changes: -------- --- /work/SRC/openSUSE:Factory/rubygem-net-ssh/rubygem-net-ssh.changes 2016-02-05 00:31:31.000000000 +0100 +++ /work/SRC/openSUSE:Factory/.rubygem-net-ssh.new/rubygem-net-ssh.changes 2016-03-29 10:39:50.000000000 +0200 @@ -1,0 +2,26 @@ +Sat Mar 19 05:30:30 UTC 2016 - [email protected] + +- updated to version 3.1.0 + see installed CHANGES.txt + + === 3.1.0 + === 3.1.0.rc1 + + * fix Secure#verify [Jean Boussier] + * use the smallest of don't spend longer time than keepalive if it's configured [Eugene Kenny] + + === 3.1.0.beta3 + + * forward/on_open_failed should stop listning closed socket otherwise it locks #269 [Miklos Fazekas,Scott McGillivray] + * fix incorrect pattern handling in config files #310 [Miklos Fazekas] + + === 3.1.0.beta2 + + * trying to execute something on a not yet opend channel throws nicer messag [Miklos Fazekas] + * calling close on a not opened channel marks the channel for close [Miklos Fazekas] + * read keepalive configuration from ssh config files [Miklos Fazekas] + * send client version on hadshake before waiting for server to reduce handshake time [Miklos Fazekas] + * allow custom Net::SSH::KnownHosts implementations [Jean Boussier] + * memoize known host so we only search it once per session [Jean Boussier, Miklos Fazekas] + +------------------------------------------------------------------- Old: ---- net-ssh-3.0.2.gem New: ---- net-ssh-3.1.0.gem ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ rubygem-net-ssh.spec ++++++ --- /var/tmp/diff_new_pack.kpPcX7/_old 2016-03-29 10:39:50.000000000 +0200 +++ /var/tmp/diff_new_pack.kpPcX7/_new 2016-03-29 10:39:50.000000000 +0200 @@ -24,7 +24,7 @@ # Name: rubygem-net-ssh -Version: 3.0.2 +Version: 3.1.0 Release: 0 %define mod_name net-ssh %define mod_full_name %{mod_name}-%{version} ++++++ net-ssh-3.0.2.gem -> net-ssh-3.1.0.gem ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/.travis.yml new/.travis.yml --- old/.travis.yml 2015-12-30 10:07:47.000000000 +0100 +++ new/.travis.yml 2016-03-18 19:59:03.000000000 +0100 @@ -1,10 +1,10 @@ language: ruby sudo: false rvm: - - 1.9.3 - 2.0.0 - 2.1.0 - 2.2.0 + - 2.3.0 - jruby-head - jruby-19mode - rbx-2 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/CHANGES.txt new/CHANGES.txt --- old/CHANGES.txt 2015-12-30 10:07:47.000000000 +0100 +++ new/CHANGES.txt 2016-03-18 19:59:03.000000000 +0100 @@ -1,3 +1,23 @@ +=== 3.1.0 +=== 3.1.0.rc1 + +* fix Secure#verify [Jean Boussier] +* use the smallest of don't spend longer time than keepalive if it's configured [Eugene Kenny] + +=== 3.1.0.beta3 + +* forward/on_open_failed should stop listning closed socket otherwise it locks #269 [Miklos Fazekas,Scott McGillivray] +* fix incorrect pattern handling in config files #310 [Miklos Fazekas] + +=== 3.1.0.beta2 + +* trying to execute something on a not yet opend channel throws nicer messag [Miklos Fazekas] +* calling close on a not opened channel marks the channel for close [Miklos Fazekas] +* read keepalive configuration from ssh config files [Miklos Fazekas] +* send client version on hadshake before waiting for server to reduce handshake time [Miklos Fazekas] +* allow custom Net::SSH::KnownHosts implementations [Jean Boussier] +* memoize known host so we only search it once per session [Jean Boussier, Miklos Fazekas] + === 3.0.2 === 3.0.2.rc1 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Rakefile new/Rakefile --- old/Rakefile 2015-12-30 10:07:47.000000000 +0100 +++ new/Rakefile 2016-03-18 19:59:03.000000000 +0100 @@ -72,6 +72,31 @@ end end +namespace :rdoc do +desc "Update gh-pages branch" +task :publish do + # copy/checkout + rm_rf "/tmp/net-ssh-rdoc" + rm_rf "/tmp/net-ssh-gh-pages" + cp_r "./rdoc", "/tmp/net-ssh-rdoc" + mkdir "/tmp/net-ssh-gh-pages" + Dir.chdir "/tmp/net-ssh-gh-pages" do + sh "git clone --branch gh-pages --single-branch https://github.com/net-ssh/net-ssh" + rm_rf "/tmp/net-ssh-gh-pages/net-ssh/*" + end + # update + sh "cp -rf ./rdoc/* /tmp/net-ssh-gh-pages/net-ssh/" + Dir.chdir "/tmp/net-ssh-gh-pages/net-ssh" do + sh "git add -A ." + sh "git commit -m \"Update docs\"" + end + # publish + Dir.chdir "/tmp/net-ssh-gh-pages/net-ssh" do + sh "git push origin gh-pages" + end +end +end + require 'rake/testtask' Rake::TestTask.new do |t| if ENV['NET_SSH_RUN_INTEGRATION_TESTS'] Files old/checksums.yaml.gz and new/checksums.yaml.gz differ Files old/checksums.yaml.gz.sig and new/checksums.yaml.gz.sig differ Files old/data.tar.gz.sig and new/data.tar.gz.sig differ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/net/ssh/authentication/pageant.rb new/lib/net/ssh/authentication/pageant.rb --- old/lib/net/ssh/authentication/pageant.rb 2015-12-30 10:07:47.000000000 +0100 +++ new/lib/net/ssh/authentication/pageant.rb 2016-03-18 19:59:03.000000000 +0100 @@ -12,8 +12,8 @@ # For now map DL to Fiddler versus updating all the code below module DL - CPtr = Fiddle::Pointer - RUBY_FREE = Fiddle::RUBY_FREE + CPtr ||= Fiddle::Pointer + RUBY_FREE ||= Fiddle::RUBY_FREE end end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/net/ssh/authentication/session.rb new/lib/net/ssh/authentication/session.rb --- old/lib/net/ssh/authentication/session.rb 2015-12-30 10:07:47.000000000 +0100 +++ new/lib/net/ssh/authentication/session.rb 2016-03-18 19:59:03.000000000 +0100 @@ -69,7 +69,7 @@ attempted << name debug { "trying #{name}" } - begin + begin method = Methods.const_get(name.split(/\W+/).map { |p| p.capitalize }.join).new(self, :key_manager => key_manager) rescue NameError debug{"Mechanism #{name} was requested, but isn't a known type. Ignoring it."} diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/net/ssh/config.rb new/lib/net/ssh/config.rb --- old/lib/net/ssh/config.rb 2015-12-30 10:07:47.000000000 +0100 +++ new/lib/net/ssh/config.rb 2016-03-18 19:59:03.000000000 +0100 @@ -178,6 +178,15 @@ hash[:keys] = value when 'macs' then hash[:hmac] = value.split(/,/) + when 'serveralivecountmax' + hash[:keepalive_maxcount] = value.to_i if value + when 'serveraliveinterval' + if value && value.to_i > 0 + hash[:keepalive] = true + hash[:keepalive_interval] = value.to_i + else + hash[:keepalive] = false + end when 'passwordauthentication' if value (hash[:auth_methods] << 'password').uniq! @@ -233,11 +242,22 @@ # Converts an ssh_config pattern into a regex for matching against # host names. def pattern2regex(pattern) - pattern = "^" + pattern.to_s.gsub(/\./, "\\."). - gsub(/\?/, '.'). - gsub(/([+\/])/, '\\\\\\0'). - gsub(/\*/, '.*') + "$" - Regexp.new(pattern, true) + tail = pattern + prefix = "" + while !tail.empty? do + head,sep,tail = tail.partition(/[\*\?]/) + prefix = prefix + Regexp.quote(head) + case sep + when '*' + prefix += '.*' + when '?' + prefix += '.' + when '' + else + fail "Unpexpcted sep:#{sep}" + end + end + Regexp.new("^" + prefix + "$", true) end # Converts the given size into an integer number of bytes. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/net/ssh/connection/channel.rb new/lib/net/ssh/connection/channel.rb --- old/lib/net/ssh/connection/channel.rb 2015-12-30 10:07:47.000000000 +0100 +++ new/lib/net/ssh/connection/channel.rb 2016-03-18 19:59:03.000000000 +0100 @@ -291,15 +291,11 @@ @remote_closed = true end - # Requests that the channel be closed. If the channel is already closing, - # this does nothing, nor does it do anything if the channel has not yet - # been confirmed open (see #do_open_confirmation). Otherwise, it sends a - # CHANNEL_CLOSE message and marks the channel as closing. + # Requests that the channel be closed. It only marks the channel to be closed + # the CHANNEL_CLOSE message will be sent from event loop def close return if @closing - if remote_id - @closing = true - end + @closing = true end # Returns true if the local end of the channel has declared that no more @@ -486,6 +482,7 @@ # convenient helper methods (see #exec and #subsystem). def send_channel_request(request_name, *data, &callback) info { "sending channel request #{request_name.inspect}" } + fail "Channel open not yet confirmed, please call send_channel_request(or exec) from block of open_channel" unless remote_id msg = Buffer.from(:byte, CHANNEL_REQUEST, :long, remote_id, :string, request_name, :bool, !callback.nil?, *data) @@ -632,6 +629,12 @@ private + # Runs the SSH event loop until the remote confirmed channel open + # experimental api + def wait_until_open_confirmed + connection.loop { !remote_id } + end + # Updates the local window size by the given amount. If the window # size drops to less than half of the local maximum (an arbitrary # threshold), a CHANNEL_WINDOW_ADJUST message will be sent to the diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/net/ssh/connection/session.rb new/lib/net/ssh/connection/session.rb --- old/lib/net/ssh/connection/session.rb 2015-12-30 10:07:47.000000000 +0100 +++ new/lib/net/ssh/connection/session.rb 2016-03-18 19:59:03.000000000 +0100 @@ -609,9 +609,11 @@ end def io_select_wait(wait) - return wait if wait - return wait unless @keepalive.enabled? - @keepalive.interval + if @keepalive.enabled? + [wait, @keepalive.interval].compact.min + else + wait + end end MAP = Constants.constants.inject({}) do |memo, name| diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/net/ssh/known_hosts.rb new/lib/net/ssh/known_hosts.rb --- old/lib/net/ssh/known_hosts.rb 2015-12-30 10:07:47.000000000 +0100 +++ new/lib/net/ssh/known_hosts.rb 2016-03-18 19:59:03.000000000 +0100 @@ -5,6 +5,24 @@ module Net; module SSH + # Represents the result of a search in known hosts + # see search_for + class HostKeys < Array + attr_reader :host + + def initialize(host_keys, host, known_hosts, options = {}) + super(host_keys) + @host = host + @known_hosts = known_hosts + @options = options + end + + def add_host_key(key) + @known_hosts.add(@host, key, @options) + push(key) + end + end + # Searches an OpenSSH-style known-host file for a given host, and returns all # matching keys. This is used to implement host-key verification, as well as # to determine what key a user prefers to use for a given host. @@ -26,9 +44,9 @@ class <<self # Searches all known host files (see KnownHosts.hostfiles) for all keys - # of the given host. Returns an array of keys found. + # of the given host. Returns an enumerable of keys found. def search_for(host, options={}) - search_in(hostfiles(options), host) + HostKeys.new(search_in(hostfiles(options), host), host, self, options) end # Search for all known keys for the given host, in every file given in diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/net/ssh/service/forward.rb new/lib/net/ssh/service/forward.rb --- old/lib/net/ssh/service/forward.rb 2015-12-30 10:07:47.000000000 +0100 +++ new/lib/net/ssh/service/forward.rb 2016-03-18 19:59:03.000000000 +0100 @@ -91,6 +91,7 @@ channel.on_open_failed do |ch, code, description| channel.error { "could not establish direct channel: #{description} (#{code})" } + session.stop_listening_to(channel[:socket]) channel[:socket].close end end @@ -273,7 +274,6 @@ 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 -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/net/ssh/transport/algorithms.rb new/lib/net/ssh/transport/algorithms.rb --- old/lib/net/ssh/transport/algorithms.rb 2015-12-30 10:07:47.000000000 +0100 +++ new/lib/net/ssh/transport/algorithms.rb 2016-03-18 19:59:03.000000000 +0100 @@ -242,7 +242,7 @@ # make sure the host keys are specified in preference order, where any # existing known key for the host has preference. - existing_keys = KnownHosts.search_for(options[:host_key_alias] || session.host_as_string, options) + existing_keys = session.host_keys host_keys = existing_keys.map { |key| key.ssh_type }.uniq algorithms[:host_key].each do |name| host_keys << name unless host_keys.include?(name) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/net/ssh/transport/server_version.rb new/lib/net/ssh/transport/server_version.rb --- old/lib/net/ssh/transport/server_version.rb 2015-12-30 10:07:47.000000000 +0100 +++ new/lib/net/ssh/transport/server_version.rb 2016-03-18 19:59:03.000000000 +0100 @@ -40,6 +40,10 @@ def negotiate!(socket, timeout) info { "negotiating protocol version" } + debug { "local is `#{PROTO_VERSION}'" } + socket.write "#{PROTO_VERSION}\r\n" + socket.flush + if timeout && !IO.select([socket], nil, nil, timeout) raise Net::SSH::ConnectionTimeout, "timeout during server version negotiating" end @@ -69,9 +73,6 @@ if timeout && !IO.select(nil, [socket], nil, timeout) raise Net::SSH::ConnectionTimeout, "timeout during client version negotiating" end - debug { "local is `#{PROTO_VERSION}'" } - socket.write "#{PROTO_VERSION}\r\n" - socket.flush end end end; end; end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/net/ssh/transport/session.rb new/lib/net/ssh/transport/session.rb --- old/lib/net/ssh/transport/session.rb 2015-12-30 10:07:47.000000000 +0100 +++ new/lib/net/ssh/transport/session.rb 2016-03-18 19:59:03.000000000 +0100 @@ -89,6 +89,13 @@ raise Net::SSH::ConnectionTimeout end + def host_keys + @host_keys ||= begin + known_hosts = options.fetch(:known_hosts, KnownHosts) + known_hosts.search_for(options[:host_key_alias] || host_as_string, options) + end + end + # Returns the host (and possibly IP address) in a format compatible with # SSH known-host files. def host_as_string diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/net/ssh/verifiers/secure.rb new/lib/net/ssh/verifiers/secure.rb --- old/lib/net/ssh/verifiers/secure.rb 2015-12-30 10:07:47.000000000 +0100 +++ new/lib/net/ssh/verifiers/secure.rb 2016-03-18 19:59:03.000000000 +0100 @@ -13,18 +13,16 @@ # Otherwise, this returns true. class Secure def verify(arguments) - options = arguments[:session].options - host = options[:host_key_alias] || arguments[:session].host_as_string - matches = Net::SSH::KnownHosts.search_for(host, arguments[:session].options) + host_keys = arguments[:session].host_keys # We've never seen this host before, so raise an exception. - if matches.empty? - process_cache_miss(host, arguments, HostKeyUnknown, "is unknown") + if host_keys.empty? + process_cache_miss(host_keys, arguments, HostKeyUnknown, "is unknown") end # If we found any matches, check to see that the key type and # blob also match. - found = matches.any? do |key| + found = host_keys.any? do |key| key.ssh_type == arguments[:key].ssh_type && key.to_blob == arguments[:key].to_blob end @@ -32,7 +30,7 @@ # If a match was found, return true. Otherwise, raise an exception # indicating that the key was not recognized. unless found - process_cache_miss(host, arguments, HostKeyMismatch, "does not match") + process_cache_miss(host_keys, arguments, HostKeyMismatch, "does not match") end found @@ -40,12 +38,12 @@ private - def process_cache_miss(host, args, exc_class, message) + def process_cache_miss(host_keys, args, exc_class, message) exception = exc_class.new("fingerprint #{args[:fingerprint]} " + - "#{message} for #{host.inspect}") + "#{message} for #{host_keys.host.inspect}") exception.data = args exception.callback = Proc.new do - Net::SSH::KnownHosts.add(host, args[:key], args[:session].options) + host_keys.add_host_key(args[:key]) end raise exception end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/net/ssh/version.rb new/lib/net/ssh/version.rb --- old/lib/net/ssh/version.rb 2015-12-30 10:07:47.000000000 +0100 +++ new/lib/net/ssh/version.rb 2016-03-18 19:59:03.000000000 +0100 @@ -48,10 +48,10 @@ MAJOR = 3 # The minor component of this version of the Net::SSH library - MINOR = 0 + MINOR = 1 # The tiny component of this version of the Net::SSH library - TINY = 2 + TINY = 0 # The prerelease component of this version of the Net::SSH library # nil allowed diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/net/ssh.rb new/lib/net/ssh.rb --- old/lib/net/ssh.rb 2015-12-30 10:07:47.000000000 +0100 +++ new/lib/net/ssh.rb 2016-03-18 19:59:03.000000000 +0100 @@ -66,7 +66,7 @@ :keepalive, :keepalive_interval, :keepalive_maxcount, :kex, :keys, :key_data, :languages, :logger, :paranoid, :password, :port, :proxy, :rekey_blocks_limit,:rekey_limit, :rekey_packet_limit, :timeout, :verbose, - :global_known_hosts_file, :user_known_hosts_file, :host_key_alias, + :known_hosts, :global_known_hosts_file, :user_known_hosts_file, :host_key_alias, :host_name, :user, :properties, :passphrase, :keys_only, :max_pkt_size, :max_win_size, :send_env, :use_agent, :number_of_password_prompts, :append_supported_algorithms, :non_interactive @@ -114,6 +114,8 @@ # * :encryption => the encryption cipher (or ciphers) to use # * :forward_agent => set to true if you want the SSH agent connection to # be forwarded + # * :known_hosts => a custom object holding known hosts records. + # It must implement #search_for and add in a similiar manner as KnownHosts. # * :global_known_hosts_file => the location of the global known hosts # file. Set to an array if you want to specify multiple global known # hosts files. Defaults to %w(/etc/ssh/ssh_known_hosts /etc/ssh/ssh_known_hosts2). @@ -132,6 +134,7 @@ # * :keepalive_interval => the interval seconds for keepalive. # Defaults to +300+ seconds. # * :keepalive_maxcount => the maximun number of keepalive packet miss allowed. + # Defaults to 3 # * :kex => the key exchange algorithm (or algorithms) to use # * :keys => an array of file names of private keys to use for publickey # and hostbased authentication diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/metadata new/metadata --- old/metadata 2015-12-30 10:07:47.000000000 +0100 +++ new/metadata 2016-03-18 19:59:03.000000000 +0100 @@ -1,7 +1,7 @@ --- !ruby/object:Gem::Specification name: net-ssh version: !ruby/object:Gem::Version - version: 3.0.2 + version: 3.1.0 platform: ruby authors: - Jamis Buck @@ -31,7 +31,7 @@ s/ZUKye79ELwFYKJOhjW5g725OL3hy+llhEleytwKRwgXFQBPTC4f5UkdxZVVWGH e2C9M1m/2odPZo8h -----END CERTIFICATE----- -date: 2015-12-30 00:00:00.000000000 Z +date: 2016-03-18 00:00:00.000000000 Z dependencies: - !ruby/object:Gem::Dependency name: test-unit @@ -236,6 +236,7 @@ - test/transport/test_server_version.rb - test/transport/test_session.rb - test/transport/test_state.rb +- test/verifiers/test_secure.rb homepage: https://github.com/net-ssh/net-ssh licenses: - MIT Files old/metadata.gz.sig and new/metadata.gz.sig differ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/net-ssh.gemspec new/net-ssh.gemspec --- old/net-ssh.gemspec 2015-12-30 10:07:47.000000000 +0100 +++ new/net-ssh.gemspec 2016-03-18 19:59:03.000000000 +0100 @@ -2,17 +2,17 @@ # DO NOT EDIT THIS FILE DIRECTLY # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec' # -*- encoding: utf-8 -*- -# stub: net-ssh 3.0.2 ruby lib +# stub: net-ssh 3.1.0 ruby lib Gem::Specification.new do |s| s.name = "net-ssh" - s.version = "3.0.2" + s.version = "3.1.0" s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.require_paths = ["lib"] s.authors = ["Jamis Buck", "Delano Mandelbaum", "Mikl\u{f3}s Fazekas"] s.cert_chain = ["net-ssh-public_cert.pem"] - s.date = "2015-12-30" + s.date = "2016-03-18" s.description = "Net::SSH: a pure-Ruby implementation of the SSH2 client protocol. It allows you to write programs that invoke and interact with processes on remote servers, via SSH2." s.email = "[email protected]" s.extra_rdoc_files = [ @@ -184,7 +184,8 @@ "test/transport/test_packet_stream.rb", "test/transport/test_server_version.rb", "test/transport/test_session.rb", - "test/transport/test_state.rb" + "test/transport/test_state.rb", + "test/verifiers/test_secure.rb" ] s.homepage = "https://github.com/net-ssh/net-ssh" s.licenses = ["MIT"] diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/test/common.rb new/test/common.rb --- old/test/common.rb 2015-12-30 10:07:47.000000000 +0100 +++ new/test/common.rb 2016-03-18 19:59:03.000000000 +0100 @@ -41,6 +41,7 @@ attr_accessor :mock_enqueue def initialize(options={}) + @options = options self.logger = options[:logger] self.host_as_string = "net.ssh.test,127.0.0.1" self.server_version = OpenStruct.new(:version => "SSH-2.0-Ruby/Net::SSH::Test") diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/test/connection/test_channel.rb new/test/connection/test_channel.rb --- old/test/connection/test_channel.rb 2015-12-30 10:07:47.000000000 +0100 +++ new/test/connection/test_channel.rb 2016-03-18 19:59:03.000000000 +0100 @@ -63,10 +63,10 @@ assert_equal "helloworld", channel.output.to_s end - def test_close_before_channel_has_been_confirmed_should_do_nothing + def test_close_before_channel_has_been_confirmed_should_set_closing assert !channel.closing? channel.close - assert !channel.closing? + assert channel.closing? end def test_close_should_set_closing_and_send_message @@ -261,6 +261,18 @@ assert channel.pending_requests.empty? end + def test_send_channel_request_should_wait_for_remote_id + channel.expects(:remote_id).times(1).returns(nil) + msg = nil + begin + channel.send_channel_request("exec", :string, "ls") + rescue RuntimeError => e + msg = e.message + end + assert_equal "Channel open not yet confirmed, please call send_channel_request(or exec) from block of open_channel", msg + assert channel.pending_requests.empty? + end + def test_send_channel_request_with_callback_should_want_reply channel.do_open_confirmation(0, 100, 100) connection.expect do |t,p| @@ -377,6 +389,11 @@ channel.wait end + def test_wait_until_open_confirmed_should_block_while_remote_id_nil + channel.expects(:remote_id).times(3).returns(nil,nil,3) + channel.send(:wait_until_open_confirmed) + end + def test_eof_bang_should_send_eof_to_server channel.do_open_confirmation(0, 1000, 1000) connection.expect { |t,p| assert_equal CHANNEL_EOF, p.type } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/test/connection/test_session.rb new/test/connection/test_session.rb --- old/test/connection/test_session.rb 2015-12-30 10:07:47.000000000 +0100 +++ new/test/connection/test_session.rb 2016-03-18 19:59:03.000000000 +0100 @@ -427,6 +427,14 @@ session(options).process end + def test_process_should_call_io_select_with_wait_if_provided_and_minimum + timeout = 10 + wait = 5 + options = { :keepalive => true, :keepalive_interval => timeout } + IO.expects(:select).with([socket],[],nil,wait).returns([[],[],[]]) + session(options).process(wait) + end + def test_loop_should_call_process_until_process_returns_false IO.stubs(:select).with([socket],[],nil,nil).returns([[],[],[]]) session.expects(:process).with(nil).times(4).returns(true,true,true,false).yields diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/test/integration/playbook.yml new/test/integration/playbook.yml --- old/test/integration/playbook.yml 2015-12-30 10:07:47.000000000 +0100 +++ new/test/integration/playbook.yml 2016-03-18 19:59:04.000000000 +0100 @@ -3,19 +3,19 @@ sudo: yes vars: ruby_version: '2.0.0-p598' - rvm1_install_path: '/usr/local/rvm' + rvm_install_path: '/usr/local/rvm' foopwd: "$6$mhOzf/yapZwS$3RwDl4GfWZ5VcfcsHrK9xNNTxyzLOJBsmMttDNaegIbXxMahV86.v/5HsNtit16MEl0EFf5CSW8Dz2yXV.8GB0" foo2pwd: "$6$JiB7y7.M0yI$Abt.ZGIc4DwkRWeI6nKxzzPUZcux7hLRXSdpoKoZvswJz1SZyg5GRQWn9pGID0dgC6e4wFglfW6ev/qZoTqGk/" pre_tasks: - name: get currently installed ruby version - command: "{{rvm1_install_path}}/rubies/ruby-{{ruby_version}}/bin/ruby -e 'puts \"#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}\"'" + command: "{{rvm_install_path}}/rubies/ruby-{{ruby_version}}/bin/ruby -e 'puts \"#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}\"'" register: current_ruby_version ignore_errors: True roles: - { role: rvm_io.rvm1-ruby, tags: ruby, sudo: True, rvm1_rubies: ["ruby-{{ruby_version}}","ruby-2.3.0"], - rvm1_install_path: "{{rvm1_install_path}}", + rvm1_install_path: "{{rvm_install_path}}", rvm1_gpg_key_server: pool.sks-keyservers.net, when: "'{{current_ruby_version.stdout|default()}}' != '{{ruby_version}}'" } tasks: diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/test/integration/test_forward.rb new/test/integration/test_forward.rb --- old/test/integration/test_forward.rb 2015-12-30 10:07:47.000000000 +0100 +++ new/test/integration/test_forward.rb 2016-03-18 19:59:04.000000000 +0100 @@ -287,8 +287,8 @@ end end - def start_server - server = TCPServer.open(0) + def start_server(server = nil, &block) + server ||= TCPServer.open(0) Thread.start do loop do Thread.start(server.accept) do |client| @@ -432,4 +432,101 @@ end end end + + def _run_reading_client(client_done, local_port) + Thread.start do + begin + client = TCPSocket.new(localhost, local_port) + data = client.read(4096) + client.close + client_done << data + rescue + client_done << $! + end + end + end + + def test_cannot_open_connection_should_allow_further_connections_on_different_forward + setup_ssh_env do + session = Net::SSH.start(*ssh_start_params) + server = start_server do |client| + data = client.write "hello" + client.close + end + # Forward to a non existing port + non_existing_port = 1234 + local_port = session.forward.local(0, localhost, non_existing_port) + # should return connection refused + client_done = Queue.new + _run_reading_client(client_done, local_port) + timeout(5) do + session.loop(0.1) { client_done.empty? } + end + assert_equal nil, client_done.pop + assert client_done.empty? + # Forward to existing port + remote_port = server.addr[1] + local_port = session.forward.local(0, localhost, remote_port) + _run_reading_client(client_done, local_port) + timeout(5) do + session.loop(0.1) { client_done.empty? } + end + assert_equal "hello", client_done.pop + assert client_done.empty? + end + end + + def test_cannot_open_connection_should_allow_further_connections_on_same + setup_ssh_env do + session = Net::SSH.start(*ssh_start_params) + server = TCPServer.open(0) + # Forward to a non existing port + remote_port = server.addr[1] + server.close + local_port = session.forward.local(0, localhost, remote_port) + # should return connection refused + client_done = Queue.new + _run_reading_client(client_done, local_port) + timeout(5) do + session.loop(0.1) { client_done.empty? } + end + assert_equal nil, client_done.pop + assert client_done.empty? + # start server + server = TCPServer.open(remote_port) + server = start_server(server) do |client| + data = client.write "hello" + client.close + end + _run_reading_client(client_done, local_port) + timeout(5) do + session.loop(0.1) { client_done.empty? } + end + assert_equal "hello", client_done.pop + assert client_done.empty? + end + end + + def test_cancel_local + setup_ssh_env do + session = Net::SSH.start(*ssh_start_params) + server = start_server(server) do |client| + data = client.write "hello" + client.close + end + remote_port = server.addr[1] + local_port = session.forward.local(0, localhost, remote_port) + # run client + client_done = Queue.new + _run_reading_client(client_done, local_port) + timeout(5) do + session.loop(0.1) { client_done.empty? } + end + assert_equal "hello", client_done.pop + # cancel + session.forward.cancel_local(local_port) + session.loop(0.1) + assert_equal({}, session.channels) + end + end end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/test/test_config.rb new/test/test_config.rb --- old/test/test_config.rb 2015-12-30 10:07:47.000000000 +0100 +++ new/test/test_config.rb 2016-03-18 19:59:04.000000000 +0100 @@ -1,6 +1,7 @@ require 'common' require 'net/ssh/config' require 'pathname' +require 'tempfile' class TestConfig < Test::Unit::TestCase def test_home_should_be_absolute_path @@ -41,6 +42,33 @@ assert !config.key?('compression') end + def test_load_with_pattern_does_match + data = %q{ + Host test.* + Port 1234 + Compression no + } + with_config_from_data data do |f| + config = Net::SSH::Config.load(f, "test.host") + assert_equal 1234, config['port'] + end + end + + def test_load_with_regex_chars + data = %q{ + Host | + Port 1234 + Compression no + } + with_config_from_data data do |f| + config = Net::SSH::Config.load(f, "test.host") + assert_equal nil, config['port'] + config = Net::SSH::Config.load(f, "|") + assert_equal 1234, config['port'] + end + end + + def test_for_should_load_all_files_and_translate_to_net_ssh_options config = Net::SSH::Config.for("test.host", [config(:exact_match), config(:wild_cards)]) assert_equal 1234, config[:port] @@ -94,7 +122,9 @@ 'pubkeyauthentication' => true, 'rekeylimit' => 1024, 'sendenv' => "LC_*", - 'numberofpasswordprompts' => '123' + 'numberofpasswordprompts' => '123', + 'serveraliveinterval' => '2', + 'serveralivecountmax' => '4' } net_ssh = Net::SSH::Config.translate(open_ssh) @@ -113,6 +143,9 @@ assert_equal "127.0.0.1", net_ssh[:bind_address] assert_equal [/^LC_.*$/], net_ssh[:send_env] assert_equal 123, net_ssh[:number_of_password_prompts] + assert_equal 4, net_ssh[:keepalive_maxcount] + assert_equal 2, net_ssh[:keepalive_interval] + assert_equal true, net_ssh[:keepalive] end def test_translate_should_turn_off_authentication_methods @@ -224,4 +257,12 @@ def config(name) "test/configs/#{name}" end + + def with_config_from_data(data, &block) + Tempfile.open('config') do |f| + f.write(data) + f.close + yield(f.path) + end + end end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/test/test_known_hosts.rb new/test/test_known_hosts.rb --- old/test/test_known_hosts.rb 2015-12-30 10:07:47.000000000 +0100 +++ new/test/test_known_hosts.rb 2016-03-18 19:59:04.000000000 +0100 @@ -2,8 +2,7 @@ class TestKnownHosts < Test::Unit::TestCase - def perform_test(hostfile) - source = File.join(File.dirname(__FILE__), hostfile) + def perform_test(source) kh = Net::SSH::KnownHosts.new(source) keys = kh.keys_for("github.com") assert_equal(1, keys.count) @@ -11,11 +10,57 @@ end def test_key_for_when_all_hosts_are_recognized - perform_test("known_hosts/github") + perform_test(path("known_hosts/github")) end def test_key_for_when_an_host_hash_is_recognized - perform_test("known_hosts/github_hash") + perform_test(path("known_hosts/github_hash")) end + def test_missing_then_add + Tempfile.open('github') do |f| + f.write(File.read(path("known_hosts/github"))) + kh = Net::SSH::KnownHosts.new(f.path) + keys = kh.keys_for("github2.com") + assert_equal(0, keys.count) + assert_equal([], keys.to_a) + + kh.add('github2.com',rsa_key) + keys2 = kh.keys_for("github2.com") + assert_equal([rsa_key.to_blob], keys2.to_a.map(&:to_blob)) + end + end + + def test_search_for + options = {user_known_hosts_file: path("known_hosts/github")} + keys = Net::SSH::KnownHosts.search_for('github.com',options) + assert_equal(["ssh-rsa"], keys.map(&:ssh_type)) + end + + def test_search_for_then_add + Tempfile.open('github') do |f| + f.write(File.read(path("known_hosts/github"))) + options = {user_known_hosts_file: f.path} + keys = Net::SSH::KnownHosts.search_for('github2.com',options) + assert_equal(0, keys.count) + + keys.add_host_key(rsa_key) + + assert_equal([rsa_key.to_blob], keys.map(&:to_blob)) + keys = Net::SSH::KnownHosts.search_for('github2.com',options) + assert_equal([rsa_key.to_blob], keys.map(&:to_blob)) + end + end + + + def path(relative_path) + File.join(File.dirname(__FILE__), "known_hosts/github") + end + + def rsa_key + key = OpenSSL::PKey::RSA.new + key.e = 0xffeeddccbbaa9988 + key.n = 0x7766554433221100 + key + end end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/test/transport/test_packet_stream.rb new/test/transport/test_packet_stream.rb --- old/test/transport/test_packet_stream.rb 2015-12-30 10:07:47.000000000 +0100 +++ new/test/transport/test_packet_stream.rb 2016-03-18 19:59:04.000000000 +0100 @@ -109,7 +109,7 @@ def test_next_packet_should_not_block_by_default IO.expects(:select).returns(nil) assert_nothing_raised do - timeout(1) { stream.next_packet } + Timeout.timeout(1) { stream.next_packet } end end @@ -1701,7 +1701,7 @@ [false, :standard].each do |compress| cipher_method_name = cipher_name.gsub(/\W/, "_") hmac_method_name = hmac_name.gsub(/\W/, "_") - + define_method("test_next_packet_with_#{cipher_method_name}_and_#{hmac_method_name}_and_#{compress}_compression") do opts = { :shared => "123", :hash => "^&*", :digester => OpenSSL::Digest::SHA1 } cipher = Net::SSH::Transport::CipherFactory.get(cipher_name, opts.merge(:key => "ABC", :decrypt => true, :iv => "abc")) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/test/transport/test_server_version.rb new/test/transport/test_server_version.rb --- old/test/transport/test_server_version.rb 2015-12-30 10:07:47.000000000 +0100 +++ new/test/transport/test_server_version.rb 2016-03-18 19:59:04.000000000 +0100 @@ -47,6 +47,9 @@ def socket(good, version_header, raise_eot=false) socket = mock("socket") + socket.expects(:write).with("#{Net::SSH::Transport::ServerVersion::PROTO_VERSION}\r\n") + socket.expects(:flush) + data = version_header.split('') recv_times = data.length recv_times += 1 if data[-1] != "\n" @@ -60,13 +63,6 @@ socket.expects(:readpartial).with(1).times(recv_times+1).returns(*data).then.raises(EOFError, "end of file reached") end - if good - socket.expects(:write).with("#{Net::SSH::Transport::ServerVersion::PROTO_VERSION}\r\n") - socket.expects(:flush) - else - socket.expects(:write).never - end - socket end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/test/verifiers/test_secure.rb new/test/verifiers/test_secure.rb --- old/test/verifiers/test_secure.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/test/verifiers/test_secure.rb 2016-03-18 19:59:04.000000000 +0100 @@ -0,0 +1,40 @@ +require 'common' +require 'net/ssh/verifiers/secure' +require 'ostruct' + +class TestSecure < Test::Unit::TestCase + def test_raises_unknown_key_error_if_empty + secure_verifier = Net::SSH::Verifiers::Secure.new + host_keys = [] + def host_keys.host + 'foo' + end + assert_raises(Net::SSH::HostKeyUnknown) { + secure_verifier.verify(session:OpenStruct.new(host_keys:host_keys)) + } + end + + def test_passess_if_sam + secure_verifier = Net::SSH::Verifiers::Secure.new + key = OpenStruct.new(ssh_type:'key_type',to_blob:'keyblob') + host_keys = [key] + def host_keys.host + 'foo' + end + secure_verifier.verify(session:OpenStruct.new(host_keys:host_keys), key:key) + end + + def test_raises_mismatch_error_if_not_the_same + secure_verifier = Net::SSH::Verifiers::Secure.new + key_in_known_hosts = OpenStruct.new(ssh_type:'key_type',to_blob:'keyblob') + key_actual = OpenStruct.new(ssh_type:'key_type',to_blob:'not keyblob') + + host_keys = [key_in_known_hosts] + def host_keys.host + 'foo' + end + assert_raises(Net::SSH::HostKeyMismatch) { + secure_verifier.verify(session:OpenStruct.new(host_keys:host_keys), key:key_actual) + } + end +end \ No newline at end of file
