mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
parent
d5bf6dc1c8
commit
9ce160df78
3 changed files with 61 additions and 0 deletions
17
core/test/unit/web/api/v2/content/middleware_spec.js
Normal file
17
core/test/unit/web/api/v2/content/middleware_spec.js
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
const should = require('should');
|
||||||
|
const middleware = require('../../../../../../server/web/api/v2/content/middleware');
|
||||||
|
|
||||||
|
describe('Content Api v2 middleware', function () {
|
||||||
|
it('exports an authenticatePublic middleware', function () {
|
||||||
|
should.exist(middleware.authenticatePublic);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('authenticatePublic', function () {
|
||||||
|
it('uses brute content api middleware as the first middleware in the chain', function () {
|
||||||
|
const firstMiddleware = middleware.authenticatePublic[0];
|
||||||
|
const brute = require('../../../../../../server/web/shared/middlewares/brute');
|
||||||
|
|
||||||
|
should.equal(firstMiddleware, brute.contentApiKey);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
|
@ -0,0 +1,17 @@
|
||||||
|
const should = require('should');
|
||||||
|
const spamPrevention = require('../../../../../../server/web/shared/middlewares/api/spam-prevention');
|
||||||
|
|
||||||
|
describe('Spam Prevention', function () {
|
||||||
|
it('exports a contentApiKey method', function () {
|
||||||
|
should.equal(typeof spamPrevention.contentApiKey, 'function');
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('contentApiKey method', function () {
|
||||||
|
it('returns an instance of express-brute', function () {
|
||||||
|
const ExpressBrute = require('express-brute');
|
||||||
|
const result = spamPrevention.contentApiKey();
|
||||||
|
|
||||||
|
should.equal(result instanceof ExpressBrute, true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
27
core/test/unit/web/shared/middleware/brute_spec.js
Normal file
27
core/test/unit/web/shared/middleware/brute_spec.js
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
const should = require('should');
|
||||||
|
const sinon = require('sinon');
|
||||||
|
const brute = require('../../../../../server/web/shared/middlewares/brute');
|
||||||
|
|
||||||
|
describe('brute middleware', function () {
|
||||||
|
it('exports a contentApiKey method', function () {
|
||||||
|
should.equal(typeof brute.contentApiKey, 'function');
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('contentApiKey', function () {
|
||||||
|
it('calls the contentApiKey method of spam prevention', function () {
|
||||||
|
const spamPrevention = require('../../../../../server/web/shared/middlewares/api/spam-prevention');
|
||||||
|
const contentApiKeyStub = sinon.stub(spamPrevention, 'contentApiKey');
|
||||||
|
|
||||||
|
// CASE: we don't care about what params it takes
|
||||||
|
// just whether it calls the spam prevention stuff
|
||||||
|
try {
|
||||||
|
brute.contentApiKey();
|
||||||
|
} catch (err) {
|
||||||
|
// I don't care
|
||||||
|
} finally {
|
||||||
|
should.equal(contentApiKeyStub.called, true);
|
||||||
|
contentApiKeyStub.reset();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
Loading…
Add table
Reference in a new issue