summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJamis Buck <jamis@37signals.com>2008-12-29 21:31:43 -0700
committerJamis Buck <jamis@37signals.com>2008-12-29 21:31:43 -0700
commit6f3d9d875fcdfc38ad32c6452341a2d47cad3f92 (patch)
tree4a7b4bff4ae3e6737916bf3c81917ab073742d53 /test
parente1d1cfc9ed78aa4a8ab0bf526ef55464a5f4768e (diff)
downloadnet-ssh-6f3d9d875fcdfc38ad32c6452341a2d47cad3f92.tar.gz
Load keys just-in-time instead of ahead-of-time
This avoids unnecessary prompts from encrypted keys as a result of the change in 2.0.7 that caused private keys to be loaded instead of public keys.
Diffstat (limited to 'test')
-rw-r--r--test/authentication/methods/test_hostbased.rb8
-rw-r--r--test/authentication/methods/test_publickey.rb8
-rw-r--r--test/authentication/test_key_manager.rb14
3 files changed, 21 insertions, 9 deletions
diff --git a/test/authentication/methods/test_hostbased.rb b/test/authentication/methods/test_hostbased.rb
index 0a994fb..281c86d 100644
--- a/test/authentication/methods/test_hostbased.rb
+++ b/test/authentication/methods/test_hostbased.rb
@@ -79,7 +79,11 @@ module Authentication; module Methods
end
def key_manager(options={})
- @key_manager ||= stub("key_manager", :identities => options[:keys] || keys)
+ @key_manager ||= begin
+ manager = stub("key_manager")
+ manager.stubs(:each_identity).multiple_yields(*(options[:keys] || keys))
+ manager
+ end
end
def subject(options={})
@@ -107,4 +111,4 @@ module Authentication; module Methods
end
-end; end \ No newline at end of file
+end; end
diff --git a/test/authentication/methods/test_publickey.rb b/test/authentication/methods/test_publickey.rb
index 33d1394..f4f544f 100644
--- a/test/authentication/methods/test_publickey.rb
+++ b/test/authentication/methods/test_publickey.rb
@@ -110,7 +110,11 @@ module Authentication; module Methods
end
def key_manager(options={})
- @key_manager ||= stub("key_manager", :identities => options[:keys] || keys)
+ @key_manager ||= begin
+ manager = stub("key_manager")
+ manager.stubs(:each_identity).multiple_yields(*(options[:keys] || keys))
+ manager
+ end
end
def subject(options={})
@@ -120,4 +124,4 @@ module Authentication; module Methods
end
-end; end \ No newline at end of file
+end; end
diff --git a/test/authentication/test_key_manager.rb b/test/authentication/test_key_manager.rb
index 00f5f4a..ca6b683 100644
--- a/test/authentication/test_key_manager.rb
+++ b/test/authentication/test_key_manager.rb
@@ -28,13 +28,15 @@ module Authentication
assert !manager.use_agent?
end
- def test_identities_should_load_from_key_files
+ def test_each_identity_should_load_from_key_files
manager.stubs(:agent).returns(nil)
stub_file_key "/first", rsa
stub_file_key "/second", dsa
- identities = manager.identities
+ identities = []
+ manager.each_identity { |identity| identities << identity }
+
assert_equal 2, identities.length
assert_equal rsa.to_blob, identities.first.to_blob
assert_equal dsa.to_blob, identities.last.to_blob
@@ -45,7 +47,9 @@ module Authentication
def test_identities_should_load_from_agent
manager.stubs(:agent).returns(agent)
- identities = manager.identities
+
+ identities = []
+ manager.each_identity { |identity| identities << identity }
assert_equal 2, identities.length
assert_equal rsa.to_blob, identities.first.to_blob
@@ -57,7 +61,7 @@ module Authentication
def test_sign_with_agent_originated_key_should_request_signature_from_agent
manager.stubs(:agent).returns(agent)
- manager.identities
+ manager.each_identity { |identity| } # preload the known_identities
agent.expects(:sign).with(rsa, "hello, world").returns("abcxyz123")
assert_equal "abcxyz123", manager.sign(rsa, "hello, world")
end
@@ -66,7 +70,7 @@ module Authentication
manager.stubs(:agent).returns(nil)
stub_file_key "/first", rsa(512), true
rsa.expects(:ssh_do_sign).with("hello, world").returns("abcxyz123")
- manager.identities
+ manager.each_identity { |identity| } # preload the known_identities
assert_equal "\0\0\0\assh-rsa\0\0\0\011abcxyz123", manager.sign(rsa, "hello, world")
end