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

fix: Empty name ("") accepted as a valid name while creating environments #583

Merged
merged 6 commits into from
Dec 9, 2024
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { 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()
Expand Down
17 changes: 17 additions & 0 deletions apps/api/src/environment/environment.e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Loading