webssh

Web based ssh client https://github.com/huashengdun/webssh webssh.huashengdun.org/
git clone http://git.hanabi.in/repos/webssh.git
Log | Files | Refs | README | LICENSE

commit 5f3641701e61f306980720ecfb88658ab9b66f4b
parent 41740690ac48a9066bb52bae0654cfc4cb3cbb72
Author: Sheng <webmaster0115@gmail.com>
Date:   Sat,  1 Sep 2018 11:00:01 +0800

Increase buffer size for channel

Diffstat:
Mtests/sshserver.py | 13++++++++++++-
Mtests/test_app.py | 30+++++++++++++++++++++++++++++-
Mwebssh/worker.py | 4+++-
3 files changed, 44 insertions(+), 3 deletions(-)

diff --git a/tests/sshserver.py b/tests/sshserver.py @@ -65,7 +65,7 @@ class Server(paramiko.ServerInterface): def check_auth_password(self, username, password): print('Auth attempt with username: {!r} & password: {!r}'.format(username, password)) # noqa - if (username in ['robey', 'bar']) and (password == 'foo'): + if (username in ['robey', 'bar', 'foo']) and (password == 'foo'): return paramiko.AUTH_SUCCESSFUL return paramiko.AUTH_FAILED @@ -150,6 +150,17 @@ def run_ssh_server(port=2200, running=True): if username == 'bar': msg = chan.recv(1024) chan.send(msg) + elif username == 'foo': + lst = [] + while True: + msg = chan.recv(32 * 1024) + lst.append(msg) + if msg.endswith(b'\r\n\r\n'): + break + data = b''.join(lst) + while data: + s = chan.send(data) + data = data[s:] chan.close() t.close() diff --git a/tests/test_app.py b/tests/test_app.py @@ -487,4 +487,32 @@ class TestAppInDebug(OtherTestBase): class TestAppMiscell(OtherTestBase): - debug = False + @tornado.testing.gen_test + def test_app_for_sending_message_with_large_size(self): + url = self.get_url('/') + client = self.get_http_client() + body = urlencode(dict(self.body, username='foo')) + response = yield client.fetch(url, method='POST', body=body, + headers=self.headers) + data = json.loads(to_str(response.body)) + self.assertIsNone(data['status']) + self.assertIsNotNone(data['id']) + self.assertIsNotNone(data['encoding']) + + url = url.replace('http', 'ws') + ws_url = url + 'ws?id=' + data['id'] + ws = yield tornado.websocket.websocket_connect(ws_url) + msg = yield ws.read_message() + self.assertEqual(to_str(msg, data['encoding']), banner) + + send = 'h' * (64 * 1024) + '\r\n\r\n' + yield ws.write_message(json.dumps({'data': send})) + lst = [] + while True: + msg = yield ws.read_message() + lst.append(msg) + if msg.endswith(b'\r\n\r\n'): + break + recv = b''.join(lst).decode(data['encoding']) + self.assertEqual(send, recv) + ws.close() diff --git a/webssh/worker.py b/webssh/worker.py @@ -6,7 +6,7 @@ from tornado.iostream import _ERRNO_CONNRESET from tornado.util import errno_from_exception -BUF_SIZE = 1024 +BUF_SIZE = 32 * 1024 workers = {} @@ -46,6 +46,8 @@ class Worker(object): if self.mode != mode: self.loop.update_handler(self.fd, mode) self.mode = mode + if mode == IOLoop.WRITE: + self.loop.call_later(0.1, self, self.fd, IOLoop.WRITE) def on_read(self): logging.debug('worker {} on read'.format(self.id))