diff --git a/framework/core/migrations/2024_11_18_000000_increase_email_field_length_of_users.php b/framework/core/migrations/2024_11_18_000000_increase_email_field_length_of_users.php new file mode 100644 index 0000000000..f1325546b8 --- /dev/null +++ b/framework/core/migrations/2024_11_18_000000_increase_email_field_length_of_users.php @@ -0,0 +1,25 @@ + function (Builder $schema) { + $schema->table('users', function (Blueprint $table) { + $table->string('email', 254)->change(); + }); + }, + + 'down' => function (Builder $schema) { + $schema->table('users', function (Blueprint $table) { + $table->string('email', 150)->change(); + }); + } +]; diff --git a/framework/core/migrations/2024_11_22_000000_increase_email_field_length_in_email_tokens.php b/framework/core/migrations/2024_11_22_000000_increase_email_field_length_in_email_tokens.php new file mode 100644 index 0000000000..d83df4db06 --- /dev/null +++ b/framework/core/migrations/2024_11_22_000000_increase_email_field_length_in_email_tokens.php @@ -0,0 +1,25 @@ + function (Builder $schema) { + $schema->table('email_tokens', function (Blueprint $table) { + $table->string('email', 254)->change(); + }); + }, + + 'down' => function (Builder $schema) { + $schema->table('email_tokens', function (Blueprint $table) { + $table->string('email', 150)->change(); + }); + } +]; diff --git a/framework/core/tests/integration/api/users/CreateTest.php b/framework/core/tests/integration/api/users/CreateTest.php index 5fce8fba83..df146fea7a 100644 --- a/framework/core/tests/integration/api/users/CreateTest.php +++ b/framework/core/tests/integration/api/users/CreateTest.php @@ -138,6 +138,67 @@ public function admins_can_create_activated_users() $this->assertEquals(1, $user->is_email_confirmed); } + #[Test] + public function admin_can_create_user_with_longest_valid_email() + { + $localPart = str_repeat('a', 64); + $domain = str_repeat('a', 61).'.'.str_repeat('a', 60).'.'.str_repeat('a', 60).'.local'; + $email = $localPart.'@'.$domain; + + $response = $this->send( + $this->request( + 'POST', + '/api/users', + [ + 'authenticatedAs' => 1, + 'json' => [ + 'data' => [ + 'attributes' => [ + 'username' => 'test', + 'password' => 'too-obscure', + 'email' => $email, + ], + ] + ], + ] + ) + ); + + $this->assertEquals(201, $response->getStatusCode()); + + /** @var User $user */ + $user = User::where('username', 'test')->firstOrFail(); + + $this->assertEquals($email, $user->email); + } + + #[Test] + public function admin_cannot_create_user_with_invalid_email_length() + { + $email = str_repeat('a', 65).'@'.str_repeat('a', 256).'.local'; + + $response = $this->send( + $this->request( + 'POST', + '/api/users', + [ + 'authenticatedAs' => 1, + 'json' => [ + 'data' => [ + 'attributes' => [ + 'username' => 'test', + 'password' => 'too-obscure', + 'email' => $email, + ], + ] + ], + ] + ) + ); + + $this->assertEquals(422, $response->getStatusCode()); + } + #[Test] public function disabling_sign_up_prevents_user_creation() {