mirror of
https://github.com/zulip/zulip.git
synced 2025-11-03 13:33:24 +00:00
js: Extract password_quality module; remove zxcvbn from globals.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
committed by
Tim Abbott
parent
84f1e27516
commit
bf056c8990
@@ -2,12 +2,10 @@
|
||||
|
||||
const {strict: assert} = require("assert");
|
||||
|
||||
const {set_global, with_field, zrequire} = require("../zjsunit/namespace");
|
||||
const {zrequire} = require("../zjsunit/namespace");
|
||||
const {run_test} = require("../zjsunit/test");
|
||||
|
||||
set_global("zxcvbn", require("zxcvbn"));
|
||||
|
||||
const common = zrequire("common");
|
||||
const {password_quality, password_warning} = zrequire("password_quality");
|
||||
|
||||
function password_field(min_length, min_guesses) {
|
||||
const self = {};
|
||||
@@ -51,41 +49,25 @@ run_test("basics w/progress bar", () => {
|
||||
})();
|
||||
|
||||
password = "z!X4@S_&";
|
||||
accepted = common.password_quality(password, bar, password_field(10, 80000));
|
||||
accepted = password_quality(password, bar, password_field(10, 80000));
|
||||
assert(!accepted);
|
||||
assert.equal(bar.w, "39.7%");
|
||||
assert.equal(bar.added_class, "bar-danger");
|
||||
warning = common.password_warning(password, password_field(10));
|
||||
warning = password_warning(password, password_field(10));
|
||||
assert.equal(warning, "translated: Password should be at least 10 characters long");
|
||||
|
||||
password = "foo";
|
||||
accepted = common.password_quality(password, bar, password_field(2, 200));
|
||||
accepted = password_quality(password, bar, password_field(2, 200));
|
||||
assert(accepted);
|
||||
assert.equal(bar.w, "10.390277164940581%");
|
||||
assert.equal(bar.added_class, "bar-success");
|
||||
warning = common.password_warning(password, password_field(2));
|
||||
warning = password_warning(password, password_field(2));
|
||||
assert.equal(warning, "translated: Password is too weak");
|
||||
|
||||
password = "aaaaaaaa";
|
||||
accepted = common.password_quality(password, bar, password_field(6, 1e100));
|
||||
accepted = password_quality(password, bar, password_field(6, 1e100));
|
||||
assert(!accepted);
|
||||
assert.equal(bar.added_class, "bar-danger");
|
||||
warning = common.password_warning(password, password_field(6));
|
||||
warning = password_warning(password, password_field(6));
|
||||
assert.equal(warning, 'Repeats like "aaa" are easy to guess');
|
||||
});
|
||||
|
||||
run_test("zxcvbn undefined", () => {
|
||||
// According to common.js, we load zxcvbn.js asynchronously, so the
|
||||
// variable might not be set. This just gets line coverage on the
|
||||
// defensive code.
|
||||
|
||||
const password = "aaaaaaaa";
|
||||
const progress_bar = undefined;
|
||||
|
||||
with_field(global, "zxcvbn", undefined, () => {
|
||||
const accepted = common.password_quality(password, progress_bar, password_field(6, 1e100));
|
||||
assert(accepted === undefined);
|
||||
const warning = common.password_warning(password, password_field(6));
|
||||
assert(warning === undefined);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user