30 lines
1.7 KiB
JavaScript
30 lines
1.7 KiB
JavaScript
const test = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
|
|
const { validatePasswordStrength } = require('../src/auth');
|
|
|
|
test('password strength requires a longer mixed-character password', () => {
|
|
assert.equal(validatePasswordStrength('weakpass'), 'Password must be at least 10 characters and include 3 of: uppercase, lowercase, number, and symbol.');
|
|
assert.equal(validatePasswordStrength('1234567890'), 'Password must be at least 10 characters and include 3 of: uppercase, lowercase, number, and symbol.');
|
|
assert.equal(validatePasswordStrength('Password12'), '');
|
|
assert.equal(validatePasswordStrength('NewPassword!1'), '');
|
|
});
|
|
|
|
test('password strength supports strong and strict policies', () => {
|
|
assert.equal(validatePasswordStrength('Password12', { policy: 'strong' }), 'Password must be at least 12 characters and include 3 of: uppercase, lowercase, number, and symbol.');
|
|
assert.equal(validatePasswordStrength('Password12!!', { policy: 'strong' }), '');
|
|
assert.equal(validatePasswordStrength('Password12!Abc', { policy: 'strict' }), '');
|
|
assert.equal(validatePasswordStrength('Password12!Ab', { policy: 'strict' }), 'Password must be at least 14 characters and include uppercase, lowercase, number, and symbol.');
|
|
});
|
|
|
|
test('password strength supports custom category requirements', () => {
|
|
const requirements = {
|
|
minimumLength: 8,
|
|
minimumCategories: 2,
|
|
requireUppercase: true,
|
|
requireSymbol: true
|
|
};
|
|
|
|
assert.equal(validatePasswordStrength('password1!', requirements), 'Password must be at least 8 characters and include uppercase, symbol.');
|
|
assert.equal(validatePasswordStrength('Password!', requirements), '');
|
|
}); |