2022-06-19 00:25:21 +00:00
|
|
|
import {expect} from "chai";
|
|
|
|
import Helper from "../../server/helper";
|
2016-10-21 19:00:43 +00:00
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
describe("Client passwords", function () {
|
2017-11-27 23:47:19 +00:00
|
|
|
this.slow(1500);
|
|
|
|
|
2016-10-21 19:00:43 +00:00
|
|
|
const inputPassword = "my$Super@Cool Password";
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
it("hashed password should match", function () {
|
2016-10-21 19:00:43 +00:00
|
|
|
// Generated with third party tool to test implementation
|
2019-07-17 09:33:59 +00:00
|
|
|
const comparedPassword = Helper.password.compare(
|
|
|
|
inputPassword,
|
|
|
|
"$2a$11$zrPPcfZ091WNfs6QrRHtQeUitlgrJcecfZhxOFiQs0FWw7TN3Q1oS"
|
|
|
|
);
|
2016-10-21 19:00:43 +00:00
|
|
|
|
2017-04-08 12:34:31 +00:00
|
|
|
return comparedPassword.then((result) => {
|
2017-03-23 07:47:51 +00:00
|
|
|
expect(result).to.be.true;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
it("wrong hashed password should not match", function () {
|
2017-03-23 07:47:51 +00:00
|
|
|
// Compare against a fake hash
|
2019-07-17 09:33:59 +00:00
|
|
|
const comparedPassword = Helper.password.compare(
|
|
|
|
inputPassword,
|
|
|
|
"$2a$11$zrPPcfZ091WRONGPASSWORDitlgrJcecfZhxOFiQs0FWw7TN3Q1oS"
|
|
|
|
);
|
2017-03-23 07:47:51 +00:00
|
|
|
|
2017-04-08 12:34:31 +00:00
|
|
|
return comparedPassword.then((result) => {
|
2017-03-23 07:47:51 +00:00
|
|
|
expect(result).to.be.false;
|
|
|
|
});
|
2016-10-21 19:00:43 +00:00
|
|
|
});
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
it("freshly hashed password should match", function () {
|
2017-04-08 12:34:31 +00:00
|
|
|
const hashedPassword = Helper.password.hash(inputPassword);
|
|
|
|
const comparedPassword = Helper.password.compare(inputPassword, hashedPassword);
|
2016-10-21 19:00:43 +00:00
|
|
|
|
2017-03-23 07:47:51 +00:00
|
|
|
return comparedPassword.then((result) => {
|
|
|
|
expect(result).to.be.true;
|
|
|
|
});
|
2016-10-21 19:00:43 +00:00
|
|
|
});
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
it("shout passwords should be marked as old", function () {
|
2019-07-17 09:33:59 +00:00
|
|
|
expect(
|
|
|
|
Helper.password.requiresUpdate(
|
|
|
|
"$2a$08$K4l.hteJcCP9D1G5PANzYuBGvdqhUSUDOLQLU.xeRxTbvtp01KINm"
|
|
|
|
)
|
|
|
|
).to.be.true;
|
|
|
|
expect(
|
|
|
|
Helper.password.requiresUpdate(
|
|
|
|
"$2a$11$zrPPcfZ091WNfs6QrRHtQeUitlgrJcecfZhxOFiQs0FWw7TN3Q1oS"
|
|
|
|
)
|
|
|
|
).to.be.false;
|
2016-10-21 19:00:43 +00:00
|
|
|
});
|
|
|
|
});
|