Use test_path to avoid relative path issues

This commit is contained in:
Scott Maxwell 2013-10-30 16:22:52 -07:00
parent 66cfa97cce
commit 644c52266c
5 changed files with 23 additions and 17 deletions

View File

@ -36,7 +36,7 @@ from tests.util import test_path
class NullServer (ServerInterface):
paranoid_did_password = False
paranoid_did_public_key = False
paranoid_key = DSSKey.from_private_key_file('tests/test_dss.key')
paranoid_key = DSSKey.from_private_key_file(test_path('test_dss.key'))
def get_allowed_auths(self, username):
if username == 'slowdive':
@ -111,8 +111,8 @@ class AuthTest (unittest.TestCase):
self.sockc.close()
def start_server(self):
host_key = RSAKey.from_private_key_file('tests/test_rsa.key')
self.public_host_key = RSAKey(data=str(host_key))
host_key = RSAKey.from_private_key_file(test_path('test_rsa.key'))
self.ts.add_server_key(host_key)
self.event = threading.Event()
self.server = NullServer()
@ -163,7 +163,7 @@ class AuthTest (unittest.TestCase):
self.tc.connect(hostkey=self.public_host_key)
remain = self.tc.auth_password(username='paranoid', password='paranoid')
self.assertEquals(['publickey'], remain)
key = DSSKey.from_private_key_file('tests/test_dss.key')
key = DSSKey.from_private_key_file(test_path('test_dss.key'))
remain = self.tc.auth_publickey(username='paranoid', key=key)
self.assertEquals([], remain)
self.verify_finished()

View File

