mirror of
https://github.com/0rangebananaspy/authelia.git
synced 2024-09-14 22:47:21 +07:00
d8ff186303
Client and server now have their own tsconfig so that the transpilation is only done on the part that is being modified. It also allows faster transpilation since tests are now excluded from tsconfig. They are compiled by ts-node during unit tests execution.
37 lines
1.4 KiB
TypeScript
37 lines
1.4 KiB
TypeScript
|
|
import TOTPValidator = require("../../src/lib/secondfactor/TOTPValidator");
|
|
import JQueryMock = require("../mocks/jquery");
|
|
import BluebirdPromise = require("bluebird");
|
|
import Assert = require("assert");
|
|
|
|
describe("test TOTPValidator", function () {
|
|
it("should initiate an identity check successfully", () => {
|
|
const postPromise = JQueryMock.JQueryDeferredMock();
|
|
postPromise.done.yields();
|
|
postPromise.done.returns(postPromise);
|
|
|
|
const jqueryMock = JQueryMock.JQueryMock();
|
|
jqueryMock.jquery.ajax.returns(postPromise);
|
|
|
|
return TOTPValidator.validate("totp_token", jqueryMock.jquery as any);
|
|
});
|
|
|
|
it("should fail validating TOTP token", () => {
|
|
const errorMessage = "Error while validating TOTP token";
|
|
|
|
const postPromise = JQueryMock.JQueryDeferredMock();
|
|
postPromise.fail.yields(undefined, errorMessage);
|
|
postPromise.done.returns(postPromise);
|
|
|
|
const jqueryMock = JQueryMock.JQueryMock();
|
|
jqueryMock.jquery.ajax.returns(postPromise);
|
|
|
|
return TOTPValidator.validate("totp_token", jqueryMock.jquery as any)
|
|
.then(function () {
|
|
return BluebirdPromise.reject(new Error("Registration successfully finished while it should have not."));
|
|
}, function (err: Error) {
|
|
Assert.equal(errorMessage, err.message);
|
|
return BluebirdPromise.resolve();
|
|
});
|
|
});
|
|
}); |