commit 6cfd981e80be062766034e693571c1f0502d7aa5
parent 49226fbf23403ae1008f042dc3b1afb95aba5006
Author: Sheng <webmaster0115@gmail.com>
Date: Wed, 29 Aug 2018 09:19:35 +0800
Tested server error
Diffstat:
3 files changed, 73 insertions(+), 6 deletions(-)
diff --git a/tests/test_app.py b/tests/test_app.py
@@ -25,7 +25,7 @@ except ImportError:
handler.DELAY = 0.1
-class TestApp(AsyncHTTPTestCase):
+class TestAppBasic(AsyncHTTPTestCase):
running = [True]
sshserver_port = 2200
@@ -63,7 +63,7 @@ class TestApp(AsyncHTTPTestCase):
print('='*20)
def get_httpserver_options(self):
- options = super(TestApp, self).get_httpserver_options()
+ options = super(TestAppBasic, self).get_httpserver_options()
options.update(max_body_size=max_body_size)
return options
@@ -420,3 +420,67 @@ class TestApp(AsyncHTTPTestCase):
self.assertIsNone(data['id'])
self.assertIsNone(data['encoding'])
self.assertIn('Bad authentication type', data['status'])
+
+
+class OtherTestBase(AsyncHTTPTestCase):
+ sshserver_port = 3300
+ headers = {'Cookie': '_xsrf=yummy'}
+ debug = False
+ body = {
+ 'hostname': '127.0.0.1',
+ 'port': '',
+ 'username': 'robey',
+ 'password': 'foo',
+ '_xsrf': 'yummy'
+ }
+
+ def get_app(self):
+ self.body.update(port=str(self.sshserver_port))
+ loop = self.io_loop
+ options.debug = self.debug
+ options.policy = random.choice(['warning', 'autoadd'])
+ options.hostFile = ''
+ options.sysHostFile = ''
+ app = make_app(make_handlers(loop, options), get_app_settings(options))
+ return app
+
+ def setUp(self):
+ print('='*20)
+ self.running = True
+ OtherTestBase.sshserver_port += 1
+
+ t = threading.Thread(
+ target=run_ssh_server, args=(self.sshserver_port, self.running)
+ )
+ t.setDaemon(True)
+ t.start()
+ super(OtherTestBase, self).setUp()
+
+ def tearDown(self):
+ self.running = False
+ print('='*20)
+ super(OtherTestBase, self).tearDown()
+
+
+class TestAppInDebug(OtherTestBase):
+
+ debug = True
+
+ def my_assertIn(self, part, whole):
+ if swallow_http_errors:
+ self.assertIn(part, whole)
+ else:
+ self.assertIn(b'Uncaught exception', whole)
+
+ def test_server_error(self):
+ response = self.fetch('/?error=generate', method='GET')
+ self.my_assertIn(b'Internal Server Error', response.body)
+
+ def test_html(self):
+ response = self.fetch('/', method='GET')
+ self.assertNotIn(b'required>', response.body)
+
+
+class TestAppMiscell(OtherTestBase):
+
+ debug = False
diff --git a/webssh/handler.py b/webssh/handler.py
@@ -222,7 +222,10 @@ class IndexHandler(MixinHandler, tornado.web.RequestHandler):
future.set_result(worker)
def get(self):
- self.render('index.html')
+ debug = self.settings.get('debug', False)
+ if debug and self.get_argument('error', u''):
+ raise ValueError('Uncaught exception')
+ self.render('index.html', debug=debug)
@tornado.gen.coroutine
def post(self):
diff --git a/webssh/templates/index.html b/webssh/templates/index.html
@@ -28,17 +28,17 @@
<div class="row">
<div class="col">
<label for="Hostname">Hostname</label>
- <input class="form-control" type="text" id="hostname" name="hostname" value="" required>
+ <input class="form-control" type="text" id="hostname" name="hostname" value="" {% if not debug %}required{% end %}>
</div>
<div class="col">
<label for="Port">Port</label>
- <input class="form-control" type="number" id="port" name="port" min=1 max=65535 value="" required>
+ <input class="form-control" type="number" id="port" name="port" value="" {% if not debug %}min=1 max=65535 required{% end %}>
</div>
</div>
<div class="row">
<div class="col">
<label for="Username">Username</label>
- <input class="form-control" type="text" id="username" name="username" value="" required>
+ <input class="form-control" type="text" id="username" name="username" value="" {% if not debug %}required{% end %}>
</div>
<div class="col">
<label for="Username">Private Key</label>