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 251fd90e5ff4c28c43cc4dec445d08e4a3221ae7
parent af6b134b6419052f8fea87b5f9c56181f9552ea7
Author: Sheng <webmaster0115@gmail.com>
Date:   Mon, 23 Apr 2018 10:17:29 +0800

Added more unittests to test_policy.py

Diffstat:
Mtests/test_policy.py | 44+++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 43 insertions(+), 1 deletion(-)

diff --git a/tests/test_policy.py b/tests/test_policy.py @@ -1,6 +1,10 @@ +import os import unittest +import paramiko + from paramiko.client import RejectPolicy, WarningPolicy -from webssh.policy import AutoAddPolicy, get_policy_dictionary +from webssh.policy import AutoAddPolicy, get_policy_dictionary, load_host_keys +from webssh.policy import get_policy_class, check_policy_setting class TestPolicy(unittest.TestCase): @@ -11,3 +15,41 @@ class TestPolicy(unittest.TestCase): for cls in classes: val = dic[cls.__name__.lower()] self.assertIs(cls, val) + + def test_load_host_keys(self): + path = '/path-not-exists' + host_keys = load_host_keys(path) + self.assertFalse(host_keys) + + path = '/tmp' + host_keys = load_host_keys(path) + self.assertFalse(host_keys) + + def test_get_policy_class(self): + keys = ['autoadd', 'reject', 'warning'] + vals = [AutoAddPolicy, RejectPolicy, WarningPolicy] + for key, val in zip(keys, vals): + cls = get_policy_class(key) + self.assertIs(cls, val) + + key = 'non-exists' + with self.assertRaises(ValueError): + get_policy_class(key) + + def test_check_policy_setting(self): + host_keys_filename = './webssh/host_keys_test.db' + host_keys_settings = dict( + host_keys=paramiko.hostkeys.HostKeys(), + system_host_keys=paramiko.hostkeys.HostKeys(), + host_keys_filename=host_keys_filename + ) + + with self.assertRaises(ValueError): + check_policy_setting(RejectPolicy, host_keys_settings) + + try: + os.unlink(host_keys_filename) + except OSError: + pass + check_policy_setting(AutoAddPolicy, host_keys_settings) + self.assertEqual(os.path.exists(host_keys_filename), True)