2017-05-25 13:09:29 +00:00
|
|
|
|
2017-07-16 12:55:01 +00:00
|
|
|
import PasswordResetHandler from "../../../../../../src/server/lib/routes/password-reset/identity/PasswordResetHandler";
|
2017-07-16 15:37:13 +00:00
|
|
|
import PasswordUpdater = require("../../../../../../src/server/lib/ldap/PasswordUpdater");
|
|
|
|
import { ServerVariables } from "../../../../../../src/server/lib/ServerVariables";
|
2017-05-25 13:09:29 +00:00
|
|
|
import sinon = require("sinon");
|
|
|
|
import winston = require("winston");
|
|
|
|
import assert = require("assert");
|
|
|
|
import BluebirdPromise = require("bluebird");
|
|
|
|
|
|
|
|
import ExpressMock = require("../../../mocks/express");
|
|
|
|
import { UserDataStore } from "../../../mocks/UserDataStore";
|
|
|
|
import ServerVariablesMock = require("../../../mocks/ServerVariablesMock");
|
|
|
|
|
|
|
|
describe("test reset password identity check", function () {
|
|
|
|
let req: ExpressMock.RequestMock;
|
|
|
|
let res: ExpressMock.ResponseMock;
|
2017-07-16 15:37:13 +00:00
|
|
|
let userDataStore: UserDataStore;
|
2017-05-25 13:09:29 +00:00
|
|
|
let configuration: any;
|
2017-07-16 15:37:13 +00:00
|
|
|
let serverVariables: ServerVariables;
|
2017-05-25 13:09:29 +00:00
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
req = {
|
|
|
|
query: {
|
|
|
|
userid: "user"
|
|
|
|
},
|
|
|
|
app: {
|
|
|
|
get: sinon.stub()
|
|
|
|
},
|
|
|
|
session: {
|
|
|
|
auth_session: {
|
|
|
|
userid: "user",
|
|
|
|
email: "user@example.com",
|
|
|
|
first_factor: true,
|
|
|
|
second_factor: false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
headers: {
|
|
|
|
host: "localhost"
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const options = {
|
|
|
|
inMemoryOnly: true
|
|
|
|
};
|
|
|
|
|
2017-07-16 15:37:13 +00:00
|
|
|
serverVariables = ServerVariablesMock.mock(req.app);
|
2017-05-25 13:09:29 +00:00
|
|
|
|
|
|
|
|
2017-07-16 15:37:13 +00:00
|
|
|
userDataStore = UserDataStore();
|
|
|
|
userDataStore.set_u2f_meta.returns(BluebirdPromise.resolve({}));
|
|
|
|
userDataStore.get_u2f_meta.returns(BluebirdPromise.resolve({}));
|
|
|
|
userDataStore.issue_identity_check_token.returns(BluebirdPromise.resolve({}));
|
|
|
|
userDataStore.consume_identity_check_token.returns(BluebirdPromise.resolve({}));
|
|
|
|
serverVariables.userDataStore = userDataStore as any;
|
2017-05-25 13:09:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
configuration = {
|
|
|
|
ldap: {
|
|
|
|
base_dn: "dc=example,dc=com",
|
|
|
|
user_name_attribute: "cn"
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-07-16 15:37:13 +00:00
|
|
|
serverVariables.logger = winston;
|
|
|
|
serverVariables.config = configuration;
|
|
|
|
serverVariables.ldapEmailsRetriever = {
|
|
|
|
retrieve: sinon.stub()
|
|
|
|
} as any;
|
2017-05-25 13:09:29 +00:00
|
|
|
|
|
|
|
res = ExpressMock.ResponseMock();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("test reset password identity pre check", () => {
|
|
|
|
it("should fail when no userid is provided", function () {
|
|
|
|
req.query.userid = undefined;
|
|
|
|
const handler = new PasswordResetHandler();
|
|
|
|
return handler.preValidationInit(req as any)
|
|
|
|
.then(function () { return BluebirdPromise.reject("It should fail"); })
|
|
|
|
.catch(function (err: Error) {
|
|
|
|
return BluebirdPromise.resolve();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should fail if ldap fail", function (done) {
|
2017-07-16 15:37:13 +00:00
|
|
|
(serverVariables.ldapEmailsRetriever as any).retrieve.returns(BluebirdPromise.reject("Internal error"));
|
2017-05-25 13:09:29 +00:00
|
|
|
new PasswordResetHandler().preValidationInit(req as any)
|
|
|
|
.catch(function (err: Error) {
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should perform a search in ldap to find email address", function (done) {
|
|
|
|
configuration.ldap.user_name_attribute = "uid";
|
2017-07-16 15:37:13 +00:00
|
|
|
(serverVariables.ldapEmailsRetriever as any).retrieve.returns(BluebirdPromise.resolve([]));
|
2017-05-25 13:09:29 +00:00
|
|
|
new PasswordResetHandler().preValidationInit(req as any)
|
|
|
|
.then(function () {
|
2017-07-16 15:37:13 +00:00
|
|
|
assert.equal("user", (serverVariables.ldapEmailsRetriever as any).retrieve.getCall(0).args[0]);
|
2017-05-25 13:09:29 +00:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should returns identity when ldap replies", function (done) {
|
2017-07-16 15:37:13 +00:00
|
|
|
(serverVariables.ldapEmailsRetriever as any).retrieve.returns(BluebirdPromise.resolve(["test@example.com"]));
|
2017-05-25 13:09:29 +00:00
|
|
|
new PasswordResetHandler().preValidationInit(req as any)
|
|
|
|
.then(function () {
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|