mirror of
https://github.com/Unleash/unleash.git
synced 2024-12-28 00:06:53 +01:00
added server side validation of feature name
This commit is contained in:
parent
ada95e4070
commit
f38a07325d
5
.gitignore
vendored
5
.gitignore
vendored
@ -35,4 +35,7 @@ public/js/bundle.js
|
|||||||
# liquibase stuff
|
# liquibase stuff
|
||||||
/sql
|
/sql
|
||||||
unleash-db.jar
|
unleash-db.jar
|
||||||
unleash-server.tar.gz
|
unleash-server.tar.gz
|
||||||
|
|
||||||
|
# idea stuff:
|
||||||
|
*.iml
|
||||||
|
@ -22,8 +22,17 @@ module.exports = function (app) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
app.post('/features', function (req, res) {
|
app.post('/features', function (req, res) {
|
||||||
var newFeature = req.body,
|
req.checkBody('name', 'Name is required').notEmpty();
|
||||||
createdBy = req.connection.remoteAddress;
|
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() {
|
var handleFeatureExist = function() {
|
||||||
res.status(403).end();
|
res.status(403).end();
|
||||||
@ -32,7 +41,7 @@ module.exports = function (app) {
|
|||||||
var handleCreateFeature = function () {
|
var handleCreateFeature = function () {
|
||||||
eventStore.create({
|
eventStore.create({
|
||||||
type: eventType.featureCreated,
|
type: eventType.featureCreated,
|
||||||
createdBy: createdBy,
|
createdBy: req.connection.remoteAddress,
|
||||||
data: newFeature
|
data: newFeature
|
||||||
}).then(function () {
|
}).then(function () {
|
||||||
res.status(201).end();
|
res.status(201).end();
|
||||||
|
@ -39,6 +39,14 @@ describe('The api', function () {
|
|||||||
.expect(201, done);
|
.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) {
|
it('can not change status of feature toggle that dose not exsist', function (done) {
|
||||||
request
|
request
|
||||||
.patch('/features/shouldNotExsist')
|
.patch('/features/shouldNotExsist')
|
||||||
|
Loading…
Reference in New Issue
Block a user