mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-11 02:12:21 -05:00
Added helper to check for content API (#10104)
no issue * Added helper to check if API called is content API
This commit is contained in:
parent
22911b5812
commit
3345618731
2 changed files with 66 additions and 0 deletions
|
@ -9,5 +9,16 @@ module.exports = {
|
|||
|
||||
get validators() {
|
||||
return require('./validators');
|
||||
},
|
||||
|
||||
/**
|
||||
* TODO: We need to check for public context as permission stage overrides
|
||||
* the whole context object currently: https://github.com/TryGhost/Ghost/issues/10099
|
||||
*/
|
||||
isContentAPI: (frame) => {
|
||||
return !!(Object.keys(frame.options.context).length === 0 ||
|
||||
(!frame.options.context.user && frame.options.context.api_key_id) ||
|
||||
frame.options.context.public
|
||||
);
|
||||
}
|
||||
};
|
||||
|
|
55
core/test/unit/api/v2/index_spec.js
Normal file
55
core/test/unit/api/v2/index_spec.js
Normal file
|
@ -0,0 +1,55 @@
|
|||
const should = require('should');
|
||||
const sinon = require('sinon');
|
||||
const utils = require('../../../../server/api/v2/utils');
|
||||
const sandbox = sinon.sandbox.create();
|
||||
|
||||
describe('Unit: v2/utils/index', function () {
|
||||
afterEach(function () {
|
||||
sandbox.restore();
|
||||
});
|
||||
describe('isContentAPI', function () {
|
||||
it('is truthy when having api key and no user', function () {
|
||||
const frame = {
|
||||
options: {
|
||||
context: {
|
||||
api_key_id: 'api_key'
|
||||
}
|
||||
}
|
||||
};
|
||||
should(utils.isContentAPI(frame)).equal(true);
|
||||
});
|
||||
|
||||
it('is falsy when having api key and a user', function () {
|
||||
const frame = {
|
||||
options: {
|
||||
context: {
|
||||
user: {},
|
||||
api_key_id: 'api_key'
|
||||
}
|
||||
}
|
||||
};
|
||||
should(utils.isContentAPI(frame)).equal(false);
|
||||
});
|
||||
|
||||
it('is truthy when context is empty', function () {
|
||||
const frame = {
|
||||
options: {
|
||||
context: {
|
||||
}
|
||||
}
|
||||
};
|
||||
should(utils.isContentAPI(frame)).equal(true);
|
||||
});
|
||||
|
||||
it('is truthy when context is public', function () {
|
||||
const frame = {
|
||||
options: {
|
||||
context: {
|
||||
public: true
|
||||
}
|
||||
}
|
||||
};
|
||||
should(utils.isContentAPI(frame)).equal(true);
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Add table
Reference in a new issue