Skip to content

Commit

Permalink
Update deps. For #4012
Browse files Browse the repository at this point in the history
  • Loading branch information
hueniverse committed Jan 9, 2020
1 parent 64c4339 commit 356f748
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 22 deletions.
17 changes: 7 additions & 10 deletions lib/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ exports = module.exports = internals.Route = class {
const method = route.method.toLowerCase();
Hoek.assert(method !== 'head', 'Cannot set HEAD route:', route.path);

const path = (realm.modifiers.route.prefix ? realm.modifiers.route.prefix + (route.path !== '/' ? route.path : '') : route.path);
const path = realm.modifiers.route.prefix ? realm.modifiers.route.prefix + (route.path !== '/' ? route.path : '') : route.path;
Hoek.assert(path === '/' || path[path.length - 1] !== '/' || !core.settings.router.stripTrailingSlash, 'Path cannot end with a trailing slash when configured to strip:', route.method, route.path);

const vhost = (realm.modifiers.route.vhost || route.vhost);
const vhost = realm.modifiers.route.vhost || route.vhost;

// Set identifying members (assert)

Expand All @@ -64,7 +64,7 @@ exports = module.exports = internals.Route = class {
// Rules

this._assert(!route.rules || !config.rules, 'Route rules can only appear once'); // XOR
const rules = (route.rules || config.rules);
const rules = route.rules || config.rules;
const rulesConfig = internals.rules(rules, { method, path, vhost }, server);
delete config.rules;

Expand All @@ -85,7 +85,7 @@ exports = module.exports = internals.Route = class {

// Validate timeouts

const socketTimeout = (this.settings.timeout.socket === undefined ? 2 * 60 * 1000 : this.settings.timeout.socket);
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');

Expand Down Expand Up @@ -136,7 +136,7 @@ exports = module.exports = internals.Route = class {

// Authentication configuration

this.settings.auth = (this._special ? false : this._core.auth._setupRoute(this.settings.auth, path));
this.settings.auth = this._special ? false : this._core.auth._setupRoute(this.settings.auth, path);

// Cache

Expand Down Expand Up @@ -227,7 +227,7 @@ exports = module.exports = internals.Route = class {
}

if (this._special) {
this._postCycle = (this._extensions.onPreResponse.nodes ? [this._extensions.onPreResponse] : []);
this._postCycle = this._extensions.onPreResponse.nodes ? [this._extensions.onPreResponse] : [];
this._buildMarshalCycle();
return;
}
Expand Down Expand Up @@ -525,10 +525,7 @@ internals.rules = function (rules, info, server) {
let realm = server.realm;
while (realm) {
if (realm._rules) {
const source = !realm._rules.settings.validate
? rules
: Joi.attempt(rules, realm._rules.settings.validate.schema, realm._rules.settings.validate.options);

const source = !realm._rules.settings.validate ? rules : Joi.attempt(rules, realm._rules.settings.validate.schema, realm._rules.settings.validate.options);
const config = realm._rules.processor(source, info);
if (config) {
configs.unshift(config);
Expand Down
20 changes: 8 additions & 12 deletions test/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -1049,30 +1049,26 @@ describe('validation', () => {

it('validates response with context', async () => {

const schema = Joi.object({
some: Joi.string(),
more: Joi.string()
})
.when('$query.user', { not: 'admin', then: Joi.object({ more: Joi.forbidden() }) });

const server = Hapi.server({ debug: false });
server.validator(Joi);
server.route({
method: 'GET',
path: '/',
options: {
response: {
schema
schema: Joi.object({
some: Joi.string(),
more: Joi.string()
})
.when('$query.user', { not: 'admin', then: Joi.object({ more: Joi.forbidden() }) })
}
},
handler: () => ({ some: 'thing', more: 'stuff' })
});

schema.validate({ some: 'thing', more: 'stuff' }, { context: { query: { user: 'test' } } });

//const res1 = await server.inject('/?user=admin');
//expect(res1.statusCode).to.equal(200);
//expect(res1.payload).to.equal('{"some":"thing","more":"stuff"}');
const res1 = await server.inject('/?user=admin');
expect(res1.statusCode).to.equal(200);
expect(res1.payload).to.equal('{"some":"thing","more":"stuff"}');

const res2 = await server.inject('/?user=test');
expect(res2.statusCode).to.equal(500);
Expand Down

0 comments on commit 356f748

Please sign in to comment.