summaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorScott Maxwell <scott@codecobblers.com>2013-10-30 16:22:52 -0700
committerScott Maxwell <scott@codecobblers.com>2013-10-30 16:22:52 -0700
commit644c52266caaa5b975a13e355d1bfd921c9c9ddb (patch)
treed6525a0626c82cb34256b678ae3fbbe145916a57 /tests
parent66cfa97cce92b1d60383d178887b18dddb999fc1 (diff)
Use test_path to avoid relative path issues
Diffstat (limited to 'tests')
-rw-r--r--tests/test_auth.py8
-rw-r--r--tests/test_client.py16
-rwxr-xr-xtests/test_sftp.py2
-rw-r--r--tests/test_transport.py8
-rw-r--r--tests/util.py6
5 files changed, 23 insertions, 17 deletions
diff --git a/tests/test_auth.py b/tests/test_auth.py
index 1e247d70..ea9b2bdd 100644
--- a/tests/test_auth.py
+++ b/tests/test_auth.py
@@ -36,8 +36,8 @@ 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':
return 'publickey,password'
@@ -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()
diff --git a/tests/test_client.py b/tests/test_client.py
index 7d1e6729..91aac334 100644
--- a/tests/test_client.py
+++ b/tests/test_client.py
@@ -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())
diff --git a/tests/test_sftp.py b/tests/test_sftp.py
index 3c1fcd52..a421355e 100755
--- a/tests/test_sftp.py
+++ b/tests/test_sftp.py
@@ -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()
diff --git a/tests/test_transport.py b/tests/test_transport.py
index ed8ebb42..ccd3f0c8 100644
--- a/tests/test_transport.py
+++ b/tests/test_transport.py
@@ -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()
diff --git a/tests/util.py b/tests/util.py
index 1b380b75..66d2696c 100644
--- a/tests/util.py
+++ b/tests/util.py
@@ -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)
+