diff --git a/lib/routes/feature.js b/lib/routes/feature.js index 7bc5778908..52bf9a91af 100644 --- a/lib/routes/feature.js +++ b/lib/routes/feature.js @@ -1,5 +1,6 @@ 'use strict'; +const joi = require('joi'); const logger = require('../logger'); const { FEATURE_CREATED, FEATURE_UPDATED, FEATURE_ARCHIVED } = require('../event-type'); const NameExistsError = require('../error/name-exists-error'); @@ -148,11 +149,29 @@ module.exports = function (app, config) { return Promise.resolve(req); } - function validateStrategy (featureToggle) { - if (!featureToggle.strategies || featureToggle.strategies.length === 0) { - return Promise.reject(new ValidationError('You must define at least one strategy')); - } - return Promise.resolve(featureToggle); + const strategiesSchema = joi.object().keys({ + name: joi.string() + .regex(/^[a-zA-Z0-9\\.\\-]{3,100}$/) + .required(), + parameters: joi.object(), + }); + + function validateStrategy (featureToggle) { + return new Promise((resolve, reject) => { + if (!featureToggle.strategies || featureToggle.strategies.length === 0) { + return reject(new ValidationError('You must define at least one strategy')); + } + + featureToggle.strategies = featureToggle.strategies.map((strategyConfig) => { + const result = joi.validate(strategyConfig, strategiesSchema); + if (result.error) { + throw result.error; + } + return result.value; + }); + + return resolve(featureToggle); + }); } };