commit 1a3880eceea67baf4886337342f6f6ed453bb7c0
parent 5519a1701648690559cdda689648c9c3925a0b35
Author: Sheng <webmaster0115@gmail.com>
Date: Sun, 26 Aug 2018 15:40:08 +0800
Raise InvalidException for empty required value
Diffstat:
2 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/tests/test_app.py b/tests/test_app.py
@@ -87,17 +87,17 @@ class TestApp(AsyncHTTPTestCase):
body = 'hostname=&port=&username=&password'
response = self.fetch('/', method='POST', body=body)
self.assertEqual(response.code, 400)
- self.assertIn(b'Missing argument hostname', response.body)
+ self.assertIn(b'Missing value hostname', response.body)
body = 'hostname=127.0.0.1&port=&username=&password'
response = self.fetch('/', method='POST', body=body)
self.assertEqual(response.code, 400)
- self.assertIn(b'Missing argument port', response.body)
+ self.assertIn(b'Missing value port', response.body)
body = 'hostname=127.0.0.1&port=7000&username=&password'
response = self.fetch('/', method='POST', body=body)
self.assertEqual(response.code, 400)
- self.assertIn(b'Missing argument username', response.body)
+ self.assertIn(b'Missing value username', response.body)
def test_app_with_invalid_form_for_invalid_value(self):
body = 'hostname=127.0.0&port=22&username=&password'
@@ -234,7 +234,7 @@ class TestApp(AsyncHTTPTestCase):
ws = yield tornado.websocket.websocket_connect(ws_url)
msg = yield ws.read_message()
self.assertIsNone(msg)
- self.assertIn('Missing argument id', ws.close_reason)
+ self.assertIn('Missing value id', ws.close_reason)
@tornado.testing.gen_test
def test_app_with_correct_credentials_but_wrong_id(self):
diff --git a/webssh/handler.py b/webssh/handler.py
@@ -55,7 +55,7 @@ class MixinHandler(object):
def get_value(self, name):
value = self.get_argument(name)
if not value:
- raise tornado.web.MissingArgumentError(name)
+ raise InvalidException('Missing value {}'.format(name))
return value
def get_real_client_addr(self):
@@ -261,8 +261,8 @@ class WsockHandler(MixinHandler, tornado.websocket.WebSocketHandler):
logging.info('Connected from {}:{}'.format(*self.src_addr))
try:
worker_id = self.get_value('id')
- except tornado.web.MissingArgumentError as exc:
- self.close(reason=exc.log_message)
+ except (tornado.web.MissingArgumentError, InvalidException) as exc:
+ self.close(reason=str(exc))
raise
else:
worker = workers.get(worker_id)