mirror of
https://github.com/0rangebananaspy/authelia.git
synced 2024-09-14 22:47:21 +07:00
b9fa786df6
This refactoring aims to ease testability and clean up a lot of soft touchy typings in test code. This is the first step of this refactoring introducing the concept and implementing missing interfaces and stubs. At the end of the day, ServerVariablesHandler should completely disappear and every variable should be injected in the endpoint handler builder itself.
40 lines
1.0 KiB
TypeScript
40 lines
1.0 KiB
TypeScript
|
|
import { TotpHandler } from "../../../src/lib/authentication/totp/TotpHandler";
|
|
import Sinon = require("sinon");
|
|
import Speakeasy = require("speakeasy");
|
|
import Assert = require("assert");
|
|
|
|
describe("test TOTP validation", function() {
|
|
let totpValidator: TotpHandler;
|
|
let validateStub: Sinon.SinonStub;
|
|
|
|
beforeEach(() => {
|
|
validateStub = Sinon.stub(Speakeasy.totp, "verify");
|
|
totpValidator = new TotpHandler(Speakeasy);
|
|
});
|
|
|
|
afterEach(function() {
|
|
validateStub.restore();
|
|
});
|
|
|
|
it("should validate the TOTP token", function() {
|
|
const totp_secret = "NBD2ZV64R9UV1O7K";
|
|
const token = "token";
|
|
validateStub.withArgs({
|
|
secret: totp_secret,
|
|
token: token,
|
|
encoding: "base32",
|
|
window: 1
|
|
}).returns(true);
|
|
Assert(totpValidator.validate(token, totp_secret));
|
|
});
|
|
|
|
it("should not validate a wrong TOTP token", function() {
|
|
const totp_secret = "NBD2ZV64R9UV1O7K";
|
|
const token = "wrong token";
|
|
validateStub.returns(false);
|
|
Assert(!totpValidator.validate(token, totp_secret));
|
|
});
|
|
});
|
|
|