summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMartin Blumenstingl <martin.blumenstingl@googlemail.com>2014-01-07 22:36:28 +0100
committerJeff Forcier <jeff@bitprophet.org>2014-01-08 12:27:24 -0800
commitbfc3953be000e426551c90d65a0633c62c9fde89 (patch)
tree0f9d4a4f9b1df71a581c2c25ad555a600128baa8
parent302e3bde38fdac8f016535d0044667478b01b7f2 (diff)
Add a testcase for client.save_host_keys.
-rw-r--r--tests/test_client.py26
1 files changed, 25 insertions, 1 deletions
diff --git a/tests/test_client.py b/tests/test_client.py
index e5352278..7aaa1bfc 100644
--- a/tests/test_client.py
+++ b/tests/test_client.py
@@ -25,6 +25,8 @@ import threading
import time
import unittest
import weakref
+import warnings
+import os
from binascii import hexlify
import paramiko
@@ -184,7 +186,29 @@ class SSHClientTest (unittest.TestCase):
self.assertEquals(1, len(self.tc.get_host_keys()))
self.assertEquals(public_host_key, self.tc.get_host_keys()['[%s]:%d' % (self.addr, self.port)]['ssh-rsa'])
- def test_5_cleanup(self):
+ def test_5_save_host_keys(self):
+ """
+ verify that SSHClient correctly saves a known_hosts file.
+ """
+ warnings.filterwarnings('ignore', 'tempnam.*')
+
+ host_key = paramiko.RSAKey.from_private_key_file('tests/test_rsa.key')
+ public_host_key = paramiko.RSAKey(data=str(host_key))
+ localname = os.tempnam()
+
+ self.tc = paramiko.SSHClient()
+ self.assertEquals(0, len(self.tc.get_host_keys()))
+
+ self.tc.get_host_keys().add('[%s]:%d' % (self.addr, self.port), 'ssh-rsa', public_host_key)
+ self.assertEquals(1, len(self.tc.get_host_keys()))
+ self.assertEquals(public_host_key, self.tc.get_host_keys()['[%s]:%d' % (self.addr, self.port)]['ssh-rsa'])
+
+ self.tc.save_host_keys(localname)
+ self.assertEquals(len('[%s]:%d' % (self.addr, self.port)) + 210, os.path.getsize(localname))
+
+ os.unlink(localname)
+
+ def test_6_cleanup(self):
"""
verify that when an SSHClient is collected, its transport (and the
transport's packetizer) is closed.