Skip to content

Commit b54ea07

Browse files
test: write failing tests for email length
1 parent 8eb56b1 commit b54ea07

File tree

1 file changed

+133
-0
lines changed

1 file changed

+133
-0
lines changed

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

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,139 @@ 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_possible_local_part_email()
146+
{
147+
$email = str_repeat('a', 64) . '@machine.local';
148+
149+
$response = $this->send(
150+
$this->request(
151+
'POST',
152+
'/api/users',
153+
[
154+
'authenticatedAs' => 1,
155+
'json' => [
156+
'data' => [
157+
'attributes' => [
158+
'username' => 'test',
159+
'password' => 'too-obscure',
160+
'email' => $email,
161+
],
162+
]
163+
],
164+
]
165+
)
166+
);
167+
168+
$this->assertEquals(201, $response->getStatusCode());
169+
170+
/** @var User $user */
171+
$user = User::where('username', 'test')->firstOrFail();
172+
173+
$this->assertEquals($email, $user->email);
174+
}
175+
176+
/**
177+
* @test
178+
*/
179+
public function admin_can_create_user_with_longest_valid_domain()
180+
{
181+
$email = 't@' . str_repeat('a', 63) . '.' . str_repeat('b', 63) . '.' . str_repeat('c', 63) . '.' . str_repeat('d', 58) . '.x';
182+
183+
$response = $this->send(
184+
$this->request(
185+
'POST',
186+
'/api/users',
187+
[
188+
'authenticatedAs' => 1,
189+
'json' => [
190+
'data' => [
191+
'attributes' => [
192+
'username' => 'test',
193+
'password' => 'too-obscure',
194+
'email' => $email,
195+
],
196+
]
197+
],
198+
]
199+
)
200+
);
201+
202+
$this->assertEquals(201, $response->getStatusCode());
203+
204+
/** @var User $user */
205+
$user = User::where('username', 'test')->firstOrFail();
206+
207+
$this->assertEquals($email, $user->email);
208+
}
209+
210+
/**
211+
* @test
212+
*/
213+
public function admin_can_create_user_with_longest_valid_email()
214+
{
215+
$localPart = str_repeat('a', 64);
216+
$domain = str_repeat('a', 61) . '.' . str_repeat('a', 60) . '.' . str_repeat('a', 60) . '.local';
217+
$email = $localPart . '@' . $domain;
218+
219+
$response = $this->send(
220+
$this->request(
221+
'POST',
222+
'/api/users',
223+
[
224+
'authenticatedAs' => 1,
225+
'json' => [
226+
'data' => [
227+
'attributes' => [
228+
'username' => 'test',
229+
'password' => 'too-obscure',
230+
'email' => $email,
231+
],
232+
]
233+
],
234+
]
235+
)
236+
);
237+
238+
$this->assertEquals(201, $response->getStatusCode());
239+
240+
/** @var User $user */
241+
$user = User::where('username', 'test')->firstOrFail();
242+
243+
$this->assertEquals($email, $user->email);
244+
}
245+
246+
/**
247+
* @test
248+
*/
249+
public function admin_cannot_create_user_with_invalid_email_length()
250+
{
251+
$email = str_repeat('a', 65) . '@' . str_repeat('a', 256) . '.local';
252+
253+
$response = $this->send(
254+
$this->request(
255+
'POST',
256+
'/api/users',
257+
[
258+
'authenticatedAs' => 1,
259+
'json' => [
260+
'data' => [
261+
'attributes' => [
262+
'username' => 'test',
263+
'password' => 'too-obscure',
264+
'email' => $email,
265+
],
266+
]
267+
],
268+
]
269+
)
270+
);
271+
272+
$this->assertEquals(422, $response->getStatusCode());
273+
}
274+
142275
/**
143276
* @test
144277
*/

0 commit comments

Comments
 (0)