Skip to content

Commit

Permalink
Added test_main.py to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
huashengdun committed Oct 23, 2018
1 parent 2755a98 commit 4525f50
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
45 changes: 45 additions & 0 deletions tests/test_main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import unittest

from tornado.web import Application
from webssh.handler import open_to_public
from webssh.main import app_listen


class TestMain(unittest.TestCase):

def test_app_listen(self):
app = Application()
app.listen = lambda x, y, **kwargs: 1
open_to_public['https'] = None
open_to_public['http'] = None

server_settings = dict(ssl_options=False)
app_listen(app, 80, '127.0.0.1', server_settings)
self.assertEqual(open_to_public['http'], False)
self.assertIsNone(open_to_public['https'])
open_to_public['http'] = None

server_settings = dict(ssl_options=False)
app_listen(app, 80, '0.0.0.0', server_settings)
self.assertEqual(open_to_public['http'], True)
self.assertIsNone(open_to_public['https'])
open_to_public['http'] = None

server_settings = dict(ssl_options=True)
app_listen(app, 443, '127.0.0.1', server_settings)
self.assertEqual(open_to_public['https'], False)
self.assertIsNone(open_to_public['http'])
open_to_public['https'] = None

server_settings = dict(ssl_options=True)
app_listen(app, 443, '0.0.0.0', server_settings)
self.assertEqual(open_to_public['https'], True)
self.assertIsNone(open_to_public['http'])
open_to_public['https'] = None

server_settings = dict(ssl_options=False)
app_listen(app, 80, '0.0.0.0', server_settings)
server_settings = dict(ssl_options=True)
app_listen(app, 443, '0.0.0.0', server_settings)
self.assertEqual(open_to_public['https'], True)
self.assertEqual(open_to_public['http'], True)
1 change: 1 addition & 0 deletions webssh/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@

def config_open_to_public(address, server_type):
status = True if is_name_open_to_public(address) else False
logging.debug('{} server open to public: {}'.format(server_type, status))
open_to_public[server_type] = status


Expand Down

0 comments on commit 4525f50

Please sign in to comment.