2006-11-10 19:53:30 -05:00
|
|
|
#!/usr/bin/env python
|
2004-03-08 12:54:19 -05:00
|
|
|
|
2009-07-19 22:45:02 -04:00
|
|
|
# Copyright (C) 2003-2007 Robey Pointer <robeypointer@gmail.com>
|
2004-03-08 12:54:19 -05:00
|
|
|
#
|
|
|
|
# This file is part of paramiko.
|
|
|
|
#
|
|
|
|
# Paramiko is free software; you can redistribute it and/or modify it under the
|
|
|
|
# terms of the GNU Lesser General Public License as published by the Free
|
|
|
|
# Software Foundation; either version 2.1 of the License, or (at your option)
|
|
|
|
# any later version.
|
|
|
|
#
|
2013-09-28 00:29:18 -04:00
|
|
|
# Paramiko is distributed in the hope that it will be useful, but WITHOUT ANY
|
2004-03-08 12:54:19 -05:00
|
|
|
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
|
|
|
# A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
|
|
|
# details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Lesser General Public License
|
2004-06-10 14:12:00 -04:00
|
|
|
# along with Paramiko; if not, write to the Free Software Foundation, Inc.,
|
2004-03-08 12:54:19 -05:00
|
|
|
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
|
|
|
|
|
|
|
|
"""
|
|
|
|
do the unit tests!
|
|
|
|
"""
|
|
|
|
|
2006-07-31 03:01:37 -04:00
|
|
|
import os
|
|
|
|
import re
|
|
|
|
import sys
|
|
|
|
import unittest
|
2004-09-25 18:03:48 -04:00
|
|
|
from optparse import OptionParser
|
|
|
|
import paramiko
|
2012-09-10 14:34:52 -04:00
|
|
|
import threading
|
2004-09-25 18:03:48 -04:00
|
|
|
|
2007-01-22 16:17:18 -05:00
|
|
|
sys.path.append('tests')
|
2004-03-08 12:54:19 -05:00
|
|
|
|
2013-10-30 19:19:30 -04:00
|
|
|
from tests.test_message import MessageTest
|
|
|
|
from tests.test_file import BufferedFileTest
|
|
|
|
from tests.test_buffered_pipe import BufferedPipeTest
|
|
|
|
from tests.test_util import UtilTest
|
|
|
|
from tests.test_hostkeys import HostKeysTest
|
|
|
|
from tests.test_pkey import KeyTest
|
|
|
|
from tests.test_kex import KexTest
|
|
|
|
from tests.test_packetizer import PacketizerTest
|
|
|
|
from tests.test_auth import AuthTest
|
|
|
|
from tests.test_transport import TransportTest
|
|
|
|
from tests.test_sftp import SFTPTest
|
|
|
|
from tests.test_sftp_big import BigSFTPTest
|
|
|
|
from tests.test_client import SSHClientTest
|
2004-03-08 12:54:19 -05:00
|
|
|
|
2004-09-25 18:03:48 -04:00
|
|
|
default_host = 'localhost'
|
|
|
|
default_user = os.environ.get('USER', 'nobody')
|
|
|
|
default_keyfile = os.path.join(os.environ.get('HOME', '/'), '.ssh/id_rsa')
|
|
|
|
default_passwd = None
|
|
|
|
|
|
|
|
|
2006-07-31 03:01:37 -04:00
|
|
|
def iter_suite_tests(suite):
|
|
|
|
"""Return all tests in a suite, recursing through nested suites"""
|
|
|
|
for item in suite._tests:
|
|
|
|
if isinstance(item, unittest.TestCase):
|
|
|
|
yield item
|
|
|
|
elif isinstance(item, unittest.TestSuite):
|
|
|
|
for r in iter_suite_tests(item):
|
|
|
|
yield r
|
|
|
|
else:
|
|
|
|
raise Exception('unknown object %r inside test suite %r'
|
|
|
|
% (item, suite))
|
2004-09-25 18:03:48 -04:00
|
|
|
|
[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.
2005-05-01 04:04:59 -04:00
|
|
|
|
2006-07-31 03:01:37 -04:00
|
|
|
def filter_suite_by_re(suite, pattern):
|
|
|
|
result = unittest.TestSuite()
|
|
|
|
filter_re = re.compile(pattern)
|
|
|
|
for test in iter_suite_tests(suite):
|
|
|
|
if filter_re.search(test.id()):
|
|
|
|
result.addTest(test)
|
|
|
|
return result
|
2004-09-25 18:03:48 -04:00
|
|
|
|
2006-07-31 03:01:37 -04:00
|
|
|
|
|
|
|
def main():
|
|
|
|
parser = OptionParser('usage: %prog [options]')
|
|
|
|
parser.add_option('--verbose', action='store_true', dest='verbose', default=False,
|
|
|
|
help='verbose display (one line per test)')
|
|
|
|
parser.add_option('--no-pkey', action='store_false', dest='use_pkey', default=True,
|
|
|
|
help='skip RSA/DSS private key tests (which can take a while)')
|
|
|
|
parser.add_option('--no-transport', action='store_false', dest='use_transport', default=True,
|
|
|
|
help='skip transport tests (which can take a while)')
|
|
|
|
parser.add_option('--no-sftp', action='store_false', dest='use_sftp', default=True,
|
|
|
|
help='skip SFTP client/server tests, which can be slow')
|
|
|
|
parser.add_option('--no-big-file', action='store_false', dest='use_big_file', default=True,
|
|
|
|
help='skip big file SFTP tests, which are slow as molasses')
|
|
|
|
parser.add_option('-R', action='store_false', dest='use_loopback_sftp', default=True,
|
|
|
|
help='perform SFTP tests against a remote server (by default, SFTP tests ' +
|
|
|
|
'are done through a loopback socket)')
|
|
|
|
parser.add_option('-H', '--sftp-host', dest='hostname', type='string', default=default_host,
|
|
|
|
metavar='<host>',
|
|
|
|
help='[with -R] host for remote sftp tests (default: %s)' % default_host)
|
|
|
|
parser.add_option('-U', '--sftp-user', dest='username', type='string', default=default_user,
|
|
|
|
metavar='<username>',
|
|
|
|
help='[with -R] username for remote sftp tests (default: %s)' % default_user)
|
|
|
|
parser.add_option('-K', '--sftp-key', dest='keyfile', type='string', default=default_keyfile,
|
|
|
|
metavar='<keyfile>',
|
|
|
|
help='[with -R] location of private key for remote sftp tests (default: %s)' %
|
|
|
|
default_keyfile)
|
|
|
|
parser.add_option('-P', '--sftp-passwd', dest='password', type='string', default=default_passwd,
|
|
|
|
metavar='<password>',
|
|
|
|
help='[with -R] (optional) password to unlock the private key for remote sftp tests')
|
|
|
|
|
|
|
|
options, args = parser.parse_args()
|
|
|
|
|
|
|
|
# setup logging
|
|
|
|
paramiko.util.log_to_file('test.log')
|
|
|
|
|
|
|
|
if options.use_sftp:
|
|
|
|
if options.use_loopback_sftp:
|
|
|
|
SFTPTest.init_loopback()
|
|
|
|
else:
|
|
|
|
SFTPTest.init(options.hostname, options.username, options.keyfile, options.password)
|
|
|
|
if not options.use_big_file:
|
|
|
|
SFTPTest.set_big_file_test(False)
|
|
|
|
|
|
|
|
suite = unittest.TestSuite()
|
|
|
|
suite.addTest(unittest.makeSuite(MessageTest))
|
|
|
|
suite.addTest(unittest.makeSuite(BufferedFileTest))
|
|
|
|
suite.addTest(unittest.makeSuite(BufferedPipeTest))
|
|
|
|
suite.addTest(unittest.makeSuite(UtilTest))
|
|
|
|
suite.addTest(unittest.makeSuite(HostKeysTest))
|
|
|
|
if options.use_pkey:
|
|
|
|
suite.addTest(unittest.makeSuite(KeyTest))
|
|
|
|
suite.addTest(unittest.makeSuite(KexTest))
|
|
|
|
suite.addTest(unittest.makeSuite(PacketizerTest))
|
|
|
|
if options.use_transport:
|
2008-01-23 20:38:49 -05:00
|
|
|
suite.addTest(unittest.makeSuite(AuthTest))
|
2006-07-31 03:01:37 -04:00
|
|
|
suite.addTest(unittest.makeSuite(TransportTest))
|
|
|
|
suite.addTest(unittest.makeSuite(SSHClientTest))
|
|
|
|
if options.use_sftp:
|
|
|
|
suite.addTest(unittest.makeSuite(SFTPTest))
|
|
|
|
if options.use_big_file:
|
|
|
|
suite.addTest(unittest.makeSuite(BigSFTPTest))
|
|
|
|
verbosity = 1
|
|
|
|
if options.verbose:
|
|
|
|
verbosity = 2
|
|
|
|
|
|
|
|
runner = unittest.TextTestRunner(verbosity=verbosity)
|
|
|
|
if len(args) > 0:
|
|
|
|
filter = '|'.join(args)
|
|
|
|
suite = filter_suite_by_re(suite, filter)
|
2012-09-10 14:34:52 -04:00
|
|
|
result = runner.run(suite)
|
|
|
|
# Clean up stale threads from poorly cleaned-up tests.
|
|
|
|
# TODO: make that not a problem, jeez
|
|
|
|
for thread in threading.enumerate():
|
|
|
|
if thread is not threading.currentThread():
|
|
|
|
thread._Thread__stop()
|
2012-09-10 14:35:02 -04:00
|
|
|
# Exit correctly
|
|
|
|
if not result.wasSuccessful():
|
|
|
|
sys.exit(1)
|
2006-07-31 03:01:37 -04:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|