const should = require('should'); const supertest = require('supertest'); const testUtils = require('../../utils'); const localUtils = require('./utils'); const config = require('../../../core/shared/config'); describe('Content API key authentication', function () { let request; before(async function () { await testUtils.startGhost(); request = supertest.agent(config.get('url')); await testUtils.initFixtures('api_keys'); }); it('Can not access without key', async function () { await request.get(localUtils.API.getApiQuery('posts/')) .expect('Content-Type', /json/) .expect('Cache-Control', testUtils.cacheRules.private) .expect(403); }); it('Can access with with valid key', async function () { const key = localUtils.getValidKey(); await request.get(localUtils.API.getApiQuery(`posts/?key=${key}`)) .expect('Content-Type', /json/) .expect('Cache-Control', testUtils.cacheRules.private) .expect(200); }); });