diff options
author | Scott Maxwell <scott@codecobblers.com> | 2014-01-16 19:50:53 -0800 |
---|---|---|
committer | Scott Maxwell <scott@codecobblers.com> | 2014-01-16 19:50:53 -0800 |
commit | b9e62182e55e3f0a6e8207f7fcc2244a61132968 (patch) | |
tree | 714c502731de8d17370942d2c1b2bb0bb04cf6ab /tests | |
parent | aa8ea3c4d42d508a722fdf4ea635ff5e609cca1b (diff) | |
parent | a08ac06083a40eb1455e5fa14cd644f7a2350f16 (diff) |
Merge remote-tracking branch 'master/master' into py3-support-without-py25
Conflicts:
paramiko/__init__.py
setup.py
tests/test_client.py
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_client.py | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/tests/test_client.py b/tests/test_client.py index c508b83a..b4724843 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -20,12 +20,13 @@ Some unit tests for SSHClient. """ -import os import socket import threading import time import unittest import weakref +import warnings +import os from binascii import hexlify from tests.util import test_path import paramiko @@ -186,7 +187,33 @@ class SSHClientTest (unittest.TestCase): self.assertEqual(1, len(self.tc.get_host_keys())) self.assertEqual(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. |