storj/web/satellite/tests/unit/utils/validation.spec.ts
Jeremy Wharton 92d81db183 satellite/console,web/satellite: limit new password length to 128
This change implements a requirement that all new passwords must be
no longer than 128 characters.

Change-Id: I7a8f23c87190d465eed59b3e0627ccd32d465bb9
2022-09-08 13:29:47 +00:00

48 lines
1.8 KiB
TypeScript

// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
import { Validator } from '@/utils/validation';
describe('validation', (): void => {
Object.defineProperties(Validator, {
PASS_MIN_LENGTH: {value: 6},
PASS_MAX_LENGTH: {value: 128},
});
it('password regex works correctly', (): void => {
const testString1 = 'test';
const testString2 = ' '.trim();
const testString3 = 'test %%%';
const testString4 = 'testtest';
const testString5 = 'test1233';
const testString6 = 'test1';
const testString7 = 'teSTt1123';
expect(Validator.password(testString1)).toBe(false);
expect(Validator.password(testString2)).toBe(false);
expect(Validator.password(testString3)).toBe(true);
expect(Validator.password(testString4)).toBe(true);
expect(Validator.password(testString5)).toBe(true);
expect(Validator.password(testString6)).toBe(false);
expect(Validator.password(testString7)).toBe(true);
});
it('email regex works correctly', () => {
const testString1 = 'test';
const testString2 = ' ';
const testString3 = 'test@';
const testString4 = 'test.test';
const testString5 = 'test1@23.3';
const testString6 = '';
const testString7 = '@teSTt.1123';
expect(Validator.email(testString1)).toBe(false);
expect(Validator.email(testString2)).toBe(false);
expect(Validator.email(testString3)).toBe(false);
expect(Validator.email(testString4)).toBe(false);
expect(Validator.email(testString5)).toBe(true);
expect(Validator.email(testString6)).toBe(false);
expect(Validator.email(testString7)).toBe(true);
});
});