Archived
2

forbid condition_template as parameter name for template

This commit is contained in:
VLE2FE 2020-05-29 14:26:39 +02:00
parent 90c8898391
commit ea336f4ebc
3 changed files with 22 additions and 3 deletions

View File

@ -5,7 +5,6 @@ import TemplateMeasurementModel from '../models/measurement_template';
import TestHelper from "../test/helper"; import TestHelper from "../test/helper";
// TODO: do not allow usage of old templates for new samples // TODO: do not allow usage of old templates for new samples
// TODO: template parameters are not allowed to be condition_template
describe('/template', () => { describe('/template', () => {
let server; let server;
@ -218,6 +217,16 @@ describe('/template', () => {
done(); done();
}); });
}); });
it('rejects `condition_template` as parameter name', done => {
TestHelper.request(server, done, {
method: 'put',
url: '/template/condition/200000000000000000000001',
auth: {basic: 'admin'},
httpStatus: 400,
req: {parameters: [{name: 'condition_template', range: {}}]},
res: {status: 'Invalid body format', details: '"parameters[0].name" contains an invalid value'}
});
});
it('rejects not specified parameters', done => { it('rejects not specified parameters', done => {
TestHelper.request(server, done, { TestHelper.request(server, done, {
method: 'put', method: 'put',
@ -227,7 +236,7 @@ describe('/template', () => {
req: {name: 'heat treatment', parameters: [{name: 'material', range: {xx: 5}}]}, req: {name: 'heat treatment', parameters: [{name: 'material', range: {xx: 5}}]},
res: {status: 'Invalid body format', details: '"parameters[0].range.xx" is not allowed'} res: {status: 'Invalid body format', details: '"parameters[0].range.xx" is not allowed'}
}); });
}) });
it('rejects an invalid id', done => { it('rejects an invalid id', done => {
TestHelper.request(server, done, { TestHelper.request(server, done, {
method: 'put', method: 'put',
@ -327,6 +336,16 @@ describe('/template', () => {
res: {status: 'Invalid body format', details: '"name" is required'} res: {status: 'Invalid body format', details: '"name" is required'}
}); });
}); });
it('rejects `condition_template` as parameter name', done => {
TestHelper.request(server, done, {
method: 'post',
url: '/template/condition/new',
auth: {basic: 'admin'},
httpStatus: 400,
req: {name: 'heat aging', parameters: [{name: 'condition_template', range: {min: 1}}]},
res: {status: 'Invalid body format', details: '"parameters[0].name" contains an invalid value'}
});
});
it('rejects a number prefix', done => { it('rejects a number prefix', done => {
TestHelper.request(server, done, { TestHelper.request(server, done, {
method: 'post', method: 'post',

View File

@ -2,7 +2,6 @@ import should from 'should/as-function';
import UserModel from '../models/user'; import UserModel from '../models/user';
import TestHelper from "../test/helper"; import TestHelper from "../test/helper";
// TODO: reject usernames containing admin, etc.
describe('/user', () => { describe('/user', () => {
let server; let server;

View File

@ -14,6 +14,7 @@ export default class TemplateValidate {
Joi.object({ Joi.object({
name: Joi.string() name: Joi.string()
.max(128) .max(128)
.invalid('condition_template')
.required(), .required(),
range: Joi.object({ range: Joi.object({