2017-05-25 13:09:29 +00:00
|
|
|
|
2017-10-06 22:09:42 +00:00
|
|
|
import TOTPValidator = require("../../src/lib/secondfactor/TOTPValidator");
|
2017-05-25 13:09:29 +00:00
|
|
|
import JQueryMock = require("../mocks/jquery");
|
|
|
|
import BluebirdPromise = require("bluebird");
|
|
|
|
import Assert = require("assert");
|
|
|
|
|
|
|
|
describe("test TOTPValidator", function () {
|
2017-10-10 21:03:30 +00:00
|
|
|
it("should initiate an identity check successfully", () => {
|
|
|
|
const postPromise = JQueryMock.JQueryDeferredMock();
|
2017-10-17 21:24:02 +00:00
|
|
|
postPromise.done.yields({ redirect: "https://home.test.url" });
|
2017-10-10 21:03:30 +00:00
|
|
|
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();
|
|
|
|
});
|
|
|
|
});
|
2017-05-25 13:09:29 +00:00
|
|
|
});
|