aboutsummaryrefslogtreecommitdiff
path: root/src/tools/password-strength-analyser/password-strength-analyser.service.test.ts
blob: cdcecbe035c622691e14498f71be3ec1b907e43b (plain) (blame)
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
import { describe, expect, it } from 'vitest';
import { getCharsetLength } from './password-strength-analyser.service';

describe('password-strength-analyser-and-crack-time-estimation', () => {
  describe('getCharsetLength', () => {
    describe('computes the charset length of a given password', () => {
      it('the charset length is 26 when the password is only lowercase characters', () => {
        expect(getCharsetLength({ password: 'abcdefghijklmnopqrstuvwxyz' })).toBe(26);
      });
      it('the charset length is 26 when the password is only uppercase characters', () => {
        expect(getCharsetLength({ password: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' })).toBe(26);
      });
      it('the charset length is 10 when the password is only digits', () => {
        expect(getCharsetLength({ password: '0123456789' })).toBe(10);
      });
      it('the charset length is 32 when the password is only special characters', () => {
        expect(getCharsetLength({ password: '-_(' })).toBe(32);
      });
      it('the charset length is 0 when the password is empty', () => {
        expect(getCharsetLength({ password: '' })).toBe(0);
      });

      it('the charset length is 36 when the password is lowercase characters and digits', () => {
        expect(getCharsetLength({ password: 'abcdefghijklmnopqrstuvwxyz0123456789' })).toBe(36);
      });
      it('the charset length is 95 when the password is lowercase characters, uppercase characters, digits and special characters', () => {
        expect(getCharsetLength({ password: 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_(' })).toBe(94);
      });
    });
  });
});