summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMusy Bite <musybite@gmail.com>2011-08-23 16:46:36 +0400
committerMusy Bite <musybite@gmail.com>2011-08-23 17:12:09 +0400
commit90ceb089749d0c73fabdbbeedce6b208a71d47d4 (patch)
tree8ecba87b42aa637b2e186c8aa5aa05cf51ed44a4
parent01f2b4ffcd31dd05ff456a8de48bda56ceefd1e9 (diff)
downloadnet-ssh-90ceb089749d0c73fabdbbeedce6b208a71d47d4.tar.gz
LH30: Failing test clarified a bit
-rw-r--r--lib/net/ssh/authentication/key_manager.rb4
-rw-r--r--test/authentication/test_key_manager.rb18
2 files changed, 13 insertions, 9 deletions
diff --git a/lib/net/ssh/authentication/key_manager.rb b/lib/net/ssh/authentication/key_manager.rb
index 7a0692f..ffa7540 100644
--- a/lib/net/ssh/authentication/key_manager.rb
+++ b/lib/net/ssh/authentication/key_manager.rb
@@ -134,7 +134,7 @@ module Net
if info[:key].nil? && info[:from] == :file
begin
- info[:key] = KeyFactory.load_private_key(info[:file], options[:passphrase])
+ info[:key] = KeyFactory.load_private_key(info[:file], options[:passphrase], true)
rescue Exception, OpenSSL::OpenSSLError => e
raise KeyManagerError, "the given identity is known, but the private key could not be loaded: #{e.class} (#{e.message})"
end
@@ -193,7 +193,7 @@ module Net
end
elsif File.readable?(file)
begin
- private_key = KeyFactory.load_private_key(file, options[:passphrase])
+ private_key = KeyFactory.load_private_key(file, options[:passphrase], true)
key = private_key.send(:public_key)
{ :public_key => key, :from => :file, :file => file, :key => private_key }
rescue Exception => e
diff --git a/test/authentication/test_key_manager.rb b/test/authentication/test_key_manager.rb
index e42a21c..0c6f585 100644
--- a/test/authentication/test_key_manager.rb
+++ b/test/authentication/test_key_manager.rb
@@ -77,12 +77,12 @@ module Authentication
manager.stubs(:agent).returns(agent)
stub_file_public_key "/first", rsa
- stub_file_private_key "/second", dsa, :known_passphrase => false
+ stub_file_private_key "/second", dsa, :passphrase => :should_not_be_asked
identities = []
manager.each_identity do |identity|
identities << identity
- break if identity[:from] == :agent
+ break if manager.known_identities[identity][:from] == :agent
end
assert_equal 1, identities.length
@@ -121,11 +121,15 @@ module Authentication
File.stubs(:readable?).with(name).returns(true)
File.stubs(:readable?).with(name + ".pub").returns(false)
- passphrase_request_expected = Net::SSH::KeyFactory.expects(:load_private_key).with(name, nil).returns(key)
- if options.fetch(:known_passphrase, true)
- passphrase_request_expected.at_least_once
- else
- passphrase_request_expected.never
+ case options.fetch(:passphrase, :indifferently)
+ when :should_be_asked
+ Net::SSH::KeyFactory.expects(:load_private_key).with(name, nil, false).raises(OpenSSL::PKey::RSAError).at_least_once
+ Net::SSH::KeyFactory.expects(:load_private_key).with(name, nil, true).returns(key).at_least_once
+ when :should_not_be_asked
+ Net::SSH::KeyFactory.expects(:load_private_key).with(name, nil, false).raises(OpenSSL::PKey::RSAError).at_least_once
+ Net::SSH::KeyFactory.expects(:load_private_key).with(name, nil, true).never
+ else # :indifferently
+ Net::SSH::KeyFactory.expects(:load_private_key).with(name, nil, any_of(true, false)).returns(key).at_least_once
end
key.stubs(:public_key).returns(key)