authelia/test/unitary/totp.test.ts

33 lines
879 B
TypeScript
Raw Normal View History

2017-05-16 21:17:46 +00:00
const totp = require("../../src/lib/totp");
const sinon = require("sinon");
import Promise = require("bluebird");
describe("test TOTP validation", function() {
it("should validate the TOTP token", function() {
const totp_secret = "NBD2ZV64R9UV1O7K";
const token = "token";
const totp_mock = sinon.mock();
totp_mock.returns("token");
const speakeasy_mock = {
totp: totp_mock
};
return totp.validate(speakeasy_mock, token, totp_secret);
});
it("should not validate a wrong TOTP token", function() {
const totp_secret = "NBD2ZV64R9UV1O7K";
const token = "wrong token";
const totp_mock = sinon.mock();
totp_mock.returns("token");
const speakeasy_mock = {
totp: totp_mock
};
return totp.validate(speakeasy_mock, token, totp_secret)
.catch(function() {
return Promise.resolve();
});
});
});