diff options
author | Florian Wininger <fw.centrale@gmail.com> | 2021-10-25 15:25:57 +0200 |
---|---|---|
committer | Florian Wininger <fw.centrale@gmail.com> | 2021-10-25 15:55:44 +0200 |
commit | f79ed49dc068317fb280bd2fb554ecb0ce13a7e1 (patch) | |
tree | 32fbf2392f8225905d6cf77412f0f01dbbf82097 /test | |
parent | cf1b4da0d56e6b0598f9d5fbc3c335011f42bc26 (diff) | |
download | net-ssh-f79ed49dc068317fb280bd2fb554ecb0ce13a7e1.tar.gz |
Fix rubocop coding style.
Lot of spacing issues :)
Diffstat (limited to 'test')
40 files changed, 264 insertions, 264 deletions
diff --git a/test/authentication/methods/common.rb b/test/authentication/methods/common.rb index be9c11a..1162e8e 100644 --- a/test/authentication/methods/common.rb +++ b/test/authentication/methods/common.rb @@ -5,15 +5,15 @@ module Authentication private - def socket(options={}) + def socket(options = {}) @socket ||= stub("socket", client_name: "me.ssh.test") end - def transport(options={}) + def transport(options = {}) @transport ||= MockTransport.new(options.merge(socket: socket)) end - def session(options={}) + def session(options = {}) @session ||= begin sess = stub("auth-session", logger: nil, transport: transport(options)) def sess.next_message diff --git a/test/authentication/methods/test_abstract.rb b/test/authentication/methods/test_abstract.rb index 4f930a9..c7944f0 100644 --- a/test/authentication/methods/test_abstract.rb +++ b/test/authentication/methods/test_abstract.rb @@ -42,7 +42,7 @@ module Authentication private - def subject(options={}) + def subject(options = {}) @subject ||= Net::SSH::Authentication::Methods::Abstract.new(session(options), options) end end diff --git a/test/authentication/methods/test_hostbased.rb b/test/authentication/methods/test_hostbased.rb index f93a5a5..99e42fe 100644 --- a/test/authentication/methods/test_hostbased.rb +++ b/test/authentication/methods/test_hostbased.rb @@ -79,7 +79,7 @@ module Authentication @@keys ||= [OpenSSL::PKey::RSA.new(512), OpenSSL::PKey::DSA.new(512)] end - def key_manager(options={}) + def key_manager(options = {}) @key_manager ||= begin manager = stub("key_manager") manager.stubs(:each_identity).multiple_yields(*(options[:keys] || keys)) @@ -87,20 +87,20 @@ module Authentication end end - def subject(options={}) + def subject(options = {}) options[:key_manager] = key_manager(options) unless options.key?(:key_manager) @subject ||= Net::SSH::Authentication::Methods::Hostbased.new(session(options), options) end - def socket(options={}) + def socket(options = {}) @socket ||= stub("socket", client_name: "me.ssh.test") end - def transport(options={}) + def transport(options = {}) @transport ||= MockTransport.new(options.merge(socket: socket)) end - def session(options={}) + def session(options = {}) @session ||= begin sess = stub("auth-session", logger: nil, transport: transport(options)) def sess.next_message diff --git a/test/authentication/methods/test_keyboard_interactive.rb b/test/authentication/methods/test_keyboard_interactive.rb index 76d5272..ebe9c16 100644 --- a/test/authentication/methods/test_keyboard_interactive.rb +++ b/test/authentication/methods/test_keyboard_interactive.rb @@ -15,7 +15,7 @@ module Authentication end def test_authenticate_should_raise_if_keyboard_interactive_disallowed - transport.expect do |t,packet| + transport.expect do |t, packet| assert_equal USERAUTH_REQUEST, packet.type assert_equal "jamis", packet.read_string assert_equal "ssh-connection", packet.read_string @@ -34,10 +34,10 @@ module Authentication def test_authenticate_should_be_false_if_given_password_is_not_accepted reset_subject(non_interactive: true) - transport.expect do |t,packet| + transport.expect do |t, packet| assert_equal USERAUTH_REQUEST, packet.type t.return(USERAUTH_INFO_REQUEST, :string, "", :string, "", :string, "", :long, 1, :string, "Password:", :bool, false) - t.expect do |t2,packet2| + t.expect do |t2, packet2| assert_equal USERAUTH_INFO_RESPONSE, packet2.type assert_equal 1, packet2.read_long assert_equal "the-password", packet2.read_string @@ -49,10 +49,10 @@ module Authentication end def test_authenticate_should_be_true_if_given_password_is_accepted - transport.expect do |t,packet| + transport.expect do |t, packet| assert_equal USERAUTH_REQUEST, packet.type t.return(USERAUTH_INFO_REQUEST, :string, "", :string, "", :string, "", :long, 1, :string, "Password:", :bool, false) - t.expect do |t2,packet2| + t.expect do |t2, packet2| assert_equal USERAUTH_INFO_RESPONSE, packet2.type t2.return(USERAUTH_SUCCESS) end @@ -62,10 +62,10 @@ module Authentication end def test_authenticate_should_duplicate_password_as_needed_to_fill_request - transport.expect do |t,packet| + transport.expect do |t, packet| assert_equal USERAUTH_REQUEST, packet.type t.return(USERAUTH_INFO_REQUEST, :string, "", :string, "", :string, "", :long, 2, :string, "Password:", :bool, false, :string, "Again:", :bool, false) - t.expect do |t2,packet2| + t.expect do |t2, packet2| assert_equal USERAUTH_INFO_RESPONSE, packet2.type assert_equal 2, packet2.read_long assert_equal "the-password", packet2.read_string @@ -79,10 +79,10 @@ module Authentication def test_authenticate_should_not_prompt_for_input_when_in_non_interactive_mode reset_subject(non_interactive: true) - transport.expect do |t,packet| + transport.expect do |t, packet| assert_equal USERAUTH_REQUEST, packet.type t.return(USERAUTH_INFO_REQUEST, :string, "", :string, "", :string, "", :long, 2, :string, "Name:", :bool, true, :string, "Password:", :bool, false) - t.expect do |t2,packet2| + t.expect do |t2, packet2| assert_equal USERAUTH_INFO_RESPONSE, packet2.type assert_equal 2, packet2.read_long assert_equal "", packet2.read_string @@ -100,10 +100,10 @@ module Authentication prompt.expects(:_ask).with("Password:", anything, false).returns("password") reset_subject(password_prompt: prompt) - transport.expect do |t,packet| + transport.expect do |t, packet| assert_equal USERAUTH_REQUEST, packet.type t.return(USERAUTH_INFO_REQUEST, :string, "", :string, "", :string, "", :long, 2, :string, "Name:", :bool, true, :string, "Password:", :bool, false) - t.expect do |t2,packet2| + t.expect do |t2, packet2| assert_equal USERAUTH_INFO_RESPONSE, packet2.type assert_equal 2, packet2.read_long assert_equal "name", packet2.read_string @@ -117,7 +117,7 @@ module Authentication private - def subject(options={}) + def subject(options = {}) @subject ||= Net::SSH::Authentication::Methods::KeyboardInteractive.new(session(options), options) end diff --git a/test/authentication/methods/test_none.rb b/test/authentication/methods/test_none.rb index bc71505..f199172 100644 --- a/test/authentication/methods/test_none.rb +++ b/test/authentication/methods/test_none.rb @@ -8,7 +8,7 @@ module Authentication include Common def test_authenticate_should_raise_if_none_disallowed - transport.expect do |t,packet| + transport.expect do |t, packet| assert_equal USERAUTH_REQUEST, packet.type assert_equal "jamis", packet.read_string assert_equal "ssh-connection", packet.read_string @@ -23,7 +23,7 @@ module Authentication end def test_authenticate_should_return_true - transport.expect do |t,packet| + transport.expect do |t, packet| assert_equal USERAUTH_REQUEST, packet.type t.return(USERAUTH_SUCCESS) end @@ -33,7 +33,7 @@ module Authentication private - def subject(options={}) + def subject(options = {}) @subject ||= Net::SSH::Authentication::Methods::None.new(session(options), options) end end diff --git a/test/authentication/methods/test_password.rb b/test/authentication/methods/test_password.rb index db520bd..2205887 100644 --- a/test/authentication/methods/test_password.rb +++ b/test/authentication/methods/test_password.rb @@ -9,7 +9,7 @@ module Authentication include Common def test_authenticate_should_raise_if_password_disallowed - transport.expect do |t,packet| + transport.expect do |t, packet| assert_equal USERAUTH_REQUEST, packet.type assert_equal "jamis", packet.read_string assert_equal "ssh-connection", packet.read_string @@ -26,7 +26,7 @@ module Authentication end def test_authenticate_ask_for_password_for_second_time_when_password_is_incorrect - transport.expect do |t,packet| + transport.expect do |t, packet| assert_equal USERAUTH_REQUEST, packet.type assert_equal "jamis", packet.read_string assert_equal "ssh-connection", packet.read_string @@ -52,7 +52,7 @@ module Authentication end def test_authenticate_ask_for_password_if_not_given - transport.expect do |t,packet| + transport.expect do |t, packet| assert_equal USERAUTH_REQUEST, packet.type assert_equal "bill", packet.read_string assert_equal "ssh-connection", packet.read_string @@ -69,7 +69,7 @@ module Authentication end def test_authenticate_when_password_is_acceptible_should_return_true - transport.expect do |t,packet| + transport.expect do |t, packet| assert_equal USERAUTH_REQUEST, packet.type t.return(USERAUTH_SUCCESS) end @@ -78,7 +78,7 @@ module Authentication end def test_authenticate_should_return_false_if_password_change_request_is_received - transport.expect do |t,packet| + transport.expect do |t, packet| assert_equal USERAUTH_REQUEST, packet.type t.return(USERAUTH_PASSWD_CHANGEREQ, :string, "Change your password:", :string, "") end @@ -88,7 +88,7 @@ module Authentication private - def subject(options={}) + def subject(options = {}) @subject ||= Net::SSH::Authentication::Methods::Password.new(session(options), options) end end diff --git a/test/authentication/methods/test_publickey.rb b/test/authentication/methods/test_publickey.rb index 029338d..db5e62f 100644 --- a/test/authentication/methods/test_publickey.rb +++ b/test/authentication/methods/test_publickey.rb @@ -39,7 +39,7 @@ module Authentication assert verify_userauth_request_packet(packet, keys.first, false) t.return(USERAUTH_PK_OK, :string, keys.first.ssh_type, :string, Net::SSH::Buffer.from(:key, keys.first)) - t.expect do |t2,packet2| + t.expect do |t2, packet2| assert_equal USERAUTH_REQUEST, packet2.type assert verify_userauth_request_packet(packet2, keys.first, true) assert_equal "sig-one", packet2.read_string @@ -61,7 +61,7 @@ module Authentication assert verify_userauth_request_packet(packet, keys.first, false) t.return(USERAUTH_PK_OK, :string, keys.first.ssh_type, :string, Net::SSH::Buffer.from(:key, keys.first)) - t.expect do |t2,packet2| + t.expect do |t2, packet2| assert_equal USERAUTH_REQUEST, packet2.type assert verify_userauth_request_packet(packet2, keys.first, true) assert_equal "sig-one", packet2.read_string @@ -72,7 +72,7 @@ module Authentication assert verify_userauth_request_packet(packet3, keys.last, false) t3.return(USERAUTH_PK_OK, :string, keys.last.ssh_type, :string, Net::SSH::Buffer.from(:key, keys.last)) - t3.expect do |t4,packet4| + t3.expect do |t4, packet4| assert_equal USERAUTH_REQUEST, packet4.type assert verify_userauth_request_packet(packet4, keys.last, true) assert_equal "sig-two", packet4.read_string @@ -93,7 +93,7 @@ module Authentication assert verify_userauth_request_packet(packet, keys.first, false) t.return(USERAUTH_PK_OK, :string, keys.first.ssh_type, :string, Net::SSH::Buffer.from(:key, keys.first)) - t.expect do |t2,packet2| + t.expect do |t2, packet2| assert_equal USERAUTH_REQUEST, packet2.type assert verify_userauth_request_packet(packet2, keys.first, true) assert_equal "sig-one", packet2.read_string @@ -131,7 +131,7 @@ module Authentication @@keys ||= [OpenSSL::PKey::RSA.new(512), OpenSSL::PKey::DSA.new(512)] end - def key_manager(options={}) + def key_manager(options = {}) @key_manager ||= begin manager = stub("key_manager") manager.stubs(:each_identity).multiple_yields(*(options[:keys] || keys)) @@ -139,7 +139,7 @@ module Authentication end end - def subject(options={}) + def subject(options = {}) options[:key_manager] = key_manager(options) unless options.key?(:key_manager) @subject ||= Net::SSH::Authentication::Methods::Publickey.new(session(options), options) end diff --git a/test/authentication/test_agent.rb b/test/authentication/test_agent.rb index a6cb623..65fee73 100644 --- a/test/authentication/test_agent.rb +++ b/test/authentication/test_agent.rb @@ -146,7 +146,7 @@ module Authentication end result = agent.identities - assert_equal 2,result.size + assert_equal 2, result.size assert_equal key1.to_blob, result.first.to_blob assert_equal key3.to_blob, result.last.to_blob assert_equal "My favorite key", result.first.comment @@ -164,7 +164,7 @@ module Authentication end result = agent.identities - assert_equal 2,result.size + assert_equal 2, result.size assert_equal key1.to_blob, result.first.to_blob assert_equal key3.to_blob, result.last.to_blob assert_equal "My favorite key", result.first.comment @@ -197,7 +197,7 @@ module Authentication end def test_sign_should_return_signed_data_from_agent - socket.expect do |s,type,buffer| + socket.expect do |s, type, buffer| assert_equal SSH2_AGENT_SIGN_REQUEST, type assert_equal key.to_blob, Net::SSH::Buffer.new(buffer.read_string).read_key.to_blob assert_equal "hello world", buffer.read_string @@ -211,7 +211,7 @@ module Authentication def test_add_rsa_identity_with_constraints rsa = OpenSSL::PKey::RSA.new(512) - socket.expect do |s,type,buffer| + socket.expect do |s, type, buffer| assert_equal SSH2_AGENT_ADD_ID_CONSTRAINED, type assert_equal buffer.read_string, "ssh-rsa" assert_equal buffer.read_bignum.to_s, rsa.n.to_s @@ -234,7 +234,7 @@ module Authentication def test_add_rsa_cert_identity cert = make_cert(OpenSSL::PKey::RSA.new(512)) - socket.expect do |s,type,buffer| + socket.expect do |s, type, buffer| assert_equal SSH2_AGENT_ADD_IDENTITY, type assert_equal buffer.read_string, "ssh-rsa-cert-v01@openssh.com" assert_equal buffer.read_string, cert.to_blob @@ -253,7 +253,7 @@ module Authentication def test_add_dsa_identity dsa = OpenSSL::PKey::DSA.new(512) - socket.expect do |s,type,buffer| + socket.expect do |s, type, buffer| assert_equal SSH2_AGENT_ADD_IDENTITY, type assert_equal buffer.read_string, "ssh-dss" assert_equal buffer.read_bignum.to_s, dsa.p.to_s @@ -272,7 +272,7 @@ module Authentication def test_add_dsa_cert_identity cert = make_cert(OpenSSL::PKey::DSA.new(512)) - socket.expect do |s,type,buffer| + socket.expect do |s, type, buffer| assert_equal SSH2_AGENT_ADD_IDENTITY, type assert_equal buffer.read_string, "ssh-dss-cert-v01@openssh.com" assert_equal buffer.read_string, cert.to_blob @@ -288,7 +288,7 @@ module Authentication def test_add_ecdsa_identity ecdsa = OpenSSL::PKey::EC.new("prime256v1").generate_key - socket.expect do |s,type,buffer| + socket.expect do |s, type, buffer| assert_equal SSH2_AGENT_ADD_IDENTITY, type assert_equal buffer.read_string, "ecdsa-sha2-nistp256" assert_equal buffer.read_string, "nistp256" @@ -305,7 +305,7 @@ module Authentication def test_add_ecdsa_cert_identity cert = make_cert(OpenSSL::PKey::EC.new("prime256v1").generate_key) - socket.expect do |s,type,buffer| + socket.expect do |s, type, buffer| assert_equal SSH2_AGENT_ADD_IDENTITY, type assert_equal buffer.read_string, "ecdsa-sha2-nistp256-cert-v01@openssh.com" assert_equal buffer.read_string, cert.to_blob @@ -323,7 +323,7 @@ module Authentication return unless Net::SSH::Authentication::ED25519Loader::LOADED ed25519 = Net::SSH::Authentication::ED25519::PrivKey.read(ED25519, nil) - socket.expect do |s,type,buffer| + socket.expect do |s, type, buffer| assert_equal SSH2_AGENT_ADD_IDENTITY, type assert_equal buffer.read_string, "ssh-ed25519" assert_equal buffer.read_string, ed25519.public_key.verify_key.to_bytes @@ -341,7 +341,7 @@ module Authentication return unless Net::SSH::Authentication::ED25519Loader::LOADED cert = make_cert(Net::SSH::Authentication::ED25519::PrivKey.read(ED25519, nil)) - socket.expect do |s,type,buffer| + socket.expect do |s, type, buffer| assert_equal SSH2_AGENT_ADD_IDENTITY, type assert_equal buffer.read_string, "ssh-ed25519-cert-v01@openssh.com" assert_equal buffer.read_string, cert.to_blob @@ -357,7 +357,7 @@ module Authentication end def test_add_identity_should_raise_error_on_failure - socket.expect do |s,_type,_buffer| + socket.expect do |s, _type, _buffer| s.return(SSH_AGENT_FAILURE) end @@ -367,7 +367,7 @@ module Authentication end def test_remove_identity - socket.expect do |s,type,buffer| + socket.expect do |s, type, buffer| assert_equal SSH2_AGENT_REMOVE_IDENTITY, type assert_equal buffer.read_string, key.to_blob assert buffer.eof? @@ -379,7 +379,7 @@ module Authentication end def test_remove_identity_should_raise_error_on_failure - socket.expect do |s,_type,_buffer| + socket.expect do |s, _type, _buffer| s.return(SSH_AGENT_FAILURE) end @@ -389,7 +389,7 @@ module Authentication end def test_remove_all_identities - socket.expect do |s,type,buffer| + socket.expect do |s, type, buffer| assert_equal SSH2_AGENT_REMOVE_ALL_IDENTITIES, type assert buffer.eof? @@ -400,7 +400,7 @@ module Authentication end def test_remove_all_identities_should_raise_error_on_failure - socket.expect do |s,_type,_buffer| + socket.expect do |s, _type, _buffer| s.return(SSH_AGENT_FAILURE) end @@ -459,7 +459,7 @@ module Authentication @factory ||= stub("socket factory", open: socket) end - def agent(auto=:connect) + def agent(auto = :connect) @agent ||= begin agent = Net::SSH::Authentication::Agent.new agent.stubs(:unix_socket_class).returns(factory) diff --git a/test/authentication/test_ed25519.rb b/test/authentication/test_ed25519.rb index 279aa85..d0d0e9e 100644 --- a/test/authentication/test_ed25519.rb +++ b/test/authentication/test_ed25519.rb @@ -22,7 +22,7 @@ unless ENV['NET_SSH_NO_ED25519'] shared_secret = "Hello" signed = priv_key.ssh_do_sign(shared_secret) - self.assert_equal(true,pub_key.ssh_do_verify(signed,shared_secret)) + self.assert_equal(true, pub_key.ssh_do_verify(signed, shared_secret)) self.assert_equal(priv_key.public_key.fingerprint, pub_key.fingerprint) self.assert_equal(pub_key.fingerprint, key_fingerprint_md5_no_pwd) self.assert_equal(pub_key.fingerprint('sha256'), key_fingerprint_sha256_no_pwd) @@ -39,7 +39,7 @@ unless ENV['NET_SSH_NO_ED25519'] shared_secret = "Hello" signed = priv_key.ssh_do_sign(shared_secret) - self.assert_equal(true,pub_key.ssh_do_verify(signed,shared_secret)) + self.assert_equal(true, pub_key.ssh_do_verify(signed, shared_secret)) self.assert_equal(priv_key.public_key.fingerprint, pub_key.fingerprint) self.assert_equal(pub_key.fingerprint, key_fingerprint_md5_no_pwd) self.assert_equal(pub_key.fingerprint('sha256'), key_fingerprint_sha256_no_pwd) @@ -56,11 +56,11 @@ unless ENV['NET_SSH_NO_ED25519'] priv = private_key_pwd pub_key = Net::SSH::Authentication::ED25519::PubKey.new(pub_data) - priv_key = Net::SSH::Authentication::ED25519::PrivKey.read(priv,'pwd') + priv_key = Net::SSH::Authentication::ED25519::PrivKey.read(priv, 'pwd') shared_secret = "Hello" signed = priv_key.ssh_do_sign(shared_secret) - self.assert_equal(true,pub_key.ssh_do_verify(signed,shared_secret)) + self.assert_equal(true, pub_key.ssh_do_verify(signed, shared_secret)) self.assert_equal(priv_key.public_key.fingerprint, pub_key.fingerprint) self.assert_equal(pub_key.fingerprint, key_fingerprint_md5_pwd) self.assert_equal(pub_key.fingerprint('sha256'), key_fingerprint_sha256_pwd) @@ -86,7 +86,7 @@ unless ENV['NET_SSH_NO_ED25519'] shared_secret = "Hello" signed = priv_key.ssh_do_sign(shared_secret) - self.assert_equal(true,pub_key.ssh_do_verify(signed,shared_secret)) + self.assert_equal(true, pub_key.ssh_do_verify(signed, shared_secret)) self.assert_equal(priv_key.public_key.fingerprint, pub_key.fingerprint) self.assert_equal(pub_key.fingerprint, key_fingerprint_md5_pwd) self.assert_equal(pub_key.fingerprint('sha256'), key_fingerprint_sha256_pwd) diff --git a/test/authentication/test_key_manager.rb b/test/authentication/test_key_manager.rb index 0ae8914..05cb15d 100644 --- a/test/authentication/test_key_manager.rb +++ b/test/authentication/test_key_manager.rb @@ -321,7 +321,7 @@ module Authentication end end - def rsa(size=512) + def rsa(size = 512) @rsa ||= OpenSSL::PKey::RSA.new(size) end diff --git a/test/authentication/test_session.rb b/test/authentication/test_session.rb index 3e46def..0f73a97 100644 --- a/test/authentication/test_session.rb +++ b/test/authentication/test_session.rb @@ -167,11 +167,11 @@ module Authentication private - def session(options={}) + def session(options = {}) @session ||= Net::SSH::Authentication::Session.new(transport(options), options) end - def transport(options={}) + def transport(options = {}) @transport ||= MockTransport.new(options) end diff --git a/test/common.rb b/test/common.rb index a666f68..e6a69bf 100644 --- a/test/common.rb +++ b/test/common.rb @@ -5,8 +5,8 @@ if ENV["CI"] require 'simplecov' SimpleCov.start -# require 'codecov' -# SimpleCov.formatter = SimpleCov::Formatter::Codecov + # require 'codecov' + # SimpleCov.formatter = SimpleCov::Formatter::Codecov end end @@ -94,7 +94,7 @@ class MockTransport < Net::SSH::Transport::Session attr_accessor :mock_enqueue - def initialize(options={}) + def initialize(options = {}) @options = options self.logger = options[:logger] self.host_as_string = "net.ssh.test,127.0.0.1" @@ -161,7 +161,7 @@ class MockTransport < Net::SSH::Transport::Session @server_options = options end - def hint(name, value=true) + def hint(name, value = true) @hints[name] = value end end diff --git a/test/connection/test_channel.rb b/test/connection/test_channel.rb index ef9f952..c1d7c20 100644 --- a/test/connection/test_channel.rb +++ b/test/connection/test_channel.rb @@ -42,7 +42,7 @@ module Connection def test_request_pty_without_options_should_use_defaults channel.expects(:send_channel_request).with("pty-req", :string, "xterm", - :long, 80, :long, 24, :long, 640, :long, 480, :string, "\0").yields + :long, 80, :long, 24, :long, 640, :long, 480, :string, "\0").yields found_block = false channel.request_pty { found_block = true } assert found_block, "expected block to be passed to send_channel_request" @@ -50,7 +50,7 @@ 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") + :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 } end @@ -72,7 +72,7 @@ module Connection channel.do_open_confirmation(0, 100, 100) assert !channel.closing? - connection.expect { |_t,packet| assert_equal CHANNEL_CLOSE, packet.type } + connection.expect { |_t, packet| assert_equal CHANNEL_CLOSE, packet.type } connection.expects(:cleanup_channel).with(channel) channel.close @@ -111,7 +111,7 @@ module Connection channel.do_open_confirmation(0, 100, 100) channel.send_data("hello world") - connection.expect do |_t,packet| + connection.expect do |_t, packet| assert_equal CHANNEL_DATA, packet.type assert_equal 0, packet[:local_id] assert_equal 11, packet[:data].length @@ -124,12 +124,12 @@ module Connection channel.do_open_confirmation(0, 100, 8) channel.send_data("hello world") - connection.expect do |t,packet| + connection.expect do |t, packet| assert_equal CHANNEL_DATA, packet.type assert_equal 0, packet[:local_id] assert_equal "hello wo", packet[:data] - t.expect do |_t2,packet2| + t.expect do |_t2, packet2| assert_equal CHANNEL_DATA, packet2.type assert_equal 0, packet2[:local_id] assert_equal "rld", packet2[:data] @@ -143,7 +143,7 @@ module Connection channel.do_open_confirmation(0, 8, 100) channel.send_data("hello world") - connection.expect do |_t,packet| + connection.expect do |_t, packet| assert_equal CHANNEL_DATA, packet.type assert_equal 0, packet[:local_id] assert_equal "hello wo", packet[:data] @@ -209,7 +209,7 @@ module Connection def test_do_request_for_unhandled_request_should_send_CHANNEL_FAILURE_if_wants_reply channel.do_open_confirmation(0, 100, 100) - connection.expect { |_t,packet| assert_equal CHANNEL_FAILURE, packet.type } + connection.expect { |_t, packet| assert_equal CHANNEL_FAILURE, packet.type } channel.do_request "keepalive@openssh.com", true, nil end @@ -233,7 +233,7 @@ module Connection channel.do_open_confirmation(0, 100, 100) flag = false channel.on_request("exit-status") { flag = true; true } - connection.expect { |_t,p| assert_equal CHANNEL_SUCCESS, p.type } + connection.expect { |_t, p| assert_equal CHANNEL_SUCCESS, p.type } assert_nothing_raised { channel.do_request "exit-status", true, nil } assert flag, "callback should have been invoked" end @@ -242,14 +242,14 @@ module Connection channel.do_open_confirmation(0, 100, 100) flag = false channel.on_request("exit-status") { flag = true; raise Net::SSH::ChannelRequestFailed } - connection.expect { |_t,p| assert_equal CHANNEL_FAILURE, p.type } + connection.expect { |_t, p| assert_equal CHANNEL_FAILURE, p.type } assert_nothing_raised { channel.do_request "exit-status", true, nil } assert flag, "callback should have been invoked" end def test_send_channel_request_without_callback_should_not_want_reply channel.do_open_confirmation(0, 100, 100) - connection.expect do |_t,p| + connection.expect do |_t, p| assert_equal CHANNEL_REQUEST, p.type assert_equal 0, p[:local_id] assert_equal "exec", p[:request] @@ -274,7 +274,7 @@ module Connection def test_send_channel_request_with_callback_should_want_reply channel.do_open_confirmation(0, 100, 100) - connection.expect do |_t,p| + connection.expect do |_t, p| assert_equal CHANNEL_REQUEST, p.type assert_equal 0, p[:local_id] assert_equal "exec", p[:request] @@ -298,7 +298,7 @@ module Connection flag = false channel { flag = true } assert !flag, "callback should not have been invoked yet" - channel.do_open_confirmation(1,2,3) + channel.do_open_confirmation(1, 2, 3) assert flag, "callback should have been invoked" end @@ -307,14 +307,14 @@ module Connection forward = mock("forward") forward.expects(:agent).with(channel) connection.expects(:forward).returns(forward) - channel.do_open_confirmation(1,2,3) + channel.do_open_confirmation(1, 2, 3) 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.expects(:forward).never - channel.do_open_confirmation(1,2,3) + channel.do_open_confirmation(1, 2, 3) end def test_do_window_adjust_should_adjust_remote_window_size_by_the_given_amount @@ -347,7 +347,7 @@ module Connection assert_equal 0x20000, channel.local_maximum_window_size assert_equal 0x20000, channel.local_window_size - connection.expect do |_t,p| + connection.expect do |_t, p| assert_equal CHANNEL_WINDOW_ADJUST, p.type assert_equal 0, p[:local_id] assert_equal 0x20000, p[:extra_bytes] @@ -384,25 +384,25 @@ module Connection end def test_wait_should_block_while_channel_is_active? - channel.expects(:active?).times(3).returns(true,true,false) + channel.expects(:active?).times(3).returns(true, true, false) 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.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 } + connection.expect { |_t, p| assert_equal CHANNEL_EOF, p.type } channel.eof! channel.process end def test_eof_bang_should_not_send_eof_if_eof_was_already_declared channel.do_open_confirmation(0, 1000, 1000) - connection.expect { |_t,p| assert_equal CHANNEL_EOF, p.type } + connection.expect { |_t, p| assert_equal CHANNEL_EOF, p.type } channel.eof! assert_nothing_raised { channel.eof! } channel.process @@ -410,7 +410,7 @@ module Connection def test_eof_q_should_return_true_if_eof_declared channel.do_open_confirmation(0, 1000, 1000) - connection.expect { |_t,p| assert_equal CHANNEL_EOF, p.type } + connection.expect { |_t, p| assert_equal CHANNEL_EOF, p.type } assert !channel.eof? channel.eof! @@ -420,7 +420,7 @@ module Connection def test_send_data_should_raise_exception_if_eof_declared channel.do_open_confirmation(0, 1000, 1000) - connection.expect { |_t,p| assert_equal CHANNEL_EOF, p.type } + connection.expect { |_t, p| assert_equal CHANNEL_EOF, p.type } channel.eof! channel.process assert_raises(EOFError) { channel.send_data("die! die! die!") } @@ -428,9 +428,9 @@ module Connection def test_data_should_precede_eof channel.do_open_confirmation(0, 1000, 1000) - connection.expect do |_t,p| + connection.expect do |_t, p| assert_equal CHANNEL_DATA, p.type - connection.expect { |_t,p2| assert_equal CHANNEL_EOF, p2.type } + connection.expect { |_t, p2| assert_equal CHANNEL_EOF, p2.type } end channel.send_data "foo" channel.eof! @@ -444,7 +444,7 @@ module Connection attr_reader :options attr_reader :channels - def initialize(options={}) + def initialize(options = {}) @expectation = nil @options = options @channels = {} @@ -472,15 +472,15 @@ module Connection end end - def connection(options={}) + def connection(options = {}) @connection ||= MockConnection.new(options) end - def channel(options={}, &block) + def channel(options = {}, &block) @channel ||= Net::SSH::Connection::Channel.new(connection(options), - options[:type] || "session", - options[:local_id] || 0, - &block) + options[:type] || "session", + options[:local_id] || 0, + &block) end end end diff --git a/test/connection/test_session.rb b/test/connection/test_session.rb index 6eb1432..5de5fd2 100644 --- a/test/connection/test_session.rb +++ b/test/connection/test_session.rb @@ -61,14 +61,14 @@ module Connection flag = false channel = session.open_channel { flag = true } assert !flag, "callback should not be invoked immediately" - channel.do_open_confirmation(1,2,3) + channel.do_open_confirmation(1, 2, 3) assert flag, "callback should have been invoked" assert_equal "session", channel.type assert_equal 0, channel.local_id assert_equal channel, session.channels[channel.local_id] packet = P(:byte, CHANNEL_OPEN, :string, "session", :long, channel.local_id, - :long, channel.local_maximum_window_size, :long, channel.local_maximum_packet_size) + :long, channel.local_maximum_window_size, :long, channel.local_maximum_packet_size) assert_equal packet.to_s, socket.write_buffer end @@ -76,15 +76,15 @@ module Connection channel = session.open_channel("direct-tcpip") assert_equal "direct-tcpip", channel.type packet = P(:byte, CHANNEL_OPEN, :string, "direct-tcpip", :long, channel.local_id, - :long, channel.local_maximum_window_size, :long, channel.local_maximum_packet_size) + :long, channel.local_maximum_window_size, :long, channel.local_maximum_packet_size) assert_equal packet.to_s, socket.write_buffer end def test_open_channel_with_extras_should_append_extras_to_packet channel = session.open_channel("direct-tcpip", :string, "other.host", :long, 1234) packet = P(:byte, CHANNEL_OPEN, :string, "direct-tcpip", :long, channel.local_id, - :long, channel.local_maximum_window_size, :long, channel.local_maximum_packet_size, - :string, "other.host", :long, 1234) + :long, channel.local_maximum_window_size, :long, channel.local_maximum_packet_size, + :string, "other.host", :long, 1234) assert_equal packet.to_s, socket.write_buffer end @@ -335,19 +335,19 @@ module Connection end def test_writers_without_pending_writes_should_not_be_considered_for_select - IO.expects(:select).with([socket],[],nil,nil).returns([[],[],[]]) + IO.expects(:select).with([socket], [], nil, nil).returns([[], [], []]) session.process end def test_writers_with_pending_writes_should_be_considered_for_select socket.enqueue("laksdjflasdkf") - IO.expects(:select).with([socket],[socket],nil,nil).returns([[],[],[]]) + IO.expects(:select).with([socket], [socket], nil, nil).returns([[], [], []]) session.process end def test_ready_readers_should_be_filled socket.expects(:recv).returns("this is some data") - IO.expects(:select).with([socket],[],nil,nil).returns([[socket],[],[]]) + IO.expects(:select).with([socket], [], nil, nil).returns([[socket], [], []]) session.process assert_equal [socket], session.listeners.keys end @@ -355,7 +355,7 @@ module Connection def test_ready_readers_that_cant_be_filled_should_be_removed socket.expects(:recv).returns("") socket.expects(:close) - IO.expects(:select).with([socket],[],nil,nil).returns([[socket],[],[]]) + IO.expects(:select).with([socket], [], nil, nil).returns([[socket], [], []]) session.process assert session.listeners.empty? end @@ -365,7 +365,7 @@ module Connection 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 } - IO.expects(:select).with([io],[],nil,nil).returns([[io],[],[]]) + IO.expects(:select).with([io], [], nil, nil).returns([[io], [], []]) session.process assert flag, "callback should have been invoked" end @@ -373,13 +373,13 @@ module Connection def test_ready_writers_should_call_send_pending socket.enqueue("laksdjflasdkf") socket.expects(:send).with("laksdjflasdkf", 0).returns(13) - IO.expects(:select).with([socket],[socket],nil,nil).returns([[],[socket],[]]) + IO.expects(:select).with([socket], [socket], nil, nil).returns([[], [socket], []]) session.process end def test_process_should_call_rekey_as_needed transport.expects(:rekey_as_needed) - IO.expects(:select).with([socket],[],nil,nil).returns([[],[],[]]) + IO.expects(:select).with([socket], [], nil, nil).returns([[], [], []]) session.process end @@ -387,7 +387,7 @@ module Connection timeout = Net::SSH::Connection::Session::DEFAULT_IO_SELECT_TIMEOUT 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) + IO.stubs(:select).with([socket], [], nil, timeout).returns(nil) transport.expects(:enqueue_message).with { |msg| msg.content == expected_packet.content } session(options).process end @@ -396,15 +396,15 @@ module Connection timeout = Net::SSH::Connection::Session::DEFAULT_IO_SELECT_TIMEOUT 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| + [1, 2, 3].each do |i| Time.stubs(:now).returns(Time.at(i * 300)) - IO.stubs(:select).with([socket],[],nil,timeout).returns(nil) + IO.stubs(:select).with([socket], [], nil, timeout).returns(nil) transport.expects(:enqueue_message).with { |msg| msg.content == expected_packet.content } session(options).process end Time.stubs(:now).returns(Time.at(4 * 300)) - IO.stubs(:select).with([socket],[],nil,timeout).returns(nil) + IO.stubs(:select).with([socket], [], nil, timeout).returns(nil) transport.expects(:enqueue_message).with { |msg| msg.content == expected_packet.content } assert_raises(Net::SSH::Timeout) { session(options).process } end @@ -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 } - IO.stubs(:select).with([socket],[],nil,timeout).returns([[socket],[],[]]) + IO.stubs(:select).with([socket], [], nil, timeout).returns([[socket], [], []]) socket.stubs(:recv).returns("x") transport.expects(:enqueue_message).never session(options).process @@ -422,20 +422,20 @@ module Connection timeout = 10 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) + IO.stubs(:select).with([socket], [], nil, timeout).returns(nil) transport.expects(:enqueue_message).times(2) 3.times { session(options).process } end def test_process_should_call_io_select_with_nil_as_last_arg_if_keepalive_disabled - IO.expects(:select).with([socket],[],nil,nil).returns([[],[],[]]) + IO.expects(:select).with([socket], [], nil, nil).returns([[], [], []]) session.process end def test_process_should_call_io_select_with_interval_as_last_arg_if_keepalive_interval_passed timeout = 10 options = { keepalive: true, keepalive_interval: timeout } - IO.expects(:select).with([socket],[],nil,timeout).returns([[],[],[]]) + IO.expects(:select).with([socket], [], nil, timeout).returns([[], [], []]) session(options).process end @@ -443,13 +443,13 @@ module Connection timeout = 10 wait = 5 options = { keepalive: true, keepalive_interval: timeout } - IO.expects(:select).with([socket],[],nil,wait).returns([[],[],[]]) + IO.expects(:select).with([socket], [], nil, wait).returns([[], [], []]) session(options).process(wait) end def test_loop_should_call_process_until_process_returns_false session.expects(:process).with(0) - session.expects(:process).with(nil).times(4).returns(true,true,true,false).yields + session.expects(:process).with(nil).times(4).returns(true, true, true, false).yields n = 0 session.loop { n += 1 } assert_equal 4, n @@ -520,7 +520,7 @@ module Connection private def prep_exec(command, *data) - IO.expects(:select).with([socket],[],nil,0).returns([[],[],[]]) + IO.expects(:select).with([socket], [], nil, 0).returns([[], [], []]) transport.mock_enqueue = true transport.expect do |t, p| assert_equal CHANNEL_OPEN, p.type @@ -544,7 +544,7 @@ module Connection end t2.return(CHANNEL_CLOSE, :long, p[:remote_id]) - t2.expect { |_t3,p3| assert_equal CHANNEL_CLOSE, p3.type } + t2.expect { |_t3, p3| assert_equal CHANNEL_CLOSE, p3.type } end end end @@ -570,11 +570,11 @@ module Connection session.channels[local_id] = stub("channel", process: true, local_closed?: false) end - def transport(options={}) + def transport(options = {}) @transport ||= MockTransport.new(options.merge(socket: socket)) end - def session(options={}) + def session(options = {}) @session ||= Net::SSH::Connection::Session.new(transport, options) end diff --git a/test/integration/common.rb b/test/integration/common.rb index b897ece..9f56fe9 100644 --- a/test/integration/common.rb +++ b/test/integration/common.rb @@ -20,14 +20,14 @@ module IntegrationTestHelpers end end - def set_authorized_key(user,pubkey) + def set_authorized_key(user, pubkey) authorized_key = "/home/#{user}/.ssh/authorized_keys" sh "sudo cp #{pubkey} #{authorized_key}" sh "sudo chown #{user} #{authorized_key}" sh "sudo chmod 0744 #{authorized_key}" end - def sign_user_key(user,pubkey) + def sign_user_key(user, pubkey) cert = "/etc/ssh/users_ca" sh "sudo ssh-keygen -s #{cert} -I user_#{user} -n #{user} -V +52w #{pubkey}" end @@ -48,7 +48,7 @@ module IntegrationTestHelpers end end - def ssh_add(key,password) + def ssh_add(key, password) command = "ssh-add #{key}" status = nil PTY.spawn(command) do |reader, writer, pid| diff --git a/test/integration/mitm_server.rb b/test/integration/mitm_server.rb index 365c318..750748c 100644 --- a/test/integration/mitm_server.rb +++ b/test/integration/mitm_server.rb @@ -49,7 +49,7 @@ class MitmServer < TCPServer server = start_server(server) do |local| remote = TCPSocket.new(remote_host, remote_port) loop do - r,_w,_e = IO.select([local, remote],nil,nil) + r, _w, _e = IO.select([local, remote], nil, nil) if r.include? local begin data = local.recv local_read_size diff --git a/test/integration/test_cert_user_auth.rb b/test/integration/test_cert_user_auth.rb index b975d0a..596d150 100644 --- a/test/integration/test_cert_user_auth.rb +++ b/test/integration/test_cert_user_auth.rb @@ -14,7 +14,7 @@ unless ENV['NET_SSH_NO_ED25519'] Dir.mktmpdir do |dir| sh "rm -rf #{dir}/id_rsa_ed25519 #{dir}/id_rsa_ed25519.pub" sh "ssh-keygen -q -f #{dir}/id_rsa_ed25519 -t ed25519 -N ''" - sign_user_key('net_ssh_1',"#{dir}/id_rsa_ed25519.pub") + sign_user_key('net_ssh_1', "#{dir}/id_rsa_ed25519.pub") ret = Net::SSH.start("localhost", "net_ssh_1", keys: "#{dir}/id_rsa_ed25519") do |ssh| ssh.exec! 'echo "hello from:$USER"' @@ -27,7 +27,7 @@ unless ENV['NET_SSH_NO_ED25519'] Dir.mktmpdir do |dir| sh "rm -rf #{dir}/id_rsa_ed25519 #{dir}/id_rsa_ed25519.pub" sh "ssh-keygen -q -f #{dir}/id_rsa_ed25519 -t ed25519 -N ''" - sign_user_key('net_ssh_1',"#{dir}/id_rsa_ed25519.pub") + sign_user_key('net_ssh_1', "#{dir}/id_rsa_ed25519.pub") sh "mv #{dir}/id_rsa_ed25519-cert.pub #{dir}/cert" ret = Net::SSH.start("localhost", "net_ssh_1", keys: "#{dir}/id_rsa_ed25519", keycerts: "#{dir}/cert") do |ssh| @@ -42,7 +42,7 @@ unless ENV['NET_SSH_NO_ED25519'] with_agent do sh "rm -rf #{dir}/id_rsa_ed25519 #{dir}/id_rsa_ed25519.pub" sh "ssh-keygen -q -f #{dir}/id_rsa_ed25519 -t ed25519 -N 'pwd'" - sign_user_key('net_ssh_1',"#{dir}/id_rsa_ed25519.pub") + sign_user_key('net_ssh_1', "#{dir}/id_rsa_ed25519.pub") ssh_add("#{dir}/id_rsa_ed25519", "pwd") sh "rm -rf #{dir}/id_rsa_ed25519 #{dir}/id_rsa_ed25519.pub #{dir}/id_rsa_ed25519-cert.pub" @@ -61,7 +61,7 @@ unless ENV['NET_SSH_NO_ED25519'] sh "ssh-keygen -q -f #{dir}/id_rsa_ed25519 -t ed25519 -N ''" # add key before signing cert ssh_add("#{dir}/id_rsa_ed25519", "pwd") - sign_user_key('net_ssh_1',"#{dir}/id_rsa_ed25519.pub") + sign_user_key('net_ssh_1', "#{dir}/id_rsa_ed25519.pub") sh "rm -rf #{dir}/id_rsa_ed25519 #{dir}/id_rsa_ed25519.pub" ret = Net::SSH.start("localhost", "net_ssh_1", keycerts: "#{dir}/id_rsa_ed25519-cert.pub") do |ssh| diff --git a/test/integration/test_channel.rb b/test/integration/test_channel.rb index 2a24eda..cd23c9e 100644 --- a/test/integration/test_channel.rb +++ b/test/integration/test_channel.rb @@ -25,7 +25,7 @@ class TestChannel < NetSSHTest @key_id_rsa = "#{dir}/id_rsa" sh "rm -rf #{@key_id_rsa} #{@key_id_rsa}.pub" sh "ssh-keygen -q -f #{@key_id_rsa} -t rsa -N ''" - set_authorized_key(user,"#{@key_id_rsa}.pub") + set_authorized_key(user, "#{@key_id_rsa}.pub") yield end end diff --git a/test/integration/test_ed25519_pkeys.rb b/test/integration/test_ed25519_pkeys.rb index 3358af7..0017801 100644 --- a/test/integration/test_ed25519_pkeys.rb +++ b/test/integration/test_ed25519_pkeys.rb @@ -15,7 +15,7 @@ unless ENV['NET_SSH_NO_ED25519'] Dir.mktmpdir do |dir| sh "rm -rf #{dir}/id_rsa_ed25519 #{dir}/id_rsa_ed25519.pub" sh "ssh-keygen -q -f #{dir}/id_rsa_ed25519 -t ed25519 -N ''" - set_authorized_key('net_ssh_1',"#{dir}/id_rsa_ed25519.pub") + set_authorized_key('net_ssh_1', "#{dir}/id_rsa_ed25519.pub") ret = Net::SSH.start("localhost", "net_ssh_1", { keys: "#{dir}/id_rsa_ed25519" }) do |ssh| ssh.exec! 'echo "hello from:$USER"' @@ -29,8 +29,8 @@ unless ENV['NET_SSH_NO_ED25519'] with_agent do sh "rm -rf #{dir}/id_rsa_ed25519 #{dir}/id_rsa_ed25519.pub" sh "ssh-keygen -q -f #{dir}/id_rsa_ed25519 -t ed25519 -N 'pwd'" - set_authorized_key('net_ssh_1',"#{dir}/id_rsa_ed25519.pub") - ssh_add("#{dir}/id_rsa_ed25519","pwd") + set_authorized_key('net_ssh_1', "#{dir}/id_rsa_ed25519.pub") + ssh_add("#{dir}/id_rsa_ed25519", "pwd") # 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" @@ -47,7 +47,7 @@ unless ENV['NET_SSH_NO_ED25519'] Dir.mktmpdir do |dir| sh "rm -rf #{dir}/id_rsa_ed25519 #{dir}/id_rsa_ed25519.pub" sh "ssh-keygen -q -f #{dir}/id_rsa_ed25519 -t ed25519 -N 'pwd'" - set_authorized_key('net_ssh_1',"#{dir}/id_rsa_ed25519.pub") + set_authorized_key('net_ssh_1', "#{dir}/id_rsa_ed25519.pub") # 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" diff --git a/test/integration/test_forward.rb b/test/integration/test_forward.rb index e7c87da..f006e2d 100644 --- a/test/integration/test_forward.rb +++ b/test/integration/test_forward.rb @@ -33,7 +33,7 @@ class ForwardTestBase < 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) @@ -41,7 +41,7 @@ class ForwardTestBase < NetSSHTest @key_id_rsa = "#{dir}/id_rsa" sh "rm -rf #{@key_id_rsa} #{@key_id_rsa}.pub" sh "ssh-keygen -q -f #{@key_id_rsa} -t rsa -N ''" - set_authorized_key(user,"#{@key_id_rsa}.pub") + set_authorized_key(user, "#{@key_id_rsa}.pub") yield end end @@ -66,7 +66,7 @@ class ForwardTestBase < NetSSHTest end class TestForward < ForwardTestBase - def start_server_closing_soon(exceptions=nil) + def start_server_closing_soon(exceptions = nil) server = TCPServer.open(0) Thread.start do loop do @@ -294,7 +294,7 @@ class TestForward < ForwardTestBase attr_reader :sockets def open(host, port, connection_options = nil) - socket = TCPSocket.new(host,port) + socket = TCPSocket.new(host, port) @sockets << socket socket end diff --git a/test/integration/test_hmac_etm.rb b/test/integration/test_hmac_etm.rb index 0c7182c..1111a26 100644 --- a/test/integration/test_hmac_etm.rb +++ b/test/integration/test_hmac_etm.rb @@ -30,7 +30,7 @@ class TestHMacEtm < NetSSHTest config_lines.push("MACs #{macs}") end - variants.each do |key,variant| + variants.each do |key, variant| define_method "test_with_only_hmac_etm#{key}" do start_sshd_7_or_later(config: config_with_macs(variant)) do |_pid, port| Timeout.timeout(4) do diff --git a/test/integration/test_http_proxy.rb b/test/integration/test_http_proxy.rb index fa71faf..a59eb60 100644 --- a/test/integration/test_http_proxy.rb +++ b/test/integration/test_http_proxy.rb @@ -31,7 +31,7 @@ class TestHTTPProxy < NetSSHTest @key_id_rsa = "#{dir}/id_rsa" sh "rm -rf #{@key_id_rsa} #{@key_id_rsa}.pub" sh "ssh-keygen -q -f #{@key_id_rsa} -t rsa -N ''" - set_authorized_key(user,"#{@key_id_rsa}.pub") + set_authorized_key(user, "#{@key_id_rsa}.pub") yield end end diff --git a/test/integration/test_id_rsa_keys.rb b/test/integration/test_id_rsa_keys.rb index 84d6728..44894cc 100644 --- a/test/integration/test_id_rsa_keys.rb +++ b/test/integration/test_id_rsa_keys.rb @@ -14,7 +14,7 @@ class TestIDRSAPKeys < NetSSHTest tmpdir do |dir| sh "rm -rf #{dir}/id_rsa #{dir}/id_rsa.pub" sh "ssh-keygen -q -f #{dir}/id_rsa -t rsa -N ''" - set_authorized_key('net_ssh_1',"#{dir}/id_rsa.pub") + set_authorized_key('net_ssh_1', "#{dir}/id_rsa.pub") ret = Net::SSH.start("localhost", "net_ssh_1", { keys: "#{dir}/id_rsa" }) do |ssh| ssh.exec! 'echo "hello from:$USER"' @@ -29,8 +29,8 @@ class TestIDRSAPKeys < NetSSHTest with_agent do sh "rm -rf #{dir}/id_rsa #{dir}/id_rsa.pub" sh "ssh-keygen -q -f #{dir}/id_rsa -t rsa -N 'pwd123'" - set_authorized_key('net_ssh_1',"#{dir}/id_rsa.pub") - ssh_add("#{dir}/id_rsa","pwd123") + set_authorized_key('net_ssh_1', "#{dir}/id_rsa.pub") + ssh_add("#{dir}/id_rsa", "pwd123") ret = Net::SSH.start("localhost", "net_ssh_1") do |ssh| ssh.exec! 'echo "hello from:$USER"' @@ -45,8 +45,8 @@ class TestIDRSAPKeys < NetSSHTest with_agent do sh "rm -rf #{dir}/id_rsa #{dir}/id_rsa.pub" sh "ssh-keygen -q -f #{dir}/id_rsa -t rsa -N 'pwd123'" - set_authorized_key('net_ssh_1',"#{dir}/id_rsa.pub") - ssh_add("#{dir}/id_rsa","pwd123") + set_authorized_key('net_ssh_1', "#{dir}/id_rsa.pub") + ssh_add("#{dir}/id_rsa", "pwd123") ret = Net::SSH.start("localhost", "net_ssh_1", keys: ["#{dir}/id_rsa"]) do |ssh| ssh.exec! 'echo "hello from:$USER"' @@ -60,7 +60,7 @@ class TestIDRSAPKeys < NetSSHTest tmpdir do |dir| sh "rm -rf #{dir}/id_rsa #{dir}/id_rsa.pub" sh "ssh-keygen -q -f #{dir}/id_rsa -t rsa -N 'pwd12'" - set_authorized_key('net_ssh_1',"#{dir}/id_rsa.pub") + set_authorized_key('net_ssh_1', "#{dir}/id_rsa.pub") ret = Net::SSH.start("localhost", "net_ssh_1", { keys: "#{dir}/id_rsa", passphrase: 'pwd12' }) do |ssh| ssh.exec! 'echo "hello from:$USER"' @@ -74,7 +74,7 @@ class TestIDRSAPKeys < NetSSHTest tmpdir do |dir| sh "rm -rf #{dir}/id_rsa #{dir}/id_rsa.pub" sh "ssh-keygen -q -f #{dir}/id_rsa -t rsa -N 'pwd12'" - set_authorized_key('net_ssh_1',"#{dir}/id_rsa.pub") + set_authorized_key('net_ssh_1', "#{dir}/id_rsa.pub") private_key = File.read("#{dir}/id_rsa") options = { keys: [], key_data: [private_key] } diff --git a/test/integration/test_proxy.rb b/test/integration/test_proxy.rb index f1419f8..6572c42 100644 --- a/test/integration/test_proxy.rb +++ b/test/integration/test_proxy.rb @@ -19,7 +19,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) @@ -27,7 +27,7 @@ class TestProxy < NetSSHTest @key_id_rsa = "#{dir}/id_rsa" sh "rm -rf #{@key_id_rsa} #{@key_id_rsa}.pub" sh "ssh-keygen -q -f #{@key_id_rsa} -t rsa -N ''" - set_authorized_key(user,"#{@key_id_rsa}.pub") + set_authorized_key(user, "#{@key_id_rsa}.pub") yield end end @@ -39,7 +39,7 @@ class TestProxy < NetSSHTest @gwkey_id_rsa = "#{dir}/id_rsa" sh "rm -rf #{@gwkey_id_rsa} #{@gwkey_id_rsa}.pub" sh "ssh-keygen -q -f #{@gwkey_id_rsa} -t rsa -N ''" - set_authorized_key(gwuser,"#{@gwkey_id_rsa}.pub") + set_authorized_key(gwuser, "#{@gwkey_id_rsa}.pub") config = "Host #{gwhost} IdentityFile #{@gwkey_id_rsa} StrictHostKeyChecking no @@ -67,7 +67,7 @@ class TestProxy < NetSSHTest end end - def with_spurious_write_wakeup_emulate(rate=99,&block) + def with_spurious_write_wakeup_emulate(rate = 99, &block) orig_io_select = IO.method(:select) count = 0 @@ -75,7 +75,7 @@ class TestProxy < NetSSHTest count += 1 if (count % rate != 0) if params && params[1] && !params[1].empty? - return [[],params[1],[]] + return [[], params[1], []] end end orig_io_select.call(*params) diff --git a/test/manual/test_pageant.rb b/test/manual/test_pageant.rb index e9a72da..b07e82c 100644 --- a/test/manual/test_pageant.rb +++ b/test/manual/test_pageant.rb @@ -28,7 +28,7 @@ module Authentication private - def agent(auto=:connect) + def agent(auto = :connect) @agent ||= begin agent = Net::SSH::Authentication::Agent.new agent.connect! if auto == :connect diff --git a/test/test_buffer.rb b/test/test_buffer.rb index 1275896..c4fc9f2 100644 --- a/test/test_buffer.rb +++ b/test/test_buffer.rb @@ -56,7 +56,7 @@ class TestBuffer < NetSSHTest end def test_from_with_array_argument_should_write_multiple_of_the_given_type - buffer = Net::SSH::Buffer.from(:byte, [1,2,3,4,5]) + buffer = Net::SSH::Buffer.from(:byte, [1, 2, 3, 4, 5]) assert_equal "\1\2\3\4\5", buffer.to_s end diff --git a/test/test_config.rb b/test/test_config.rb index e315c86..82c2377 100644 --- a/test/test_config.rb +++ b/test/test_config.rb @@ -543,7 +543,7 @@ class TestConfig < NetSSHTest private - def with_home_env(value,&block) + def with_home_env(value, &block) env_home_before = ENV['HOME'] begin ENV['HOME'] = value diff --git a/test/test_key_factory.rb b/test/test_key_factory.rb index f0a5116..c6f7705 100644 --- a/test/test_key_factory.rb +++ b/test/test_key_factory.rb @@ -65,7 +65,7 @@ class TestKeyFactory < NetSSHTest def test_load_encrypted_private_key_should_give_three_tries_for_the_password_and_then_raise_exception prompt = MockPrompt.new File.expects(:read).with(@key_file).returns(encrypted(rsa_key, "password")) - prompt.expects(:_ask).times(3).with("Enter passphrase for #{@key_file}:", has_entries(type: 'private_key', filename: @key_file), false).returns("passwod","passphrase","passwd") + prompt.expects(:_ask).times(3).with("Enter passphrase for #{@key_file}:", has_entries(type: 'private_key', filename: @key_file), false).returns("passwod", "passphrase", "passwd") if OpenSSL::PKey.respond_to?(:read) error_class = [ArgumentError, OpenSSL::PKey::PKeyError] else diff --git a/test/test_known_hosts.rb b/test/test_known_hosts.rb index 5bd7668..f960351 100644 --- a/test/test_known_hosts.rb +++ b/test/test_known_hosts.rb @@ -28,7 +28,7 @@ class TestKnownHosts < NetSSHTest assert_equal(0, keys.count) assert_equal([], keys.to_a) - kh.add('github2.com',rsa_key) + 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 @@ -36,89 +36,89 @@ class TestKnownHosts < NetSSHTest def test_search_for options = { user_known_hosts_file: path("known_hosts/github"), global_known_hosts_file: [] } - keys = Net::SSH::KnownHosts.search_for('github.com',options) + keys = Net::SSH::KnownHosts.search_for('github.com', options) assert_equal(["ssh-rsa"], keys.map(&:ssh_type)) end def test_search_for_with_hostname_and_right_ip_with_check_host_ip options = { user_known_hosts_file: path("known_hosts/gitlab"), check_host_ip: true } - keys = Net::SSH::KnownHosts.search_for('gitlab.com,35.231.145.151',options) + keys = Net::SSH::KnownHosts.search_for('gitlab.com,35.231.145.151', options) assert_equal(1, keys.count) end def test_search_for_with_hostname_and_right_ip_without_check_host_ip options = { user_known_hosts_file: path("known_hosts/gitlab"), check_host_ip: false } - keys = Net::SSH::KnownHosts.search_for('gitlab.com,35.231.145.151',options) + keys = Net::SSH::KnownHosts.search_for('gitlab.com,35.231.145.151', options) assert_equal(1, keys.count) end def test_search_for_with_hostname_and_wrong_ip_with_check_host_ip options = { user_known_hosts_file: path("known_hosts/gitlab"), check_host_ip: true } - keys = Net::SSH::KnownHosts.search_for('gitlab.com,192.0.2.1',options) + keys = Net::SSH::KnownHosts.search_for('gitlab.com,192.0.2.1', options) assert_equal(0, keys.count) end def test_search_for_with_hostname_and_wrong_ip_without_check_host_ip options = { user_known_hosts_file: path("known_hosts/gitlab"), check_host_ip: false } - keys = Net::SSH::KnownHosts.search_for('gitlab.com,192.0.2.2',options) + keys = Net::SSH::KnownHosts.search_for('gitlab.com,192.0.2.2', options) assert_equal(1, keys.count) end def test_search_for_with_hostname_only_with_check_host_ip options = { user_known_hosts_file: path("known_hosts/gitlab"), check_host_ip: true } - keys = Net::SSH::KnownHosts.search_for('gitlab.com',options) + keys = Net::SSH::KnownHosts.search_for('gitlab.com', options) assert_equal(1, keys.count) end def test_search_for_with_hostname_only_without_check_host_ip options = { user_known_hosts_file: path("known_hosts/gitlab"), check_host_ip: false } - keys = Net::SSH::KnownHosts.search_for('gitlab.com',options) + keys = Net::SSH::KnownHosts.search_for('gitlab.com', options) assert_equal(1, keys.count) end def test_search_for_with_ip_only_with_check_host_ip options = { user_known_hosts_file: path("known_hosts/gitlab"), check_host_ip: true } - keys = Net::SSH::KnownHosts.search_for('35.231.145.151',options) + keys = Net::SSH::KnownHosts.search_for('35.231.145.151', options) assert_equal(1, keys.count) end def test_search_for_with_ip_only_without_check_host_ip options = { user_known_hosts_file: path("known_hosts/gitlab"), check_host_ip: false } - keys = Net::SSH::KnownHosts.search_for('35.231.145.151',options) + keys = Net::SSH::KnownHosts.search_for('35.231.145.151', options) assert_equal(1, keys.count) end def test_search_for_with_hostname_matching_pattern options = { user_known_hosts_file: path("known_hosts/misc") } - keys = Net::SSH::KnownHosts.search_for('subdomain.gitfoo.com',options) + keys = Net::SSH::KnownHosts.search_for('subdomain.gitfoo.com', options) assert_equal(1, keys.count) end def test_search_for_with_hostname_not_matching_pattern_1 options = { user_known_hosts_file: path("known_hosts/misc") } - keys = Net::SSH::KnownHosts.search_for('gitfoo.com',options) + keys = Net::SSH::KnownHosts.search_for('gitfoo.com', options) assert_equal(0, keys.count) end def test_search_for_with_hostname_not_matching_pattern_2 options = { user_known_hosts_file: path("known_hosts/misc") } - keys = Net::SSH::KnownHosts.search_for('subdomain.gitmisc.com',options) + keys = Net::SSH::KnownHosts.search_for('subdomain.gitmisc.com', options) assert_equal(0, keys.count) end def test_search_for_with_hostname_not_matching_pattern_3 options = { user_known_hosts_file: path("known_hosts/misc") } - keys = Net::SSH::KnownHosts.search_for('subsubdomain.subdomain.gitfoo.com',options) + keys = Net::SSH::KnownHosts.search_for('subsubdomain.subdomain.gitfoo.com', options) assert_equal(1, keys.count) end def test_asterisk_matches_multiple_dots with_config_file(lines: ["*.git???.com #{sample_key}"]) do |path| options = { user_known_hosts_file: path } - keys = Net::SSH::KnownHosts.search_for('subsubdomain.subdomain.gitfoo.com',options) + keys = Net::SSH::KnownHosts.search_for('subsubdomain.subdomain.gitfoo.com', options) assert_equal(1, keys.count) - keys = Net::SSH::KnownHosts.search_for('subsubdomain.subdomain.gitfoo2.com',options) + keys = Net::SSH::KnownHosts.search_for('subsubdomain.subdomain.gitfoo2.com', options) assert_equal(0, keys.count) end end @@ -126,10 +126,10 @@ class TestKnownHosts < NetSSHTest def test_asterisk_matches_everything with_config_file(lines: ["* #{sample_key}"]) do |path| options = { user_known_hosts_file: path } - keys = Net::SSH::KnownHosts.search_for('subsubdomain.subdomain.gitfoo.com',options) + keys = Net::SSH::KnownHosts.search_for('subsubdomain.subdomain.gitfoo.com', options) assert_equal(1, keys.count) - keys = Net::SSH::KnownHosts.search_for('subsubdomain.subdomain.gitfoo2.com',options) + keys = Net::SSH::KnownHosts.search_for('subsubdomain.subdomain.gitfoo2.com', options) assert_equal(1, keys.count) end end @@ -138,13 +138,13 @@ class TestKnownHosts < NetSSHTest 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) + 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) + keys = Net::SSH::KnownHosts.search_for('github2.com', options) assert_equal([rsa_key.to_blob], keys.map(&:to_blob)) end end diff --git a/test/transport/kex/test_diffie_hellman_group1_sha1.rb b/test/transport/kex/test_diffie_hellman_group1_sha1.rb index 5d6df93..a3b846c 100644 --- a/test/transport/kex/test_diffie_hellman_group1_sha1.rb +++ b/test/transport/kex/test_diffie_hellman_group1_sha1.rb @@ -85,7 +85,7 @@ module Transport private - def exchange!(options={}) + def exchange!(options = {}) connection.expect do |t, buffer| assert_equal KEXDH_INIT, buffer.type assert_equal dh.dh.pub_key, buffer.read_bignum @@ -99,7 +99,7 @@ module Transport dh.exchange_keys end - def dh_options(options={}) + def dh_options(options = {}) @dh_options = options end @@ -107,7 +107,7 @@ module Transport @dh ||= subject.new(algorithms, connection, packet_data.merge(need_bytes: 20).merge(@dh_options || {})) end - def algorithms(options={}) + def algorithms(options = {}) @algorithms ||= OpenStruct.new(host_key: options[:host_key] || "ssh-rsa", host_key_format: options[:host_key] || "ssh-rsa") end @@ -121,7 +121,7 @@ module Transport # 512 bits is the smallest possible key that will work with this, so # we use it for speed reasons - def server_key(bits=512) + def server_key(bits = 512) @server_key ||= OpenSSL::PKey::RSA.new(bits) end @@ -143,13 +143,13 @@ module Transport def session_id @session_id ||= begin buffer = Net::SSH::Buffer.from(:string, packet_data[:client_version_string], - :string, packet_data[:server_version_string], - :string, packet_data[:client_algorithm_packet], - :string, packet_data[:server_algorithm_packet], - :string, Net::SSH::Buffer.from(:key, server_key), - :bignum, dh.dh.pub_key, - :bignum, server_dh_pubkey, - :bignum, shared_secret) + :string, packet_data[:server_version_string], + :string, packet_data[:client_algorithm_packet], + :string, packet_data[:server_algorithm_packet], + :string, Net::SSH::Buffer.from(:key, server_key), + :bignum, dh.dh.pub_key, + :bignum, server_dh_pubkey, + :bignum, shared_secret) digest_type.digest(buffer.to_s) end end @@ -158,7 +158,7 @@ module Transport @signature ||= server_key.ssh_do_sign(session_id) end - def bn(number, base=10) + def bn(number, base = 10) OpenSSL::BN.new(number.to_s, base) end 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 29a7d36..d0df04b 100644 --- a/test/transport/kex/test_diffie_hellman_group_exchange_sha1.rb +++ b/test/transport/kex/test_diffie_hellman_group_exchange_sha1.rb @@ -42,11 +42,11 @@ module Transport private - def need_bits(bits=1024) + def need_bits(bits = 1024) @need_bits ||= need_minimum(bits) end - def need_minimum(bits=1024) + def need_minimum(bits = 1024) return @dh_options[:minimum_dh_bits] if @dh_options && @dh_options[:minimum_dh_bits] bits @@ -56,7 +56,7 @@ module Transport 142326151570335518660743995281621698377057354949884468943021767573608899048361360422513557553514790045512299468953431585300812548859419857171094366358158903433167915517332113861059747425408670144201099811846875730766487278261498262568348338476437200556998366087779709990807518291581860338635288400119315130179 end - def exchange!(options={}) + def exchange!(options = {}) connection.expect do |t, buffer| assert_equal KEXDH_GEX_REQUEST, buffer.type assert_equal need_minimum, buffer.read_long @@ -88,18 +88,18 @@ module Transport def session_id @session_id ||= begin buffer = Net::SSH::Buffer.from(:string, packet_data[:client_version_string], - :string, packet_data[:server_version_string], - :string, packet_data[:client_algorithm_packet], - :string, packet_data[:server_algorithm_packet], - :string, Net::SSH::Buffer.from(:key, server_key), - :long, 1024, - :long, need_bits, # need bits, figure this part out, - :long, 8192, - :bignum, dh.dh.p, - :bignum, dh.dh.g, - :bignum, dh.dh.pub_key, - :bignum, server_dh_pubkey, - :bignum, shared_secret) + :string, packet_data[:server_version_string], + :string, packet_data[:client_algorithm_packet], + :string, packet_data[:server_algorithm_packet], + :string, Net::SSH::Buffer.from(:key, server_key), + :long, 1024, + :long, need_bits, # need bits, figure this part out, + :long, 8192, + :bignum, dh.dh.p, + :bignum, dh.dh.g, + :bignum, dh.dh.pub_key, + :bignum, server_dh_pubkey, + :bignum, shared_secret) digest_type.digest(buffer.to_s) end end diff --git a/test/transport/test_algorithms.rb b/test/transport/test_algorithms.rb index d4f9737..e52782c 100644 --- a/test/transport/test_algorithms.rb +++ b/test/transport/test_algorithms.rb @@ -146,7 +146,7 @@ module Transport def test_constructor_with_unrecognized_hmac_should_ignore_those assert_equal %w[hmac-sha2-512-etm@openssh.com hmac-sha2-256-etm@openssh.com hmac-sha2-512 hmac-sha2-256 hmac-sha1 hmac-sha2-512-96 hmac-sha2-256-96 hmac-sha1-96 hmac-ripemd160 hmac-ripemd160@openssh.com hmac-md5 hmac-md5-96 none], - algorithms(hmac: "unknown hmac-md5-96", append_all_supported_algorithms: true)[:hmac] + algorithms(hmac: "unknown hmac-md5-96", append_all_supported_algorithms: true)[:hmac] end def test_constructor_with_preferred_hmac_supports_additions @@ -224,7 +224,7 @@ module Transport def test_key_exchange_when_server_does_not_support_preferred_kex_should_fallback_to_secondary kexinit kex: "diffie-hellman-group14-sha1" - transport.expect do |_t,buffer| + transport.expect do |_t, buffer| assert_kexinit(buffer) install_mock_key_exchange(buffer, kex: Net::SSH::Transport::Kex::DiffieHellmanGroup1SHA1) end @@ -233,7 +233,7 @@ module Transport def test_key_exchange_when_server_does_not_support_any_preferred_kex_should_raise_error kexinit kex: "something-obscure" - transport.expect { |_t,buffer| assert_kexinit(buffer) } + transport.expect { |_t, buffer| assert_kexinit(buffer) } assert_raises(Net::SSH::Exception) { algorithms.accept_kexinit(kexinit) } end @@ -335,7 +335,7 @@ module Transport private - def install_mock_key_exchange(buffer, options={}) + def install_mock_key_exchange(buffer, options = {}) kex = options[:kex] || Net::SSH::Transport::Kex::DiffieHellmanGroupExchangeSHA256 Net::SSH::Transport::Kex::MAP.each do |_name, klass| @@ -346,17 +346,17 @@ 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: 32, - minimum_dh_bits: nil, - logger: nil) + 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: 32, + 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={}) + def install_mock_algorithm_lookups(options = {}) params = { shared: shared_secret.to_ssh, hash: session_id, digester: hashing_algorithm } Net::SSH::Transport::CipherFactory.expects(:get) .with(options[:client_cipher] || "aes256-ctr", params.merge(iv: key("A"), key: key("C"), encrypt: true)) @@ -386,27 +386,27 @@ module Transport hashing_algorithm.digest(shared_secret.to_ssh + session_id + salt + session_id) end - def cipher(type, options={}) + def cipher(type, options = {}) Net::SSH::Transport::CipherFactory.get(type, options) end - def kexinit(options={}) + def kexinit(options = {}) @kexinit ||= P(:byte, KEXINIT, - :long, rand(0xFFFFFFFF), :long, rand(0xFFFFFFFF), :long, rand(0xFFFFFFFF), :long, rand(0xFFFFFFFF), - :string, options[:kex] || "diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha256,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1", - :string, options[:host_key] || "ssh-rsa,ssh-dss", - :string, options[:encryption_client] || "aes256-ctr,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,rijndael-cbc@lysator.liu.se,idea-cbc", - :string, options[:encryption_server] || "aes256-ctr,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,rijndael-cbc@lysator.liu.se,idea-cbc", - :string, options[:hmac_client] || "hmac-sha2-256,hmac-sha1,hmac-md5,hmac-sha1-96,hmac-md5-96", - :string, options[:hmac_server] || "hmac-sha2-256,hmac-sha1,hmac-md5,hmac-sha1-96,hmac-md5-96", - :string, options[:compression_client] || "none,zlib@openssh.com,zlib", - :string, options[:compression_server] || "none,zlib@openssh.com,zlib", - :string, options[:language_client] || "", - :string, options[:language_server] || "", - :bool, options[:first_kex_follows]) - end - - def assert_kexinit(buffer, options={}) + :long, rand(0xFFFFFFFF), :long, rand(0xFFFFFFFF), :long, rand(0xFFFFFFFF), :long, rand(0xFFFFFFFF), + :string, options[:kex] || "diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha256,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1", + :string, options[:host_key] || "ssh-rsa,ssh-dss", + :string, options[:encryption_client] || "aes256-ctr,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,rijndael-cbc@lysator.liu.se,idea-cbc", + :string, options[:encryption_server] || "aes256-ctr,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,rijndael-cbc@lysator.liu.se,idea-cbc", + :string, options[:hmac_client] || "hmac-sha2-256,hmac-sha1,hmac-md5,hmac-sha1-96,hmac-md5-96", + :string, options[:hmac_server] || "hmac-sha2-256,hmac-sha1,hmac-md5,hmac-sha1-96,hmac-md5-96", + :string, options[:compression_client] || "none,zlib@openssh.com,zlib", + :string, options[:compression_server] || "none,zlib@openssh.com,zlib", + :string, options[:language_client] || "", + :string, options[:language_server] || "", + :bool, options[:first_kex_follows]) + end + + def assert_kexinit(buffer, options = {}) assert_equal KEXINIT, buffer.type assert_equal 16, buffer.read(16).length assert_equal options[:kex] || (x25519_kex + ec_kex + %w[diffie-hellman-group-exchange-sha256 diffie-hellman-group14-sha256 diffie-hellman-group14-sha1]).join(','), buffer.read_string @@ -433,14 +433,14 @@ module Transport assert_equal :server_hmac, transport.server_options[:hmac] end - def algorithms(algorithms_options={}, transport_options={}) + def algorithms(algorithms_options = {}, transport_options = {}) @algorithms ||= Net::SSH::Transport::Algorithms.new( transport(transport_options), algorithms_options ) end - def transport(transport_options={}) + def transport(transport_options = {}) @transport ||= MockTransport.new( { user_known_hosts_file: '/dev/null', diff --git a/test/transport/test_cipher_factory.rb b/test/transport/test_cipher_factory.rb index 768fbf8..0d651aa 100644 --- a/test/transport/test_cipher_factory.rb +++ b/test/transport/test_cipher_factory.rb @@ -10,66 +10,66 @@ module Transport end def test_lengths_for_none - assert_equal [0,0], factory.get_lengths("none") - assert_equal [0,0], factory.get_lengths("bogus") + assert_equal [0, 0], factory.get_lengths("none") + assert_equal [0, 0], factory.get_lengths("bogus") end def test_lengths_for_blowfish_cbc - assert_equal [16,8], factory.get_lengths("blowfish-cbc") + assert_equal [16, 8], factory.get_lengths("blowfish-cbc") end if_supported?("idea-cbc") do def test_lengths_for_idea_cbc - assert_equal [16,8], factory.get_lengths("idea-cbc") + assert_equal [16, 8], factory.get_lengths("idea-cbc") end end def test_lengths_for_rijndael_cbc - assert_equal [32,16], factory.get_lengths("rijndael-cbc@lysator.liu.se") + assert_equal [32, 16], factory.get_lengths("rijndael-cbc@lysator.liu.se") end def test_lengths_for_cast128_cbc - assert_equal [16,8], factory.get_lengths("cast128-cbc") + assert_equal [16, 8], factory.get_lengths("cast128-cbc") end def test_lengths_for_3des_cbc - assert_equal [24,8], factory.get_lengths("3des-cbc") + assert_equal [24, 8], factory.get_lengths("3des-cbc") end def test_lengths_for_aes128_cbc - assert_equal [16,16], factory.get_lengths("aes128-cbc") + assert_equal [16, 16], factory.get_lengths("aes128-cbc") end def test_lengths_for_aes192_cbc - assert_equal [24,16], factory.get_lengths("aes192-cbc") + assert_equal [24, 16], factory.get_lengths("aes192-cbc") end def test_lengths_for_aes256_cbc - assert_equal [32,16], factory.get_lengths("aes256-cbc") + assert_equal [32, 16], factory.get_lengths("aes256-cbc") end def test_lengths_for_3des_ctr - assert_equal [24,8], factory.get_lengths("3des-ctr") + assert_equal [24, 8], factory.get_lengths("3des-ctr") end def test_lengths_for_aes128_ctr - assert_equal [16,16], factory.get_lengths("aes128-ctr") + assert_equal [16, 16], factory.get_lengths("aes128-ctr") end def test_lengths_for_aes192_ctr - assert_equal [24,16], factory.get_lengths("aes192-ctr") + assert_equal [24, 16], factory.get_lengths("aes192-ctr") end def test_lengths_for_aes256_ctr - assert_equal [32,16], factory.get_lengths("aes256-ctr") + assert_equal [32, 16], factory.get_lengths("aes256-ctr") end def test_lengths_for_blowfish_ctr - assert_equal [16,8], factory.get_lengths("blowfish-ctr") + assert_equal [16, 8], factory.get_lengths("blowfish-ctr") end def test_lengths_for_cast128_ctr - assert_equal [16,8], factory.get_lengths("cast128-ctr") + assert_equal [16, 8], factory.get_lengths("cast128-ctr") end BLOWFISH_CBC = "\210\021\200\315\240_\026$\352\204g\233\244\242x\332e\370\001\327\224Nv@9_\323\037\252kb\037\036\237\375]\343/y\037\237\312Q\f7]\347Y\005\275%\377\0010$G\272\250B\265Nd\375\342\372\025r6}+Y\213y\n\237\267\\\374^\346BdJ$\353\220Ik\023<\236&H\277=\225" @@ -231,7 +231,7 @@ module Transport end def test_aes256_ctr_for_encryption2 - assert_equal [AES256_CTR,AES256_CTR2], encrypt2("aes256-ctr") + assert_equal [AES256_CTR, AES256_CTR2], encrypt2("aes256-ctr") end def test_aes256_ctr_for_decryption diff --git a/test/transport/test_hmac.rb b/test/transport/test_hmac.rb index 009c900..4317b1a 100644 --- a/test/transport/test_hmac.rb +++ b/test/transport/test_hmac.rb @@ -6,7 +6,7 @@ module Transport Net::SSH::Transport::HMAC::MAP.each do |name, _value| 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] + 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 }) assert_instance_of Net::SSH::Transport::HMAC::MAP[name], hmac assert_equal key, hmac.key diff --git a/test/transport/test_packet_stream.rb b/test/transport/test_packet_stream.rb index b79f640..2921765 100644 --- a/test/transport/test_packet_stream.rb +++ b/test/transport/test_packet_stream.rb @@ -57,12 +57,12 @@ module Transport end def test_available_for_read_should_return_nontrue_when_self_is_not_ready - IO.expects(:select).with([stream], nil, nil, 0).returns([[],[],[]]) + IO.expects(:select).with([stream], nil, nil, 0).returns([[], [], []]) assert !stream.available_for_read? end def test_available_for_read_should_return_true_when_self_is_ready - IO.expects(:select).with([stream], nil, nil, 0).returns([[self],[],[]]) + IO.expects(:select).with([stream], nil, nil, 0).returns([[self], [], []]) assert stream.available_for_read? end @@ -134,7 +134,7 @@ module Transport def test_next_packet_should_eventually_return_packet_when_non_blocking_and_partial_read IO.stubs(:select).returns([[stream]]) - stream.stubs(:recv).returns(packet[0,10], packet[10..-1]) + stream.stubs(:recv).returns(packet[0, 10], packet[10..-1]) assert_nil stream.next_packet(:nonblock) packet = stream.next_packet(:nonblock) assert_not_nil packet @@ -159,7 +159,7 @@ module Transport def test_next_packet_should_block_when_requested_until_entire_packet_is_available IO.stubs(:select).returns([[stream]]) - stream.stubs(:recv).returns(packet[0,10], packet[10,20], packet[20..-1]) + stream.stubs(:recv).returns(packet[0, 10], packet[10, 20], packet[20..-1]) packet = stream.next_packet(:block) assert_not_nil packet assert_equal DEBUG, packet.type @@ -181,7 +181,7 @@ module Transport end def test_send_packet_should_enqueue_and_send_data_immediately - stream.expects(:send).times(3).with { |a,b| a == stream.write_buffer && b == 0 }.returns(15) + stream.expects(:send).times(3).with { |a, b| a == stream.write_buffer && b == 0 }.returns(15) IO.expects(:select).times(2).returns([[], [stream]]) stream.send_packet(ssh_packet) assert !stream.pending_write? diff --git a/test/transport/test_server_version.rb b/test/transport/test_server_version.rb index ae443cc..c4b92a3 100644 --- a/test/transport/test_server_version.rb +++ b/test/transport/test_server_version.rb @@ -42,7 +42,7 @@ module Transport private - def socket(good, version_header, raise_eot=false) + def socket(good, version_header, raise_eot = false) socket = mock("socket") socket.expects(:write).with("#{Net::SSH::Transport::ServerVersion::PROTO_VERSION}\r\n") diff --git a/test/transport/test_session.rb b/test/transport/test_session.rb index 117fb89..7a26dfc 100644 --- a/test/transport/test_session.rb +++ b/test/transport/test_session.rb @@ -402,7 +402,7 @@ module Transport @algorithms ||= stub("algorithms", initialized?: true, allow?: true, start: true) end - def session(options={}) + def session(options = {}) @session ||= begin host = options.delete(:host) || TEST_HOST if (proxy = options[:proxy]) diff --git a/test/transport/test_state.rb b/test/transport/test_state.rb index 389f012..bc9b00d 100644 --- a/test/transport/test_state.rb +++ b/test/transport/test_state.rb @@ -161,7 +161,7 @@ module Transport private - def deflater(level=Zlib::DEFAULT_COMPRESSION) + def deflater(level = Zlib::DEFAULT_COMPRESSION) @deflater ||= Zlib::Deflate.new(level) end diff --git a/test/verifiers/test_always.rb b/test/verifiers/test_always.rb index 9d93d9a..c387d7f 100644 --- a/test/verifiers/test_always.rb +++ b/test/verifiers/test_always.rb @@ -16,7 +16,7 @@ class TestAlways < NetSSHTest def test_passess_if_sam secure_verifier = Net::SSH::Verifiers::Always.new - key = OpenStruct.new(ssh_type: 'key_type',to_blob: 'keyblob') + key = OpenStruct.new(ssh_type: 'key_type', to_blob: 'keyblob') host_keys = [key] def host_keys.host 'foo' @@ -26,8 +26,8 @@ class TestAlways < NetSSHTest def test_raises_mismatch_error_if_not_the_same secure_verifier = Net::SSH::Verifiers::Always.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') + 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 diff --git a/test/win_integration/test_pageant.rb b/test/win_integration/test_pageant.rb index b7e89fa..0a909a7 100644 --- a/test/win_integration/test_pageant.rb +++ b/test/win_integration/test_pageant.rb @@ -30,7 +30,7 @@ module Authentication private - def agent(auto=:connect) + def agent(auto = :connect) @agent ||= begin agent = Net::SSH::Authentication::Agent.new agent.connect! if auto == :connect |