mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
Test 400 responds for invalid PUT payloads
This commit is contained in:
parent
526e8e7e74
commit
53d35573ee
3 changed files with 67 additions and 15 deletions
|
@ -99,7 +99,7 @@ export default function (server) {
|
|||
method: 'POST',
|
||||
handler: function (req, reply) {
|
||||
if (_.isEmpty(req.payload)) { return reply(Boom.badRequest('Payload required')); }
|
||||
const validation = Joi.validate(req.payload, indexPatternSchema);
|
||||
const validation = Joi.validate(req.payload, indexPatternSchema.post);
|
||||
if (validation.error) {
|
||||
return reply(Boom.badRequest(validation.error));
|
||||
}
|
||||
|
@ -173,6 +173,10 @@ export default function (server) {
|
|||
handler: function (req, reply) {
|
||||
if (_.isEmpty(req.payload)) { return reply(Boom.badRequest('Payload required')); }
|
||||
if (req.payload.title !== req.params.id) { return reply(Boom.badRequest('Updates to title not supported')); }
|
||||
const validation = Joi.validate(req.payload, indexPatternSchema.put);
|
||||
if (validation.error) {
|
||||
return reply(Boom.badRequest(validation.error));
|
||||
}
|
||||
|
||||
let client = server.plugins.elasticsearch.client;
|
||||
const indexPattern = _.cloneDeep(req.payload);
|
||||
|
|
|
@ -1,16 +1,31 @@
|
|||
var Joi = require('joi');
|
||||
|
||||
module.exports = Joi.object({
|
||||
title: Joi.string().required(),
|
||||
timeFieldName: Joi.string(),
|
||||
intervalName: Joi.string(),
|
||||
fields: Joi.array().items(Joi.object({
|
||||
name: Joi.string().required(),
|
||||
count: Joi.number().integer(),
|
||||
scripted: Joi.boolean(),
|
||||
mapping: Joi.object({
|
||||
type: Joi.string().required()
|
||||
}).unknown()
|
||||
})),
|
||||
fieldFormatMap: Joi.object()
|
||||
});
|
||||
module.exports = {
|
||||
post: Joi.object({
|
||||
title: Joi.string().required(),
|
||||
timeFieldName: Joi.string(),
|
||||
intervalName: Joi.string(),
|
||||
fields: Joi.array().items(Joi.object({
|
||||
name: Joi.string().required(),
|
||||
count: Joi.number().integer(),
|
||||
scripted: Joi.boolean(),
|
||||
mapping: Joi.object({
|
||||
type: Joi.string().required()
|
||||
}).unknown()
|
||||
})),
|
||||
fieldFormatMap: Joi.object()
|
||||
}),
|
||||
|
||||
put: Joi.object({
|
||||
title: Joi.string(),
|
||||
timeFieldName: Joi.string(),
|
||||
intervalName: Joi.string(),
|
||||
fields: Joi.array().items(Joi.object({
|
||||
name: Joi.string().required(),
|
||||
count: Joi.number().integer(),
|
||||
scripted: Joi.boolean(),
|
||||
mapping: Joi.any().forbidden()
|
||||
})),
|
||||
fieldFormatMap: Joi.object()
|
||||
})
|
||||
};
|
||||
|
|
|
@ -50,6 +50,39 @@ define(function (require) {
|
|||
.expect(400);
|
||||
});
|
||||
|
||||
bdd.it('should return 400 if you try to update mappings', function () {
|
||||
return request.put('/index-patterns/logstash-*')
|
||||
.send(createTestData().indexPatternWithMappings)
|
||||
.expect(400);
|
||||
});
|
||||
|
||||
bdd.it('should return 400 for an invalid payload', function () {
|
||||
function omitMappings(pattern) {
|
||||
pattern.fields = _.map(pattern.fields, function (field) {
|
||||
return _.omit(field, 'mapping');
|
||||
});
|
||||
return pattern;
|
||||
};
|
||||
|
||||
return Promise.all([
|
||||
request.put('/index-patterns/logstash-*').expect(400),
|
||||
|
||||
request.put('/index-patterns/logstash-*')
|
||||
.send({})
|
||||
.expect(400),
|
||||
|
||||
//fields must be an array
|
||||
request.put('/index-patterns/logstash-*')
|
||||
.send(_.assign(omitMappings(createTestData().indexPatternWithMappings), {fields: {}}))
|
||||
.expect(400),
|
||||
|
||||
// field objects must have a name
|
||||
request.put('/index-patterns/logstash-*')
|
||||
.send(_.assign(omitMappings(createTestData().indexPatternWithMappings), {fields: [{count: 0}]}))
|
||||
.expect(400)
|
||||
]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue