From 0790c23b87ab42fca5dd5189dff1ef06ae600683 Mon Sep 17 00:00:00 2001 From: Gareth Visagie Date: Wed, 21 Sep 2016 17:26:41 +0100 Subject: [PATCH] test: test proxying exact bytes of POST bodies --- test/functional/client-server.test.js | 17 ++++++++++++++++- test/functional/server-client.test.js | 17 ++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/test/functional/client-server.test.js b/test/functional/client-server.test.js index ec685a83b..9fbea760a 100644 --- a/test/functional/client-server.test.js +++ b/test/functional/client-server.test.js @@ -36,7 +36,7 @@ test('proxy requests originating from behind the broker client', t => { // wait for the client to successfully connect to the server and identify itself server.io.once('connection', socket => { socket.once('identify', () => { - t.plan(6); + t.plan(7); t.test('successfully broker POST', t => { const url = `http://localhost:${clientPort}/echo-body`; @@ -48,6 +48,21 @@ test('proxy requests originating from behind the broker client', t => { }); }); + t.test('successfully broker exact bytes of POST body', t => { + const url = `http://localhost:${clientPort}/echo-body`; + // stringify the JSON unusually to ensure an unusual exact body + const body = Buffer.from( + JSON.stringify({ some: { example: 'json' }}, null, 5) + ); + const headers = { 'Content-Type': 'application/json' }; + request({ url, method: 'post', headers, body }, (err, res) => { + const responseBody = Buffer.from(res.body); + t.equal(res.statusCode, 200, '200 statusCode'); + t.same(responseBody, body, 'body brokered exactly'); + t.end(); + }); + }); + t.test('successfully broker GET', t => { const url = `http://localhost:${clientPort}/echo-param/xyz`; request({ url, method: 'get' }, (err, res) => { diff --git a/test/functional/server-client.test.js b/test/functional/server-client.test.js index 251b4c5f1..2bfa981e9 100644 --- a/test/functional/server-client.test.js +++ b/test/functional/server-client.test.js @@ -35,7 +35,7 @@ test('proxy requests originating from behind the broker server', t => { // wait for the client to successfully connect to the server and identify itself server.io.on('connection', socket => { socket.on('identify', id => { - t.plan(8); + t.plan(9); t.test('successfully broker POST', t => { const url = `http://localhost:${serverPort}/broker/${id}/echo-body`; @@ -47,6 +47,21 @@ test('proxy requests originating from behind the broker server', t => { }); }); + t.test('successfully broker exact bytes of POST body', t => { + const url = `http://localhost:${serverPort}/broker/${id}/echo-body`; + // stringify the JSON unusually to ensure an unusual exact body + const body = Buffer.from( + JSON.stringify({ some: { example: 'json' }}, null, 5) + ); + const headers = { 'Content-Type': 'application/json' }; + request({ url, method: 'post', headers, body }, (err, res) => { + const responseBody = Buffer.from(res.body); + t.equal(res.statusCode, 200, '200 statusCode'); + t.same(responseBody, body, 'body brokered exactly'); + t.end(); + }); + }); + t.test('successfully broker GET', t => { const url = `http://localhost:${serverPort}/broker/${id}/echo-param/xyz`; request({ url, method: 'get' }, (err, res) => {