Bug 619567: allow leading and trailing whitespace in pre-normalized passphrases. r=philiKON

This commit is contained in:
Richard Newman 2010-12-20 14:46:16 -08:00
Родитель a108a4e85b
Коммит f3265a73ed
2 изменённых файлов: 16 добавлений и 2 удалений

Просмотреть файл

@ -1309,7 +1309,8 @@ let Utils = {
normalizePassphrase: function normalizePassphrase(pp) {
// Short var name... have you seen the lines below?!
pp = pp.toLowerCase();
// Allow leading and trailing whitespace.
pp = pp.toLowerCase().replace(/^\s+/, "").replace(/\s+$/, "");
// 20-char sync key.
if (pp.length == 23 &&

Просмотреть файл

@ -47,12 +47,25 @@ function run_test() {
_("Normalize passphrase recognizes hyphens.");
do_check_eq(Utils.normalizePassphrase(hyphenated), pp);
_("Skip whitespace.");
do_check_eq("aaaaaaaaaaaaaaaaaaaaaaaaaa", Utils.normalizePassphrase("aaaaaaaaaaaaaaaaaaaaaaaaaa "));
do_check_eq("aaaaaaaaaaaaaaaaaaaaaaaaaa", Utils.normalizePassphrase(" aaaaaaaaaaaaaaaaaaaaaaaaaa"));
do_check_eq("aaaaaaaaaaaaaaaaaaaaaaaaaa", Utils.normalizePassphrase(" aaaaaaaaaaaaaaaaaaaaaaaaaa "));
do_check_eq("aaaaaaaaaaaaaaaaaaaaaaaaaa", Utils.normalizePassphrase(" a-aaaaa-aaaaa-aaaaa-aaaaa-aaaaa "));
do_check_true(Utils.isPassphrase("aaaaaaaaaaaaaaaaaaaaaaaaaa "));
do_check_true(Utils.isPassphrase(" aaaaaaaaaaaaaaaaaaaaaaaaaa"));
do_check_true(Utils.isPassphrase(" aaaaaaaaaaaaaaaaaaaaaaaaaa "));
do_check_true(Utils.isPassphrase(" a-aaaaa-aaaaa-aaaaa-aaaaa-aaaaa "));
do_check_false(Utils.isPassphrase(" -aaaaa-aaaaa-aaaaa-aaaaa-aaaaa "));
_("Normalizing 20-char passphrases.");
do_check_eq(Utils.normalizePassphrase("abcde-abcde-abcde-abcde"),
"abcdeabcdeabcdeabcde");
do_check_eq(Utils.normalizePassphrase("a-bcde-abcde-abcde-abcde"),
"a-bcde-abcde-abcde-abcde");
do_check_eq(Utils.normalizePassphrase(" abcde-abcde-abcde-abcde "),
"abcdeabcdeabcdeabcde");
_("Passphrase strength calculated according to the NIST algorithm.");
do_check_eq(Utils.passphraseStrength(""), 0);