fix: increase length of email field (#4118)

This commit is contained in:
Davide Iadeluca 2024-11-22 11:03:04 +01:00 committed by GitHub
parent 7cfa560b4e
commit 49064f6912
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 111 additions and 0 deletions

View File

@ -0,0 +1,25 @@
<?php
/*
* This file is part of Flarum.
*
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder;
return [
'up' => 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();
});
}
];

View File

@ -0,0 +1,25 @@
<?php
/*
* This file is part of Flarum.
*
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder;
return [
'up' => 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();
});
}
];

View File

@ -138,6 +138,67 @@ class CreateTest extends TestCase
$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()
{