Extended test coverage for tokens module

refs https://github.com/TryGhost/Ghost/issues/11878

- There are multiple reasons why the token can be invalid. This coverage is meant cover these reasons and pave the way for introduction of more rganular errors causing the invlid token
This commit is contained in:
Nazar Gargol 2020-09-22 13:17:07 +12:00
parent 01f6345c08
commit 54f9ff24c2

View File

@ -42,7 +42,7 @@ describe('Utils: tokens', function () {
tokenIsCorrect.should.eql(true);
});
it('compare: error', function () {
it('compare: error from invalid password', function () {
const expires = Date.now() + 60 * 1000;
const dbHash = uuid.v4();
let token;
@ -64,6 +64,50 @@ describe('Utils: tokens', function () {
tokenIsCorrect.should.eql(false);
});
it('compare: error from invalid expires parameter', function () {
const invalidDate = 'not a date';
const dbHash = uuid.v4();
let token;
let tokenIsCorrect;
token = security.tokens.resetToken.generateHash({
email: 'test1@ghost.org',
expires: invalidDate,
password: '12345678',
dbHash: dbHash
});
tokenIsCorrect = security.tokens.resetToken.compare({
token: token,
dbHash: dbHash,
password: '123456'
});
tokenIsCorrect.should.eql(false);
});
it('compare: error from expired token', function () {
const dateInThePast = Date.now() - 60 * 1000;
const dbHash = uuid.v4();
let token;
let tokenIsCorrect;
token = security.tokens.resetToken.generateHash({
email: 'test1@ghost.org',
expires: dateInThePast,
password: '12345678',
dbHash: dbHash
});
tokenIsCorrect = security.tokens.resetToken.compare({
token: token,
dbHash: dbHash,
password: '123456'
});
tokenIsCorrect.should.eql(false);
});
it('extract', function () {
const expires = Date.now() + 60 * 1000;
const dbHash = uuid.v4();