summaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorJeff Forcier <jeff@bitprophet.org>2014-01-08 13:43:03 -0800
committerJeff Forcier <jeff@bitprophet.org>2014-01-08 13:43:03 -0800
commitb352357efb43d31fd933102a2ca15e6490ddbdb0 (patch)
treedf37aadf6b0fa5ca610a6c7872b79bae892fd89a /tests
parentec95e8d943051c81dc14173e697e6a0b66c99077 (diff)
parentb57e825f77544a88eea77cf65bbe7d2d0426d4c9 (diff)
Merge branch '1.10' into 1.11
Conflicts: NEWS
Diffstat (limited to 'tests')
-rw-r--r--tests/test_client.py31
1 files changed, 30 insertions, 1 deletions
diff --git a/tests/test_client.py b/tests/test_client.py
index e5352278..fae1d329 100644
--- a/tests/test_client.py
+++ b/tests/test_client.py
@@ -20,11 +20,14 @@
Some unit tests for SSHClient.
"""
+from __future__ import with_statement # Python 2.5 support
import socket
import threading
import time
import unittest
import weakref
+import warnings
+import os
from binascii import hexlify
import paramiko
@@ -184,7 +187,33 @@ 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()
+
+ client = paramiko.SSHClient()
+ self.assertEquals(0, len(client.get_host_keys()))
+
+ host_id = '[%s]:%d' % (self.addr, self.port)
+
+ client.get_host_keys().add(host_id, 'ssh-rsa', public_host_key)
+ self.assertEquals(1, len(client.get_host_keys()))
+ self.assertEquals(public_host_key, client.get_host_keys()[host_id]['ssh-rsa'])
+
+ client.save_host_keys(localname)
+
+ with open(localname) as fd:
+ assert host_id in fd.read()
+
+ os.unlink(localname)
+
+ def test_6_cleanup(self):
"""
verify that when an SSHClient is collected, its transport (and the
transport's packetizer) is closed.