2017-01-09 21:51:22 +01:00
|
|
|
add_dependencies({
|
|
|
|
zxcvbn: 'node_modules/zxcvbn/dist/zxcvbn.js',
|
|
|
|
});
|
|
|
|
|
2017-06-29 16:26:48 +02:00
|
|
|
set_global('i18n', global.stub_i18n);
|
|
|
|
|
2017-01-09 21:51:22 +01:00
|
|
|
var common = require("js/common.js");
|
|
|
|
|
|
|
|
(function test_basics() {
|
|
|
|
var accepted;
|
|
|
|
var password;
|
2017-06-29 16:26:48 +02:00
|
|
|
var warning;
|
2017-01-09 21:51:22 +01:00
|
|
|
|
|
|
|
var bar = (function () {
|
|
|
|
var self = {};
|
|
|
|
|
|
|
|
self.width = function (width) {
|
|
|
|
self.w = width;
|
|
|
|
return self;
|
|
|
|
};
|
|
|
|
|
|
|
|
self.removeClass = function (arg) {
|
|
|
|
assert.equal(arg, 'bar-success bar-danger');
|
|
|
|
return self;
|
|
|
|
};
|
|
|
|
|
|
|
|
self.addClass = function (arg) {
|
|
|
|
self.added_class = arg;
|
|
|
|
return self;
|
|
|
|
};
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}());
|
|
|
|
|
|
|
|
function password_field(min_length, min_quality) {
|
|
|
|
var self = {};
|
|
|
|
|
|
|
|
self.data = function (field) {
|
|
|
|
if (field === 'minLength') {
|
|
|
|
return min_length;
|
|
|
|
} else if (field === 'minQuality') {
|
|
|
|
return min_quality;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
password = 'z!X4@S_&';
|
|
|
|
accepted = common.password_quality(password, bar, password_field(10, 0.10));
|
|
|
|
assert(!accepted);
|
|
|
|
assert.equal(bar.w, '39.7%');
|
|
|
|
assert.equal(bar.added_class, 'bar-danger');
|
2017-06-29 16:26:48 +02:00
|
|
|
warning = common.password_warning(password, password_field(10));
|
|
|
|
assert.equal(warning, 'translated: Password should be at least 10 characters long');
|
2017-01-09 21:51:22 +01:00
|
|
|
|
|
|
|
password = 'foo';
|
|
|
|
accepted = common.password_quality(password, bar, password_field(2, 0.001));
|
|
|
|
assert(accepted);
|
|
|
|
assert.equal(bar.w, '10.390277164940581%');
|
|
|
|
assert.equal(bar.added_class, 'bar-success');
|
2017-06-29 16:26:48 +02:00
|
|
|
warning = common.password_warning(password, password_field(2));
|
|
|
|
assert.equal(warning, 'translated: Password is too weak');
|
2017-05-23 00:53:53 +02:00
|
|
|
|
|
|
|
password = 'aaaaaaaa';
|
|
|
|
accepted = common.password_quality(password, bar, password_field(6, 1000));
|
|
|
|
assert(!accepted);
|
|
|
|
assert.equal(bar.added_class, 'bar-danger');
|
2017-06-29 16:26:48 +02:00
|
|
|
warning = common.password_warning(password, password_field(6));
|
|
|
|
assert.equal(warning, 'Repeats like "aaa" are easy to guess');
|
2017-05-23 00:53:53 +02:00
|
|
|
|
|
|
|
delete global.zxcvbn;
|
|
|
|
password = 'aaaaaaaa';
|
|
|
|
accepted = common.password_quality(password, bar, password_field(6, 1000));
|
|
|
|
assert(accepted === undefined);
|
2017-06-29 16:26:48 +02:00
|
|
|
warning = common.password_warning(password, password_field(6));
|
|
|
|
assert(warning === undefined);
|
2017-01-09 21:51:22 +01:00
|
|
|
}());
|