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