2017-05-25 20:09:29 +07:00
|
|
|
|
2017-08-05 02:20:31 +07:00
|
|
|
import FirstFactorValidator = require("../../../../src/client/lib/firstfactor/FirstFactorValidator");
|
2017-05-25 20:09:29 +07: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-25 04:19:03 +07:00
|
|
|
postPromise.done.yields({ redirect: "http://redirect" });
|
2017-05-25 20:09:29 +07:00
|
|
|
postPromise.done.returns(postPromise);
|
|
|
|
|
|
|
|
const jqueryMock = JQueryMock.JQueryMock();
|
2017-09-25 04:19:03 +07:00
|
|
|
jqueryMock.jquery.ajax.returns(postPromise);
|
2017-05-25 20:09:29 +07:00
|
|
|
|
2017-09-25 04:19:03 +07:00
|
|
|
return FirstFactorValidator.validate("username", "password", "http://redirect", false, jqueryMock.jquery as any);
|
2017-05-25 20:09:29 +07:00
|
|
|
});
|
|
|
|
|
2017-08-05 02:20:31 +07:00
|
|
|
function should_fail_first_factor_validation(errorMessage: string) {
|
2017-05-25 20:09:29 +07:00
|
|
|
const xhr = {
|
2017-08-05 02:20:31 +07:00
|
|
|
status: 401
|
2017-05-25 20:09:29 +07:00
|
|
|
};
|
|
|
|
const postPromise = JQueryMock.JQueryDeferredMock();
|
|
|
|
postPromise.fail.yields(xhr, errorMessage);
|
|
|
|
postPromise.done.returns(postPromise);
|
|
|
|
|
|
|
|
const jqueryMock = JQueryMock.JQueryMock();
|
2017-09-25 04:19:03 +07:00
|
|
|
jqueryMock.jquery.ajax.returns(postPromise);
|
2017-05-25 20:09:29 +07:00
|
|
|
|
2017-09-25 04:19:03 +07:00
|
|
|
return FirstFactorValidator.validate("username", "password", "http://redirect", false, jqueryMock.jquery as any)
|
2017-05-25 20:09:29 +07: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-05 02:20:31 +07:00
|
|
|
it("should fail with error", () => {
|
|
|
|
return should_fail_first_factor_validation("Authetication failed. Please check your credentials.");
|
2017-05-25 20:09:29 +07:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|