diff options
| author | rich <rich@shopittome.com> | 2012-01-21 22:59:50 -0800 |
|---|---|---|
| committer | rich <rich@shopittome.com> | 2012-01-21 22:59:50 -0800 |
| commit | 6c878c82006a4cd7d351625bedf65d70e0f7c9c5 (patch) | |
| tree | 74d7cf216ce73f5d1210e16439a26ac64e744736 /test | |
| parent | 770a08a3767f3f47e2fcd45fe05f46993bedeebc (diff) | |
| parent | a5ebe60f7f6652ea73238b2884e03b87cbac5231 (diff) | |
| download | net-ssh-6c878c82006a4cd7d351625bedf65d70e0f7c9c5.tar.gz | |
Merge remote-tracking branch 'graffic/master'
and fix some tests for windows
* graffic/master:
Adds support for Putty ssh agent and ruby 1.9 (Windows)
Added the same description as github has.
All tests pass Ruby 1.9.2 on Windows
test_ket_manager: Tests should pass in windows too.
Conflicts:
test/authentication/test_key_manager.rb
test/transport/test_algorithms.rb
Diffstat (limited to 'test')
| -rw-r--r-- | test/authentication/test_key_manager.rb | 29 | ||||
| -rw-r--r-- | test/test_config.rb | 5 | ||||
| -rw-r--r-- | test/test_key_factory.rb | 46 |
3 files changed, 46 insertions, 34 deletions
diff --git a/test/authentication/test_key_manager.rb b/test/authentication/test_key_manager.rb index 0c6f585..6078447 100644 --- a/test/authentication/test_key_manager.rb +++ b/test/authentication/test_key_manager.rb @@ -18,7 +18,9 @@ module Authentication manager.add "/second" manager.add "/third" manager.add "/second" - assert_equal %w(/first /second /third), manager.key_files + assert_true manager.key_files.length == 3 + final_files = manager.key_files.map {|item| item.split('/').last} + assert_equal %w(first second third), final_files end def test_use_agent_should_be_set_to_false_if_agent_could_not_be_found @@ -30,9 +32,10 @@ module Authentication def test_each_identity_should_load_from_key_files manager.stubs(:agent).returns(nil) - - stub_file_private_key "/first", rsa - stub_file_private_key "/second", dsa + first = File.expand_path("/first") + second = File.expand_path("/second") + stub_file_private_key first, rsa + stub_file_private_key second, dsa identities = [] manager.each_identity { |identity| identities << identity } @@ -40,9 +43,9 @@ module Authentication assert_equal 2, identities.length 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_identities_should_load_from_agent @@ -62,7 +65,8 @@ module Authentication def test_only_identities_with_key_files_should_load_from_agent_of_keys_only_set manager(:keys_only => true).stubs(:agent).returns(agent) - stub_file_private_key "/first", rsa + first = File.expand_path("/first") + stub_file_private_key first, rsa identities = [] manager.each_identity { |identity| identities << identity } @@ -76,8 +80,10 @@ module Authentication def test_identities_without_public_key_files_should_not_be_touched_if_identity_loaded_from_agent manager.stubs(:agent).returns(agent) - stub_file_public_key "/first", rsa - stub_file_private_key "/second", dsa, :passphrase => :should_not_be_asked + 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 identities = [] manager.each_identity do |identity| @@ -98,7 +104,8 @@ module Authentication def test_sign_with_file_originated_key_should_load_private_key_and_sign_with_it manager.stubs(:agent).returns(nil) - stub_file_private_key "/first", rsa(512) + first = File.expand_path("/first") + stub_file_private_key first, rsa(512) rsa.expects(:ssh_do_sign).with("hello, world").returns("abcxyz123") manager.each_identity { |identity| } # preload the known_identities assert_equal "\0\0\0\assh-rsa\0\0\0\011abcxyz123", manager.sign(rsa, "hello, world") diff --git a/test/test_config.rb b/test/test_config.rb index 5fc9795..548072f 100644 --- a/test/test_config.rb +++ b/test/test_config.rb @@ -3,8 +3,9 @@ require 'net/ssh/config' class TestConfig < Test::Unit::TestCase def test_load_for_non_existant_file_should_return_empty_hash - File.expects(:readable?).with("/bogus/file").returns(false) - assert_equal({}, Net::SSH::Config.load("/bogus/file", "host.name")) + bogus_file = File.expand_path("/bogus/file") + File.expects(:readable?).with(bogus_file).returns(false) + assert_equal({}, Net::SSH::Config.load(bogus_file, "host.name")) end def test_load_should_expand_path diff --git a/test/test_key_factory.rb b/test/test_key_factory.rb index caaa899..8ce07c8 100644 --- a/test/test_key_factory.rb +++ b/test/test_key_factory.rb @@ -2,53 +2,57 @@ require 'common' require 'net/ssh/key_factory' class TestKeyFactory < Test::Unit::TestCase + def setup + @key_file = File.expand_path("/key-file") + end + def test_load_unencrypted_private_RSA_key_should_return_key - File.expects(:read).with("/key-file").returns(rsa_key.export) - assert_equal rsa_key.to_der, Net::SSH::KeyFactory.load_private_key("/key-file").to_der + File.expects(:read).with(@key_file).returns(rsa_key.export) + assert_equal rsa_key.to_der, Net::SSH::KeyFactory.load_private_key(@key_file).to_der end def test_load_unencrypted_private_DSA_key_should_return_key - File.expects(:read).with("/key-file").returns(dsa_key.export) - assert_equal dsa_key.to_der, Net::SSH::KeyFactory.load_private_key("/key-file").to_der + File.expects(:read).with(@key_file).returns(dsa_key.export) + assert_equal dsa_key.to_der, Net::SSH::KeyFactory.load_private_key(@key_file).to_der end def test_load_encrypted_private_RSA_key_should_prompt_for_password_and_return_key - File.expects(:read).with("/key-file").returns(encrypted(rsa_key, "password")) - Net::SSH::KeyFactory.expects(:prompt).with("Enter passphrase for /key-file:", false).returns("password") - assert_equal rsa_key.to_der, Net::SSH::KeyFactory.load_private_key("/key-file").to_der + File.expects(:read).with(@key_file).returns(encrypted(rsa_key, "password")) + Net::SSH::KeyFactory.expects(:prompt).with("Enter passphrase for #{@key_file}:", false).returns("password") + assert_equal rsa_key.to_der, Net::SSH::KeyFactory.load_private_key(@key_file).to_der end def test_load_encrypted_private_RSA_key_with_password_should_not_prompt_and_return_key - File.expects(:read).with("/key-file").returns(encrypted(rsa_key, "password")) - assert_equal rsa_key.to_der, Net::SSH::KeyFactory.load_private_key("/key-file", "password").to_der + File.expects(:read).with(@key_file).returns(encrypted(rsa_key, "password")) + assert_equal rsa_key.to_der, Net::SSH::KeyFactory.load_private_key(@key_file, "password").to_der end def test_load_encrypted_private_DSA_key_should_prompt_for_password_and_return_key - File.expects(:read).with("/key-file").returns(encrypted(dsa_key, "password")) - Net::SSH::KeyFactory.expects(:prompt).with("Enter passphrase for /key-file:", false).returns("password") - assert_equal dsa_key.to_der, Net::SSH::KeyFactory.load_private_key("/key-file").to_der + File.expects(:read).with(@key_file).returns(encrypted(dsa_key, "password")) + Net::SSH::KeyFactory.expects(:prompt).with("Enter passphrase for #{@key_file}:", false).returns("password") + assert_equal dsa_key.to_der, Net::SSH::KeyFactory.load_private_key(@key_file).to_der end def test_load_encrypted_private_DSA_key_with_password_should_not_prompt_and_return_key - File.expects(:read).with("/key-file").returns(encrypted(dsa_key, "password")) - assert_equal dsa_key.to_der, Net::SSH::KeyFactory.load_private_key("/key-file", "password").to_der + File.expects(:read).with(@key_file).returns(encrypted(dsa_key, "password")) + assert_equal dsa_key.to_der, Net::SSH::KeyFactory.load_private_key(@key_file, "password").to_der end def test_load_encrypted_private_key_should_give_three_tries_for_the_password_and_then_raise_exception - File.expects(:read).with("/key-file").returns(encrypted(rsa_key, "password")) - Net::SSH::KeyFactory.expects(:prompt).times(3).with("Enter passphrase for /key-file:", false).returns("passwod","passphrase","passwd") - assert_raises(OpenSSL::PKey::RSAError) { Net::SSH::KeyFactory.load_private_key("/key-file") } + File.expects(:read).with(@key_file).returns(encrypted(rsa_key, "password")) + Net::SSH::KeyFactory.expects(:prompt).times(3).with("Enter passphrase for #{@key_file}:", false).returns("passwod","passphrase","passwd") + assert_raises(OpenSSL::PKey::RSAError) { Net::SSH::KeyFactory.load_private_key(@key_file) } end def test_load_encrypted_private_key_should_raise_exception_without_asking_passphrase - File.expects(:read).with("/key-file").returns(encrypted(rsa_key, "password")) + File.expects(:read).with(@key_file).returns(encrypted(rsa_key, "password")) Net::SSH::KeyFactory.expects(:prompt).never - assert_raises(OpenSSL::PKey::RSAError) { Net::SSH::KeyFactory.load_private_key("/key-file", nil, false) } + assert_raises(OpenSSL::PKey::RSAError) { Net::SSH::KeyFactory.load_private_key(@key_file, nil, false) } end def test_load_public_rsa_key_should_return_key - File.expects(:read).with("/key-file").returns(public(rsa_key)) - assert_equal rsa_key.to_blob, Net::SSH::KeyFactory.load_public_key("/key-file").to_blob + File.expects(:read).with(@key_file).returns(public(rsa_key)) + assert_equal rsa_key.to_blob, Net::SSH::KeyFactory.load_public_key(@key_file).to_blob end private |
