Skip to content

Commit

Permalink
Make email validation on registration stricter
Browse files Browse the repository at this point in the history
  • Loading branch information
korridor committed Oct 28, 2024
1 parent b41d208 commit 27b40d8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/Actions/Fortify/CreateNewUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function create(array $input): User
'email' => [
'required',
'string',
'email',
'email:rfc,strict',
'max:255',
UniqueEloquent::make(User::class, 'email', function (Builder $builder): Builder {
/** @var Builder<User> $builder */
Expand Down
30 changes: 30 additions & 0 deletions tests/Feature/RegistrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,36 @@ public function test_new_users_can_register(): void
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' => '[email protected] ',
'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
Expand Down

0 comments on commit 27b40d8

Please sign in to comment.