Move some config variables to handler.py

This commit is contained in:
Sheng
2018-10-18 15:07:45 +08:00
parent 383f61d4cc
commit 5d6f92e529
5 changed files with 38 additions and 30 deletions
+21 -8
View File
@@ -1,4 +1,5 @@
import io
import random
import ssl
import sys
import os.path
@@ -7,7 +8,7 @@ import paramiko
import tornado.options as options
from tests.utils import make_tests_data_path
from webssh import settings
from webssh import handler
from webssh.policy import load_host_keys
from webssh.settings import (
get_host_keys_settings, get_policy_setting, base_dir, print_version,
@@ -140,27 +141,39 @@ class TestSettings(unittest.TestCase):
get_trusted_downstream(options), tdstream
def test_detect_is_open_to_public(self):
options.fbidhttp = True
options.fbidhttp = random.choice([True, False])
options.address = 'localhost'
detect_is_open_to_public(options)
self.assertFalse(settings.is_open_to_public)
self.assertFalse(handler.is_open_to_public)
self.assertEqual(handler.forbid_public_http, options.fbidhttp)
options.fbidhttp = random.choice([True, False])
options.fbidhttp = False
options.address = '127.0.0.1'
detect_is_open_to_public(options)
self.assertFalse(settings.is_open_to_public)
self.assertFalse(handler.is_open_to_public)
self.assertEqual(handler.forbid_public_http, options.fbidhttp)
options.fbidhttp = random.choice([True, False])
options.address = '192.168.1.1'
detect_is_open_to_public(options)
self.assertFalse(settings.is_open_to_public)
self.assertFalse(handler.is_open_to_public)
self.assertEqual(handler.forbid_public_http, options.fbidhttp)
options.fbidhttp = random.choice([True, False])
options.address = ''
detect_is_open_to_public(options)
self.assertTrue(settings.is_open_to_public)
self.assertTrue(handler.is_open_to_public)
self.assertEqual(handler.forbid_public_http, options.fbidhttp)
options.fbidhttp = random.choice([True, False])
options.address = '0.0.0.0'
detect_is_open_to_public(options)
self.assertTrue(settings.is_open_to_public)
self.assertTrue(handler.is_open_to_public)
self.assertEqual(handler.forbid_public_http, options.fbidhttp)
options.fbidhttp = random.choice([True, False])
options.address = '::'
detect_is_open_to_public(options)
self.assertTrue(settings.is_open_to_public)
self.assertTrue(handler.is_open_to_public)
self.assertEqual(handler.forbid_public_http, options.fbidhttp)