diff options
author | Miklos Fazekas <mfazekas@szemafor.com> | 2016-12-11 12:58:32 +0100 |
---|---|---|
committer | Miklos Fazekas <mfazekas@szemafor.com> | 2016-12-11 12:58:32 +0100 |
commit | 3f4cb5f36eae11c29137f81e99f72b3b8e9c5940 (patch) | |
tree | f193403e59b40f1bc62b64bae56034223a291c68 | |
parent | 3622f63edf1f34c4b9db020e57fe8c7cd15b340f (diff) | |
download | net-ssh-3f4cb5f36eae11c29137f81e99f72b3b8e9c5940.tar.gz |
Use 1.9 hash syntax
40 files changed, 272 insertions, 305 deletions
diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 45b48d2..9afab70 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -22,14 +22,6 @@ Lint/BlockAlignment: Exclude: - 'test/integration/test_proxy.rb' -# Offense count: 3 -# Cop supports --auto-correct. -Lint/Debugger: - Exclude: - - 'quicktest.rb' - - 'test.rb' - - 'test_connection_close_shall_close_cannels.rb' - # Offense count: 1 # Cop supports --auto-correct. Lint/DeprecatedClassMethods: @@ -65,7 +57,6 @@ Lint/ImplicitStringConcatenation: Lint/LiteralInCondition: Exclude: - 'lib/net/ssh/authentication/pageant.rb' - - 'quicktest.rb' # Offense count: 2 Lint/Loop: @@ -96,13 +87,6 @@ Lint/RescueException: - 'lib/net/ssh/service/forward.rb' - 'lib/net/ssh/transport/kex/diffie_hellman_group1_sha1.rb' -# Offense count: 9 -Lint/ShadowingOuterLocalVariable: - Exclude: - - 'quicktest_1_open_channel_nb.rb' - - 'quicktest_337.rb' - - 'quicktest_4gb.rb' - # Offense count: 1 Lint/UnderscorePrefixedVariableName: Exclude: @@ -116,8 +100,6 @@ Lint/UnusedBlockArgument: - 'lib/net/ssh/connection/keepalive.rb' - 'lib/net/ssh/connection/session.rb' - 'lib/net/ssh/service/forward.rb' - - 'quicktest_337.rb' - - 'quicktest_4gb.rb' - 'test/authentication/methods/test_password.rb' - 'test/authentication/test_agent.rb' - 'test/common.rb' @@ -145,7 +127,6 @@ Lint/UselessAssignment: - 'lib/net/ssh/key_factory.rb' - 'lib/net/ssh/proxy/socks4.rb' - 'lib/net/ssh/proxy/socks5.rb' - - 'quicktest_337.rb' - 'test/integration/common.rb' - 'test/integration/test_forward.rb' @@ -555,7 +536,6 @@ Style/ExtraSpacing: - 'lib/net/ssh/proxy/socks5.rb' - 'lib/net/ssh/transport/hmac/sha2_256_96.rb' - 'lib/net/ssh/transport/hmac/sha2_512_96.rb' - - 'quicktest_337.rb' - 'test/authentication/test_key_manager.rb' - 'test/integration/test_forward.rb' - 'test/test_config.rb' @@ -604,7 +584,8 @@ Style/GuardClause: # Configuration parameters: EnforcedStyle, SupportedStyles, UseHashRocketsWithSymbolValues. # SupportedStyles: ruby19, ruby19_no_mixed_keys, hash_rockets Style/HashSyntax: - Enabled: false + Enabled: true + EnforcedStyle: ruby19 # Offense count: 2 Style/IfInsideElse: @@ -666,10 +647,6 @@ Style/InfiniteLoop: # Cop supports --auto-correct. Style/LeadingCommentSpace: Exclude: - - 'quicktest.rb' - - 'quicktest_1_open_channel_nb.rb' - - 'quicktest_337.rb' - - 'quicktest_keepalive.rb' - 'test/integration/test_ed25519_pkeys.rb' - 'test/integration/test_forward.rb' - 'test/integration/test_id_rsa_keys.rb' @@ -689,7 +666,6 @@ Style/LineEndConcatenation: # Cop supports --auto-correct. Style/MethodCallParentheses: Exclude: - - 'quicktest_337.rb' - 'test/authentication/test_key_manager.rb' - 'test/connection/test_session.rb' - 'test/integration/test_forward.rb' @@ -899,7 +875,6 @@ Style/RescueModifier: Style/SelfAssignment: Exclude: - 'lib/net/ssh/config.rb' - - 'quicktest_337.rb' # Offense count: 10 # Cop supports --auto-correct. @@ -907,7 +882,6 @@ Style/SelfAssignment: Style/Semicolon: Exclude: - 'lib/net/ssh/buffer.rb' - - 'quicktest_337.rb' - 'test/connection/test_channel.rb' - 'test/connection/test_session.rb' - 'test/transport/kex/test_ecdh_sha2_nistp256.rb' @@ -933,7 +907,6 @@ Style/SingleLineMethods: Style/SpaceAfterColon: Exclude: - 'lib/net/ssh/authentication/ed25519.rb' - - 'quicktest_keepalive.rb' - 'test/integration/test_ed25519_pkeys.rb' - 'test/verifiers/test_secure.rb' @@ -978,12 +951,6 @@ Style/SpaceBeforeFirstArg: - 'lib/net/ssh/transport/hmac/sha2_512_96.rb' - 'test/authentication/test_key_manager.rb' -# Offense count: 1 -# Cop supports --auto-correct. -Style/SpaceBeforeSemicolon: - Exclude: - - 'quicktest_337.rb' - # Offense count: 30 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters. @@ -22,7 +22,7 @@ Rake::Task[:release].enhance [:check_NET_SSH_BUILDGEM_SIGNED] Rake::Task[:release].prerequisites.unshift(:check_NET_SSH_BUILDGEM_SIGNED) -task :default => ["build"] +task default: ["build"] CLEAN.include [ 'pkg', 'rdoc' ] name = "net-ssh" diff --git a/lib/net/ssh/authentication/key_manager.rb b/lib/net/ssh/authentication/key_manager.rb index 31a613d..f324b7c 100644 --- a/lib/net/ssh/authentication/key_manager.rb +++ b/lib/net/ssh/authentication/key_manager.rb @@ -108,7 +108,7 @@ module Net user_identities.delete(corresponding_user_identity) if corresponding_user_identity if !options[:keys_only] || corresponding_user_identity - known_identities[key] = { :from => :agent } + known_identities[key] = { from: :agent } yield key end end @@ -208,7 +208,7 @@ module Net # Prepared identities from user key_data, preserving their order and sources. def prepare_identities_from_data key_data.map do |data| - { :load_from => :data, :data => data } + { load_from: :data, data: data } end end @@ -219,15 +219,15 @@ module Net case identity[:load_from] when :pubkey_file key = KeyFactory.load_public_key(identity[:pubkey_file]) - { :public_key => key, :from => :file, :file => identity[:privkey_file] } + { public_key: key, from: :file, file: identity[:privkey_file] } when :privkey_file private_key = KeyFactory.load_private_key(identity[:privkey_file], options[:passphrase], ask_passphrase, options[:password_prompt]) key = private_key.send(:public_key) - { :public_key => key, :from => :file, :file => identity[:privkey_file], :key => private_key } + { public_key: key, from: :file, file: identity[:privkey_file], key: private_key } when :data private_key = KeyFactory.load_data_private_key(identity[:data], options[:passphrase], ask_passphrase, "<key in memory>", options[:password_prompt]) key = private_key.send(:public_key) - { :public_key => key, :from => :key_data, :data => identity[:data], :key => private_key } + { public_key: key, from: :key_data, data: identity[:data], key: private_key } else identity end diff --git a/lib/net/ssh/config.rb b/lib/net/ssh/config.rb index 4a01e8b..4d8cf77 100644 --- a/lib/net/ssh/config.rb +++ b/lib/net/ssh/config.rb @@ -144,7 +144,7 @@ module Net; module SSH def translate(settings) auth_methods = default_auth_methods.clone (auth_methods << 'challenge-response').uniq! - ret = settings.inject({:auth_methods=>auth_methods}) do |hash, (key, value)| + ret = settings.inject({auth_methods: auth_methods}) do |hash, (key, value)| case key when 'bindaddress' then hash[:bind_address] = value diff --git a/lib/net/ssh/connection/channel.rb b/lib/net/ssh/connection/channel.rb index f29affd..e3a2426 100644 --- a/lib/net/ssh/connection/channel.rb +++ b/lib/net/ssh/connection/channel.rb @@ -189,12 +189,12 @@ module Net; module SSH; module Connection end # A hash of the valid PTY options (see #request_pty). - VALID_PTY_OPTIONS = { :term => "xterm", - :chars_wide => 80, - :chars_high => 24, - :pixels_wide => 640, - :pixels_high => 480, - :modes => {} } + VALID_PTY_OPTIONS = { term: "xterm", + chars_wide: 80, + chars_high: 24, + pixels_wide: 640, + pixels_high: 480, + modes: {} } # Requests that a pseudo-tty (or "pty") be made available for this channel. # This is useful when you want to invoke and interact with some kind of diff --git a/lib/net/ssh/key_factory.rb b/lib/net/ssh/key_factory.rb index a830dbc..93ea6a6 100644 --- a/lib/net/ssh/key_factory.rb +++ b/lib/net/ssh/key_factory.rb @@ -37,7 +37,7 @@ module Net; module SSH # whether the file describes an RSA or DSA key, and will load it # appropriately. The new key is returned. If the key itself is # encrypted (requiring a passphrase to use), the user will be - # prompted to enter their password unless passphrase works. + # prompted to enter their password unless passphrase works. def load_private_key(filename, passphrase=nil, ask_passphrase=true, prompt=Prompt.default) data = File.read(File.expand_path(filename)) load_data_private_key(data, passphrase, ask_passphrase, filename, prompt) @@ -47,7 +47,7 @@ module Net; module SSH # whether the file describes an RSA or DSA key, and will load it # appropriately. The new key is returned. If the key itself is # encrypted (requiring a passphrase to use), the user will be - # prompted to enter their password unless passphrase works. + # prompted to enter their password unless passphrase works. def load_data_private_key(data, passphrase=nil, ask_passphrase=true, filename="", prompt=Prompt.default) key_read, error_classes = classify_key(data, filename) @@ -55,7 +55,7 @@ module Net; module SSH tries = 0 prompter = nil - result = + result = begin key_read[data, passphrase || 'invalid'] rescue *error_classes diff --git a/lib/net/ssh/proxy/http.rb b/lib/net/ssh/proxy/http.rb index 5d64173..49b1695 100644 --- a/lib/net/ssh/proxy/http.rb +++ b/lib/net/ssh/proxy/http.rb @@ -87,11 +87,11 @@ module Net; module SSH; module Proxy body = socket.read(headers["Content-Length"].to_i) end - return { :version => version, - :code => code.to_i, - :reason => reason, - :headers => headers, - :body => body } + return { version: version, + code: code.to_i, + reason: reason, + headers: headers, + body: body } end end diff --git a/lib/net/ssh/test.rb b/lib/net/ssh/test.rb index 3e4677d..cd623a8 100644 --- a/lib/net/ssh/test.rb +++ b/lib/net/ssh/test.rb @@ -71,7 +71,7 @@ module Net; module SSH # in these tests. It is a fully functional SSH transport session, operating # over a mock socket (#socket). def transport(options={}) - @transport ||= Net::SSH::Transport::Session.new(options[:host] || "localhost", options.merge(:kex => "test", :host_key => "ssh-rsa", :paranoid => false, :proxy => socket(options))) + @transport ||= Net::SSH::Transport::Session.new(options[:host] || "localhost", options.merge(kex: "test", host_key: "ssh-rsa", paranoid: false, proxy: socket(options))) end # First asserts that a story has been described (see #story). Then yields, diff --git a/lib/net/ssh/test/kex.rb b/lib/net/ssh/test/kex.rb index fc13095..0ed873f 100644 --- a/lib/net/ssh/test/kex.rb +++ b/lib/net/ssh/test/kex.rb @@ -31,10 +31,10 @@ module Net; module SSH; module Test buffer = @connection.next_message raise Net::SSH::Exception, "expected NEWKEYS" unless buffer.type == NEWKEYS - { :session_id => "abc-xyz", - :server_key => OpenSSL::PKey::RSA.new(512), - :shared_secret => OpenSSL::BN.new("1234567890", 10), - :hashing_algorithm => OpenSSL::Digest::SHA1 } + { session_id: "abc-xyz", + server_key: OpenSSL::PKey::RSA.new(512), + shared_secret: OpenSSL::BN.new("1234567890", 10), + hashing_algorithm: OpenSSL::Digest::SHA1 } end end diff --git a/lib/net/ssh/transport/algorithms.rb b/lib/net/ssh/transport/algorithms.rb index ae1a1dc..7e941a6 100644 --- a/lib/net/ssh/transport/algorithms.rb +++ b/lib/net/ssh/transport/algorithms.rb @@ -23,27 +23,27 @@ module Net; module SSH; module Transport # Define the default algorithms, in order of preference, supported by # Net::SSH. ALGORITHMS = { - :host_key => %w(ssh-rsa ssh-dss - ssh-rsa-cert-v01@openssh.com - ssh-rsa-cert-v00@openssh.com), - :kex => %w(diffie-hellman-group-exchange-sha1 - diffie-hellman-group1-sha1 - diffie-hellman-group14-sha1 - diffie-hellman-group-exchange-sha256), - :encryption => %w(aes128-cbc 3des-cbc blowfish-cbc cast128-cbc - aes192-cbc aes256-cbc rijndael-cbc@lysator.liu.se - idea-cbc none arcfour128 arcfour256 arcfour - aes128-ctr aes192-ctr aes256-ctr - cast128-ctr blowfish-ctr 3des-ctr + host_key: %w(ssh-rsa ssh-dss + ssh-rsa-cert-v01@openssh.com + ssh-rsa-cert-v00@openssh.com), + kex: %w(diffie-hellman-group-exchange-sha1 + diffie-hellman-group1-sha1 + diffie-hellman-group14-sha1 + diffie-hellman-group-exchange-sha256), + encryption: %w(aes128-cbc 3des-cbc blowfish-cbc cast128-cbc + aes192-cbc aes256-cbc rijndael-cbc@lysator.liu.se + idea-cbc none arcfour128 arcfour256 arcfour + aes128-ctr aes192-ctr aes256-ctr + cast128-ctr blowfish-ctr 3des-ctr ), - :hmac => %w(hmac-sha1 hmac-md5 hmac-sha1-96 hmac-md5-96 - hmac-ripemd160 hmac-ripemd160@openssh.com - hmac-sha2-256 hmac-sha2-512 hmac-sha2-256-96 - hmac-sha2-512-96 none), + hmac: %w(hmac-sha1 hmac-md5 hmac-sha1-96 hmac-md5-96 + hmac-ripemd160 hmac-ripemd160@openssh.com + hmac-sha2-256 hmac-sha2-512 hmac-sha2-256-96 + hmac-sha2-512-96 none), - :compression => %w(none zlib@openssh.com zlib), - :language => %w() + compression: %w(none zlib@openssh.com zlib), + language: %w() } if defined?(OpenSSL::PKey::EC) ALGORITHMS[:host_key] += %w(ecdsa-sha2-nistp256 @@ -255,7 +255,7 @@ module Net; module SSH; module Transport # Parses a KEXINIT packet from the server. def parse_server_algorithm_packet(packet) - data = { :raw => packet.content } + data = { raw: packet.content } packet.read(16) # skip the cookie value @@ -356,13 +356,13 @@ module Net; module SSH; module Transport debug { "exchanging keys" } algorithm = Kex::MAP[kex].new(self, session, - :client_version_string => Net::SSH::Transport::ServerVersion::PROTO_VERSION, - :server_version_string => session.server_version.version, - :server_algorithm_packet => @server_packet, - :client_algorithm_packet => @client_packet, - :need_bytes => kex_byte_requirement, - :minimum_dh_bits => options[:minimum_dh_bits], - :logger => logger) + client_version_string: Net::SSH::Transport::ServerVersion::PROTO_VERSION, + server_version_string: session.server_version.version, + server_algorithm_packet: @server_packet, + client_algorithm_packet: @client_packet, + need_bytes: kex_byte_requirement, + minimum_dh_bits: options[:minimum_dh_bits], + logger: logger) result = algorithm.exchange_keys secret = result[:shared_secret].to_ssh @@ -372,7 +372,7 @@ module Net; module SSH; module Transport @session_id ||= hash key = Proc.new { |salt| digester.digest(secret + hash + salt + @session_id) } - + iv_client = key["A"] iv_server = key["B"] key_client = key["C"] @@ -380,26 +380,26 @@ module Net; module SSH; module Transport mac_key_client = key["E"] mac_key_server = key["F"] - parameters = { :shared => secret, :hash => hash, :digester => digester } - - cipher_client = CipherFactory.get(encryption_client, parameters.merge(:iv => iv_client, :key => key_client, :encrypt => true)) - cipher_server = CipherFactory.get(encryption_server, parameters.merge(:iv => iv_server, :key => key_server, :decrypt => true)) + parameters = { shared: secret, hash: hash, digester: digester } + + cipher_client = CipherFactory.get(encryption_client, parameters.merge(iv: iv_client, key: key_client, encrypt: true)) + cipher_server = CipherFactory.get(encryption_server, parameters.merge(iv: iv_server, key: key_server, decrypt: true)) mac_client = HMAC.get(hmac_client, mac_key_client, parameters) mac_server = HMAC.get(hmac_server, mac_key_server, parameters) - session.configure_client :cipher => cipher_client, :hmac => mac_client, - :compression => normalize_compression_name(compression_client), - :compression_level => options[:compression_level], - :rekey_limit => options[:rekey_limit], - :max_packets => options[:rekey_packet_limit], - :max_blocks => options[:rekey_blocks_limit] - - session.configure_server :cipher => cipher_server, :hmac => mac_server, - :compression => normalize_compression_name(compression_server), - :rekey_limit => options[:rekey_limit], - :max_packets => options[:rekey_packet_limit], - :max_blocks => options[:rekey_blocks_limit] + session.configure_client cipher: cipher_client, hmac: mac_client, + compression: normalize_compression_name(compression_client), + compression_level: options[:compression_level], + rekey_limit: options[:rekey_limit], + max_packets: options[:rekey_packet_limit], + max_blocks: options[:rekey_blocks_limit] + + session.configure_server cipher: cipher_server, hmac: mac_server, + compression: normalize_compression_name(compression_server), + rekey_limit: options[:rekey_limit], + max_packets: options[:rekey_packet_limit], + max_blocks: options[:rekey_blocks_limit] @initialized = true end diff --git a/lib/net/ssh/transport/kex/diffie_hellman_group1_sha1.rb b/lib/net/ssh/transport/kex/diffie_hellman_group1_sha1.rb index 7379e01..8c808d3 100644 --- a/lib/net/ssh/transport/kex/diffie_hellman_group1_sha1.rb +++ b/lib/net/ssh/transport/kex/diffie_hellman_group1_sha1.rb @@ -69,10 +69,10 @@ module Net; module SSH; module Transport; module Kex session_id = verify_signature(result) confirm_newkeys - return { :session_id => session_id, - :server_key => result[:server_key], - :shared_secret => result[:shared_secret], - :hashing_algorithm => digester } + return { session_id: session_id, + server_key: result[:server_key], + shared_secret: result[:shared_secret], + hashing_algorithm: digester } end private @@ -170,7 +170,7 @@ module Net; module SSH; module Transport; module Kex blob, fingerprint = generate_key_fingerprint(key) - unless connection.host_key_verifier.verify(:key => key, :key_blob => blob, :fingerprint => fingerprint, :session => connection) + unless connection.host_key_verifier.verify(key: key, key_blob: blob, fingerprint: fingerprint, session: connection) raise Net::SSH::Exception, "host key verification failed" end end diff --git a/lib/net/ssh/transport/session.rb b/lib/net/ssh/transport/session.rb index f4905a6..cb9a3cc 100644 --- a/lib/net/ssh/transport/session.rb +++ b/lib/net/ssh/transport/session.rb @@ -164,7 +164,7 @@ module Net; module SSH; module Transport # Returns a hash of information about the peer (remote) side of the socket, # including :ip, :port, :host, and :canonized (see #host_as_string). def peer - @peer ||= { :ip => socket.peer_ip, :port => @port.to_i, :host => @host, :canonized => host_as_string } + @peer ||= { ip: socket.peer_ip, port: @port.to_i, host: @host, canonized: host_as_string } end # Blocks until a new packet is available to be read, and returns that diff --git a/support/arcfour_check.rb b/support/arcfour_check.rb index a823a1f..142bd26 100644 --- a/support/arcfour_check.rb +++ b/support/arcfour_check.rb @@ -14,7 +14,7 @@ require 'net/ssh' [['arcfour128', 16], ['arcfour256', 32], ['arcfour512', 64]].each do |cipher| print "#{cipher[0]}: " a = Net::SSH::Transport::CipherFactory.get_lengths(cipher[0]) - b = Net::SSH::Transport::CipherFactory.get(cipher[0], :key => ([].fill('x', 0, cipher[1]).join)) + b = Net::SSH::Transport::CipherFactory.get(cipher[0], key: ([].fill('x', 0, cipher[1]).join)) puts "#{a} #{b.class}" end diff --git a/support/ssh_tunnel_bug.rb b/support/ssh_tunnel_bug.rb index abadf4d..ef0db97 100755 --- a/support/ssh_tunnel_bug.rb +++ b/support/ssh_tunnel_bug.rb @@ -37,7 +37,7 @@ pass = ask("Password: ") { |q| q.echo = "*" } puts "Configure your browser proxy to localhost:#{LOCAL_PORT}" begin - session = Net::SSH.start(host, user, :password => pass) + session = Net::SSH.start(host, user, password: pass) session.forward.local(LOCAL_PORT, host, PROXY_PORT) session.loop{true} rescue => e diff --git a/test/authentication/methods/common.rb b/test/authentication/methods/common.rb index 0bfba99..ab5f67c 100644 --- a/test/authentication/methods/common.rb +++ b/test/authentication/methods/common.rb @@ -6,7 +6,7 @@ module Authentication; module Methods private def socket(options={}) - @socket ||= stub("socket", :client_name => "me.ssh.test") + @socket ||= stub("socket", client_name: "me.ssh.test") end def transport(options={}) @@ -15,7 +15,7 @@ module Authentication; module Methods def session(options={}) @session ||= begin - sess = stub("auth-session", :logger => nil, :transport => transport(options)) + sess = stub("auth-session", logger: nil, transport: transport(options)) def sess.next_message transport.next_message end diff --git a/test/authentication/methods/test_abstract.rb b/test/authentication/methods/test_abstract.rb index c6a51df..3af9b72 100644 --- a/test/authentication/methods/test_abstract.rb +++ b/test/authentication/methods/test_abstract.rb @@ -12,11 +12,11 @@ module Authentication; module Methods end def test_constructor_should_honor_options - assert_equal :manager, subject(:key_manager => :manager).key_manager + assert_equal :manager, subject(key_manager: :manager).key_manager end def test_session_id_should_query_session_id_from_key_exchange - transport.stubs(:algorithms).returns(stub("algorithms", :session_id => "abcxyz123")) + transport.stubs(:algorithms).returns(stub("algorithms", session_id: "abcxyz123")) assert_equal "abcxyz123", subject.session_id end diff --git a/test/authentication/methods/test_hostbased.rb b/test/authentication/methods/test_hostbased.rb index dc831b1..75e7394 100644 --- a/test/authentication/methods/test_hostbased.rb +++ b/test/authentication/methods/test_hostbased.rb @@ -8,11 +8,11 @@ module Authentication; module Methods include Common def test_authenticate_should_return_false_when_no_key_manager_has_been_set - assert_equal false, subject(:key_manager => nil).authenticate("ssh-connection", "jamis") + assert_equal false, subject(key_manager: nil).authenticate("ssh-connection", "jamis") end def test_authenticate_should_return_false_when_key_manager_has_no_keys - assert_equal false, subject(:keys => []).authenticate("ssh-connection", "jamis") + assert_equal false, subject(keys: []).authenticate("ssh-connection", "jamis") end def test_authenticate_should_return_false_if_no_keys_can_authenticate @@ -92,16 +92,16 @@ module Authentication; module Methods end def socket(options={}) - @socket ||= stub("socket", :client_name => "me.ssh.test") + @socket ||= stub("socket", client_name: "me.ssh.test") end def transport(options={}) - @transport ||= MockTransport.new(options.merge(:socket => socket)) + @transport ||= MockTransport.new(options.merge(socket: socket)) end def session(options={}) @session ||= begin - sess = stub("auth-session", :logger => nil, :transport => transport(options)) + sess = stub("auth-session", logger: nil, transport: transport(options)) def sess.next_message transport.next_message end diff --git a/test/authentication/methods/test_publickey.rb b/test/authentication/methods/test_publickey.rb index d9c7434..1d63b96 100644 --- a/test/authentication/methods/test_publickey.rb +++ b/test/authentication/methods/test_publickey.rb @@ -8,11 +8,11 @@ module Authentication; module Methods include Common def test_authenticate_should_return_false_when_no_key_manager_has_been_set - assert_equal false, subject(:key_manager => nil).authenticate("ssh-connection", "jamis") + assert_equal false, subject(key_manager: nil).authenticate("ssh-connection", "jamis") end def test_authenticate_should_return_false_when_key_manager_has_no_keys - assert_equal false, subject(:keys => []).authenticate("ssh-connection", "jamis") + assert_equal false, subject(keys: []).authenticate("ssh-connection", "jamis") end def test_authenticate_should_return_false_if_no_keys_can_authenticate diff --git a/test/authentication/test_agent.rb b/test/authentication/test_agent.rb index 9f0c54a..eb16f90 100644 --- a/test/authentication/test_agent.rb +++ b/test/authentication/test_agent.rb @@ -212,7 +212,7 @@ module Authentication end def factory - @factory ||= stub("socket factory", :open => socket) + @factory ||= stub("socket factory", open: socket) end def agent(auto=:connect) diff --git a/test/authentication/test_key_manager.rb b/test/authentication/test_key_manager.rb index 080e1ec..7c51d75 100644 --- a/test/authentication/test_key_manager.rb +++ b/test/authentication/test_key_manager.rb @@ -35,7 +35,7 @@ module Authentication end def test_agent_should_not_be_used_with_no_agent - assert !manager(:use_agent => false).use_agent? + assert !manager(use_agent: false).use_agent? end def test_each_identity_should_load_from_key_files @@ -52,14 +52,14 @@ module Authentication assert_equal rsa.to_blob, identities.first.to_blob assert_equal dsa.to_blob, identities.last.to_blob - assert_equal({:from => :file, :file => first, :key => rsa}, manager.known_identities[rsa]) - assert_equal({:from => :file, :file => second, :key => dsa}, manager.known_identities[dsa]) + assert_equal({from: :file, file: first, key: rsa}, manager.known_identities[rsa]) + assert_equal({from: :file, file: second, key: dsa}, manager.known_identities[dsa]) end def test_each_identity_should_not_prompt_for_passphrase_in_non_interactive_mode - manager(:non_interactive => true).stubs(:agent).returns(nil) + manager(non_interactive: true).stubs(:agent).returns(nil) first = File.expand_path("/first") - stub_file_private_key first, rsa, :passphrase => :should_not_be_asked + stub_file_private_key first, rsa, passphrase: :should_not_be_asked identities = [] manager.each_identity { |identity| identities << identity } assert_equal(identities, []) @@ -75,8 +75,8 @@ module Authentication assert_equal rsa.to_blob, identities.first.to_blob assert_equal dsa.to_blob, identities.last.to_blob - assert_equal({:from => :agent}, manager.known_identities[rsa]) - assert_equal({:from => :agent}, manager.known_identities[dsa]) + assert_equal({from: :agent}, manager.known_identities[rsa]) + assert_equal({from: :agent}, manager.known_identities[dsa]) end if defined?(OpenSSL::PKey::EC) @@ -93,16 +93,16 @@ module Authentication assert_equal ecdsa_sha2_nistp384.to_blob, identities[3].to_blob assert_equal ecdsa_sha2_nistp521.to_blob, identities[4].to_blob - assert_equal({:from => :agent}, manager.known_identities[rsa]) - assert_equal({:from => :agent}, manager.known_identities[dsa]) - assert_equal({:from => :agent}, manager.known_identities[ecdsa_sha2_nistp256]) - assert_equal({:from => :agent}, manager.known_identities[ecdsa_sha2_nistp384]) - assert_equal({:from => :agent}, manager.known_identities[ecdsa_sha2_nistp521]) + assert_equal({from: :agent}, manager.known_identities[rsa]) + assert_equal({from: :agent}, manager.known_identities[dsa]) + assert_equal({from: :agent}, manager.known_identities[ecdsa_sha2_nistp256]) + assert_equal({from: :agent}, manager.known_identities[ecdsa_sha2_nistp384]) + assert_equal({from: :agent}, manager.known_identities[ecdsa_sha2_nistp521]) end end def test_only_identities_with_key_files_should_load_from_agent_of_keys_only_set - manager(:keys_only => true).stubs(:agent).returns(agent) + manager(keys_only: true).stubs(:agent).returns(agent) first = File.expand_path("/first") stub_file_private_key first, rsa @@ -113,7 +113,7 @@ module Authentication assert_equal 1, identities.length assert_equal rsa.to_blob, identities.first.to_blob - assert_equal({:from => :agent}, manager.known_identities[rsa]) + assert_equal({from: :agent}, manager.known_identities[rsa]) assert manager.use_agent? end @@ -123,7 +123,7 @@ module Authentication first = File.expand_path("/first") stub_file_public_key first, rsa second = File.expand_path("/second") - stub_file_private_key second, dsa, :passphrase => :should_not_be_asked + stub_file_private_key second, dsa, passphrase: :should_not_be_asked identities = [] manager.each_identity do |identity| @@ -152,7 +152,7 @@ module Authentication end def test_sign_with_file_originated_key_should_raise_key_manager_error_if_unloadable - manager.known_identities[rsa] = { :from => :file, :file => "/first" } + manager.known_identities[rsa] = { from: :file, file: "/first" } Net::SSH::KeyFactory.expects(:load_private_key).raises(OpenSSL::PKey::RSAError) @@ -221,14 +221,14 @@ module Authentication end def agent - @agent ||= stub("agent", :identities => [rsa, dsa]) + @agent ||= stub("agent", identities: [rsa, dsa]) end def agent_with_ecdsa_keys - @agent ||= stub("agent", :identities => [rsa, dsa, - ecdsa_sha2_nistp256, - ecdsa_sha2_nistp384, - ecdsa_sha2_nistp521]) + @agent ||= stub("agent", identities: [rsa, dsa, + ecdsa_sha2_nistp256, + ecdsa_sha2_nistp384, + ecdsa_sha2_nistp521]) end def prompt diff --git a/test/common.rb b/test/common.rb index 02b5b6d..e84a624 100644 --- a/test/common.rb +++ b/test/common.rb @@ -91,12 +91,12 @@ class MockTransport < Net::SSH::Transport::Session @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") + self.server_version = OpenStruct.new(version: "SSH-2.0-Ruby/Net::SSH::Test") @expectation = nil @queue = [] @hints = {} @socket = options[:socket] - @algorithms = OpenStruct.new(:session_id => "abcxyz123") + @algorithms = OpenStruct.new(session_id: "abcxyz123") verifier { |data| true } end diff --git a/test/connection/test_channel.rb b/test/connection/test_channel.rb index 7d3ab6a..5273b17 100644 --- a/test/connection/test_channel.rb +++ b/test/connection/test_channel.rb @@ -37,7 +37,7 @@ module Connection def test_request_pty_with_invalid_option_should_raise_error assert_raises(ArgumentError) do - channel.request_pty(:bogus => "thing") + channel.request_pty(bogus: "thing") end end @@ -52,8 +52,8 @@ module Connection def test_request_pty_with_options_should_honor_options channel.expects(:send_channel_request).with("pty-req", :string, "vanilla", :long, 60, :long, 15, :long, 400, :long, 200, :string, "\5\0\0\0\1\0") - channel.request_pty :term => "vanilla", :chars_wide => 60, :chars_high => 15, - :pixels_wide => 400, :pixels_high => 200, :modes => { 5 => 1 } + channel.request_pty term: "vanilla", chars_wide: 60, chars_high: 15, + pixels_wide: 400, pixels_high: 200, modes: { 5 => 1 } end def test_send_data_should_append_to_channels_output_buffer @@ -304,7 +304,7 @@ module Connection end def test_do_open_confirmation_with_session_channel_should_invoke_agent_forwarding_if_agent_forwarding_requested - connection :forward_agent => true + connection forward_agent: true forward = mock("forward") forward.expects(:agent).with(channel) connection.expects(:forward).returns(forward) @@ -312,8 +312,8 @@ module Connection end def test_do_open_confirmation_with_non_session_channel_should_not_invoke_agent_forwarding_even_if_agent_forwarding_requested - connection :forward_agent => true - channel :type => "direct-tcpip" + connection forward_agent: true + channel type: "direct-tcpip" connection.expects(:forward).never channel.do_open_confirmation(1,2,3) end diff --git a/test/connection/test_session.rb b/test/connection/test_session.rb index 32b795e..eba1ddf 100644 --- a/test/connection/test_session.rb +++ b/test/connection/test_session.rb @@ -33,7 +33,7 @@ module Connection end def test_listen_to_should_add_argument_to_listeners_list_if_block_is_given - io = stub("io", :pending_write? => true) + io = stub("io", pending_write?: true) flag = false session.listen_to(io) { flag = true } assert !flag, "callback should not be invoked immediately" @@ -43,7 +43,7 @@ module Connection end def test_stop_listening_to_should_remove_argument_from_listeners - io = stub("io", :pending_write? => true) + io = stub("io", pending_write?: true) session.listen_to(io) assert session.listeners.key?(io) @@ -111,14 +111,14 @@ module Connection end def test_process_should_exit_immediately_if_block_is_false - session.channels[0] = stub("channel", :closing? => false) + session.channels[0] = stub("channel", closing?: false) session.channels[0].expects(:process).never process_times(0) end def test_can_open_channels_in_process # see #110 chid = session.send(:get_next_channel_id) - session.channels[chid] = stub("channel", :local_closed? => false) + session.channels[chid] = stub("channel", local_closed?: false) session.channels[chid].expects(:process).with() do session.open_channel true @@ -128,14 +128,14 @@ module Connection end def test_process_should_exit_after_processing_if_block_is_true_then_false - session.channels[0] = stub("channel", :local_closed? => false) + session.channels[0] = stub("channel", local_closed?: false) session.channels[0].expects(:process) IO.expects(:select).never process_times(2) end def test_process_should_not_process_channels_that_are_closing - session.channels[0] = stub("channel", :local_closed? => true) + session.channels[0] = stub("channel", local_closed?: true) session.channels[0].expects(:process).never IO.expects(:select).never process_times(2) @@ -362,7 +362,7 @@ module Connection end def test_ready_readers_that_are_registered_with_a_block_should_call_block_instead_of_fill - io = stub("io", :pending_write? => false) + io = stub("io", pending_write?: false) flag = false session.stop_listening_to(socket) # so that we only have to test the presence of a single IO object session.listen_to(io) { flag = true } @@ -386,7 +386,7 @@ module Connection def test_process_should_call_enqueue_message_if_io_select_timed_out timeout = Net::SSH::Connection::Session::DEFAULT_IO_SELECT_TIMEOUT - options = { :keepalive => true } + options = { keepalive: true } expected_packet = P(:byte, Net::SSH::Packet::GLOBAL_REQUEST, :string, "keepalive@openssh.com", :bool, true) IO.stubs(:select).with([socket],[],nil,timeout).returns(nil) transport.expects(:enqueue_message).with{ |msg| msg.content == expected_packet.content } @@ -395,7 +395,7 @@ module Connection def test_process_should_raise_if_keepalives_not_answered timeout = Net::SSH::Connection::Session::DEFAULT_IO_SELECT_TIMEOUT - options = { :keepalive => true, :keepalive_interval => 300, :keepalive_maxcount => 3 } + options = { keepalive: true, keepalive_interval: 300, keepalive_maxcount: 3 } expected_packet = P(:byte, Net::SSH::Packet::GLOBAL_REQUEST, :string, "keepalive@openssh.com", :bool, true) [1,2,3].each do |i| Time.stubs(:now).returns(Time.at(i*300)) @@ -412,7 +412,7 @@ module Connection def test_process_should_not_call_enqueue_message_unless_io_select_timed_out timeout = Net::SSH::Connection::Session::DEFAULT_IO_SELECT_TIMEOUT - options = { :keepalive => true } + options = { keepalive: true } IO.stubs(:select).with([socket],[],nil,timeout).returns([[socket],[],[]]) socket.stubs(:recv).returns("x") transport.expects(:enqueue_message).never @@ -421,7 +421,7 @@ module Connection def test_process_should_not_call_enqueue_message_unless_keepalive_interval_not_go_on timeout = 10 - options = { :keepalive => true, :keepalive_interval => timeout } + options = { keepalive: true, keepalive_interval: timeout } Time.stubs(:now).returns(Time.at(0), Time.at(9), Time.at(timeout)) IO.stubs(:select).with([socket],[],nil,timeout).returns(nil) transport.expects(:enqueue_message).times(2) @@ -435,7 +435,7 @@ module Connection def test_process_should_call_io_select_with_interval_as_last_arg_if_keepalive_interval_passed timeout = 10 - options = { :keepalive => true, :keepalive_interval => timeout } + options = { keepalive: true, keepalive_interval: timeout } IO.expects(:select).with([socket],[],nil,timeout).returns([[],[],[]]) session(options).process end @@ -443,7 +443,7 @@ module Connection def test_process_should_call_io_select_with_wait_if_provided_and_minimum timeout = 10 wait = 5 - options = { :keepalive => true, :keepalive_interval => timeout } + options = { keepalive: true, keepalive_interval: timeout } IO.expects(:select).with([socket],[],nil,wait).returns([[],[],[]]) session(options).process(wait) end @@ -509,7 +509,7 @@ module Connection end def test_max_select_wait_time_should_return_keepalive_interval_when_keepalive_enabled - options = { :keepalive => true, :keepalive_interval => 5 } + options = { keepalive: true, keepalive_interval: 5 } assert_equal 5, session(options).max_select_wait_time end @@ -566,11 +566,11 @@ module Connection end def channel_at(local_id) - session.channels[local_id] = stub("channel", :process => true, :local_closed? => false) + session.channels[local_id] = stub("channel", process: true, local_closed?: false) end def transport(options={}) - @transport ||= MockTransport.new(options.merge(:socket => socket)) + @transport ||= MockTransport.new(options.merge(socket: socket)) end def session(options={}) diff --git a/test/integration/test_channel.rb b/test/integration/test_channel.rb index 776843d..7307df8 100644 --- a/test/integration/test_channel.rb +++ b/test/integration/test_channel.rb @@ -17,7 +17,7 @@ class TestChannel < NetSSHTest end def ssh_start_params(options = {}) - [localhost, user, {:keys => @key_id_rsa}.merge(options)] + [localhost, user, {keys: @key_id_rsa}.merge(options)] end def setup_ssh_env(&block) diff --git a/test/integration/test_ed25519_pkeys.rb b/test/integration/test_ed25519_pkeys.rb index dab5c80..dd3eb42 100644 --- a/test/integration/test_ed25519_pkeys.rb +++ b/test/integration/test_ed25519_pkeys.rb @@ -19,7 +19,7 @@ class TestED25519PKeys < NetSSHTest # TODO: fix bug in net ssh which reads public key even if private key is there sh "mv #{dir}/id_rsa_ed25519.pub #{dir}/id_rsa_ed25519.pub.hidden" - + #sshopts = '-vvvv -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' #sh "ssh -i #{dir}/id_rsa_ed25519 #{sshopts} net_ssh_1@localhost echo 'hello'" diff --git a/test/integration/test_forward.rb b/test/integration/test_forward.rb index e07fe16..a913535 100644 --- a/test/integration/test_forward.rb +++ b/test/integration/test_forward.rb @@ -33,7 +33,7 @@ class TestForward < NetSSHTest end def ssh_start_params(options = {}) - [localhost ,user , {:keys => @key_id_rsa}.merge(options)] + [localhost ,user , {keys: @key_id_rsa}.merge(options)] end def setup_ssh_env(&block) diff --git a/test/integration/test_http_proxy.rb b/test/integration/test_http_proxy.rb index 431dba8..d35421d 100644 --- a/test/integration/test_http_proxy.rb +++ b/test/integration/test_http_proxy.rb @@ -23,7 +23,7 @@ class TestHTTPProxy < NetSSHTest end def ssh_start_params(options) - [localhost, user, {:keys => @key_id_rsa}.merge(options)] + [localhost, user, {keys: @key_id_rsa}.merge(options)] end def setup_ssh_env(&block) @@ -50,7 +50,7 @@ class TestHTTPProxy < NetSSHTest setup_ssh_env do with_http_proxy_server do |http_proxy| msg = 'echo123' - ret = Net::SSH.start(*ssh_start_params(:proxy => Net::SSH::Proxy::HTTP.new('localhost', http_proxy.config[:Port]))) do |ssh| + ret = Net::SSH.start(*ssh_start_params(proxy: Net::SSH::Proxy::HTTP.new('localhost', http_proxy.config[:Port]))) do |ssh| ssh.exec! "echo \"$USER:#{msg}\"" end assert_equal "net_ssh_1:#{msg}\n", ret @@ -73,7 +73,7 @@ class TestHTTPProxy < NetSSHTest setup_ssh_env do with_http_tls_proxy_server do |http_proxy| msg = 'echo123' - ret = Net::SSH.start(*ssh_start_params(:proxy => Net::SSH::Proxy::HTTPS.new('localhost', http_proxy.config[:Port]))) do |ssh| + ret = Net::SSH.start(*ssh_start_params(proxy: Net::SSH::Proxy::HTTPS.new('localhost', http_proxy.config[:Port]))) do |ssh| ssh.exec! "echo \"$USER:#{msg}\"" end assert_equal "net_ssh_1:#{msg}\n", ret diff --git a/test/integration/test_proxy.rb b/test/integration/test_proxy.rb index 8c54388..0310df1 100644 --- a/test/integration/test_proxy.rb +++ b/test/integration/test_proxy.rb @@ -17,7 +17,7 @@ class TestProxy < NetSSHTest end def ssh_start_params(options) - [localhost ,user , {:keys => @key_id_rsa}.merge(options)] + [localhost ,user , {keys: @key_id_rsa}.merge(options)] end def setup_ssh_env(&block) @@ -34,7 +34,7 @@ class TestProxy < NetSSHTest setup_ssh_env do proxy = Net::SSH::Proxy::Command.new("/bin/nc localhost 22") msg = 'echo123' - ret = Net::SSH.start(*ssh_start_params(:proxy => proxy)) do |ssh| + ret = Net::SSH.start(*ssh_start_params(proxy: proxy)) do |ssh| ssh.exec! "echo \"$USER:#{msg}\"" end assert_equal "net_ssh_1:#{msg}\n", ret @@ -71,7 +71,7 @@ class TestProxy < NetSSHTest #proxy = Net::SSH::Proxy::Command.new("/bin/nc localhost 22") begin large_msg = 'echo123'*30000 - ok = Net::SSH.start(*ssh_start_params(:proxy => proxy)) do |ssh| + ok = Net::SSH.start(*ssh_start_params(proxy: proxy)) do |ssh| with_spurious_write_wakeup_emulate do ret = ssh.exec! "echo \"$USER:#{large_msg}\"" #assert_equal "net_ssh_1:#{large_msg}\n", ret diff --git a/test/start/test_connection.rb b/test/start/test_connection.rb index 3334f73..ab7175d 100644 --- a/test/start/test_connection.rb +++ b/test/start/test_connection.rb @@ -11,7 +11,7 @@ module NetSSH Net::SSH::Authentication::Session.stubs(:new).returns(authentication_session) Net::SSH::Transport::Session.stubs(:new).returns(mock('transport_session')) @connection_session = mock('connection_session') - Net::SSH::Connection::Session.expects(:new => connection_session) + Net::SSH::Connection::Session.expects(new: connection_session) end def test_close_connection_on_exception diff --git a/test/start/test_options.rb b/test/start/test_options.rb index b9f7b41..08dace8 100644 --- a/test/start/test_options.rb +++ b/test/start/test_options.rb @@ -13,49 +13,49 @@ module NetSSH def test_start_should_accept_keepalive_option assert_nothing_raised do - options = { :keepalive => true } + options = { keepalive: true } Net::SSH.start('localhost', 'testuser', options) end end def test_start_should_accept_keepalive_interval_option assert_nothing_raised do - options = { :keepalive_interval => 10 } + options = { keepalive_interval: 10 } Net::SSH.start('localhost', 'testuser', options) end end def test_start_should_accept_send_env_option assert_nothing_raised do - options = { :send_env => [ /^LC_.*$/, "LANG" ] } + options = { send_env: [ /^LC_.*$/, "LANG" ] } Net::SSH.start('localhost', 'testuser', options) end end def test_start_should_accept_number_of_password_prompts_option assert_nothing_raised do - options = { :number_of_password_prompts => 2 } + options = { number_of_password_prompts: 2 } Net::SSH.start('localhost', 'testuser', options) end end def test_start_should_accept_non_interactive_option assert_nothing_raised do - options = { :non_interactive => true } + options = { non_interactive: true } Net::SSH.start('localhost', 'testuser', options) end end def test_start_should_accept_remote_user_option assert_nothing_raised do - options = { :remote_user => 'foo' } + options = { remote_user: 'foo' } Net::SSH.start('localhost', 'testuser', options) end end def test_constructor_should_reject_options_set_to_nil assert_raises(ArgumentError) do - options = { :remote_user => nil } + options = { remote_user: nil } Net::SSH.start('localhost', 'testuser', options) end end @@ -69,13 +69,13 @@ module NetSSH def test_constructor_should_reject_invalid_options assert_raises(ArgumentError) do - options = { :some_invalid_option => "some setting" } + options = { some_invalid_option: "some setting" } Net::SSH.start('localhost', 'testuser', options) end end def test_constructor_should_set_default_options - options = { :logger => nil, :password_prompt => nil } + options = { logger: nil, password_prompt: nil } Net::SSH.start('localhost', 'testuser', options) assert !options[:logger].nil? assert !options[:password_prompt].nil? diff --git a/test/start/test_transport.rb b/test/start/test_transport.rb index 9c2b27e..fcf1c4e 100644 --- a/test/start/test_transport.rb +++ b/test/start/test_transport.rb @@ -9,12 +9,12 @@ module NetSSH def setup @transport_session = mock('transport_session') @authentication_session = mock('authentication_session') - Net::SSH::Transport::Session.expects(:new => transport_session) - Net::SSH::Authentication::Session.expects(:new => authentication_session) + Net::SSH::Transport::Session.expects(new: transport_session) + Net::SSH::Authentication::Session.expects(new: authentication_session) end def test_close_transport_when_authentication_fails - authentication_session.expects(:authenticate => false) + authentication_session.expects(authenticate: false) transport_session.expects(:close).at_least_once diff --git a/test/transport/kex/test_diffie_hellman_group1_sha1.rb b/test/transport/kex/test_diffie_hellman_group1_sha1.rb index fad630d..2a0ad16 100644 --- a/test/transport/kex/test_diffie_hellman_group1_sha1.rb +++ b/test/transport/kex/test_diffie_hellman_group1_sha1.rb @@ -30,12 +30,12 @@ module Transport; module Kex end def test_exchange_keys_with_signature_key_type_mismatch_should_raise_exception - assert_raises(Net::SSH::Exception) { exchange! :key_type => "ssh-dss" } + assert_raises(Net::SSH::Exception) { exchange! key_type: "ssh-dss" } end def test_exchange_keys_with_host_key_type_mismatch_should_raise_exception - algorithms :host_key => "ssh-dss" - assert_raises(Net::SSH::Exception) { exchange! :key_type => "ssh-dss" } + algorithms host_key: "ssh-dss" + assert_raises(Net::SSH::Exception) { exchange! key_type: "ssh-dss" } end def test_exchange_keys_when_server_signature_could_not_be_verified_should_raise_exception @@ -84,11 +84,11 @@ module Transport; module Kex end def dh - @dh ||= subject.new(algorithms, connection, packet_data.merge(:need_bytes => 20).merge(@dh_options || {})) + @dh ||= subject.new(algorithms, connection, packet_data.merge(need_bytes: 20).merge(@dh_options || {})) end def algorithms(options={}) - @algorithms ||= OpenStruct.new(:host_key => options[:host_key] || "ssh-rsa") + @algorithms ||= OpenStruct.new(host_key: options[:host_key] || "ssh-rsa") end def connection @@ -106,10 +106,10 @@ module Transport; module Kex end def packet_data - @packet_data ||= { :client_version_string => "client version string", - :server_version_string => "server version string", - :server_algorithm_packet => "server algorithm packet", - :client_algorithm_packet => "client algorithm packet" } + @packet_data ||= { client_version_string: "client version string", + server_version_string: "server version string", + server_algorithm_packet: "server algorithm packet", + client_algorithm_packet: "client algorithm packet" } end def server_dh_pubkey diff --git a/test/transport/kex/test_diffie_hellman_group_exchange_sha1.rb b/test/transport/kex/test_diffie_hellman_group_exchange_sha1.rb index 6ee04e7..6d59f5f 100644 --- a/test/transport/kex/test_diffie_hellman_group_exchange_sha1.rb +++ b/test/transport/kex/test_diffie_hellman_group_exchange_sha1.rb @@ -11,31 +11,31 @@ module Transport; module Kex KEXDH_GEX_REQUEST = 34 def test_exchange_with_fewer_than_minimum_bits_uses_minimum_bits - dh_options :need_bytes => 20 + dh_options need_bytes: 20 assert_equal 1024, need_bits assert_nothing_raised { exchange! } end def test_exchange_with_optional_minimum_bits_declared - dh_options :minimum_dh_bits => 4096 + dh_options minimum_dh_bits: 4096 assert_equal 4096, need_bits assert_nothing_raised { exchange! } end def test_exchange_with_fewer_than_maximum_bits_uses_need_bits - dh_options :need_bytes => 500 + dh_options need_bytes: 500 need_bits(8001) assert_nothing_raised { exchange! } end def test_exchange_with_more_than_maximum_bits_uses_maximum_bits - dh_options :need_bytes => 2000 + dh_options need_bytes: 2000 need_bits(8192) assert_nothing_raised { exchange! } end def test_that_p_and_g_are_provided_by_the_server - assert_nothing_raised { exchange! :p => default_p+2, :g => 3 } + assert_nothing_raised { exchange! p: default_p+2, g: 3 } assert_equal default_p+2, dh.dh.p assert_equal 3, dh.dh.g end diff --git a/test/transport/kex/test_ecdh_sha2_nistp256.rb b/test/transport/kex/test_ecdh_sha2_nistp256.rb index e613b28..b63f0eb 100644 --- a/test/transport/kex/test_ecdh_sha2_nistp256.rb +++ b/test/transport/kex/test_ecdh_sha2_nistp256.rb @@ -32,12 +32,12 @@ else end def test_exchange_keys_with_signature_key_type_mismatch_should_raise_exception - assert_raises(Net::SSH::Exception) { exchange! :key_type => "ssh-dss" } + assert_raises(Net::SSH::Exception) { exchange! key_type: "ssh-dss" } end def test_exchange_keys_with_host_key_type_mismatch_should_raise_exception - algorithms :host_key => "ssh-dss" - assert_raises(Net::SSH::Exception) { exchange! :key_type => "ssh-dss" } + algorithms host_key: "ssh-dss" + assert_raises(Net::SSH::Exception) { exchange! key_type: "ssh-dss" } end def test_exchange_keys_when_server_signature_could_not_be_verified_should_raise_exception @@ -105,7 +105,7 @@ else end def algorithms(options={}) - @algorithms ||= OpenStruct.new(:host_key => options[:server_host_key] || "ecdsa-sha2-nistp256") + @algorithms ||= OpenStruct.new(host_key: options[:server_host_key] || "ecdsa-sha2-nistp256") end def connection @@ -121,10 +121,10 @@ else end def packet_data - @packet_data ||= { :client_version_string => "client version string", - :server_version_string => "server version string", - :server_algorithm_packet => "server algorithm packet", - :client_algorithm_packet => "client algorithm packet" } + @packet_data ||= { client_version_string: "client version string", + server_version_string: "server version string", + server_algorithm_packet: "server algorithm packet", + client_algorithm_packet: "client algorithm packet" } end def server_ecdh_pubkey diff --git a/test/transport/test_algorithms.rb b/test/transport/test_algorithms.rb index d9c4155..610fa4d 100644 --- a/test/transport/test_algorithms.rb +++ b/test/transport/test_algorithms.rb @@ -8,7 +8,7 @@ module Transport def test_allowed_packets (0..255).each do |type| - packet = stub("packet", :type => type) + packet = stub("packet", type: type) case type when 1..4, 6..19, 21..49 then assert(Net::SSH::Transport::Algorithms.allowed_packet?(packet), "#{type} should be allowed during key exchange") else assert(!Net::SSH::Transport::Algorithms.allowed_packet?(packet), "#{type} should not be allowed during key exchange") @@ -36,11 +36,11 @@ module Transport end def test_constructor_with_preferred_host_key_type_should_put_preferred_host_key_type_first - assert_equal %w(ssh-dss ssh-rsa ssh-rsa-cert-v01@openssh.com ssh-rsa-cert-v00@openssh.com)+ec_ed_host_keys, algorithms(:host_key => "ssh-dss", :append_all_supported_algorithms => true)[:host_key] + assert_equal %w(ssh-dss ssh-rsa ssh-rsa-cert-v01@openssh.com ssh-rsa-cert-v00@openssh.com)+ec_ed_host_keys, algorithms(host_key: "ssh-dss", append_all_supported_algorithms: true)[:host_key] end def test_constructor_with_known_hosts_reporting_known_host_key_should_use_that_host_key_type - Net::SSH::KnownHosts.expects(:search_for).with("net.ssh.test,127.0.0.1", {}).returns([stub("key", :ssh_type => "ssh-dss")]) + Net::SSH::KnownHosts.expects(:search_for).with("net.ssh.test,127.0.0.1", {}).returns([stub("key", ssh_type: "ssh-dss")]) assert_equal %w(ssh-dss ssh-rsa ssh-rsa-cert-v01@openssh.com ssh-rsa-cert-v00@openssh.com )+ec_ed_host_keys, algorithms[:host_key] end @@ -65,7 +65,7 @@ module Transport end def test_constructor_with_unrecognized_host_key_type_should_return_whats_supported - assert_equal %w(ssh-rsa ssh-dss ssh-rsa-cert-v01@openssh.com ssh-rsa-cert-v00@openssh.com )+ec_ed_host_keys, algorithms(:host_key => "bogus ssh-rsa",:append_all_supported_algorithms => true)[:host_key] + assert_equal %w(ssh-rsa ssh-dss ssh-rsa-cert-v01@openssh.com ssh-rsa-cert-v00@openssh.com )+ec_ed_host_keys, algorithms(host_key: "bogus ssh-rsa",append_all_supported_algorithms: true)[:host_key] end def ec_kex @@ -77,56 +77,56 @@ module Transport end def test_constructor_with_preferred_kex_should_put_preferred_kex_first - assert_equal %w(diffie-hellman-group1-sha1 diffie-hellman-group-exchange-sha1 diffie-hellman-group14-sha1 diffie-hellman-group-exchange-sha256)+ec_kex, algorithms(:kex => "diffie-hellman-group1-sha1", :append_all_supported_algorithms => true)[:kex] + assert_equal %w(diffie-hellman-group1-sha1 diffie-hellman-group-exchange-sha1 diffie-hellman-group14-sha1 diffie-hellman-group-exchange-sha256)+ec_kex, algorithms(kex: "diffie-hellman-group1-sha1", append_all_supported_algorithms: true)[:kex] end def test_constructor_with_unrecognized_kex_should_not_raise_exception assert_equal %w(diffie-hellman-group1-sha1 diffie-hellman-group-exchange-sha1 diffie-hellman-group14-sha1 diffie-hellman-group-exchange-sha256)+ec_kex, algorithms( - :kex => %w(bogus diffie-hellman-group1-sha1),:append_all_supported_algorithms => true)[:kex] + kex: %w(bogus diffie-hellman-group1-sha1),append_all_supported_algorithms: true)[:kex] end def test_constructor_with_preferred_encryption_should_put_preferred_encryption_first - assert_equal %w(aes256-cbc aes128-cbc 3des-cbc blowfish-cbc cast128-cbc aes192-cbc rijndael-cbc@lysator.liu.se idea-cbc none arcfour128 arcfour256 arcfour aes128-ctr aes192-ctr aes256-ctr cast128-ctr blowfish-ctr 3des-ctr), algorithms(:encryption => "aes256-cbc", - :append_all_supported_algorithms => true)[:encryption] + assert_equal %w(aes256-cbc aes128-cbc 3des-cbc blowfish-cbc cast128-cbc aes192-cbc rijndael-cbc@lysator.liu.se idea-cbc none arcfour128 arcfour256 arcfour aes128-ctr aes192-ctr aes256-ctr cast128-ctr blowfish-ctr 3des-ctr), algorithms(encryption: "aes256-cbc", + append_all_supported_algorithms: true)[:encryption] end def test_constructor_with_multiple_preferred_encryption_should_put_all_preferred_encryption_first - assert_equal %w(aes256-cbc 3des-cbc idea-cbc aes128-cbc blowfish-cbc cast128-cbc aes192-cbc rijndael-cbc@lysator.liu.se none arcfour128 arcfour256 arcfour aes128-ctr aes192-ctr aes256-ctr cast128-ctr blowfish-ctr 3des-ctr), algorithms(:encryption => %w(aes256-cbc 3des-cbc idea-cbc), :append_all_supported_algorithms => true)[:encryption] + assert_equal %w(aes256-cbc 3des-cbc idea-cbc aes128-cbc blowfish-cbc cast128-cbc aes192-cbc rijndael-cbc@lysator.liu.se none arcfour128 arcfour256 arcfour aes128-ctr aes192-ctr aes256-ctr cast128-ctr blowfish-ctr 3des-ctr), algorithms(encryption: %w(aes256-cbc 3des-cbc idea-cbc), append_all_supported_algorithms: true)[:encryption] end def test_constructor_with_unrecognized_encryption_should_keep_whats_supported - assert_equal %w(aes256-cbc aes128-cbc 3des-cbc blowfish-cbc cast128-cbc aes192-cbc rijndael-cbc@lysator.liu.se idea-cbc none arcfour128 arcfour256 arcfour aes128-ctr aes192-ctr aes256-ctr cast128-ctr blowfish-ctr 3des-ctr), algorithms(:encryption => %w(bogus aes256-cbc), :append_all_supported_algorithms => true)[:encryption] + assert_equal %w(aes256-cbc aes128-cbc 3des-cbc blowfish-cbc cast128-cbc aes192-cbc rijndael-cbc@lysator.liu.se idea-cbc none arcfour128 arcfour256 arcfour aes128-ctr aes192-ctr aes256-ctr cast128-ctr blowfish-ctr 3des-ctr), algorithms(encryption: %w(bogus aes256-cbc), append_all_supported_algorithms: true)[:encryption] end def test_constructor_with_preferred_hmac_should_put_preferred_hmac_first - assert_equal %w(hmac-md5-96 hmac-sha1 hmac-md5 hmac-sha1-96 hmac-ripemd160 hmac-ripemd160@openssh.com hmac-sha2-256 hmac-sha2-512 hmac-sha2-256-96 hmac-sha2-512-96 none), algorithms(:hmac => "hmac-md5-96", :append_all_supported_algorithms => true)[:hmac] + assert_equal %w(hmac-md5-96 hmac-sha1 hmac-md5 hmac-sha1-96 hmac-ripemd160 hmac-ripemd160@openssh.com hmac-sha2-256 hmac-sha2-512 hmac-sha2-256-96 hmac-sha2-512-96 none), algorithms(hmac: "hmac-md5-96", append_all_supported_algorithms: true)[:hmac] end def test_constructor_with_multiple_preferred_hmac_should_put_all_preferred_hmac_first - assert_equal %w(hmac-md5-96 hmac-sha1-96 hmac-sha1 hmac-md5 hmac-ripemd160 hmac-ripemd160@openssh.com hmac-sha2-256 hmac-sha2-512 hmac-sha2-256-96 hmac-sha2-512-96 none), algorithms(:hmac => %w(hmac-md5-96 hmac-sha1-96), :append_all_supported_algorithms => true)[:hmac] + assert_equal %w(hmac-md5-96 hmac-sha1-96 hmac-sha1 hmac-md5 hmac-ripemd160 hmac-ripemd160@openssh.com hmac-sha2-256 hmac-sha2-512 hmac-sha2-256-96 hmac-sha2-512-96 none), algorithms(hmac: %w(hmac-md5-96 hmac-sha1-96), append_all_supported_algorithms: true)[:hmac] end def test_constructor_with_unrecognized_hmac_should_ignore_those assert_equal %w(hmac-md5-96 hmac-sha1 hmac-md5 hmac-sha1-96 hmac-ripemd160 hmac-ripemd160@openssh.com hmac-sha2-256 hmac-sha2-512 hmac-sha2-256-96 hmac-sha2-512-96 none), - algorithms(:hmac => "hmac-md5-96", :append_all_supported_algorithms => true)[:hmac] + algorithms(hmac: "hmac-md5-96", append_all_supported_algorithms: true)[:hmac] end def test_constructor_with_preferred_compression_should_put_preferred_compression_first - assert_equal %w(zlib none zlib@openssh.com), algorithms(:compression => "zlib", :append_all_supported_algorithms => true)[:compression] + assert_equal %w(zlib none zlib@openssh.com), algorithms(compression: "zlib", append_all_supported_algorithms: true)[:compression] end def test_constructor_with_multiple_preferred_compression_should_put_all_preferred_compression_first - assert_equal %w(zlib@openssh.com zlib none), algorithms(:compression => %w(zlib@openssh.com zlib), - :append_all_supported_algorithms => true)[:compression] + assert_equal %w(zlib@openssh.com zlib none), algorithms(compression: %w(zlib@openssh.com zlib), + append_all_supported_algorithms: true)[:compression] end def test_constructor_with_general_preferred_compression_should_put_none_last assert_equal %w(zlib@openssh.com zlib none), algorithms( - :compression => true, :append_all_supported_algorithms => true)[:compression] + compression: true, append_all_supported_algorithms: true)[:compression] end def test_constructor_with_unrecognized_compression_should_return_whats_supported - assert_equal %w(none zlib zlib@openssh.com), algorithms(:compression => %w(bogus none zlib), :append_all_supported_algorithms => true)[:compression] + assert_equal %w(none zlib zlib@openssh.com), algorithms(compression: %w(bogus none zlib), append_all_supported_algorithms: true)[:compression] end def test_initial_state_should_be_neither_pending_nor_initialized @@ -165,23 +165,23 @@ module Transport end def test_key_exchange_when_server_does_not_support_preferred_kex_should_fallback_to_secondary - kexinit :kex => "diffie-hellman-group1-sha1" + kexinit kex: "diffie-hellman-group1-sha1" transport.expect do |t,buffer| assert_kexinit(buffer) - install_mock_key_exchange(buffer, :kex => Net::SSH::Transport::Kex::DiffieHellmanGroup1SHA1) + install_mock_key_exchange(buffer, kex: Net::SSH::Transport::Kex::DiffieHellmanGroup1SHA1) end algorithms.accept_kexinit(kexinit) end def test_key_exchange_when_server_does_not_support_any_preferred_kex_should_raise_error - kexinit :kex => "something-obscure" + kexinit kex: "something-obscure" transport.expect { |t,buffer| assert_kexinit(buffer) } assert_raises(Net::SSH::Exception) { algorithms.accept_kexinit(kexinit) } end def test_allow_when_not_pending_should_be_true_for_all_packets (0..255).each do |type| - packet = stub("packet", :type => type) + packet = stub("packet", type: type) assert algorithms.allow?(packet), type.to_s end end @@ -192,7 +192,7 @@ module Transport assert algorithms.pending? (0..255).each do |type| - packet = stub("packet", :type => type) + packet = stub("packet", type: type) case type when 1..4, 6..19, 21..49 then assert(algorithms.allow?(packet), "#{type} should be allowed during key exchange") else assert(!algorithms.allow?(packet), "#{type} should not be allowed during key exchange") @@ -201,10 +201,10 @@ module Transport end def test_exchange_with_zlib_compression_enabled_sets_compression_to_standard - algorithms :compression => "zlib", :append_all_supported_algorithms => true + algorithms compression: "zlib", append_all_supported_algorithms: true transport.expect do |t, buffer| - assert_kexinit(buffer, :compression_client => "zlib,none,zlib@openssh.com", :compression_server => "zlib,none,zlib@openssh.com") + assert_kexinit(buffer, compression_client: "zlib,none,zlib@openssh.com", compression_server: "zlib,none,zlib@openssh.com") install_mock_key_exchange(buffer) end @@ -216,10 +216,10 @@ module Transport end def test_exchange_with_zlib_at_openssh_dot_com_compression_enabled_sets_compression_to_delayed - algorithms :compression => "zlib@openssh.com", :append_all_supported_algorithms => true + algorithms compression: "zlib@openssh.com", append_all_supported_algorithms: true transport.expect do |t, buffer| - assert_kexinit(buffer, :compression_client => "zlib@openssh.com,none,zlib", :compression_server => "zlib@openssh.com,none,zlib") + assert_kexinit(buffer, compression_client: "zlib@openssh.com,none,zlib", compression_server: "zlib@openssh.com,none,zlib") install_mock_key_exchange(buffer) end @@ -242,24 +242,24 @@ module Transport kex.expects(:new). with(algorithms, transport, - :client_version_string => Net::SSH::Transport::ServerVersion::PROTO_VERSION, - :server_version_string => transport.server_version.version, - :server_algorithm_packet => kexinit.to_s, - :client_algorithm_packet => buffer.to_s, - :need_bytes => 20, - :minimum_dh_bits => nil, - :logger => nil). - returns(stub("kex", :exchange_keys => { :shared_secret => shared_secret, :session_id => session_id, :hashing_algorithm => hashing_algorithm })) + client_version_string: Net::SSH::Transport::ServerVersion::PROTO_VERSION, + server_version_string: transport.server_version.version, + server_algorithm_packet: kexinit.to_s, + client_algorithm_packet: buffer.to_s, + need_bytes: 20, + minimum_dh_bits: nil, + logger: nil). + returns(stub("kex", exchange_keys: { shared_secret: shared_secret, session_id: session_id, hashing_algorithm: hashing_algorithm })) end def install_mock_algorithm_lookups(options={}) - params = { :shared => shared_secret.to_ssh, :hash => session_id, :digester => hashing_algorithm } + params = { shared: shared_secret.to_ssh, hash: session_id, digester: hashing_algorithm } Net::SSH::Transport::CipherFactory.expects(:get). - with(options[:client_cipher] || "aes128-cbc", params.merge(:iv => key("A"), :key => key("C"), :encrypt => true)). + with(options[:client_cipher] || "aes128-cbc", params.merge(iv: key("A"), key: key("C"), encrypt: true)). returns(:client_cipher) Net::SSH::Transport::CipherFactory.expects(:get). - with(options[:server_cipher] || "aes128-cbc", params.merge(:iv => key("B"), :key => key("D"), :decrypt => true)). + with(options[:server_cipher] || "aes128-cbc", params.merge(iv: key("B"), key: key("D"), decrypt: true)). returns(:server_cipher) Net::SSH::Transport::HMAC.expects(:get).with(options[:client_hmac] || "hmac-sha1", key("E"), params).returns(:client_hmac) diff --git a/test/transport/test_cipher_factory.rb b/test/transport/test_cipher_factory.rb index 607ff53..0e59a7b 100644 --- a/test/transport/test_cipher_factory.rb +++ b/test/transport/test_cipher_factory.rb @@ -294,11 +294,11 @@ module Transport TEXT = "But soft! What light through yonder window breaks? It is the east, and Juliet is the sun!" - OPTIONS = { :iv => "ABC", - :key => "abc", - :digester => OpenSSL::Digest::MD5, - :shared => "1234567890123456780", - :hash => '!@#$%#$^%$&^&%#$@$' + OPTIONS = { iv: "ABC", + key: "abc", + digester: OpenSSL::Digest::MD5, + shared: "1234567890123456780", + hash: '!@#$%#$^%$&^&%#$@$' } def factory @@ -306,7 +306,7 @@ module Transport end def encrypt(type) - cipher = factory.get(type, OPTIONS.merge(:encrypt => true)) + cipher = factory.get(type, OPTIONS.merge(encrypt: true)) padding = TEXT.length % cipher.block_size result = cipher.update(TEXT.dup) result << cipher.update(" " * (cipher.block_size - padding)) if padding > 0 @@ -314,7 +314,7 @@ module Transport end def decrypt(type, data) - cipher = factory.get(type, OPTIONS.merge(:decrypt => true)) + cipher = factory.get(type, OPTIONS.merge(decrypt: true)) result = cipher.update(data.dup) result << cipher.final result.strip diff --git a/test/transport/test_hmac.rb b/test/transport/test_hmac.rb index 55c4655..4e2238b 100644 --- a/test/transport/test_hmac.rb +++ b/test/transport/test_hmac.rb @@ -8,7 +8,7 @@ module Transport method = name.tr("-", "_") define_method("test_get_with_#{method}_returns_new_hmac_instance") do key = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!&$%"[0,Net::SSH::Transport::HMAC::MAP[name].key_length] - hmac = Net::SSH::Transport::HMAC.get(name, key, { :shared => "123", :hash => "^&*", :digester => OpenSSL::Digest::SHA1 }) + hmac = Net::SSH::Transport::HMAC.get(name, key, { shared: "123", hash: "^&*", digester: OpenSSL::Digest::SHA1 }) assert_instance_of Net::SSH::Transport::HMAC::MAP[name], hmac assert_equal key, hmac.key end diff --git a/test/transport/test_packet_stream.rb b/test/transport/test_packet_stream.rb index 3e01f55..4867a79 100644 --- a/test/transport/test_packet_stream.rb +++ b/test/transport/test_packet_stream.rb @@ -1143,11 +1143,11 @@ module Transport 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")) + opts = { shared: "123", hash: "^&*", digester: OpenSSL::Digest::SHA1 } + cipher = Net::SSH::Transport::CipherFactory.get(cipher_name, opts.merge(key: "ABC", decrypt: true, iv: "abc")) hmac = Net::SSH::Transport::HMAC.get(hmac_name, "{}|", opts) - stream.server.set :cipher => cipher, :hmac => hmac, :compression => compress + stream.server.set cipher: cipher, hmac: hmac, compression: compress stream.stubs(:recv).returns(PACKETS[cipher_name][hmac_name][compress]) IO.stubs(:select).returns([[stream]]) packet = stream.next_packet(:nonblock) @@ -1160,12 +1160,12 @@ module Transport end define_method("test_enqueue_packet_with_#{cipher_method_name}_and_#{hmac_method_name}_and_#{compress}_compression") do - opts = { :shared => "123", :digester => OpenSSL::Digest::SHA1, :hash => "^&*" } - cipher = Net::SSH::Transport::CipherFactory.get(cipher_name, opts.merge(:key => "ABC", :iv => "abc", :encrypt => true)) + opts = { shared: "123", digester: OpenSSL::Digest::SHA1, hash: "^&*" } + cipher = Net::SSH::Transport::CipherFactory.get(cipher_name, opts.merge(key: "ABC", iv: "abc", encrypt: true)) hmac = Net::SSH::Transport::HMAC.get(hmac_name, "{}|", opts) srand(100) - stream.client.set :cipher => cipher, :hmac => hmac, :compression => compress + stream.client.set cipher: cipher, hmac: hmac, compression: compress stream.enqueue_packet(ssh_packet) assert_equal PACKETS[cipher_name][hmac_name][compress], stream.write_buffer stream.cleanup diff --git a/test/transport/test_session.rb b/test/transport/test_session.rb index 3640a2b..419dd00 100644 --- a/test/transport/test_session.rb +++ b/test/transport/test_session.rb @@ -21,28 +21,28 @@ module Transport end def test_paranoid_true_uses_lenient_verifier - assert_instance_of Net::SSH::Verifiers::Lenient, session(:paranoid => true).host_key_verifier + assert_instance_of Net::SSH::Verifiers::Lenient, session(paranoid: true).host_key_verifier end def test_paranoid_very_uses_strict_verifier - assert_instance_of Net::SSH::Verifiers::Strict, session(:paranoid => :very).host_key_verifier + assert_instance_of Net::SSH::Verifiers::Strict, session(paranoid: :very).host_key_verifier end def test_paranoid_secure_uses_secure_verifier - assert_instance_of Net::SSH::Verifiers::Secure, session(:paranoid => :secure).host_key_verifier + assert_instance_of Net::SSH::Verifiers::Secure, session(paranoid: :secure).host_key_verifier end def test_paranoid_false_uses_null_verifier - assert_instance_of Net::SSH::Verifiers::Null, session(:paranoid => false).host_key_verifier + assert_instance_of Net::SSH::Verifiers::Null, session(paranoid: false).host_key_verifier end def test_unknown_paranoid_value_raises_exception_if_value_does_not_respond_to_verify - assert_raises(ArgumentError) { session(:paranoid => :bogus).host_key_verifier } + assert_raises(ArgumentError) { session(paranoid: :bogus).host_key_verifier } end def test_paranoid_value_responding_to_verify_should_pass_muster - object = stub("thingy", :verify => true) - assert_equal object, session(:paranoid => object).host_key_verifier + object = stub("thingy", verify: true) + assert_equal object, session(paranoid: object).host_key_verifier end def test_host_as_string_should_return_host_and_ip_when_port_is_default @@ -52,31 +52,31 @@ module Transport end def test_host_as_string_should_return_host_and_ip_with_port_when_port_is_not_default - session(:port => 1234) # force session to be instantiated + session(port: 1234) # force session to be instantiated socket.stubs(:peer_ip).returns("1.2.3.4") assert_equal "[net.ssh.test]:1234,[1.2.3.4]:1234", session.host_as_string end def test_host_as_string_should_return_only_host_when_host_is_ip - session!(:host => "1.2.3.4") + session!(host: "1.2.3.4") socket.stubs(:peer_ip).returns("1.2.3.4") assert_equal "1.2.3.4", session.host_as_string end def test_host_as_string_should_return_only_host_and_port_when_host_is_ip_and_port_is_not_default - session!(:host => "1.2.3.4", :port => 1234) + session!(host: "1.2.3.4", port: 1234) socket.stubs(:peer_ip).returns("1.2.3.4") assert_equal "[1.2.3.4]:1234", session.host_as_string end def test_host_as_string_should_return_only_host_when_proxy_command_is_set - session!(:host => "1.2.3.4") + session!(host: "1.2.3.4") socket.stubs(:peer_ip).returns(Net::SSH::Transport::PacketStream::PROXY_COMMAND_HOST_IP) assert_equal "1.2.3.4", session.host_as_string end 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 - session!(:host => "1.2.3.4", :port => 1234) + session!(host: "1.2.3.4", port: 1234) socket.stubs(:peer_ip).returns(Net::SSH::Transport::PacketStream::PROXY_COMMAND_HOST_IP) assert_equal "[1.2.3.4]:1234", session.host_as_string end @@ -93,13 +93,13 @@ module Transport end def test_rekey_when_kex_is_pending_should_do_nothing - algorithms.stubs(:pending? => true) + algorithms.stubs(pending?: true) algorithms.expects(:rekey!).never session.rekey! end def test_rekey_when_no_kex_is_pending_should_initiate_rekey_and_block_until_it_completes - algorithms.stubs(:pending? => false) + algorithms.stubs(pending?: false) algorithms.expects(:rekey!) session.expects(:wait).yields algorithms.expects(:initialized?).returns(true) @@ -108,22 +108,22 @@ module Transport def test_rekey_as_needed_when_kex_is_pending_should_do_nothing session! - algorithms.stubs(:pending? => true) + algorithms.stubs(pending?: true) socket.expects(:if_needs_rekey?).never session.rekey_as_needed end def test_rekey_as_needed_when_no_kex_is_pending_and_no_rekey_is_needed_should_do_nothing session! - algorithms.stubs(:pending? => false) - socket.stubs(:if_needs_rekey? => false) + algorithms.stubs(pending?: false) + socket.stubs(if_needs_rekey?: false) session.expects(:rekey!).never session.rekey_as_needed end def test_rekey_as_needed_when_no_kex_is_pending_and_rekey_is_needed_should_initiate_rekey_and_block session! - algorithms.stubs(:pending? => false) + algorithms.stubs(pending?: false) socket.expects(:if_needs_rekey?).yields session.expects(:rekey!) session.rekey_as_needed @@ -131,8 +131,8 @@ module Transport def test_peer_should_return_hash_of_info_about_peer session! - socket.stubs(:peer_ip => "1.2.3.4") - assert_equal({:ip => "1.2.3.4", :port => 22, :host => "net.ssh.test", :canonized => "net.ssh.test,1.2.3.4"}, session.peer) + socket.stubs(peer_ip: "1.2.3.4") + assert_equal({ip: "1.2.3.4", port: 22, host: "net.ssh.test", canonized: "net.ssh.test,1.2.3.4"}, session.peer) end def test_next_message_should_block_until_next_message_is_available @@ -283,12 +283,12 @@ module Transport end def test_configure_client_should_pass_options_to_socket_client_state - session.configure_client :compression => :standard + session.configure_client compression: :standard assert_equal :standard, socket.client.compression end def test_configure_server_should_pass_options_to_socket_server_state - session.configure_server :compression => :standard + session.configure_server compression: :standard assert_equal :standard, socket.server.compression end @@ -301,7 +301,7 @@ module Transport private def socket - @socket ||= stub("socket", :hints => {}) + @socket ||= stub("socket", hints: {}) end def server_version @@ -309,7 +309,7 @@ module Transport end def algorithms - @algorithms ||= stub("algorithms", :initialized? => true, :allow? => true, :start => true) + @algorithms ||= stub("algorithms", initialized?: true, allow?: true, start: true) end def session(options={}) diff --git a/test/transport/test_state.rb b/test/transport/test_state.rb index 592974e..44557fa 100644 --- a/test/transport/test_state.rb +++ b/test/transport/test_state.rb @@ -59,9 +59,9 @@ module Transport def test_set_should_set_variables_and_reset_counters state.expects(:reset!) - state.set :cipher => :a, :hmac => :b, :compression => :c, - :compression_level => :d, :max_packets => 500, :max_blocks => 1000, - :rekey_limit => 1500 + state.set cipher: :a, hmac: :b, compression: :c, + compression_level: :d, max_packets: 500, max_blocks: 1000, + rekey_limit: 1500 assert_equal :a, state.cipher assert_equal :b, state.hmac assert_equal :c, state.compression @@ -72,17 +72,17 @@ module Transport end def test_set_with_max_packets_should_respect_max_packets_setting - state.set :max_packets => 500 + state.set max_packets: 500 assert_equal 500, state.max_packets end def test_set_with_max_blocks_should_respect_max_blocks_setting - state.set :max_blocks => 1000 + state.set max_blocks: 1000 assert_equal 1000, state.max_blocks end def test_set_with_rekey_limit_should_include_rekey_limit_in_computation_of_max_blocks - state.set :rekey_limit => 4000 + state.set rekey_limit: 4000 assert_equal 500, state.max_blocks end @@ -92,7 +92,7 @@ module Transport end def test_compressor_uses_compression_level_when_given - state.set :compression_level => 1 + state.set compression_level: 1 expect = deflater(1).deflate("hello world") assert_equal expect, state.compressor.deflate("hello world") end @@ -106,17 +106,17 @@ module Transport end def test_compress_when_compression_is_delayed_and_no_auth_hint_is_set_should_return_text - state.set :compression => :delayed + state.set compression: :delayed assert_equal "hello everybody", state.compress("hello everybody") end def test_decompress_when_compression_is_delayed_and_no_auth_hint_is_set_should_return_text - state.set :compression => :delayed + state.set compression: :delayed assert_equal "hello everybody", state.decompress("hello everybody") end def test_compress_when_compression_is_enabled_should_return_compressed_text - state.set :compression => :standard + state.set compression: :standard # JRuby Zlib implementation (1.4 & 1.5) does not have byte-to-byte compatibility with MRI's. # skip this test under JRuby. return if defined?(JRUBY_VERSION) @@ -124,7 +124,7 @@ module Transport end def test_decompress_when_compression_is_enabled_should_return_decompressed_text - state.set :compression => :standard + state.set compression: :standard # JRuby Zlib implementation (1.4 & 1.5) does not have byte-to-byte compatibility with MRI's. # skip this test under JRuby. return if defined?(JRUBY_VERSION) @@ -133,18 +133,18 @@ module Transport def test_compress_when_compression_is_delayed_and_auth_hint_is_set_should_return_compressed_text socket.hints[:authenticated] = true - state.set :compression => :delayed + state.set compression: :delayed assert_equal "x\234\312H\315\311\311WH-K-\252L\312O\251\004\000\000\000\377\377", state.compress("hello everybody") end def test_decompress_when_compression_is_delayed_and_auth_hint_is_set_should_return_decompressed_text socket.hints[:authenticated] = true - state.set :compression => :delayed + state.set compression: :delayed assert_equal "hello everybody", state.decompress("x\234\312H\315\311\311WH-K-\252L\312O\251\004\000\000\000\377\377") end def test_needs_rekey_should_be_true_if_packets_exceeds_max_packets - state.set :max_packets => 2 + state.set max_packets: 2 state.increment(8) state.increment(8) assert !state.needs_rekey? @@ -153,7 +153,7 @@ module Transport end def test_needs_rekey_should_be_true_if_blocks_exceeds_max_blocks - state.set :max_blocks => 10 + state.set max_blocks: 10 assert !state.needs_rekey? state.increment(88) assert state.needs_rekey? @@ -170,7 +170,7 @@ module Transport end def socket - @socket ||= stub("socket", :hints => {}) + @socket ||= stub("socket", hints: {}) end def state |