Use open_to_public to store the status of the http(s) server

This commit is contained in:
Sheng
2018-10-20 17:26:33 +08:00
parent e31e9be433
commit 40cf1095ff
7 changed files with 51 additions and 59 deletions
+4 -1
View File
@@ -4,7 +4,9 @@ import paramiko
from tornado.httputil import HTTPServerRequest
from tornado.options import options
from tests.utils import read_file, make_tests_data_path
from webssh.handler import MixinHandler, IndexHandler, InvalidValueError
from webssh.handler import (
MixinHandler, IndexHandler, InvalidValueError, open_to_public
)
try:
from unittest.mock import Mock
@@ -16,6 +18,7 @@ class TestMixinHandler(unittest.TestCase):
def test_is_forbidden(self):
handler = MixinHandler()
open_to_public['http'] = True
options.fbidhttp = True
context = Mock(
+1 -22
View File
@@ -10,7 +10,7 @@ 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,
get_ssl_context, get_trusted_downstream, detect_is_open_to_public,
get_ssl_context, get_trusted_downstream
)
from webssh.utils import UnicodeType
from webssh._version import __version__
@@ -137,24 +137,3 @@ class TestSettings(unittest.TestCase):
tdstream = '1.1.1.1, 2.2.2.'
with self.assertRaises(ValueError):
get_trusted_downstream(tdstream)
def test_detect_is_open_to_public(self):
options.fbidhttp = True
options.address = '127.0.0.1'
detect_is_open_to_public(options)
self.assertFalse(options.fbidhttp)
options.fbidhttp = False
options.address = '127.0.0.1'
detect_is_open_to_public(options)
self.assertFalse(options.fbidhttp)
options.fbidhttp = False
options.address = '0.0.0.0'
detect_is_open_to_public(options)
self.assertFalse(options.fbidhttp)
options.fbidhttp = True
options.address = '0.0.0.0'
detect_is_open_to_public(options)
self.assertTrue(options.fbidhttp)
+8 -9
View File
@@ -2,8 +2,8 @@ import unittest
from webssh.utils import (
is_valid_ip_address, is_valid_port, is_valid_hostname, to_str, to_bytes,
to_int, on_public_network_interface, on_public_network_interfaces,
get_ips_by_name
to_int, on_public_network_interface, get_ips_by_name,
is_name_open_to_public
)
@@ -67,10 +67,9 @@ class TestUitls(unittest.TestCase):
self.assertTrue(on_public_network_interface('2:2:2:2:2:2:2:2'))
self.assertIsNone(on_public_network_interface('127.0.0.1'))
def test_on_public_network_interfaces(self):
self.assertTrue(
on_public_network_interfaces(['0.0.0.0', '127.0.0.1'])
)
self.assertIsNone(
on_public_network_interfaces(['192.168.1.1', '127.0.0.1'])
)
def test_is_name_open_to_public(self):
self.assertTrue(is_name_open_to_public('0.0.0.0'))
self.assertTrue(is_name_open_to_public('::'))
self.assertIsNone(is_name_open_to_public('192.168.1.1'))
self.assertIsNone(is_name_open_to_public('127.0.0.1'))
self.assertIsNone(is_name_open_to_public('localhost'))