diff --git a/core/server/services/settings/validate.js b/core/server/services/settings/validate.js index 4bce0e9f95..c67d4c5cbc 100644 --- a/core/server/services/settings/validate.js +++ b/core/server/services/settings/validate.js @@ -302,6 +302,7 @@ _private.validateCollections = function validateCollections(collections) { }; _private.validateTaxonomies = function validateTaxonomies(taxonomies) { + const validRoutingTypeObjectKeys = Object.keys(RESOURCE_CONFIG.TAXONOMIES); _.each(taxonomies, (routingTypeObject, routingTypeObjectKey) => { if (!routingTypeObject) { throw new common.errors.ValidationError({ @@ -313,6 +314,15 @@ _private.validateTaxonomies = function validateTaxonomies(taxonomies) { }); } + if (!validRoutingTypeObjectKeys.includes(routingTypeObjectKey)) { + throw new common.errors.ValidationError({ + message: common.i18n.t('errors.services.settings.yaml.validate', { + at: routingTypeObjectKey, + reason: 'Unknown taxonomy.' + }) + }); + } + // CASE: we hard-require trailing slashes for the taxonomie permalink route if (!routingTypeObject.match(/\/$/)) { throw new common.errors.ValidationError({ diff --git a/core/test/unit/services/settings/validate_spec.js b/core/test/unit/services/settings/validate_spec.js index 3d757c5cb6..e13b7646b9 100644 --- a/core/test/unit/services/settings/validate_spec.js +++ b/core/test/unit/services/settings/validate_spec.js @@ -35,7 +35,22 @@ describe('UNIT: services/settings/validate', function () { try { validate({ taxonomies: { - tags: '/categories/:slug/' + tag: '/categories/:slug/' + } + }); + } catch (err) { + (err instanceof common.errors.ValidationError).should.be.true(); + return; + } + + throw new Error('should fail'); + }); + + it('throws error when using an undefined taxonomy', function () { + try { + validate({ + taxonomies: { + sweet_baked_good: '/patisserie/{slug}' } }); } catch (err) { @@ -220,7 +235,7 @@ describe('UNIT: services/settings/validate', function () { } }, taxonomies: { - tags: '/tags/{slug}/', + tag: '/tags/{slug}/', author: '/authors/{slug}/', } }); @@ -228,7 +243,7 @@ describe('UNIT: services/settings/validate', function () { object.should.eql({ routes: {}, taxonomies: { - tags: '/tags/:slug/', + tag: '/tags/:slug/', author: '/authors/:slug/' }, collections: {