2017-05-25 13:09:29 +00:00
|
|
|
|
2017-08-04 19:20:31 +00:00
|
|
|
import TOTPValidator = require("../../../../src/client/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 () {
|
|
|
|
it("should initiate an identity check successfully", () => {
|
|
|
|
const postPromise = JQueryMock.JQueryDeferredMock();
|
|
|
|
postPromise.done.yields();
|
|
|
|
postPromise.done.returns(postPromise);
|
|
|
|
|
|
|
|
const jqueryMock = JQueryMock.JQueryMock();
|
2017-08-04 19:20:31 +00:00
|
|
|
jqueryMock.jquery.ajax.returns(postPromise);
|
2017-05-25 13:09:29 +00:00
|
|
|
|
2017-08-04 19:20:31 +00:00
|
|
|
return TOTPValidator.validate("totp_token", jqueryMock.jquery as any);
|
2017-05-25 13:09:29 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
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();
|
2017-08-04 19:20:31 +00:00
|
|
|
jqueryMock.jquery.ajax.returns(postPromise);
|
2017-05-25 13:09:29 +00:00
|
|
|
|
2017-08-04 19:20:31 +00:00
|
|
|
return TOTPValidator.validate("totp_token", jqueryMock.jquery as any)
|
2017-05-25 13:09:29 +00:00
|
|
|
.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();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|