forked from huashengdun/webssh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_settings.py
68 lines (58 loc) · 2.47 KB
/
test_settings.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import os.path
import unittest
import paramiko
import tornado.options as options
from webssh.settings import (
get_host_keys_settings, get_policy_setting, base_dir, print_version
)
from webssh.policy import load_host_keys
from webssh._version import __version__
class TestSettings(unittest.TestCase):
def test_print_version(self):
self.assertNotEqual(print_version(False), 2, msg=__version__)
with self.assertRaises(SystemExit):
self.assertEqual(print_version(True), 2, msg=__version__)
def test_get_host_keys_settings(self):
options.hostFile = ''
options.sysHostFile = ''
dic = get_host_keys_settings(options)
filename = os.path.join(base_dir, 'known_hosts')
self.assertEqual(dic['host_keys'], load_host_keys(filename))
self.assertEqual(dic['host_keys_filename'], filename)
self.assertEqual(
dic['system_host_keys'],
load_host_keys(os.path.expanduser('~/.ssh/known_hosts'))
)
options.hostFile = 'tests/known_hosts_example'
options.sysHostFile = 'tests/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)
self.assertEqual(dic2['system_host_keys'],
load_host_keys(options.sysHostFile))
def test_get_policy_setting(self):
options.policy = 'warning'
options.hostFile = ''
options.sysHostFile = ''
settings = get_host_keys_settings(options)
instance = get_policy_setting(options, settings)
self.assertIsInstance(instance, paramiko.client.WarningPolicy)
options.policy = 'autoadd'
options.hostFile = ''
options.sysHostFile = ''
settings = get_host_keys_settings(options)
instance = get_policy_setting(options, settings)
self.assertIsInstance(instance, paramiko.client.AutoAddPolicy)
os.unlink(settings['host_keys_filename'])
options.policy = 'reject'
options.hostFile = ''
options.sysHostFile = ''
settings = get_host_keys_settings(options)
try:
instance = get_policy_setting(options, settings)
except ValueError:
self.assertFalse(
settings['host_keys'] and settings['system_host_keys']
)
else:
self.assertIsInstance(instance, paramiko.client.RejectPolicy)