allow emails without a tld (#2762)

It's perfectly valid to have an email address without a TLD, for instance:

- test@localhost
- test@svc-in-same-k8s-namespace
- test@internal-corp

Fixes #2667
This commit is contained in:
Thomas
2023-06-14 22:26:17 +01:00
committed by GitHub
parent eed1243263
commit 408fa45c51
8 changed files with 94 additions and 7 deletions

View File

@@ -3,6 +3,15 @@ import { validateSync } from 'class-validator';
import { LoginCredentialDto } from './login-credential.dto';
describe('LoginCredentialDto', () => {
it('should allow emails without a tld', () => {
const someEmail = 'test@test';
const dto = plainToInstance(LoginCredentialDto, { email: someEmail, password: 'password' });
const errors = validateSync(dto);
expect(errors).toHaveLength(0);
expect(dto.email).toEqual(someEmail);
});
it('should fail without an email', () => {
const dto = plainToInstance(LoginCredentialDto, { password: 'password' });
const errors = validateSync(dto);

View File

@@ -3,7 +3,7 @@ import { Transform } from 'class-transformer';
import { IsEmail, IsNotEmpty, IsString } from 'class-validator';
export class LoginCredentialDto {
@IsEmail()
@IsEmail({ require_tld: false })
@ApiProperty({ example: 'testuser@email.com' })
@Transform(({ value }) => value.toLowerCase())
email!: string;

View File

@@ -30,6 +30,20 @@ describe('SignUpDto', () => {
expect(errors[0].property).toEqual('email');
});
it('should allow emails without a tld', () => {
const someEmail = 'test@test';
const dto = plainToInstance(SignUpDto, {
email: someEmail,
password: 'password',
firstName: 'first name',
lastName: 'last name',
});
const errors = validateSync(dto);
expect(errors).toHaveLength(0);
expect(dto.email).toEqual(someEmail);
});
it('should make the email all lowercase', () => {
const dto = plainToInstance(SignUpDto, {
email: 'TeSt@ImMiCh.com',

View File

@@ -3,7 +3,7 @@ import { Transform } from 'class-transformer';
import { IsEmail, IsNotEmpty, IsString } from 'class-validator';
export class SignUpDto {
@IsEmail()
@IsEmail({ require_tld: false })
@ApiProperty({ example: 'testuser@email.com' })
@Transform(({ value }) => value.toLowerCase())
email!: string;