@ -76,7 +76,7 @@ class SSHClientTest (unittest.TestCase):
def _run(self):
self.socks, addr = self.sockl.accept()
self.ts = paramiko.Transport(self.socks)
host_key = paramiko.RSAKey.from_private_key_file('tests/test_rsa.key')
host_key = paramiko.RSAKey.from_private_key_file(test_path('test_rsa.key'))
self.ts.add_server_key(host_key)
server = NullServer()
self.ts.start_server(self.event, server)
@ -86,8 +86,8 @@ class SSHClientTest (unittest.TestCase):
"""
verify that the SSHClient stuff works too.
"""
host_key = paramiko.RSAKey.from_private_key_file('tests/test_rsa.key')
public_host_key = paramiko.RSAKey(data=str(host_key))
host_key = paramiko.RSAKey.from_private_key_file(test_path('test_rsa.key'))
self.tc = paramiko.SSHClient()
self.tc.get_host_keys().add('[%s]:%d' % (self.addr, self.port), 'ssh-rsa', public_host_key)
@ -119,12 +119,12 @@ class SSHClientTest (unittest.TestCase):
"""
verify that SSHClient works with a DSA key.
"""
host_key = paramiko.RSAKey.from_private_key_file('tests/test_rsa.key')
public_host_key = paramiko.RSAKey(data=str(host_key))
host_key = paramiko.RSAKey.from_private_key_file(test_path('test_rsa.key'))
self.tc = paramiko.SSHClient()
self.tc.get_host_keys().add('[%s]:%d' % (self.addr, self.port), 'ssh-rsa', public_host_key)
self.tc.connect(self.addr, self.port, username='slowdive', key_filename='tests/test_dss.key')
self.tc.connect(self.addr, self.port, username='slowdive', key_filename=test_path('test_dss.key'))
self.event.wait(1.0)
self.assert_(self.event.isSet())
@ -152,12 +152,12 @@ class SSHClientTest (unittest.TestCase):
"""
verify that SSHClient accepts and tries multiple key files.
"""
host_key = paramiko.RSAKey.from_private_key_file('tests/test_rsa.key')
public_host_key = paramiko.RSAKey(data=str(host_key))
host_key = paramiko.RSAKey.from_private_key_file(test_path('test_rsa.key'))
self.tc = paramiko.SSHClient()
self.tc.get_host_keys().add('[%s]:%d' % (self.addr, self.port), 'ssh-rsa', public_host_key)
self.tc.connect(self.addr, self.port, username='slowdive', key_filename=[ 'tests/test_rsa.key', 'tests/test_dss.key' ])
self.tc.connect(self.addr, self.port, username='slowdive', key_filename=[ test_path('test_rsa.key'), test_path('test_dss.key') ])
self.event.wait(1.0)
self.assert_(self.event.isSet())
@ -169,8 +169,8 @@ class SSHClientTest (unittest.TestCase):
"""
verify that SSHClient's AutoAddPolicy works.
"""
host_key = paramiko.RSAKey.from_private_key_file('tests/test_rsa.key')
public_host_key = paramiko.RSAKey(data=str(host_key))
host_key = paramiko.RSAKey.from_private_key_file(test_path('test_rsa.key'))
self.tc = paramiko.SSHClient()
self.tc.set_missing_host_key_policy(paramiko.AutoAddPolicy())
@ -190,8 +190,8 @@ class SSHClientTest (unittest.TestCase):
verify that when an SSHClient is collected, its transport (and the
transport's packetizer) is closed.
"""
host_key = paramiko.RSAKey.from_private_key_file('tests/test_rsa.key')
public_host_key = paramiko.RSAKey(data=str(host_key))
host_key = paramiko.RSAKey.from_private_key_file(test_path('test_rsa.key'))
self.tc = paramiko.SSHClient()
self.tc.set_missing_host_key_policy(paramiko.AutoAddPolicy())

View File

@ -122,7 +122,7 @@ class SFTPTest (unittest.TestCase):
tc = paramiko.Transport(sockc)
ts = paramiko.Transport(socks)
host_key = paramiko.RSAKey.from_private_key_file('tests/test_rsa.key')
host_key = paramiko.RSAKey.from_private_key_file(test_path('test_rsa.key'))
ts.add_server_key(host_key)
event = threading.Event()
server = StubServer()

View File

@ -55,7 +55,7 @@ Maybe.
class NullServer (ServerInterface):
paranoid_did_password = False
paranoid_did_public_key = False
paranoid_key = DSSKey.from_private_key_file('tests/test_dss.key')
paranoid_key = DSSKey.from_private_key_file(test_path('test_dss.key'))
def get_allowed_auths(self, username):
if username == 'slowdive':
@ -121,8 +121,8 @@ class TransportTest(ParamikoTest):
self.sockc.close()
def setup_test_server(self, client_options=None, server_options=None):
host_key = RSAKey.from_private_key_file('tests/test_rsa.key')
public_host_key = RSAKey(data=str(host_key))
host_key = RSAKey.from_private_key_file(test_path('test_rsa.key'))
self.ts.add_server_key(host_key)
if client_options is not None:
@ -171,8 +171,8 @@ class TransportTest(ParamikoTest):
loopback sockets. this is hardly "simple" but it's simpler than the
later tests. :)
"""
host_key = RSAKey.from_private_key_file('tests/test_rsa.key')
public_host_key = RSAKey(data=str(host_key))
host_key = RSAKey.from_private_key_file(test_path('test_rsa.key'))
self.ts.add_server_key(host_key)
event = threading.Event()
server = NullServer()
@ -196,8 +196,8 @@ class TransportTest(ParamikoTest):
"""
verify that a long banner doesn't mess up the handshake.
"""
host_key = RSAKey.from_private_key_file('tests/test_rsa.key')
public_host_key = RSAKey(data=str(host_key))
host_key = RSAKey.from_private_key_file(test_path('test_rsa.key'))
self.ts.add_server_key(host_key)
event = threading.Event()
server = NullServer()

View File

@ -1,6 +1,8 @@
import os
import unittest
root_path = os.path.dirname(os.path.realpath(__file__))
class ParamikoTest(unittest.TestCase):
# for Python 2.3 and below
@ -9,3 +11,7 @@ class ParamikoTest(unittest.TestCase):
if not hasattr(unittest.TestCase, 'assertFalse'):
assertFalse = unittest.TestCase.failIf
def test_path(filename):
return os.path.join(root_path, filename)