summaryrefslogtreecommitdiff
path: root/test/test_key_factory.rb
diff options
context:
space:
mode:
authorFrancis Sullivan <francis@garlic.local>2008-04-13 21:35:33 -0500
committerFrancis Sullivan <francis@garlic.local>2008-04-13 21:35:33 -0500
commitbbfb24fb4e654a0068a55399487aaa9488907337 (patch)
treececa3d0cf5b27c2f95c600529987de29a9b34309 /test/test_key_factory.rb
parent183c94101115a2e9e30a2ca263731b34e05d05ce (diff)
downloadnet-ssh-bbfb24fb4e654a0068a55399487aaa9488907337.tar.gz
If a password is given as an option, and a publickey needs a password, first try that password before prompting.
Diffstat (limited to 'test/test_key_factory.rb')
-rw-r--r--test/test_key_factory.rb10
1 files changed, 10 insertions, 0 deletions
diff --git a/test/test_key_factory.rb b/test/test_key_factory.rb
index 12e2beb..a5603cd 100644
--- a/test/test_key_factory.rb
+++ b/test/test_key_factory.rb
@@ -18,12 +18,22 @@ class TestKeyFactory < Test::Unit::TestCase
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
+ 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 password 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
+ 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 password for /key-file:", false).returns("passwod","passphrase","passwd")