Skip to content
Snippets Groups Projects
Commit 568a276c authored by Lloyd Hilaiel's avatar Lloyd Hilaiel
Browse files

Merge pull request #2069 from mozilla/password_length_refactor

Instead of hard coding 8 and 80, use named constants.
parents 684b785a cba99176
No related branches found
No related tags found
No related merge requests found
......@@ -61,7 +61,7 @@ BrowserID.Validation = (function() {
}
function passwordLength(password) {
var valid = password && (password.length >= 8 && password.length <= 80);
var valid = password && (password.length >= bid.PASSWORD_MIN_LENGTH && password.length <= bid.PASSWORD_MAX_LENGTH);
if(!valid) {
tooltip.showTooltip("#password_length");
......
......@@ -147,7 +147,7 @@ BrowserID.manageAccount = (function() {
tooltip.showTooltip("#tooltipPasswordsSame");
complete(false);
}
else if(newPassword.length < 8 || 80 < newPassword.length) {
else if(newPassword.length < bid.PASSWORD_MIN_LENGTH || bid.PASSWORD_MAX_LENGTH < newPassword.length) {
tooltip.showTooltip("#tooltipPasswordLength");
complete(false);
}
......
......@@ -8,6 +8,7 @@
var bid = BrowserID,
validation = bid.Validation,
testHelpers = bid.TestHelpers,
tooltipShown,
origShowTooltip;
......@@ -205,21 +206,19 @@
test("passwordAndValidationPassword with too short password", function() {
var valid = validation.passwordAndValidationPassword("pass", "password");
var tooShort = testHelpers.generateString(bid.PASSWORD_MIN_LENGTH - 1);
var valid = validation.passwordAndValidationPassword(tooShort, tooShort);
equal(valid, false, "too short password is invalid");
equal(tooltipShown, true, "too short password shows tooltip");
});
test("passwordAndValidationPassword with too long password", function() {
var tooLong = "";
for(var i = 0; i < 81; i++) {
tooLong += (i % 10);
}
var tooLong = testHelpers.generateString(bid.PASSWORD_MAX_LENGTH + 1);
var valid = validation.passwordAndValidationPassword(tooLong, tooLong);
equal(valid, false, "too short password is invalid");
equal(tooltipShown, true, "too short password shows tooltip");
equal(valid, false, "too long password is invalid");
equal(tooltipShown, true, "too long password shows tooltip");
});
test("passwordAndValidationPassword with empty validation password", function() {
......
......@@ -72,14 +72,14 @@
asyncTest("requestPasswordReset with too short of a password", function() {
$("#email").val("unregistered@testuser.com");
$("#password,#vpassword").val("fail");
$("#password,#vpassword").val(testHelpers.generateString(bid.PASSWORD_MIN_LENGTH - 1));
testEmailNotSent();
});
asyncTest("requestPasswordReset with too long of a password", function() {
$("#email").val("unregistered@testuser.com");
$("#password,#vpassword").val(testHelpers.generateString(81));
$("#password,#vpassword").val(testHelpers.generateString(bid.PASSWORD_MAX_LENGTH + 1));
testEmailNotSent();
});
......
......@@ -96,7 +96,7 @@
});
});
});
asyncTest("removeEmail doesn't cancel the account when removing a non-existent e-mail", function() {
bid.manageAccount(mocks, function() {
bid.manageAccount.removeEmail("non@existent.com", function() {
......@@ -105,7 +105,7 @@
});
});
});
asyncTest("removeEmail doesn't cancel the account when out of sync with the server", function() {
bid.manageAccount(mocks, function() {
xhr.useResult("multiple");
......@@ -206,7 +206,7 @@
asyncTest("changePassword with too short of a password - tooltip", function() {
bid.manageAccount(mocks, function() {
$("#old_password").val("oldpassword");
$("#new_password").val("pass");
$("#new_password").val(testHelpers.generateString(bid.PASSWORD_MIN_LENGTH - 1));
bid.manageAccount.changePassword(function(status) {
equal(status, false, "on too short of a password, status is false");
......@@ -219,7 +219,7 @@
asyncTest("changePassword with too long of a password - tooltip", function() {
bid.manageAccount(mocks, function() {
$("#old_password").val("oldpassword");
$("#new_password").val(testHelpers.generateString(81));
$("#new_password").val(testHelpers.generateString(bid.PASSWORD_MAX_LENGTH + 1));
bid.manageAccount.changePassword(function(status) {
equal(status, false, "on too long of a password, status is false");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment