summaryrefslogtreecommitdiff
path: root/tests/test_client.py
diff options
context:
space:
mode:
authorJeremy T. Bouse <jbouse@debian.org>2014-02-14 21:29:58 -0500
committerJeremy T. Bouse <jbouse@debian.org>2014-02-14 21:29:58 -0500
commit3bb46c9cb414ca82afab715d2d0cc00ed71cfb6d (patch)
tree968464cb0214980291af70f9d1756d907b35aa6c /tests/test_client.py
parent1a716ed46d1d556d4ba6798608ab498320acd886 (diff)
downloadpython-paramiko-3bb46c9cb414ca82afab715d2d0cc00ed71cfb6d.tar
python-paramiko-3bb46c9cb414ca82afab715d2d0cc00ed71cfb6d.tar.gz
Imported Upstream version 1.12.2upstream/1.12.2
Diffstat (limited to 'tests/test_client.py')
-rw-r--r--tests/test_client.py33
1 files changed, 31 insertions, 2 deletions
diff --git a/tests/test_client.py b/tests/test_client.py
index 08ef1f9..fae1d32 100644
--- a/tests/test_client.py
+++ b/tests/test_client.py
@@ -7,7 +7,7 @@
# Software Foundation; either version 2.1 of the License, or (at your option)
# any later version.
#
-# Paramiko is distrubuted in the hope that it will be useful, but WITHOUT ANY
+# Paramiko is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
@@ -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.