2019-01-24 12:37:27 +00:00
|
|
|
const should = require('should');
|
|
|
|
const supertest = require('supertest');
|
|
|
|
const _ = require('lodash');
|
2019-09-20 17:02:45 +02:00
|
|
|
const testUtils = require('../../utils');
|
2019-01-24 12:37:27 +00:00
|
|
|
const localUtils = require('./utils');
|
2020-03-30 16:26:47 +01:00
|
|
|
const config = require('../../../core/server/config');
|
2019-01-24 12:37:27 +00:00
|
|
|
|
|
|
|
const ghost = testUtils.startGhost;
|
|
|
|
|
2019-02-04 15:49:59 +01:00
|
|
|
describe('Content API key authentication', function () {
|
2019-01-24 12:37:27 +00:00
|
|
|
let request;
|
|
|
|
|
|
|
|
before(function () {
|
|
|
|
return ghost()
|
2019-02-04 15:49:59 +01:00
|
|
|
.then(function () {
|
2019-01-24 12:37:27 +00:00
|
|
|
request = supertest.agent(config.get('url'));
|
|
|
|
})
|
|
|
|
.then(function () {
|
|
|
|
return testUtils.initFixtures('api_keys');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-02-04 15:49:59 +01:00
|
|
|
it('Can not access without key', function () {
|
2019-01-24 12:37:27 +00:00
|
|
|
return request.get(localUtils.API.getApiQuery('posts/'))
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
|
|
|
.expect(403);
|
|
|
|
});
|
|
|
|
|
2019-02-04 15:49:59 +01:00
|
|
|
it('Can access with with valid key', function () {
|
2019-01-24 12:37:27 +00:00
|
|
|
const key = localUtils.getValidKey();
|
|
|
|
|
|
|
|
return request.get(localUtils.API.getApiQuery(`posts/?key=${key}`))
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
|
|
|
.expect(200);
|
|
|
|
});
|
|
|
|
});
|