diff --git a/packages/bruno-schema/src/common/index.js b/packages/bruno-schema/src/common/index.js index 12d6ee11..59328836 100644 --- a/packages/bruno-schema/src/common/index.js +++ b/packages/bruno-schema/src/common/index.js @@ -2,7 +2,8 @@ const Yup = require('yup'); const uidSchema = Yup.string() .length(21, 'uid must be 21 characters in length') - .matches(/^[a-zA-Z0-9]*$/, 'uid must be alphanumeric'); + .matches(/^[a-zA-Z0-9]*$/, 'uid must be alphanumeric') + .strict(); module.exports = { uidSchema diff --git a/packages/bruno-schema/src/workspaces/index.js b/packages/bruno-schema/src/workspaces/index.js index 6e141ef6..795ff6d7 100644 --- a/packages/bruno-schema/src/workspaces/index.js +++ b/packages/bruno-schema/src/workspaces/index.js @@ -8,7 +8,7 @@ const workspaceSchema = Yup.object({ .max(50, 'name must be 50 characters or less') .required('name is required'), collectionUids: Yup.array().of(uidSchema) -}); +}).noUnknown(true).strict(); module.exports = { workspaceSchema diff --git a/packages/bruno-schema/src/workspaces/index.spec.js b/packages/bruno-schema/src/workspaces/index.spec.js index d3cec174..fcd0b89a 100644 --- a/packages/bruno-schema/src/workspaces/index.spec.js +++ b/packages/bruno-schema/src/workspaces/index.spec.js @@ -69,4 +69,18 @@ describe('Workspace Schema Validation', () => { ) ]); }); + + it('workspace schema must throw error when unknown key is present', async () => { + const workspace = { + uid: uuid(), + name: 'My Workspace', + foo: 'bar' + }; + + return Promise.all([ + expect(workspaceSchema.validate(workspace)).rejects.toEqual( + validationErrorWithMessages('this field has unspecified keys: foo') + ) + ]); + }); });