Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump @nestjs/cli from 10.4.8 to 10.4.9 #6457

Merged
merged 7 commits into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions apps/backend/src/pipes/password-change.pipe.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {ArgumentMetadata, BadRequestException} from '@nestjs/common';
import {BadRequestException} from '@nestjs/common';
import {
UPDATE_USER_DTO_TEST_OBJ,
UPDATE_USER_DTO_TEST_OBJ_WITH_UPDATED_PASSWORD,
Expand All @@ -9,7 +9,6 @@ import {PasswordChangePipe} from './password-change.pipe';

describe('PasswordChangePipe', () => {
let passwordChangePipe: PasswordChangePipe;
let metaData: ArgumentMetadata;

beforeEach(() => {
passwordChangePipe = new PasswordChangePipe();
Expand Down Expand Up @@ -95,18 +94,14 @@ describe('PasswordChangePipe', () => {
it('should return the same UpdateUserDto', () => {
expect(
passwordChangePipe.transform(
UPDATE_USER_DTO_TEST_OBJ_WITH_UPDATED_PASSWORD,
metaData
UPDATE_USER_DTO_TEST_OBJ_WITH_UPDATED_PASSWORD
)
).toEqual(UPDATE_USER_DTO_TEST_OBJ_WITH_UPDATED_PASSWORD);
});

it('should return UpdateUserDto if password fields are null', () => {
expect(
passwordChangePipe.transform(
UPDATE_USER_DTO_WITHOUT_PASSWORD_FIELDS,
metaData
)
passwordChangePipe.transform(UPDATE_USER_DTO_WITHOUT_PASSWORD_FIELDS)
).toEqual(UPDATE_USER_DTO_WITHOUT_PASSWORD_FIELDS);
});

Expand All @@ -118,8 +113,7 @@ describe('PasswordChangePipe', () => {
it('should should pass when the currentPassword is not provided and a valid new password is provided', () => {
expect(
passwordChangePipe.transform(
UPDATE_USER_DTO_WITH_INVALID_CURRENT_PASSWORD,
metaData
UPDATE_USER_DTO_WITH_INVALID_CURRENT_PASSWORD
)
).toEqual(UPDATE_USER_DTO_WITH_INVALID_CURRENT_PASSWORD);
});
Expand All @@ -130,10 +124,10 @@ describe('PasswordChangePipe', () => {
describe('Test Invalid Password Changes', () => {
it('should throw a BadRequestException', () => {
expect(() =>
passwordChangePipe.transform(UPDATE_USER_DTO_TEST_OBJ, metaData)
passwordChangePipe.transform(UPDATE_USER_DTO_TEST_OBJ)
).toThrowError(BadRequestException);
expect(() =>
passwordChangePipe.transform(UPDATE_USER_DTO_TEST_OBJ, metaData)
passwordChangePipe.transform(UPDATE_USER_DTO_TEST_OBJ)
).toThrowError(
'A minimum of four character classes must be changed when updating a password.' +
' A minimum of eight of the total number of characters must be changed when updating a password.'
Expand Down
20 changes: 6 additions & 14 deletions apps/backend/src/pipes/password-change.pipe.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
import {
ArgumentMetadata,
BadRequestException,
Injectable,
PipeTransform
} from '@nestjs/common';
import {BadRequestException, Injectable, PipeTransform} from '@nestjs/common';
import levenshtein = require('js-levenshtein');

@Injectable()
export class PasswordChangePipe implements PipeTransform {
transform(
value: {
currentPassword?: string;
password: string | undefined;
passwordConfirmation: string | undefined;
},
_metadata: ArgumentMetadata
): Record<string, unknown> {
transform(value: {
currentPassword?: string;
password: string | undefined;
passwordConfirmation: string | undefined;
}): Record<string, unknown> {
if (
(!value.password && !value.passwordConfirmation) ||
!value.currentPassword
Expand Down
26 changes: 8 additions & 18 deletions apps/backend/src/pipes/password-complexity.pipe.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {validators} from '@heimdall/password-complexity';
import {ArgumentMetadata, BadRequestException} from '@nestjs/common';
import {BadRequestException} from '@nestjs/common';
import {
CREATE_USER_DTO_TEST_OBJ,
CREATE_USER_DTO_TEST_OBJ_WITH_MISSING_PASSWORD_FIELD,
Expand All @@ -14,7 +14,6 @@ import {

describe('PasswordComplexityPipe', () => {
let passwordComplexityPipe: PasswordComplexityPipe;
let metaData: ArgumentMetadata;

beforeEach(() => {
passwordComplexityPipe = new PasswordComplexityPipe();
Expand Down Expand Up @@ -121,21 +120,20 @@ describe('PasswordComplexityPipe', () => {
describe('Test Valid Password', () => {
it('should return the same CreateUserDto', () => {
expect(
passwordComplexityPipe.transform(CREATE_USER_DTO_TEST_OBJ, metaData)
passwordComplexityPipe.transform(CREATE_USER_DTO_TEST_OBJ)
).toEqual(CREATE_USER_DTO_TEST_OBJ);
});

it('should return the same UpdateUserDto', () => {
expect(
passwordComplexityPipe.transform(UPDATE_USER_DTO_TEST_OBJ, metaData)
passwordComplexityPipe.transform(UPDATE_USER_DTO_TEST_OBJ)
).toEqual(UPDATE_USER_DTO_TEST_OBJ);
});

it('should return UpdateUserDto if password fields are null', () => {
expect(
passwordComplexityPipe.transform(
UPDATE_USER_DTO_WITHOUT_PASSWORD_FIELDS,
metaData
UPDATE_USER_DTO_WITHOUT_PASSWORD_FIELDS
)
).toEqual(UPDATE_USER_DTO_WITHOUT_PASSWORD_FIELDS);
});
Expand All @@ -147,30 +145,22 @@ describe('PasswordComplexityPipe', () => {
it('should throw a BadRequestException for CreateUserDto with missing password', () => {
expect(() =>
passwordComplexityPipe.transform(
CREATE_USER_DTO_TEST_OBJ_WITH_MISSING_PASSWORD_FIELD,
metaData
CREATE_USER_DTO_TEST_OBJ_WITH_MISSING_PASSWORD_FIELD
)
).toThrowError(BadRequestException);
expect(() =>
passwordComplexityPipe.transform(
CREATE_USER_DTO_TEST_OBJ_WITH_MISSING_PASSWORD_FIELD,
metaData
CREATE_USER_DTO_TEST_OBJ_WITH_MISSING_PASSWORD_FIELD
)
).toThrowError('Password must be of type string');
});

it('should throw a BadRequestException for UpdateUserDto with missing password', () => {
expect(() =>
passwordComplexityPipe.transform(
UPDATE_USER_DTO_TEST_WITHOUT_PASSWORD,
metaData
)
passwordComplexityPipe.transform(UPDATE_USER_DTO_TEST_WITHOUT_PASSWORD)
).toThrowError(BadRequestException);
expect(() =>
passwordComplexityPipe.transform(
UPDATE_USER_DTO_TEST_WITHOUT_PASSWORD,
metaData
)
passwordComplexityPipe.transform(UPDATE_USER_DTO_TEST_WITHOUT_PASSWORD)
).toThrowError('Password must be of type string');
});
});
Expand Down
31 changes: 9 additions & 22 deletions apps/backend/src/pipes/password-complexity.pipe.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,22 @@
import {validators} from '@heimdall/password-complexity';
import {
ArgumentMetadata,
BadRequestException,
Injectable,
PipeTransform
} from '@nestjs/common';
import {BadRequestException, Injectable, PipeTransform} from '@nestjs/common';

export function validatePassword(password?: string): string[] {
const errors = [];
if (typeof password !== 'string') {
errors.push('Password must be of type string');
return ['Password must be of type string'];
} else {
validators.forEach((validator) => {
if (!validator.check(password)) {
errors.push(validator.name);
}
});
return validators
.filter((validator) => !validator.check(password))
.map((validator) => validator.name);
}

return errors;
}

@Injectable()
export class PasswordComplexityPipe implements PipeTransform {
transform(
value: {
password: string | undefined;
passwordConfirmation: string | undefined;
},
_metadata: ArgumentMetadata
): Record<string, unknown> {
transform(value: {
password: string | undefined;
passwordConfirmation: string | undefined;
}): Record<string, unknown> {
if (!value.password && !value.passwordConfirmation) {
return value;
}
Expand Down
26 changes: 10 additions & 16 deletions apps/backend/src/pipes/passwords-match.pipe.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {ArgumentMetadata, BadRequestException} from '@nestjs/common';
import {BadRequestException} from '@nestjs/common';
import {
CREATE_USER_DTO_TEST_OBJ,
CREATE_USER_DTO_TEST_OBJ_WITH_UNMATCHING_PASSWORDS,
Expand All @@ -9,7 +9,6 @@ import {PasswordsMatchPipe} from './passwords-match.pipe';

describe('PasswordsMatchPipe', () => {
let passwordsMatchPipe: PasswordsMatchPipe;
let metaData: ArgumentMetadata;

beforeEach(() => {
passwordsMatchPipe = new PasswordsMatchPipe();
Expand All @@ -23,23 +22,20 @@ describe('PasswordsMatchPipe', () => {
the same CreateUserDto obj that is passed to the pipeline, is returned */
describe('Test Matching Passwords', () => {
it('should return the same CreateUserDto', () => {
expect(
passwordsMatchPipe.transform(CREATE_USER_DTO_TEST_OBJ, metaData)
).toEqual(CREATE_USER_DTO_TEST_OBJ);
expect(passwordsMatchPipe.transform(CREATE_USER_DTO_TEST_OBJ)).toEqual(
CREATE_USER_DTO_TEST_OBJ
);
});

it('should return the same UpdateUserDto', () => {
expect(
passwordsMatchPipe.transform(UPDATE_USER_DTO_TEST_OBJ, metaData)
).toEqual(UPDATE_USER_DTO_TEST_OBJ);
expect(passwordsMatchPipe.transform(UPDATE_USER_DTO_TEST_OBJ)).toEqual(
UPDATE_USER_DTO_TEST_OBJ
);
});

it('should return UpdateUserDto if password fields are null', () => {
expect(
passwordsMatchPipe.transform(
UPDATE_USER_DTO_WITHOUT_PASSWORD_FIELDS,
metaData
)
passwordsMatchPipe.transform(UPDATE_USER_DTO_WITHOUT_PASSWORD_FIELDS)
).toEqual(UPDATE_USER_DTO_WITHOUT_PASSWORD_FIELDS);
});
});
Expand All @@ -50,14 +46,12 @@ describe('PasswordsMatchPipe', () => {
it('should throw a Bad Request Exception', () => {
expect(() =>
passwordsMatchPipe.transform(
CREATE_USER_DTO_TEST_OBJ_WITH_UNMATCHING_PASSWORDS,
metaData
CREATE_USER_DTO_TEST_OBJ_WITH_UNMATCHING_PASSWORDS
)
).toThrowError(BadRequestException);
expect(() =>
passwordsMatchPipe.transform(
CREATE_USER_DTO_TEST_OBJ_WITH_UNMATCHING_PASSWORDS,
metaData
CREATE_USER_DTO_TEST_OBJ_WITH_UNMATCHING_PASSWORDS
)
).toThrowError('Passwords do not match');
});
Expand Down
20 changes: 6 additions & 14 deletions apps/backend/src/pipes/passwords-match.pipe.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
import {
ArgumentMetadata,
BadRequestException,
Injectable,
PipeTransform
} from '@nestjs/common';
import {BadRequestException, Injectable, PipeTransform} from '@nestjs/common';

@Injectable()
export class PasswordsMatchPipe implements PipeTransform {
transform(
value: {
currentPassword?: string;
password: string | undefined;
passwordConfirmation: string | undefined;
},
_metadata: ArgumentMetadata
): Record<string, unknown> {
transform(value: {
currentPassword?: string;
password: string | undefined;
passwordConfirmation: string | undefined;
}): Record<string, unknown> {
if (
value.currentPassword != null &&
value.password == null &&
Expand Down
Loading
Loading