Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
maxConnectionsPerUser: Joi.number().integer().min(1).allow(false).when('index', { is: true, otherwise: Joi.valid(false) }),
minAuthVerifyInterval: Joi.number().integer().allow(false).when('...heartbeat', {
is: false,
then: Joi.number().min(1),
otherwise: Joi.number().min(Joi.ref('...heartbeat.interval'))
})
})
.allow(false)
.required(),
headers: Joi.array().items(Joi.string().lowercase()).min(1).allow('*', null),
payload: {
maxChunkChars: Joi.number().integer().min(1).allow(false)
},
heartbeat: Joi.object({
interval: Joi.number().integer().min(1).required(),
timeout: Joi.number().integer().min(1).less(Joi.ref('interval')).required()
})
.allow(false),
maxConnections: Joi.number().integer().min(1).allow(false),
origin: Joi.array().items(Joi.string()).single().min(1)
});
exports.plugin = {
name: 'nes', // Override package name
pkg: require('../package.json'),
requirements: {
hapi: '>=18.0.0'
},
register: function (server, options) {
const settings = Hoek.applyToDefaults(internals.defaults, options);
it('validates valid input using app context', async () => {
const server = Hapi.server();
server.route({
method: 'GET',
path: '/',
handler: () => 'ok',
options: {
validate: {
query: {
x: Joi.ref('$app.route.some')
}
},
app: {
some: 'b'
}
}
});
const res1 = await server.inject('/?x=a');
expect(res1.statusCode).to.equal(400);
const res2 = await server.inject('/?x=b');
expect(res2.statusCode).to.equal(200);
});
query: Joi.object({
param1: Joi.ref('a.b'),
param2: Joi.ref('$x')
})
}
}
},
{
method: 'GET',
path: '/withassert',
options: {
handler: () => 'ok',
validate: {
query: Joi.object({
param1: Joi.object().assert('d.e', Joi.ref('a.c'), 'equal to a.c'),
param2: Joi.object().assert('$x', Joi.ref('b.e'), 'equal to b.e')
})
}
}
},
{
method: 'GET',
path: '/withproperties',
vhost: 'john.doe',
options: {
handler: () => 'ok',
cors: {
maxAge: 12345
},
jsonp: 'callback'
}
},
validate: {
query: Joi.object({
param1: Joi.ref('a.b'),
param2: Joi.ref('$x')
})
}
}
},
{
method: 'GET',
path: '/withassert',
options: {
handler: () => 'ok',
validate: {
query: Joi.object({
param1: Joi.object().assert('d.e', Joi.ref('a.c'), 'equal to a.c'),
param2: Joi.object().assert('$x', Joi.ref('b.e'), 'equal to b.e')
})
}
}
},
{
method: 'GET',
path: '/withproperties',
vhost: 'john.doe',
options: {
handler: () => 'ok',
cors: {
maxAge: 12345
},
jsonp: 'callback'
}
}
};
};
server.auth.scheme('none', scheme);
server.auth.strategy('default', 'none');
server.auth.default('default');
server.route({
method: 'GET',
path: '/{user?}',
handler: () => 'ok',
options: {
validate: {
query: {
me: Joi.boolean().truthy('true').when('$auth.credentials.name', { is: Joi.ref('$params.user'), otherwise: Joi.forbidden() })
}
}
}
});
const res1 = await server.inject('/?me=true');
expect(res1.statusCode).to.equal(400);
const res2 = await server.inject('/');
expect(res2.statusCode).to.equal(200);
const res3 = await server.inject('/steve?me=true');
expect(res3.statusCode).to.equal(400);
const res4 = await server.inject('/john?me=true');
expect(res4.statusCode).to.equal(200);
export const validUser = {
username: Joi.string()
.alphanum()
.min(2)
.max(30)
.required(),
email: Joi.string()
.email()
.required(),
password: validPassword.required()
};
export const validPasswordUpdate = Joi.object().keys({
oldPassword: Joi.string().required(),
newPassword: validPassword.required(),
confirmPassword: Joi.any().valid(Joi.ref("newPassword"))
});
export const validAuthenticatedUser = {
user: Joi.alternatives()
.try(
Joi.string()
.alphanum()
.min(2)
.max(30),
Joi.string().email()
)
.required(),
password: Joi.alternatives()
.try(validPassword, Joi.string())
.required()
};
const vsCharRegEx = /^[\x20-\x7E]*$/;
const optionsSchema = Joi
.object()
.keys({
client: Joi.object().keys({
id: Joi.string().regex(vsCharRegEx).allow(''),
secret: Joi.string().regex(vsCharRegEx).allow(''),
secretParamName: Joi.string().default('client_secret'),
idParamName: Joi.string().default('client_id'),
}).required(),
auth: Joi.object().keys({
tokenHost: Joi.string().required().uri({ scheme: ['http', 'https'] }),
tokenPath: Joi.string().default('/oauth/token'),
revokePath: Joi.string().default('/oauth/revoke'),
authorizeHost: Joi.string().default(Joi.ref('tokenHost')),
authorizePath: Joi.string().default('/oauth/authorize'),
}).required(),
http: Joi.object().unknown(true),
options: Joi.object().keys({
bodyFormat: Joi.any().only('form', 'json').default('form'),
authorizationMethod: Joi.any().only('header', 'body').default('header'),
}).default(),
});
module.exports = {
/**
* Creates a new simple-oauth2 client with the provided configuration
* @param {Object} opts Module options as defined in schema
* @returns {Object} The simple-oauth2 client
*/
path: Joi.string().allow(null),
domain: Joi.string().allow(null),
ttl: Joi.number().allow(null),
iron: Joi.object(),
password: Joi.alternatives([
Joi.string(),
Joi.binary(),
Joi.object()
]),
index: Joi.boolean(),
timeout: Joi.number().integer().min(1).allow(false),
maxConnectionsPerUser: Joi.number().integer().min(1).allow(false).when('index', { is: true, otherwise: Joi.valid(false) }),
minAuthVerifyInterval: Joi.number().integer().allow(false).when('...heartbeat', {
is: false,
then: Joi.number().min(1),
otherwise: Joi.number().min(Joi.ref('...heartbeat.interval'))
})
})
.allow(false)
.required(),
headers: Joi.array().items(Joi.string().lowercase()).min(1).allow('*', null),
payload: {
maxChunkChars: Joi.number().integer().min(1).allow(false)
},
heartbeat: Joi.object({
interval: Joi.number().integer().min(1).required(),
timeout: Joi.number().integer().min(1).less(Joi.ref('interval')).required()
})
.allow(false),
maxConnections: Joi.number().integer().min(1).allow(false),
origin: Joi.array().items(Joi.string()).single().min(1)
});
function normalizeConfig(config: Object) {
const schema = Joi.object().keys({
routingType: Joi.string().valid('browser', 'hash').default('browser'),
routes: Joi.string().default('src/**/*.route.js'),
'entry-react': Joi.string().allow(null).default(null),
'render-html': Joi.string().allow(null).default(null),
'pre-init': Joi.string().allow(null).default(null),
'service-worker': Joi.string().allow(null).default(null),
directories: Joi.object().keys({
logs: Joi.string().default(Joi.ref('build')),
build: Joi.string().default('./.build'),
resources: Joi.string().default('./src/public'),
translations: Joi.string().default('./src/translations'),
}).default(),
hooks: Joi.object({
client: Joi.string().allow(null).default(null),
server: Joi.string().allow(null).default(null),
}).default(),
plugins: Joi.object().unknown(true).default(),
}).default();
const normalizedConfig = Joi.attempt(config, schema, `${frameworkConfigFile} is invalid`);
const fileEntries = [
'entry-react',