mirror of https://github.com/huashengdun/webssh
Tested server error
parent
49226fbf23
commit
6cfd981e80
|
@ -25,7 +25,7 @@ except ImportError:
|
||||||
handler.DELAY = 0.1
|
handler.DELAY = 0.1
|
||||||
|
|
||||||
|
|
||||||
class TestApp(AsyncHTTPTestCase):
|
class TestAppBasic(AsyncHTTPTestCase):
|
||||||
|
|
||||||
running = [True]
|
running = [True]
|
||||||
sshserver_port = 2200
|
sshserver_port = 2200
|
||||||
|
@ -63,7 +63,7 @@ class TestApp(AsyncHTTPTestCase):
|
||||||
print('='*20)
|
print('='*20)
|
||||||
|
|
||||||
def get_httpserver_options(self):
|
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)
|
options.update(max_body_size=max_body_size)
|
||||||
return options
|
return options
|
||||||
|
|
||||||
|
@ -420,3 +420,67 @@ class TestApp(AsyncHTTPTestCase):
|
||||||
self.assertIsNone(data['id'])
|
self.assertIsNone(data['id'])
|
||||||
self.assertIsNone(data['encoding'])
|
self.assertIsNone(data['encoding'])
|
||||||
self.assertIn('Bad authentication type', data['status'])
|
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
|
||||||
|
|
|
@ -222,7 +222,10 @@ class IndexHandler(MixinHandler, tornado.web.RequestHandler):
|
||||||
future.set_result(worker)
|
future.set_result(worker)
|
||||||
|
|
||||||
def get(self):
|
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
|
@tornado.gen.coroutine
|
||||||
def post(self):
|
def post(self):
|
||||||
|
|
|
@ -28,17 +28,17 @@
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<label for="Hostname">Hostname</label>
|
<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>
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<label for="Port">Port</label>
|
<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>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<label for="Username">Username</label>
|
<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>
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<label for="Username">Private Key</label>
|
<label for="Username">Private Key</label>
|
||||||
|
|
Loading…
Reference in New Issue