mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-11 09:53:32 +03:00
7fdddf34b3
closes https://github.com/TryGhost/Ghost/issues/12347 This change allows a token to be used multiple times for the first 10 seconds after its initial use, this will stop dynamic link checking software from invaliding magic links.
42 lines
1.1 KiB
JavaScript
42 lines
1.1 KiB
JavaScript
const models = require('../../../core/server/models');
|
|
const should = require('should');
|
|
const sinon = require('sinon');
|
|
|
|
let clock;
|
|
let sandbox;
|
|
|
|
describe('Unit: models/single-use-token', function () {
|
|
before(function () {
|
|
models.init();
|
|
sandbox = sinon.createSandbox();
|
|
clock = sandbox.useFakeTimers();
|
|
});
|
|
|
|
after(function () {
|
|
clock.restore();
|
|
sandbox.restore();
|
|
});
|
|
|
|
describe('fn: findOne', function () {
|
|
it('Calls destroy after the grace period', async function () {
|
|
const data = {};
|
|
const options = {};
|
|
const fakeModel = {
|
|
id: 'fake_id'
|
|
};
|
|
|
|
const findOneSuperStub = sandbox.stub(models.Base.Model, 'findOne').resolves(fakeModel);
|
|
const destroyStub = sandbox.stub(models.SingleUseToken, 'destroy').resolves();
|
|
|
|
await models.SingleUseToken.findOne(data, options);
|
|
|
|
should.ok(findOneSuperStub.calledWith(data, options), 'super.findOne was called');
|
|
|
|
clock.tick(10000);
|
|
|
|
should.ok(destroyStub.called, 'destroy was called after 10 seconds');
|
|
});
|
|
});
|
|
});
|
|
|