Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ node_modules

coverage/
coverage.lcov
.nyc_output/
.nyc_output/
tmp/
161 changes: 0 additions & 161 deletions test/bodyEncoding.js

This file was deleted.

4 changes: 2 additions & 2 deletions test/catchingErrors.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ describe('when server responds with an error', function () {
app = express();
});

afterEach(function () {
serverReference.close();
afterEach(async function () {
await serverReference.close();
});

var STATUS_CODES = [
Expand Down
51 changes: 28 additions & 23 deletions test/cookies.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,44 @@ var proxyRouteFn = [{
method: 'get',
path: '/cookieTest',
fn: function (req, res) {
Object.keys(req.cookies).forEach(function (key) {
// This stub proxy server method simply copies the cookies from the inbound
// request to the outbound response. This lets us check the proxy reponse
// for the cookies on the request.
Object.keys(req.cookies).forEach(key => {
res.cookie(key, req.cookies[key]);
});
res.sendStatus(200);
}
}];

describe('proxies cookie', function () {
this.timeout(TIMEOUT.STANDARD);
describe("cookies", () => {
describe('when cookies are sent on the user request', function () {
this.timeout(TIMEOUT.STANDARD);

var app;
var proxyServer;
var app;
var proxyServer;

beforeEach(function () {
proxyServer = proxyTarget(12346, 100, proxyRouteFn);
app = express();
app.use(proxy('localhost:12346'));
});
beforeEach(function () {
proxyServer = proxyTarget(12346, 100, proxyRouteFn);
app = express();
app.use(proxy('localhost:12346'));
});

afterEach(function () {
proxyServer.close();
});
afterEach(function () {
proxyServer.close();
});

it('set cookie', function (done) {
request(app)
.get('/cookieTest')
.set('Cookie', 'myApp-token=12345667')
.end(function (err, res) {
var cookiesMatch = res.headers['set-cookie'].filter(function (item) {
return item.match(/myApp-token=12345667/);
it('they are copied to the proxy request', function (done) {
request(app)
.get('/cookieTest')
.set('Cookie', 'myApp-token=12345667')
.end(function (err, res) {
var cookiesMatch = res.headers['set-cookie'].filter(function (item) {
return item.match(/myApp-token=12345667/);
});
assert(cookiesMatch);
done(err);
});
assert(cookiesMatch);
done(err);
});
});
});
});
6 changes: 3 additions & 3 deletions test/proxyReqPathResolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('resolveProxyReqPath', function () {

this.timeout(TIMEOUT.STANDARD);

before(function () {
beforeEach(function () {
var handlers = [{
method: 'get',
path: '/working',
Expand All @@ -27,8 +27,8 @@ describe('resolveProxyReqPath', function () {
server = proxyTarget(12345, 100, handlers);
});

after(function () {
server.close();
afterEach(async () => {
await server.close();
});

aliases.forEach(function (alias) {
Expand Down
86 changes: 86 additions & 0 deletions test/rawBodyLimit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
'use strict';
var getRawBody = require('raw-body');
var assert = require('assert');
var express = require('express');
var request = require('supertest');
var fs = require('fs');
var os = require('os');
var proxy = require('../');
var startProxyTarget = require('./support/proxyTarget');
var TIMEOUT = require('./constants');

const PORT_NUMBER =8109;

const pngHex = '89504e470d0a1a0a0' +
'000000d4948445200' +
'00000100000001080' +
'60000001f15c48900' +
'00000a49444154789' +
'c6300010000050001' +
'0d0a2db4000000004' +
'9454e44ae426082';
const pngData = Buffer.from(pngHex, 'hex');

const processStuff = (req, res, next) => {
getRawBody(req, {
length: req.headers['content-length'],
}).then((rawBody) => {
res.json({rawBody, headers: req.headers});
})
}

describe('limit', function () {
var server;

beforeEach(function () {
server = startProxyTarget(8109);
});

afterEach(async function () {
await server.close();
});

it('should not fail on large limit', function (done) {
var filename = os.tmpdir() + '/express-http-proxy-test-' + (new Date()).getTime() + '-png-transparent.png';
var app = express();
app.use(proxy('localhost:8109', {
parseReqBody: false,
limit: '20gb',
}));
fs.writeFile(filename, pngData, function (err) {
if (err) { throw err; }
request(app)
.post('/post')
.attach('image', filename)
.end(function (err) {
fs.unlinkSync(filename);
assert(err === null);
// This test is both broken and I think unnecessary.
// Its broken because http.bin no longer supports /post, but this test assertion is based on the old
// httpbin behavior.
// The assertion in the decorateRequest above verifies the test title.
//var response = new Buffer(res.body.attachment.data).toString('base64');
//assert(response.indexOf(pngData.toString('base64')) >= 0, 'response should include original raw data');

done(err);
});
});
});
it('should fail with an error when exceeding limit', function (done) {
var app = express();
app.use(proxy('localhost:8109', {
limit: 1,
}));
// silence jshint warning about unused vars - express error handler *needs* 4 args
app.use(function (err, req, res, next) { // eslint-disable-line no-unused-vars
res.json(err);
});
request(app)
.post('/post')
.send({ some: 'json' })
.end(function (err, response) {
assert(response.body.message === 'request entity too large');
done();
});
});
});
Loading