From 64fa52078913c6d4fe95673f182aac4924961e8b Mon Sep 17 00:00:00 2001 From: glortho Date: Wed, 28 Oct 2015 15:52:37 -0400 Subject: [PATCH] Add tests for testing forwarding of continuation frames This adds two tests that send payloads below and at the threshold for continuation frames. Using node 0.12.7 both tests pass. Using node 4.1.2 the test below the threshold passes but the other fails. --- test/lib-http-proxy-test.js | 65 ++++++++++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) diff --git a/test/lib-http-proxy-test.js b/test/lib-http-proxy-test.js index 49e8a86..6380b8b 100644 --- a/test/lib-http-proxy-test.js +++ b/test/lib-http-proxy-test.js @@ -487,6 +487,69 @@ describe('lib/http-proxy.js', function() { }); }); }); + + it('should forward frames with single frame payload (including on node 4.x)', function (done) { + var payload = Array(65529).join('0'); + var ports = { source: gen.port, proxy: gen.port }; + var proxy = httpProxy.createProxyServer({ + target: 'ws://127.0.0.1:' + ports.source, + ws: true + }), + proxyServer = proxy.listen(ports.proxy), + destiny = new ws.Server({ port: ports.source }, function () { + var client = new ws('ws://127.0.0.1:' + ports.proxy); + + client.on('open', function () { + client.send(payload); + }); + + client.on('message', function (msg) { + expect(msg).to.be('Hello over websockets'); + client.close(); + proxyServer.close(); + destiny.close(); + done(); + }); + }); + + destiny.on('connection', function (socket) { + socket.on('message', function (msg) { + expect(msg).to.be(payload); + socket.send('Hello over websockets'); + }); + }); + }); - }) + it('should forward continuation frames with big payload (including on node 4.x)', function (done) { + var payload = Array(65530).join('0'); + var ports = { source: gen.port, proxy: gen.port }; + var proxy = httpProxy.createProxyServer({ + target: 'ws://127.0.0.1:' + ports.source, + ws: true + }), + proxyServer = proxy.listen(ports.proxy), + destiny = new ws.Server({ port: ports.source }, function () { + var client = new ws('ws://127.0.0.1:' + ports.proxy); + + client.on('open', function () { + client.send(payload); + }); + + client.on('message', function (msg) { + expect(msg).to.be('Hello over websockets'); + client.close(); + proxyServer.close(); + destiny.close(); + done(); + }); + }); + + destiny.on('connection', function (socket) { + socket.on('message', function (msg) { + expect(msg).to.be(payload); + socket.send('Hello over websockets'); + }); + }); + }); + }); });