diff options
author | Robey Pointer <robey@lag.net> | 2005-05-01 08:04:59 +0000 |
---|---|---|
committer | Robey Pointer <robey@lag.net> | 2005-05-01 08:04:59 +0000 |
commit | 36055c5ac2bd786a21aa05d248935a77a8fbccec (patch) | |
tree | d14484cff9237385fed9af7e2091524691365187 /tests | |
parent | 2f2d7bdee88c9f9b14dc2495fb77d7abd1587d64 (diff) |
[project @ Arch-1:robey@lag.net--2005-master-shake%paramiko--dev--1--patch-5]
split out Packetizer, fix banner detection bug, new unit test
split out a chunk of BaseTransport into a Packetizer class, which handles
the in/out packet data, ciphers, etc. it didn't make the code any smaller
(transport.py is still close to 1500 lines, which is awful) but it did split
out a coherent chunk of functionality into a discrete unit.
in the process, fixed a bug that alain spineux pointed out: the banner
check was too forgiving and would block forever waiting for an SSH banner.
now it waits 5 seconds for the first line, and 2 seconds for each subsequent
line, before giving up.
added a unit test to test keepalive, since i wasn't sure that was still
working after pulling out Packetizer.
Diffstat (limited to 'tests')
-rwxr-xr-x | tests/test_sftp.py | 34 | ||||
-rw-r--r-- | tests/test_transport.py | 46 |
2 files changed, 53 insertions, 27 deletions
diff --git a/tests/test_sftp.py b/tests/test_sftp.py index 5d4d921c..5031f02f 100755 --- a/tests/test_sftp.py +++ b/tests/test_sftp.py @@ -1,5 +1,3 @@ -#!/usr/bin/python - # Copyright (C) 2003-2005 Robey Pointer <robey@lag.net> # # This file is part of paramiko. @@ -145,7 +143,7 @@ class SFTPTest (unittest.TestCase): finally: sftp.remove(FOLDER + '/test') - def test_1a_close(self): + def test_2_close(self): """ verify that closing the sftp session doesn't do anything bad, and that a new one can be opened. @@ -159,7 +157,7 @@ class SFTPTest (unittest.TestCase): pass sftp = paramiko.SFTP.from_transport(tc) - def test_2_write(self): + def test_3_write(self): """ verify that a file can be created and written, and the size is correct. """ @@ -171,7 +169,7 @@ class SFTPTest (unittest.TestCase): finally: sftp.remove(FOLDER + '/duck.txt') - def test_3_append(self): + def test_4_append(self): """ verify that a file can be opened for append, and tell() still works. """ @@ -191,7 +189,7 @@ class SFTPTest (unittest.TestCase): finally: sftp.remove(FOLDER + '/append.txt') - def test_4_rename(self): + def test_5_rename(self): """ verify that renaming a file works. """ @@ -219,7 +217,7 @@ class SFTPTest (unittest.TestCase): except: pass - def test_5_folder(self): + def test_6_folder(self): """ create a temporary folder, verify that we can create a file in it, then remove the folder and verify that we can't create a file in it anymore. @@ -236,7 +234,7 @@ class SFTPTest (unittest.TestCase): except IOError: pass - def test_6_listdir(self): + def test_7_listdir(self): """ verify that a folder can be created, a bunch of files can be placed in it, and those files show up in sftp.listdir. @@ -262,7 +260,7 @@ class SFTPTest (unittest.TestCase): sftp.remove(FOLDER + '/fish.txt') sftp.remove(FOLDER + '/tertiary.py') - def test_7_setstat(self): + def test_8_setstat(self): """ verify that the setstat functions (chown, chmod, utime) work. """ @@ -285,7 +283,7 @@ class SFTPTest (unittest.TestCase): finally: sftp.remove(FOLDER + '/special') - def test_8_readline_seek(self): + def test_9_readline_seek(self): """ create a text file and write a bunch of text into it. then count the lines in the file, and seek around to retreive particular lines. this should @@ -315,7 +313,7 @@ class SFTPTest (unittest.TestCase): finally: sftp.remove(FOLDER + '/duck.txt') - def test_9_write_seek(self): + def test_A_write_seek(self): """ create a text file, seek back and change part of it, and verify that the changes worked. @@ -335,7 +333,7 @@ class SFTPTest (unittest.TestCase): finally: sftp.remove(FOLDER + '/testing.txt') - def test_A_symlink(self): + def test_B_symlink(self): """ create a symlink and then check that lstat doesn't follow it. """ @@ -378,7 +376,7 @@ class SFTPTest (unittest.TestCase): except: pass - def test_B_flush_seek(self): + def test_C_flush_seek(self): """ verify that buffered writes are automatically flushed on seek. """ @@ -400,7 +398,7 @@ class SFTPTest (unittest.TestCase): except: pass - def test_C_lots_of_files(self): + def test_D_lots_of_files(self): """ create a bunch of files over the same session. """ @@ -431,7 +429,7 @@ class SFTPTest (unittest.TestCase): except: pass - def test_D_big_file(self): + def test_E_big_file(self): """ write a 1MB file, with no linefeeds, using line buffering. FIXME: this is slow! what causes the slowness? @@ -453,7 +451,7 @@ class SFTPTest (unittest.TestCase): finally: sftp.remove('%s/hongry.txt' % FOLDER) - def test_E_big_file_big_buffer(self): + def test_F_big_file_big_buffer(self): """ write a 1MB file, with no linefeeds, and a big buffer. """ @@ -470,7 +468,7 @@ class SFTPTest (unittest.TestCase): finally: sftp.remove('%s/hongry.txt' % FOLDER) - def test_F_realpath(self): + def test_G_realpath(self): """ test that realpath is returning something non-empty and not an error. @@ -481,7 +479,7 @@ class SFTPTest (unittest.TestCase): self.assert_(len(f) > 0) self.assertEquals(os.path.join(pwd, FOLDER), f) - def test_G_mkdir(self): + def test_H_mkdir(self): """ verify that mkdir/rmdir work. """ diff --git a/tests/test_transport.py b/tests/test_transport.py index bd11487f..5afc2e12 100644 --- a/tests/test_transport.py +++ b/tests/test_transport.py @@ -22,7 +22,7 @@ Some unit tests for the ssh2 protocol in Transport. """ -import sys, unittest, threading +import sys, time, threading, unittest from paramiko import Transport, SecurityOptions, ServerInterface, RSAKey, DSSKey, \ SSHException, BadAuthenticationType from paramiko import AUTH_FAILED, AUTH_PARTIALLY_SUCCESSFUL, AUTH_SUCCESSFUL @@ -77,6 +77,10 @@ class NullServer (ServerInterface): def check_channel_shell_request(self, channel): return True + + def check_global_request(self, kind, msg): + self._global_request = kind + return False class TransportTest (unittest.TestCase): @@ -160,14 +164,38 @@ class TransportTest (unittest.TestCase): self.assert_(self.ts.is_active()) self.assertEquals('aes256-cbc', self.tc.local_cipher) self.assertEquals('aes256-cbc', self.tc.remote_cipher) - self.assertEquals(12, self.tc.local_mac_len) - self.assertEquals(12, self.tc.remote_mac_len) + self.assertEquals(12, self.tc.packetizer.get_mac_size_out()) + self.assertEquals(12, self.tc.packetizer.get_mac_size_in()) self.tc.send_ignore(1024) self.assert_(self.tc.renegotiate_keys()) self.ts.send_ignore(1024) - def test_4_bad_auth_type(self): + def test_4_keepalive(self): + """ + verify that the keepalive will be sent. + """ + self.tc.set_hexdump(True) + + host_key = RSAKey.from_private_key_file('tests/test_rsa.key') + public_host_key = RSAKey(data=str(host_key)) + self.ts.add_server_key(host_key) + event = threading.Event() + server = NullServer() + self.assert_(not event.isSet()) + self.ts.start_server(event, server) + self.tc.connect(hostkey=public_host_key, + username='slowdive', password='pygmalion') + event.wait(1.0) + self.assert_(event.isSet()) + self.assert_(self.ts.is_active()) + + self.assertEquals(None, getattr(server, '_global_request', None)) + self.tc.set_keepalive(1) + time.sleep(2) + self.assertEquals('keepalive@lag.net', server._global_request) + + def test_5_bad_auth_type(self): """ verify that we get the right exception when an unsupported auth type is requested. @@ -188,7 +216,7 @@ class TransportTest (unittest.TestCase): self.assertEquals(BadAuthenticationType, etype) self.assertEquals(['publickey'], evalue.allowed_types) - def test_5_bad_password(self): + def test_6_bad_password(self): """ verify that a bad password gets the right exception, and that a retry with the right password works. @@ -213,7 +241,7 @@ class TransportTest (unittest.TestCase): self.assert_(event.isSet()) self.assert_(self.ts.is_active()) - def test_6_multipart_auth(self): + def test_7_multipart_auth(self): """ verify that multipart auth works. """ @@ -235,7 +263,7 @@ class TransportTest (unittest.TestCase): self.assert_(event.isSet()) self.assert_(self.ts.is_active()) - def test_7_exec_command(self): + def test_8_exec_command(self): """ verify that exec_command() does something reasonable. """ @@ -285,7 +313,7 @@ class TransportTest (unittest.TestCase): self.assertEquals('This is on stderr.\n', f.readline()) self.assertEquals('', f.readline()) - def test_8_invoke_shell(self): + def test_9_invoke_shell(self): """ verify that invoke_shell() does something reasonable. """ @@ -312,7 +340,7 @@ class TransportTest (unittest.TestCase): chan.close() self.assertEquals('', f.readline()) - def test_9_exit_status(self): + def test_A_exit_status(self): """ verify that get_exit_status() works. """ |