2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2025-09-06 09:10:25 +08:00
discourse/test/javascripts/acceptance/preferences-test.js.es6
Jeff Wong f4f8a293e7 FEATURE: Implement 2factor login TOTP
implemented review items.

Blocking previous codes - valid 2-factor auth tokens can only be authenticated once/30 seconds.
I played with updating the “last used” any time the token was attempted but that seemed to be overkill, and frustrating as to why a token would fail.
Translatable texts.
Move second factor logic to a helper class.
Move second factor specific controller endpoints to its own controller.
Move serialization logic for 2-factor details in admin user views.
Add a login ember component for de-duplication
Fix up code formatting
Change verbiage of google authenticator

add controller tests:
second factor controller tests
change email tests
change password tests
admin login tests

add qunit tests - password reset, preferences

fix: check for 2factor on change email controller
fix: email controller - only show second factor errors on attempt
fix: check against 'true' to enable second factor.

Add modal for explaining what 2fa with links to Google Authenticator/FreeOTP

add two factor to email signin link

rate limit if second factor token present

add rate limiter test for second factor attempts
2018-02-21 09:04:07 +08:00

103 lines
3.1 KiB
JavaScript

import { acceptance } from "helpers/qunit-helpers";
acceptance("User Preferences", {
loggedIn: true,
beforeEach() {
const response = (object) => {
return [
200,
{"Content-Type": "application/json"},
object
];
};
server.post('/second_factor/create', () => { //eslint-disable-line
return response({key: "rcyryaqage3jexfj", qr: '<div id="test-qr">qr-code</div>'});
});
}
});
QUnit.test("update some fields", assert => {
visit("/u/eviltrout/preferences");
andThen(() => {
assert.ok($('body.user-preferences-page').length, "has the body class");
assert.equal(currentURL(), '/u/eviltrout/preferences/account', "defaults to account tab");
assert.ok(exists('.user-preferences'), 'it shows the preferences');
});
const savePreferences = () => {
click('.save-user');
assert.ok(!exists('.saved-user'), "it hasn't been saved yet");
andThen(() => {
assert.ok(exists('.saved-user'), 'it displays the saved message');
});
};
fillIn(".pref-name input[type=text]", "Jon Snow");
savePreferences();
click(".preferences-nav .nav-profile a");
fillIn("#edit-location", "Westeros");
savePreferences();
click(".preferences-nav .nav-emails a");
click(".pref-activity-summary input[type=checkbox]");
savePreferences();
click(".preferences-nav .nav-notifications a");
selectKit('.control-group.notifications .combo-box.duration').expand().selectRowByValue(1440);
savePreferences();
click(".preferences-nav .nav-categories a");
fillIn('.category-controls .category-selector', 'faq');
savePreferences();
assert.ok(!exists('.preferences-nav .nav-tags a'), "tags tab isn't there when tags are disabled");
// Error: Unhandled request in test environment: /themes/assets/10d71596-7e4e-4dc0-b368-faa3b6f1ce6d?_=1493833562388 (GET)
// click(".preferences-nav .nav-interface a");
// click('.control-group.other input[type=checkbox]:first');
// savePreferences();
assert.ok(!exists('.preferences-nav .nav-apps a'), "apps tab isn't there when you have no authorized apps");
});
QUnit.test("username", assert => {
visit("/u/eviltrout/preferences/username");
andThen(() => {
assert.ok(exists("#change_username"), "it has the input element");
});
});
QUnit.test("about me", assert => {
visit("/u/eviltrout/preferences/about-me");
andThen(() => {
assert.ok(exists(".raw-bio"), "it has the input element");
});
});
QUnit.test("email", assert => {
visit("/u/eviltrout/preferences/email");
andThen(() => {
assert.ok(exists("#change-email"), "it has the input element");
});
fillIn("#change-email", 'invalidemail');
andThen(() => {
assert.equal(find('.tip.bad').text().trim(), I18n.t('user.email.invalid'), 'it should display invalid email tip');
});
});
QUnit.test("second factor", assert => {
visit("/u/eviltrout/preferences/second-factor");
andThen(() => {
assert.ok(exists("#password"), "it has a password input");
});
fillIn('#password', 'secrets');
click(".user-content .btn-primary");
andThen(() => {
assert.ok(exists("#test-qr"), "shows qr code");
assert.notOk(exists("#password"), "it hides the password input");
});
});