From 6de2298af0a6464162918470d5a372ab4a33529f Mon Sep 17 00:00:00 2001 From: zaheer-khan3260 Date: Sat, 7 Dec 2024 22:47:15 +0530 Subject: [PATCH 1/4] fix: Empty name () accepted as a valid name while creating environments --- .../src/environment/dto/create.environment/create.environment.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/api/src/environment/dto/create.environment/create.environment.ts b/apps/api/src/environment/dto/create.environment/create.environment.ts index db1adb9a..a07ca020 100644 --- a/apps/api/src/environment/dto/create.environment/create.environment.ts +++ b/apps/api/src/environment/dto/create.environment/create.environment.ts @@ -2,6 +2,7 @@ import { IsOptional, IsString } from 'class-validator' export class CreateEnvironment { @IsString() + @IsNotEmpty() name: string @IsString() From 436d381e7837d74e418b6e795249412f0461a6b6 Mon Sep 17 00:00:00 2001 From: zaheer-khan3260 Date: Sat, 7 Dec 2024 22:53:23 +0530 Subject: [PATCH 2/4] fix: Empty name () accepted as a valid name while creating environments --- .../environment/dto/create.environment/create.environment.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/api/src/environment/dto/create.environment/create.environment.ts b/apps/api/src/environment/dto/create.environment/create.environment.ts index a07ca020..6d95d658 100644 --- a/apps/api/src/environment/dto/create.environment/create.environment.ts +++ b/apps/api/src/environment/dto/create.environment/create.environment.ts @@ -1,4 +1,4 @@ -import { IsOptional, IsString } from 'class-validator' +import {IsNotEmpty, IsOptional, IsString } from 'class-validator' export class CreateEnvironment { @IsString() From be8a6bc4200b2381553bd7097e9f0569f74ff12d Mon Sep 17 00:00:00 2001 From: zaheer-khan3260 Date: Sun, 8 Dec 2024 18:15:39 +0530 Subject: [PATCH 3/4] test: Adding test case for #583 Pull request --- .../api/src/environment/environment.e2e.spec.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/apps/api/src/environment/environment.e2e.spec.ts b/apps/api/src/environment/environment.e2e.spec.ts index be15ee7e..ad949f1c 100644 --- a/apps/api/src/environment/environment.e2e.spec.ts +++ b/apps/api/src/environment/environment.e2e.spec.ts @@ -172,6 +172,23 @@ describe('Environment Controller Tests', () => { expect(environmentFromDb).toBeDefined() }) + it('should not be able to create an environment with an empty name', async () => { + const response = await app.inject({ + method: 'POST', + url: `/environment/${project1.slug}`, + payload: { + name: '', + description: 'Empty name test' + }, + headers: { + 'x-e2e-user-email': user1.email + } + }) + + expect(response.statusCode).toBe(400) + expect(response.json().message).toContain('name should not be empty') + }) + it('should not be able to create an environment in a project that does not exist', async () => { const response = await app.inject({ method: 'POST', From 7fd533fdd1538f812e5027501153fb1be3e8d7a9 Mon Sep 17 00:00:00 2001 From: zaheer-khan3260 Date: Mon, 9 Dec 2024 18:47:46 +0530 Subject: [PATCH 4/4] fix: Empty name () accepted as a valid name while creating environments --- .../environment/dto/create.environment/create.environment.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/api/src/environment/dto/create.environment/create.environment.ts b/apps/api/src/environment/dto/create.environment/create.environment.ts index 6d95d658..ffa62e3f 100644 --- a/apps/api/src/environment/dto/create.environment/create.environment.ts +++ b/apps/api/src/environment/dto/create.environment/create.environment.ts @@ -1,8 +1,9 @@ -import {IsNotEmpty, IsOptional, IsString } from 'class-validator' +import { IsNotEmpty, IsOptional, IsString, Matches } from 'class-validator' export class CreateEnvironment { @IsString() @IsNotEmpty() + @Matches(/^[a-zA-Z0-9-_]{1,64}$/) name: string @IsString()