Test that passwords containing the username are penalised.

Tidy up some spelling, indentation and whitespace whilst we're at it.

Props iandunn. See #25088.


git-svn-id: https://develop.svn.wordpress.org/trunk@25175 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Jon Cave 2013-08-29 22:28:32 +00:00
parent 7e5192393a
commit 94e03ce09f
1 changed files with 60 additions and 48 deletions

View File

@ -1,20 +1,20 @@
jQuery(function() {
module('password-strength-meter');
test('missmached passwords should return 5', function(){
equal( passwordStrength( 'password1', 'username', 'password2' ) , 5, 'miss matched passwords return 5');
test('mismatched passwords should return 5', function(){
equal( passwordStrength( 'password1', 'username', 'password2' ) , 5, 'mismatched passwords return 5');
});
test('passwords shorter than 4 charachters should return 0', function(){
test('passwords shorter than 4 characters should return 0', function(){
equal( passwordStrength( 'abc', 'username', 'abc' ) , 0, 'short passwords return 0');
});
test('long complicated passwords should return 4', function(){
var password = function( length ){
var possability = 'abcdefghijklnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',
var possibility = 'abcdefghijklnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',
retVal = "";
for( var i = 0, n = possability.length; i < length; ++i) {
retVal += possability.charAt( Math.floor( Math.random() * n ) );
for (var i = 0, n = possibility.length; i < length; ++i) {
retVal += possibility.charAt( Math.floor( Math.random() * n ) );
}
return retVal + 'aB2'; // add a lower case, uppercase and number just to make sure we always have one of each
},
@ -34,7 +34,7 @@ jQuery(function() {
equal( passwordStrength( password, 'username', password ), 0, 'password of `' + password + '` returns 0' );
});
test('zxcvbn passward tests should return the score we expect', function(){
test('zxcvbn password tests should return the score we expect', function(){
var passwords = [
{ pw: 'zxcvbn', score: 0},
{ pw: 'qwER43@!', score: 1},
@ -72,8 +72,20 @@ jQuery(function() {
{ pw: 'Ba9ZyWABu99[BK#6MBgbH88Tofv)vs$w', score: 4}
];
for(var i=0; i < passwords.length; i++) {
for (var i=0; i < passwords.length; i++) {
equal( passwordStrength( passwords[i].pw, 'username', passwords[i].pw ), passwords[i].score, 'password of `' + passwords[i].pw + '` returns '+passwords[i].score );
}
});
test( 'username in password should be penalized', function() {
var allowedPasswordScore, penalizedPasswordScore,
allowedPassword = 'a[janedoe]4',
penalizedPassword = 'a[johndoe]4',
username = 'johndoe';
allowedPasswordScore = passwordStrength( allowedPassword, username, allowedPassword );
penalizedPasswordScore = passwordStrength( penalizedPassword, username, penalizedPassword );
ok( penalizedPasswordScore < allowedPasswordScore, 'Penalized password scored ' + penalizedPasswordScore + '; allowed password scored: ' + allowedPasswordScore );
} );
});