webssh

Web based ssh client https://github.com/huashengdun/webssh webssh.huashengdun.org/
git clone http://git.hanabi.in/repos/webssh.git
Log | Files | Refs | README | LICENSE

commit 757702127a972d1cc408f84736fa9ccabed21126
parent 74cdb2d31f67acd3203f61cc4d6d8afd53cea006
Author: Sheng <webmaster0115@gmail.com>
Date:   Fri, 24 Aug 2018 15:11:21 +0800

Move all tests data into a separate directory

Diffstat:
Rtests/known_hosts_example -> tests/data/known_hosts_example | 0
Rtests/known_hosts_example2 -> tests/data/known_hosts_example2 | 0
Rtests/known_hosts_example3 -> tests/data/known_hosts_example3 | 0
Rtests/test_ed25519.key -> tests/data/test_ed25519.key | 0
Rtests/test_ed25519_password.key -> tests/data/test_ed25519_password.key | 0
Rtests/test_rsa.key -> tests/data/test_rsa.key | 0
Rtests/test_rsa_password.key -> tests/data/test_rsa_password.key | 0
Rtests/user_rsa_key -> tests/data/user_rsa_key | 0
Mtests/sshserver.py | 7+++----
Mtests/test_app.py | 7+++----
Mtests/test_handler.py | 12+++++-------
Mtests/test_policy.py | 18+++++++++---------
Mtests/test_settings.py | 5+++--
Mtests/utils.py | 6++++++
14 files changed, 29 insertions(+), 26 deletions(-)

diff --git a/tests/known_hosts_example b/tests/data/known_hosts_example diff --git a/tests/known_hosts_example2 b/tests/data/known_hosts_example2 diff --git a/tests/known_hosts_example3 b/tests/data/known_hosts_example3 diff --git a/tests/test_ed25519.key b/tests/data/test_ed25519.key diff --git a/tests/test_ed25519_password.key b/tests/data/test_ed25519_password.key diff --git a/tests/test_rsa.key b/tests/data/test_rsa.key diff --git a/tests/test_rsa_password.key b/tests/data/test_rsa_password.key diff --git a/tests/user_rsa_key b/tests/data/user_rsa_key diff --git a/tests/sshserver.py b/tests/sshserver.py @@ -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()))) diff --git a/tests/test_app.py b/tests/test_app.py @@ -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) diff --git a/tests/test_handler.py b/tests/test_handler.py @@ -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: diff --git a/tests/test_policy.py b/tests/test_policy.py @@ -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) diff --git a/tests/test_settings.py b/tests/test_settings.py @@ -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) diff --git a/tests/utils.py b/tests/utils.py @@ -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)