Skip to content

Commit 6c89f81

Browse files
[1.x] fix: change length of email field (#4117)
* 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
1 parent 8eb56b1 commit 6c89f81

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
/*
4+
* This file is part of Flarum.
5+
*
6+
* For detailed copyright and license information, please view the
7+
* LICENSE file that was distributed with this source code.
8+
*/
9+
10+
use Illuminate\Database\Schema\Blueprint;
11+
use Illuminate\Database\Schema\Builder;
12+
13+
return [
14+
'up' => function (Builder $schema) {
15+
$schema->table('users', function (Blueprint $table) {
16+
$table->string('email', 254)->change();
17+
});
18+
},
19+
20+
'down' => function (Builder $schema) {
21+
$schema->table('users', function (Blueprint $table) {
22+
$table->string('email', 150)->change();
23+
});
24+
}
25+
];

framework/core/tests/integration/api/users/CreateTest.php

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,71 @@ public function admins_can_create_activated_users()
139139
$this->assertEquals(1, $user->is_email_confirmed);
140140
}
141141

142+
/**
143+
* @test
144+
*/
145+
public function admin_can_create_user_with_longest_valid_email()
146+
{
147+
$localPart = str_repeat('a', 64);
148+
$domain = str_repeat('a', 61).'.'.str_repeat('a', 60).'.'.str_repeat('a', 60).'.local';
149+
$email = $localPart.'@'.$domain;
150+
151+
$response = $this->send(
152+
$this->request(
153+
'POST',
154+
'/api/users',
155+
[
156+
'authenticatedAs' => 1,
157+
'json' => [
158+
'data' => [
159+
'attributes' => [
160+
'username' => 'test',
161+
'password' => 'too-obscure',
162+
'email' => $email,
163+
],
164+
]
165+
],
166+
]
167+
)
168+
);
169+
170+
$this->assertEquals(201, $response->getStatusCode());
171+
172+
/** @var User $user */
173+
$user = User::where('username', 'test')->firstOrFail();
174+
175+
$this->assertEquals($email, $user->email);
176+
}
177+
178+
/**
179+
* @test
180+
*/
181+
public function admin_cannot_create_user_with_invalid_email_length()
182+
{
183+
$email = str_repeat('a', 65).'@'.str_repeat('a', 256).'.local';
184+
185+
$response = $this->send(
186+
$this->request(
187+
'POST',
188+
'/api/users',
189+
[
190+
'authenticatedAs' => 1,
191+
'json' => [
192+
'data' => [
193+
'attributes' => [
194+
'username' => 'test',
195+
'password' => 'too-obscure',
196+
'email' => $email,
197+
],
198+
]
199+
],
200+
]
201+
)
202+
);
203+
204+
$this->assertEquals(422, $response->getStatusCode());
205+
}
206+
142207
/**
143208
* @test
144209
*/

0 commit comments

Comments
 (0)