diff --git a/lib/route.js b/lib/route.js index a1e840de5..0e6a70dcd 100755 --- a/lib/route.js +++ b/lib/route.js @@ -83,11 +83,6 @@ exports = module.exports = internals.Route = class { const settings = internals.config([core.settings.routes, handlerDefaults, realm.settings, rulesConfig, config]); this.settings = Config.apply('routeConfig', settings, method, path); - // Validate timeouts - - const socketTimeout = this.settings.timeout.socket === undefined ? 2 * 60 * 1000 : this.settings.timeout.socket; - this._assert(!this.settings.timeout.server || !socketTimeout || this.settings.timeout.server < socketTimeout, 'Server timeout must be shorter than socket timeout'); - this._assert(!this.settings.payload.timeout || !socketTimeout || this.settings.payload.timeout < socketTimeout, 'Payload timeout must be shorter than socket timeout'); // Route members diff --git a/test/route.js b/test/route.js index 02ad10504..f47b09dbd 100755 --- a/test/route.js +++ b/test/route.js @@ -326,6 +326,22 @@ describe('Route', () => { expect(called).to.be.false(); }); + it('throws error when the default routes payload validation is set without payload parsing', () => { + + expect(() => { + + Hapi.server({ routes: { validate: { payload: {}, validator: Joi }, payload: { parse: false } } }); + }).to.throw('Route payload must be set to \'parse\' when payload validation enabled'); + }); + + it('throws error when the default routes state validation is set without state parsing', () => { + + expect(() => { + + Hapi.server({ routes: { validate: { state: {}, validator: Joi }, state: { parse: false } } }); + }).to.throw('Route state must be set to \'parse\' when state validation enabled'); + }); + it('ignores default validation on GET', async () => { const server = Hapi.server({ routes: { validate: { payload: { a: Joi.required() }, validator: Joi } } }); @@ -450,20 +466,36 @@ describe('Route', () => { expect(res.payload).to.contain('hapi'); }); - it('throws when server timeout is more then socket timeout', () => { + it('allows payload timeout more then socket timeout', () => { + + expect(() => { + + Hapi.server({ routes: { payload: { timeout: 60000 }, timeout: { socket: 12000 } } }); + }).to.not.throw(); + }); + + it('allows payload timeout more then socket timeout (node default)', () => { + + expect(() => { + + Hapi.server({ routes: { payload: { timeout: 6000000 } } }); + }).to.not.throw(); + }); + + it('allows server timeout more then socket timeout', () => { expect(() => { Hapi.server({ routes: { timeout: { server: 60000, socket: 12000 } } }); - }).to.throw('Server timeout must be shorter than socket timeout'); + }).to.not.throw(); }); - it('throws when server timeout is more then socket timeout (node default)', () => { + it('allows server timeout more then socket timeout (node default)', () => { expect(() => { Hapi.server({ routes: { timeout: { server: 6000000 } } }); - }).to.throw('Server timeout must be shorter than socket timeout'); + }).to.not.throw(); }); it('ignores large server timeout when socket timeout disabled', () => {