2017-01-31 15:42:12 -05:00
|
|
|
import { acceptance } from "helpers/qunit-helpers";
|
|
|
|
import PreloadStore from 'preload-store';
|
|
|
|
import { parsePostData } from "helpers/create-pretender";
|
|
|
|
|
|
|
|
acceptance("Password Reset", {
|
2017-06-14 13:57:58 -04:00
|
|
|
beforeEach() {
|
2017-01-31 15:42:12 -05:00
|
|
|
const response = (object) => {
|
|
|
|
return [
|
|
|
|
200,
|
|
|
|
{"Content-Type": "application/json"},
|
|
|
|
object
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
2017-03-28 12:16:58 -04:00
|
|
|
server.get('/u/confirm-email-token/myvalidtoken.json', () => { //eslint-disable-line
|
2017-01-31 15:42:12 -05:00
|
|
|
return response({success: "OK"});
|
|
|
|
});
|
|
|
|
|
2017-03-28 12:16:58 -04:00
|
|
|
server.put('/u/password-reset/myvalidtoken.json', request => { //eslint-disable-line
|
2017-01-31 15:42:12 -05:00
|
|
|
const body = parsePostData(request.requestBody);
|
|
|
|
if (body.password === "jonesyAlienSlayer") {
|
|
|
|
return response({success: false, errors: {password: ["is the name of your cat"]}});
|
|
|
|
} else {
|
|
|
|
return response({success: "OK", message: I18n.t('password_reset.success')});
|
|
|
|
}
|
|
|
|
});
|
2017-12-21 20:18:12 -05:00
|
|
|
|
|
|
|
server.get('/u/confirm-email-token/requiretwofactor.json', () => { //eslint-disable-line
|
2018-02-20 01:44:51 -05:00
|
|
|
return response({ success: "OK" });
|
2017-12-21 20:18:12 -05:00
|
|
|
});
|
2018-02-20 01:44:51 -05:00
|
|
|
|
2017-12-21 20:18:12 -05:00
|
|
|
server.put('/u/password-reset/requiretwofactor.json', request => { //eslint-disable-line
|
|
|
|
const body = parsePostData(request.requestBody);
|
|
|
|
if (body.password === "perf3ctly5ecur3" && body.second_factor_token === "123123") {
|
2018-02-20 01:44:51 -05:00
|
|
|
return response({ success: "OK", message: I18n.t('password_reset.success') });
|
2017-12-21 20:18:12 -05:00
|
|
|
} else if (body.second_factor_token === "123123") {
|
2018-02-20 01:44:51 -05:00
|
|
|
return response({ success: false, errors: { password: ["invalid"] } });
|
2017-12-21 20:18:12 -05:00
|
|
|
} else {
|
2018-02-20 01:44:51 -05:00
|
|
|
return response({
|
|
|
|
success: false,
|
|
|
|
message: "invalid token",
|
|
|
|
errors: { user_second_factor: ["invalid token"] }
|
|
|
|
});
|
2017-12-21 20:18:12 -05:00
|
|
|
}
|
|
|
|
});
|
2017-01-31 15:42:12 -05:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-06-14 13:57:58 -04:00
|
|
|
QUnit.test("Password Reset Page", assert => {
|
2017-01-31 15:42:12 -05:00
|
|
|
PreloadStore.store('password_reset', {is_developer: false});
|
|
|
|
|
2017-03-28 14:27:54 -04:00
|
|
|
visit("/u/password-reset/myvalidtoken");
|
2017-01-31 15:42:12 -05:00
|
|
|
andThen(() => {
|
2017-06-14 13:57:58 -04:00
|
|
|
assert.ok(exists(".password-reset input"), "shows the input");
|
2017-01-31 15:42:12 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
fillIn('.password-reset input', 'perf3ctly5ecur3');
|
|
|
|
andThen(() => {
|
2017-06-14 13:57:58 -04:00
|
|
|
assert.ok(exists(".password-reset .tip.good"), "input looks good");
|
2017-01-31 15:42:12 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
fillIn('.password-reset input', '123');
|
|
|
|
andThen(() => {
|
2017-06-14 13:57:58 -04:00
|
|
|
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");
|
2017-01-31 15:42:12 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
fillIn('.password-reset input', 'jonesyAlienSlayer');
|
|
|
|
click('.password-reset form button');
|
|
|
|
andThen(() => {
|
2017-06-14 13:57:58 -04:00
|
|
|
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");
|
2017-01-31 15:42:12 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
fillIn('.password-reset input', 'perf3ctly5ecur3');
|
|
|
|
click('.password-reset form button');
|
|
|
|
andThen(() => {
|
2017-06-14 13:57:58 -04:00
|
|
|
assert.ok(!exists(".password-reset form"), "form is gone");
|
2017-01-31 15:42:12 -05:00
|
|
|
});
|
2017-12-21 20:18:12 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
QUnit.test("Password Reset Page With Second Factor", assert => {
|
2018-02-20 01:44:51 -05:00
|
|
|
PreloadStore.store('password_reset', {
|
|
|
|
is_developer: false,
|
|
|
|
second_factor_required: true
|
|
|
|
});
|
2017-12-21 20:18:12 -05:00
|
|
|
|
|
|
|
visit("/u/password-reset/requiretwofactor");
|
2018-02-20 01:44:51 -05:00
|
|
|
|
2017-12-21 20:18:12 -05:00
|
|
|
andThen(() => {
|
|
|
|
assert.notOk(exists("#new-account-password"), "does not show the input");
|
|
|
|
assert.ok(exists("#second-factor"), "shows the second factor prompt");
|
|
|
|
});
|
|
|
|
|
|
|
|
fillIn('#second-factor', '0000');
|
|
|
|
click('.password-reset form button');
|
2018-02-20 01:44:51 -05:00
|
|
|
|
2017-12-21 20:18:12 -05:00
|
|
|
andThen(() => {
|
|
|
|
assert.ok(exists(".alert-error"), "shows 2 factor error");
|
2018-02-20 01:44:51 -05:00
|
|
|
|
|
|
|
assert.ok(
|
|
|
|
find(".alert-error").html().indexOf("invalid token") > -1,
|
|
|
|
"shows server validation error message"
|
|
|
|
);
|
2017-12-21 20:18:12 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
fillIn('#second-factor', '123123');
|
|
|
|
click('.password-reset form button');
|
2018-02-20 01:44:51 -05:00
|
|
|
|
2017-12-21 20:18:12 -05:00
|
|
|
andThen(() => {
|
|
|
|
assert.notOk(exists(".alert-error"), "hides error");
|
|
|
|
assert.ok(exists("#new-account-password"), "shows the input");
|
|
|
|
});
|
|
|
|
|
|
|
|
fillIn('.password-reset input', 'perf3ctly5ecur3');
|
|
|
|
click('.password-reset form button');
|
2018-02-20 01:44:51 -05:00
|
|
|
|
2017-12-21 20:18:12 -05:00
|
|
|
andThen(() => {
|
|
|
|
assert.ok(!exists(".password-reset form"), "form is gone");
|
|
|
|
});
|
|
|
|
});
|