forked from nowsecure/owasp-password-strength-test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
140 lines (116 loc) · 4.66 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
var should = require('should');
var owasp = require('./owasp-password-strength-test');
describe('passwords', function() {
describe('required tests', function() {
it('minLength should be enforced', function() {
var result = owasp.test('L0^eSex');
result.strong.should.be.false;
result.errors.should.have.length(1);
result.requiredTestErrors.should.have.length(1);
result.failedTests.should.containEql(0);
});
it('maxLength should be enforced', function() {
var password = '';
for (var i = 0; i < 50; i++) {
password += 'abc';
}
var result = owasp.test(password);
result.strong.should.be.false;
result.errors.should.have.length(1);
result.requiredTestErrors.should.have.length(1);
result.failedTests.should.containEql(1);
});
it('repeating characters (3 times or more) should be forbidden', function() {
var result = owasp.test('L0veSexxxSecre+God');
result.strong.should.be.false;
result.errors.should.have.length(1);
result.requiredTestErrors.should.have.length(1);
result.failedTests.should.containEql(2);
});
});
describe('optional tests', function() {
it('valid passwords should be recognized as such', function() {
var result = owasp.test('L0veSexSecre+God');
result.strong.should.be.true;
result.errors.should.be.empty;
result.requiredTestErrors.should.be.empty;
result.optionalTestErrors.should.be.empty;
result.failedTests.should.be.empty;
result.passedTests.should.eql([0, 1, 2, 3, 4, 5, 6]);
});
it('at least one lowercase character should be required', function() {
var result = owasp.test('L0VESEXSECRE+GOD');
result.strong.should.be.false;
result.errors.should.have.length(1);
result.optionalTestErrors.should.have.length(1);
result.failedTests.should.containEql(3);
});
it('at least one uppercase character should be required', function() {
var result = owasp.test('l0vesexsecre+god');
result.strong.should.be.false;
result.errors.should.have.length(1);
result.optionalTestErrors.should.have.length(1);
result.failedTests.should.containEql(4);
});
it('at least one number should be required', function() {
var result = owasp.test('LoveSexSecre+God');
result.strong.should.be.false;
result.errors.should.have.length(1);
result.optionalTestErrors.should.have.length(1);
result.failedTests.should.containEql(5);
});
it('at least one special character should be required', function() {
var result = owasp.test('L0veSexSecretGod');
result.strong.should.be.false;
result.errors.should.have.length(1);
result.optionalTestErrors.should.have.length(1);
result.failedTests.should.containEql(6);
});
it('the appropriate characters should be recognized as special', function() {
// see: https://www.owasp.org/index.php/Password_special_characters
var specials = ' !"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'.split('');
// test each special character
specials.forEach(function(special) {
var password = ['L0veSex', special, 'SecretGod'].join('');
var result = owasp.test(password);
result.strong.should.be.true;
result.errors.should.be.empty;
result.requiredTestErrors.should.be.empty;
result.optionalTestErrors.should.be.empty;
result.failedTests.should.be.empty;
result.passedTests.should.eql([0, 1, 2, 3, 4, 5, 6]);
});
});
});
});
describe('passphrases', function() {
it('should not be subject to optional tests by default', function() {
var result = owasp.test('Hack the planet! Hack the planet!');
result.strong.should.be.true;
result.errors.should.be.empty;
});
it('should be subject to optional tests per configuration', function() {
owasp.config({ allowPassphrases: false });
owasp.test('Hack the planet! Hack the planet!').strong.should.be.false;
});
});
describe('configs', function() {
it('should be settable', function() {
owasp.config({
allowPassphrases : false,
maxLength : 5,
minLength : 5,
minPhraseLength : 5,
minOptionalTestsToPass : 5,
});
owasp.configs.allowPassphrases.should.be.false;
owasp.configs.maxLength.should.be.exactly(5);
owasp.configs.minLength.should.be.exactly(5);
owasp.configs.minPhraseLength.should.be.exactly(5);
owasp.configs.minOptionalTestsToPass.should.be.exactly(5);
});
it('should reject invalid parameter keys', function() {
owasp.config({ foo: 'bar' });
owasp.configs.should.not.have.property('foo');
});
});