Skip to content

Commit

Permalink
[1.x] fix: change length of email field (#4117)
Browse files Browse the repository at this point in the history
* test: write failing tests for email length

* style: formatting

* style: formatting

* fix: change length of email field

* test: write test for email with too long local part

* style: formatting

* chore: remove unnecessary tests
  • Loading branch information
DavideIadeluca authored Nov 19, 2024
1 parent 8eb56b1 commit 6c89f81
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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();
});
}
];
65 changes: 65 additions & 0 deletions framework/core/tests/integration/api/users/CreateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,71 @@ 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
*/
Expand Down

0 comments on commit 6c89f81

Please sign in to comment.