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
|
|
|
|
2022-06-09 00:50:31 +12:00
|
|
|
use Appwrite\Auth\Phone\Mock;
|
2020-01-14 04:15:52 +13:00
|
|
|
use Tests\E2E\Client;
|
2020-01-12 02:58:02 +13:00
|
|
|
use Tests\E2E\Scopes\Scope;
|
|
|
|
use Tests\E2E\Scopes\ProjectCustom;
|
|
|
|
use Tests\E2E\Scopes\SideClient;
|
2022-05-24 02:54:50 +12:00
|
|
|
|
2022-02-04 23:23:06 +13:00
|
|
|
use function sleep;
|
2020-01-12 02:58:02 +13:00
|
|
|
|
|
|
|
class AccountCustomClientTest extends Scope
|
|
|
|
{
|
|
|
|
use AccountBase;
|
|
|
|
use ProjectCustom;
|
|
|
|
use SideClient;
|
2020-01-14 04:15:52 +13:00
|
|
|
|
2021-07-18 09:21:33 +12:00
|
|
|
/**
|
|
|
|
* @depends testCreateAccountSession
|
|
|
|
*/
|
2022-05-16 22:11:37 +12:00
|
|
|
public function testCreateOAuth2AccountSession(): array
|
2020-01-14 04:15:52 +13:00
|
|
|
{
|
|
|
|
$provider = 'mock';
|
|
|
|
$appId = '1';
|
|
|
|
$secret = '123456';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
2022-05-16 22:11:37 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $this->getProject()['$id'] . '/oauth2', array_merge([
|
2020-01-14 04:15:52 +13:00
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => 'console',
|
|
|
|
'cookie' => 'a_session_console=' . $this->getRoot()['session'],
|
|
|
|
]), [
|
|
|
|
'provider' => $provider,
|
|
|
|
'appId' => $appId,
|
|
|
|
'secret' => $secret,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 200);
|
|
|
|
|
2022-05-16 22:11:37 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/account/sessions/oauth2/' . $provider, array_merge([
|
2020-01-14 04:15:52 +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-14 04:15:52 +13:00
|
|
|
]), [
|
2020-02-17 00:41:03 +13:00
|
|
|
'success' => 'http://localhost/v1/mock/tests/general/oauth2/success',
|
|
|
|
'failure' => 'http://localhost/v1/mock/tests/general/oauth2/failure',
|
2020-01-14 04:15:52 +13:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$this->assertEquals('success', $response['body']['result']);
|
|
|
|
|
|
|
|
return [];
|
|
|
|
}
|
2020-12-28 09:32:39 +13:00
|
|
|
|
2022-05-16 22:11:37 +12:00
|
|
|
public function testBlockedAccount(): array
|
2020-12-28 09:32:39 +13:00
|
|
|
{
|
2022-05-16 22:11:37 +12:00
|
|
|
$email = uniqid() . 'user@localhost.test';
|
2020-12-28 09:32:39 +13:00
|
|
|
$password = 'password';
|
|
|
|
$name = 'User Name (blocked)';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/account', array_merge([
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
]), [
|
2021-08-05 17:02:55 +12:00
|
|
|
'userId' => 'unique()',
|
2020-12-28 09:32:39 +13:00
|
|
|
'email' => $email,
|
|
|
|
'password' => $password,
|
|
|
|
'name' => $name,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$id = $response['body']['$id'];
|
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 201);
|
2022-05-16 22:11:37 +12:00
|
|
|
|
2022-06-14 20:17:50 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/account/sessions/email', array_merge([
|
2020-12-28 09:32:39 +13:00
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
]), [
|
|
|
|
'email' => $email,
|
|
|
|
'password' => $password,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 201);
|
|
|
|
|
|
|
|
$sessionId = $response['body']['$id'];
|
2022-05-16 22:11:37 +12:00
|
|
|
$session = $this->client->parseCookie((string)$response['headers']['set-cookie'])['a_session_' . $this->getProject()['$id']];
|
2020-12-28 09:32:39 +13:00
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/account', array_merge([
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2022-05-16 22:11:37 +12:00
|
|
|
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session,
|
2020-12-28 09:32:39 +13:00
|
|
|
]));
|
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 200);
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/users/' . $id . '/status', [
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'x-appwrite-key' => $this->getProject()['apiKey'],
|
|
|
|
], [
|
2021-07-14 23:02:12 +12:00
|
|
|
'status' => false,
|
2020-12-28 09:32:39 +13:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 200);
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/account', array_merge([
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2022-05-16 22:11:37 +12:00
|
|
|
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session,
|
|
|
|
]));
|
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 401);
|
|
|
|
|
2022-06-14 20:17:50 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/account/sessions/email', array_merge([
|
2022-05-16 22:11:37 +12:00
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
]), [
|
|
|
|
'email' => $email,
|
|
|
|
'password' => $password,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 401);
|
|
|
|
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testSelfBlockedAccount(): array
|
|
|
|
{
|
|
|
|
$email = uniqid() . 'user55@localhost.test';
|
|
|
|
$password = 'password';
|
|
|
|
$name = 'User Name (self blocked)';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/account', array_merge([
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
]), [
|
|
|
|
'userId' => 'unique()',
|
|
|
|
'email' => $email,
|
|
|
|
'password' => $password,
|
|
|
|
'name' => $name,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$id = $response['body']['$id'];
|
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 201);
|
|
|
|
|
2022-06-14 20:17:50 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/account/sessions/email', array_merge([
|
2022-05-16 22:11:37 +12:00
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
]), [
|
|
|
|
'email' => $email,
|
|
|
|
'password' => $password,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 201);
|
|
|
|
|
|
|
|
$session = $this->client->parseCookie((string)$response['headers']['set-cookie'])['a_session_' . $this->getProject()['$id']];
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/account', array_merge([
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session,
|
|
|
|
]));
|
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 200);
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/account/status', [
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session,
|
|
|
|
], [
|
|
|
|
'status' => false,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 200);
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/account', array_merge([
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session,
|
2020-12-28 09:32:39 +13:00
|
|
|
]));
|
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 401);
|
|
|
|
|
2022-06-14 20:17:50 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/account/sessions/email', array_merge([
|
2020-12-28 09:32:39 +13:00
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
]), [
|
|
|
|
'email' => $email,
|
|
|
|
'password' => $password,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 401);
|
|
|
|
|
|
|
|
return [];
|
|
|
|
}
|
2020-12-29 09:31:55 +13:00
|
|
|
|
2022-05-16 22:11:37 +12:00
|
|
|
public function testCreateJWT(): array
|
2020-12-29 09:31:55 +13:00
|
|
|
{
|
2022-05-16 22:11:37 +12:00
|
|
|
$email = uniqid() . 'user@localhost.test';
|
2020-12-29 09:31:55 +13:00
|
|
|
$password = 'password';
|
|
|
|
$name = 'User Name (JWT)';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/account', array_merge([
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
]), [
|
2021-08-05 17:02:55 +12:00
|
|
|
'userId' => 'unique()',
|
2020-12-29 09:31:55 +13:00
|
|
|
'email' => $email,
|
|
|
|
'password' => $password,
|
|
|
|
'name' => $name,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$id = $response['body']['$id'];
|
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 201);
|
2022-05-16 22:11:37 +12:00
|
|
|
|
2022-06-14 20:17:50 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/account/sessions/email', array_merge([
|
2020-12-29 09:31:55 +13:00
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
]), [
|
|
|
|
'email' => $email,
|
|
|
|
'password' => $password,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 201);
|
|
|
|
|
|
|
|
$sessionId = $response['body']['$id'];
|
2022-05-16 22:11:37 +12:00
|
|
|
$session = $this->client->parseCookie((string)$response['headers']['set-cookie'])['a_session_' . $this->getProject()['$id']];
|
2020-12-29 09:31:55 +13:00
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/account', array_merge([
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2022-05-16 22:11:37 +12:00
|
|
|
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session,
|
2020-12-29 09:31:55 +13:00
|
|
|
]));
|
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 200);
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/account/jwt', array_merge([
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2022-05-16 22:11:37 +12:00
|
|
|
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session,
|
2020-12-29 09:31:55 +13:00
|
|
|
]));
|
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 201);
|
2022-06-09 11:17:15 +12:00
|
|
|
$this->assertEquals($response['headers']['x-ratelimit-remaining'], 99);
|
2020-12-29 09:31:55 +13:00
|
|
|
$this->assertNotEmpty($response['body']['jwt']);
|
|
|
|
$this->assertIsString($response['body']['jwt']);
|
|
|
|
|
|
|
|
$jwt = $response['body']['jwt'];
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/account', array_merge([
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'x-appwrite-jwt' => 'wrong-token',
|
|
|
|
]));
|
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 401);
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/account', array_merge([
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'x-appwrite-jwt' => $jwt,
|
|
|
|
]));
|
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 200);
|
|
|
|
|
2022-05-16 22:11:37 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_DELETE, '/account/sessions/' . $sessionId, array_merge([
|
2020-12-29 09:31:55 +13:00
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2022-05-16 22:11:37 +12:00
|
|
|
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session,
|
2020-12-29 09:31:55 +13:00
|
|
|
]));
|
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 204);
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/account', array_merge([
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'x-appwrite-jwt' => $jwt,
|
|
|
|
]));
|
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 401);
|
|
|
|
|
|
|
|
return [];
|
|
|
|
}
|
2021-02-17 02:49:21 +13:00
|
|
|
|
|
|
|
public function testCreateAnonymousAccount()
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/account/sessions/anonymous', [
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
]);
|
|
|
|
|
2021-02-24 11:43:05 +13:00
|
|
|
$this->assertEquals(201, $response['headers']['status-code']);
|
2021-05-21 01:41:55 +12:00
|
|
|
$this->assertIsArray($response['body']);
|
|
|
|
$this->assertNotEmpty($response['body']);
|
|
|
|
$this->assertNotEmpty($response['body']['$id']);
|
2021-02-17 02:49:21 +13:00
|
|
|
|
2022-05-16 22:11:37 +12:00
|
|
|
$session = $this->client->parseCookie((string)$response['headers']['set-cookie'])['a_session_' . $this->getProject()['$id']];
|
2021-02-17 02:49:21 +13:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for FAILURE
|
|
|
|
*/
|
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/account/sessions/anonymous', [
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2022-05-16 22:11:37 +12:00
|
|
|
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session,
|
2021-02-17 02:49:21 +13:00
|
|
|
]);
|
|
|
|
|
2021-02-24 11:43:05 +13:00
|
|
|
$this->assertEquals(401, $response['headers']['status-code']);
|
2021-02-17 02:49:21 +13:00
|
|
|
|
|
|
|
return $session;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testCreateAnonymousAccount
|
|
|
|
*/
|
2021-04-17 04:50:16 +12:00
|
|
|
public function testUpdateAnonymousAccountPassword($session)
|
2021-02-17 02:49:21 +13:00
|
|
|
{
|
|
|
|
/**
|
2021-05-07 01:21:36 +12:00
|
|
|
* Test for FAILURE
|
2021-02-17 02:49:21 +13:00
|
|
|
*/
|
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/account/password', array_merge([
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2022-05-16 22:11:37 +12:00
|
|
|
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session,
|
2021-02-17 02:49:21 +13:00
|
|
|
]), [
|
2021-02-17 03:14:36 +13:00
|
|
|
'oldPassword' => '',
|
2021-02-17 02:49:21 +13:00
|
|
|
]);
|
|
|
|
|
2021-05-07 01:21:36 +12:00
|
|
|
$this->assertEquals(400, $response['headers']['status-code']);
|
2021-02-17 02:49:21 +13:00
|
|
|
|
2021-04-17 04:50:16 +12:00
|
|
|
return $session;
|
2021-02-17 02:49:21 +13:00
|
|
|
}
|
|
|
|
|
2021-02-17 03:14:36 +13:00
|
|
|
/**
|
|
|
|
* @depends testUpdateAnonymousAccountPassword
|
|
|
|
*/
|
2021-04-17 04:50:16 +12:00
|
|
|
public function testUpdateAnonymousAccountEmail($session)
|
2021-02-17 03:14:36 +13:00
|
|
|
{
|
2022-05-16 22:11:37 +12:00
|
|
|
$email = uniqid() . 'new@localhost.test';
|
2021-02-17 03:14:36 +13:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for FAILURE
|
|
|
|
*/
|
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/account/email', array_merge([
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2022-05-16 22:11:37 +12:00
|
|
|
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session,
|
2021-02-17 03:14:36 +13:00
|
|
|
]), [
|
|
|
|
'email' => $email,
|
|
|
|
'password' => '',
|
|
|
|
]);
|
|
|
|
|
2021-04-17 04:50:16 +12:00
|
|
|
$this->assertEquals(400, $response['headers']['status-code']);
|
2021-02-17 03:14:36 +13:00
|
|
|
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
2021-04-17 04:50:16 +12:00
|
|
|
public function testConvertAnonymousAccount()
|
2021-02-17 02:49:21 +13:00
|
|
|
{
|
2021-02-17 04:51:08 +13:00
|
|
|
$session = $this->testCreateAnonymousAccount();
|
2022-05-16 22:11:37 +12:00
|
|
|
$email = uniqid() . 'new@localhost.test';
|
2021-02-17 02:49:21 +13:00
|
|
|
$password = 'new-password';
|
|
|
|
|
2021-02-17 04:01:15 +13:00
|
|
|
/**
|
|
|
|
* Test for FAILURE
|
|
|
|
*/
|
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/account', array_merge([
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
]), [
|
2021-08-05 17:02:55 +12:00
|
|
|
'userId' => 'unique()',
|
2021-02-17 04:01:15 +13:00
|
|
|
'email' => $email,
|
|
|
|
'password' => $password
|
|
|
|
]);
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/account/email', array_merge([
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2022-05-16 22:11:37 +12:00
|
|
|
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session,
|
2021-02-17 04:01:15 +13:00
|
|
|
]), [
|
|
|
|
'email' => $email,
|
|
|
|
'password' => $password,
|
|
|
|
]);
|
|
|
|
|
2021-08-30 17:51:06 +12:00
|
|
|
$this->assertEquals($response['headers']['status-code'], 409);
|
2021-02-17 04:01:15 +13:00
|
|
|
|
2021-02-17 02:49:21 +13:00
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
2022-05-16 22:11:37 +12:00
|
|
|
$email = uniqid() . 'new@localhost.test';
|
2021-02-17 04:01:15 +13:00
|
|
|
|
2021-02-17 02:49:21 +13:00
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/account/email', array_merge([
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2022-05-16 22:11:37 +12:00
|
|
|
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session,
|
2021-02-17 02:49:21 +13:00
|
|
|
]), [
|
|
|
|
'email' => $email,
|
|
|
|
'password' => $password,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 200);
|
|
|
|
$this->assertIsArray($response['body']);
|
|
|
|
$this->assertNotEmpty($response['body']);
|
|
|
|
$this->assertNotEmpty($response['body']['$id']);
|
|
|
|
$this->assertIsNumeric($response['body']['registration']);
|
|
|
|
$this->assertEquals($response['body']['email'], $email);
|
|
|
|
|
2022-06-14 20:17:50 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/account/sessions/email', array_merge([
|
2021-02-17 03:20:15 +13:00
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
]), [
|
|
|
|
'email' => $email,
|
|
|
|
'password' => $password,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 201);
|
|
|
|
|
2021-02-17 02:49:21 +13:00
|
|
|
return [];
|
|
|
|
}
|
2021-02-17 04:51:08 +13:00
|
|
|
|
2021-04-17 04:50:16 +12:00
|
|
|
public function testConvertAnonymousAccountOAuth2()
|
2021-02-17 04:51:08 +13:00
|
|
|
{
|
|
|
|
$session = $this->testCreateAnonymousAccount();
|
|
|
|
$provider = 'mock';
|
|
|
|
$appId = '1';
|
|
|
|
$secret = '123456';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
2021-07-18 09:21:33 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/account', array_merge([
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2022-05-16 22:11:37 +12:00
|
|
|
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session,
|
2021-07-18 09:21:33 +12:00
|
|
|
]));
|
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 200);
|
|
|
|
|
|
|
|
$userId = $response['body']['$id'] ?? '';
|
2022-05-16 22:11:37 +12:00
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $this->getProject()['$id'] . '/oauth2', array_merge([
|
2021-02-17 04:51:08 +13:00
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => 'console',
|
|
|
|
'cookie' => 'a_session_console=' . $this->getRoot()['session'],
|
|
|
|
]), [
|
|
|
|
'provider' => $provider,
|
|
|
|
'appId' => $appId,
|
|
|
|
'secret' => $secret,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 200);
|
|
|
|
|
2022-05-16 22:11:37 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/account/sessions/oauth2/' . $provider, array_merge([
|
2021-02-17 04:51:08 +13:00
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2022-05-16 22:11:37 +12:00
|
|
|
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session,
|
2021-02-17 04:51:08 +13:00
|
|
|
]), [
|
|
|
|
'success' => 'http://localhost/v1/mock/tests/general/oauth2/success',
|
|
|
|
'failure' => 'http://localhost/v1/mock/tests/general/oauth2/failure',
|
|
|
|
]);
|
2022-02-04 23:23:06 +13:00
|
|
|
|
2022-05-16 22:11:37 +12:00
|
|
|
$session = $this->client->parseCookie((string)$response['headers']['set-cookie'])['a_session_' . $this->getProject()['$id']];
|
2021-02-17 04:51:08 +13:00
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$this->assertEquals('success', $response['body']['result']);
|
2022-05-16 22:11:37 +12:00
|
|
|
|
2021-02-17 04:51:08 +13:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/account', array_merge([
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2022-05-16 22:11:37 +12:00
|
|
|
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session,
|
2021-02-17 04:51:08 +13:00
|
|
|
]));
|
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 200);
|
2021-07-18 09:21:33 +12:00
|
|
|
$this->assertEquals($response['body']['$id'], $userId);
|
2021-02-17 04:51:08 +13:00
|
|
|
$this->assertEquals($response['body']['name'], 'User Name');
|
2022-02-04 23:23:06 +13:00
|
|
|
$this->assertEquals($response['body']['email'], 'useroauth@localhost.test');
|
|
|
|
|
|
|
|
// Since we only support one oauth user, let's also check updateSession here
|
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 200);
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/account/sessions/current', array_merge([
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2022-05-16 22:11:37 +12:00
|
|
|
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session,
|
2022-02-04 23:23:06 +13:00
|
|
|
]));
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$this->assertEquals('123456', $response['body']['providerAccessToken']);
|
|
|
|
$this->assertEquals('tuvwxyz', $response['body']['providerRefreshToken']);
|
|
|
|
$this->assertGreaterThan(\time() + 14400 - 5, $response['body']['providerAccessTokenExpiry']); // 5 seconds allowed networking delay
|
|
|
|
|
|
|
|
$initialExpiry = $response['body']['providerAccessTokenExpiry'];
|
2022-05-16 22:11:37 +12:00
|
|
|
|
2022-02-04 23:23:06 +13:00
|
|
|
sleep(3);
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/account/sessions/current', array_merge([
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2022-05-16 22:11:37 +12:00
|
|
|
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session,
|
2022-02-04 23:23:06 +13:00
|
|
|
]));
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$this->assertEquals('123456', $response['body']['providerAccessToken']);
|
|
|
|
$this->assertEquals('tuvwxyz', $response['body']['providerRefreshToken']);
|
|
|
|
$this->assertNotEquals($initialExpiry, $response['body']['providerAccessTokenExpiry']);
|
2021-02-17 04:51:08 +13:00
|
|
|
|
|
|
|
return [];
|
|
|
|
}
|
2021-06-16 22:41:15 +12:00
|
|
|
|
2022-05-16 22:11:37 +12:00
|
|
|
public function testGetSessionByID()
|
|
|
|
{
|
2021-06-16 22:41:15 +12:00
|
|
|
$session = $this->testCreateAnonymousAccount();
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/account/sessions/current', array_merge([
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2022-05-16 22:11:37 +12:00
|
|
|
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session,
|
2021-06-16 22:41:15 +12:00
|
|
|
]));
|
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 200);
|
|
|
|
$this->assertEquals($response['body']['provider'], 'anonymous');
|
|
|
|
|
|
|
|
$sessionID = $response['body']['$id'];
|
|
|
|
|
2022-05-16 22:11:37 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/account/sessions/' . $sessionID, array_merge([
|
2021-06-16 22:41:15 +12:00
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2022-05-16 22:11:37 +12:00
|
|
|
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session,
|
2021-06-16 22:41:15 +12:00
|
|
|
]));
|
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 200);
|
|
|
|
$this->assertEquals($response['body']['provider'], 'anonymous');
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/account/sessions/97823askjdkasd80921371980', array_merge([
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2022-05-16 22:11:37 +12:00
|
|
|
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session,
|
2021-06-16 22:41:15 +12:00
|
|
|
]));
|
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 404);
|
|
|
|
}
|
2022-04-26 22:07:33 +12:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testUpdateAccountName
|
|
|
|
*/
|
|
|
|
public function testUpdateAccountNameSearch($data): void
|
|
|
|
{
|
|
|
|
$id = $data['id'] ?? '';
|
|
|
|
$email = $data['email'] ?? '';
|
|
|
|
$newName = 'Lorem';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/users', [
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'x-appwrite-key' => $this->getProject()['apiKey'],
|
|
|
|
], [
|
|
|
|
'search' => $newName
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 200);
|
|
|
|
$this->assertNotEmpty($response['body']);
|
|
|
|
$this->assertNotEmpty($response['body']['users']);
|
|
|
|
$this->assertCount(1, $response['body']['users']);
|
|
|
|
$this->assertEquals($response['body']['users'][0]['email'], $email);
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/users', [
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'x-appwrite-key' => $this->getProject()['apiKey'],
|
|
|
|
], [
|
|
|
|
'search' => $id
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 200);
|
|
|
|
$this->assertNotEmpty($response['body']);
|
|
|
|
$this->assertNotEmpty($response['body']['users']);
|
|
|
|
$this->assertCount(1, $response['body']['users']);
|
|
|
|
$this->assertEquals($response['body']['users'][0]['email'], $email);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testUpdateAccountEmail
|
|
|
|
*/
|
|
|
|
public function testUpdateAccountEmailSearch($data): void
|
|
|
|
{
|
|
|
|
$id = $data['id'] ?? '';
|
|
|
|
$email = $data['email'] ?? '';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/users', [
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'x-appwrite-key' => $this->getProject()['apiKey'],
|
|
|
|
], [
|
|
|
|
'search' => '"' . $email . '"'
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 200);
|
|
|
|
$this->assertNotEmpty($response['body']);
|
|
|
|
$this->assertNotEmpty($response['body']['users']);
|
|
|
|
$this->assertCount(1, $response['body']['users']);
|
|
|
|
$this->assertEquals($response['body']['users'][0]['email'], $email);
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/users', [
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'x-appwrite-key' => $this->getProject()['apiKey'],
|
|
|
|
], [
|
|
|
|
'search' => $id
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 200);
|
|
|
|
$this->assertNotEmpty($response['body']);
|
|
|
|
$this->assertNotEmpty($response['body']['users']);
|
|
|
|
$this->assertCount(1, $response['body']['users']);
|
|
|
|
$this->assertEquals($response['body']['users'][0]['email'], $email);
|
|
|
|
}
|
2022-06-09 00:50:31 +12:00
|
|
|
|
|
|
|
|
|
|
|
public function testCreatePhone(): array
|
|
|
|
{
|
|
|
|
$number = '+123456789';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/account/sessions/phone', array_merge([
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
]), [
|
|
|
|
'userId' => 'unique()',
|
|
|
|
'number' => $number,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(201, $response['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($response['body']['$id']);
|
|
|
|
$this->assertEmpty($response['body']['secret']);
|
|
|
|
$this->assertIsNumeric($response['body']['expire']);
|
|
|
|
|
|
|
|
$userId = $response['body']['userId'];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for FAILURE
|
|
|
|
*/
|
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/account/sessions/phone', array_merge([
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
]), [
|
|
|
|
'userId' => 'unique()'
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(400, $response['headers']['status-code']);
|
|
|
|
|
|
|
|
$data['token'] = Mock::$defaultDigits;
|
|
|
|
$data['id'] = $userId;
|
|
|
|
$data['number'] = $number;
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testCreatePhone
|
|
|
|
*/
|
|
|
|
public function testCreateSessionWithPhone(array $data): array
|
|
|
|
{
|
|
|
|
$id = $data['id'] ?? '';
|
|
|
|
$token = $data['token'] ?? '';
|
|
|
|
$number = $data['number'] ?? '';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for FAILURE
|
|
|
|
*/
|
|
|
|
$response = $this->client->call(Client::METHOD_PUT, '/account/sessions/phone', array_merge([
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
]), [
|
|
|
|
'userId' => 'ewewe',
|
|
|
|
'secret' => $token,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(404, $response['headers']['status-code']);
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_PUT, '/account/sessions/phone', array_merge([
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
]), [
|
|
|
|
'userId' => $id,
|
|
|
|
'secret' => 'sdasdasdasd',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(401, $response['headers']['status-code']);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
|
|
|
$response = $this->client->call(Client::METHOD_PUT, '/account/sessions/phone', array_merge([
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
]), [
|
|
|
|
'userId' => $id,
|
|
|
|
'secret' => $token,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(201, $response['headers']['status-code']);
|
|
|
|
$this->assertIsArray($response['body']);
|
|
|
|
$this->assertNotEmpty($response['body']);
|
|
|
|
$this->assertNotEmpty($response['body']['$id']);
|
|
|
|
$this->assertNotEmpty($response['body']['userId']);
|
|
|
|
|
|
|
|
$session = $this->client->parseCookie((string)$response['headers']['set-cookie'])['a_session_' . $this->getProject()['$id']];
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/account', array_merge([
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session,
|
|
|
|
]));
|
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 200);
|
|
|
|
$this->assertNotEmpty($response['body']);
|
|
|
|
$this->assertNotEmpty($response['body']['$id']);
|
|
|
|
$this->assertIsNumeric($response['body']['registration']);
|
|
|
|
$this->assertEquals($response['body']['phone'], $number);
|
|
|
|
$this->assertTrue($response['body']['phoneVerification']);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for FAILURE
|
|
|
|
*/
|
|
|
|
$response = $this->client->call(Client::METHOD_PUT, '/account/sessions/phone', array_merge([
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
]), [
|
|
|
|
'userId' => $id,
|
|
|
|
'secret' => $token,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(401, $response['headers']['status-code']);
|
|
|
|
|
|
|
|
$data['session'] = $session;
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testCreateSessionWithPhone
|
|
|
|
*/
|
|
|
|
public function testConvertPhoneToPassword(array $data): array
|
|
|
|
{
|
|
|
|
$session = $data['session'];
|
|
|
|
$email = uniqid() . 'new@localhost.test';
|
|
|
|
$password = 'new-password';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
|
|
|
$email = uniqid() . 'new@localhost.test';
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/account/email', array_merge([
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session,
|
|
|
|
]), [
|
|
|
|
'email' => $email,
|
|
|
|
'password' => $password,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 200);
|
|
|
|
$this->assertIsArray($response['body']);
|
|
|
|
$this->assertNotEmpty($response['body']);
|
|
|
|
$this->assertNotEmpty($response['body']['$id']);
|
|
|
|
$this->assertIsNumeric($response['body']['registration']);
|
|
|
|
$this->assertEquals($response['body']['email'], $email);
|
|
|
|
|
2022-06-14 20:17:50 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/account/sessions/email', array_merge([
|
2022-06-09 00:50:31 +12:00
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
]), [
|
|
|
|
'email' => $email,
|
|
|
|
'password' => $password,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 201);
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testConvertPhoneToPassword
|
|
|
|
*/
|
|
|
|
public function testUpdatePhone(array $data): array
|
|
|
|
{
|
|
|
|
$newPhone = '+45632569856';
|
|
|
|
$session = $data['session'] ?? '';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/account/phone', array_merge([
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session,
|
|
|
|
]), [
|
|
|
|
'number' => $newPhone,
|
|
|
|
'password' => 'new-password'
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 200);
|
|
|
|
$this->assertIsArray($response['body']);
|
|
|
|
$this->assertNotEmpty($response['body']);
|
|
|
|
$this->assertNotEmpty($response['body']['$id']);
|
|
|
|
$this->assertIsNumeric($response['body']['registration']);
|
|
|
|
$this->assertEquals($response['body']['phone'], $newPhone);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for FAILURE
|
|
|
|
*/
|
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/account/phone', array_merge([
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
]));
|
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 401);
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/account/phone', array_merge([
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session,
|
|
|
|
]), []);
|
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 400);
|
|
|
|
|
|
|
|
$data['phone'] = $newPhone;
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testUpdatePhone
|
|
|
|
*/
|
|
|
|
public function testPhoneVerification(array $data): array
|
|
|
|
{
|
|
|
|
$session = $data['session'] ?? '';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/account/verification/phone', array_merge([
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session,
|
|
|
|
|
|
|
|
]));
|
|
|
|
|
|
|
|
$this->assertEquals(201, $response['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($response['body']['$id']);
|
|
|
|
$this->assertEmpty($response['body']['secret']);
|
|
|
|
$this->assertIsNumeric($response['body']['expire']);
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testPhoneVerification
|
|
|
|
*/
|
|
|
|
public function testUpdatePhoneVerification($data): array
|
|
|
|
{
|
|
|
|
$id = $data['id'] ?? '';
|
|
|
|
$session = $data['session'] ?? '';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
|
|
|
$response = $this->client->call(Client::METHOD_PUT, '/account/verification/phone', array_merge([
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session,
|
|
|
|
]), [
|
|
|
|
'userId' => $id,
|
|
|
|
'secret' => Mock::$defaultDigits,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for FAILURE
|
|
|
|
*/
|
|
|
|
$response = $this->client->call(Client::METHOD_PUT, '/account/verification/phone', array_merge([
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session,
|
|
|
|
]), [
|
|
|
|
'userId' => 'ewewe',
|
|
|
|
'secret' => Mock::$defaultDigits,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(404, $response['headers']['status-code']);
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_PUT, '/account/verification/phone', array_merge([
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session,
|
|
|
|
]), [
|
|
|
|
'userId' => $id,
|
|
|
|
'secret' => '999999',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(401, $response['headers']['status-code']);
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
2022-04-26 22:07:33 +12:00
|
|
|
}
|