Use test_path to avoid relative path issues
This commit is contained in:
parent
66cfa97cce
commit
644c52266c
|
@ -36,7 +36,7 @@ from tests.util import test_path
|
||||||
class NullServer (ServerInterface):
|
class NullServer (ServerInterface):
|
||||||
paranoid_did_password = False
|
paranoid_did_password = False
|
||||||
paranoid_did_public_key = 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):
|
def get_allowed_auths(self, username):
|
||||||
if username == 'slowdive':
|
if username == 'slowdive':
|
||||||
|
@ -111,8 +111,8 @@ class AuthTest (unittest.TestCase):
|
||||||
self.sockc.close()
|
self.sockc.close()
|
||||||
|
|
||||||
def start_server(self):
|
def start_server(self):
|
||||||
host_key = RSAKey.from_private_key_file('tests/test_rsa.key')
|
|
||||||
self.public_host_key = RSAKey(data=str(host_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.ts.add_server_key(host_key)
|
||||||
self.event = threading.Event()
|
self.event = threading.Event()
|
||||||
self.server = NullServer()
|
self.server = NullServer()
|
||||||
|
@ -163,7 +163,7 @@ class AuthTest (unittest.TestCase):
|
||||||
self.tc.connect(hostkey=self.public_host_key)
|
self.tc.connect(hostkey=self.public_host_key)
|
||||||
remain = self.tc.auth_password(username='paranoid', password='paranoid')
|
remain = self.tc.auth_password(username='paranoid', password='paranoid')
|
||||||
self.assertEquals(['publickey'], remain)
|
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)
|
remain = self.tc.auth_publickey(username='paranoid', key=key)
|
||||||
self.assertEquals([], remain)
|
self.assertEquals([], remain)
|
||||||
self.verify_finished()
|
self.verify_finished()
|
||||||
|
|
|
@ -76,7 +76,7 @@ class SSHClientTest (unittest.TestCase):
|
||||||
def _run(self):
|
def _run(self):
|
||||||
self.socks, addr = self.sockl.accept()
|
self.socks, addr = self.sockl.accept()
|
||||||
self.ts = paramiko.Transport(self.socks)
|
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)
|
self.ts.add_server_key(host_key)
|
||||||
server = NullServer()
|
server = NullServer()
|
||||||
self.ts.start_server(self.event, server)
|
self.ts.start_server(self.event, server)
|
||||||
|
@ -86,8 +86,8 @@ class SSHClientTest (unittest.TestCase):
|
||||||
"""
|
"""
|
||||||
verify that the SSHClient stuff works too.
|
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))
|
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 = paramiko.SSHClient()
|
||||||
self.tc.get_host_keys().add('[%s]:%d' % (self.addr, self.port), 'ssh-rsa', public_host_key)
|
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.
|
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))
|
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 = paramiko.SSHClient()
|
||||||
self.tc.get_host_keys().add('[%s]:%d' % (self.addr, self.port), 'ssh-rsa', public_host_key)
|
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.event.wait(1.0)
|
||||||
self.assert_(self.event.isSet())
|
self.assert_(self.event.isSet())
|
||||||
|
@ -152,12 +152,12 @@ class SSHClientTest (unittest.TestCase):
|
||||||
"""
|
"""
|
||||||
verify that SSHClient accepts and tries multiple key files.
|
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))
|
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 = paramiko.SSHClient()
|
||||||
self.tc.get_host_keys().add('[%s]:%d' % (self.addr, self.port), 'ssh-rsa', public_host_key)
|
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.event.wait(1.0)
|
||||||
self.assert_(self.event.isSet())
|
self.assert_(self.event.isSet())
|
||||||
|
@ -169,8 +169,8 @@ class SSHClientTest (unittest.TestCase):
|
||||||
"""
|
"""
|
||||||
verify that SSHClient's AutoAddPolicy works.
|
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))
|
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 = paramiko.SSHClient()
|
||||||
self.tc.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
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
|
verify that when an SSHClient is collected, its transport (and the
|
||||||
transport's packetizer) is closed.
|
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))
|
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 = paramiko.SSHClient()
|
||||||
self.tc.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
self.tc.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||||
|
|
|
@ -122,7 +122,7 @@ class SFTPTest (unittest.TestCase):
|
||||||
tc = paramiko.Transport(sockc)
|
tc = paramiko.Transport(sockc)
|
||||||
ts = paramiko.Transport(socks)
|
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)
|
ts.add_server_key(host_key)
|
||||||
event = threading.Event()
|
event = threading.Event()
|
||||||
server = StubServer()
|
server = StubServer()
|
||||||
|
|
|
@ -55,7 +55,7 @@ Maybe.
|
||||||
class NullServer (ServerInterface):
|
class NullServer (ServerInterface):
|
||||||
paranoid_did_password = False
|
paranoid_did_password = False
|
||||||
paranoid_did_public_key = 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):
|
def get_allowed_auths(self, username):
|
||||||
if username == 'slowdive':
|
if username == 'slowdive':
|
||||||
|
@ -121,8 +121,8 @@ class TransportTest(ParamikoTest):
|
||||||
self.sockc.close()
|
self.sockc.close()
|
||||||
|
|
||||||
def setup_test_server(self, client_options=None, server_options=None):
|
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))
|
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.ts.add_server_key(host_key)
|
||||||
|
|
||||||
if client_options is not None:
|
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
|
loopback sockets. this is hardly "simple" but it's simpler than the
|
||||||
later tests. :)
|
later tests. :)
|
||||||
"""
|
"""
|
||||||
host_key = RSAKey.from_private_key_file('tests/test_rsa.key')
|
|
||||||
public_host_key = RSAKey(data=str(host_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)
|
self.ts.add_server_key(host_key)
|
||||||
event = threading.Event()
|
event = threading.Event()
|
||||||
server = NullServer()
|
server = NullServer()
|
||||||
|
@ -196,8 +196,8 @@ class TransportTest(ParamikoTest):
|
||||||
"""
|
"""
|
||||||
verify that a long banner doesn't mess up the handshake.
|
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))
|
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.ts.add_server_key(host_key)
|
||||||
event = threading.Event()
|
event = threading.Event()
|
||||||
server = NullServer()
|
server = NullServer()
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
import os
|
import os
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
|
root_path = os.path.dirname(os.path.realpath(__file__))
|
||||||
|
|
||||||
|
|
||||||
class ParamikoTest(unittest.TestCase):
|
class ParamikoTest(unittest.TestCase):
|
||||||
# for Python 2.3 and below
|
# for Python 2.3 and below
|
||||||
|
@ -9,3 +11,7 @@ class ParamikoTest(unittest.TestCase):
|
||||||
if not hasattr(unittest.TestCase, 'assertFalse'):
|
if not hasattr(unittest.TestCase, 'assertFalse'):
|
||||||
assertFalse = unittest.TestCase.failIf
|
assertFalse = unittest.TestCase.failIf
|
||||||
|
|
||||||
|
|
||||||
|
def test_path(filename):
|
||||||
|
return os.path.join(root_path, filename)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue