Skip to content

Commit

Permalink
Proxy handler config bug. Closes #1517
Browse files Browse the repository at this point in the history
  • Loading branch information
Eran Hammer committed Mar 24, 2014
1 parent 5f30d64 commit 8145ee9
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var internals = {};

exports.handler = function (route, options) {

Utils.assert(!route.payload || ((route.payload.output === 'data' || route.payload.output === 'stream') && !route.payload.parse), 'Cannot proxy if payload is parsed or if output is not stream or data');
Utils.assert(!route.settings.payload || ((route.settings.payload.output === 'data' || route.settings.payload.output === 'stream') && !route.settings.payload.parse), 'Cannot proxy if payload is parsed or if output is not stream or data');
var settings = Utils.applyToDefaults(Defaults.proxy, options);
settings.mapUri = options.mapUri || internals.mapUri(options.protocol, options.host, options.port, options.uri);

Expand Down
23 changes: 23 additions & 0 deletions test/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,29 @@ describe('Auth', function () {
});
});

it('errors on missing scope using arrays', function (done) {

var server = new Hapi.Server();
server.auth.scheme('custom', internals.implementation);
server.auth.strategy('default', 'custom', true, { users: { steve: { scope: ['a', 'b'] } } });
server.route({
method: 'GET',
path: '/',
config: {
handler: function (request, reply) { reply(request.auth.credentials.user); },
auth: {
scope: ['c', 'd']
}
}
});

server.inject({ url: '/', headers: { authorization: 'Custom steve' } }, function (res) {

expect(res.statusCode).to.equal(403);
done();
});
});

it('matches tos', function (done) {

var server = new Hapi.Server();
Expand Down
21 changes: 21 additions & 0 deletions test/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,27 @@ describe('Proxy', function () {
});
});

it('throws when used with explicit route payload config other than data or steam', function (done) {

var server = new Hapi.Server();
expect(function () {

server.route({
method: 'POST',
path: '/',
config: {
handler: {
proxy: { host: 'example.com' }
},
payload: {
output: 'file'
}
}
});
}).to.throw('Cannot proxy if payload is parsed or if output is not stream or data');
done();
});

it('overrides maxSockets', function (done) {

var server = new Hapi.Server({ maxSockets: 1 });
Expand Down

0 comments on commit 8145ee9

Please sign in to comment.