1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-22 19:07:54 +01:00

added server side validation of feature name

This commit is contained in:
ivaosthu 2014-11-01 11:47:21 +01:00 committed by Ivar Conradi Østhus
parent ee034c22d6
commit b2d4cbf5de
3 changed files with 24 additions and 4 deletions

5
.gitignore vendored
View File

@ -35,4 +35,7 @@ public/js/bundle.js
# liquibase stuff
/sql
unleash-db.jar
unleash-server.tar.gz
unleash-server.tar.gz
# idea stuff:
*.iml

View File

@ -22,8 +22,17 @@ module.exports = function (app) {
});
app.post('/features', function (req, res) {
var newFeature = req.body,
createdBy = req.connection.remoteAddress;
req.checkBody('name', 'Name is required').notEmpty();
req.checkBody('name', 'Name must match format ^[a-zA-Z\\.\\-]+$').matches(/^[a-zA-Z\\.\\-]+$/i);
var errors = req.validationErrors();
if (errors) {
res.json(400, errors);
return;
}
var newFeature = req.body;
var handleFeatureExist = function() {
res.status(403).end();
@ -32,7 +41,7 @@ module.exports = function (app) {
var handleCreateFeature = function () {
eventStore.create({
type: eventType.featureCreated,
createdBy: createdBy,
createdBy: req.connection.remoteAddress,
data: newFeature
}).then(function () {
res.status(201).end();

View File

@ -39,6 +39,14 @@ describe('The api', function () {
.expect(201, done);
});
it('require new feature toggle to have a name', function (done) {
request
.post('/features')
.send({name: ''})
.set('Content-Type', 'application/json')
.expect(400, done);
});
it('can not change status of feature toggle that dose not exsist', function (done) {
request
.patch('/features/shouldNotExsist')