From d7ca5116a72e06755e121d9310c8fa751b668c62 Mon Sep 17 00:00:00 2001 From: Hugo <hnouts.dev@gmail.com> Date: Mon, 5 Jul 2021 14:44:51 +0200 Subject: [PATCH] changed password regex to match front regex, fix typo --- src/users/users.service.spec.ts | 4 ++-- src/users/users.service.ts | 10 ++++++---- test/mock/services/categoriesOthers.mock.service.ts | 4 ++-- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/users/users.service.spec.ts b/src/users/users.service.spec.ts index 668890e12..558492b5d 100644 --- a/src/users/users.service.spec.ts +++ b/src/users/users.service.spec.ts @@ -80,7 +80,7 @@ describe('UsersService', () => { it('User should not be created, weak password', async () => { const result = new HttpException( - 'Weak password, it must contain ne lowercase alphabetical character, one uppercase alphabetical character, one numeric character, one special character and be eight characters or longer', + 'Weak password, it must contain one lowercase alphabetical character, one uppercase alphabetical character, one numeric character, one special character and be eight characters or longer', HttpStatus.UNPROCESSABLE_ENTITY ); const userDto: CreateUserDto = { @@ -253,7 +253,7 @@ describe('UsersService', () => { it('should not validate new password: weak password', async () => { const result = new HttpException( - 'Weak password, it must contain ne lowercase alphabetical character, one uppercase alphabetical character, one numeric character, one special character and be eight characters or longer', + 'Weak password, it must contain one lowercase alphabetical character, one uppercase alphabetical character, one numeric character, one special character and be eight characters or longer', HttpStatus.UNPROCESSABLE_ENTITY ); jest.spyOn(service, 'validatePasswordResetToken').mockImplementation(async (): Promise<HttpException> => result); diff --git a/src/users/users.service.ts b/src/users/users.service.ts index 354f5cee6..d02c4b13e 100644 --- a/src/users/users.service.ts +++ b/src/users/users.service.ts @@ -28,7 +28,7 @@ export class UsersService { } if (!this.isStrongPassword(createUserDto.password)) { throw new HttpException( - 'Weak password, it must contain ne lowercase alphabetical character, one uppercase alphabetical character, one numeric character, one special character and be eight characters or longer', + 'Weak password, it must contain one lowercase alphabetical character, one uppercase alphabetical character, one numeric character, one special character and be eight characters or longer', HttpStatus.UNPROCESSABLE_ENTITY ); } @@ -57,7 +57,9 @@ export class UsersService { * @param password string */ private isStrongPassword(password: string): boolean { - const strongRegex = new RegExp('^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!@#$%^&*])(?=.{8,})'); //NOSONAR + const strongRegex = new RegExp( + '^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[*.! @#$%^&(){}[]:;<>,?/\\~_+-=|])(?=.{8,})' + ); //NOSONAR return strongRegex.test(password); } @@ -237,7 +239,7 @@ export class UsersService { } if (!this.isStrongPassword(newPassword)) { throw new HttpException( - 'Weak password, it must contain ne lowercase alphabetical character, one uppercase alphabetical character, one numeric character, one special character and be eight characters or longer', + 'Weak password, it must contain one lowercase alphabetical character, one uppercase alphabetical character, one numeric character, one special character and be eight characters or longer', HttpStatus.UNPROCESSABLE_ENTITY ); } @@ -281,7 +283,7 @@ export class UsersService { if (user) { if (!this.isStrongPassword(password)) { throw new HttpException( - 'Weak password, it must contain ne lowercase alphabetical character, one uppercase alphabetical character, one numeric character, one special character and be eight characters or longer', + 'Weak password, it must contain one lowercase alphabetical character, one uppercase alphabetical character, one numeric character, one special character and be eight characters or longer', HttpStatus.UNPROCESSABLE_ENTITY ); } diff --git a/test/mock/services/categoriesOthers.mock.service.ts b/test/mock/services/categoriesOthers.mock.service.ts index 7b952c68d..70e0b3fa9 100644 --- a/test/mock/services/categoriesOthers.mock.service.ts +++ b/test/mock/services/categoriesOthers.mock.service.ts @@ -18,8 +18,8 @@ export class CategoriesOthersServiceMock { { modules: [ { - id: "Personnes en situation d'illetrisme", - text: "Personnes en situation d'illetrisme", + id: "Personnes en situation d'illettrisme", + text: "Personnes en situation d'illettrisme", }, { id: 'Langue étrangère (anglais)', -- GitLab