2020-05-14 10:04:08 -04:00
|
|
|
import I18n from "I18n";
|
2017-01-31 15:42:12 -05:00
|
|
|
import { acceptance } from "helpers/qunit-helpers";
|
2020-05-06 15:28:06 -04:00
|
|
|
import PreloadStore from "discourse/lib/preload-store";
|
2017-01-31 15:42:12 -05:00
|
|
|
import { parsePostData } from "helpers/create-pretender";
|
|
|
|
|
|
|
|
acceptance("Password Reset", {
|
2018-07-26 06:16:32 -04:00
|
|
|
pretend(server, helper) {
|
|
|
|
server.get("/u/confirm-email-token/myvalidtoken.json", () =>
|
|
|
|
helper.response(200, { success: "OK" })
|
|
|
|
);
|
|
|
|
|
|
|
|
server.get("/u/confirm-email-token/requiretwofactor.json", () =>
|
|
|
|
helper.response(200, { success: "OK" })
|
|
|
|
);
|
2017-01-31 15:42:12 -05:00
|
|
|
|
2018-07-26 06:16:32 -04:00
|
|
|
server.put("/u/password-reset/myvalidtoken.json", request => {
|
2017-01-31 15:42:12 -05:00
|
|
|
const body = parsePostData(request.requestBody);
|
|
|
|
if (body.password === "jonesyAlienSlayer") {
|
2018-07-26 06:16:32 -04:00
|
|
|
return helper.response(200, {
|
2018-06-15 11:03:24 -04:00
|
|
|
success: false,
|
|
|
|
errors: { password: ["is the name of your cat"] }
|
|
|
|
});
|
2017-01-31 15:42:12 -05:00
|
|
|
} else {
|
2018-07-26 06:16:32 -04:00
|
|
|
return helper.response(200, {
|
2018-06-15 11:03:24 -04:00
|
|
|
success: "OK",
|
|
|
|
message: I18n.t("password_reset.success")
|
|
|
|
});
|
2017-01-31 15:42:12 -05:00
|
|
|
}
|
|
|
|
});
|
2017-12-21 20:18:12 -05:00
|
|
|
|
2018-07-26 06:16:32 -04:00
|
|
|
server.put("/u/password-reset/requiretwofactor.json", request => {
|
2017-12-21 20:18:12 -05:00
|
|
|
const body = parsePostData(request.requestBody);
|
2018-06-15 11:03:24 -04:00
|
|
|
if (
|
|
|
|
body.password === "perf3ctly5ecur3" &&
|
|
|
|
body.second_factor_token === "123123"
|
|
|
|
) {
|
2018-07-26 06:16:32 -04:00
|
|
|
return helper.response(200, {
|
2018-06-15 11:03:24 -04:00
|
|
|
success: "OK",
|
|
|
|
message: I18n.t("password_reset.success")
|
|
|
|
});
|
2017-12-21 20:18:12 -05:00
|
|
|
} else if (body.second_factor_token === "123123") {
|
2018-07-26 06:16:32 -04:00
|
|
|
return helper.response(200, {
|
|
|
|
success: false,
|
|
|
|
errors: { password: ["invalid"] }
|
|
|
|
});
|
2017-12-21 20:18:12 -05:00
|
|
|
} else {
|
2018-07-26 06:16:32 -04:00
|
|
|
return helper.response(200, {
|
2018-02-20 01:44:51 -05:00
|
|
|
success: false,
|
|
|
|
message: "invalid token",
|
2018-06-28 04:12:32 -04:00
|
|
|
errors: { user_second_factors: ["invalid token"] }
|
2018-02-20 01:44:51 -05:00
|
|
|
});
|
2017-12-21 20:18:12 -05:00
|
|
|
}
|
|
|
|
});
|
2017-01-31 15:42:12 -05:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-07-26 06:16:32 -04:00
|
|
|
QUnit.test("Password Reset Page", async assert => {
|
2018-06-15 11:03:24 -04:00
|
|
|
PreloadStore.store("password_reset", { is_developer: false });
|
2017-01-31 15:42:12 -05:00
|
|
|
|
2018-07-26 06:16:32 -04:00
|
|
|
await visit("/u/password-reset/myvalidtoken");
|
|
|
|
assert.ok(exists(".password-reset input"), "shows the input");
|
|
|
|
|
|
|
|
await fillIn(".password-reset input", "perf3ctly5ecur3");
|
|
|
|
assert.ok(exists(".password-reset .tip.good"), "input looks good");
|
|
|
|
|
|
|
|
await fillIn(".password-reset input", "123");
|
|
|
|
assert.ok(exists(".password-reset .tip.bad"), "input is not valid");
|
|
|
|
assert.ok(
|
|
|
|
find(".password-reset .tip.bad")
|
|
|
|
.html()
|
|
|
|
.indexOf(I18n.t("user.password.too_short")) > -1,
|
|
|
|
"password too short"
|
|
|
|
);
|
|
|
|
|
|
|
|
await fillIn(".password-reset input", "jonesyAlienSlayer");
|
|
|
|
await click(".password-reset form button");
|
|
|
|
assert.ok(exists(".password-reset .tip.bad"), "input is not valid");
|
|
|
|
assert.ok(
|
|
|
|
find(".password-reset .tip.bad")
|
|
|
|
.html()
|
|
|
|
.indexOf("is the name of your cat") > -1,
|
|
|
|
"server validation error message shows"
|
|
|
|
);
|
|
|
|
|
|
|
|
await fillIn(".password-reset input", "perf3ctly5ecur3");
|
|
|
|
await click(".password-reset form button");
|
|
|
|
assert.ok(!exists(".password-reset form"), "form is gone");
|
2017-12-21 20:18:12 -05:00
|
|
|
});
|
|
|
|
|
2018-07-26 06:16:32 -04:00
|
|
|
QUnit.test("Password Reset Page With Second Factor", async assert => {
|
2018-06-15 11:03:24 -04:00
|
|
|
PreloadStore.store("password_reset", {
|
2018-02-20 01:44:51 -05:00
|
|
|
is_developer: false,
|
|
|
|
second_factor_required: true
|
|
|
|
});
|
2017-12-21 20:18:12 -05:00
|
|
|
|
2018-07-26 06:16:32 -04:00
|
|
|
await visit("/u/password-reset/requiretwofactor");
|
2018-02-20 01:44:51 -05:00
|
|
|
|
2018-07-26 06:16:32 -04:00
|
|
|
assert.notOk(exists("#new-account-password"), "does not show the input");
|
|
|
|
assert.ok(exists("#second-factor"), "shows the second factor prompt");
|
2017-12-21 20:18:12 -05:00
|
|
|
|
2018-07-26 06:16:32 -04:00
|
|
|
await fillIn("input#second-factor", "0000");
|
|
|
|
await click(".password-reset form button");
|
2018-02-20 01:44:51 -05:00
|
|
|
|
2018-07-26 06:16:32 -04:00
|
|
|
assert.ok(exists(".alert-error"), "shows 2 factor error");
|
2018-02-20 01:44:51 -05:00
|
|
|
|
2018-07-26 06:16:32 -04:00
|
|
|
assert.ok(
|
|
|
|
find(".alert-error")
|
|
|
|
.html()
|
|
|
|
.indexOf("invalid token") > -1,
|
|
|
|
"shows server validation error message"
|
|
|
|
);
|
2017-12-21 20:18:12 -05:00
|
|
|
|
2018-07-26 06:16:32 -04:00
|
|
|
await fillIn("input#second-factor", "123123");
|
|
|
|
await click(".password-reset form button");
|
2018-02-20 01:44:51 -05:00
|
|
|
|
2018-07-26 06:16:32 -04:00
|
|
|
assert.notOk(exists(".alert-error"), "hides error");
|
|
|
|
assert.ok(exists("#new-account-password"), "shows the input");
|
2017-12-21 20:18:12 -05:00
|
|
|
|
2018-07-26 06:16:32 -04:00
|
|
|
await fillIn(".password-reset input", "perf3ctly5ecur3");
|
|
|
|
await click(".password-reset form button");
|
2018-02-20 01:44:51 -05:00
|
|
|
|
2018-07-26 06:16:32 -04:00
|
|
|
assert.ok(!exists(".password-reset form"), "form is gone");
|
2017-12-21 20:18:12 -05:00
|
|
|
});
|