Skip to content

Commit

Permalink
test: write failing tests for email length
Browse files Browse the repository at this point in the history
  • Loading branch information
DavideIadeluca committed Nov 18, 2024
1 parent 8eb56b1 commit b54ea07
Showing 1 changed file with 133 additions and 0 deletions.
133 changes: 133 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,139 @@ public function admins_can_create_activated_users()
$this->assertEquals(1, $user->is_email_confirmed);
}

/**
* @test
*/
public function admin_can_create_user_with_longest_possible_local_part_email()
{
$email = str_repeat('a', 64) . '@machine.local';

$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_can_create_user_with_longest_valid_domain()
{
$email = 't@' . str_repeat('a', 63) . '.' . str_repeat('b', 63) . '.' . str_repeat('c', 63) . '.' . str_repeat('d', 58) . '.x';

$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_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 b54ea07

Please sign in to comment.