2020-01-12 02:58:02 +13:00
|
|
|
<?php
|
|
|
|
|
2020-01-12 19:35:37 +13:00
|
|
|
namespace Tests\E2E\Services\Account;
|
2020-01-12 02:58:02 +13:00
|
|
|
|
|
|
|
use Tests\E2E\Client;
|
2023-02-06 09:07:46 +13:00
|
|
|
use Utopia\Database\Helpers\ID;
|
2023-03-02 01:00:36 +13:00
|
|
|
use Utopia\Database\Validator\Datetime as DatetimeValidator;
|
2020-01-12 02:58:02 +13:00
|
|
|
|
|
|
|
trait AccountBase
|
|
|
|
{
|
2022-06-03 00:47:07 +12:00
|
|
|
public function testCreateAccount(): array
|
2020-01-12 02:58:02 +13:00
|
|
|
{
|
2022-06-03 00:47:07 +12:00
|
|
|
$email = uniqid() . 'user@localhost.test';
|
2020-01-12 10:53:57 +13:00
|
|
|
$password = 'password';
|
2020-01-12 02:58:02 +13:00
|
|
|
$name = 'User Name';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
2020-01-13 10:28:26 +13:00
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/account', array_merge([
|
2020-01-12 02:58:02 +13:00
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
2020-02-17 20:16:11 +13:00
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2020-01-13 10:28:26 +13:00
|
|
|
]), [
|
2022-08-14 22:33:36 +12:00
|
|
|
'userId' => ID::unique(),
|
2020-01-12 02:58:02 +13:00
|
|
|
'email' => $email,
|
|
|
|
'password' => $password,
|
|
|
|
'name' => $name,
|
|
|
|
]);
|
|
|
|
|
2020-02-17 20:16:11 +13:00
|
|
|
$id = $response['body']['$id'];
|
2020-01-12 02:58:02 +13:00
|
|
|
|
2023-10-27 03:04:47 +13:00
|
|
|
$this->assertEquals(201, $response['headers']['status-code']);
|
2020-01-12 02:58:02 +13:00
|
|
|
$this->assertNotEmpty($response['body']);
|
2020-02-17 20:16:11 +13:00
|
|
|
$this->assertNotEmpty($response['body']['$id']);
|
2023-02-06 09:39:41 +13:00
|
|
|
$this->assertEquals(true, (new DatetimeValidator())->isValid($response['body']['registration']));
|
2020-01-12 02:58:02 +13:00
|
|
|
$this->assertEquals($response['body']['email'], $email);
|
|
|
|
$this->assertEquals($response['body']['name'], $name);
|
2023-05-27 12:15:38 +12:00
|
|
|
$this->assertEquals($response['body']['labels'], []);
|
2023-07-07 12:12:39 +12:00
|
|
|
$this->assertArrayHasKey('accessedAt', $response['body']);
|
|
|
|
$this->assertNotEmpty($response['body']['accessedAt']);
|
2020-01-12 02:58:02 +13:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for FAILURE
|
|
|
|
*/
|
2020-01-13 10:28:26 +13:00
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/account', array_merge([
|
2020-01-12 02:58:02 +13:00
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
2020-02-17 20:16:11 +13:00
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2020-01-13 10:28:26 +13:00
|
|
|
]), [
|
2022-08-14 22:33:36 +12:00
|
|
|
'userId' => ID::unique(),
|
2020-01-12 02:58:02 +13:00
|
|
|
'email' => $email,
|
|
|
|
'password' => $password,
|
|
|
|
'name' => $name,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 409);
|
|
|
|
|
2021-02-17 02:49:21 +13:00
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/account', array_merge([
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
]), [
|
2022-08-14 22:33:36 +12:00
|
|
|
'userId' => ID::unique(),
|
2021-02-17 02:49:21 +13:00
|
|
|
'email' => '',
|
|
|
|
'password' => '',
|
|
|
|
]);
|
|
|
|
|
2023-10-27 03:04:47 +13:00
|
|
|
$this->assertEquals(400, $response['headers']['status-code']);
|
2021-02-17 02:49:21 +13:00
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/account', array_merge([
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
]), [
|
2022-08-14 22:33:36 +12:00
|
|
|
'userId' => ID::unique(),
|
2021-02-17 02:49:21 +13:00
|
|
|
'email' => $email,
|
|
|
|
'password' => '',
|
|
|
|
]);
|
|
|
|
|
2023-10-27 03:04:47 +13:00
|
|
|
$this->assertEquals(400, $response['headers']['status-code']);
|
2021-02-17 02:49:21 +13:00
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/account', array_merge([
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
]), [
|
2022-08-14 22:33:36 +12:00
|
|
|
'userId' => ID::unique(),
|
2021-02-17 02:49:21 +13:00
|
|
|
'email' => '',
|
|
|
|
'password' => $password,
|
|
|
|
]);
|
|
|
|
|
2023-10-27 03:04:47 +13:00
|
|
|
$this->assertEquals(400, $response['headers']['status-code']);
|
2021-02-17 02:49:21 +13:00
|
|
|
|
2024-01-02 23:59:35 +13:00
|
|
|
$shortPassword = 'short';
|
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/account', array_merge([
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
]), [
|
|
|
|
'userId' => ID::unique(),
|
|
|
|
'email' => 'shortpass@appwrite.io',
|
|
|
|
'password' => $shortPassword
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 400);
|
|
|
|
|
|
|
|
$longPassword = '';
|
|
|
|
for ($i = 0; $i < 257; $i++) { // 256 is the limit
|
|
|
|
$longPassword .= 'p';
|
|
|
|
}
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/account', array_merge([
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
]), [
|
|
|
|
'userId' => ID::unique(),
|
|
|
|
'email' => 'longpass@appwrite.io',
|
|
|
|
'password' => $longPassword,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 400);
|
|
|
|
|
2020-01-12 02:58:02 +13:00
|
|
|
return [
|
2020-04-22 19:03:34 +12:00
|
|
|
'id' => $id,
|
2020-01-12 02:58:02 +13:00
|
|
|
'email' => $email,
|
|
|
|
'password' => $password,
|
|
|
|
'name' => $name,
|
|
|
|
];
|
|
|
|
}
|
2022-06-03 00:47:07 +12:00
|
|
|
}
|