2019-01-24 15:37:27 +03:00
|
|
|
const should = require('should');
|
|
|
|
const supertest = require('supertest');
|
2019-09-20 18:02:45 +03:00
|
|
|
const testUtils = require('../../utils');
|
2019-01-24 15:37:27 +03:00
|
|
|
const localUtils = require('./utils');
|
2020-05-27 20:47:53 +03:00
|
|
|
const config = require('../../../core/shared/config');
|
2021-04-09 15:45:26 +03:00
|
|
|
const configUtils = require('../../utils/configUtils');
|
2019-01-24 15:37:27 +03:00
|
|
|
|
2019-02-04 17:49:59 +03:00
|
|
|
describe('Content API key authentication', function () {
|
2019-01-24 15:37:27 +03:00
|
|
|
let request;
|
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
before(async function () {
|
2021-11-18 11:55:35 +03:00
|
|
|
await localUtils.startGhost();
|
2020-11-30 17:25:22 +03:00
|
|
|
request = supertest.agent(config.get('url'));
|
|
|
|
await testUtils.initFixtures('api_keys');
|
2019-01-24 15:37:27 +03:00
|
|
|
});
|
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
it('Can not access without key', async function () {
|
|
|
|
await request.get(localUtils.API.getApiQuery('posts/'))
|
2019-01-24 15:37:27 +03:00
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
|
|
|
.expect(403);
|
|
|
|
});
|
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
it('Can access with with valid key', async function () {
|
2019-01-24 15:37:27 +03:00
|
|
|
const key = localUtils.getValidKey();
|
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
await request.get(localUtils.API.getApiQuery(`posts/?key=${key}`))
|
2019-01-24 15:37:27 +03:00
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
|
|
|
.expect(200);
|
|
|
|
});
|
2021-04-09 15:45:26 +03:00
|
|
|
|
|
|
|
describe('Host Settings: custom integration limits', function () {
|
|
|
|
afterEach(function () {
|
|
|
|
configUtils.set('hostSettings:limits', undefined);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Blocks the request when host limit is in place for custom integrations', async function () {
|
|
|
|
configUtils.set('hostSettings:limits', {
|
|
|
|
customIntegrations: {
|
|
|
|
disabled: true,
|
|
|
|
error: 'Custom limit error message'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// NOTE: need to do a full reboot to reinitialize hostSettings
|
2021-11-18 11:55:35 +03:00
|
|
|
await localUtils.startGhost();
|
2021-04-09 15:45:26 +03:00
|
|
|
await testUtils.initFixtures('api_keys');
|
|
|
|
|
|
|
|
const key = localUtils.getValidKey();
|
|
|
|
|
|
|
|
const response = await request.get(localUtils.API.getApiQuery(`posts/?key=${key}`))
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
|
|
|
.expect(403);
|
|
|
|
|
2022-05-07 17:28:28 +03:00
|
|
|
response.body.errors[0].type.should.equal('HostLimitError');
|
2021-04-09 15:45:26 +03:00
|
|
|
response.body.errors[0].message.should.equal('Custom limit error message');
|
|
|
|
});
|
|
|
|
});
|
2019-01-24 15:37:27 +03:00
|
|
|
});
|