Skip to content

Commit 27b40d8

Browse files
committed
Make email validation on registration stricter
1 parent b41d208 commit 27b40d8

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

app/Actions/Fortify/CreateNewUser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function create(array $input): User
4343
'email' => [
4444
'required',
4545
'string',
46-
'email',
46+
'email:rfc,strict',
4747
'max:255',
4848
UniqueEloquent::make(User::class, 'email', function (Builder $builder): Builder {
4949
/** @var Builder<User> $builder */

tests/Feature/RegistrationTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,36 @@ public function test_new_users_can_register(): void
6363
Event::assertNotDispatched(NewsletterRegistered::class);
6464
}
6565

66+
public function test_new_user_can_not_register_with_likely_invalid_domain(): void
67+
{
68+
// Act
69+
$response = $this->post('/register', [
70+
'name' => 'Test User',
71+
'email' => 'peter.test@gmail',
72+
'password' => 'password',
73+
'password_confirmation' => 'password',
74+
'terms' => Jetstream::hasTermsAndPrivacyPolicyFeature(),
75+
]);
76+
77+
// Assert
78+
$response->assertInvalid(['email']);
79+
}
80+
81+
public function test_new_user_can_register_with_uppercase_email(): void
82+
{
83+
// Act
84+
$response = $this->post('/register', [
85+
'name' => 'Test User',
86+
'email' => 'PETER.test@gmail.com ',
87+
'password' => 'password',
88+
'password_confirmation' => 'password',
89+
'terms' => Jetstream::hasTermsAndPrivacyPolicyFeature(),
90+
]);
91+
92+
// Assert
93+
$response->assertValid(['email']);
94+
}
95+
6696
public function test_new_users_can_consent_to_newsletter_during_registration(): void
6797
{
6898
// Arrange

0 commit comments

Comments
 (0)