From 4f0b53267c96a789555fede723a5b0ccb646fe13 Mon Sep 17 00:00:00 2001 From: Damien Arrachequesne Date: Fri, 7 Apr 2017 08:33:16 +0200 Subject: [PATCH 1/2] add test for maxHttpBufferSize option with websocket --- README.md | 2 +- test/server.js | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f07e6d42a..fc33c4fc1 100644 --- a/README.md +++ b/README.md @@ -201,7 +201,7 @@ to a single process. packet (`25000`) - `upgradeTimeout` (`Number`): how many ms before an uncompleted transport upgrade is cancelled (`10000`) - `maxHttpBufferSize` (`Number`): how many bytes or characters a message - can be when polling, before closing the session (to avoid DoS). Default + can be, before closing the session (to avoid DoS). Default value is `10E7`. - `allowRequest` (`Function`): A function that receives a given handshake or upgrade request as its first parameter, and can decide whether to diff --git a/test/server.js b/test/server.js index 0b9d88569..4f81ced38 100644 --- a/test/server.js +++ b/test/server.js @@ -1153,6 +1153,22 @@ describe('server', function () { setTimeout(done, 1000); }); + it('should not be receiving data when getting a message longer than maxHttpBufferSize (websocket)', function (done) { + var opts = { maxHttpBufferSize: 5 }; + var engine = listen(opts, function (port) { + var socket = new eioc.Socket('ws://localhost:%d'.s(port), { transports: ['websocket'] }); + engine.on('connection', function (conn) { + conn.on('message', function (msg) { + done(new Error('Test invalidation (message is longer than allowed)')); + }); + }); + socket.on('open', function () { + socket.send('aasdasdakjhasdkjhasdkjhasdkjhasdkjhasdkjhasdkjha'); + }); + }); + setTimeout(done, 1000); + }); + it('should receive data when getting a message shorter than maxHttpBufferSize when polling', function (done) { var opts = { allowUpgrades: false, transports: ['polling'], maxHttpBufferSize: 5 }; var engine = listen(opts, function (port) { From 7f1d101bf08003bdea70033e487a2d61b4f26ca4 Mon Sep 17 00:00:00 2001 From: Damien Arrachequesne Date: Sat, 8 Apr 2017 08:25:26 +0200 Subject: [PATCH 2/2] update test --- test/server.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/test/server.js b/test/server.js index 4f81ced38..cef2b96b1 100644 --- a/test/server.js +++ b/test/server.js @@ -1143,14 +1143,16 @@ describe('server', function () { var socket = new eioc.Socket('ws://localhost:%d'.s(port)); engine.on('connection', function (conn) { conn.on('message', function (msg) { - console.log(msg); + done(new Error('Test invalidation (message is longer than allowed)')); }); }); socket.on('open', function () { socket.send('aasdasdakjhasdkjhasdkjhasdkjhasdkjhasdkjhasdkjha'); }); + socket.on('close', function () { + done(); + }); }); - setTimeout(done, 1000); }); it('should not be receiving data when getting a message longer than maxHttpBufferSize (websocket)', function (done) { @@ -1165,8 +1167,10 @@ describe('server', function () { socket.on('open', function () { socket.send('aasdasdakjhasdkjhasdkjhasdkjhasdkjhasdkjhasdkjha'); }); + socket.on('close', function () { + done(); + }); }); - setTimeout(done, 1000); }); it('should receive data when getting a message shorter than maxHttpBufferSize when polling', function (done) {