Make email validation on registration stricter

This commit is contained in:
Constantin Graf
2024-10-28 14:32:27 +01:00
parent b41d20839e
commit 27b40d863e
2 changed files with 31 additions and 1 deletions

View File

@@ -43,7 +43,7 @@ class CreateNewUser implements CreatesNewUsers
'email' => [
'required',
'string',
'email',
'email:rfc,strict',
'max:255',
UniqueEloquent::make(User::class, 'email', function (Builder $builder): Builder {
/** @var Builder<User> $builder */

View File

@@ -63,6 +63,36 @@ class RegistrationTest extends TestCase
Event::assertNotDispatched(NewsletterRegistered::class);
}
public function test_new_user_can_not_register_with_likely_invalid_domain(): void
{
// Act
$response = $this->post('/register', [
'name' => 'Test User',
'email' => 'peter.test@gmail',
'password' => 'password',
'password_confirmation' => 'password',
'terms' => Jetstream::hasTermsAndPrivacyPolicyFeature(),
]);
// Assert
$response->assertInvalid(['email']);
}
public function test_new_user_can_register_with_uppercase_email(): void
{
// Act
$response = $this->post('/register', [
'name' => 'Test User',
'email' => 'PETER.test@gmail.com ',
'password' => 'password',
'password_confirmation' => 'password',
'terms' => Jetstream::hasTermsAndPrivacyPolicyFeature(),
]);
// Assert
$response->assertValid(['email']);
}
public function test_new_users_can_consent_to_newsletter_during_registration(): void
{
// Arrange