mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-22 18:31:57 +03:00
bc75d20cef
refs https://github.com/TryGhost/Team/issues/1216 Some email security clients are scanning links at delivery, rather than at the point the user clicks on them. This is causing magic links to expire. To get around this we're increasing the grace period in which a link can be used multiple times to 10 minutes.
45 lines
1.3 KiB
JavaScript
45 lines
1.3 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 not called after 10 seconds');
|
|
|
|
clock.tick(10 * 60 * 1000 - 10000);
|
|
|
|
should.ok(destroyStub.called, 'destroy was not called after 10 seconds');
|
|
});
|
|
});
|
|
});
|