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;
|
|
|
|
|
|
|
|
trait AccountBase
|
|
|
|
{
|
|
|
|
public function testCreateAccount():array
|
|
|
|
{
|
|
|
|
$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
|
|
|
]), [
|
2021-08-05 17:02:55 +12:00
|
|
|
'userId' => '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
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 201);
|
|
|
|
$this->assertNotEmpty($response['body']);
|
2020-02-17 20:16:11 +13:00
|
|
|
$this->assertNotEmpty($response['body']['$id']);
|
2020-01-12 02:58:02 +13:00
|
|
|
$this->assertIsNumeric($response['body']['registration']);
|
|
|
|
$this->assertEquals($response['body']['email'], $email);
|
|
|
|
$this->assertEquals($response['body']['name'], $name);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
]), [
|
2021-08-05 17:02:55 +12:00
|
|
|
'userId' => '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'],
|
|
|
|
]), [
|
2021-08-05 17:02:55 +12:00
|
|
|
'userId' => 'unique()',
|
2021-02-17 02:49:21 +13:00
|
|
|
'email' => '',
|
|
|
|
'password' => '',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 400);
|
|
|
|
|
|
|
|
$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 02:49:21 +13:00
|
|
|
'email' => $email,
|
|
|
|
'password' => '',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 400);
|
|
|
|
|
|
|
|
$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 02:49:21 +13:00
|
|
|
'email' => '',
|
|
|
|
'password' => $password,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$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,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testCreateAccount
|
|
|
|
*/
|
|
|
|
public function testCreateAccountSession($data):array
|
|
|
|
{
|
2020-10-15 10:11:12 +13:00
|
|
|
$email = $data['email'] ?? '';
|
|
|
|
$password = $data['password'] ?? '';
|
2020-01-12 02:58:02 +13:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
2020-01-13 10:28:26 +13:00
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/account/sessions', 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
|
|
|
]), [
|
2020-01-12 02:58:02 +13:00
|
|
|
'email' => $email,
|
|
|
|
'password' => $password,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 201);
|
|
|
|
|
2020-02-17 20:16:11 +13:00
|
|
|
$sessionId = $response['body']['$id'];
|
2020-07-03 09:48:02 +12:00
|
|
|
$session = $this->client->parseCookie((string)$response['headers']['set-cookie'])['a_session_'.$this->getProject()['$id']];
|
2020-01-12 10:53:57 +13:00
|
|
|
|
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/sessions', 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
|
|
|
]), [
|
2020-01-12 02:58:02 +13:00
|
|
|
'email' => $email.'x',
|
|
|
|
'password' => $password,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 401);
|
|
|
|
|
2020-01-13 10:28:26 +13:00
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/account/sessions', 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
|
|
|
]), [
|
2020-01-12 02:58:02 +13:00
|
|
|
'email' => $email,
|
|
|
|
'password' => $password.'x',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 401);
|
|
|
|
|
2020-01-13 10:28:26 +13:00
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/account/sessions', 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
|
|
|
]), [
|
2020-01-12 02:58:02 +13:00
|
|
|
'email' => '',
|
|
|
|
'password' => '',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 400);
|
|
|
|
|
|
|
|
return array_merge($data, [
|
2020-02-16 07:34:16 +13:00
|
|
|
'sessionId' => $sessionId,
|
2020-01-12 02:58:02 +13:00
|
|
|
'session' => $session,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testCreateAccountSession
|
|
|
|
*/
|
|
|
|
public function testGetAccount($data):array
|
|
|
|
{
|
2020-10-15 10:11:12 +13:00
|
|
|
$email = $data['email'] ?? '';
|
|
|
|
$name = $data['name'] ?? '';
|
|
|
|
$session = $data['session'] ?? '';
|
2020-01-12 02:58:02 +13:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
2020-01-13 10:28:26 +13:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/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'],
|
|
|
|
'cookie' => 'a_session_'.$this->getProject()['$id'].'=' . $session,
|
2020-01-13 10:28:26 +13:00
|
|
|
]));
|
2020-01-12 02:58:02 +13:00
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 200);
|
|
|
|
$this->assertNotEmpty($response['body']);
|
2020-02-17 20:16:11 +13:00
|
|
|
$this->assertNotEmpty($response['body']['$id']);
|
2020-01-12 02:58:02 +13:00
|
|
|
$this->assertIsNumeric($response['body']['registration']);
|
|
|
|
$this->assertEquals($response['body']['email'], $email);
|
|
|
|
$this->assertEquals($response['body']['name'], $name);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for FAILURE
|
|
|
|
*/
|
2020-01-13 10:28:26 +13:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/account', array_merge([
|
2020-01-12 02:58:02 +13:00
|
|
|
'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
|
|
|
]));
|
2020-01-12 02:58:02 +13:00
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 401);
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/account', [
|
|
|
|
'content-type' => 'application/json',
|
2020-02-17 20:16:11 +13:00
|
|
|
'cookie' => 'a_session_'.$this->getProject()['$id'].'=' . $session.'xx',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2020-01-12 02:58:02 +13:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 401);
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testCreateAccountSession
|
|
|
|
*/
|
|
|
|
public function testGetAccountPrefs($data):array
|
|
|
|
{
|
2020-10-15 10:11:12 +13:00
|
|
|
$session = $data['session'] ?? '';
|
2020-01-12 02:58:02 +13:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
2020-01-13 10:28:26 +13:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/account/prefs', 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'],
|
|
|
|
'cookie' => 'a_session_'.$this->getProject()['$id'].'=' . $session,
|
2020-01-13 10:28:26 +13:00
|
|
|
]));
|
2020-01-12 02:58:02 +13:00
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 200);
|
|
|
|
$this->assertIsArray($response['body']);
|
|
|
|
$this->assertEmpty($response['body']);
|
|
|
|
$this->assertCount(0, $response['body']);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for FAILURE
|
|
|
|
*/
|
2020-01-13 10:28:26 +13:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/account/prefs', 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
|
|
|
]));
|
2020-01-12 02:58:02 +13:00
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 401);
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testCreateAccountSession
|
|
|
|
*/
|
|
|
|
public function testGetAccountSessions($data):array
|
|
|
|
{
|
2020-10-15 10:11:12 +13:00
|
|
|
$session = $data['session'] ?? '';
|
|
|
|
$sessionId = $data['sessionId'] ?? '';
|
2020-01-12 02:58:02 +13:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
2020-01-13 10:28:26 +13:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/account/sessions', 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'],
|
|
|
|
'cookie' => 'a_session_'.$this->getProject()['$id'].'=' . $session,
|
2020-01-13 10:28:26 +13:00
|
|
|
]));
|
2020-01-12 02:58:02 +13:00
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 200);
|
|
|
|
$this->assertIsArray($response['body']);
|
|
|
|
$this->assertNotEmpty($response['body']);
|
2020-10-31 08:53:27 +13:00
|
|
|
$this->assertCount(2, $response['body']);
|
|
|
|
$this->assertEquals(1, $response['body']['sum']);
|
|
|
|
$this->assertEquals($sessionId, $response['body']['sessions'][0]['$id']);
|
2020-01-12 02:58:02 +13:00
|
|
|
|
2020-10-31 08:53:27 +13:00
|
|
|
$this->assertEquals('Windows', $response['body']['sessions'][0]['osName']);
|
|
|
|
$this->assertEquals('WIN', $response['body']['sessions'][0]['osCode']);
|
|
|
|
$this->assertEquals('10', $response['body']['sessions'][0]['osVersion']);
|
|
|
|
|
|
|
|
$this->assertEquals('browser', $response['body']['sessions'][0]['clientType']);
|
|
|
|
$this->assertEquals('Chrome', $response['body']['sessions'][0]['clientName']);
|
|
|
|
$this->assertEquals('CH', $response['body']['sessions'][0]['clientCode']);
|
|
|
|
$this->assertEquals('70.0', $response['body']['sessions'][0]['clientVersion']);
|
|
|
|
$this->assertEquals('Blink', $response['body']['sessions'][0]['clientEngine']);
|
|
|
|
$this->assertEquals('desktop', $response['body']['sessions'][0]['deviceName']);
|
|
|
|
$this->assertEquals('', $response['body']['sessions'][0]['deviceBrand']);
|
|
|
|
$this->assertEquals('', $response['body']['sessions'][0]['deviceModel']);
|
|
|
|
$this->assertEquals($response['body']['sessions'][0]['ip'], filter_var($response['body']['sessions'][0]['ip'], FILTER_VALIDATE_IP));
|
2021-11-15 22:49:11 +13:00
|
|
|
|
2020-10-31 08:53:27 +13:00
|
|
|
$this->assertEquals('--', $response['body']['sessions'][0]['countryCode']);
|
|
|
|
$this->assertEquals('Unknown', $response['body']['sessions'][0]['countryName']);
|
2021-11-15 22:49:11 +13:00
|
|
|
|
2020-10-31 08:53:27 +13:00
|
|
|
$this->assertEquals(true, $response['body']['sessions'][0]['current']);
|
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_GET, '/account/sessions', 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
|
|
|
]));
|
2020-01-12 02:58:02 +13:00
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 401);
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testCreateAccountSession
|
|
|
|
*/
|
|
|
|
public function testGetAccountLogs($data):array
|
|
|
|
{
|
2020-06-20 05:21:55 +12:00
|
|
|
sleep(10);
|
2020-10-15 10:11:12 +13:00
|
|
|
$session = $data['session'] ?? '';
|
2020-01-12 02:58:02 +13:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
2020-01-13 10:28:26 +13:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/account/logs', 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'],
|
|
|
|
'cookie' => 'a_session_'.$this->getProject()['$id'].'=' . $session,
|
2020-01-13 10:28:26 +13:00
|
|
|
]));
|
2020-01-12 02:58:02 +13:00
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 200);
|
2020-10-31 08:53:27 +13:00
|
|
|
$this->assertIsArray($response['body']['logs']);
|
|
|
|
$this->assertNotEmpty($response['body']['logs']);
|
|
|
|
$this->assertCount(2, $response['body']['logs']);
|
2021-11-17 03:54:29 +13:00
|
|
|
$this->assertIsNumeric($response['body']['sum']);
|
2021-11-15 22:49:11 +13:00
|
|
|
|
2021-01-01 23:03:18 +13:00
|
|
|
$this->assertContains($response['body']['logs'][0]['event'], ['account.create', 'account.sessions.create']);
|
2020-10-31 08:53:27 +13:00
|
|
|
$this->assertEquals($response['body']['logs'][0]['ip'], filter_var($response['body']['logs'][0]['ip'], FILTER_VALIDATE_IP));
|
|
|
|
$this->assertIsNumeric($response['body']['logs'][0]['time']);
|
|
|
|
|
|
|
|
$this->assertEquals('Windows', $response['body']['logs'][0]['osName']);
|
|
|
|
$this->assertEquals('WIN', $response['body']['logs'][0]['osCode']);
|
|
|
|
$this->assertEquals('10', $response['body']['logs'][0]['osVersion']);
|
|
|
|
|
|
|
|
$this->assertEquals('browser', $response['body']['logs'][0]['clientType']);
|
|
|
|
$this->assertEquals('Chrome', $response['body']['logs'][0]['clientName']);
|
2021-01-01 23:03:18 +13:00
|
|
|
$this->assertEquals('CH', $response['body']['logs'][0]['clientCode']);
|
2020-10-31 08:53:27 +13:00
|
|
|
$this->assertEquals('70.0', $response['body']['logs'][0]['clientVersion']);
|
|
|
|
$this->assertEquals('Blink', $response['body']['logs'][0]['clientEngine']);
|
|
|
|
|
|
|
|
$this->assertEquals('desktop', $response['body']['logs'][0]['deviceName']);
|
|
|
|
$this->assertEquals('', $response['body']['logs'][0]['deviceBrand']);
|
|
|
|
$this->assertEquals('', $response['body']['logs'][0]['deviceModel']);
|
|
|
|
$this->assertEquals($response['body']['logs'][0]['ip'], filter_var($response['body']['logs'][0]['ip'], FILTER_VALIDATE_IP));
|
2021-11-15 22:49:11 +13:00
|
|
|
|
2020-10-31 08:53:27 +13:00
|
|
|
$this->assertEquals('--', $response['body']['logs'][0]['countryCode']);
|
|
|
|
$this->assertEquals('Unknown', $response['body']['logs'][0]['countryName']);
|
|
|
|
|
2021-01-01 23:03:18 +13:00
|
|
|
$this->assertContains($response['body']['logs'][1]['event'], ['account.create', 'account.sessions.create']);
|
2020-10-31 08:53:27 +13:00
|
|
|
$this->assertEquals($response['body']['logs'][1]['ip'], filter_var($response['body']['logs'][1]['ip'], FILTER_VALIDATE_IP));
|
|
|
|
$this->assertIsNumeric($response['body']['logs'][1]['time']);
|
|
|
|
|
|
|
|
$this->assertEquals('Windows', $response['body']['logs'][1]['osName']);
|
|
|
|
$this->assertEquals('WIN', $response['body']['logs'][1]['osCode']);
|
|
|
|
$this->assertEquals('10', $response['body']['logs'][1]['osVersion']);
|
|
|
|
|
|
|
|
$this->assertEquals('browser', $response['body']['logs'][1]['clientType']);
|
|
|
|
$this->assertEquals('Chrome', $response['body']['logs'][1]['clientName']);
|
2021-01-01 23:03:18 +13:00
|
|
|
$this->assertEquals('CH', $response['body']['logs'][1]['clientCode']);
|
2020-10-31 08:53:27 +13:00
|
|
|
$this->assertEquals('70.0', $response['body']['logs'][1]['clientVersion']);
|
|
|
|
$this->assertEquals('Blink', $response['body']['logs'][1]['clientEngine']);
|
|
|
|
|
|
|
|
$this->assertEquals('desktop', $response['body']['logs'][1]['deviceName']);
|
|
|
|
$this->assertEquals('', $response['body']['logs'][1]['deviceBrand']);
|
|
|
|
$this->assertEquals('', $response['body']['logs'][1]['deviceModel']);
|
|
|
|
$this->assertEquals($response['body']['logs'][1]['ip'], filter_var($response['body']['logs'][1]['ip'], FILTER_VALIDATE_IP));
|
2021-11-15 22:49:11 +13:00
|
|
|
|
2020-10-31 08:53:27 +13:00
|
|
|
$this->assertEquals('--', $response['body']['logs'][1]['countryCode']);
|
|
|
|
$this->assertEquals('Unknown', $response['body']['logs'][1]['countryName']);
|
2021-11-15 22:49:11 +13:00
|
|
|
|
|
|
|
$responseLimit = $this->client->call(Client::METHOD_GET, '/account/logs', array_merge([
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'cookie' => 'a_session_'.$this->getProject()['$id'].'=' . $session,
|
|
|
|
]), [
|
|
|
|
'limit' => 1
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($responseLimit['headers']['status-code'], 200);
|
|
|
|
$this->assertIsArray($responseLimit['body']['logs']);
|
|
|
|
$this->assertNotEmpty($responseLimit['body']['logs']);
|
|
|
|
$this->assertCount(1, $responseLimit['body']['logs']);
|
2021-11-17 03:54:29 +13:00
|
|
|
$this->assertIsNumeric($responseLimit['body']['sum']);
|
2021-11-15 22:49:11 +13:00
|
|
|
|
|
|
|
$this->assertEquals($response['body']['logs'][0], $responseLimit['body']['logs'][0]);
|
|
|
|
|
|
|
|
$responseOffset = $this->client->call(Client::METHOD_GET, '/account/logs', array_merge([
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'cookie' => 'a_session_'.$this->getProject()['$id'].'=' . $session,
|
|
|
|
]), [
|
|
|
|
'offset' => 1
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($responseOffset['headers']['status-code'], 200);
|
|
|
|
$this->assertIsArray($responseOffset['body']['logs']);
|
|
|
|
$this->assertNotEmpty($responseOffset['body']['logs']);
|
|
|
|
$this->assertCount(1, $responseOffset['body']['logs']);
|
2021-11-17 03:54:29 +13:00
|
|
|
$this->assertIsNumeric($responseOffset['body']['sum']);
|
2021-11-15 22:49:11 +13:00
|
|
|
|
|
|
|
$this->assertEquals($response['body']['logs'][1], $responseOffset['body']['logs'][0]);
|
|
|
|
|
|
|
|
$responseLimitOffset = $this->client->call(Client::METHOD_GET, '/account/logs', array_merge([
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'cookie' => 'a_session_'.$this->getProject()['$id'].'=' . $session,
|
|
|
|
]), [
|
|
|
|
'limit' => 1,
|
|
|
|
'offset' => 1
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($responseLimitOffset['headers']['status-code'], 200);
|
|
|
|
$this->assertIsArray($responseLimitOffset['body']['logs']);
|
|
|
|
$this->assertNotEmpty($responseLimitOffset['body']['logs']);
|
|
|
|
$this->assertCount(1, $responseLimitOffset['body']['logs']);
|
2021-11-17 03:54:29 +13:00
|
|
|
$this->assertIsNumeric($responseLimitOffset['body']['sum']);
|
2021-11-15 22:49:11 +13:00
|
|
|
|
|
|
|
$this->assertEquals($response['body']['logs'][1], $responseLimitOffset['body']['logs'][0]);
|
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_GET, '/account/logs', 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
|
|
|
]));
|
2020-01-12 02:58:02 +13:00
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 401);
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
2021-07-28 02:16:12 +12:00
|
|
|
// TODO Add tests for OAuth2 session creation
|
2020-01-12 02:58:02 +13:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testCreateAccountSession
|
|
|
|
*/
|
|
|
|
public function testUpdateAccountName($data):array
|
|
|
|
{
|
2020-10-15 10:11:12 +13:00
|
|
|
$email = $data['email'] ?? '';
|
|
|
|
$session = $data['session'] ?? '';
|
2020-01-12 02:58:02 +13:00
|
|
|
$newName = 'New Name';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
2020-01-13 10:28:26 +13:00
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/account/name', 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'],
|
|
|
|
'cookie' => 'a_session_'.$this->getProject()['$id'].'=' . $session,
|
2020-01-13 10:28:26 +13:00
|
|
|
]), [
|
2020-01-12 02:58:02 +13:00
|
|
|
'name' => $newName
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 200);
|
|
|
|
$this->assertIsArray($response['body']);
|
|
|
|
$this->assertNotEmpty($response['body']);
|
2020-02-17 20:16:11 +13:00
|
|
|
$this->assertNotEmpty($response['body']['$id']);
|
2020-01-12 02:58:02 +13:00
|
|
|
$this->assertIsNumeric($response['body']['registration']);
|
|
|
|
$this->assertEquals($response['body']['email'], $email);
|
|
|
|
$this->assertEquals($response['body']['name'], $newName);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for FAILURE
|
|
|
|
*/
|
2020-01-13 10:28:26 +13:00
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/account/name', 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
|
|
|
]));
|
2020-01-12 02:58:02 +13:00
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 401);
|
|
|
|
|
2020-01-13 10:28:26 +13:00
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/account/name', 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'],
|
|
|
|
'cookie' => 'a_session_'.$this->getProject()['$id'].'=' . $session,
|
2020-01-13 10:28:26 +13:00
|
|
|
]), [
|
2020-01-12 02:58:02 +13:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 400);
|
|
|
|
|
2020-01-13 10:28:26 +13:00
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/account/name', 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'],
|
|
|
|
'cookie' => 'a_session_'.$this->getProject()['$id'].'=' . $session,
|
2020-01-13 10:28:26 +13:00
|
|
|
]), [
|
2020-09-08 10:27:34 +12:00
|
|
|
'name' => 'ocSRq1d3QphHivJyUmYY7WMnrxyjdk5YvVwcDqx2zS0coxESN8RmsQwLWw5Whnf0WbVohuFWTRAaoKgCOO0Y0M7LwgFnZmi8881Y72222222222222222222222222222'
|
2020-01-12 02:58:02 +13:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 400);
|
|
|
|
|
|
|
|
$data['name'] = $newName;
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testUpdateAccountName
|
|
|
|
*/
|
|
|
|
public function testUpdateAccountPassword($data):array
|
|
|
|
{
|
2020-10-15 10:11:12 +13:00
|
|
|
$email = $data['email'] ?? '';
|
|
|
|
$password = $data['password'] ?? '';
|
|
|
|
$session = $data['session'] ?? '';
|
2020-01-12 02:58:02 +13:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
2020-01-13 10:28:26 +13:00
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/account/password', 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'],
|
|
|
|
'cookie' => 'a_session_'.$this->getProject()['$id'].'=' . $session,
|
2020-01-13 10:28:26 +13:00
|
|
|
]), [
|
2020-01-12 02:58:02 +13:00
|
|
|
'password' => 'new-password',
|
2020-03-26 09:19:19 +13:00
|
|
|
'oldPassword' => $password,
|
2020-01-12 02:58:02 +13:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 200);
|
|
|
|
$this->assertIsArray($response['body']);
|
|
|
|
$this->assertNotEmpty($response['body']);
|
2020-02-17 20:16:11 +13:00
|
|
|
$this->assertNotEmpty($response['body']['$id']);
|
2020-01-12 02:58:02 +13:00
|
|
|
$this->assertIsNumeric($response['body']['registration']);
|
|
|
|
$this->assertEquals($response['body']['email'], $email);
|
|
|
|
$this->assertEquals($response['body']['name'], 'New Name');
|
|
|
|
|
2020-01-13 10:28:26 +13:00
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/account/sessions', 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
|
|
|
]), [
|
2020-01-12 02:58:02 +13:00
|
|
|
'email' => $email,
|
|
|
|
'password' => 'new-password',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 201);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for FAILURE
|
|
|
|
*/
|
2020-01-13 10:28:26 +13:00
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/account/password', 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
|
|
|
]));
|
2020-01-12 02:58:02 +13:00
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 401);
|
|
|
|
|
2020-01-13 10:28:26 +13:00
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/account/password', 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'],
|
|
|
|
'cookie' => 'a_session_'.$this->getProject()['$id'].'=' . $session,
|
2020-01-13 10:28:26 +13:00
|
|
|
]), [
|
2020-01-12 02:58:02 +13:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 400);
|
|
|
|
|
2021-05-05 06:52:46 +12:00
|
|
|
/**
|
|
|
|
* Existing user tries to update password by passing wrong old password -> SHOULD FAIL
|
|
|
|
*/
|
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/account/password', array_merge([
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'cookie' => 'a_session_'.$this->getProject()['$id'].'=' . $session,
|
|
|
|
]), [
|
|
|
|
'password' => 'new-password',
|
|
|
|
'oldPassword' => $password,
|
|
|
|
]);
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 401);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Existing user tries to update password without passing old password -> SHOULD FAIL
|
|
|
|
*/
|
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/account/password', array_merge([
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'cookie' => 'a_session_'.$this->getProject()['$id'].'=' . $session,
|
|
|
|
]), [
|
|
|
|
'password' => 'new-password'
|
|
|
|
]);
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 401);
|
|
|
|
|
2020-01-12 02:58:02 +13:00
|
|
|
$data['password'] = 'new-password';
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testUpdateAccountPassword
|
|
|
|
*/
|
|
|
|
public function testUpdateAccountEmail($data):array
|
|
|
|
{
|
|
|
|
$newEmail = uniqid().'new@localhost.test';
|
2020-10-15 10:11:12 +13:00
|
|
|
$session = $data['session'] ?? '';
|
2020-01-12 02:58:02 +13:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
2020-01-13 10:28:26 +13:00
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/account/email', 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'],
|
|
|
|
'cookie' => 'a_session_'.$this->getProject()['$id'].'=' . $session,
|
2020-01-13 10:28:26 +13:00
|
|
|
]), [
|
2020-01-12 02:58:02 +13:00
|
|
|
'email' => $newEmail,
|
|
|
|
'password' => 'new-password',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 200);
|
|
|
|
$this->assertIsArray($response['body']);
|
|
|
|
$this->assertNotEmpty($response['body']);
|
2020-02-17 20:16:11 +13:00
|
|
|
$this->assertNotEmpty($response['body']['$id']);
|
2020-01-12 02:58:02 +13:00
|
|
|
$this->assertIsNumeric($response['body']['registration']);
|
|
|
|
$this->assertEquals($response['body']['email'], $newEmail);
|
|
|
|
$this->assertEquals($response['body']['name'], 'New Name');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for FAILURE
|
|
|
|
*/
|
2020-01-13 10:28:26 +13:00
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/account/email', 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
|
|
|
]));
|
2020-01-12 02:58:02 +13:00
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 401);
|
|
|
|
|
2020-01-13 10:28:26 +13:00
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/account/email', 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'],
|
|
|
|
'cookie' => 'a_session_'.$this->getProject()['$id'].'=' . $session,
|
2020-01-13 10:28:26 +13:00
|
|
|
]), [
|
2020-01-12 02:58:02 +13:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 400);
|
|
|
|
|
2021-06-24 03:06:52 +12:00
|
|
|
// Test if we can create a new account with the old email
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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()',
|
2021-06-24 03:06:52 +12:00
|
|
|
'email' => $data['email'],
|
|
|
|
'password' => $data['password'],
|
|
|
|
'name' => $data['name'],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 201);
|
|
|
|
$this->assertNotEmpty($response['body']);
|
|
|
|
$this->assertNotEmpty($response['body']['$id']);
|
|
|
|
$this->assertIsNumeric($response['body']['registration']);
|
|
|
|
$this->assertEquals($response['body']['email'], $data['email']);
|
|
|
|
$this->assertEquals($response['body']['name'], $data['name'],);
|
|
|
|
|
|
|
|
|
2020-01-12 02:58:02 +13:00
|
|
|
$data['email'] = $newEmail;
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testUpdateAccountEmail
|
|
|
|
*/
|
|
|
|
public function testUpdateAccountPrefs($data):array
|
|
|
|
{
|
|
|
|
$newEmail = uniqid().'new@localhost.test';
|
2020-10-15 10:11:12 +13:00
|
|
|
$session = $data['session'] ?? '';
|
2020-01-12 02:58:02 +13:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
2020-01-13 10:28:26 +13:00
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/account/prefs', 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'],
|
|
|
|
'cookie' => 'a_session_'.$this->getProject()['$id'].'=' . $session,
|
2020-01-13 10:28:26 +13:00
|
|
|
]), [
|
2020-01-12 02:58:02 +13:00
|
|
|
'prefs' => [
|
2020-10-31 08:53:27 +13:00
|
|
|
'prefKey1' => 'prefValue1',
|
|
|
|
'prefKey2' => 'prefValue2',
|
2020-01-12 02:58:02 +13:00
|
|
|
]
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 200);
|
|
|
|
$this->assertIsArray($response['body']);
|
|
|
|
$this->assertNotEmpty($response['body']);
|
2020-11-24 04:04:02 +13:00
|
|
|
$this->assertEquals('prefValue1', $response['body']['prefs']['prefKey1']);
|
|
|
|
$this->assertEquals('prefValue2', $response['body']['prefs']['prefKey2']);
|
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_PATCH, '/account/prefs', 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
|
|
|
]));
|
2020-01-12 02:58:02 +13:00
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 401);
|
|
|
|
|
2020-01-19 08:07:02 +13:00
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/account/prefs', array_merge([
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
2020-02-17 20:16:11 +13:00
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'cookie' => 'a_session_'.$this->getProject()['$id'].'=' . $session,
|
2020-01-19 08:07:02 +13:00
|
|
|
]), [
|
|
|
|
'prefs' => '{}'
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 400);
|
|
|
|
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/account/prefs', array_merge([
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
2020-02-17 20:16:11 +13:00
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'cookie' => 'a_session_'.$this->getProject()['$id'].'=' . $session,
|
2020-01-19 08:07:02 +13:00
|
|
|
]), [
|
|
|
|
'prefs' => '[]'
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 400);
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/account/prefs', array_merge([
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
2020-02-17 20:16:11 +13:00
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'cookie' => 'a_session_'.$this->getProject()['$id'].'=' . $session,
|
2020-01-19 08:07:02 +13:00
|
|
|
]), [
|
|
|
|
'prefs' => '{"test": "value"}'
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 400);
|
|
|
|
|
2021-12-14 02:09:23 +13:00
|
|
|
/**
|
|
|
|
* Prefs size exceeded
|
|
|
|
*/
|
|
|
|
|
|
|
|
$prefsObject = [];
|
2021-12-21 04:21:01 +13:00
|
|
|
// Add 1024 keys
|
|
|
|
for($i = 1000; $i < 2024; $i++) {
|
2021-12-21 04:37:17 +13:00
|
|
|
$prefsObject["key" . $i] = "HelloWorldHelloWorldHelloWorldHelloWorldHelloWorldHelloWorldHel";
|
2021-12-21 04:21:01 +13:00
|
|
|
// Each key is 7 characters and value is 63 characters
|
2021-12-14 02:09:23 +13:00
|
|
|
}
|
2021-12-21 04:21:01 +13:00
|
|
|
// That makes total size minimum of 70kB, plus any JSON stuff. Max supported is 64kB, so this should exceed.
|
2021-12-14 02:09:23 +13:00
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/account/prefs', array_merge([
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'cookie' => 'a_session_'.$this->getProject()['$id'].'=' . $session,
|
|
|
|
]), [
|
|
|
|
'prefs' => $prefsObject
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 400);
|
|
|
|
|
2020-01-12 02:58:02 +13:00
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testUpdateAccountPrefs
|
|
|
|
*/
|
2020-02-10 20:34:02 +13:00
|
|
|
public function testCreateAccountVerification($data):array
|
|
|
|
{
|
2020-10-15 10:11:12 +13:00
|
|
|
$email = $data['email'] ?? '';
|
|
|
|
$name = $data['name'] ?? '';
|
|
|
|
$session = $data['session'] ?? '';
|
2020-02-10 20:34:02 +13:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/account/verification', array_merge([
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
2020-02-17 20:16:11 +13:00
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'cookie' => 'a_session_'.$this->getProject()['$id'].'=' . $session,
|
2020-02-10 20:34:02 +13:00
|
|
|
|
|
|
|
]), [
|
|
|
|
'url' => 'http://localhost/verification',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(201, $response['headers']['status-code']);
|
2020-02-17 20:16:11 +13:00
|
|
|
$this->assertNotEmpty($response['body']['$id']);
|
2020-11-19 08:38:31 +13:00
|
|
|
$this->assertEmpty($response['body']['secret']);
|
2020-02-10 20:34:02 +13:00
|
|
|
$this->assertIsNumeric($response['body']['expire']);
|
2020-06-14 06:30:44 +12:00
|
|
|
|
2020-02-10 20:34:02 +13:00
|
|
|
$lastEmail = $this->getLastEmail();
|
|
|
|
|
|
|
|
$this->assertEquals($email, $lastEmail['to'][0]['address']);
|
|
|
|
$this->assertEquals($name, $lastEmail['to'][0]['name']);
|
|
|
|
$this->assertEquals('Account Verification', $lastEmail['subject']);
|
|
|
|
|
|
|
|
$verification = substr($lastEmail['text'], strpos($lastEmail['text'], '&secret=', 0) + 8, 256);
|
|
|
|
|
2021-07-07 02:39:45 +12:00
|
|
|
$expireTime = strpos($lastEmail['text'], 'expire='.$response['body']['expire'], 0);
|
2021-06-18 21:28:54 +12:00
|
|
|
|
|
|
|
$this->assertNotFalse($expireTime);
|
|
|
|
|
|
|
|
$secretTest = strpos($lastEmail['text'], 'secret='.$response['body']['secret'], 0);
|
|
|
|
|
|
|
|
$this->assertNotFalse($secretTest);
|
|
|
|
|
|
|
|
$userIDTest = strpos($lastEmail['text'], 'userId='.$response['body']['userId'], 0);
|
|
|
|
|
|
|
|
$this->assertNotFalse($userIDTest);
|
|
|
|
|
2020-02-10 20:34:02 +13:00
|
|
|
/**
|
|
|
|
* Test for FAILURE
|
|
|
|
*/
|
2020-11-25 09:54:37 +13:00
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/account/verification', array_merge([
|
2020-02-10 20:34:02 +13:00
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
2020-02-17 20:16:11 +13:00
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'cookie' => 'a_session_'.$this->getProject()['$id'].'=' . $session,
|
2020-02-10 20:34:02 +13:00
|
|
|
]), [
|
2020-11-25 09:54:37 +13:00
|
|
|
'url' => 'localhost/verification',
|
2020-02-10 20:34:02 +13:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(400, $response['headers']['status-code']);
|
|
|
|
|
2020-11-25 09:54:37 +13:00
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/account/verification', array_merge([
|
2020-02-10 20:34:02 +13:00
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
2020-02-17 20:16:11 +13:00
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'cookie' => 'a_session_'.$this->getProject()['$id'].'=' . $session,
|
2020-02-10 20:34:02 +13:00
|
|
|
]), [
|
2020-11-25 09:54:37 +13:00
|
|
|
'url' => 'http://remotehost/verification',
|
2020-02-10 20:34:02 +13:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(400, $response['headers']['status-code']);
|
|
|
|
|
|
|
|
$data['verification'] = $verification;
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testCreateAccountVerification
|
|
|
|
*/
|
|
|
|
public function testUpdateAccountVerification($data):array
|
|
|
|
{
|
2020-10-15 10:11:12 +13:00
|
|
|
$id = $data['id'] ?? '';
|
|
|
|
$session = $data['session'] ?? '';
|
|
|
|
$verification = $data['verification'] ?? '';
|
2020-02-10 20:34:02 +13:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
|
|
|
$response = $this->client->call(Client::METHOD_PUT, '/account/verification', array_merge([
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
2020-02-17 20:16:11 +13:00
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'cookie' => 'a_session_'.$this->getProject()['$id'].'=' . $session,
|
2020-02-10 20:34:02 +13:00
|
|
|
]), [
|
2020-02-17 20:16:11 +13:00
|
|
|
'userId' => $id,
|
2020-02-10 20:34:02 +13:00
|
|
|
'secret' => $verification,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for FAILURE
|
|
|
|
*/
|
|
|
|
$response = $this->client->call(Client::METHOD_PUT, '/account/verification', array_merge([
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
2020-02-17 20:16:11 +13:00
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'cookie' => 'a_session_'.$this->getProject()['$id'].'=' . $session,
|
2020-02-10 20:34:02 +13:00
|
|
|
]), [
|
|
|
|
'userId' => 'ewewe',
|
|
|
|
'secret' => $verification,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(404, $response['headers']['status-code']);
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_PUT, '/account/verification', array_merge([
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
2020-02-17 20:16:11 +13:00
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'cookie' => 'a_session_'.$this->getProject()['$id'].'=' . $session,
|
2020-02-10 20:34:02 +13:00
|
|
|
]), [
|
2020-02-17 20:16:11 +13:00
|
|
|
'userId' => $id,
|
2020-02-10 20:34:02 +13:00
|
|
|
'secret' => 'sdasdasdasd',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(401, $response['headers']['status-code']);
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testUpdateAccountVerification
|
|
|
|
*/
|
2020-01-12 02:58:02 +13:00
|
|
|
public function testDeleteAccountSession($data):array
|
|
|
|
{
|
2020-10-15 10:11:12 +13:00
|
|
|
$email = $data['email'] ?? '';
|
|
|
|
$password = $data['password'] ?? '';
|
|
|
|
$session = $data['session'] ?? '';
|
2020-01-12 02:58:02 +13:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
2020-01-13 10:28:26 +13:00
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/account/sessions', 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
|
|
|
]), [
|
2020-01-12 02:58:02 +13:00
|
|
|
'email' => $email,
|
|
|
|
'password' => $password,
|
|
|
|
]);
|
|
|
|
|
2020-04-22 19:03:34 +12:00
|
|
|
$sessionNewId = $response['body']['$id'];
|
2020-07-03 09:48:02 +12:00
|
|
|
$sessionNew = $this->client->parseCookie((string)$response['headers']['set-cookie'])['a_session_'.$this->getProject()['$id']];
|
2020-01-12 02:58:02 +13:00
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 201);
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/account', [
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
2020-02-17 20:16:11 +13:00
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'cookie' => 'a_session_'.$this->getProject()['$id'].'=' . $sessionNew,
|
2020-01-12 02:58:02 +13:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 200);
|
|
|
|
|
2020-04-22 19:03:34 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_DELETE, '/account/sessions/'.$sessionNewId, 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'],
|
|
|
|
'cookie' => 'a_session_'.$this->getProject()['$id'].'=' . $sessionNew,
|
2020-01-13 10:28:26 +13:00
|
|
|
]));
|
2020-01-12 02:58:02 +13:00
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 204);
|
|
|
|
|
2020-01-13 10:28:26 +13:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/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'],
|
|
|
|
'cookie' => 'a_session_'.$this->getProject()['$id'].'=' . $session,
|
2020-01-13 10:28:26 +13:00
|
|
|
]));
|
2020-01-12 02:58:02 +13:00
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 200);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for FAILURE
|
|
|
|
*/
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/account', [
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
2020-02-17 20:16:11 +13:00
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'cookie' => 'a_session_'.$this->getProject()['$id'].'=' . $sessionNew,
|
2020-01-12 02:58:02 +13:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 401);
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-02-10 20:34:02 +13:00
|
|
|
* @depends testUpdateAccountVerification
|
2020-01-12 02:58:02 +13:00
|
|
|
*/
|
|
|
|
public function testDeleteAccountSessionCurrent($data):array
|
|
|
|
{
|
2020-10-15 10:11:12 +13:00
|
|
|
$email = $data['email'] ?? '';
|
|
|
|
$password = $data['password'] ?? '';
|
2020-01-12 02:58:02 +13:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
2020-01-13 10:28:26 +13:00
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/account/sessions', 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
|
|
|
]), [
|
2020-01-12 02:58:02 +13:00
|
|
|
'email' => $email,
|
|
|
|
'password' => $password,
|
|
|
|
]);
|
|
|
|
|
2020-07-03 09:48:02 +12:00
|
|
|
$sessionNew = $this->client->parseCookie((string)$response['headers']['set-cookie'])['a_session_'.$this->getProject()['$id']];
|
2020-01-12 02:58:02 +13:00
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 201);
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/account', [
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
2020-02-17 20:16:11 +13:00
|
|
|
'cookie' => 'a_session_'.$this->getProject()['$id'].'=' . $sessionNew,
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2020-01-12 02:58:02 +13:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 200);
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_DELETE, '/account/sessions/current', [
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
2020-02-17 20:16:11 +13:00
|
|
|
'cookie' => 'a_session_'.$this->getProject()['$id'].'=' . $sessionNew,
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2020-01-12 02:58:02 +13:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 204);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for FAILURE
|
|
|
|
*/
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/account', [
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
2020-02-17 20:16:11 +13:00
|
|
|
'cookie' => 'a_session_'.$this->getProject()['$id'].'=' . $sessionNew,
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2020-01-12 02:58:02 +13:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 401);
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-02-10 20:34:02 +13:00
|
|
|
* @depends testUpdateAccountVerification
|
2020-01-12 02:58:02 +13:00
|
|
|
*/
|
|
|
|
public function testDeleteAccountSessions($data):array
|
|
|
|
{
|
2020-10-15 10:11:12 +13:00
|
|
|
$session = $data['session'] ?? '';
|
2020-01-12 02:58:02 +13:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
2020-01-13 10:28:26 +13:00
|
|
|
$response = $this->client->call(Client::METHOD_DELETE, '/account/sessions', 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'],
|
|
|
|
'cookie' => 'a_session_'.$this->getProject()['$id'].'=' . $session,
|
2020-01-13 10:28:26 +13:00
|
|
|
]));
|
2020-01-12 02:58:02 +13:00
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 204);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for FAILURE
|
|
|
|
*/
|
2020-01-13 10:28:26 +13:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/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
|
|
|
]));
|
2020-01-12 02:58:02 +13:00
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 401);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create new fallback session
|
|
|
|
*/
|
2020-10-15 10:11:12 +13:00
|
|
|
$email = $data['email'] ?? '';
|
|
|
|
$password = $data['password'] ?? '';
|
2020-01-12 02:58:02 +13:00
|
|
|
|
2020-01-13 10:28:26 +13:00
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/account/sessions', 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
|
|
|
]), [
|
2020-01-12 02:58:02 +13:00
|
|
|
'email' => $email,
|
|
|
|
'password' => $password,
|
|
|
|
]);
|
|
|
|
|
2020-07-03 09:48:02 +12:00
|
|
|
$data['session'] = $this->client->parseCookie((string)$response['headers']['set-cookie'])['a_session_'.$this->getProject()['$id']];
|
2020-01-12 02:58:02 +13:00
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testDeleteAccountSession
|
|
|
|
*/
|
2020-02-09 07:51:57 +13:00
|
|
|
public function testCreateAccountRecovery($data):array
|
2020-01-12 02:58:02 +13:00
|
|
|
{
|
2020-10-15 10:11:12 +13:00
|
|
|
$email = $data['email'] ?? '';
|
|
|
|
$name = $data['name'] ?? '';
|
2020-01-12 02:58:02 +13:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
2020-01-13 10:28:26 +13:00
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/account/recovery', 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
|
|
|
]), [
|
2020-01-12 02:58:02 +13:00
|
|
|
'email' => $email,
|
2020-01-12 13:20:35 +13:00
|
|
|
'url' => 'http://localhost/recovery',
|
2020-01-12 02:58:02 +13:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(201, $response['headers']['status-code']);
|
2020-02-17 20:16:11 +13:00
|
|
|
$this->assertNotEmpty($response['body']['$id']);
|
2020-11-19 08:38:31 +13:00
|
|
|
$this->assertEmpty($response['body']['secret']);
|
2020-01-12 02:58:02 +13:00
|
|
|
$this->assertIsNumeric($response['body']['expire']);
|
2020-06-14 06:30:44 +12:00
|
|
|
|
2020-01-12 02:58:02 +13:00
|
|
|
$lastEmail = $this->getLastEmail();
|
|
|
|
|
|
|
|
$this->assertEquals($email, $lastEmail['to'][0]['address']);
|
|
|
|
$this->assertEquals($name, $lastEmail['to'][0]['name']);
|
|
|
|
$this->assertEquals('Password Reset', $lastEmail['subject']);
|
|
|
|
|
2020-01-20 01:22:45 +13:00
|
|
|
$recovery = substr($lastEmail['text'], strpos($lastEmail['text'], '&secret=', 0) + 8, 256);
|
2020-01-12 02:58:02 +13:00
|
|
|
|
2021-07-07 02:39:45 +12:00
|
|
|
$expireTime = strpos($lastEmail['text'], 'expire='.$response['body']['expire'], 0);
|
2021-06-18 01:17:35 +12:00
|
|
|
|
|
|
|
$this->assertNotFalse($expireTime);
|
|
|
|
|
2021-06-18 21:28:54 +12:00
|
|
|
$secretTest = strpos($lastEmail['text'], 'secret='.$response['body']['secret'], 0);
|
|
|
|
|
|
|
|
$this->assertNotFalse($secretTest);
|
|
|
|
|
|
|
|
$userIDTest = strpos($lastEmail['text'], 'userId='.$response['body']['userId'], 0);
|
|
|
|
|
|
|
|
$this->assertNotFalse($userIDTest);
|
2021-06-18 01:17:35 +12:00
|
|
|
|
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/recovery', 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
|
|
|
]), [
|
2020-01-12 02:58:02 +13:00
|
|
|
'email' => $email,
|
2020-01-12 13:20:35 +13:00
|
|
|
'url' => 'localhost/recovery',
|
2020-01-12 02:58:02 +13:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(400, $response['headers']['status-code']);
|
|
|
|
|
2020-01-13 10:28:26 +13:00
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/account/recovery', 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
|
|
|
]), [
|
2020-01-12 02:58:02 +13:00
|
|
|
'email' => $email,
|
2020-01-12 13:20:35 +13:00
|
|
|
'url' => 'http://remotehost/recovery',
|
2020-01-12 02:58:02 +13:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(400, $response['headers']['status-code']);
|
|
|
|
|
2020-01-13 10:28:26 +13:00
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/account/recovery', 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
|
|
|
]), [
|
2020-01-12 02:58:02 +13:00
|
|
|
'email' => 'not-found@localhost.test',
|
2020-01-12 13:20:35 +13:00
|
|
|
'url' => 'http://localhost/recovery',
|
2020-01-12 02:58:02 +13:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(404, $response['headers']['status-code']);
|
|
|
|
|
|
|
|
$data['recovery'] = $recovery;
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testCreateAccountRecovery
|
|
|
|
*/
|
2020-02-09 07:51:57 +13:00
|
|
|
public function testUpdateAccountRecovery($data):array
|
2020-01-12 02:58:02 +13:00
|
|
|
{
|
2020-10-15 10:11:12 +13:00
|
|
|
$id = $data['id'] ?? '';
|
|
|
|
$recovery = $data['recovery'] ?? '';
|
2020-01-12 02:58:02 +13:00
|
|
|
$newPassowrd = 'test-recovery';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
2020-01-13 10:28:26 +13:00
|
|
|
$response = $this->client->call(Client::METHOD_PUT, '/account/recovery', 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
|
|
|
]), [
|
2020-02-17 20:16:11 +13:00
|
|
|
'userId' => $id,
|
2020-01-20 01:22:45 +13:00
|
|
|
'secret' => $recovery,
|
2020-03-26 09:19:19 +13:00
|
|
|
'password' => $newPassowrd,
|
|
|
|
'passwordAgain' => $newPassowrd,
|
2020-01-12 02:58:02 +13:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for FAILURE
|
|
|
|
*/
|
2020-01-13 10:28:26 +13:00
|
|
|
$response = $this->client->call(Client::METHOD_PUT, '/account/recovery', 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
|
|
|
]), [
|
2020-01-12 02:58:02 +13:00
|
|
|
'userId' => 'ewewe',
|
2020-01-20 01:22:45 +13:00
|
|
|
'secret' => $recovery,
|
2020-03-26 09:19:19 +13:00
|
|
|
'password' => $newPassowrd,
|
|
|
|
'passwordAgain' => $newPassowrd,
|
2020-01-12 02:58:02 +13:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(404, $response['headers']['status-code']);
|
|
|
|
|
2020-01-13 10:28:26 +13:00
|
|
|
$response = $this->client->call(Client::METHOD_PUT, '/account/recovery', 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
|
|
|
]), [
|
2020-02-17 20:16:11 +13:00
|
|
|
'userId' => $id,
|
2020-01-20 01:22:45 +13:00
|
|
|
'secret' => 'sdasdasdasd',
|
2020-03-26 09:19:19 +13:00
|
|
|
'password' => $newPassowrd,
|
|
|
|
'passwordAgain' => $newPassowrd,
|
2020-01-12 02:58:02 +13:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(401, $response['headers']['status-code']);
|
|
|
|
|
2020-01-13 10:28:26 +13:00
|
|
|
$response = $this->client->call(Client::METHOD_PUT, '/account/recovery', 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
|
|
|
]), [
|
2020-02-17 20:16:11 +13:00
|
|
|
'userId' => $id,
|
2020-01-20 01:22:45 +13:00
|
|
|
'secret' => $recovery,
|
2020-03-26 09:19:19 +13:00
|
|
|
'password' => $newPassowrd.'x',
|
|
|
|
'passwordAgain' => $newPassowrd,
|
2020-01-12 02:58:02 +13:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(400, $response['headers']['status-code']);
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
2021-08-31 21:22:48 +12:00
|
|
|
|
|
|
|
public function testCreateMagicUrl():array
|
|
|
|
{
|
|
|
|
$email = \time().'user@appwrite.io';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/account/sessions/magic-url', array_merge([
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
]), [
|
2021-10-08 08:10:43 +13:00
|
|
|
'userId' => 'unique()',
|
2021-08-31 21:22:48 +12:00
|
|
|
'email' => $email,
|
|
|
|
// 'url' => 'http://localhost/magiclogin',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$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'];
|
|
|
|
|
|
|
|
$lastEmail = $this->getLastEmail();
|
|
|
|
$this->assertEquals($email, $lastEmail['to'][0]['address']);
|
|
|
|
$this->assertEquals('Login', $lastEmail['subject']);
|
|
|
|
|
|
|
|
$token = substr($lastEmail['text'], strpos($lastEmail['text'], '&secret=', 0) + 8, 256);
|
|
|
|
|
|
|
|
$expireTime = strpos($lastEmail['text'], 'expire='.$response['body']['expire'], 0);
|
|
|
|
|
|
|
|
$this->assertNotFalse($expireTime);
|
|
|
|
|
|
|
|
$secretTest = strpos($lastEmail['text'], 'secret='.$response['body']['secret'], 0);
|
|
|
|
|
|
|
|
$this->assertNotFalse($secretTest);
|
|
|
|
|
|
|
|
$userIDTest = strpos($lastEmail['text'], 'userId='.$response['body']['userId'], 0);
|
|
|
|
|
|
|
|
$this->assertNotFalse($userIDTest);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for FAILURE
|
|
|
|
*/
|
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/account/sessions/magic-url', array_merge([
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
]), [
|
2021-10-08 08:10:43 +13:00
|
|
|
'userId' => 'unique()',
|
2021-08-31 21:22:48 +12:00
|
|
|
'email' => $email,
|
|
|
|
'url' => 'localhost/magiclogin',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(400, $response['headers']['status-code']);
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/account/sessions/magic-url', array_merge([
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
]), [
|
2021-10-08 08:10:43 +13:00
|
|
|
'userId' => 'unique()',
|
2021-08-31 21:22:48 +12:00
|
|
|
'email' => $email,
|
|
|
|
'url' => 'http://remotehost/magiclogin',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(400, $response['headers']['status-code']);
|
|
|
|
|
2021-10-08 08:10:43 +13:00
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/account/sessions/magic-url', array_merge([
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
]), [
|
|
|
|
'email' => $email,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(400, $response['headers']['status-code']);
|
|
|
|
|
2021-08-31 21:22:48 +12:00
|
|
|
$data['token'] = $token;
|
|
|
|
$data['id'] = $userId;
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testCreateMagicUrl
|
|
|
|
*/
|
|
|
|
public function testCreateSessionWithMagicUrl($data):array
|
|
|
|
{
|
|
|
|
$id = $data['id'] ?? '';
|
|
|
|
$token = $data['token'] ?? '';
|
2021-10-08 08:10:43 +13:00
|
|
|
|
2021-08-31 21:22:48 +12:00
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
|
|
|
$response = $this->client->call(Client::METHOD_PUT, '/account/sessions/magic-url', 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']);
|
2021-10-08 08:10:43 +13:00
|
|
|
|
2021-08-31 21:22:48 +12:00
|
|
|
/**
|
|
|
|
* Test for FAILURE
|
|
|
|
*/
|
|
|
|
$response = $this->client->call(Client::METHOD_PUT, '/account/sessions/magic-url', 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/magic-url', 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']);
|
2021-10-08 08:10:43 +13:00
|
|
|
|
2021-08-31 21:22:48 +12:00
|
|
|
return $data;
|
|
|
|
}
|
2020-01-12 02:58:02 +13:00
|
|
|
}
|