yup blocks unexpected fields

This commit is contained in:
Ben Irvin 2022-08-25 12:01:52 +02:00
parent 2195e9a2f2
commit 9e42345011
2 changed files with 4 additions and 8 deletions

View File

@ -101,12 +101,6 @@ module.exports = {
attributes.description = trim(body.description);
}
// TODO: can yup handle this and throw an error if an unexpected field is included?
// Don't allow updating lastUsedAt time
if (has(attributes, 'lastUsedAt')) {
throw new ApplicationError('lastUsedAt cannot be updated');
}
await validateApiTokenUpdateInput(attributes);
const apiTokenExists = await apiTokenService.getById(id);

View File

@ -12,7 +12,8 @@ const apiTokenCreationSchema = yup
permissions: yup.array().of(yup.string()).nullable(),
lifespan: yup.number().integer().min(1).nullable(),
})
.noUnknown();
.noUnknown()
.strict();
const apiTokenUpdateSchema = yup
.object()
@ -23,7 +24,8 @@ const apiTokenUpdateSchema = yup
permissions: yup.array().of(yup.string()).nullable(),
lifespan: yup.number().integer().min(1).nullable(),
})
.noUnknown();
.noUnknown()
.strict();
module.exports = {
validateApiTokenCreationInput: validateYupSchema(apiTokenCreationSchema),