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
+3 -2
View File
@@ -3,16 +3,16 @@ import random
import threading
import tornado.websocket
import tornado.gen
import webssh.handler as handler
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, make_tests_data_path # noqa
from webssh import handler
from webssh.main import make_app, make_handlers
from webssh.settings import (
get_app_settings, get_server_settings, max_body_size, swallow_http_errors
get_app_settings, get_server_settings, max_body_size
)
from webssh.utils import to_str
@@ -23,6 +23,7 @@ except ImportError:
handler.DELAY = 0.1
swallow_http_errors = handler.swallow_http_errors
class TestAppBasic(AsyncHTTPTestCase):
+3 -2
View File
@@ -1,5 +1,6 @@
import unittest
import paramiko
import webssh.handler
from tornado.httpclient import HTTPRequest
from tornado.httputil import HTTPServerRequest
@@ -16,8 +17,8 @@ class TestMixinHandler(unittest.TestCase):
def test_is_forbidden(self):
handler = MixinHandler()
handler.is_open_to_public = True
handler.forbid_public_http = True
webssh.handler.is_open_to_public = True
webssh.handler.forbid_public_http = True
request = HTTPRequest('http://example.com/')
handler.request = request
+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)