1
0
Fork 0
mirror of synced 2024-05-17 19:22:34 +12:00
appwrite/tests/e2e/Services/Account/AccountBase.php

1136 lines
42 KiB
PHP
Raw Normal View History

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
]), [
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
]), [
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'],
]), [
'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'],
]), [
'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'],
]), [
'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));
2020-01-12 02:58:02 +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']);
2020-01-12 02:58:02 +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']);
2020-01-12 02:58:02 +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));
2020-01-12 02:58:02 +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));
2020-01-12 02:58:02 +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']);
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;
}
2020-02-17 00:41:03 +13: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',
'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);
/**
* 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'],
]), [
'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);
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);
/**
* 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']);
$recovery = substr($lastEmail['text'], strpos($lastEmail['text'], '&secret=', 0) + 8, 256);
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,
'secret' => $recovery,
'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',
'secret' => $recovery,
'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,
'secret' => 'sdasdasdasd',
'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,
'secret' => $recovery,
'password' => $newPassowrd.'x',
'passwordAgain' => $newPassowrd,
2020-01-12 02:58:02 +13:00
]);
$this->assertEquals(400, $response['headers']['status-code']);
return $data;
}
}