Skip to content

Commit

Permalink
test: test proxying exact bytes of POST bodies
Browse files Browse the repository at this point in the history
  • Loading branch information
gjvis committed Sep 21, 2016
1 parent 16ab1b6 commit 0790c23
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
17 changes: 16 additions & 1 deletion test/functional/client-server.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`;
Expand All @@ -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) => {
Expand Down
17 changes: 16 additions & 1 deletion test/functional/server-client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`;
Expand All @@ -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) => {
Expand Down

0 comments on commit 0790c23

Please sign in to comment.