0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-03 23:00:14 -05:00

Added clause in validation for include to not error (#10350)

* Added clause in validation for include to not error

refs #10337

Here we forgo erroring when an invalid property for include is sent, and
instead remove the invalid properties.

* Fixed authors test

* Fixed validators tests
This commit is contained in:
Fabien O'Carroll 2019-01-08 12:29:15 +01:00 committed by GitHub
parent 3a923c597f
commit 76bb40b7c0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 7 deletions

View file

@ -63,6 +63,12 @@ const validate = (config, attrs) => {
}); });
if (unallowedValues.length) { if (unallowedValues.length) {
// CASE: we do not error for invalid includes, just silently remove
if (key === 'include') {
attrs.include = valuesAsArray.filter(x => allowedValues.includes(x));
return;
}
errors.push(new common.errors.ValidationError({ errors.push(new common.errors.ValidationError({
message: common.i18n.t('notices.data.validation.index.validationFailed', { message: common.i18n.t('notices.data.validation.index.validationFailed', {
validationName: 'AllowedValues', validationName: 'AllowedValues',

View file

@ -63,18 +63,18 @@ describe('Authors Content API V2', function () {
}); });
}); });
it('browse authors: throws error if trying to fetch roles', function (done) { it('browse authors: does not give back roles if trying to fetch roles', function (done) {
request.get(localUtils.API.getApiQuery(`authors/?key=${validKey}&include=roles`)) request.get(localUtils.API.getApiQuery(`authors/?key=${validKey}&include=roles`))
.set('Origin', testUtils.API.getURL()) .set('Origin', testUtils.API.getURL())
.expect('Content-Type', /json/) .expect('Content-Type', /json/)
.expect('Cache-Control', testUtils.cacheRules.private) .expect('Cache-Control', testUtils.cacheRules.private)
.expect(422) .expect(200)
.end(function (err, res) { .end(function (err, res) {
if (err) { if (err) {
return done(err); return done(err);
} }
should.not.exist(res.headers['x-cache-invalidate']); should.not.exist(res.body.authors[0].roles);
done(); done();
}); });
}); });

View file

@ -132,7 +132,7 @@ describe('Unit: api/shared/validators/input/all', function () {
}); });
}); });
it('fails', function () { it('does not fail', function () {
const frame = { const frame = {
options: { options: {
context: {}, context: {},
@ -151,11 +151,11 @@ describe('Unit: api/shared/validators/input/all', function () {
return shared.validators.input.all.all(apiConfig, frame) return shared.validators.input.all.all(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
should.exist(err); should.not.exist(err);
}); });
}); });
it('fails include array notation', function () { it('does not fail include array notation', function () {
const frame = { const frame = {
options: { options: {
context: {}, context: {},
@ -172,7 +172,7 @@ describe('Unit: api/shared/validators/input/all', function () {
return shared.validators.input.all.all(apiConfig, frame) return shared.validators.input.all.all(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
should.exist(err); should.not.exist(err);
}); });
}); });