2017-05-25 20:09:29 +07:00
|
|
|
|
2017-10-07 05:09:42 +07:00
|
|
|
import PasswordResetHandler from "../../../../src/lib/routes/password-reset/identity/PasswordResetHandler";
|
|
|
|
import PasswordUpdater = require("../../../../src/lib/ldap/PasswordUpdater");
|
|
|
|
import { UserDataStore } from "../../../../src/lib/storage/UserDataStore";
|
2017-07-20 02:06:12 +07:00
|
|
|
import Sinon = require("sinon");
|
2017-05-25 20:09:29 +07:00
|
|
|
import winston = require("winston");
|
|
|
|
import assert = require("assert");
|
|
|
|
import BluebirdPromise = require("bluebird");
|
|
|
|
import ExpressMock = require("../../../mocks/express");
|
2017-10-18 04:24:02 +07:00
|
|
|
import { ServerVariablesMock, ServerVariablesMockBuilder } from "../../../mocks/ServerVariablesMockBuilder";
|
|
|
|
import { ServerVariables } from "../../../../src/lib/ServerVariables";
|
2017-05-25 20:09:29 +07:00
|
|
|
|
|
|
|
describe("test reset password identity check", function () {
|
2017-10-18 04:24:02 +07:00
|
|
|
let req: ExpressMock.RequestMock;
|
|
|
|
let res: ExpressMock.ResponseMock;
|
|
|
|
let mocks: ServerVariablesMock;
|
|
|
|
let vars: ServerVariables;
|
2017-05-25 20:09:29 +07:00
|
|
|
|
2017-10-18 04:24:02 +07:00
|
|
|
beforeEach(function () {
|
|
|
|
req = {
|
|
|
|
query: {
|
|
|
|
userid: "user"
|
|
|
|
},
|
|
|
|
session: {
|
|
|
|
auth: {
|
|
|
|
userid: "user",
|
|
|
|
email: "user@example.com",
|
|
|
|
first_factor: true,
|
|
|
|
second_factor: false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
headers: {
|
|
|
|
host: "localhost"
|
|
|
|
}
|
|
|
|
};
|
2017-05-25 20:09:29 +07:00
|
|
|
|
2017-10-18 04:24:02 +07:00
|
|
|
const options = {
|
|
|
|
inMemoryOnly: true
|
|
|
|
};
|
2017-05-25 20:09:29 +07:00
|
|
|
|
2017-10-18 04:24:02 +07:00
|
|
|
const s = ServerVariablesMockBuilder.build();
|
|
|
|
mocks = s.mocks;
|
|
|
|
vars = s.variables;
|
2017-05-25 20:09:29 +07:00
|
|
|
|
2017-10-18 04:24:02 +07:00
|
|
|
mocks.userDataStore.saveU2FRegistrationStub.returns(BluebirdPromise.resolve({}));
|
|
|
|
mocks.userDataStore.retrieveU2FRegistrationStub.returns(BluebirdPromise.resolve({}));
|
|
|
|
mocks.userDataStore.produceIdentityValidationTokenStub.returns(BluebirdPromise.resolve({}));
|
|
|
|
mocks.userDataStore.consumeIdentityValidationTokenStub.returns(BluebirdPromise.resolve({}));
|
|
|
|
res = ExpressMock.ResponseMock();
|
|
|
|
});
|
2017-05-25 20:09:29 +07:00
|
|
|
|
2017-10-18 04:24:02 +07:00
|
|
|
describe("test reset password identity pre check", () => {
|
|
|
|
it("should fail when no userid is provided", function () {
|
|
|
|
req.query.userid = undefined;
|
|
|
|
const handler = new PasswordResetHandler(vars.logger, vars.ldapEmailsRetriever);
|
|
|
|
return handler.preValidationInit(req as any)
|
|
|
|
.then(function () { return BluebirdPromise.reject("It should fail"); })
|
|
|
|
.catch(function (err: Error) {
|
|
|
|
return BluebirdPromise.resolve();
|
2017-05-25 20:09:29 +07:00
|
|
|
});
|
2017-10-18 04:24:02 +07:00
|
|
|
});
|
2017-05-25 20:09:29 +07:00
|
|
|
|
2017-10-18 04:24:02 +07:00
|
|
|
it("should fail if ldap fail", function () {
|
|
|
|
mocks.ldapEmailsRetriever.retrieveStub.returns(BluebirdPromise.reject("Internal error"));
|
|
|
|
new PasswordResetHandler(vars.logger, vars.ldapEmailsRetriever).preValidationInit(req as any)
|
|
|
|
.then(function () { return BluebirdPromise.reject(new Error("should not be here")); },
|
|
|
|
function (err: Error) {
|
|
|
|
return BluebirdPromise.resolve();
|
2017-05-25 20:09:29 +07:00
|
|
|
});
|
2017-10-18 04:24:02 +07:00
|
|
|
});
|
2017-05-25 20:09:29 +07:00
|
|
|
|
2017-10-18 04:24:02 +07:00
|
|
|
it("should returns identity when ldap replies", function () {
|
|
|
|
mocks.ldapEmailsRetriever.retrieveStub.returns(BluebirdPromise.resolve(["test@example.com"]));
|
|
|
|
return new PasswordResetHandler(vars.logger, vars.ldapEmailsRetriever).preValidationInit(req as any);
|
2017-05-25 20:09:29 +07:00
|
|
|
});
|
2017-10-18 04:24:02 +07:00
|
|
|
});
|
2017-05-25 20:09:29 +07:00
|
|
|
});
|