2017-05-25 13:09:29 +00:00
|
|
|
|
2017-10-06 22:09:42 +00: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-19 19:06:12 +00:00
|
|
|
import Sinon = require("sinon");
|
2017-05-25 13:09:29 +00:00
|
|
|
import winston = require("winston");
|
|
|
|
import assert = require("assert");
|
|
|
|
import BluebirdPromise = require("bluebird");
|
|
|
|
import ExpressMock = require("../../../mocks/express");
|
2017-10-17 21:24:02 +00:00
|
|
|
import { ServerVariablesMock, ServerVariablesMockBuilder } from "../../../mocks/ServerVariablesMockBuilder";
|
|
|
|
import { ServerVariables } from "../../../../src/lib/ServerVariables";
|
2017-05-25 13:09:29 +00:00
|
|
|
|
|
|
|
describe("test reset password identity check", function () {
|
2017-10-17 21:24:02 +00:00
|
|
|
let req: ExpressMock.RequestMock;
|
|
|
|
let res: ExpressMock.ResponseMock;
|
|
|
|
let mocks: ServerVariablesMock;
|
|
|
|
let vars: ServerVariables;
|
2017-05-25 13:09:29 +00:00
|
|
|
|
2017-10-17 21:24:02 +00:00
|
|
|
beforeEach(function () {
|
|
|
|
req = {
|
2017-11-01 13:24:18 +00:00
|
|
|
originalUrl: "/non-api/xxx",
|
2017-10-17 21:24:02 +00:00
|
|
|
query: {
|
|
|
|
userid: "user"
|
|
|
|
},
|
|
|
|
session: {
|
|
|
|
auth: {
|
|
|
|
userid: "user",
|
|
|
|
email: "user@example.com",
|
|
|
|
first_factor: true,
|
|
|
|
second_factor: false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
headers: {
|
|
|
|
host: "localhost"
|
|
|
|
}
|
|
|
|
};
|
2017-05-25 13:09:29 +00:00
|
|
|
|
2017-10-17 21:24:02 +00:00
|
|
|
const options = {
|
|
|
|
inMemoryOnly: true
|
|
|
|
};
|
2017-05-25 13:09:29 +00:00
|
|
|
|
2017-10-17 21:24:02 +00:00
|
|
|
const s = ServerVariablesMockBuilder.build();
|
|
|
|
mocks = s.mocks;
|
|
|
|
vars = s.variables;
|
2017-05-25 13:09:29 +00:00
|
|
|
|
2017-10-17 21:24:02 +00: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 13:09:29 +00:00
|
|
|
|
2017-10-17 21:24:02 +00: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 13:09:29 +00:00
|
|
|
});
|
2017-10-17 21:24:02 +00:00
|
|
|
});
|
2017-05-25 13:09:29 +00:00
|
|
|
|
2017-10-17 21:24:02 +00: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 13:09:29 +00:00
|
|
|
});
|
2017-10-17 21:24:02 +00:00
|
|
|
});
|
2017-05-25 13:09:29 +00:00
|
|
|
|
2017-10-17 21:24:02 +00: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 13:09:29 +00:00
|
|
|
});
|
2017-10-17 21:24:02 +00:00
|
|
|
});
|
2017-05-25 13:09:29 +00:00
|
|
|
});
|