Make WordPress Core

Changeset 25175


Ignore:
Timestamp:
08/29/2013 10:28:32 PM (11 years ago)
Author:
duck_
Message:

Test that passwords containing the username are penalised.

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

Props iandunn. See #25088.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/qunit/wp-admin/js/password-strength-meter.js

    r25167 r25175  
    22    module('password-strength-meter');
    33
    4     test('missmached passwords should return 5', function(){
    5         equal( passwordStrength( 'password1',  'username', 'password2' ) , 5, 'miss matched passwords return 5');
     4    test('mismatched passwords should return 5', function(){
     5        equal( passwordStrength( 'password1',  'username', 'password2' ) , 5, 'mismatched passwords return 5');
    66    });
    77
    8     test('passwords shorter than 4 charachters should return 0', function(){
     8    test('passwords shorter than 4 characters should return 0', function(){
    99        equal( passwordStrength( 'abc',  'username', 'abc' ) , 0, 'short passwords return 0');
    1010    });
     
    1212    test('long complicated passwords should return 4', function(){
    1313        var password = function( length ){
    14             var possability = 'abcdefghijklnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',
     14            var possibility = 'abcdefghijklnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',
    1515                retVal = "";
    16             for( var i = 0, n = possability.length; i < length; ++i) {
    17                 retVal += possability.charAt( Math.floor( Math.random() * n ) );
     16            for (var i = 0, n = possibility.length; i < length; ++i) {
     17                retVal += possibility.charAt( Math.floor( Math.random() * n ) );
    1818            }
    1919            return retVal + 'aB2'; // add a lower case, uppercase and number just to make sure we always have one of each
     
    2727        var letters = 'aaaa',
    2828            numbers = '1111',
    29             password = 'password',
     29            password = 'password',
    3030            uppercase = 'AAAA';
    3131        equal( passwordStrength( letters, 'username', letters ), 0, 'password of `' + letters + '` returns 0' );
     
    3535    });
    3636
    37     test('zxcvbn passward tests should return the score we expect', function(){
    38         var passwords = [
    39             { pw: 'zxcvbn', score: 0},
    40             { pw: 'qwER43@!', score: 1},
    41             { pw: 'Tr0ub4dour&3', score: 2},
    42             { pw: 'correcthorsebatterystaple', score: 4},
    43             { pw: 'coRrecth0rseba++ery9.23.2007staple$', score: 4},
    44             { pw: 'D0g..................', score: 0},
    45             { pw: 'abcdefghijk987654321', score: 0},
    46             { pw: 'neverforget13/3/1997', score: 2},
    47             { pw: '1qaz2wsx3edc', score: 0},
    48             { pw: 'temppass22', score: 1},
    49             { pw: 'briansmith', score: 0},
    50             { pw: 'briansmith4mayor', score: 0},
    51             { pw: 'password1', score: 0},
    52             { pw: 'viking', score: 0},
    53             { pw: 'thx1138', score: 0},
    54             { pw: 'ScoRpi0ns', score: 0},
    55             { pw: 'do you know', score: 0},
    56             { pw: 'ryanhunter2000', score: 0},
    57             { pw: 'rianhunter2000', score: 1},
    58             { pw: 'asdfghju7654rewq', score: 2},
    59             { pw: 'AOEUIDHG&*()LS_', score: 2},
    60             { pw: '12345678', score: 0},
    61             { pw: 'defghi6789', score: 0},
    62             { pw: 'rosebud', score: 0},
    63             { pw: 'Rosebud', score: 0},
    64             { pw: 'ROSEBUD', score: 0},
    65             { pw: 'rosebuD', score: 0},
    66             { pw: 'ros3bud99', score: 0},
    67             { pw: 'r0s3bud99', score: 0},
    68             { pw: 'R0$38uD99', score: 1},
    69             { pw: 'verlineVANDERMARK', score: 1},
    70             { pw: 'eheuczkqyq', score: 4},
    71             { pw: 'rWibMFACxAUGZmxhVncy', score: 4},
    72             { pw: 'Ba9ZyWABu99[BK#6MBgbH88Tofv)vs$w', score: 4}
    73         ];
     37    test('zxcvbn password tests should return the score we expect', function(){
     38        var passwords = [
     39            { pw: 'zxcvbn', score: 0},
     40            { pw: 'qwER43@!', score: 1},
     41            { pw: 'Tr0ub4dour&3', score: 2},
     42            { pw: 'correcthorsebatterystaple', score: 4},
     43            { pw: 'coRrecth0rseba++ery9.23.2007staple$', score: 4},
     44            { pw: 'D0g..................', score: 0},
     45            { pw: 'abcdefghijk987654321', score: 0},
     46            { pw: 'neverforget13/3/1997', score: 2},
     47            { pw: '1qaz2wsx3edc', score: 0},
     48            { pw: 'temppass22', score: 1},
     49            { pw: 'briansmith', score: 0},
     50            { pw: 'briansmith4mayor', score: 0},
     51            { pw: 'password1', score: 0},
     52            { pw: 'viking', score: 0},
     53            { pw: 'thx1138', score: 0},
     54            { pw: 'ScoRpi0ns', score: 0},
     55            { pw: 'do you know', score: 0},
     56            { pw: 'ryanhunter2000', score: 0},
     57            { pw: 'rianhunter2000', score: 1},
     58            { pw: 'asdfghju7654rewq', score: 2},
     59            { pw: 'AOEUIDHG&*()LS_', score: 2},
     60            { pw: '12345678', score: 0},
     61            { pw: 'defghi6789', score: 0},
     62            { pw: 'rosebud', score: 0},
     63            { pw: 'Rosebud', score: 0},
     64            { pw: 'ROSEBUD', score: 0},
     65            { pw: 'rosebuD', score: 0},
     66            { pw: 'ros3bud99', score: 0},
     67            { pw: 'r0s3bud99', score: 0},
     68            { pw: 'R0$38uD99', score: 1},
     69            { pw: 'verlineVANDERMARK', score: 1},
     70            { pw: 'eheuczkqyq', score: 4},
     71            { pw: 'rWibMFACxAUGZmxhVncy', score: 4},
     72            { pw: 'Ba9ZyWABu99[BK#6MBgbH88Tofv)vs$w', score: 4}
     73        ];
    7474
    75         for(var i=0; i < passwords.length; i++) {
    76             equal( passwordStrength( passwords[i].pw, 'username', passwords[i].pw ), passwords[i].score, 'password of `' + passwords[i].pw + '` returns '+passwords[i].score  );
    77         }
    78     });
     75        for (var i=0; i < passwords.length; i++) {
     76            equal( passwordStrength( passwords[i].pw, 'username', passwords[i].pw ), passwords[i].score, 'password of `' + passwords[i].pw + '` returns '+passwords[i].score );
     77        }
     78    });
     79
     80    test( 'username in password should be penalized', function() {
     81        var allowedPasswordScore, penalizedPasswordScore,
     82            allowedPassword   = 'a[janedoe]4',
     83            penalizedPassword = 'a[johndoe]4',
     84            username          = 'johndoe';
     85
     86        allowedPasswordScore = passwordStrength( allowedPassword, username, allowedPassword );
     87        penalizedPasswordScore = passwordStrength( penalizedPassword, username, penalizedPassword );
     88
     89        ok( penalizedPasswordScore < allowedPasswordScore, 'Penalized password scored ' + penalizedPasswordScore + '; allowed password scored: ' + allowedPasswordScore );
     90    } );
    7991});
Note: See TracChangeset for help on using the changeset viewer.