From c7795f40a4e55d697fe4971bf0e9ff0780e159a1 Mon Sep 17 00:00:00 2001 From: John Brett Date: Sun, 13 Dec 2015 01:42:44 +0000 Subject: [PATCH 1/2] Add validation check for stripUnknown route response option --- lib/schema.js | 3 ++- test/validation.js | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/lib/schema.js b/lib/schema.js index 376de4950..dfc262d4c 100755 --- a/lib/schema.js +++ b/lib/schema.js @@ -129,7 +129,8 @@ internals.routeBase = Joi.object({ modify: Joi.boolean(), options: Joi.object() }) - .without('modify', 'sample'), + .without('modify', 'sample') + .assert('options.stripUnknown', Joi.ref('modify'), 'meet requirement of having peer modify set to true'), security: Joi.object({ hsts: [ Joi.object({ diff --git a/test/validation.js b/test/validation.js index 94bd9acdf..0aa5adff1 100755 --- a/test/validation.js +++ b/test/validation.js @@ -1585,6 +1585,34 @@ describe('validation', () => { done(); }); }); + + it('throws on options.stripUnknown without modify', (done) => { + + const server = new Hapi.Server(); + server.connection(); + + expect(() => { + + server.route({ + method: 'GET', + path: '/', + handler: function (request, reply) { + + return reply('ok'); + }, + config: { + response: { + schema: Joi.string(), + options: { + stripUnknown: true + } + } + } + }); + }).to.throw(/"options.stripUnknown" failed to meet requirement of having peer modify set to true/); + + done(); + }); }); From ba86849ed7d663d0ab03b1f77db698ddfea66067 Mon Sep 17 00:00:00 2001 From: John Brett Date: Sun, 13 Dec 2015 13:33:34 +0000 Subject: [PATCH 2/2] remove trailing spaces --- test/validation.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/validation.js b/test/validation.js index 0aa5adff1..80067bebe 100755 --- a/test/validation.js +++ b/test/validation.js @@ -1610,7 +1610,7 @@ describe('validation', () => { } }); }).to.throw(/"options.stripUnknown" failed to meet requirement of having peer modify set to true/); - + done(); }); });