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:
parent
ada95e4070
commit
f38a07325d
5
.gitignore
vendored
5
.gitignore
vendored
@ -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
|
||||
|
@ -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();
|
||||
|
@ -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')
|
||||
|
Loading…
Reference in New Issue
Block a user