passwordGenerator.test.ts
Ricky/StrongPassword/backend/src/__tests__/passwordGenerator.test.ts
import { PasswordGenerator } from '../utils/passwordGenerator';
describe('PasswordGenerator', () => {
describe('generatePassword', () => {
it('should generate password with specified length', () => {
const options = {
length: 16,
includeUppercase: true,
includeLowercase: true,
includeNumbers: true,
includeSymbols: true,
};
const password = PasswordGenerator.generatePassword(options);
expect(password).toHaveLength(16);
});
it('should include at least one character from each enabled class', () => {
const options = {
length: 8,
includeUppercase: true,
includeLowercase: true,
includeNumbers: true,
includeSymbols: false,
};
const password = PasswordGenerator.generatePassword(options);
expect(/[A-Z]/.test(password)).toBe(true); // Uppercase
expect(/[a-z]/.test(password)).toBe(true); // Lowercase
expect(/\d/.test(password)).toBe(true); // Numbers
expect(/[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]/.test(password)).toBe(false); // Symbols
});
it('should handle minimum length constraint', () => {
const options = {
length: 8,
includeUppercase: true,
includeLowercase: true,
includeNumbers: true,
includeSymbols: true,
};
const password = PasswordGenerator.generatePassword(options);
expect(password.length).toBeGreaterThanOrEqual(8);
});
});
describe('getPasswordStrength', () => {
it('should return weak for simple passwords', () => {
const result = PasswordGenerator.getPasswordStrength('password');
expect(result.label).toBe('Weak');
expect(result.color).toBe('text-red-500');
});
it('should return strong for complex passwords', () => {
const result = PasswordGenerator.getPasswordStrength('P@ssw0rd!');
expect(result.label).toBe('Strong');
expect(result.color).toBe('text-green-500');
});
it('should handle empty password', () => {
const result = PasswordGenerator.getPasswordStrength('');
expect(result.label).toBe('No Password');
expect(result.color).toBe('text-gray-500');
});
});
});
相关文章
__init__.py
__init__.py — python source code from the Ricky learning materials (Ricky/Cat Project Final/back_web-4/app/__init__.py).
阅读文章 →auth.py
auth.py — python source code from the Ricky learning materials (Ricky/Cat Project Final/back_web-4/app/admin/auth.py).
阅读文章 →routes.py
routes.py — python source code from the Ricky learning materials (Ricky/Cat Project Final/back_web-4/app/admin/routes.py).
阅读文章 →config.py
config.py — python source code from the Ricky learning materials (Ricky/Cat Project Final/back_web-4/app/config.py).
阅读文章 →admin_ingest.py
admin_ingest.py — python source code from the Ricky learning materials (Ricky/Cat Project Final/back_web-4/app/routes/admin_ingest.py).
阅读文章 →admin_stats.py
admin_stats.py — python source code from the Ricky learning materials (Ricky/Cat Project Final/back_web-4/app/routes/admin_stats.py).
阅读文章 →