mirror of https://github.com/huashengdun/webssh
Move all tests data into a separate directory
parent
74cdb2d31f
commit
757702127a
|
@ -18,7 +18,6 @@
|
|||
# along with Paramiko; if not, write to the Free Software Foundation, Inc.,
|
||||
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
|
||||
|
||||
import os.path
|
||||
import random
|
||||
import socket
|
||||
# import sys
|
||||
|
@ -28,13 +27,13 @@ import paramiko
|
|||
|
||||
from binascii import hexlify
|
||||
from paramiko.py3compat import u, decodebytes
|
||||
from webssh.settings import base_dir
|
||||
from tests.utils import make_tests_data_path
|
||||
|
||||
|
||||
# setup logging
|
||||
paramiko.util.log_to_file(os.path.join(base_dir, 'tests', 'sshserver.log'))
|
||||
paramiko.util.log_to_file(make_tests_data_path('sshserver.log'))
|
||||
|
||||
host_key = paramiko.RSAKey(filename=os.path.join(base_dir, 'tests', 'test_rsa.key')) # noqa
|
||||
host_key = paramiko.RSAKey(filename=make_tests_data_path('test_rsa.key'))
|
||||
# host_key = paramiko.DSSKey(filename='test_dss.key')
|
||||
|
||||
print('Read key: ' + u(hexlify(host_key.get_fingerprint())))
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import json
|
||||
import os.path
|
||||
import random
|
||||
import threading
|
||||
import tornado.websocket
|
||||
|
@ -10,9 +9,9 @@ from tornado.testing import AsyncHTTPTestCase
|
|||
from tornado.httpclient import HTTPError
|
||||
from tornado.options import options
|
||||
from tests.sshserver import run_ssh_server, banner
|
||||
from tests.utils import encode_multipart_formdata, read_file
|
||||
from tests.utils import encode_multipart_formdata, read_file, make_tests_data_path # noqa
|
||||
from webssh.main import make_app, make_handlers
|
||||
from webssh.settings import get_app_settings, max_body_size, base_dir
|
||||
from webssh.settings import get_app_settings, max_body_size
|
||||
from webssh.utils import to_str
|
||||
|
||||
|
||||
|
@ -133,7 +132,7 @@ class TestApp(AsyncHTTPTestCase):
|
|||
response = yield client.fetch(url)
|
||||
self.assertEqual(response.code, 200)
|
||||
|
||||
privatekey = read_file(os.path.join(base_dir, 'tests', 'user_rsa_key'))
|
||||
privatekey = read_file(make_tests_data_path('user_rsa_key'))
|
||||
files = [('privatekey', 'user_rsa_key', privatekey)]
|
||||
content_type, body = encode_multipart_formdata(self.body_dict.items(),
|
||||
files)
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
import unittest
|
||||
import os.path
|
||||
import paramiko
|
||||
|
||||
from tornado.httputil import HTTPServerRequest
|
||||
from tests.utils import read_file
|
||||
from tests.utils import read_file, make_tests_data_path
|
||||
from webssh.handler import MixinHandler, IndexHandler, parse_encoding
|
||||
from webssh.settings import base_dir
|
||||
|
||||
|
||||
class TestHandler(unittest.TestCase):
|
||||
|
@ -53,7 +51,7 @@ class TestIndexHandler(unittest.TestCase):
|
|||
|
||||
fname = 'test_rsa.key'
|
||||
cls = paramiko.RSAKey
|
||||
key = read_file(os.path.join(base_dir, 'tests', fname))
|
||||
key = read_file(make_tests_data_path(fname))
|
||||
pkey = IndexHandler.get_specific_pkey(cls, key, None)
|
||||
self.assertIsInstance(pkey, cls)
|
||||
pkey = IndexHandler.get_specific_pkey(cls, key, 'iginored')
|
||||
|
@ -66,7 +64,7 @@ class TestIndexHandler(unittest.TestCase):
|
|||
cls = paramiko.RSAKey
|
||||
password = 'television'
|
||||
|
||||
key = read_file(os.path.join(base_dir, 'tests', fname))
|
||||
key = read_file(make_tests_data_path(fname))
|
||||
pkey = IndexHandler.get_specific_pkey(cls, key, password)
|
||||
self.assertIsInstance(pkey, cls)
|
||||
pkey = IndexHandler.get_specific_pkey(cls, 'x'+key, None)
|
||||
|
@ -78,7 +76,7 @@ class TestIndexHandler(unittest.TestCase):
|
|||
def test_get_pkey_obj_with_plain_key(self):
|
||||
fname = 'test_ed25519.key'
|
||||
cls = paramiko.Ed25519Key
|
||||
key = read_file(os.path.join(base_dir, 'tests', fname))
|
||||
key = read_file(make_tests_data_path(fname))
|
||||
pkey = IndexHandler.get_pkey_obj(key, None, fname)
|
||||
self.assertIsInstance(pkey, cls)
|
||||
pkey = IndexHandler.get_pkey_obj(key, 'iginored', fname)
|
||||
|
@ -91,7 +89,7 @@ class TestIndexHandler(unittest.TestCase):
|
|||
fname = 'test_ed25519_password.key'
|
||||
password = 'abc123'
|
||||
cls = paramiko.Ed25519Key
|
||||
key = read_file(os.path.join(base_dir, 'tests', fname))
|
||||
key = read_file(make_tests_data_path(fname))
|
||||
pkey = IndexHandler.get_pkey_obj(key, password, fname)
|
||||
self.assertIsInstance(pkey, cls)
|
||||
with self.assertRaises(ValueError) as exc:
|
||||
|
|
|
@ -4,11 +4,11 @@ import paramiko
|
|||
|
||||
from shutil import copyfile
|
||||
from paramiko.client import RejectPolicy, WarningPolicy
|
||||
from tests.utils import make_tests_data_path
|
||||
from webssh.policy import (
|
||||
AutoAddPolicy, get_policy_dictionary, load_host_keys,
|
||||
get_policy_class, check_policy_setting
|
||||
)
|
||||
from webssh.settings import base_dir
|
||||
|
||||
|
||||
class TestPolicy(unittest.TestCase):
|
||||
|
@ -29,7 +29,7 @@ class TestPolicy(unittest.TestCase):
|
|||
host_keys = load_host_keys(path)
|
||||
self.assertFalse(host_keys)
|
||||
|
||||
path = os.path.join(base_dir, 'tests', 'known_hosts_example')
|
||||
path = make_tests_data_path('known_hosts_example')
|
||||
host_keys = load_host_keys(path)
|
||||
self.assertEqual(host_keys, paramiko.hostkeys.HostKeys(path))
|
||||
|
||||
|
@ -45,7 +45,7 @@ class TestPolicy(unittest.TestCase):
|
|||
get_policy_class(key)
|
||||
|
||||
def test_check_policy_setting(self):
|
||||
host_keys_filename = os.path.join(base_dir, 'tests', 'host_keys_test.db') # noqa
|
||||
host_keys_filename = make_tests_data_path('host_keys_test.db')
|
||||
host_keys_settings = dict(
|
||||
host_keys=paramiko.hostkeys.HostKeys(),
|
||||
system_host_keys=paramiko.hostkeys.HostKeys(),
|
||||
|
@ -64,8 +64,8 @@ class TestPolicy(unittest.TestCase):
|
|||
|
||||
def test_is_missing_host_key(self):
|
||||
client = paramiko.SSHClient()
|
||||
file1 = os.path.join(base_dir, 'tests', 'known_hosts_example')
|
||||
file2 = os.path.join(base_dir, 'tests', 'known_hosts_example2')
|
||||
file1 = make_tests_data_path('known_hosts_example')
|
||||
file2 = make_tests_data_path('known_hosts_example2')
|
||||
client.load_host_keys(file1)
|
||||
client.load_system_host_keys(file2)
|
||||
|
||||
|
@ -86,7 +86,7 @@ class TestPolicy(unittest.TestCase):
|
|||
autoadd.is_missing_host_key(client, hostname, key)
|
||||
)
|
||||
|
||||
file3 = os.path.join(base_dir, 'tests', 'known_hosts_example3')
|
||||
file3 = make_tests_data_path('known_hosts_example3')
|
||||
entry = paramiko.hostkeys.HostKeys(file3)._entries[0]
|
||||
hostname = entry.hostnames[0]
|
||||
key = entry.key
|
||||
|
@ -95,9 +95,9 @@ class TestPolicy(unittest.TestCase):
|
|||
|
||||
def test_missing_host_key(self):
|
||||
client = paramiko.SSHClient()
|
||||
file1 = os.path.join(base_dir, 'tests', 'known_hosts_example')
|
||||
file2 = os.path.join(base_dir, 'tests', 'known_hosts_example2')
|
||||
filename = os.path.join(base_dir, 'tests', 'known_hosts')
|
||||
file1 = make_tests_data_path('known_hosts_example')
|
||||
file2 = make_tests_data_path('known_hosts_example2')
|
||||
filename = make_tests_data_path('known_hosts')
|
||||
copyfile(file1, filename)
|
||||
client.load_host_keys(filename)
|
||||
n1 = len(client._host_keys)
|
||||
|
|
|
@ -3,6 +3,7 @@ import unittest
|
|||
import paramiko
|
||||
import tornado.options as options
|
||||
|
||||
from tests.utils import make_tests_data_path
|
||||
from webssh.policy import load_host_keys
|
||||
from webssh.settings import (
|
||||
get_host_keys_settings, get_policy_setting, base_dir, print_version
|
||||
|
@ -30,8 +31,8 @@ class TestSettings(unittest.TestCase):
|
|||
load_host_keys(os.path.expanduser('~/.ssh/known_hosts'))
|
||||
)
|
||||
|
||||
options.hostFile = os.path.join(base_dir, 'tests', 'known_hosts_example') # noqa
|
||||
options.sysHostFile = os.path.join(base_dir, 'tests', 'known_hosts_example2') # noqa
|
||||
options.hostFile = make_tests_data_path('known_hosts_example')
|
||||
options.sysHostFile = make_tests_data_path('known_hosts_example2')
|
||||
dic2 = get_host_keys_settings(options)
|
||||
self.assertEqual(dic2['host_keys'], load_host_keys(options.hostFile))
|
||||
self.assertEqual(dic2['host_keys_filename'], options.hostFile)
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
import mimetypes
|
||||
import os.path
|
||||
from uuid import uuid4
|
||||
from webssh.settings import base_dir
|
||||
|
||||
|
||||
def encode_multipart_formdata(fields, files):
|
||||
|
@ -40,3 +42,7 @@ def get_content_type(filename):
|
|||
|
||||
def read_file(path, encoding='utf-8'):
|
||||
return open(path, 'rb').read().decode(encoding)
|
||||
|
||||
|
||||
def make_tests_data_path(filename):
|
||||
return os.path.join(base_dir, 'tests', 'data', filename)
|
||||
|
|
Loading…
Reference in New Issue