Skip to content

Commit

Permalink
Keep the original payload at the handler level
Browse files Browse the repository at this point in the history
  • Loading branch information
Rui Quelhas committed Jan 31, 2016
1 parent 77810be commit 8670c13
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
13 changes: 10 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const Stream = require('stream');

const Henning = require('henning');
const Recourier = require('recourier');
const Subtext = require('subtext');

const internals = {};
Expand Down Expand Up @@ -36,14 +37,20 @@ internals.onPostAuth = function (options) {

exports.register = function (server, options, next) {

const plugin = {
const plugins = [{
register: Henning,
options: options
};
}, {
register: Recourier,
options: {
namespace: 'burton'
}
}];

server.register(plugin, (err) => {
server.register(plugins, (err) => {

server.ext('onPostAuth', internals.onPostAuth(options));

next(err);
});
};
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"homepage": "https://github.com/ruiquelhas/burton#readme",
"devDependencies": {
"code": "2.x.x",
"content": "3.x.x",
"coveralls": "2.x.x",
"form-data": "0.x.x",
"hapi": "12.x.x",
Expand All @@ -37,6 +38,7 @@
},
"dependencies": {
"henning": "1.x.x",
"recourier": "ruiquelhas/recourier",
"subtext": "4.x.x"
},
"engines": {
Expand Down
25 changes: 24 additions & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const Os = require('os');
const Path = require('path');

const Code = require('code');
const Content = require('content');
const FormData = require('form-data');
const Hapi = require('hapi');
const Lab = require('lab');
Expand Down Expand Up @@ -32,7 +33,7 @@ lab.experiment('burton', () => {

const main = {
config: {
handler: (request, reply) => reply(),
handler: (request, reply) => reply(request.payload),
payload: {
output: 'stream',
parse: false
Expand Down Expand Up @@ -109,4 +110,26 @@ lab.experiment('burton', () => {
});
});
});

lab.test('should return control to the server if all files the in payload are allowed', (done) => {

const png = Path.join(Os.tmpdir(), 'foo.png');
Fs.createWriteStream(png).end(new Buffer([0x89, 0x50]));

const form = new FormData();
form.append('file1', Fs.createReadStream(png));
form.append('file2', Fs.createReadStream(png));
form.append('foo', 'bar');

StreamToPromise(form).then((payload) => {

server.inject({ headers: form.getHeaders(), method: 'POST', payload: payload, url: '/main' }, (response) => {

Code.expect(response.statusCode).to.equal(200);
Code.expect(response.headers['content-validation']).to.equal('success');
Code.expect(Content.type(response.headers['content-type']).mime).to.equal('multipart/form-data');
done();
});
});
});
});

0 comments on commit 8670c13

Please sign in to comment.