Ghost/test/unit/server/models/single-use-token.test.js
Fabien 'egg' O'Carroll bc75d20cef
Updated SingleUseToken grace period to 10 minutes (#13926)
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.
2022-01-03 17:55:53 +02:00

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');
});
});
});