2017-05-25 13:09:29 +00:00
|
|
|
|
2017-10-06 22:09:42 +00:00
|
|
|
import FirstFactorValidator = require("../../src/lib/firstfactor/FirstFactorValidator");
|
2017-05-25 13:09:29 +00:00
|
|
|
import JQueryMock = require("../mocks/jquery");
|
|
|
|
import BluebirdPromise = require("bluebird");
|
|
|
|
import Assert = require("assert");
|
|
|
|
|
|
|
|
describe("test FirstFactorValidator", function () {
|
|
|
|
it("should validate first factor successfully", () => {
|
|
|
|
const postPromise = JQueryMock.JQueryDeferredMock();
|
2017-09-24 21:19:03 +00:00
|
|
|
postPromise.done.yields({ redirect: "http://redirect" });
|
2017-05-25 13:09:29 +00:00
|
|
|
postPromise.done.returns(postPromise);
|
|
|
|
|
|
|
|
const jqueryMock = JQueryMock.JQueryMock();
|
2017-09-24 21:19:03 +00:00
|
|
|
jqueryMock.jquery.ajax.returns(postPromise);
|
2017-05-25 13:09:29 +00:00
|
|
|
|
2018-10-21 14:11:31 +00:00
|
|
|
return FirstFactorValidator.validate("username", "password", false,
|
|
|
|
"http://redirect", jqueryMock.jquery as any);
|
2017-05-25 13:09:29 +00:00
|
|
|
});
|
|
|
|
|
2017-08-04 19:20:31 +00:00
|
|
|
function should_fail_first_factor_validation(errorMessage: string) {
|
2017-05-25 13:09:29 +00:00
|
|
|
const xhr = {
|
2017-08-04 19:20:31 +00:00
|
|
|
status: 401
|
2017-05-25 13:09:29 +00:00
|
|
|
};
|
|
|
|
const postPromise = JQueryMock.JQueryDeferredMock();
|
|
|
|
postPromise.fail.yields(xhr, errorMessage);
|
|
|
|
postPromise.done.returns(postPromise);
|
|
|
|
|
|
|
|
const jqueryMock = JQueryMock.JQueryMock();
|
2017-09-24 21:19:03 +00:00
|
|
|
jqueryMock.jquery.ajax.returns(postPromise);
|
2017-05-25 13:09:29 +00:00
|
|
|
|
2018-10-21 14:11:31 +00:00
|
|
|
return FirstFactorValidator.validate("username", "password", false,
|
|
|
|
"http://redirect", jqueryMock.jquery as any)
|
2017-05-25 13:09:29 +00:00
|
|
|
.then(function () {
|
|
|
|
return BluebirdPromise.reject(new Error("First factor validation successfully finished while it should have not."));
|
|
|
|
}, function (err: Error) {
|
|
|
|
Assert.equal(errorMessage, err.message);
|
|
|
|
return BluebirdPromise.resolve();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
describe("should fail first factor validation", () => {
|
2017-08-04 19:20:31 +00:00
|
|
|
it("should fail with error", () => {
|
2017-10-10 21:03:30 +00:00
|
|
|
return should_fail_first_factor_validation("Authentication failed. Please check your credentials.");
|
2017-05-25 13:09:29 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|