2020-07-08 21:11:12 +12:00
< ? php
2020-12-27 01:10:14 +13:00
namespace Tests\E2E\Services\Projects ;
2020-07-08 21:11:12 +12:00
2022-07-06 06:55:20 +12:00
use Appwrite\Auth\Auth ;
2023-04-14 08:20:03 +12:00
use Appwrite\Extend\Exception ;
2020-07-08 21:11:12 +12:00
use Tests\E2E\Client ;
2023-12-10 23:03:01 +13:00
use Tests\E2E\General\UsageTest ;
2024-03-07 06:34:21 +13:00
use Tests\E2E\Scopes\ProjectConsole ;
use Tests\E2E\Scopes\Scope ;
use Tests\E2E\Scopes\SideClient ;
2023-11-28 00:30:02 +13:00
use Utopia\Database\Database ;
2022-07-13 01:32:39 +12:00
use Utopia\Database\DateTime ;
2023-12-20 23:55:09 +13:00
use Utopia\Database\Document ;
2022-12-15 04:42:25 +13:00
use Utopia\Database\Helpers\ID ;
2023-12-20 23:55:09 +13:00
use Utopia\Database\Query ;
2020-07-08 21:11:12 +12:00
class ProjectsConsoleClientTest extends Scope
{
use ProjectsBase ;
use ProjectConsole ;
use SideClient ;
2023-03-14 20:21:56 +13:00
/**
2024-02-15 06:22:43 +13:00
* @ group testing
2024-02-14 19:40:19 +13:00
* */
2020-07-08 21:11:12 +12:00
public function testCreateProject () : array
{
/**
* Test for SUCCESS
*/
$team = $this -> client -> call ( Client :: METHOD_POST , '/teams' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
2022-08-14 22:33:36 +12:00
'teamId' => ID :: unique (),
2020-07-08 21:11:12 +12:00
'name' => 'Project Test' ,
]);
$this -> assertEquals ( 201 , $team [ 'headers' ][ 'status-code' ]);
$this -> assertEquals ( 'Project Test' , $team [ 'body' ][ 'name' ]);
$this -> assertNotEmpty ( $team [ 'body' ][ '$id' ]);
$response = $this -> client -> call ( Client :: METHOD_POST , '/projects' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
2022-08-14 22:33:36 +12:00
'projectId' => ID :: unique (),
2020-07-08 21:11:12 +12:00
'name' => 'Project Test' ,
'teamId' => $team [ 'body' ][ '$id' ],
2022-10-01 01:22:11 +13:00
'region' => 'default' ,
2020-07-08 21:11:12 +12:00
]);
$this -> assertEquals ( 201 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertNotEmpty ( $response [ 'body' ][ '$id' ]);
$this -> assertEquals ( 'Project Test' , $response [ 'body' ][ 'name' ]);
$this -> assertEquals ( $team [ 'body' ][ '$id' ], $response [ 'body' ][ 'teamId' ]);
$this -> assertArrayHasKey ( 'platforms' , $response [ 'body' ]);
$this -> assertArrayHasKey ( 'webhooks' , $response [ 'body' ]);
$this -> assertArrayHasKey ( 'keys' , $response [ 'body' ]);
$projectId = $response [ 'body' ][ '$id' ];
2022-11-25 10:37:11 +13:00
$response = $this -> client -> call ( Client :: METHOD_POST , '/projects' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
'projectId' => ID :: unique (),
'name' => 'Project Test' ,
'teamId' => $team [ 'body' ][ '$id' ],
]);
$this -> assertEquals ( 201 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertNotEmpty ( $response [ 'body' ][ '$id' ]);
$this -> assertEquals ( 'Project Test' , $response [ 'body' ][ 'name' ]);
$this -> assertEquals ( $team [ 'body' ][ '$id' ], $response [ 'body' ][ 'teamId' ]);
$this -> assertArrayHasKey ( 'platforms' , $response [ 'body' ]);
$this -> assertArrayHasKey ( 'webhooks' , $response [ 'body' ]);
$this -> assertArrayHasKey ( 'keys' , $response [ 'body' ]);
2020-07-08 21:11:12 +12:00
/**
* Test for FAILURE
*/
$response = $this -> client -> call ( Client :: METHOD_POST , '/projects' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
2022-08-14 22:33:36 +12:00
'projectId' => ID :: unique (),
2020-07-08 21:11:12 +12:00
'name' => '' ,
'teamId' => $team [ 'body' ][ '$id' ],
2022-10-01 01:22:11 +13:00
'region' => 'default'
2020-07-08 21:11:12 +12:00
]);
$this -> assertEquals ( 400 , $response [ 'headers' ][ 'status-code' ]);
2021-08-10 00:47:16 +12:00
2020-07-08 21:11:12 +12:00
$response = $this -> client -> call ( Client :: METHOD_POST , '/projects' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
2022-08-14 22:33:36 +12:00
'projectId' => ID :: unique (),
2020-07-08 21:11:12 +12:00
'name' => 'Project Test' ,
2022-10-01 01:22:11 +13:00
'region' => 'default'
2020-07-08 21:11:12 +12:00
]);
$this -> assertEquals ( 400 , $response [ 'headers' ][ 'status-code' ]);
2023-04-29 19:43:33 +12:00
return [
'projectId' => $projectId ,
'teamId' => $team [ 'body' ][ '$id' ]
];
}
/**
* @ depends testCreateProject
*/
public function testCreateDuplicateProject ( $data )
{
$teamId = $data [ 'teamId' ] ? ? '' ;
$projectId = $data [ 'projectId' ] ? ? '' ;
/**
* Test for FAILURE
*/
$response = $this -> client -> call ( Client :: METHOD_POST , '/projects' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
'projectId' => $projectId ,
'name' => 'Project Duplicate' ,
'teamId' => $teamId ,
'region' => 'default'
]);
2023-04-30 08:24:45 +12:00
$this -> assertEquals ( 409 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertEquals ( 409 , $response [ 'body' ][ 'code' ]);
2023-04-29 19:43:33 +12:00
$this -> assertEquals ( Exception :: PROJECT_ALREADY_EXISTS , $response [ 'body' ][ 'type' ]);
2020-07-08 21:11:12 +12:00
}
2023-05-10 18:46:30 +12:00
/** @group projectsCRUD */
2023-05-02 19:28:46 +12:00
public function testTransferProjectTeam ()
{
/**
* Test for SUCCESS
*/
$team = $this -> client -> call ( Client :: METHOD_POST , '/teams' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
'teamId' => ID :: unique (),
2023-05-10 18:46:30 +12:00
'name' => 'Team 1' ,
2023-05-02 19:28:46 +12:00
]);
$this -> assertEquals ( 201 , $team [ 'headers' ][ 'status-code' ]);
2023-05-10 18:46:30 +12:00
$this -> assertEquals ( 'Team 1' , $team [ 'body' ][ 'name' ]);
2023-05-02 19:28:46 +12:00
$this -> assertNotEmpty ( $team [ 'body' ][ '$id' ]);
$team1 = $team [ 'body' ][ '$id' ];
$team = $this -> client -> call ( Client :: METHOD_POST , '/teams' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
'teamId' => ID :: unique (),
2023-05-10 18:46:30 +12:00
'name' => 'Team 2' ,
2023-05-02 19:28:46 +12:00
]);
$this -> assertEquals ( 201 , $team [ 'headers' ][ 'status-code' ]);
2023-05-10 18:46:30 +12:00
$this -> assertEquals ( 'Team 2' , $team [ 'body' ][ 'name' ]);
2023-05-02 19:28:46 +12:00
$this -> assertNotEmpty ( $team [ 'body' ][ '$id' ]);
$team2 = $team [ 'body' ][ '$id' ];
$response = $this -> client -> call ( Client :: METHOD_POST , '/projects' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
'projectId' => ID :: unique (),
2023-05-10 18:46:30 +12:00
'name' => 'Team 1 Project' ,
2023-05-02 19:28:46 +12:00
'teamId' => $team1 ,
'region' => 'default' ,
]);
$this -> assertEquals ( 201 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertNotEmpty ( $response [ 'body' ][ '$id' ]);
2023-05-10 18:46:30 +12:00
$this -> assertEquals ( 'Team 1 Project' , $response [ 'body' ][ 'name' ]);
2023-05-02 19:28:46 +12:00
$this -> assertEquals ( $team1 , $response [ 'body' ][ 'teamId' ]);
$this -> assertArrayHasKey ( 'platforms' , $response [ 'body' ]);
$this -> assertArrayHasKey ( 'webhooks' , $response [ 'body' ]);
$this -> assertArrayHasKey ( 'keys' , $response [ 'body' ]);
$projectId = $response [ 'body' ][ '$id' ];
$response = $this -> client -> call ( Client :: METHOD_PATCH , '/projects/' . $projectId . '/team' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
'teamId' => $team2 ,
]);
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertNotEmpty ( $response [ 'body' ][ '$id' ]);
2023-05-10 18:46:30 +12:00
$this -> assertEquals ( 'Team 1 Project' , $response [ 'body' ][ 'name' ]);
2023-05-02 19:28:46 +12:00
$this -> assertEquals ( $team2 , $response [ 'body' ][ 'teamId' ]);
2020-07-08 21:11:12 +12:00
}
2020-07-09 03:20:18 +12:00
/**
2023-05-10 18:46:30 +12:00
* @ group projectsCRUD
2020-07-09 03:20:18 +12:00
* @ depends testCreateProject
*/
2022-04-19 04:21:45 +12:00
public function testListProject ( $data ) : array
2020-07-09 03:20:18 +12:00
{
2020-10-15 10:11:12 +13:00
$id = $data [ 'projectId' ] ? ? '' ;
2020-07-09 03:20:18 +12:00
/**
* Test for SUCCESS
*/
2021-09-23 19:01:10 +12:00
2020-07-09 03:20:18 +12:00
$response = $this -> client -> call ( Client :: METHOD_GET , '/projects' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()));
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertNotEmpty ( $response [ 'body' ]);
$this -> assertEquals ( $id , $response [ 'body' ][ 'projects' ][ 0 ][ '$id' ]);
$this -> assertEquals ( 'Project Test' , $response [ 'body' ][ 'projects' ][ 0 ][ 'name' ]);
2021-09-23 19:01:10 +12:00
/**
* Test search queries
*/
2021-09-21 20:22:13 +12:00
$response = $this -> client -> call ( Client :: METHOD_GET , '/projects' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders (), [
'search' => $id
]));
2021-09-23 19:01:10 +12:00
$this -> assertEquals ( $response [ 'headers' ][ 'status-code' ], 200 );
2023-05-04 13:26:03 +12:00
$this -> assertEquals ( $response [ 'body' ][ 'total' ], 3 );
2021-09-23 19:01:10 +12:00
$this -> assertIsArray ( $response [ 'body' ][ 'projects' ]);
2023-05-10 18:46:30 +12:00
$this -> assertCount ( 3 , $response [ 'body' ][ 'projects' ]);
2021-09-23 19:01:10 +12:00
$this -> assertEquals ( $response [ 'body' ][ 'projects' ][ 0 ][ 'name' ], 'Project Test' );
2021-09-21 20:22:13 +12:00
$response = $this -> client -> call ( Client :: METHOD_GET , '/projects' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders (), [
'search' => 'Project Test'
]));
2021-09-23 19:01:10 +12:00
$this -> assertEquals ( $response [ 'headers' ][ 'status-code' ], 200 );
2023-05-10 18:46:30 +12:00
$this -> assertEquals ( 3 , $response [ 'body' ][ 'total' ]);
2021-09-23 19:01:10 +12:00
$this -> assertIsArray ( $response [ 'body' ][ 'projects' ]);
2023-05-10 18:46:30 +12:00
$this -> assertCount ( 3 , $response [ 'body' ][ 'projects' ]);
2021-09-23 19:01:10 +12:00
$this -> assertEquals ( $response [ 'body' ][ 'projects' ][ 0 ][ '$id' ], $data [ 'projectId' ]);
2021-09-21 20:22:13 +12:00
2021-08-10 00:47:16 +12:00
/**
2022-09-01 04:00:14 +12:00
* Test pagination
2021-08-10 00:47:16 +12:00
*/
$team = $this -> client -> call ( Client :: METHOD_POST , '/teams' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
2022-08-14 22:33:36 +12:00
'teamId' => ID :: unique (),
2021-08-10 00:47:16 +12:00
'name' => 'Project Test 2' ,
]);
$this -> assertEquals ( 201 , $team [ 'headers' ][ 'status-code' ]);
$this -> assertEquals ( 'Project Test 2' , $team [ 'body' ][ 'name' ]);
$this -> assertNotEmpty ( $team [ 'body' ][ '$id' ]);
$response = $this -> client -> call ( Client :: METHOD_POST , '/projects' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
2022-08-14 22:33:36 +12:00
'projectId' => ID :: unique (),
2021-08-10 00:47:16 +12:00
'name' => 'Project Test 2' ,
'teamId' => $team [ 'body' ][ '$id' ],
2022-10-01 01:22:11 +13:00
'region' => 'default'
2021-08-10 00:47:16 +12:00
]);
$this -> assertEquals ( 201 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertNotEmpty ( $response [ 'body' ][ '$id' ]);
$this -> assertEquals ( 'Project Test 2' , $response [ 'body' ][ 'name' ]);
$this -> assertEquals ( $team [ 'body' ][ '$id' ], $response [ 'body' ][ 'teamId' ]);
$this -> assertArrayHasKey ( 'platforms' , $response [ 'body' ]);
$this -> assertArrayHasKey ( 'webhooks' , $response [ 'body' ]);
$this -> assertArrayHasKey ( 'keys' , $response [ 'body' ]);
2022-09-01 04:00:14 +12:00
$response = $this -> client -> call ( Client :: METHOD_GET , '/projects' , array_merge ([
'content-type' => 'application/json' ,
2022-10-03 20:16:49 +13:00
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
2023-12-20 23:55:09 +13:00
'queries' => [
Query :: equal ( 'teamId' , [ $team [ 'body' ][ '$id' ]]) -> toString (),
],
2022-10-03 20:16:49 +13:00
]);
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertNotEmpty ( $response [ 'body' ]);
$this -> assertCount ( 1 , $response [ 'body' ][ 'projects' ]);
2022-10-03 20:54:55 +13:00
$this -> assertEquals ( $team [ 'body' ][ '$id' ], $response [ 'body' ][ 'projects' ][ 0 ][ 'teamId' ]);
2022-10-03 20:16:49 +13:00
2022-09-01 04:00:14 +12:00
$response = $this -> client -> call ( Client :: METHOD_GET , '/projects' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
2023-12-20 23:55:09 +13:00
'queries' => [
Query :: limit ( 1 ) -> toString (),
],
2022-09-01 04:00:14 +12:00
]);
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertNotEmpty ( $response [ 'body' ]);
$this -> assertCount ( 1 , $response [ 'body' ][ 'projects' ]);
$this -> assertEquals ( 'Project Test' , $response [ 'body' ][ 'projects' ][ 0 ][ 'name' ]);
$response = $this -> client -> call ( Client :: METHOD_GET , '/projects' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
2023-12-20 23:55:09 +13:00
'queries' => [
Query :: offset ( 3 ) -> toString (),
],
2022-09-01 04:00:14 +12:00
]);
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertNotEmpty ( $response [ 'body' ]);
$this -> assertCount ( 1 , $response [ 'body' ][ 'projects' ]);
$this -> assertEquals ( 'Project Test 2' , $response [ 'body' ][ 'projects' ][ 0 ][ 'name' ]);
$response = $this -> client -> call ( Client :: METHOD_GET , '/projects' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
2023-12-20 23:55:09 +13:00
'queries' => [
Query :: equal ( 'name' , [ 'Project Test 2' ]) -> toString (),
],
2022-09-01 04:00:14 +12:00
]);
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertNotEmpty ( $response [ 'body' ]);
$this -> assertCount ( 1 , $response [ 'body' ][ 'projects' ]);
$this -> assertEquals ( 'Project Test 2' , $response [ 'body' ][ 'projects' ][ 0 ][ 'name' ]);
$response = $this -> client -> call ( Client :: METHOD_GET , '/projects' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
2023-12-20 23:55:09 +13:00
'queries' => [
Query :: orderDesc () -> toString (),
],
2022-09-01 04:00:14 +12:00
]);
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertNotEmpty ( $response [ 'body' ]);
2023-05-10 18:46:30 +12:00
$this -> assertCount ( 4 , $response [ 'body' ][ 'projects' ]);
2022-09-01 04:00:14 +12:00
$this -> assertEquals ( 'Project Test 2' , $response [ 'body' ][ 'projects' ][ 0 ][ 'name' ]);
2023-05-10 18:46:30 +12:00
$this -> assertEquals ( 'Team 1 Project' , $response [ 'body' ][ 'projects' ][ 1 ][ 'name' ]);
2022-09-01 04:00:14 +12:00
2021-08-10 00:47:16 +12:00
$response = $this -> client -> call ( Client :: METHOD_GET , '/projects' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()));
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertNotEmpty ( $response [ 'body' ]);
2023-05-10 18:46:30 +12:00
$this -> assertCount ( 4 , $response [ 'body' ][ 'projects' ]);
2021-08-10 00:47:16 +12:00
$this -> assertEquals ( 'Project Test' , $response [ 'body' ][ 'projects' ][ 0 ][ 'name' ]);
2023-05-10 18:46:30 +12:00
$this -> assertEquals ( 'Team 1 Project' , $response [ 'body' ][ 'projects' ][ 2 ][ 'name' ]);
2021-08-10 00:47:16 +12:00
$response = $this -> client -> call ( Client :: METHOD_GET , '/projects' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
2022-04-19 04:21:45 +12:00
], $this -> getHeaders ()), [
2023-12-20 23:55:09 +13:00
'queries' => [
Query :: cursorAfter ( new Document ([ '$id' => $response [ 'body' ][ 'projects' ][ 0 ][ '$id' ]])) -> toString (),
],
2021-08-10 00:47:16 +12:00
]);
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertNotEmpty ( $response [ 'body' ]);
2023-05-10 18:46:30 +12:00
$this -> assertCount ( 3 , $response [ 'body' ][ 'projects' ]);
$this -> assertEquals ( 'Team 1 Project' , $response [ 'body' ][ 'projects' ][ 1 ][ 'name' ]);
2021-10-05 23:30:33 +13:00
$response = $this -> client -> call ( Client :: METHOD_GET , '/projects' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
2022-04-19 04:21:45 +12:00
], $this -> getHeaders ()), [
2023-12-20 23:55:09 +13:00
'queries' => [
Query :: cursorBefore ( new Document ([ '$id' => $response [ 'body' ][ 'projects' ][ 0 ][ '$id' ]])) -> toString (),
],
2021-10-05 23:30:33 +13:00
]);
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertNotEmpty ( $response [ 'body' ]);
$this -> assertCount ( 1 , $response [ 'body' ][ 'projects' ]);
$this -> assertEquals ( 'Project Test' , $response [ 'body' ][ 'projects' ][ 0 ][ 'name' ]);
2020-07-09 03:20:18 +12:00
/**
* Test for FAILURE
*/
2021-10-05 23:30:33 +13:00
$response = $this -> client -> call ( Client :: METHOD_GET , '/projects' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
2022-04-19 04:21:45 +12:00
], $this -> getHeaders ()), [
2023-12-20 23:55:09 +13:00
'queries' => [
Query :: cursorAfter ( new Document ([ '$id' => 'unknown' ])) -> toString (),
],
2021-10-05 23:30:33 +13:00
]);
$this -> assertEquals ( 400 , $response [ 'headers' ][ 'status-code' ]);
2020-07-09 03:20:18 +12:00
2020-07-09 21:13:14 +12:00
return $data ;
2020-07-09 03:20:18 +12:00
}
2020-07-08 21:11:12 +12:00
/**
* @ depends testCreateProject
*/
2022-04-19 04:21:45 +12:00
public function testGetProject ( $data ) : array
2020-07-08 21:11:12 +12:00
{
2020-10-15 10:11:12 +13:00
$id = $data [ 'projectId' ] ? ? '' ;
2020-07-08 21:11:12 +12:00
/**
* Test for SUCCESS
*/
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_GET , '/projects/' . $id , array_merge ([
2020-07-08 21:11:12 +12:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()));
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertNotEmpty ( $response [ 'body' ]);
$this -> assertEquals ( $id , $response [ 'body' ][ '$id' ]);
$this -> assertEquals ( 'Project Test' , $response [ 'body' ][ 'name' ]);
/**
* Test for FAILURE
*/
$response = $this -> client -> call ( Client :: METHOD_GET , '/projects/empty' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()));
$this -> assertEquals ( 404 , $response [ 'headers' ][ 'status-code' ]);
$response = $this -> client -> call ( Client :: METHOD_GET , '/projects/id-is-really-long-id-is-really-long-id-is-really-long-id-is-really-long' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()));
$this -> assertEquals ( 400 , $response [ 'headers' ][ 'status-code' ]);
2020-10-28 08:48:38 +13:00
return $data ;
2020-07-08 21:11:12 +12:00
}
2020-07-09 03:20:18 +12:00
/**
* @ depends testCreateProject
*/
2022-04-19 04:21:45 +12:00
public function testGetProjectUsage ( $data ) : array
2020-07-09 03:20:18 +12:00
{
2024-01-10 00:58:36 +13:00
$this -> markTestIncomplete (
'This test is failing right now due to functions collection.'
);
2020-07-09 03:20:18 +12:00
/**
* Test for SUCCESS
*/
2023-10-25 20:39:59 +13:00
$response = $this -> client -> call ( Client :: METHOD_GET , '/project/usage' , array_merge ([
2020-07-09 03:20:18 +12:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
2023-12-10 23:03:01 +13:00
], $this -> getHeaders ()), [
'startDate' => UsageTest :: getToday (),
'endDate' => UsageTest :: getTomorrow (),
]);
2020-07-09 03:20:18 +12:00
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
2023-12-10 23:03:01 +13:00
$this -> assertEquals ( 8 , count ( $response [ 'body' ]));
2020-07-09 03:20:18 +12:00
$this -> assertNotEmpty ( $response [ 'body' ]);
2023-08-21 00:29:43 +12:00
$this -> assertIsArray ( $response [ 'body' ][ 'requests' ]);
2021-08-29 20:11:29 +12:00
$this -> assertIsArray ( $response [ 'body' ][ 'network' ]);
2023-11-27 09:57:57 +13:00
$this -> assertIsNumeric ( $response [ 'body' ][ 'executionsTotal' ]);
$this -> assertIsNumeric ( $response [ 'body' ][ 'documentsTotal' ]);
$this -> assertIsNumeric ( $response [ 'body' ][ 'databasesTotal' ]);
$this -> assertIsNumeric ( $response [ 'body' ][ 'bucketsTotal' ]);
$this -> assertIsNumeric ( $response [ 'body' ][ 'usersTotal' ]);
$this -> assertIsNumeric ( $response [ 'body' ][ 'filesStorageTotal' ]);
2020-07-09 03:20:18 +12:00
/**
* Test for FAILURE
*/
$response = $this -> client -> call ( Client :: METHOD_GET , '/projects/empty' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()));
$this -> assertEquals ( 404 , $response [ 'headers' ][ 'status-code' ]);
$response = $this -> client -> call ( Client :: METHOD_GET , '/projects/id-is-really-long-id-is-really-long-id-is-really-long-id-is-really-long' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()));
$this -> assertEquals ( 400 , $response [ 'headers' ][ 'status-code' ]);
2020-10-28 08:48:38 +13:00
return $data ;
2020-07-09 21:13:14 +12:00
}
/**
2024-01-10 00:58:36 +13:00
* @ depends testCreateProject
2020-07-09 21:13:14 +12:00
*/
2022-04-19 04:21:45 +12:00
public function testUpdateProject ( $data ) : array
2020-07-09 21:13:14 +12:00
{
2020-10-15 10:11:12 +13:00
$id = $data [ 'projectId' ] ? ? '' ;
2020-07-09 21:13:14 +12:00
/**
* Test for SUCCESS
*/
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_PATCH , '/projects/' . $id , array_merge ([
2020-07-09 21:13:14 +12:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
2022-08-14 22:33:36 +12:00
'projectId' => ID :: unique (),
2020-07-09 21:13:14 +12:00
'name' => 'Project Test 2' ,
]);
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertNotEmpty ( $response [ 'body' ][ '$id' ]);
$this -> assertEquals ( 'Project Test 2' , $response [ 'body' ][ 'name' ]);
2020-11-21 12:31:17 +13:00
$this -> assertArrayHasKey ( 'platforms' , $response [ 'body' ]);
$this -> assertArrayHasKey ( 'webhooks' , $response [ 'body' ]);
$this -> assertArrayHasKey ( 'keys' , $response [ 'body' ]);
2020-07-09 21:13:14 +12:00
$projectId = $response [ 'body' ][ '$id' ];
/**
* Test for FAILURE
*/
2022-04-19 04:21:45 +12:00
2020-07-09 21:13:14 +12:00
$response = $this -> client -> call ( Client :: METHOD_POST , '/projects' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
2022-08-14 22:33:36 +12:00
'projectId' => ID :: unique (),
2020-07-09 21:13:14 +12:00
'name' => '' ,
]);
$this -> assertEquals ( 400 , $response [ 'headers' ][ 'status-code' ]);
return [ 'projectId' => $projectId ];
}
2023-03-10 15:44:43 +13:00
/**
2023-03-14 20:21:56 +13:00
* @ group smtpAndTemplates
2023-03-10 15:44:43 +13:00
* @ depends testCreateProject
*/
2023-03-10 15:46:34 +13:00
public function testUpdateProjectSMTP ( $data ) : array
{
2023-03-10 15:44:43 +13:00
$id = $data [ 'projectId' ];
$response = $this -> client -> call ( Client :: METHOD_PATCH , '/projects/' . $id . '/smtp' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
'enabled' => true ,
2023-08-30 16:30:44 +12:00
'senderEmail' => 'mailer@appwrite.io' ,
'senderName' => 'Mailer' ,
2023-07-20 13:32:19 +12:00
'host' => 'maildev' ,
'port' => 1025 ,
'username' => 'user' ,
'password' => 'password' ,
2023-03-10 15:44:43 +13:00
]);
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertTrue ( $response [ 'body' ][ 'smtpEnabled' ]);
2023-08-30 16:30:44 +12:00
$this -> assertEquals ( 'mailer@appwrite.io' , $response [ 'body' ][ 'smtpSenderEmail' ]);
$this -> assertEquals ( 'Mailer' , $response [ 'body' ][ 'smtpSenderName' ]);
2023-07-20 13:32:19 +12:00
$this -> assertEquals ( 'maildev' , $response [ 'body' ][ 'smtpHost' ]);
$this -> assertEquals ( 1025 , $response [ 'body' ][ 'smtpPort' ]);
$this -> assertEquals ( 'user' , $response [ 'body' ][ 'smtpUsername' ]);
$this -> assertEquals ( 'password' , $response [ 'body' ][ 'smtpPassword' ]);
2023-03-10 15:44:43 +13:00
$this -> assertEquals ( '' , $response [ 'body' ][ 'smtpSecure' ]);
2023-03-14 20:21:56 +13:00
/** Test Reading Project */
$response = $this -> client -> call ( Client :: METHOD_GET , '/projects/' . $id , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()));
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertTrue ( $response [ 'body' ][ 'smtpEnabled' ]);
2023-08-30 16:30:44 +12:00
$this -> assertEquals ( 'mailer@appwrite.io' , $response [ 'body' ][ 'smtpSenderEmail' ]);
$this -> assertEquals ( 'Mailer' , $response [ 'body' ][ 'smtpSenderName' ]);
2023-07-20 13:33:27 +12:00
$this -> assertEquals ( 'maildev' , $response [ 'body' ][ 'smtpHost' ]);
$this -> assertEquals ( 1025 , $response [ 'body' ][ 'smtpPort' ]);
$this -> assertEquals ( 'user' , $response [ 'body' ][ 'smtpUsername' ]);
$this -> assertEquals ( 'password' , $response [ 'body' ][ 'smtpPassword' ]);
2023-03-14 20:21:56 +13:00
$this -> assertEquals ( '' , $response [ 'body' ][ 'smtpSecure' ]);
2023-03-17 19:37:16 +13:00
2023-03-14 20:21:56 +13:00
return $data ;
}
2023-12-20 04:19:57 +13:00
/**
* @ group smtpAndTemplates
2024-01-16 00:00:33 +13:00
* @ depends testCreateProject
2023-12-20 04:19:57 +13:00
*/
public function testCreateProjectSMTPTests ( $data ) : array
{
$id = $data [ 'projectId' ];
2023-12-20 11:31:45 +13:00
$response = $this -> client -> call ( Client :: METHOD_POST , '/projects/' . $id . '/smtp/tests' , array_merge ([
2023-12-20 04:19:57 +13:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
2024-06-21 02:49:56 +12:00
'emails' => [ 'testuser@appwrite.io' , 'testusertwo@appwrite.io' ],
2024-01-16 00:00:33 +13:00
'senderEmail' => 'custommailer@appwrite.io' ,
'senderName' => 'Custom Mailer' ,
'replyTo' => 'reply@appwrite.io' ,
'host' => 'maildev' ,
'port' => 1025 ,
'username' => '' ,
'password' => '' ,
2023-12-20 04:19:57 +13:00
]);
$this -> assertEquals ( 204 , $response [ 'headers' ][ 'status-code' ]);
2024-01-16 00:00:33 +13:00
$emails = $this -> getLastEmail ( 2 );
$this -> assertCount ( 2 , $emails );
$this -> assertEquals ( 'custommailer@appwrite.io' , $emails [ 0 ][ 'from' ][ 0 ][ 'address' ]);
$this -> assertEquals ( 'Custom Mailer' , $emails [ 0 ][ 'from' ][ 0 ][ 'name' ]);
$this -> assertEquals ( 'reply@appwrite.io' , $emails [ 0 ][ 'replyTo' ][ 0 ][ 'address' ]);
$this -> assertEquals ( 'Custom Mailer' , $emails [ 0 ][ 'replyTo' ][ 0 ][ 'name' ]);
2024-01-18 00:22:08 +13:00
$this -> assertEquals ( 'Custom SMTP email sample' , $emails [ 0 ][ 'subject' ]);
$this -> assertStringContainsStringIgnoringCase ( 'working correctly' , $emails [ 0 ][ 'text' ]);
$this -> assertStringContainsStringIgnoringCase ( 'working correctly' , $emails [ 0 ][ 'html' ]);
$this -> assertStringContainsStringIgnoringCase ( '251 Little Falls Drive' , $emails [ 0 ][ 'text' ]);
$this -> assertStringContainsStringIgnoringCase ( '251 Little Falls Drive' , $emails [ 0 ][ 'html' ]);
2024-01-16 00:00:33 +13:00
$to = [
$emails [ 0 ][ 'to' ][ 0 ][ 'address' ],
$emails [ 1 ][ 'to' ][ 0 ][ 'address' ]
];
\sort ( $to );
$this -> assertEquals ( 'testuser@appwrite.io' , $to [ 0 ]);
$this -> assertEquals ( 'testusertwo@appwrite.io' , $to [ 1 ]);
2023-12-20 10:39:40 +13:00
2024-01-18 05:47:26 +13:00
$response = $this -> client -> call ( Client :: METHOD_POST , '/projects/' . $id . '/smtp/tests' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
2024-06-21 02:49:56 +12:00
'emails' => [ 'u1@appwrite.io' , 'u2@appwrite.io' , 'u3@appwrite.io' , 'u4@appwrite.io' , 'u5@appwrite.io' , 'u6@appwrite.io' , 'u7@appwrite.io' , 'u8@appwrite.io' , 'u9@appwrite.io' , 'u10@appwrite.io' ],
2024-01-18 05:47:26 +13:00
'senderEmail' => 'custommailer@appwrite.io' ,
'senderName' => 'Custom Mailer' ,
'replyTo' => 'reply@appwrite.io' ,
'host' => 'maildev' ,
'port' => 1025 ,
'username' => '' ,
'password' => '' ,
]);
$this -> assertEquals ( 204 , $response [ 'headers' ][ 'status-code' ]);
$response = $this -> client -> call ( Client :: METHOD_POST , '/projects/' . $id . '/smtp/tests' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
2024-06-21 02:49:56 +12:00
'emails' => [ 'u1@appwrite.io' , 'u2@appwrite.io' , 'u3@appwrite.io' , 'u4@appwrite.io' , 'u5@appwrite.io' , 'u6@appwrite.io' , 'u7@appwrite.io' , 'u8@appwrite.io' , 'u9@appwrite.io' , 'u10@appwrite.io' , 'u11@appwrite.io' ],
2024-01-18 05:47:26 +13:00
'senderEmail' => 'custommailer@appwrite.io' ,
'senderName' => 'Custom Mailer' ,
'replyTo' => 'reply@appwrite.io' ,
'host' => 'maildev' ,
'port' => 1025 ,
'username' => '' ,
'password' => '' ,
]);
$this -> assertEquals ( 400 , $response [ 'headers' ][ 'status-code' ]);
2023-12-20 04:19:57 +13:00
return $data ;
}
2023-03-14 20:21:56 +13:00
/**
2023-03-14 20:24:03 +13:00
* @ group smtpAndTemplates
2023-08-29 14:41:48 +12:00
* @ depends testUpdateProjectSMTP
*/
2023-03-14 20:21:56 +13:00
public function testUpdateTemplates ( $data ) : array
{
$id = $data [ 'projectId' ];
2023-03-14 22:13:43 +13:00
/** Get Default Email Template */
2023-04-18 19:13:52 +12:00
$response = $this -> client -> call ( Client :: METHOD_GET , '/projects/' . $id . '/templates/email/verification/en-us' , array_merge ([
2023-03-14 20:21:56 +13:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()));
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertEquals ( 'Account Verification' , $response [ 'body' ][ 'subject' ]);
2023-08-30 17:31:21 +12:00
$this -> assertEquals ( '' , $response [ 'body' ][ 'senderEmail' ]);
2023-03-14 20:21:56 +13:00
$this -> assertEquals ( 'verification' , $response [ 'body' ][ 'type' ]);
2023-04-18 19:13:52 +12:00
$this -> assertEquals ( 'en-us' , $response [ 'body' ][ 'locale' ]);
2023-03-14 20:24:03 +13:00
2023-03-14 22:13:43 +13:00
/** Update Email template */
2023-04-18 19:13:52 +12:00
$response = $this -> client -> call ( Client :: METHOD_PATCH , '/projects/' . $id . '/templates/email/verification/en-us' , array_merge ([
2023-03-14 20:21:56 +13:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
'subject' => 'Please verify your email' ,
'message' => 'Please verify your email {{url}}' ,
'senderName' => 'Appwrite Custom' ,
'senderEmail' => 'custom@appwrite.io' ,
]);
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertEquals ( 'Please verify your email' , $response [ 'body' ][ 'subject' ]);
$this -> assertEquals ( 'Appwrite Custom' , $response [ 'body' ][ 'senderName' ]);
$this -> assertEquals ( 'custom@appwrite.io' , $response [ 'body' ][ 'senderEmail' ]);
$this -> assertEquals ( 'verification' , $response [ 'body' ][ 'type' ]);
2023-04-18 19:13:52 +12:00
$this -> assertEquals ( 'en-us' , $response [ 'body' ][ 'locale' ]);
2023-03-14 20:21:56 +13:00
$this -> assertEquals ( 'Please verify your email {{url}}' , $response [ 'body' ][ 'message' ]);
2023-03-14 22:13:43 +13:00
/** Get Updated Email Template */
2023-04-18 19:13:52 +12:00
$response = $this -> client -> call ( Client :: METHOD_GET , '/projects/' . $id . '/templates/email/verification/en-us' , array_merge ([
2023-03-14 20:21:56 +13:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()));
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertEquals ( 'Please verify your email' , $response [ 'body' ][ 'subject' ]);
$this -> assertEquals ( 'Appwrite Custom' , $response [ 'body' ][ 'senderName' ]);
$this -> assertEquals ( 'custom@appwrite.io' , $response [ 'body' ][ 'senderEmail' ]);
$this -> assertEquals ( 'verification' , $response [ 'body' ][ 'type' ]);
2023-04-18 19:13:52 +12:00
$this -> assertEquals ( 'en-us' , $response [ 'body' ][ 'locale' ]);
2023-03-14 20:21:56 +13:00
$this -> assertEquals ( 'Please verify your email {{url}}' , $response [ 'body' ][ 'message' ]);
2023-08-26 03:13:25 +12:00
// Temporary disabled until implemented
// /** Get Default SMS Template */
// $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/templates/sms/verification/en-us', array_merge([
// 'content-type' => 'application/json',
// 'x-appwrite-project' => $this->getProject()['$id'],
// ], $this->getHeaders()));
// $this->assertEquals(200, $response['headers']['status-code']);
// $this->assertEquals('verification', $response['body']['type']);
// $this->assertEquals('en-us', $response['body']['locale']);
// $this->assertEquals('{{token}}', $response['body']['message']);
// /** Update SMS template */
// $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/templates/sms/verification/en-us', array_merge([
// 'content-type' => 'application/json',
// 'x-appwrite-project' => $this->getProject()['$id'],
// ], $this->getHeaders()), [
// 'message' => 'Please verify your email {{token}}',
// ]);
// $this->assertEquals(200, $response['headers']['status-code']);
// $this->assertEquals('verification', $response['body']['type']);
// $this->assertEquals('en-us', $response['body']['locale']);
// $this->assertEquals('Please verify your email {{token}}', $response['body']['message']);
// /** Get Updated SMS Template */
// $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/templates/sms/verification/en-us', array_merge([
// 'content-type' => 'application/json',
// 'x-appwrite-project' => $this->getProject()['$id'],
// ], $this->getHeaders()));
// $this->assertEquals(200, $response['headers']['status-code']);
// $this->assertEquals('verification', $response['body']['type']);
// $this->assertEquals('en-us', $response['body']['locale']);
// $this->assertEquals('Please verify your email {{token}}', $response['body']['message']);
2023-03-14 22:13:43 +13:00
2023-03-10 15:44:43 +13:00
return $data ;
}
2024-01-10 00:58:36 +13:00
/** @depends testCreateProject */
2022-11-02 03:43:18 +13:00
public function testUpdateProjectAuthDuration ( $data ) : array
2022-11-02 00:15:45 +13:00
{
$id = $data [ 'projectId' ];
2022-11-15 23:19:35 +13:00
// Check defaults
$response = $this -> client -> call ( Client :: METHOD_GET , '/projects/' . $id , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => 'console' ,
], $this -> getHeaders ()));
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertEquals ( Auth :: TOKEN_EXPIRATION_LOGIN_LONG , $response [ 'body' ][ 'authDuration' ]); // 1 Year
2022-11-02 00:15:45 +13:00
/**
* Test for SUCCESS
*/
2022-11-14 22:42:18 +13:00
2022-11-15 02:00:50 +13:00
$response = $this -> client -> call ( Client :: METHOD_PATCH , '/projects/' . $id . '/auth/duration' , array_merge ([
2022-11-02 00:15:45 +13:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
2024-01-16 03:37:47 +13:00
'duration' => 60 , // Set session duration to 1 minute
2022-11-02 00:15:45 +13:00
]);
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertNotEmpty ( $response [ 'body' ][ '$id' ]);
$this -> assertEquals ( 'Project Test 2' , $response [ 'body' ][ 'name' ]);
$this -> assertArrayHasKey ( 'platforms' , $response [ 'body' ]);
$this -> assertArrayHasKey ( 'webhooks' , $response [ 'body' ]);
$this -> assertArrayHasKey ( 'keys' , $response [ 'body' ]);
2022-11-15 02:00:50 +13:00
$this -> assertEquals ( 60 , $response [ 'body' ][ 'authDuration' ]);
2022-11-02 00:15:45 +13:00
$projectId = $response [ 'body' ][ '$id' ];
// Create New User
$response = $this -> client -> call ( Client :: METHOD_POST , '/account' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $projectId ,
], $this -> getHeaders ()), [
'userId' => 'unique()' ,
'email' => 'test' . rand ( 0 , 9999 ) . '@example.com' ,
'password' => 'password' ,
'name' => 'Test User' ,
]);
$this -> assertEquals ( 201 , $response [ 'headers' ][ 'status-code' ]);
$userEmail = $response [ 'body' ][ 'email' ];
// Create New User Session
$response = $this -> client -> call ( Client :: METHOD_POST , '/account/sessions/email' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $projectId ,
]), [
'email' => $userEmail ,
'password' => 'password' ,
]);
$this -> assertEquals ( 201 , $response [ 'headers' ][ 'status-code' ]);
$sessionCookie = $response [ 'headers' ][ 'set-cookie' ];
// Test for SUCCESS
$response = $this -> client -> call ( Client :: METHOD_GET , '/account' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $projectId ,
'Cookie' => $sessionCookie ,
]));
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
2022-11-15 23:31:32 +13:00
// Check session doesn't expire too soon.
sleep ( 30 );
// Get User
$response = $this -> client -> call ( Client :: METHOD_GET , '/account' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $projectId ,
'Cookie' => $sessionCookie ,
]));
2022-11-15 23:38:02 +13:00
2022-11-15 23:31:32 +13:00
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
2022-11-02 00:15:45 +13:00
// Wait just over a minute
2022-11-15 23:31:32 +13:00
sleep ( 35 );
2022-11-02 00:15:45 +13:00
// Get User
$response = $this -> client -> call ( Client :: METHOD_GET , '/account' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $projectId ,
'Cookie' => $sessionCookie ,
]));
$this -> assertEquals ( 401 , $response [ 'headers' ][ 'status-code' ]);
2024-01-16 09:04:36 +13:00
// Set session duration to 15s
$response = $this -> client -> call ( Client :: METHOD_PATCH , '/projects/' . $id . '/auth/duration' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
'duration' => 15 , // seconds
]);
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertEquals ( 15 , $response [ 'body' ][ 'authDuration' ]);
// Create session
$response = $this -> client -> call ( Client :: METHOD_POST , '/account/sessions/email' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $projectId ,
]), [
'email' => $userEmail ,
'password' => 'password' ,
]);
$this -> assertEquals ( 201 , $response [ 'headers' ][ 'status-code' ]);
$sessionCookie = $response [ 'headers' ][ 'set-cookie' ];
// Wait 10 seconds, ensure valid session, extend session
\sleep ( 10 );
$response = $this -> client -> call ( Client :: METHOD_GET , '/account' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $projectId ,
'Cookie' => $sessionCookie ,
]));
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
$response = $this -> client -> call ( Client :: METHOD_PATCH , '/account/sessions/current' , array_merge ([
'origin' => 'http://localhost' ,
'content-type' => 'application/json' ,
'x-appwrite-project' => $projectId ,
'cookie' => $sessionCookie ,
]));
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
// Wait 20 seconds, ensure non-valid session
\sleep ( 20 );
$response = $this -> client -> call ( Client :: METHOD_GET , '/account' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $projectId ,
'Cookie' => $sessionCookie ,
]));
$this -> assertEquals ( 401 , $response [ 'headers' ][ 'status-code' ]);
2022-11-02 00:15:45 +13:00
// Return project back to normal
2022-11-15 02:00:50 +13:00
$response = $this -> client -> call ( Client :: METHOD_PATCH , '/projects/' . $id . '/auth/duration' , array_merge ([
2022-11-02 00:15:45 +13:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
2022-11-15 23:31:32 +13:00
'duration' => Auth :: TOKEN_EXPIRATION_LOGIN_LONG ,
2022-11-02 00:15:45 +13:00
]);
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
$projectId = $response [ 'body' ][ '$id' ];
2022-11-02 00:34:56 +13:00
// Check project is back to normal
$response = $this -> client -> call ( Client :: METHOD_GET , '/projects/' . $projectId , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => 'console' ,
], $this -> getHeaders ()));
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
2022-11-15 23:31:32 +13:00
$this -> assertEquals ( Auth :: TOKEN_EXPIRATION_LOGIN_LONG , $response [ 'body' ][ 'authDuration' ]); // 1 Year
2022-11-02 00:34:56 +13:00
2022-11-02 00:15:45 +13:00
return [ 'projectId' => $projectId ];
}
2020-07-09 21:13:14 +12:00
/**
2024-01-10 00:58:36 +13:00
* @ depends testCreateProject
2020-07-09 21:13:14 +12:00
*/
2022-04-19 04:21:45 +12:00
public function testUpdateProjectOAuth ( $data ) : array
2020-07-09 21:13:14 +12:00
{
2020-10-15 10:11:12 +13:00
$id = $data [ 'projectId' ] ? ? '' ;
2024-05-06 18:29:15 +12:00
$providers = require ( __DIR__ . '/../../../../app/config/oAuthProviders.php' );
2020-07-09 21:13:14 +12:00
/**
* Test for SUCCESS
*/
2020-10-28 08:48:38 +13:00
foreach ( $providers as $key => $provider ) {
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_PATCH , '/projects/' . $id . '/oauth2' , array_merge ([
2020-07-09 21:13:14 +12:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
'provider' => $key ,
2022-04-19 04:21:45 +12:00
'appId' => 'AppId-' . ucfirst ( $key ),
'secret' => 'Secret-' . ucfirst ( $key ),
2020-07-09 21:13:14 +12:00
]);
2022-04-19 04:21:45 +12:00
2020-07-09 21:13:14 +12:00
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertNotEmpty ( $response [ 'body' ][ '$id' ]);
}
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_GET , '/projects/' . $id , array_merge ([
2020-07-09 21:13:14 +12:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()));
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertNotEmpty ( $response [ 'body' ]);
$this -> assertEquals ( $id , $response [ 'body' ][ '$id' ]);
2020-10-28 08:48:38 +13:00
foreach ( $providers as $key => $provider ) {
2022-08-19 21:43:03 +12:00
$asserted = false ;
2023-10-26 06:33:23 +13:00
foreach ( $response [ 'body' ][ 'oAuthProviders' ] as $responseProvider ) {
2023-07-21 10:54:38 +12:00
if ( $responseProvider [ 'key' ] === $key ) {
2022-08-19 21:43:03 +12:00
$this -> assertEquals ( 'AppId-' . ucfirst ( $key ), $responseProvider [ 'appId' ]);
$this -> assertEquals ( 'Secret-' . ucfirst ( $key ), $responseProvider [ 'secret' ]);
$this -> assertFalse ( $responseProvider [ 'enabled' ]);
$asserted = true ;
break ;
}
}
$this -> assertTrue ( $asserted );
}
// Enable providers
$i = 0 ;
foreach ( $providers as $key => $provider ) {
$response = $this -> client -> call ( Client :: METHOD_PATCH , '/projects/' . $id . '/oauth2' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
'provider' => $key ,
'enabled' => $i === 0 ? false : true // On first provider, test enabled=false
]);
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertNotEmpty ( $response [ 'body' ][ '$id' ]);
$i ++ ;
}
$response = $this -> client -> call ( Client :: METHOD_GET , '/projects/' . $id , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()));
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertNotEmpty ( $response [ 'body' ]);
$this -> assertEquals ( $id , $response [ 'body' ][ '$id' ]);
$i = 0 ;
foreach ( $providers as $key => $provider ) {
$asserted = false ;
2023-10-26 06:33:23 +13:00
foreach ( $response [ 'body' ][ 'oAuthProviders' ] as $responseProvider ) {
2023-07-21 10:54:38 +12:00
if ( $responseProvider [ 'key' ] === $key ) {
2022-08-19 21:43:03 +12:00
// On first provider, test enabled=false
$this -> assertEquals ( $i !== 0 , $responseProvider [ 'enabled' ]);
$asserted = true ;
break ;
}
}
$this -> assertTrue ( $asserted );
$i ++ ;
2020-07-09 21:13:14 +12:00
}
/**
* Test for FAILURE
*/
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_PATCH , '/projects/' . $id . '/oauth2' , array_merge ([
2020-07-09 21:13:14 +12:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
'provider' => 'unknown' ,
2022-08-27 15:16:37 +12:00
'appId' => 'AppId' ,
2020-07-09 21:13:14 +12:00
'secret' => 'Secret' ,
]);
$this -> assertEquals ( 400 , $response [ 'headers' ][ 'status-code' ]);
return $data ;
}
2021-03-01 10:22:03 +13:00
/**
2024-01-10 00:58:36 +13:00
* @ depends testCreateProject
2021-03-01 10:22:03 +13:00
*/
2022-04-19 04:21:45 +12:00
public function testUpdateProjectAuthStatus ( $data ) : array
2021-03-01 10:22:03 +13:00
{
$id = $data [ 'projectId' ] ? ? '' ;
2024-03-05 01:58:28 +13:00
$auth = require ( __DIR__ . '/../../../../app/config/auth.php' );
2022-04-19 04:21:45 +12:00
$originalEmail = uniqid () . 'user@localhost.test' ;
2021-03-01 10:22:03 +13:00
$originalPassword = 'password' ;
$originalName = 'User Name' ;
2022-04-19 04:21:45 +12:00
2021-03-01 10:22:03 +13:00
$response = $this -> client -> call ( Client :: METHOD_POST , '/account' , array_merge ([
'origin' => 'http://localhost' ,
'content-type' => 'application/json' ,
'x-appwrite-project' => $id ,
]), [
2022-08-14 22:33:36 +12:00
'userId' => ID :: unique (),
2021-03-01 10:22:03 +13:00
'email' => $originalEmail ,
'password' => $originalPassword ,
'name' => $originalName ,
]);
2022-06-14 20:17:50 +12:00
$response = $this -> client -> call ( Client :: METHOD_POST , '/account/sessions/email' , array_merge ([
2021-03-01 10:22:03 +13:00
'origin' => 'http://localhost' ,
'content-type' => 'application/json' ,
'x-appwrite-project' => $id ,
]), [
'email' => $originalEmail ,
'password' => $originalPassword ,
]);
2023-12-09 12:17:13 +13:00
$session = $response [ 'cookies' ][ 'a_session_' . $id ];
2021-03-01 10:22:03 +13:00
/**
* Test for SUCCESS
*/
foreach ( $auth as $index => $method ) {
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_PATCH , '/projects/' . $id . '/auth/' . $index , array_merge ([
2021-03-01 10:22:03 +13:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
'status' => false ,
]);
2022-04-19 04:21:45 +12:00
2021-03-01 10:22:03 +13:00
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertNotEmpty ( $response [ 'body' ][ '$id' ]);
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_GET , '/projects/' . $id , array_merge ([
2021-03-01 10:22:03 +13:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()));
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertNotEmpty ( $response [ 'body' ][ '$id' ]);
2022-04-19 04:21:45 +12:00
$this -> assertEquals ( false , $response [ 'body' ][ 'auth' . ucfirst ( $method [ 'key' ])]);
2021-03-01 10:22:03 +13:00
}
2022-04-19 04:21:45 +12:00
$email = uniqid () . 'user@localhost.test' ;
2021-03-01 10:22:03 +13:00
$password = 'password' ;
$name = 'User Name' ;
/**
* Test for FAILURE
*/
$response = $this -> client -> call ( Client :: METHOD_POST , '/account' , array_merge ([
'origin' => 'http://localhost' ,
'content-type' => 'application/json' ,
'x-appwrite-project' => $id ,
]), [
2022-08-14 22:33:36 +12:00
'userId' => ID :: unique (),
2021-03-01 10:22:03 +13:00
'email' => $email ,
'password' => $password ,
'name' => $name ,
]);
$this -> assertEquals ( $response [ 'headers' ][ 'status-code' ], 501 );
$response = $this -> client -> call ( Client :: METHOD_POST , '/teams' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $id ,
2022-04-19 04:21:45 +12:00
'cookie' => 'a_session_' . $id . '=' . $session ,
2021-03-01 10:22:03 +13:00
]), [
2022-08-14 22:33:36 +12:00
'teamId' => ID :: unique (),
2021-03-01 10:22:03 +13:00
'name' => 'Arsenal'
]);
$this -> assertEquals ( 201 , $response [ 'headers' ][ 'status-code' ]);
$teamUid = $response [ 'body' ][ '$id' ];
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_POST , '/teams/' . $teamUid . '/memberships' , array_merge ([
2021-03-01 10:22:03 +13:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $id ,
2022-04-19 04:21:45 +12:00
'cookie' => 'a_session_' . $id . '=' . $session ,
2021-03-01 10:22:03 +13:00
]), [
'email' => $email ,
'name' => 'Friend User' ,
'roles' => [ 'admin' , 'editor' ],
'url' => 'http://localhost:5000/join-us#title'
]);
$this -> assertEquals ( $response [ 'headers' ][ 'status-code' ], 501 );
$response = $this -> client -> call ( Client :: METHOD_POST , '/account/jwt' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $id ,
2022-04-19 04:21:45 +12:00
'cookie' => 'a_session_' . $id . '=' . $session ,
2021-03-01 10:22:03 +13:00
]));
$this -> assertEquals ( $response [ 'headers' ][ 'status-code' ], 501 );
2022-06-14 20:17:50 +12:00
$response = $this -> client -> call ( Client :: METHOD_POST , '/account/sessions/email' , array_merge ([
2021-03-01 10:22:03 +13:00
'origin' => 'http://localhost' ,
'content-type' => 'application/json' ,
'x-appwrite-project' => $id ,
]), [
'email' => $originalEmail ,
'password' => $originalPassword ,
]);
2022-04-19 04:21:45 +12:00
2021-03-01 10:22:03 +13:00
$this -> assertEquals ( $response [ 'headers' ][ 'status-code' ], 501 );
2023-05-30 18:26:17 +12:00
$response = $this -> client -> call ( Client :: METHOD_POST , '/account/sessions/anonymous' , array_merge ([
2021-04-03 21:56:32 +13:00
'origin' => 'http://localhost' ,
'content-type' => 'application/json' ,
'x-appwrite-project' => $id ,
2023-05-30 18:26:17 +12:00
]));
2021-04-03 21:56:32 +13:00
$this -> assertEquals ( $response [ 'headers' ][ 'status-code' ], 501 );
2021-03-01 10:22:03 +13:00
// Cleanup
foreach ( $auth as $index => $method ) {
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_PATCH , '/projects/' . $id . '/auth/' . $index , array_merge ([
2021-03-01 10:22:03 +13:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
'status' => true ,
]);
}
return $data ;
}
/**
2024-01-10 00:58:36 +13:00
* @ depends testCreateProject
2021-03-01 10:22:03 +13:00
*/
2022-04-19 04:21:45 +12:00
public function testUpdateProjectAuthLimit ( $data ) : array
2021-03-01 10:22:03 +13:00
{
$id = $data [ 'projectId' ] ? ? '' ;
2022-04-19 04:21:45 +12:00
2021-03-01 10:22:03 +13:00
/**
* Test for SUCCESS
*/
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_PATCH , '/projects/' . $id . '/auth/limit' , array_merge ([
2021-03-01 10:22:03 +13:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
'limit' => 1 ,
]);
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertNotEmpty ( $response [ 'body' ][ '$id' ]);
2022-04-19 04:21:45 +12:00
$email = uniqid () . 'user@localhost.test' ;
2021-03-01 10:22:03 +13:00
$password = 'password' ;
$name = 'User Name' ;
/**
* Test for SUCCESS
*/
$response = $this -> client -> call ( Client :: METHOD_POST , '/account' , array_merge ([
'origin' => 'http://localhost' ,
'content-type' => 'application/json' ,
'x-appwrite-project' => $id ,
]), [
2022-08-14 22:33:36 +12:00
'userId' => ID :: unique (),
2021-03-01 10:22:03 +13:00
'email' => $email ,
'password' => $password ,
'name' => $name ,
]);
2024-05-20 23:46:37 +12:00
// Creating A Team
$team = $this -> client -> call ( Client :: METHOD_POST , '/teams' , array_merge ([
'origin' => 'http://localhost' ,
'content-type' => 'application/json' ,
'x-appwrite-project' => $id ,
'x-appwrite-mode' => 'admin' ,
], $this -> getHeaders ()), [
'teamId' => ID :: unique (),
'name' => 'Test Team 1' ,
]);
$this -> assertEquals ( 201 , $team [ 'headers' ][ 'status-code' ]);
$teamId = $team [ 'body' ][ '$id' ];
$email = uniqid () . 'user@localhost.test' ;
// Creating A User Using Team membership
$response = $this -> client -> call ( Client :: METHOD_POST , '/teams/' . $teamId . '/memberships' , array_merge ( $this -> getHeaders (), [
'origin' => 'http://localhost' ,
'content-type' => 'application/json' ,
'x-appwrite-project' => $id ,
'x-appwrite-mode' => 'admin' ,
]), [
'email' => $email ,
'roles' => [],
'url' => 'http://localhost' ,
]);
$this -> assertEquals ( 201 , $response [ 'headers' ][ 'status-code' ]);
2023-05-30 18:26:17 +12:00
$email = uniqid () . 'user@localhost.test' ;
$response = $this -> client -> call ( Client :: METHOD_POST , '/account' , array_merge ([
'origin' => 'http://localhost' ,
'content-type' => 'application/json' ,
'x-appwrite-project' => $id ,
]), [
'userId' => ID :: unique (),
'email' => $email ,
'password' => $password ,
'name' => $name ,
]);
2024-05-23 15:37:13 +12:00
$this -> assertEquals ( Exception :: USER_COUNT_EXCEEDED , $response [ 'body' ][ 'type' ]);
2024-05-22 13:42:34 +12:00
$this -> assertEquals ( 400 , $response [ 'headers' ][ 'status-code' ]);
2021-03-01 10:22:03 +13:00
/**
* Test for FAILURE
*/
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_PATCH , '/projects/' . $id . '/auth/limit' , array_merge ([
2021-03-01 10:22:03 +13:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
'limit' => 0 ,
]);
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertNotEmpty ( $response [ 'body' ][ '$id' ]);
2022-04-19 04:21:45 +12:00
2023-05-30 18:26:17 +12:00
$email = uniqid () . 'user@localhost.test' ;
2021-03-01 10:22:03 +13:00
$response = $this -> client -> call ( Client :: METHOD_POST , '/account' , array_merge ([
'origin' => 'http://localhost' ,
'content-type' => 'application/json' ,
'x-appwrite-project' => $id ,
]), [
2022-08-14 22:33:36 +12:00
'userId' => ID :: unique (),
2021-03-01 10:22:03 +13:00
'email' => $email ,
'password' => $password ,
'name' => $name ,
]);
$this -> assertEquals ( $response [ 'headers' ][ 'status-code' ], 201 );
return $data ;
}
2022-12-10 00:54:23 +13:00
/**
* @ depends testUpdateProjectAuthLimit
*/
2022-12-27 23:33:38 +13:00
public function testUpdateProjectAuthSessionsLimit ( $data ) : array
2022-12-10 00:54:23 +13:00
{
$id = $data [ 'projectId' ] ? ? '' ;
/**
* Test for failure
*/
$response = $this -> client -> call ( Client :: METHOD_PATCH , '/projects/' . $id . '/auth/max-sessions' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
'limit' => 0 ,
]);
$this -> assertEquals ( 400 , $response [ 'headers' ][ 'status-code' ]);
/**
* Test for SUCCESS
*/
$response = $this -> client -> call ( Client :: METHOD_PATCH , '/projects/' . $id . '/auth/max-sessions' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
'limit' => 1 ,
]);
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertNotEmpty ( $response [ 'body' ][ '$id' ]);
2022-12-27 23:40:24 +13:00
$this -> assertEquals ( 1 , $response [ 'body' ][ 'authSessionsLimit' ]);
2022-12-10 00:54:23 +13:00
$email = uniqid () . 'user@localhost.test' ;
$password = 'password' ;
$name = 'User Name' ;
/**
* Create new user
*/
$response = $this -> client -> call ( Client :: METHOD_POST , '/account' , array_merge ([
'origin' => 'http://localhost' ,
'content-type' => 'application/json' ,
'x-appwrite-project' => $id ,
]), [
'userId' => ID :: unique (),
'email' => $email ,
'password' => $password ,
'name' => $name ,
]);
2022-12-11 20:15:47 +13:00
$this -> assertEquals ( 201 , $response [ 'headers' ][ 'status-code' ]);
2022-12-10 00:54:23 +13:00
/**
* create new session
*/
$response = $this -> client -> call ( Client :: METHOD_POST , '/account/sessions/email' , array_merge ([
'origin' => 'http://localhost' ,
'content-type' => 'application/json' ,
'x-appwrite-project' => $id ,
]), [
'email' => $email ,
'password' => $password ,
]);
2022-12-11 20:15:47 +13:00
$this -> assertEquals ( 201 , $response [ 'headers' ][ 'status-code' ]);
2022-12-10 00:54:23 +13:00
$sessionId1 = $response [ 'body' ][ '$id' ];
/**
* create new session
*/
$response = $this -> client -> call ( Client :: METHOD_POST , '/account/sessions/email' , array_merge ([
'origin' => 'http://localhost' ,
'content-type' => 'application/json' ,
'x-appwrite-project' => $id ,
]), [
'email' => $email ,
'password' => $password ,
]);
2022-12-11 20:15:47 +13:00
$this -> assertEquals ( 201 , $response [ 'headers' ][ 'status-code' ]);
2022-12-10 00:54:23 +13:00
$sessionCookie = $response [ 'headers' ][ 'set-cookie' ];
$sessionId2 = $response [ 'body' ][ '$id' ];
2022-12-11 21:26:31 +13:00
// request was called in parallel and test failed
sleep ( 5 );
2022-12-10 00:54:23 +13:00
/**
* List sessions
*/
$response = $this -> client -> call ( Client :: METHOD_GET , '/account/sessions' , [
'origin' => 'http://localhost' ,
'content-type' => 'application/json' ,
'x-appwrite-project' => $id ,
'Cookie' => $sessionCookie ,
]);
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
$sessions = $response [ 'body' ][ 'sessions' ];
$this -> assertEquals ( 1 , count ( $sessions ));
$this -> assertEquals ( $sessionId2 , $sessions [ 0 ][ '$id' ]);
2022-12-12 18:02:48 +13:00
/**
* Reset Limit
*/
$response = $this -> client -> call ( Client :: METHOD_PATCH , '/projects/' . $id . '/auth/max-sessions' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
'limit' => 10 ,
]);
2022-12-10 00:54:23 +13:00
return $data ;
}
2022-12-18 19:27:41 +13:00
/**
* @ depends testUpdateProjectAuthLimit
*/
public function testUpdateProjectAuthPasswordHistory ( $data ) : array
{
$id = $data [ 'projectId' ] ? ? '' ;
2022-12-21 19:42:27 +13:00
/**
* Test for Failure
*/
$response = $this -> client -> call ( Client :: METHOD_PATCH , '/projects/' . $id . '/auth/password-history' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
'limit' => 25 ,
]);
$this -> assertEquals ( 400 , $response [ 'headers' ][ 'status-code' ]);
2022-12-18 19:27:41 +13:00
/**
* Test for Success
*/
$response = $this -> client -> call ( Client :: METHOD_PATCH , '/projects/' . $id . '/auth/password-history' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
'limit' => 1 ,
]);
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertEquals ( 1 , $response [ 'body' ][ 'authPasswordHistory' ]);
$email = uniqid () . 'user@localhost.test' ;
$password = 'password' ;
$name = 'User Name' ;
/**
* Create new user
*/
$response = $this -> client -> call ( Client :: METHOD_POST , '/account' , array_merge ([
'origin' => 'http://localhost' ,
'content-type' => 'application/json' ,
'x-appwrite-project' => $id ,
]), [
'userId' => ID :: unique (),
'email' => $email ,
'password' => $password ,
'name' => $name ,
]);
$this -> assertEquals ( 201 , $response [ 'headers' ][ 'status-code' ]);
2022-12-19 18:07:41 +13:00
$userId = $response [ 'body' ][ '$id' ];
2022-12-18 19:27:41 +13:00
// create session
$session = $this -> client -> call ( Client :: METHOD_POST , '/account/sessions/email' , [
'origin' => 'http://localhost' ,
'content-type' => 'application/json' ,
'x-appwrite-project' => $id ,
], [
'email' => $email ,
'password' => $password ,
]);
$this -> assertEquals ( 201 , $session [ 'headers' ][ 'status-code' ]);
2023-12-09 12:36:01 +13:00
$session = $session [ 'cookies' ][ 'a_session_' . $id ];
2022-12-18 19:27:41 +13:00
$response = $this -> client -> call ( Client :: METHOD_PATCH , '/account/password' , array_merge ([
'origin' => 'http://localhost' ,
'content-type' => 'application/json' ,
'x-appwrite-project' => $id ,
'cookie' => 'a_session_' . $id . '=' . $session ,
]), [
'oldPassword' => $password ,
'password' => $password ,
]);
2023-04-14 08:20:03 +12:00
$this -> assertEquals ( 400 , $response [ 'headers' ][ 'status-code' ]);
2022-12-19 18:07:41 +13:00
2022-12-19 21:28:02 +13:00
$headers = array_merge ( $this -> getHeaders (), [
'x-appwrite-mode' => 'admin' ,
2022-12-19 18:07:41 +13:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $id ,
2022-12-19 21:28:02 +13:00
]);
$response = $this -> client -> call ( Client :: METHOD_PATCH , '/users/' . $userId . '/password' , $headers , [
2022-12-19 18:07:41 +13:00
'password' => $password ,
]);
2022-12-18 19:27:41 +13:00
2023-04-14 08:20:03 +12:00
$this -> assertEquals ( 400 , $response [ 'headers' ][ 'status-code' ]);
2022-12-18 19:27:41 +13:00
2022-12-18 19:31:14 +13:00
2024-03-07 06:34:21 +13:00
/**
2024-06-21 02:49:56 +12:00
* Reset
*/
2022-12-18 19:27:41 +13:00
$response = $this -> client -> call ( Client :: METHOD_PATCH , '/projects/' . $id . '/auth/password-history' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
'limit' => 0 ,
]);
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertEquals ( 0 , $response [ 'body' ][ 'authPasswordHistory' ]);
return $data ;
}
2024-02-14 19:40:19 +13:00
/**
2024-06-21 03:01:20 +12:00
* @ group smtpAndTemplates
2024-06-21 03:14:02 +12:00
* @ group projectsCRUD
*
* @ depends testCreateProject
2024-06-21 03:01:20 +12:00
* */
2024-02-14 19:40:19 +13:00
public function testUpdateMockNumbers ( $data )
{
$id = $data [ 'projectId' ] ? ? '' ;
/**
* Test for Failure
*/
/** Trying to pass an empty body to the endpoint */
$response = $this -> client -> call ( Client :: METHOD_PATCH , '/projects/' . $id . '/auth/mock-numbers' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
2024-06-21 02:49:56 +12:00
], $this -> getHeaders ()), []);
2024-02-14 19:40:19 +13:00
$this -> assertEquals ( 400 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertEquals ( 'Param "numbers" is not optional.' , $response [ 'body' ][ 'message' ]);
/** Trying to pass body with incorrect structure */
$response = $this -> client -> call ( Client :: METHOD_PATCH , '/projects/' . $id . '/auth/mock-numbers' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
'numbers' => [
2024-02-15 06:22:43 +13:00
'phone' => '+1655513432' ,
2024-02-14 19:40:19 +13:00
'otp' => '123456'
]
]);
$this -> assertEquals ( 400 , $response [ 'headers' ][ 'status-code' ]);
2024-06-21 02:49:56 +12:00
$this -> assertEquals ( 'Invalid `numbers` param: Value must a valid array no longer than 10 items and Invalid payload structure. Please check the "phone" and "otp" fields' , $response [ 'body' ][ 'message' ]);
2024-02-14 19:40:19 +13:00
/** Trying to pass an OTP longer than 6 characters*/
$response = $this -> client -> call ( Client :: METHOD_PATCH , '/projects/' . $id . '/auth/mock-numbers' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
'numbers' => [
[
2024-02-15 06:22:43 +13:00
'phone' => '+1655513432' ,
2024-02-14 19:40:19 +13:00
'otp' => '12345678'
]
]
]);
$this -> assertEquals ( 400 , $response [ 'headers' ][ 'status-code' ]);
2024-06-21 02:49:56 +12:00
$this -> assertEquals ( 'Invalid `numbers` param: Value must a valid array no longer than 10 items and OTP must be a valid string and exactly 6 characters.' , $response [ 'body' ][ 'message' ]);
2024-02-14 19:40:19 +13:00
/** Trying to pass an OTP shorter than 6 characters*/
$response = $this -> client -> call ( Client :: METHOD_PATCH , '/projects/' . $id . '/auth/mock-numbers' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
'numbers' => [
[
2024-02-15 06:22:43 +13:00
'phone' => '+1655513432' ,
2024-02-14 19:40:19 +13:00
'otp' => '123'
]
]
]);
$this -> assertEquals ( 400 , $response [ 'headers' ][ 'status-code' ]);
2024-06-21 02:49:56 +12:00
$this -> assertEquals ( 'Invalid `numbers` param: Value must a valid array no longer than 10 items and OTP must be a valid string and exactly 6 characters.' , $response [ 'body' ][ 'message' ]);
2024-02-14 19:40:19 +13:00
/** Trying to pass an invalid phone number */
$response = $this -> client -> call ( Client :: METHOD_PATCH , '/projects/' . $id . '/auth/mock-numbers' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
'numbers' => [
[
2024-02-15 06:22:43 +13:00
'phone' => '1655234' ,
2024-02-14 19:40:19 +13:00
'otp' => '123456'
]
]
]);
$this -> assertEquals ( 400 , $response [ 'headers' ][ 'status-code' ]);
2024-06-21 02:49:56 +12:00
$this -> assertEquals ( 'Invalid `numbers` param: Value must a valid array no longer than 10 items and Phone number must start with a \'+\' can have a maximum of fifteen digits.' , $response [ 'body' ][ 'message' ]);
2024-02-14 19:40:19 +13:00
/** Trying to pass a number longer than 15 digits */
$response = $this -> client -> call ( Client :: METHOD_PATCH , '/projects/' . $id . '/auth/mock-numbers' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
'numbers' => [
[
2024-02-15 06:22:43 +13:00
'phone' => '+1234567890987654' ,
2024-02-14 19:40:19 +13:00
'otp' => '123456'
]
]
]);
$this -> assertEquals ( 400 , $response [ 'headers' ][ 'status-code' ]);
2024-06-21 02:49:56 +12:00
$this -> assertEquals ( 'Invalid `numbers` param: Value must a valid array no longer than 10 items and Phone number must start with a \'+\' can have a maximum of fifteen digits.' , $response [ 'body' ][ 'message' ]);
2024-02-14 19:40:19 +13:00
$numbers = [];
for ( $i = 0 ; $i < 11 ; $i ++ ) {
$numbers [] = [
2024-02-15 06:22:43 +13:00
'phone' => '+1655513432' ,
2024-02-14 19:40:19 +13:00
'otp' => '123456'
];
}
2024-02-15 06:22:43 +13:00
2024-02-14 19:40:19 +13:00
/** Trying to pass more than 10 values */
$response = $this -> client -> call ( Client :: METHOD_PATCH , '/projects/' . $id . '/auth/mock-numbers' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
'numbers' => $numbers
]);
$this -> assertEquals ( 400 , $response [ 'headers' ][ 'status-code' ]);
2024-06-21 02:49:56 +12:00
$this -> assertEquals ( 'Invalid `numbers` param: Value must a valid array no longer than 10 items and Phone number must start with a \'+\' can have a maximum of fifteen digits.' , $response [ 'body' ][ 'message' ]);
2024-02-14 19:40:19 +13:00
/**
* Test for success
*/
$response = $this -> client -> call ( Client :: METHOD_PATCH , '/projects/' . $id . '/auth/mock-numbers' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
'numbers' => []
]);
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
$response = $this -> client -> call ( Client :: METHOD_PATCH , '/projects/' . $id . '/auth/mock-numbers' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
'numbers' => [
[
2024-02-15 06:22:43 +13:00
'phone' => '+1655513432' ,
2024-02-14 19:40:19 +13:00
'otp' => '123456'
]
]
]);
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
// Create phone session for this project and check if the mock number is used
$response = $this -> client -> call ( Client :: METHOD_POST , '/account/sessions/phone' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $id ,
]), [
2024-06-21 02:31:33 +12:00
'userId' => 'unique()' ,
'phone' => '+1655513432' ,
2024-02-14 19:40:19 +13:00
]);
$this -> assertEquals ( 201 , $response [ 'headers' ][ 'status-code' ]);
$userId = $response [ 'body' ][ 'userId' ];
$response = $this -> client -> call ( Client :: METHOD_PUT , '/account/sessions/phone' , array_merge ([
'content-type' => 'application/json' ,
2024-06-21 03:01:20 +12:00
'x-appwrite-project' => $id ,
]), [
'userId' => $userId ,
'secret' => '654321' , // Try a random code
]);
$this -> assertEquals ( 401 , $response [ 'headers' ][ 'status-code' ]);
$response = $this -> client -> call ( Client :: METHOD_PUT , '/account/sessions/phone' , array_merge ([
'content-type' => 'application/json' ,
2024-02-14 19:40:19 +13:00
'x-appwrite-project' => $id ,
]), [
2024-06-21 02:31:33 +12:00
'userId' => $userId ,
'secret' => '123456' ,
2024-02-14 19:40:19 +13:00
]);
$this -> assertEquals ( 201 , $response [ 'headers' ][ 'status-code' ]);
}
2022-12-26 18:46:35 +13:00
/**
* @ depends testUpdateProjectAuthLimit
*/
public function testUpdateProjectAuthPasswordDictionary ( $data ) : array
{
$id = $data [ 'projectId' ] ? ? '' ;
$password = 'password' ;
$name = 'User Name' ;
/**
* Test for Success
*/
/**
* create account
*/
$response = $this -> client -> call ( Client :: METHOD_POST , '/account' , array_merge ([
'origin' => 'http://localhost' ,
'content-type' => 'application/json' ,
'x-appwrite-project' => $id ,
]), [
'userId' => ID :: unique (),
'email' => uniqid () . 'user@localhost.test' ,
'password' => $password ,
'name' => $name ,
]);
$this -> assertEquals ( 201 , $response [ 'headers' ][ 'status-code' ]);
$userId = $response [ 'body' ][ '$id' ];
/**
* Create user
*/
$user = $this -> client -> call ( Client :: METHOD_POST , '/users' , array_merge ( $this -> getHeaders (), [
'content-type' => 'application/json' ,
'x-appwrite-project' => $id ,
'x-appwrite-mode' => 'admin' ,
]), [
'userId' => ID :: unique (),
'email' => uniqid () . 'user@localhost.test' ,
'password' => 'password' ,
'name' => 'Cristiano Ronaldo' ,
]);
$this -> assertEquals ( 201 , $response [ 'headers' ][ 'status-code' ]);
/**
* Enable Disctionary
*/
$response = $this -> client -> call ( Client :: METHOD_PATCH , '/projects/' . $id . '/auth/password-dictionary' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
'enabled' => true ,
]);
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertEquals ( true , $response [ 'body' ][ 'authPasswordDictionary' ]);
/**
* Test for failure
*/
$response = $this -> client -> call ( Client :: METHOD_POST , '/account' , array_merge ([
'origin' => 'http://localhost' ,
'content-type' => 'application/json' ,
'x-appwrite-project' => $id ,
]), [
'userId' => ID :: unique (),
'email' => uniqid () . 'user@localhost.test' ,
'password' => $password ,
'name' => $name ,
]);
2022-12-26 23:22:25 +13:00
$this -> assertEquals ( 400 , $response [ 'headers' ][ 'status-code' ]);
2022-12-26 18:47:20 +13:00
2022-12-26 18:46:35 +13:00
/**
* Create user
*/
$user = $this -> client -> call ( Client :: METHOD_POST , '/users' , array_merge ( $this -> getHeaders (), [
'content-type' => 'application/json' ,
'x-appwrite-project' => $id ,
'x-appwrite-mode' => 'admin' ,
]), [
'userId' => ID :: unique (),
'email' => uniqid () . 'user@localhost.test' ,
'password' => 'password' ,
'name' => 'Cristiano Ronaldo' ,
]);
2022-12-26 23:22:25 +13:00
$this -> assertEquals ( 400 , $response [ 'headers' ][ 'status-code' ]);
2022-12-26 18:46:35 +13:00
$headers = array_merge ( $this -> getHeaders (), [
'x-appwrite-mode' => 'admin' ,
'content-type' => 'application/json' ,
'x-appwrite-project' => $id ,
]);
$response = $this -> client -> call ( Client :: METHOD_PATCH , '/users/' . $userId . '/password' , $headers , [
'password' => $password ,
]);
2022-12-26 23:22:25 +13:00
$this -> assertEquals ( 400 , $response [ 'headers' ][ 'status-code' ]);
2022-12-26 18:46:35 +13:00
2024-03-07 06:34:21 +13:00
/**
2024-06-21 02:49:56 +12:00
* Reset
*/
2022-12-26 18:46:35 +13:00
$response = $this -> client -> call ( Client :: METHOD_PATCH , '/projects/' . $id . '/auth/password-history' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
'limit' => 0 ,
]);
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertEquals ( 0 , $response [ 'body' ][ 'authPasswordHistory' ]);
/**
* Reset
*/
$response = $this -> client -> call ( Client :: METHOD_PATCH , '/projects/' . $id . '/auth/password-dictionary' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
2022-12-26 23:22:25 +13:00
'enabled' => false ,
2022-12-26 18:46:35 +13:00
]);
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
2022-12-26 23:22:25 +13:00
$this -> assertEquals ( false , $response [ 'body' ][ 'authPasswordDictionary' ]);
2022-12-26 18:46:35 +13:00
return $data ;
}
2023-04-14 08:20:03 +12:00
/**
* @ depends testCreateProject
*/
public function testUpdateDisallowPersonalData ( $data ) : void
{
$id = $data [ 'projectId' ] ? ? '' ;
/**
* Enable Disallowing of Personal Data
*/
2023-07-21 01:12:41 +12:00
$response = $this -> client -> call ( Client :: METHOD_PATCH , '/projects/' . $id . '/auth/personal-data' , array_merge ([
2023-04-14 08:20:03 +12:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
'enabled' => true ,
]);
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
2023-07-20 10:24:32 +12:00
$this -> assertEquals ( true , $response [ 'body' ][ 'authPersonalDataCheck' ]);
2023-04-14 08:20:03 +12:00
/**
* Test for failure
*/
$email = uniqid () . 'user@localhost.test' ;
$password = 'password' ;
$name = 'username' ;
$userId = ID :: unique ();
$response = $this -> client -> call ( Client :: METHOD_POST , '/account' , array_merge ([
'origin' => 'http://localhost' ,
'content-type' => 'application/json' ,
'x-appwrite-project' => $id ,
]), [
'email' => $email ,
'password' => $email ,
'name' => $name ,
'userId' => $userId
]);
$this -> assertEquals ( 400 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertEquals ( 400 , $response [ 'body' ][ 'code' ]);
$this -> assertEquals ( Exception :: USER_PASSWORD_PERSONAL_DATA , $response [ 'body' ][ 'type' ]);
2023-04-14 08:59:35 +12:00
$response = $this -> client -> call ( Client :: METHOD_POST , '/account' , array_merge ([
'origin' => 'http://localhost' ,
'content-type' => 'application/json' ,
'x-appwrite-project' => $id ,
]), [
'email' => $email ,
'password' => $name ,
'name' => $name ,
'userId' => $userId
]);
2023-04-14 08:20:03 +12:00
$phone = '+123456789' ;
$response = $this -> client -> call ( Client :: METHOD_POST , '/users' , array_merge ( $this -> getHeaders (), [
'content-type' => 'application/json' ,
'x-appwrite-project' => $id ,
'x-appwrite-mode' => 'admin' ,
]), [
'email' => $email ,
'password' => $phone ,
'name' => $name ,
'userId' => $userId ,
'phone' => $phone
]);
$this -> assertEquals ( 400 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertEquals ( 400 , $response [ 'body' ][ 'code' ]);
$this -> assertEquals ( Exception :: USER_PASSWORD_PERSONAL_DATA , $response [ 'body' ][ 'type' ]);
/** Test for success */
$email = uniqid () . 'user@localhost.test' ;
$password = 'password' ;
$name = 'username' ;
$userId = ID :: unique ();
$response = $this -> client -> call ( Client :: METHOD_POST , '/account' , array_merge ([
'origin' => 'http://localhost' ,
'content-type' => 'application/json' ,
'x-appwrite-project' => $id ,
]), [
'email' => $email ,
'password' => $password ,
'name' => $name ,
'userId' => $userId
]);
$this -> assertEquals ( 201 , $response [ 'headers' ][ 'status-code' ]);
2024-02-25 23:25:51 +13:00
$response = $this -> client -> call ( Client :: METHOD_POST , '/users' , array_merge ( $this -> getHeaders (), [
2024-02-25 22:19:30 +13:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $id ,
2024-02-25 23:25:51 +13:00
'x-appwrite-mode' => 'admin' ,
2024-02-25 22:19:30 +13:00
]), [
2024-02-25 23:25:51 +13:00
// Empty password
'email' => uniqid () . 'user@localhost.test' ,
'name' => 'User' ,
'userId' => ID :: unique (),
2024-02-25 22:19:30 +13:00
]);
$this -> assertEquals ( 201 , $response [ 'headers' ][ 'status-code' ]);
2023-04-14 08:20:03 +12:00
$email = uniqid () . 'user@localhost.test' ;
$userId = ID :: unique ();
$response = $this -> client -> call ( Client :: METHOD_POST , '/users' , array_merge ( $this -> getHeaders (), [
'content-type' => 'application/json' ,
'x-appwrite-project' => $id ,
'x-appwrite-mode' => 'admin' ,
]), [
'email' => $email ,
'password' => $password ,
'name' => $name ,
'userId' => $userId ,
'phone' => $phone
]);
$this -> assertEquals ( 201 , $response [ 'headers' ][ 'status-code' ]);
/**
* Reset
*/
2023-07-21 01:12:41 +12:00
$response = $this -> client -> call ( Client :: METHOD_PATCH , '/projects/' . $id . '/auth/personal-data' , array_merge ([
2023-04-14 08:20:03 +12:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
'enabled' => false ,
]);
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
2023-07-20 10:24:32 +12:00
$this -> assertEquals ( false , $response [ 'body' ][ 'authPersonalDataCheck' ]);
2023-04-14 08:20:03 +12:00
}
2023-11-06 12:34:44 +13:00
public function testUpdateProjectServicesAll () : void
{
$team = $this -> client -> call ( Client :: METHOD_POST , '/teams' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
'cookie' => 'a_session_console=' . $this -> getRoot ()[ 'session' ],
]), [
'teamId' => ID :: unique (),
'name' => 'Project Test' ,
]);
$this -> assertEquals ( 201 , $team [ 'headers' ][ 'status-code' ]);
$this -> assertNotEmpty ( $team [ 'body' ][ '$id' ]);
$project = $this -> client -> call ( Client :: METHOD_POST , '/projects' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
'cookie' => 'a_session_console=' . $this -> getRoot ()[ 'session' ],
]), [
'projectId' => ID :: unique (),
'name' => 'Project Test' ,
'teamId' => $team [ 'body' ][ '$id' ],
'region' => 'default'
]);
$this -> assertEquals ( 201 , $project [ 'headers' ][ 'status-code' ]);
$this -> assertNotEmpty ( $project [ 'body' ][ '$id' ]);
$id = $project [ 'body' ][ '$id' ];
$response = $this -> client -> call ( Client :: METHOD_PATCH , '/projects/' . $id . '/service/all' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
'cookie' => 'a_session_console=' . $this -> getRoot ()[ 'session' ],
]), [
'status' => false ,
]);
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertNotEmpty ( $response [ 'body' ][ '$id' ]);
$response = $this -> client -> call ( Client :: METHOD_GET , '/projects/' . $id , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
'cookie' => 'a_session_console=' . $this -> getRoot ()[ 'session' ],
]));
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertNotEmpty ( $response [ 'body' ][ '$id' ]);
$matches = [];
$pattern = '/serviceStatusFor.*/' ;
foreach ( $response [ 'body' ] as $key => $value ) {
if ( \preg_match ( $pattern , $key )) {
$matches [ $key ] = $value ;
}
}
foreach ( $matches as $value ) {
$this -> assertFalse ( $value );
}
$response = $this -> client -> call ( Client :: METHOD_PATCH , '/projects/' . $id . '/service/all' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
'cookie' => 'a_session_console=' . $this -> getRoot ()[ 'session' ],
]), [
'status' => true ,
]);
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertNotEmpty ( $response [ 'body' ][ '$id' ]);
$response = $this -> client -> call ( Client :: METHOD_GET , '/projects/' . $id , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
'cookie' => 'a_session_console=' . $this -> getRoot ()[ 'session' ],
]));
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
$matches = [];
foreach ( $response [ 'body' ] as $key => $value ) {
if ( \preg_match ( $pattern , $key )) {
$matches [ $key ] = $value ;
}
}
foreach ( $matches as $value ) {
$this -> assertTrue ( $value );
}
}
2022-12-18 19:27:41 +13:00
2021-07-29 22:56:25 +12:00
public function testUpdateProjectServiceStatusAdmin () : array
2021-07-29 22:28:17 +12:00
{
2021-07-29 22:56:25 +12:00
$team = $this -> client -> call ( Client :: METHOD_POST , '/teams' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
'cookie' => 'a_session_console=' . $this -> getRoot ()[ 'session' ],
]), [
2022-08-14 22:33:36 +12:00
'teamId' => ID :: unique (),
2021-07-29 22:56:25 +12:00
'name' => 'Project Test' ,
]);
$this -> assertEquals ( 201 , $team [ 'headers' ][ 'status-code' ]);
$this -> assertNotEmpty ( $team [ 'body' ][ '$id' ]);
$project = $this -> client -> call ( Client :: METHOD_POST , '/projects' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
'cookie' => 'a_session_console=' . $this -> getRoot ()[ 'session' ],
]), [
2022-08-14 22:33:36 +12:00
'projectId' => ID :: unique (),
2021-07-29 22:56:25 +12:00
'name' => 'Project Test' ,
'teamId' => $team [ 'body' ][ '$id' ],
2022-10-01 01:22:11 +13:00
'region' => 'default'
2021-07-29 22:56:25 +12:00
]);
$this -> assertEquals ( 201 , $project [ 'headers' ][ 'status-code' ]);
$this -> assertNotEmpty ( $project [ 'body' ][ '$id' ]);
$id = $project [ 'body' ][ '$id' ];
2024-03-05 01:58:28 +13:00
$services = require ( __DIR__ . '/../../../../app/config/services.php' );
2021-07-29 22:28:17 +12:00
/**
* Test for Disabled
*/
foreach ( $services as $service ) {
2022-04-19 04:21:45 +12:00
if ( ! $service [ 'optional' ]) {
2021-08-01 20:00:13 +12:00
continue ;
}
2021-08-01 22:15:06 +12:00
$key = $service [ 'key' ] ? ? '' ;
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_PATCH , '/projects/' . $id . '/service' , array_merge ([
2021-07-29 22:28:17 +12:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
2021-07-29 22:56:25 +12:00
'cookie' => 'a_session_console=' . $this -> getRoot ()[ 'session' ],
]), [
2021-08-01 22:15:06 +12:00
'service' => $key ,
2021-07-29 22:28:17 +12:00
'status' => false ,
]);
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertNotEmpty ( $response [ 'body' ][ '$id' ]);
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_GET , '/projects/' . $id , array_merge ([
2021-07-29 22:28:17 +12:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
2021-07-29 22:56:25 +12:00
'cookie' => 'a_session_console=' . $this -> getRoot ()[ 'session' ],
]));
2021-07-29 22:28:17 +12:00
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertNotEmpty ( $response [ 'body' ][ '$id' ]);
2022-04-19 04:21:45 +12:00
$this -> assertEquals ( false , $response [ 'body' ][ 'serviceStatusFor' . ucfirst ( $key )]);
2021-07-29 22:28:17 +12:00
}
2022-04-19 04:21:45 +12:00
2021-07-29 22:28:17 +12:00
/**
2021-07-29 22:56:25 +12:00
* Admin request must succeed
2021-07-29 22:28:17 +12:00
*/
2022-04-19 04:21:45 +12:00
2021-07-29 22:28:17 +12:00
$response = $this -> client -> call ( Client :: METHOD_GET , '/functions' , array_merge ([
'origin' => 'http://localhost' ,
'content-type' => 'application/json' ,
2021-07-29 22:56:25 +12:00
// 'x-appwrite-project' => $this->getProject()['$id'],
2021-07-29 22:28:17 +12:00
'x-appwrite-project' => $id ,
2021-07-29 22:56:25 +12:00
'cookie' => 'a_session_console=' . $this -> getRoot ()[ 'session' ],
'x-appwrite-mode' => 'admin'
]));
2022-04-19 04:21:45 +12:00
2021-07-29 22:56:25 +12:00
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
2021-07-29 22:28:17 +12:00
foreach ( $services as $service ) {
2022-04-19 04:21:45 +12:00
if ( ! $service [ 'optional' ]) {
2021-08-01 22:15:06 +12:00
continue ;
}
$key = $service [ 'key' ] ? ? '' ;
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_PATCH , '/projects/' . $id . '/service/' , array_merge ([
2021-07-29 22:28:17 +12:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
2021-08-01 22:15:06 +12:00
'service' => $key ,
2021-07-29 22:28:17 +12:00
'status' => true ,
]);
}
2021-07-29 22:56:25 +12:00
return [ 'projectId' => $id ];
2021-07-29 22:28:17 +12:00
}
2021-07-29 22:56:25 +12:00
/** @depends testUpdateProjectServiceStatusAdmin */
2022-04-19 04:21:45 +12:00
public function testUpdateProjectServiceStatus ( $data ) : void
2021-07-29 22:28:17 +12:00
{
2021-07-29 22:56:25 +12:00
$id = $data [ 'projectId' ];
2021-07-29 22:28:17 +12:00
2024-03-05 01:58:28 +13:00
$services = require ( __DIR__ . '/../../../../app/config/services.php' );
2021-07-29 22:28:17 +12:00
/**
* Test for Disabled
*/
foreach ( $services as $service ) {
2022-04-19 04:21:45 +12:00
if ( ! $service [ 'optional' ]) {
2021-08-01 22:15:06 +12:00
continue ;
}
$key = $service [ 'key' ] ? ? '' ;
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_PATCH , '/projects/' . $id . '/service' , array_merge ([
2021-07-29 22:28:17 +12:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
'cookie' => 'a_session_console=' . $this -> getRoot ()[ 'session' ],
]), [
2021-08-01 22:15:06 +12:00
'service' => $key ,
2021-07-29 22:28:17 +12:00
'status' => false ,
]);
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertNotEmpty ( $response [ 'body' ][ '$id' ]);
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_GET , '/projects/' . $id , array_merge ([
2021-07-29 22:28:17 +12:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
'cookie' => 'a_session_console=' . $this -> getRoot ()[ 'session' ],
]));
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertNotEmpty ( $response [ 'body' ][ '$id' ]);
2022-04-19 04:21:45 +12:00
$this -> assertEquals ( false , $response [ 'body' ][ 'serviceStatusFor' . ucfirst ( $key )]);
2021-07-29 22:28:17 +12:00
}
/**
2021-07-29 22:56:25 +12:00
* Test for FAILURE
2021-07-29 22:28:17 +12:00
*/
$response = $this -> client -> call ( Client :: METHOD_GET , '/functions' , array_merge ([
'origin' => 'http://localhost' ,
'content-type' => 'application/json' ,
'x-appwrite-project' => $id ,
2021-07-29 22:56:25 +12:00
], $this -> getHeaders ()));
2021-07-29 22:28:17 +12:00
2024-02-27 01:28:57 +13:00
$this -> assertEquals ( 403 , $response [ 'headers' ][ 'status-code' ]);
2021-07-29 22:56:25 +12:00
$response = $this -> client -> call ( Client :: METHOD_POST , '/teams' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $id ,
]), [
2022-08-14 22:33:36 +12:00
'teamId' => ID :: unique (),
2021-07-29 22:56:25 +12:00
'name' => 'Arsenal'
]);
2024-02-27 01:28:57 +13:00
$this -> assertEquals ( 403 , $response [ 'headers' ][ 'status-code' ]);
2021-07-29 22:56:25 +12:00
// Cleanup
foreach ( $services as $service ) {
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_PATCH , '/projects/' . $id . '/service/' , array_merge ([
2021-07-29 22:56:25 +12:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
'service' => $service ,
'status' => true ,
]);
}
2021-07-29 22:28:17 +12:00
}
2022-05-22 18:57:59 +12:00
/** @depends testUpdateProjectServiceStatusAdmin */
public function testUpdateProjectServiceStatusServer ( $data ) : void
{
$id = $data [ 'projectId' ];
2024-03-05 01:58:28 +13:00
$services = require ( __DIR__ . '/../../../../app/config/services.php' );
2022-05-22 18:57:59 +12:00
/**
* Test for Disabled
*/
foreach ( $services as $service ) {
if ( ! $service [ 'optional' ]) {
continue ;
}
$key = $service [ 'key' ] ? ? '' ;
$response = $this -> client -> call ( Client :: METHOD_PATCH , '/projects/' . $id . '/service' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
'cookie' => 'a_session_console=' . $this -> getRoot ()[ 'session' ],
]), [
'service' => $key ,
'status' => false ,
]);
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertNotEmpty ( $response [ 'body' ][ '$id' ]);
$response = $this -> client -> call ( Client :: METHOD_GET , '/projects/' . $id , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
'cookie' => 'a_session_console=' . $this -> getRoot ()[ 'session' ],
]));
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertNotEmpty ( $response [ 'body' ][ '$id' ]);
$this -> assertEquals ( false , $response [ 'body' ][ 'serviceStatusFor' . ucfirst ( $key )]);
}
// Create API Key
$response = $this -> client -> call ( Client :: METHOD_POST , '/projects/' . $id . '/keys' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
'cookie' => 'a_session_console=' . $this -> getRoot ()[ 'session' ],
]), [
'name' => 'Key Test' ,
'scopes' => [ 'functions.read' , 'teams.write' ],
]);
$this -> assertEquals ( 201 , $response [ 'headers' ][ 'status-code' ]);
$keyId = $response [ 'body' ][ '$id' ];
$keySecret = $response [ 'body' ][ 'secret' ];
/**
* Request with API Key must succeed
*/
$response = $this -> client -> call ( Client :: METHOD_GET , '/functions' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $id ,
'x-appwrite-key' => $keySecret ,
2022-08-31 02:04:42 +12:00
'x-sdk-name' => 'python'
2022-05-22 18:57:59 +12:00
]));
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
$response = $this -> client -> call ( Client :: METHOD_POST , '/teams' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $id ,
'x-appwrite-key' => $keySecret ,
2022-08-31 02:04:42 +12:00
'x-sdk-name' => 'php'
2022-05-22 18:57:59 +12:00
]), [
2022-08-14 22:33:36 +12:00
'teamId' => ID :: unique (),
2022-05-22 18:57:59 +12:00
'name' => 'Arsenal'
]);
$this -> assertEquals ( 201 , $response [ 'headers' ][ 'status-code' ]);
2022-08-31 02:04:42 +12:00
/** Check that the API key has been updated */
$response = $this -> client -> call ( Client :: METHOD_GET , '/projects/' . $id . '/keys/' . $keyId , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
'cookie' => 'a_session_console=' . $this -> getRoot ()[ 'session' ],
]), []);
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertArrayHasKey ( 'sdks' , $response [ 'body' ]);
$this -> assertCount ( 2 , $response [ 'body' ][ 'sdks' ]);
2022-08-31 05:33:54 +12:00
$this -> assertContains ( 'python' , $response [ 'body' ][ 'sdks' ]);
$this -> assertContains ( 'php' , $response [ 'body' ][ 'sdks' ]);
2022-08-31 02:04:42 +12:00
$this -> assertArrayHasKey ( 'accessedAt' , $response [ 'body' ]);
$this -> assertNotEmpty ( $response [ 'body' ][ 'accessedAt' ]);
2022-08-31 06:26:02 +12:00
2022-05-22 18:57:59 +12:00
// Cleanup
$response = $this -> client -> call ( Client :: METHOD_DELETE , '/projects/' . $id . '/keys/' . $keyId , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
'cookie' => 'a_session_console=' . $this -> getRoot ()[ 'session' ],
]), []);
$this -> assertEquals ( 204 , $response [ 'headers' ][ 'status-code' ]);
foreach ( $services as $service ) {
$response = $this -> client -> call ( Client :: METHOD_PATCH , '/projects/' . $id . '/service/' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
'service' => $service ,
'status' => true ,
]);
}
}
2020-07-09 21:13:14 +12:00
/**
* @ depends testCreateProject
*/
public function testCreateProjectWebhook ( $data ) : array
{
2020-10-15 10:11:12 +13:00
$id = $data [ 'projectId' ] ? ? '' ;
2020-07-09 21:13:14 +12:00
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_POST , '/projects/' . $id . '/webhooks' , array_merge ([
2020-07-09 21:13:14 +12:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
'name' => 'Webhook Test' ,
2022-04-19 04:21:45 +12:00
'events' => [ 'users.*.create' , 'users.*.update.email' ],
2020-07-09 21:13:14 +12:00
'url' => 'https://appwrite.io' ,
'security' => true ,
'httpUser' => 'username' ,
'httpPass' => 'password' ,
]);
$this -> assertEquals ( 201 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertNotEmpty ( $response [ 'body' ][ '$id' ]);
2022-04-19 04:21:45 +12:00
$this -> assertContains ( 'users.*.create' , $response [ 'body' ][ 'events' ]);
$this -> assertContains ( 'users.*.update.email' , $response [ 'body' ][ 'events' ]);
2020-07-09 21:13:14 +12:00
$this -> assertCount ( 2 , $response [ 'body' ][ 'events' ]);
$this -> assertEquals ( 'https://appwrite.io' , $response [ 'body' ][ 'url' ]);
2020-07-12 01:01:04 +12:00
$this -> assertIsBool ( $response [ 'body' ][ 'security' ]);
$this -> assertEquals ( true , $response [ 'body' ][ 'security' ]);
2020-07-09 21:13:14 +12:00
$this -> assertEquals ( 'username' , $response [ 'body' ][ 'httpUser' ]);
2022-04-19 04:21:45 +12:00
2022-06-21 06:35:33 +12:00
$data = array_merge ( $data , [ 'webhookId' => $response [ 'body' ][ '$id' ], 'signatureKey' => $response [ 'body' ][ 'signatureKey' ]]);
2020-07-09 21:13:14 +12:00
/**
* Test for FAILURE
*/
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_POST , '/projects/' . $id . '/webhooks' , array_merge ([
2020-07-12 01:01:04 +12:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
'name' => 'Webhook Test' ,
2022-04-19 04:21:45 +12:00
'events' => [ 'account.unknown' , 'users.*.update.email' ],
2020-07-12 01:01:04 +12:00
'url' => 'https://appwrite.io' ,
'security' => true ,
'httpUser' => 'username' ,
'httpPass' => 'password' ,
]);
$this -> assertEquals ( 400 , $response [ 'headers' ][ 'status-code' ]);
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_POST , '/projects/' . $id . '/webhooks' , array_merge ([
2022-02-17 04:16:37 +13:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
'name' => 'Webhook Test' ,
2022-04-19 04:21:45 +12:00
'events' => [ 'users.*.create' , 'users.*.update.email' ],
2022-02-17 04:16:37 +13:00
'url' => 'invalid://appwrite.io' ,
]);
$this -> assertEquals ( 400 , $response [ 'headers' ][ 'status-code' ]);
2020-07-12 01:01:04 +12:00
return $data ;
}
2020-07-13 01:43:47 +12:00
/**
* @ depends testCreateProjectWebhook
*/
public function testListProjectWebhook ( $data ) : array
{
2020-10-15 10:11:12 +13:00
$id = $data [ 'projectId' ] ? ? '' ;
2020-07-13 01:43:47 +12:00
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_GET , '/projects/' . $id . '/webhooks' , array_merge ([
2020-07-13 01:43:47 +12:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), []);
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
2022-02-27 22:57:09 +13:00
$this -> assertEquals ( 1 , $response [ 'body' ][ 'total' ]);
2022-04-19 04:21:45 +12:00
2020-07-13 01:43:47 +12:00
/**
* Test for FAILURE
*/
return $data ;
}
2020-07-12 01:01:04 +12:00
/**
* @ depends testCreateProjectWebhook
*/
public function testGetProjectWebhook ( $data ) : array
{
2020-10-15 10:11:12 +13:00
$id = $data [ 'projectId' ] ? ? '' ;
$webhookId = $data [ 'webhookId' ] ? ? '' ;
2020-07-12 01:01:04 +12:00
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_GET , '/projects/' . $id . '/webhooks/' . $webhookId , array_merge ([
2020-07-12 01:01:04 +12:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), []);
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertNotEmpty ( $response [ 'body' ][ '$id' ]);
$this -> assertEquals ( $webhookId , $response [ 'body' ][ '$id' ]);
2022-04-19 04:21:45 +12:00
$this -> assertContains ( 'users.*.create' , $response [ 'body' ][ 'events' ]);
$this -> assertContains ( 'users.*.update.email' , $response [ 'body' ][ 'events' ]);
2020-07-12 01:01:04 +12:00
$this -> assertCount ( 2 , $response [ 'body' ][ 'events' ]);
$this -> assertEquals ( 'https://appwrite.io' , $response [ 'body' ][ 'url' ]);
$this -> assertEquals ( 'username' , $response [ 'body' ][ 'httpUser' ]);
$this -> assertEquals ( 'password' , $response [ 'body' ][ 'httpPass' ]);
2022-04-19 04:21:45 +12:00
2020-07-12 01:01:04 +12:00
/**
* Test for FAILURE
*/
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_GET , '/projects/' . $id . '/webhooks/error' , array_merge ([
2020-07-12 01:01:04 +12:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), []);
$this -> assertEquals ( 404 , $response [ 'headers' ][ 'status-code' ]);
return $data ;
}
/**
* @ depends testCreateProjectWebhook
*/
public function testUpdateProjectWebhook ( $data ) : array
{
2020-10-15 10:11:12 +13:00
$id = $data [ 'projectId' ] ? ? '' ;
$webhookId = $data [ 'webhookId' ] ? ? '' ;
2020-07-12 01:01:04 +12:00
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_PUT , '/projects/' . $id . '/webhooks/' . $webhookId , array_merge ([
2020-07-12 01:01:04 +12:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
'name' => 'Webhook Test Update' ,
2022-04-19 04:21:45 +12:00
'events' => [ 'users.*.delete' , 'users.*.sessions.*.delete' , 'buckets.*.files.*.create' ],
2020-07-12 01:01:04 +12:00
'url' => 'https://appwrite.io/new' ,
'security' => false ,
]);
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertNotEmpty ( $response [ 'body' ][ '$id' ]);
$this -> assertEquals ( $webhookId , $response [ 'body' ][ '$id' ]);
$this -> assertEquals ( 'Webhook Test Update' , $response [ 'body' ][ 'name' ]);
2022-04-19 04:21:45 +12:00
$this -> assertContains ( 'users.*.delete' , $response [ 'body' ][ 'events' ]);
$this -> assertContains ( 'users.*.sessions.*.delete' , $response [ 'body' ][ 'events' ]);
$this -> assertContains ( 'buckets.*.files.*.create' , $response [ 'body' ][ 'events' ]);
2020-07-12 01:01:04 +12:00
$this -> assertCount ( 3 , $response [ 'body' ][ 'events' ]);
$this -> assertEquals ( 'https://appwrite.io/new' , $response [ 'body' ][ 'url' ]);
$this -> assertIsBool ( $response [ 'body' ][ 'security' ]);
$this -> assertEquals ( false , $response [ 'body' ][ 'security' ]);
$this -> assertEquals ( '' , $response [ 'body' ][ 'httpUser' ]);
2020-11-21 12:31:17 +13:00
$this -> assertEquals ( '' , $response [ 'body' ][ 'httpPass' ]);
2020-07-12 01:01:04 +12:00
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_GET , '/projects/' . $id . '/webhooks/' . $webhookId , array_merge ([
2020-07-12 01:01:04 +12:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), []);
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertNotEmpty ( $response [ 'body' ][ '$id' ]);
$this -> assertEquals ( $webhookId , $response [ 'body' ][ '$id' ]);
$this -> assertEquals ( 'Webhook Test Update' , $response [ 'body' ][ 'name' ]);
2022-04-19 04:21:45 +12:00
$this -> assertContains ( 'users.*.delete' , $response [ 'body' ][ 'events' ]);
$this -> assertContains ( 'users.*.sessions.*.delete' , $response [ 'body' ][ 'events' ]);
$this -> assertContains ( 'buckets.*.files.*.create' , $response [ 'body' ][ 'events' ]);
2020-07-12 01:01:04 +12:00
$this -> assertCount ( 3 , $response [ 'body' ][ 'events' ]);
$this -> assertEquals ( 'https://appwrite.io/new' , $response [ 'body' ][ 'url' ]);
$this -> assertIsBool ( $response [ 'body' ][ 'security' ]);
$this -> assertEquals ( false , $response [ 'body' ][ 'security' ]);
$this -> assertEquals ( '' , $response [ 'body' ][ 'httpUser' ]);
2020-11-21 12:31:17 +13:00
$this -> assertEquals ( '' , $response [ 'body' ][ 'httpPass' ]);
2022-04-19 04:21:45 +12:00
2020-07-12 01:01:04 +12:00
/**
* Test for FAILURE
*/
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_PUT , '/projects/' . $id . '/webhooks/' . $webhookId , array_merge ([
2020-07-12 01:01:04 +12:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
'name' => 'Webhook Test Update' ,
2022-04-19 04:21:45 +12:00
'events' => [ 'users.*.delete' , 'users.*.sessions.*.delete' , 'buckets.*.files.*.unknown' ],
2020-07-12 01:01:04 +12:00
'url' => 'https://appwrite.io/new' ,
'security' => false ,
]);
$this -> assertEquals ( 400 , $response [ 'headers' ][ 'status-code' ]);
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_PUT , '/projects/' . $id . '/webhooks/' . $webhookId , array_merge ([
2020-07-12 01:01:04 +12:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
'name' => 'Webhook Test Update' ,
2022-04-19 04:21:45 +12:00
'events' => [ 'users.*.delete' , 'users.*.sessions.*.delete' , 'buckets.*.files.*.create' ],
2020-07-12 01:01:04 +12:00
'url' => 'appwrite.io/new' ,
'security' => false ,
]);
$this -> assertEquals ( 400 , $response [ 'headers' ][ 'status-code' ]);
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_PUT , '/projects/' . $id . '/webhooks/' . $webhookId , array_merge ([
2022-02-17 04:16:37 +13:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
'name' => 'Webhook Test Update' ,
2022-04-19 04:21:45 +12:00
'events' => [ 'users.*.delete' , 'users.*.sessions.*.delete' , 'buckets.*.files.*.create' ],
2022-02-17 04:16:37 +13:00
'url' => 'invalid://appwrite.io/new' ,
]);
$this -> assertEquals ( 400 , $response [ 'headers' ][ 'status-code' ]);
2020-07-12 01:01:04 +12:00
return $data ;
}
2022-06-21 06:35:33 +12:00
/**
* @ depends testCreateProjectWebhook
*/
public function testUpdateProjectWebhookSignature ( $data ) : void
{
$id = $data [ 'projectId' ] ? ? '' ;
$webhookId = $data [ 'webhookId' ] ? ? '' ;
$signatureKey = $data [ 'signatureKey' ] ? ? '' ;
$response = $this -> client -> call ( Client :: METHOD_PATCH , '/projects/' . $id . '/webhooks/' . $webhookId . '/signature' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()));
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertNotEmpty ( $response [ 'body' ][ 'signatureKey' ]);
$this -> assertNotEquals ( $signatureKey , $response [ 'body' ][ 'signatureKey' ]);
}
2020-07-12 01:01:04 +12:00
/**
* @ depends testCreateProjectWebhook
*/
public function testDeleteProjectWebhook ( $data ) : array
{
2020-10-15 10:11:12 +13:00
$id = $data [ 'projectId' ] ? ? '' ;
$webhookId = $data [ 'webhookId' ] ? ? '' ;
2020-07-12 01:01:04 +12:00
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_DELETE , '/projects/' . $id . '/webhooks/' . $webhookId , array_merge ([
2020-07-12 01:01:04 +12:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), []);
$this -> assertEquals ( 204 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertEmpty ( $response [ 'body' ]);
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_GET , '/projects/' . $id . '/webhooks/' . $webhookId , array_merge ([
2020-07-12 01:01:04 +12:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), []);
$this -> assertEquals ( 404 , $response [ 'headers' ][ 'status-code' ]);
2022-04-19 04:21:45 +12:00
2020-07-12 01:01:04 +12:00
/**
* Test for FAILURE
*/
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_DELETE , '/projects/' . $id . '/webhooks/error' , array_merge ([
2020-07-12 01:01:04 +12:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), []);
2020-07-09 21:13:14 +12:00
2020-07-12 01:01:04 +12:00
$this -> assertEquals ( 404 , $response [ 'headers' ][ 'status-code' ]);
2020-07-09 21:13:14 +12:00
return $data ;
2020-07-09 03:20:18 +12:00
}
2020-07-12 01:01:04 +12:00
// Keys
/**
* @ depends testCreateProject
*/
public function testCreateProjectKey ( $data ) : array
{
2020-10-15 10:11:12 +13:00
$id = $data [ 'projectId' ] ? ? '' ;
2020-07-12 01:01:04 +12:00
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_POST , '/projects/' . $id . '/keys' , array_merge ([
2020-07-12 01:01:04 +12:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
'name' => 'Key Test' ,
'scopes' => [ 'teams.read' , 'teams.write' ],
]);
$this -> assertEquals ( 201 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertNotEmpty ( $response [ 'body' ][ '$id' ]);
$this -> assertEquals ( 'Key Test' , $response [ 'body' ][ 'name' ]);
$this -> assertContains ( 'teams.read' , $response [ 'body' ][ 'scopes' ]);
$this -> assertContains ( 'teams.write' , $response [ 'body' ][ 'scopes' ]);
$this -> assertNotEmpty ( $response [ 'body' ][ 'secret' ]);
2022-08-31 02:04:42 +12:00
$this -> assertArrayHasKey ( 'sdks' , $response [ 'body' ]);
$this -> assertEmpty ( $response [ 'body' ][ 'sdks' ]);
$this -> assertArrayHasKey ( 'accessedAt' , $response [ 'body' ]);
$this -> assertEmpty ( $response [ 'body' ][ 'accessedAt' ]);
2022-04-19 04:21:45 +12:00
2022-06-01 03:41:12 +12:00
$data = array_merge ( $data , [
'keyId' => $response [ 'body' ][ '$id' ],
'secret' => $response [ 'body' ][ 'secret' ]
]);
2020-07-12 01:01:04 +12:00
/**
* Test for FAILURE
*/
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_POST , '/projects/' . $id . '/keys' , array_merge ([
2020-07-12 01:01:04 +12:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
'name' => 'Key Test' ,
'scopes' => [ 'unknown' ],
]);
$this -> assertEquals ( 400 , $response [ 'headers' ][ 'status-code' ]);
return $data ;
}
2022-06-01 03:41:12 +12:00
2020-07-13 01:43:47 +12:00
/**
* @ depends testCreateProjectKey
*/
public function testListProjectKey ( $data ) : array
{
2020-10-15 10:11:12 +13:00
$id = $data [ 'projectId' ] ? ? '' ;
2020-07-13 01:43:47 +12:00
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_GET , '/projects/' . $id . '/keys' , array_merge ([
2020-07-13 01:43:47 +12:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), []);
2022-06-01 18:26:55 +12:00
2020-07-13 01:43:47 +12:00
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
2022-02-27 22:57:09 +13:00
$this -> assertEquals ( 1 , $response [ 'body' ][ 'total' ]);
2022-04-19 04:21:45 +12:00
2020-07-13 01:43:47 +12:00
/**
* Test for FAILURE
*/
return $data ;
}
2022-06-01 03:41:12 +12:00
2020-07-12 01:01:04 +12:00
/**
* @ depends testCreateProjectKey
*/
public function testGetProjectKey ( $data ) : array
{
2020-10-15 10:11:12 +13:00
$id = $data [ 'projectId' ] ? ? '' ;
$keyId = $data [ 'keyId' ] ? ? '' ;
2020-07-12 01:01:04 +12:00
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_GET , '/projects/' . $id . '/keys/' . $keyId , array_merge ([
2020-07-12 01:01:04 +12:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), []);
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertNotEmpty ( $response [ 'body' ][ '$id' ]);
$this -> assertEquals ( $keyId , $response [ 'body' ][ '$id' ]);
$this -> assertEquals ( 'Key Test' , $response [ 'body' ][ 'name' ]);
$this -> assertContains ( 'teams.read' , $response [ 'body' ][ 'scopes' ]);
$this -> assertContains ( 'teams.write' , $response [ 'body' ][ 'scopes' ]);
$this -> assertCount ( 2 , $response [ 'body' ][ 'scopes' ]);
$this -> assertNotEmpty ( $response [ 'body' ][ 'secret' ]);
2022-08-31 02:04:42 +12:00
$this -> assertArrayHasKey ( 'sdks' , $response [ 'body' ]);
$this -> assertEmpty ( $response [ 'body' ][ 'sdks' ]);
$this -> assertArrayHasKey ( 'accessedAt' , $response [ 'body' ]);
$this -> assertEmpty ( $response [ 'body' ][ 'accessedAt' ]);
2022-04-19 04:21:45 +12:00
2020-07-12 01:01:04 +12:00
/**
* Test for FAILURE
*/
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_GET , '/projects/' . $id . '/keys/error' , array_merge ([
2020-07-12 01:01:04 +12:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), []);
$this -> assertEquals ( 404 , $response [ 'headers' ][ 'status-code' ]);
return $data ;
}
2022-06-01 03:41:12 +12:00
/**
2022-06-01 18:26:55 +12:00
* @ depends testCreateProject
2022-06-01 03:41:12 +12:00
*/
public function testValidateProjectKey ( $data ) : void
{
$id = $data [ 'projectId' ] ? ? '' ;
2022-06-01 18:26:55 +12:00
/**
* Test for SUCCESS
*/
$response = $this -> client -> call ( Client :: METHOD_POST , '/projects/' . $id . '/keys' , array_merge ([
2022-06-01 03:41:12 +12:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
2022-06-01 18:26:55 +12:00
], $this -> getHeaders ()), [
'name' => 'Key Test' ,
'scopes' => [ 'health.read' ],
2022-07-14 02:02:49 +12:00
'expire' => DateTime :: addSeconds ( new \DateTime (), 3600 ),
2022-06-01 18:26:55 +12:00
]);
2022-06-03 21:12:19 +12:00
$response = $this -> client -> call ( Client :: METHOD_GET , '/health' , [
2022-06-01 18:26:55 +12:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $id ,
'x-appwrite-key' => $response [ 'body' ][ 'secret' ]
], []);
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
/**
* Test for SUCCESS
*/
$response = $this -> client -> call ( Client :: METHOD_POST , '/projects/' . $id . '/keys' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
'name' => 'Key Test' ,
'scopes' => [ 'health.read' ],
2022-07-06 06:55:20 +12:00
'expire' => null ,
2022-06-01 18:26:55 +12:00
]);
2022-06-03 21:12:19 +12:00
$response = $this -> client -> call ( Client :: METHOD_GET , '/health' , [
2022-06-01 18:26:55 +12:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $id ,
'x-appwrite-key' => $response [ 'body' ][ 'secret' ]
], []);
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
/**
* Test for FAILURE
*/
$response = $this -> client -> call ( Client :: METHOD_POST , '/projects/' . $id . '/keys' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
'name' => 'Key Test' ,
'scopes' => [ 'health.read' ],
2022-07-14 02:02:49 +12:00
'expire' => DateTime :: addSeconds ( new \DateTime (), - 3600 ),
2022-06-01 18:26:55 +12:00
]);
2022-06-03 21:12:19 +12:00
$response = $this -> client -> call ( Client :: METHOD_GET , '/health' , [
2022-06-01 18:26:55 +12:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $id ,
'x-appwrite-key' => $response [ 'body' ][ 'secret' ]
], []);
$this -> assertEquals ( 401 , $response [ 'headers' ][ 'status-code' ]);
2022-06-01 03:41:12 +12:00
}
2020-07-12 01:26:04 +12:00
/**
* @ depends testCreateProjectKey
*/
public function testUpdateProjectKey ( $data ) : array
{
2020-10-15 10:11:12 +13:00
$id = $data [ 'projectId' ] ? ? '' ;
$keyId = $data [ 'keyId' ] ? ? '' ;
2020-07-12 01:26:04 +12:00
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_PUT , '/projects/' . $id . '/keys/' . $keyId , array_merge ([
2020-07-12 01:26:04 +12:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
'name' => 'Key Test Update' ,
'scopes' => [ 'users.read' , 'users.write' , 'collections.read' ],
2022-07-14 02:02:49 +12:00
'expire' => DateTime :: addSeconds ( new \DateTime (), 360 ),
2020-07-12 01:26:04 +12:00
]);
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertNotEmpty ( $response [ 'body' ][ '$id' ]);
$this -> assertEquals ( $keyId , $response [ 'body' ][ '$id' ]);
$this -> assertEquals ( 'Key Test Update' , $response [ 'body' ][ 'name' ]);
$this -> assertContains ( 'users.read' , $response [ 'body' ][ 'scopes' ]);
$this -> assertContains ( 'users.write' , $response [ 'body' ][ 'scopes' ]);
$this -> assertContains ( 'collections.read' , $response [ 'body' ][ 'scopes' ]);
$this -> assertCount ( 3 , $response [ 'body' ][ 'scopes' ]);
2022-08-31 02:04:42 +12:00
$this -> assertArrayHasKey ( 'sdks' , $response [ 'body' ]);
$this -> assertEmpty ( $response [ 'body' ][ 'sdks' ]);
$this -> assertArrayHasKey ( 'accessedAt' , $response [ 'body' ]);
$this -> assertEmpty ( $response [ 'body' ][ 'accessedAt' ]);
2020-07-12 01:26:04 +12:00
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_GET , '/projects/' . $id . '/keys/' . $keyId , array_merge ([
2020-07-12 01:26:04 +12:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), []);
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertNotEmpty ( $response [ 'body' ][ '$id' ]);
$this -> assertEquals ( $keyId , $response [ 'body' ][ '$id' ]);
$this -> assertEquals ( 'Key Test Update' , $response [ 'body' ][ 'name' ]);
$this -> assertContains ( 'users.read' , $response [ 'body' ][ 'scopes' ]);
$this -> assertContains ( 'users.write' , $response [ 'body' ][ 'scopes' ]);
$this -> assertContains ( 'collections.read' , $response [ 'body' ][ 'scopes' ]);
$this -> assertCount ( 3 , $response [ 'body' ][ 'scopes' ]);
2022-08-31 02:04:42 +12:00
$this -> assertArrayHasKey ( 'sdks' , $response [ 'body' ]);
$this -> assertEmpty ( $response [ 'body' ][ 'sdks' ]);
$this -> assertArrayHasKey ( 'accessedAt' , $response [ 'body' ]);
$this -> assertEmpty ( $response [ 'body' ][ 'accessedAt' ]);
2022-04-19 04:21:45 +12:00
2020-07-12 01:26:04 +12:00
/**
* Test for FAILURE
*/
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_PUT , '/projects/' . $id . '/keys/' . $keyId , array_merge ([
2020-07-12 01:26:04 +12:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
'name' => 'Key Test Update' ,
'scopes' => [ 'users.read' , 'users.write' , 'collections.read' , 'unknown' ],
]);
$this -> assertEquals ( 400 , $response [ 'headers' ][ 'status-code' ]);
return $data ;
}
/**
* @ depends testCreateProjectKey
*/
public function testDeleteProjectKey ( $data ) : array
{
2020-10-15 10:11:12 +13:00
$id = $data [ 'projectId' ] ? ? '' ;
$keyId = $data [ 'keyId' ] ? ? '' ;
2020-07-12 01:26:04 +12:00
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_DELETE , '/projects/' . $id . '/keys/' . $keyId , array_merge ([
2020-07-12 01:26:04 +12:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), []);
$this -> assertEquals ( 204 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertEmpty ( $response [ 'body' ]);
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_GET , '/projects/' . $id . '/keys/' . $keyId , array_merge ([
2020-07-12 01:26:04 +12:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), []);
$this -> assertEquals ( 404 , $response [ 'headers' ][ 'status-code' ]);
2022-04-19 04:21:45 +12:00
2020-07-12 01:26:04 +12:00
/**
* Test for FAILURE
*/
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_DELETE , '/projects/' . $id . '/keys/error' , array_merge ([
2020-07-12 01:26:04 +12:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), []);
$this -> assertEquals ( 404 , $response [ 'headers' ][ 'status-code' ]);
return $data ;
}
2020-07-12 07:40:58 +12:00
2024-05-16 20:39:15 +12:00
/**
* @ depends testCreateProject
*/
public function testCreateProjectKeyOutdated ( $data ) : void
{
$id = $data [ 'projectId' ] ? ? '' ;
$response = $this -> client -> call ( Client :: METHOD_POST , '/mock/api-key-unprefixed' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
'projectId' => $id
]);
$this -> assertEquals ( 201 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertContains ( 'users.read' , $response [ 'body' ][ 'scopes' ]);
$this -> assertNotEmpty ( $response [ 'body' ][ 'secret' ]);
$this -> assertStringStartsNotWith ( API_KEY_STANDARD . '_' , $response [ 'body' ][ 'secret' ]);
$keyId = $response [ 'body' ][ '$id' ];
$secret = $response [ 'body' ][ 'secret' ];
$response = $this -> client -> call ( Client :: METHOD_GET , '/users' , [
'content-type' => 'application/json' ,
'x-appwrite-project' => $id ,
'x-appwrite-key' => $secret
], []);
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
$response = $this -> client -> call ( Client :: METHOD_DELETE , '/projects/' . $id . '/keys/' . $keyId , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), []);
$this -> assertEquals ( 204 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertEmpty ( $response [ 'body' ]);
}
2024-05-29 21:33:39 +12:00
// JWT Keys
/**
* @ depends testCreateProject
*/
public function testJWTKey ( $data ) : void
{
$id = $data [ 'projectId' ] ? ? '' ;
// Create JWT key
$response = $this -> client -> call ( Client :: METHOD_POST , '/projects/' . $id . '/jwts' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
'duration' => 5 ,
'scopes' => [ 'users.read' ],
]);
$this -> assertEquals ( 201 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertNotEmpty ( $response [ 'body' ][ 'jwt' ]);
$jwt = $response [ 'body' ][ 'jwt' ];
// Ensure JWT key works
$response = $this -> client -> call ( Client :: METHOD_GET , '/users' , [
'content-type' => 'application/json' ,
'x-appwrite-project' => $id ,
'x-appwrite-key' => $jwt ,
]);
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertArrayHasKey ( 'users' , $response [ 'body' ]);
// Ensure JWT key respect scopes
$response = $this -> client -> call ( Client :: METHOD_GET , '/functions' , [
'content-type' => 'application/json' ,
'x-appwrite-project' => $id ,
'x-appwrite-key' => $jwt ,
]);
$this -> assertEquals ( 401 , $response [ 'headers' ][ 'status-code' ]);
// Ensure JWT key expires
\sleep ( 10 );
$response = $this -> client -> call ( Client :: METHOD_GET , '/users' , [
'content-type' => 'application/json' ,
'x-appwrite-project' => $id ,
'x-appwrite-key' => $jwt ,
]);
$this -> assertEquals ( 401 , $response [ 'headers' ][ 'status-code' ]);
}
2020-07-12 23:57:31 +12:00
// Platforms
/**
* @ depends testCreateProject
*/
public function testCreateProjectPlatform ( $data ) : array
{
2020-10-15 10:11:12 +13:00
$id = $data [ 'projectId' ] ? ? '' ;
2020-07-12 23:57:31 +12:00
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_POST , '/projects/' . $id . '/platforms' , array_merge ([
2020-07-12 23:57:31 +12:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
'type' => 'web' ,
'name' => 'Web App' ,
'hostname' => 'localhost' ,
]);
$this -> assertEquals ( 201 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertNotEmpty ( $response [ 'body' ][ '$id' ]);
$this -> assertEquals ( 'web' , $response [ 'body' ][ 'type' ]);
$this -> assertEquals ( 'Web App' , $response [ 'body' ][ 'name' ]);
$this -> assertEquals ( '' , $response [ 'body' ][ 'key' ]);
$this -> assertEquals ( '' , $response [ 'body' ][ 'store' ]);
$this -> assertEquals ( 'localhost' , $response [ 'body' ][ 'hostname' ]);
2022-04-19 04:21:45 +12:00
2020-07-12 23:57:31 +12:00
$data = array_merge ( $data , [ 'platformWebId' => $response [ 'body' ][ '$id' ]]);
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_POST , '/projects/' . $id . '/platforms' , array_merge ([
2020-07-12 23:57:31 +12:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
'type' => 'flutter-ios' ,
'name' => 'Flutter App (iOS)' ,
'key' => 'com.example.ios' ,
]);
$this -> assertEquals ( 201 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertNotEmpty ( $response [ 'body' ][ '$id' ]);
$this -> assertEquals ( 'flutter-ios' , $response [ 'body' ][ 'type' ]);
$this -> assertEquals ( 'Flutter App (iOS)' , $response [ 'body' ][ 'name' ]);
$this -> assertEquals ( 'com.example.ios' , $response [ 'body' ][ 'key' ]);
$this -> assertEquals ( '' , $response [ 'body' ][ 'store' ]);
$this -> assertEquals ( '' , $response [ 'body' ][ 'hostname' ]);
2022-04-19 04:21:45 +12:00
2020-07-12 23:57:31 +12:00
$data = array_merge ( $data , [ 'platformFultteriOSId' => $response [ 'body' ][ '$id' ]]);
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_POST , '/projects/' . $id . '/platforms' , array_merge ([
2020-07-12 23:57:31 +12:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
'type' => 'flutter-android' ,
'name' => 'Flutter App (Android)' ,
'key' => 'com.example.android' ,
]);
$this -> assertEquals ( 201 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertNotEmpty ( $response [ 'body' ][ '$id' ]);
$this -> assertEquals ( 'flutter-android' , $response [ 'body' ][ 'type' ]);
$this -> assertEquals ( 'Flutter App (Android)' , $response [ 'body' ][ 'name' ]);
$this -> assertEquals ( 'com.example.android' , $response [ 'body' ][ 'key' ]);
$this -> assertEquals ( '' , $response [ 'body' ][ 'store' ]);
$this -> assertEquals ( '' , $response [ 'body' ][ 'hostname' ]);
2022-04-19 04:21:45 +12:00
2020-07-12 23:57:31 +12:00
$data = array_merge ( $data , [ 'platformFultterAndroidId' => $response [ 'body' ][ '$id' ]]);
2023-01-12 12:38:09 +13:00
$response = $this -> client -> call ( Client :: METHOD_POST , '/projects/' . $id . '/platforms' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
'type' => 'flutter-web' ,
'name' => 'Flutter App (Web)' ,
'hostname' => 'flutter.appwrite.io' ,
]);
$this -> assertEquals ( 201 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertNotEmpty ( $response [ 'body' ][ '$id' ]);
$this -> assertEquals ( 'flutter-web' , $response [ 'body' ][ 'type' ]);
$this -> assertEquals ( 'Flutter App (Web)' , $response [ 'body' ][ 'name' ]);
$this -> assertEquals ( '' , $response [ 'body' ][ 'key' ]);
$this -> assertEquals ( '' , $response [ 'body' ][ 'store' ]);
$this -> assertEquals ( 'flutter.appwrite.io' , $response [ 'body' ][ 'hostname' ]);
$data = array_merge ( $data , [ 'platformFultterWebId' => $response [ 'body' ][ '$id' ]]);
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_POST , '/projects/' . $id . '/platforms' , array_merge ([
2021-10-14 02:44:52 +13:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
'type' => 'apple-ios' ,
'name' => 'iOS App' ,
'key' => 'com.example.ios' ,
]);
$this -> assertEquals ( 201 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertNotEmpty ( $response [ 'body' ][ '$id' ]);
$this -> assertEquals ( 'apple-ios' , $response [ 'body' ][ 'type' ]);
$this -> assertEquals ( 'iOS App' , $response [ 'body' ][ 'name' ]);
$this -> assertEquals ( 'com.example.ios' , $response [ 'body' ][ 'key' ]);
$this -> assertEquals ( '' , $response [ 'body' ][ 'store' ]);
$this -> assertEquals ( '' , $response [ 'body' ][ 'hostname' ]);
$data = array_merge ( $data , [ 'platformAppleIosId' => $response [ 'body' ][ '$id' ]]);
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_POST , '/projects/' . $id . '/platforms' , array_merge ([
2021-10-14 02:44:52 +13:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
'type' => 'apple-macos' ,
'name' => 'macOS App' ,
'key' => 'com.example.macos' ,
]);
$this -> assertEquals ( 201 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertNotEmpty ( $response [ 'body' ][ '$id' ]);
$this -> assertEquals ( 'apple-macos' , $response [ 'body' ][ 'type' ]);
$this -> assertEquals ( 'macOS App' , $response [ 'body' ][ 'name' ]);
$this -> assertEquals ( 'com.example.macos' , $response [ 'body' ][ 'key' ]);
$this -> assertEquals ( '' , $response [ 'body' ][ 'store' ]);
$this -> assertEquals ( '' , $response [ 'body' ][ 'hostname' ]);
$data = array_merge ( $data , [ 'platformAppleMacOsId' => $response [ 'body' ][ '$id' ]]);
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_POST , '/projects/' . $id . '/platforms' , array_merge ([
2021-10-14 02:44:52 +13:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
'type' => 'apple-watchos' ,
'name' => 'watchOS App' ,
'key' => 'com.example.watchos' ,
]);
$this -> assertEquals ( 201 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertNotEmpty ( $response [ 'body' ][ '$id' ]);
$this -> assertEquals ( 'apple-watchos' , $response [ 'body' ][ 'type' ]);
$this -> assertEquals ( 'watchOS App' , $response [ 'body' ][ 'name' ]);
$this -> assertEquals ( 'com.example.watchos' , $response [ 'body' ][ 'key' ]);
$this -> assertEquals ( '' , $response [ 'body' ][ 'store' ]);
$this -> assertEquals ( '' , $response [ 'body' ][ 'hostname' ]);
$data = array_merge ( $data , [ 'platformAppleWatchOsId' => $response [ 'body' ][ '$id' ]]);
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_POST , '/projects/' . $id . '/platforms' , array_merge ([
2021-10-14 02:44:52 +13:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
'type' => 'apple-tvos' ,
'name' => 'tvOS App' ,
'key' => 'com.example.tvos' ,
]);
$this -> assertEquals ( 201 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertNotEmpty ( $response [ 'body' ][ '$id' ]);
$this -> assertEquals ( 'apple-tvos' , $response [ 'body' ][ 'type' ]);
$this -> assertEquals ( 'tvOS App' , $response [ 'body' ][ 'name' ]);
$this -> assertEquals ( 'com.example.tvos' , $response [ 'body' ][ 'key' ]);
$this -> assertEquals ( '' , $response [ 'body' ][ 'store' ]);
$this -> assertEquals ( '' , $response [ 'body' ][ 'hostname' ]);
$data = array_merge ( $data , [ 'platformAppleTvOsId' => $response [ 'body' ][ '$id' ]]);
2020-07-12 23:57:31 +12:00
/**
* Test for FAILURE
*/
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_POST , '/projects/' . $id . '/platforms' , array_merge ([
2020-07-12 23:57:31 +12:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
'type' => 'unknown' ,
'name' => 'Web App' ,
'hostname' => 'localhost' ,
]);
2021-12-02 00:48:23 +13:00
$this -> assertEquals ( 400 , $response [ 'headers' ][ 'status-code' ]);
2020-07-12 23:57:31 +12:00
return $data ;
}
2020-07-13 01:43:47 +12:00
/**
* @ depends testCreateProjectPlatform
*/
public function testListProjectPlatform ( $data ) : array
{
2020-10-15 10:11:12 +13:00
$id = $data [ 'projectId' ] ? ? '' ;
2021-12-02 00:48:23 +13:00
sleep ( 1 );
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_GET , '/projects/' . $id . '/platforms' , array_merge ([
2020-07-13 01:43:47 +12:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), []);
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
2023-01-12 12:38:09 +13:00
$this -> assertEquals ( 8 , $response [ 'body' ][ 'total' ]);
2020-07-13 01:43:47 +12:00
/**
* Test for FAILURE
*/
2022-04-19 04:21:45 +12:00
2020-07-13 01:43:47 +12:00
return $data ;
}
2020-07-12 23:57:31 +12:00
/**
* @ depends testCreateProjectPlatform
*/
public function testGetProjectPlatform ( $data ) : array
{
2020-10-15 10:11:12 +13:00
$id = $data [ 'projectId' ] ? ? '' ;
2021-12-02 00:48:23 +13:00
2020-10-15 10:11:12 +13:00
$platformWebId = $data [ 'platformWebId' ] ? ? '' ;
2020-07-12 23:57:31 +12:00
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_GET , '/projects/' . $id . '/platforms/' . $platformWebId , array_merge ([
2020-07-12 23:57:31 +12:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), []);
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertNotEmpty ( $response [ 'body' ][ '$id' ]);
$this -> assertEquals ( $platformWebId , $response [ 'body' ][ '$id' ]);
$this -> assertEquals ( 'web' , $response [ 'body' ][ 'type' ]);
$this -> assertEquals ( 'Web App' , $response [ 'body' ][ 'name' ]);
$this -> assertEquals ( '' , $response [ 'body' ][ 'key' ]);
$this -> assertEquals ( '' , $response [ 'body' ][ 'store' ]);
$this -> assertEquals ( 'localhost' , $response [ 'body' ][ 'hostname' ]);
2022-04-19 04:21:45 +12:00
2020-10-15 10:11:12 +13:00
$platformFultteriOSId = $data [ 'platformFultteriOSId' ] ? ? '' ;
2020-07-12 23:57:31 +12:00
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_GET , '/projects/' . $id . '/platforms/' . $platformFultteriOSId , array_merge ([
2020-07-12 23:57:31 +12:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), []);
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertNotEmpty ( $response [ 'body' ][ '$id' ]);
$this -> assertEquals ( $platformFultteriOSId , $response [ 'body' ][ '$id' ]);
$this -> assertEquals ( 'flutter-ios' , $response [ 'body' ][ 'type' ]);
$this -> assertEquals ( 'Flutter App (iOS)' , $response [ 'body' ][ 'name' ]);
$this -> assertEquals ( 'com.example.ios' , $response [ 'body' ][ 'key' ]);
$this -> assertEquals ( '' , $response [ 'body' ][ 'store' ]);
$this -> assertEquals ( '' , $response [ 'body' ][ 'hostname' ]);
2022-04-19 04:21:45 +12:00
2020-10-15 10:11:12 +13:00
$platformFultterAndroidId = $data [ 'platformFultterAndroidId' ] ? ? '' ;
2020-07-12 23:57:31 +12:00
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_GET , '/projects/' . $id . '/platforms/' . $platformFultterAndroidId , array_merge ([
2020-07-12 23:57:31 +12:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), []);
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertNotEmpty ( $response [ 'body' ][ '$id' ]);
$this -> assertEquals ( $platformFultterAndroidId , $response [ 'body' ][ '$id' ]);
$this -> assertEquals ( 'flutter-android' , $response [ 'body' ][ 'type' ]);
$this -> assertEquals ( 'Flutter App (Android)' , $response [ 'body' ][ 'name' ]);
$this -> assertEquals ( 'com.example.android' , $response [ 'body' ][ 'key' ]);
$this -> assertEquals ( '' , $response [ 'body' ][ 'store' ]);
$this -> assertEquals ( '' , $response [ 'body' ][ 'hostname' ]);
2021-10-14 02:44:52 +13:00
2023-01-12 12:38:09 +13:00
$platformFultterWebId = $data [ 'platformFultterWebId' ] ? ? '' ;
$response = $this -> client -> call ( Client :: METHOD_GET , '/projects/' . $id . '/platforms/' . $platformFultterWebId , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), []);
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertNotEmpty ( $response [ 'body' ][ '$id' ]);
$this -> assertEquals ( $platformFultterWebId , $response [ 'body' ][ '$id' ]);
$this -> assertEquals ( 'flutter-web' , $response [ 'body' ][ 'type' ]);
$this -> assertEquals ( 'Flutter App (Web)' , $response [ 'body' ][ 'name' ]);
$this -> assertEquals ( '' , $response [ 'body' ][ 'key' ]);
$this -> assertEquals ( '' , $response [ 'body' ][ 'store' ]);
$this -> assertEquals ( 'flutter.appwrite.io' , $response [ 'body' ][ 'hostname' ]);
2021-10-14 02:44:52 +13:00
$platformAppleIosId = $data [ 'platformAppleIosId' ] ? ? '' ;
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_GET , '/projects/' . $id . '/platforms/' . $platformAppleIosId , array_merge ([
2021-10-14 02:44:52 +13:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), []);
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertNotEmpty ( $response [ 'body' ][ '$id' ]);
$this -> assertEquals ( $platformAppleIosId , $response [ 'body' ][ '$id' ]);
$this -> assertEquals ( 'apple-ios' , $response [ 'body' ][ 'type' ]);
$this -> assertEquals ( 'iOS App' , $response [ 'body' ][ 'name' ]);
$this -> assertEquals ( 'com.example.ios' , $response [ 'body' ][ 'key' ]);
$this -> assertEquals ( '' , $response [ 'body' ][ 'store' ]);
$this -> assertEquals ( '' , $response [ 'body' ][ 'hostname' ]);
$platformAppleMacOsId = $data [ 'platformAppleMacOsId' ] ? ? '' ;
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_GET , '/projects/' . $id . '/platforms/' . $platformAppleMacOsId , array_merge ([
2021-10-14 02:44:52 +13:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), []);
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertNotEmpty ( $response [ 'body' ][ '$id' ]);
$this -> assertEquals ( $platformAppleMacOsId , $response [ 'body' ][ '$id' ]);
$this -> assertEquals ( 'apple-macos' , $response [ 'body' ][ 'type' ]);
$this -> assertEquals ( 'macOS App' , $response [ 'body' ][ 'name' ]);
$this -> assertEquals ( 'com.example.macos' , $response [ 'body' ][ 'key' ]);
$this -> assertEquals ( '' , $response [ 'body' ][ 'store' ]);
$this -> assertEquals ( '' , $response [ 'body' ][ 'hostname' ]);
$platformAppleWatchOsId = $data [ 'platformAppleWatchOsId' ] ? ? '' ;
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_GET , '/projects/' . $id . '/platforms/' . $platformAppleWatchOsId , array_merge ([
2021-10-14 02:44:52 +13:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), []);
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertNotEmpty ( $response [ 'body' ][ '$id' ]);
$this -> assertEquals ( $platformAppleWatchOsId , $response [ 'body' ][ '$id' ]);
$this -> assertEquals ( 'apple-watchos' , $response [ 'body' ][ 'type' ]);
$this -> assertEquals ( 'watchOS App' , $response [ 'body' ][ 'name' ]);
$this -> assertEquals ( 'com.example.watchos' , $response [ 'body' ][ 'key' ]);
$this -> assertEquals ( '' , $response [ 'body' ][ 'store' ]);
$this -> assertEquals ( '' , $response [ 'body' ][ 'hostname' ]);
$platformAppleTvOsId = $data [ 'platformAppleTvOsId' ] ? ? '' ;
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_GET , '/projects/' . $id . '/platforms/' . $platformAppleTvOsId , array_merge ([
2021-10-14 02:44:52 +13:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), []);
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertNotEmpty ( $response [ 'body' ][ '$id' ]);
$this -> assertEquals ( $platformAppleTvOsId , $response [ 'body' ][ '$id' ]);
$this -> assertEquals ( 'apple-tvos' , $response [ 'body' ][ 'type' ]);
$this -> assertEquals ( 'tvOS App' , $response [ 'body' ][ 'name' ]);
$this -> assertEquals ( 'com.example.tvos' , $response [ 'body' ][ 'key' ]);
$this -> assertEquals ( '' , $response [ 'body' ][ 'store' ]);
$this -> assertEquals ( '' , $response [ 'body' ][ 'hostname' ]);
2020-07-12 23:57:31 +12:00
/**
* Test for FAILURE
*/
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_GET , '/projects/' . $id . '/platforms/error' , array_merge ([
2020-07-12 23:57:31 +12:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), []);
$this -> assertEquals ( 404 , $response [ 'headers' ][ 'status-code' ]);
return $data ;
}
/**
* @ depends testCreateProjectPlatform
*/
public function testUpdateProjectPlatform ( $data ) : array
{
2020-10-15 10:11:12 +13:00
$id = $data [ 'projectId' ] ? ? '' ;
2020-07-12 23:57:31 +12:00
2020-10-15 10:11:12 +13:00
$platformWebId = $data [ 'platformWebId' ] ? ? '' ;
2020-07-12 23:57:31 +12:00
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_PUT , '/projects/' . $id . '/platforms/' . $platformWebId , array_merge ([
2020-07-12 23:57:31 +12:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
'name' => 'Web App 2' ,
'hostname' => 'localhost-new' ,
]);
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertNotEmpty ( $response [ 'body' ][ '$id' ]);
$this -> assertEquals ( $platformWebId , $response [ 'body' ][ '$id' ]);
$this -> assertEquals ( 'web' , $response [ 'body' ][ 'type' ]);
$this -> assertEquals ( 'Web App 2' , $response [ 'body' ][ 'name' ]);
$this -> assertEquals ( '' , $response [ 'body' ][ 'key' ]);
$this -> assertEquals ( '' , $response [ 'body' ][ 'store' ]);
$this -> assertEquals ( 'localhost-new' , $response [ 'body' ][ 'hostname' ]);
2020-10-15 10:11:12 +13:00
$platformFultteriOSId = $data [ 'platformFultteriOSId' ] ? ? '' ;
2020-07-12 23:57:31 +12:00
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_PUT , '/projects/' . $id . '/platforms/' . $platformFultteriOSId , array_merge ([
2020-07-12 23:57:31 +12:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
'name' => 'Flutter App (iOS) 2' ,
'key' => 'com.example.ios2' ,
]);
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertNotEmpty ( $response [ 'body' ][ '$id' ]);
$this -> assertEquals ( $platformFultteriOSId , $response [ 'body' ][ '$id' ]);
$this -> assertEquals ( 'flutter-ios' , $response [ 'body' ][ 'type' ]);
$this -> assertEquals ( 'Flutter App (iOS) 2' , $response [ 'body' ][ 'name' ]);
$this -> assertEquals ( 'com.example.ios2' , $response [ 'body' ][ 'key' ]);
$this -> assertEquals ( '' , $response [ 'body' ][ 'store' ]);
$this -> assertEquals ( '' , $response [ 'body' ][ 'hostname' ]);
2022-04-19 04:21:45 +12:00
2020-10-15 10:11:12 +13:00
$platformFultterAndroidId = $data [ 'platformFultterAndroidId' ] ? ? '' ;
2020-07-12 23:57:31 +12:00
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_PUT , '/projects/' . $id . '/platforms/' . $platformFultterAndroidId , array_merge ([
2020-07-12 23:57:31 +12:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
'name' => 'Flutter App (Android) 2' ,
'key' => 'com.example.android2' ,
]);
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertNotEmpty ( $response [ 'body' ][ '$id' ]);
$this -> assertEquals ( $platformFultterAndroidId , $response [ 'body' ][ '$id' ]);
$this -> assertEquals ( 'flutter-android' , $response [ 'body' ][ 'type' ]);
$this -> assertEquals ( 'Flutter App (Android) 2' , $response [ 'body' ][ 'name' ]);
$this -> assertEquals ( 'com.example.android2' , $response [ 'body' ][ 'key' ]);
$this -> assertEquals ( '' , $response [ 'body' ][ 'store' ]);
$this -> assertEquals ( '' , $response [ 'body' ][ 'hostname' ]);
2023-01-12 12:38:09 +13:00
$platformFultterWebId = $data [ 'platformFultterWebId' ] ? ? '' ;
$response = $this -> client -> call ( Client :: METHOD_PUT , '/projects/' . $id . '/platforms/' . $platformFultterWebId , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
'name' => 'Flutter App (Web) 2' ,
'hostname' => 'flutter2.appwrite.io' ,
]);
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertNotEmpty ( $response [ 'body' ][ '$id' ]);
$this -> assertEquals ( $platformFultterWebId , $response [ 'body' ][ '$id' ]);
$this -> assertEquals ( 'flutter-web' , $response [ 'body' ][ 'type' ]);
$this -> assertEquals ( 'Flutter App (Web) 2' , $response [ 'body' ][ 'name' ]);
$this -> assertEquals ( '' , $response [ 'body' ][ 'key' ]);
$this -> assertEquals ( '' , $response [ 'body' ][ 'store' ]);
$this -> assertEquals ( 'flutter2.appwrite.io' , $response [ 'body' ][ 'hostname' ]);
2021-10-14 02:44:52 +13:00
$platformAppleIosId = $data [ 'platformAppleIosId' ] ? ? '' ;
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_PUT , '/projects/' . $id . '/platforms/' . $platformAppleIosId , array_merge ([
2021-10-14 02:44:52 +13:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
'name' => 'iOS App 2' ,
'key' => 'com.example.ios2' ,
]);
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertNotEmpty ( $response [ 'body' ][ '$id' ]);
$this -> assertEquals ( $platformAppleIosId , $response [ 'body' ][ '$id' ]);
$this -> assertEquals ( 'apple-ios' , $response [ 'body' ][ 'type' ]);
$this -> assertEquals ( 'iOS App 2' , $response [ 'body' ][ 'name' ]);
$this -> assertEquals ( 'com.example.ios2' , $response [ 'body' ][ 'key' ]);
$this -> assertEquals ( '' , $response [ 'body' ][ 'store' ]);
$this -> assertEquals ( '' , $response [ 'body' ][ 'hostname' ]);
$platformAppleMacOsId = $data [ 'platformAppleMacOsId' ] ? ? '' ;
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_PUT , '/projects/' . $id . '/platforms/' . $platformAppleMacOsId , array_merge ([
2021-10-14 02:44:52 +13:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
'name' => 'macOS App 2' ,
'key' => 'com.example.macos2' ,
]);
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertNotEmpty ( $response [ 'body' ][ '$id' ]);
$this -> assertEquals ( $platformAppleMacOsId , $response [ 'body' ][ '$id' ]);
$this -> assertEquals ( 'apple-macos' , $response [ 'body' ][ 'type' ]);
$this -> assertEquals ( 'macOS App 2' , $response [ 'body' ][ 'name' ]);
$this -> assertEquals ( 'com.example.macos2' , $response [ 'body' ][ 'key' ]);
$this -> assertEquals ( '' , $response [ 'body' ][ 'store' ]);
$this -> assertEquals ( '' , $response [ 'body' ][ 'hostname' ]);
$platformAppleWatchOsId = $data [ 'platformAppleWatchOsId' ] ? ? '' ;
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_PUT , '/projects/' . $id . '/platforms/' . $platformAppleWatchOsId , array_merge ([
2021-10-14 02:44:52 +13:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
'name' => 'watchOS App 2' ,
'key' => 'com.example.watchos2' ,
]);
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertNotEmpty ( $response [ 'body' ][ '$id' ]);
$this -> assertEquals ( $platformAppleWatchOsId , $response [ 'body' ][ '$id' ]);
$this -> assertEquals ( 'apple-watchos' , $response [ 'body' ][ 'type' ]);
$this -> assertEquals ( 'watchOS App 2' , $response [ 'body' ][ 'name' ]);
$this -> assertEquals ( 'com.example.watchos2' , $response [ 'body' ][ 'key' ]);
$this -> assertEquals ( '' , $response [ 'body' ][ 'store' ]);
$this -> assertEquals ( '' , $response [ 'body' ][ 'hostname' ]);
$platformAppleTvOsId = $data [ 'platformAppleTvOsId' ] ? ? '' ;
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_PUT , '/projects/' . $id . '/platforms/' . $platformAppleTvOsId , array_merge ([
2021-10-14 02:44:52 +13:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
'name' => 'tvOS App 2' ,
'key' => 'com.example.tvos2' ,
]);
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertNotEmpty ( $response [ 'body' ][ '$id' ]);
$this -> assertEquals ( $platformAppleTvOsId , $response [ 'body' ][ '$id' ]);
$this -> assertEquals ( 'apple-tvos' , $response [ 'body' ][ 'type' ]);
$this -> assertEquals ( 'tvOS App 2' , $response [ 'body' ][ 'name' ]);
$this -> assertEquals ( 'com.example.tvos2' , $response [ 'body' ][ 'key' ]);
$this -> assertEquals ( '' , $response [ 'body' ][ 'store' ]);
$this -> assertEquals ( '' , $response [ 'body' ][ 'hostname' ]);
2020-07-12 23:57:31 +12:00
/**
* Test for FAILURE
*/
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_PUT , '/projects/' . $id . '/platforms/error' , array_merge ([
2021-09-01 19:03:22 +12:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
'name' => 'Flutter App (Android) 2' ,
'key' => 'com.example.android2' ,
]);
$this -> assertEquals ( 404 , $response [ 'headers' ][ 'status-code' ]);
2020-07-12 23:57:31 +12:00
return $data ;
}
/**
* @ depends testCreateProjectPlatform
*/
public function testDeleteProjectPlatform ( $data ) : array
{
2020-10-15 10:11:12 +13:00
$id = $data [ 'projectId' ] ? ? '' ;
2022-04-19 04:21:45 +12:00
2020-10-15 10:11:12 +13:00
$platformWebId = $data [ 'platformWebId' ] ? ? '' ;
2020-07-12 23:57:31 +12:00
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_DELETE , '/projects/' . $id . '/platforms/' . $platformWebId , array_merge ([
2020-07-12 23:57:31 +12:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), []);
$this -> assertEquals ( 204 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertEmpty ( $response [ 'body' ]);
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_GET , '/projects/' . $id . '/platforms/' . $platformWebId , array_merge ([
2020-07-12 23:57:31 +12:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), []);
$this -> assertEquals ( 404 , $response [ 'headers' ][ 'status-code' ]);
2020-10-15 10:11:12 +13:00
$platformFultteriOSId = $data [ 'platformFultteriOSId' ] ? ? '' ;
2020-07-12 23:57:31 +12:00
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_DELETE , '/projects/' . $id . '/platforms/' . $platformFultteriOSId , array_merge ([
2020-07-12 23:57:31 +12:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), []);
$this -> assertEquals ( 204 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertEmpty ( $response [ 'body' ]);
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_GET , '/projects/' . $id . '/platforms/' . $platformFultteriOSId , array_merge ([
2020-07-12 23:57:31 +12:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), []);
$this -> assertEquals ( 404 , $response [ 'headers' ][ 'status-code' ]);
2020-10-15 10:11:12 +13:00
$platformFultterAndroidId = $data [ 'platformFultterAndroidId' ] ? ? '' ;
2020-07-12 23:57:31 +12:00
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_DELETE , '/projects/' . $id . '/platforms/' . $platformFultterAndroidId , array_merge ([
2020-07-12 23:57:31 +12:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), []);
$this -> assertEquals ( 204 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertEmpty ( $response [ 'body' ]);
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_GET , '/projects/' . $id . '/platforms/' . $platformFultterAndroidId , array_merge ([
2020-07-12 23:57:31 +12:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
2021-10-14 02:44:52 +13:00
], $this -> getHeaders ()), []);
$this -> assertEquals ( 404 , $response [ 'headers' ][ 'status-code' ]);
2023-01-12 12:38:09 +13:00
$platformFultterWebId = $data [ 'platformFultterWebId' ] ? ? '' ;
$response = $this -> client -> call ( Client :: METHOD_DELETE , '/projects/' . $id . '/platforms/' . $platformFultterWebId , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), []);
$this -> assertEquals ( 204 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertEmpty ( $response [ 'body' ]);
$response = $this -> client -> call ( Client :: METHOD_GET , '/projects/' . $id . '/platforms/' . $platformFultterWebId , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), []);
$this -> assertEquals ( 404 , $response [ 'headers' ][ 'status-code' ]);
2021-10-14 02:44:52 +13:00
$platformAppleIosId = $data [ 'platformAppleIosId' ] ? ? '' ;
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_DELETE , '/projects/' . $id . '/platforms/' . $platformAppleIosId , array_merge ([
2021-10-14 02:44:52 +13:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), []);
$this -> assertEquals ( 204 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertEmpty ( $response [ 'body' ]);
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_GET , '/projects/' . $id . '/platforms/' . $platformAppleIosId , array_merge ([
2021-10-14 02:44:52 +13:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), []);
$this -> assertEquals ( 404 , $response [ 'headers' ][ 'status-code' ]);
$platformAppleMacOsId = $data [ 'platformAppleMacOsId' ] ? ? '' ;
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_DELETE , '/projects/' . $id . '/platforms/' . $platformAppleMacOsId , array_merge ([
2021-10-14 02:44:52 +13:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), []);
$this -> assertEquals ( 204 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertEmpty ( $response [ 'body' ]);
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_GET , '/projects/' . $id . '/platforms/' . $platformAppleMacOsId , array_merge ([
2021-10-14 02:44:52 +13:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), []);
$this -> assertEquals ( 404 , $response [ 'headers' ][ 'status-code' ]);
$platformAppleWatchOsId = $data [ 'platformAppleWatchOsId' ] ? ? '' ;
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_DELETE , '/projects/' . $id . '/platforms/' . $platformAppleWatchOsId , array_merge ([
2021-10-14 02:44:52 +13:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), []);
$this -> assertEquals ( 204 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertEmpty ( $response [ 'body' ]);
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_GET , '/projects/' . $id . '/platforms/' . $platformAppleWatchOsId , array_merge ([
2021-10-14 02:44:52 +13:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), []);
$this -> assertEquals ( 404 , $response [ 'headers' ][ 'status-code' ]);
$platformAppleTvOsId = $data [ 'platformAppleTvOsId' ] ? ? '' ;
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_DELETE , '/projects/' . $id . '/platforms/' . $platformAppleTvOsId , array_merge ([
2021-10-14 02:44:52 +13:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), []);
$this -> assertEquals ( 204 , $response [ 'headers' ][ 'status-code' ]);
$this -> assertEmpty ( $response [ 'body' ]);
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_GET , '/projects/' . $id . '/platforms/' . $platformAppleTvOsId , array_merge ([
2021-10-14 02:44:52 +13:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
2020-07-12 23:57:31 +12:00
], $this -> getHeaders ()), []);
$this -> assertEquals ( 404 , $response [ 'headers' ][ 'status-code' ]);
/**
* Test for FAILURE
*/
2022-04-19 04:21:45 +12:00
$response = $this -> client -> call ( Client :: METHOD_DELETE , '/projects/' . $id . '/webhooks/error' , array_merge ([
2020-07-12 23:57:31 +12:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), []);
$this -> assertEquals ( 404 , $response [ 'headers' ][ 'status-code' ]);
return $data ;
}
2020-07-13 01:43:47 +12:00
2022-10-03 21:06:48 +13:00
public function testDeleteProject () : array
{
$data = [];
// Create a team and a project
$team = $this -> client -> call ( Client :: METHOD_POST , '/teams' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
'teamId' => ID :: unique (),
'name' => 'Amating Team' ,
]);
$this -> assertEquals ( 201 , $team [ 'headers' ][ 'status-code' ]);
$this -> assertEquals ( 'Amating Team' , $team [ 'body' ][ 'name' ]);
$this -> assertNotEmpty ( $team [ 'body' ][ '$id' ]);
$teamId = $team [ 'body' ][ '$id' ];
$project = $this -> client -> call ( Client :: METHOD_POST , '/projects' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
'projectId' => ID :: unique (),
'name' => 'Amazing Project' ,
'teamId' => $teamId ,
'region' => 'default'
]);
$this -> assertEquals ( 201 , $project [ 'headers' ][ 'status-code' ]);
$this -> assertEquals ( 'Amazing Project' , $project [ 'body' ][ 'name' ]);
$this -> assertEquals ( $teamId , $project [ 'body' ][ 'teamId' ]);
$this -> assertNotEmpty ( $project [ 'body' ][ '$id' ]);
$projectId = $project [ 'body' ][ '$id' ];
// Ensure I can get both team and project
$team = $this -> client -> call ( Client :: METHOD_GET , '/teams/' . $teamId , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()));
$this -> assertEquals ( 200 , $team [ 'headers' ][ 'status-code' ]);
$project = $this -> client -> call ( Client :: METHOD_GET , '/projects/' . $projectId , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()));
$this -> assertEquals ( 200 , $project [ 'headers' ][ 'status-code' ]);
2023-05-25 12:32:49 +12:00
// Delete Project
2023-05-25 13:26:13 +12:00
$project = $this -> client -> call ( Client :: METHOD_DELETE , '/projects/' . $projectId , array_merge ([
2022-10-03 21:06:48 +13:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
2023-05-25 12:32:49 +12:00
], $this -> getHeaders ()));
2022-10-03 21:06:48 +13:00
2023-05-25 12:32:49 +12:00
$this -> assertEquals ( 204 , $project [ 'headers' ][ 'status-code' ]);
2022-10-03 21:06:48 +13:00
// Ensure I can get team but not a project
$team = $this -> client -> call ( Client :: METHOD_GET , '/teams/' . $teamId , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()));
$this -> assertEquals ( 200 , $team [ 'headers' ][ 'status-code' ]);
$project = $this -> client -> call ( Client :: METHOD_GET , '/projects/' . $projectId , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()));
$this -> assertEquals ( 404 , $project [ 'headers' ][ 'status-code' ]);
return $data ;
}
2023-11-28 00:30:02 +13:00
public function testTenantIsolation () : void
{
// Create a team and a project
$team = $this -> client -> call ( Client :: METHOD_POST , '/teams' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
'teamId' => ID :: unique (),
'name' => 'Amazing Team' ,
]);
$teamId = $team [ 'body' ][ '$id' ];
// Project-level isolation
$project1 = $this -> client -> call ( Client :: METHOD_POST , '/projects' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
2024-05-07 17:59:24 +12:00
'x-appwrite-shared-tables' => false
2023-11-28 00:30:02 +13:00
], $this -> getHeaders ()), [
'projectId' => ID :: unique (),
'name' => 'Amazing Project' ,
'teamId' => $teamId ,
'region' => 'default'
]);
// Application level isolation (shared tables)
$project2 = $this -> client -> call ( Client :: METHOD_POST , '/projects' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
2024-05-07 17:59:24 +12:00
'x-appwrite-shared-tables' => true
2023-11-28 00:30:02 +13:00
], $this -> getHeaders ()), [
'projectId' => ID :: unique (),
'name' => 'Amazing Project' ,
'teamId' => $teamId ,
'region' => 'default'
]);
// Project-level isolation
$project3 = $this -> client -> call ( Client :: METHOD_POST , '/projects' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
2024-05-07 17:59:24 +12:00
'x-appwrite-shared-tables' => false
2023-11-28 00:30:02 +13:00
], $this -> getHeaders ()), [
'projectId' => ID :: unique (),
'name' => 'Amazing Project' ,
'teamId' => $teamId ,
'region' => 'default'
]);
// Application level isolation (shared tables)
$project4 = $this -> client -> call ( Client :: METHOD_POST , '/projects' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
2024-05-07 17:59:24 +12:00
'x-appwrite-shared-tables' => true
2023-11-28 00:30:02 +13:00
], $this -> getHeaders ()), [
'projectId' => ID :: unique (),
'name' => 'Amazing Project' ,
'teamId' => $teamId ,
'region' => 'default'
]);
// Create and API key in each project
$key1 = $this -> client -> call ( Client :: METHOD_POST , '/projects/' . $project1 [ 'body' ][ '$id' ] . '/keys' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
'name' => 'Key Test' ,
2024-05-07 18:11:30 +12:00
'scopes' => [ 'databases.read' , 'databases.write' , 'collections.read' , 'collections.write' , 'attributes.read' , 'attributes.write' , 'indexes.read' , 'indexes.write' , 'documents.read' , 'documents.write' , 'users.read' , 'users.write' ],
2023-11-28 00:30:02 +13:00
]);
$key2 = $this -> client -> call ( Client :: METHOD_POST , '/projects/' . $project2 [ 'body' ][ '$id' ] . '/keys' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
'name' => 'Key Test' ,
2024-05-07 18:11:30 +12:00
'scopes' => [ 'databases.read' , 'databases.write' , 'collections.read' , 'collections.write' , 'attributes.read' , 'attributes.write' , 'indexes.read' , 'indexes.write' , 'documents.read' , 'documents.write' , 'users.read' , 'users.write' ],
2023-11-28 00:30:02 +13:00
]);
$key3 = $this -> client -> call ( Client :: METHOD_POST , '/projects/' . $project3 [ 'body' ][ '$id' ] . '/keys' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
'name' => 'Key Test' ,
2024-05-07 18:11:30 +12:00
'scopes' => [ 'databases.read' , 'databases.write' , 'collections.read' , 'collections.write' , 'attributes.read' , 'attributes.write' , 'indexes.read' , 'indexes.write' , 'documents.read' , 'documents.write' , 'users.read' , 'users.write' ],
2023-11-28 00:30:02 +13:00
]);
$key4 = $this -> client -> call ( Client :: METHOD_POST , '/projects/' . $project4 [ 'body' ][ '$id' ] . '/keys' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
'name' => 'Key Test' ,
2024-05-07 18:11:30 +12:00
'scopes' => [ 'databases.read' , 'databases.write' , 'collections.read' , 'collections.write' , 'attributes.read' , 'attributes.write' , 'indexes.read' , 'indexes.write' , 'documents.read' , 'documents.write' , 'users.read' , 'users.write' ],
2023-11-28 00:30:02 +13:00
]);
// Create a database in each project
$database1 = $this -> client -> call ( Client :: METHOD_POST , '/databases' , [
'content-type' => 'application/json' ,
'x-appwrite-project' => $project1 [ 'body' ][ '$id' ],
'x-appwrite-key' => $key1 [ 'body' ][ 'secret' ]
], [
'databaseId' => ID :: unique (),
'name' => 'Amazing Database' ,
]);
$database2 = $this -> client -> call ( Client :: METHOD_POST , '/databases' , [
'content-type' => 'application/json' ,
'x-appwrite-project' => $project2 [ 'body' ][ '$id' ],
'x-appwrite-key' => $key2 [ 'body' ][ 'secret' ]
], [
'databaseId' => ID :: unique (),
'name' => 'Amazing Database' ,
]);
$database3 = $this -> client -> call ( Client :: METHOD_POST , '/databases' , [
'content-type' => 'application/json' ,
'x-appwrite-project' => $project3 [ 'body' ][ '$id' ],
'x-appwrite-key' => $key3 [ 'body' ][ 'secret' ]
], [
'databaseId' => ID :: unique (),
'name' => 'Amazing Database' ,
]);
$database4 = $this -> client -> call ( Client :: METHOD_POST , '/databases' , [
'content-type' => 'application/json' ,
'x-appwrite-project' => $project4 [ 'body' ][ '$id' ],
'x-appwrite-key' => $key4 [ 'body' ][ 'secret' ]
], [
'databaseId' => ID :: unique (),
'name' => 'Amazing Database' ,
]);
// Create a collection in each project
$collection1 = $this -> client -> call ( Client :: METHOD_POST , '/databases/' . $database1 [ 'body' ][ '$id' ] . '/collections' , [
'content-type' => 'application/json' ,
'x-appwrite-project' => $project1 [ 'body' ][ '$id' ],
'x-appwrite-key' => $key1 [ 'body' ][ 'secret' ]
], [
'databaseId' => $database1 [ 'body' ][ '$id' ],
'collectionId' => ID :: unique (),
'name' => 'Amazing Collection' ,
]);
$collection2 = $this -> client -> call ( Client :: METHOD_POST , '/databases/' . $database2 [ 'body' ][ '$id' ] . '/collections' , [
'content-type' => 'application/json' ,
'x-appwrite-project' => $project2 [ 'body' ][ '$id' ],
'x-appwrite-key' => $key2 [ 'body' ][ 'secret' ]
], [
'databaseId' => $database2 [ 'body' ][ '$id' ],
'collectionId' => ID :: unique (),
'name' => 'Amazing Collection' ,
]);
$collection3 = $this -> client -> call ( Client :: METHOD_POST , '/databases/' . $database3 [ 'body' ][ '$id' ] . '/collections' , [
'content-type' => 'application/json' ,
'x-appwrite-project' => $project3 [ 'body' ][ '$id' ],
'x-appwrite-key' => $key3 [ 'body' ][ 'secret' ]
], [
'databaseId' => $database3 [ 'body' ][ '$id' ],
'collectionId' => ID :: unique (),
'name' => 'Amazing Collection' ,
]);
$collection4 = $this -> client -> call ( Client :: METHOD_POST , '/databases/' . $database4 [ 'body' ][ '$id' ] . '/collections' , [
'content-type' => 'application/json' ,
'x-appwrite-project' => $project4 [ 'body' ][ '$id' ],
'x-appwrite-key' => $key4 [ 'body' ][ 'secret' ]
], [
'databaseId' => $database4 [ 'body' ][ '$id' ],
'collectionId' => ID :: unique (),
'name' => 'Amazing Collection' ,
]);
// Create an attribute in each project
$attribute1 = $this -> client -> call ( Client :: METHOD_POST , '/databases/' . $database1 [ 'body' ][ '$id' ] . '/collections/' . $collection1 [ 'body' ][ '$id' ] . '/attributes/string' , [
'content-type' => 'application/json' ,
'x-appwrite-project' => $project1 [ 'body' ][ '$id' ],
'x-appwrite-key' => $key1 [ 'body' ][ 'secret' ]
], [
'databaseId' => $database1 [ 'body' ][ '$id' ],
'collectionId' => $collection1 [ 'body' ][ '$id' ],
'key' => ID :: unique (),
'size' => 255 ,
'required' => true
]);
$attribute2 = $this -> client -> call ( Client :: METHOD_POST , '/databases/' . $database2 [ 'body' ][ '$id' ] . '/collections/' . $collection2 [ 'body' ][ '$id' ] . '/attributes/string' , [
'content-type' => 'application/json' ,
'x-appwrite-project' => $project2 [ 'body' ][ '$id' ],
'x-appwrite-key' => $key2 [ 'body' ][ 'secret' ]
], [
'databaseId' => $database2 [ 'body' ][ '$id' ],
'collectionId' => $collection2 [ 'body' ][ '$id' ],
'key' => ID :: unique (),
'size' => 255 ,
'required' => true
]);
$attribute3 = $this -> client -> call ( Client :: METHOD_POST , '/databases/' . $database3 [ 'body' ][ '$id' ] . '/collections/' . $collection3 [ 'body' ][ '$id' ] . '/attributes/string' , [
'content-type' => 'application/json' ,
'x-appwrite-project' => $project3 [ 'body' ][ '$id' ],
'x-appwrite-key' => $key3 [ 'body' ][ 'secret' ]
], [
'databaseId' => $database3 [ 'body' ][ '$id' ],
'collectionId' => $collection3 [ 'body' ][ '$id' ],
'key' => ID :: unique (),
'size' => 255 ,
'required' => true
]);
$attribute4 = $this -> client -> call ( Client :: METHOD_POST , '/databases/' . $database4 [ 'body' ][ '$id' ] . '/collections/' . $collection4 [ 'body' ][ '$id' ] . '/attributes/string' , [
'content-type' => 'application/json' ,
'x-appwrite-project' => $project4 [ 'body' ][ '$id' ],
'x-appwrite-key' => $key4 [ 'body' ][ 'secret' ]
], [
'databaseId' => $database4 [ 'body' ][ '$id' ],
'collectionId' => $collection4 [ 'body' ][ '$id' ],
'key' => ID :: unique (),
'size' => 255 ,
'required' => true
]);
// Wait for attributes
\sleep ( 2 );
// Create an index in each project
$index1 = $this -> client -> call ( Client :: METHOD_POST , '/databases/' . $database1 [ 'body' ][ '$id' ] . '/collections/' . $collection1 [ 'body' ][ '$id' ] . '/indexes' , [
'content-type' => 'application/json' ,
'x-appwrite-project' => $project1 [ 'body' ][ '$id' ],
'x-appwrite-key' => $key1 [ 'body' ][ 'secret' ]
], [
'databaseId' => $database1 [ 'body' ][ '$id' ],
'collectionId' => $collection1 [ 'body' ][ '$id' ],
'key' => ID :: unique (),
'type' => Database :: INDEX_KEY ,
'attributes' => [ $attribute1 [ 'body' ][ 'key' ]],
]);
$index2 = $this -> client -> call ( Client :: METHOD_POST , '/databases/' . $database2 [ 'body' ][ '$id' ] . '/collections/' . $collection2 [ 'body' ][ '$id' ] . '/indexes' , [
'content-type' => 'application/json' ,
'x-appwrite-project' => $project2 [ 'body' ][ '$id' ],
'x-appwrite-key' => $key2 [ 'body' ][ 'secret' ]
], [
'databaseId' => $database2 [ 'body' ][ '$id' ],
'collectionId' => $collection2 [ 'body' ][ '$id' ],
'key' => ID :: unique (),
'type' => Database :: INDEX_KEY ,
'attributes' => [ $attribute2 [ 'body' ][ 'key' ]],
]);
$index3 = $this -> client -> call ( Client :: METHOD_POST , '/databases/' . $database3 [ 'body' ][ '$id' ] . '/collections/' . $collection3 [ 'body' ][ '$id' ] . '/indexes' , [
'content-type' => 'application/json' ,
'x-appwrite-project' => $project3 [ 'body' ][ '$id' ],
'x-appwrite-key' => $key3 [ 'body' ][ 'secret' ]
], [
'databaseId' => $database3 [ 'body' ][ '$id' ],
'collectionId' => $collection3 [ 'body' ][ '$id' ],
'key' => ID :: unique (),
'type' => Database :: INDEX_KEY ,
'attributes' => [ $attribute3 [ 'body' ][ 'key' ]],
]);
$index4 = $this -> client -> call ( Client :: METHOD_POST , '/databases/' . $database4 [ 'body' ][ '$id' ] . '/collections/' . $collection4 [ 'body' ][ '$id' ] . '/indexes' , [
'content-type' => 'application/json' ,
'x-appwrite-project' => $project4 [ 'body' ][ '$id' ],
'x-appwrite-key' => $key4 [ 'body' ][ 'secret' ]
], [
'databaseId' => $database4 [ 'body' ][ '$id' ],
'collectionId' => $collection4 [ 'body' ][ '$id' ],
'key' => ID :: unique (),
'type' => Database :: INDEX_KEY ,
'attributes' => [ $attribute4 [ 'body' ][ 'key' ]],
]);
// Wait for indexes
\sleep ( 2 );
// Assert that each project has only 1 database, 1 collection, 1 attribute and 1 index
$databasesProject1 = $this -> client -> call ( Client :: METHOD_GET , '/databases' , [
'content-type' => 'application/json' ,
'x-appwrite-project' => $project1 [ 'body' ][ '$id' ],
'x-appwrite-key' => $key1 [ 'body' ][ 'secret' ]
]);
$this -> assertEquals ( 1 , $databasesProject1 [ 'body' ][ 'total' ]);
$this -> assertEquals ( 1 , \count ( $databasesProject1 [ 'body' ][ 'databases' ]));
$databasesProject2 = $this -> client -> call ( Client :: METHOD_GET , '/databases' , [
'content-type' => 'application/json' ,
'x-appwrite-project' => $project2 [ 'body' ][ '$id' ],
'x-appwrite-key' => $key2 [ 'body' ][ 'secret' ]
]);
$this -> assertEquals ( 1 , $databasesProject2 [ 'body' ][ 'total' ]);
$this -> assertEquals ( 1 , \count ( $databasesProject2 [ 'body' ][ 'databases' ]));
$databasesProject3 = $this -> client -> call ( Client :: METHOD_GET , '/databases' , [
'content-type' => 'application/json' ,
'x-appwrite-project' => $project3 [ 'body' ][ '$id' ],
'x-appwrite-key' => $key3 [ 'body' ][ 'secret' ]
]);
$this -> assertEquals ( 1 , $databasesProject3 [ 'body' ][ 'total' ]);
$this -> assertEquals ( 1 , \count ( $databasesProject3 [ 'body' ][ 'databases' ]));
$databasesProject4 = $this -> client -> call ( Client :: METHOD_GET , '/databases' , [
'content-type' => 'application/json' ,
'x-appwrite-project' => $project4 [ 'body' ][ '$id' ],
'x-appwrite-key' => $key4 [ 'body' ][ 'secret' ]
]);
$this -> assertEquals ( 1 , $databasesProject4 [ 'body' ][ 'total' ]);
$this -> assertEquals ( 1 , \count ( $databasesProject4 [ 'body' ][ 'databases' ]));
$collectionsProject1 = $this -> client -> call ( Client :: METHOD_GET , '/databases/' . $database1 [ 'body' ][ '$id' ] . '/collections' , [
'content-type' => 'application/json' ,
'x-appwrite-project' => $project1 [ 'body' ][ '$id' ],
'x-appwrite-key' => $key1 [ 'body' ][ 'secret' ]
]);
$this -> assertEquals ( 1 , $collectionsProject1 [ 'body' ][ 'total' ]);
$this -> assertEquals ( 1 , \count ( $collectionsProject1 [ 'body' ][ 'collections' ]));
$collectionsProject2 = $this -> client -> call ( Client :: METHOD_GET , '/databases/' . $database2 [ 'body' ][ '$id' ] . '/collections' , [
'content-type' => 'application/json' ,
'x-appwrite-project' => $project2 [ 'body' ][ '$id' ],
'x-appwrite-key' => $key2 [ 'body' ][ 'secret' ]
]);
$this -> assertEquals ( 1 , $collectionsProject2 [ 'body' ][ 'total' ]);
$this -> assertEquals ( 1 , \count ( $collectionsProject2 [ 'body' ][ 'collections' ]));
$collectionsProject3 = $this -> client -> call ( Client :: METHOD_GET , '/databases/' . $database3 [ 'body' ][ '$id' ] . '/collections' , [
'content-type' => 'application/json' ,
'x-appwrite-project' => $project3 [ 'body' ][ '$id' ],
'x-appwrite-key' => $key3 [ 'body' ][ 'secret' ]
]);
$this -> assertEquals ( 1 , $collectionsProject3 [ 'body' ][ 'total' ]);
$this -> assertEquals ( 1 , \count ( $collectionsProject3 [ 'body' ][ 'collections' ]));
$collectionsProject4 = $this -> client -> call ( Client :: METHOD_GET , '/databases/' . $database4 [ 'body' ][ '$id' ] . '/collections' , [
'content-type' => 'application/json' ,
'x-appwrite-project' => $project4 [ 'body' ][ '$id' ],
'x-appwrite-key' => $key4 [ 'body' ][ 'secret' ]
]);
$this -> assertEquals ( 1 , $collectionsProject4 [ 'body' ][ 'total' ]);
$this -> assertEquals ( 1 , \count ( $collectionsProject4 [ 'body' ][ 'collections' ]));
$attributesProject1 = $this -> client -> call ( Client :: METHOD_GET , '/databases/' . $database1 [ 'body' ][ '$id' ] . '/collections/' . $collection1 [ 'body' ][ '$id' ] . '/attributes' , [
'content-type' => 'application/json' ,
'x-appwrite-project' => $project1 [ 'body' ][ '$id' ],
'x-appwrite-key' => $key1 [ 'body' ][ 'secret' ]
]);
$this -> assertEquals ( 1 , $attributesProject1 [ 'body' ][ 'total' ]);
$this -> assertEquals ( 1 , \count ( $attributesProject1 [ 'body' ][ 'attributes' ]));
2024-05-08 16:28:00 +12:00
$this -> assertEquals ( 'available' , $attributesProject1 [ 'body' ][ 'attributes' ][ 0 ][ 'status' ]);
2023-11-28 00:30:02 +13:00
$attributesProject2 = $this -> client -> call ( Client :: METHOD_GET , '/databases/' . $database2 [ 'body' ][ '$id' ] . '/collections/' . $collection2 [ 'body' ][ '$id' ] . '/attributes' , [
'content-type' => 'application/json' ,
'x-appwrite-project' => $project2 [ 'body' ][ '$id' ],
'x-appwrite-key' => $key2 [ 'body' ][ 'secret' ]
]);
$this -> assertEquals ( 1 , $attributesProject2 [ 'body' ][ 'total' ]);
$this -> assertEquals ( 1 , \count ( $attributesProject2 [ 'body' ][ 'attributes' ]));
2024-05-08 16:28:00 +12:00
$this -> assertEquals ( 'available' , $attributesProject2 [ 'body' ][ 'attributes' ][ 0 ][ 'status' ]);
2023-11-28 00:30:02 +13:00
$attributesProject3 = $this -> client -> call ( Client :: METHOD_GET , '/databases/' . $database3 [ 'body' ][ '$id' ] . '/collections/' . $collection3 [ 'body' ][ '$id' ] . '/attributes' , [
'content-type' => 'application/json' ,
'x-appwrite-project' => $project3 [ 'body' ][ '$id' ],
'x-appwrite-key' => $key3 [ 'body' ][ 'secret' ]
]);
$this -> assertEquals ( 1 , $attributesProject3 [ 'body' ][ 'total' ]);
$this -> assertEquals ( 1 , \count ( $attributesProject3 [ 'body' ][ 'attributes' ]));
2024-05-08 16:28:00 +12:00
$this -> assertEquals ( 'available' , $attributesProject3 [ 'body' ][ 'attributes' ][ 0 ][ 'status' ]);
2023-11-28 00:30:02 +13:00
$attributesProject4 = $this -> client -> call ( Client :: METHOD_GET , '/databases/' . $database4 [ 'body' ][ '$id' ] . '/collections/' . $collection4 [ 'body' ][ '$id' ] . '/attributes' , [
'content-type' => 'application/json' ,
'x-appwrite-project' => $project4 [ 'body' ][ '$id' ],
'x-appwrite-key' => $key4 [ 'body' ][ 'secret' ]
]);
$this -> assertEquals ( 1 , $attributesProject4 [ 'body' ][ 'total' ]);
$this -> assertEquals ( 1 , \count ( $attributesProject4 [ 'body' ][ 'attributes' ]));
2024-05-08 16:28:00 +12:00
$this -> assertEquals ( 'available' , $attributesProject4 [ 'body' ][ 'attributes' ][ 0 ][ 'status' ]);
2023-11-28 00:30:02 +13:00
$indexesProject1 = $this -> client -> call ( Client :: METHOD_GET , '/databases/' . $database1 [ 'body' ][ '$id' ] . '/collections/' . $collection1 [ 'body' ][ '$id' ] . '/indexes' , [
'content-type' => 'application/json' ,
'x-appwrite-project' => $project1 [ 'body' ][ '$id' ],
'x-appwrite-key' => $key1 [ 'body' ][ 'secret' ]
]);
$this -> assertEquals ( 1 , $indexesProject1 [ 'body' ][ 'total' ]);
$this -> assertEquals ( 1 , \count ( $indexesProject1 [ 'body' ][ 'indexes' ]));
$indexesProject2 = $this -> client -> call ( Client :: METHOD_GET , '/databases/' . $database2 [ 'body' ][ '$id' ] . '/collections/' . $collection2 [ 'body' ][ '$id' ] . '/indexes' , [
'content-type' => 'application/json' ,
'x-appwrite-project' => $project2 [ 'body' ][ '$id' ],
'x-appwrite-key' => $key2 [ 'body' ][ 'secret' ]
]);
$this -> assertEquals ( 1 , $indexesProject2 [ 'body' ][ 'total' ]);
$this -> assertEquals ( 1 , \count ( $indexesProject2 [ 'body' ][ 'indexes' ]));
$indexesProject3 = $this -> client -> call ( Client :: METHOD_GET , '/databases/' . $database3 [ 'body' ][ '$id' ] . '/collections/' . $collection3 [ 'body' ][ '$id' ] . '/indexes' , [
'content-type' => 'application/json' ,
'x-appwrite-project' => $project3 [ 'body' ][ '$id' ],
'x-appwrite-key' => $key3 [ 'body' ][ 'secret' ]
]);
$this -> assertEquals ( 1 , $indexesProject3 [ 'body' ][ 'total' ]);
$this -> assertEquals ( 1 , \count ( $indexesProject3 [ 'body' ][ 'indexes' ]));
$indexesProject4 = $this -> client -> call ( Client :: METHOD_GET , '/databases/' . $database4 [ 'body' ][ '$id' ] . '/collections/' . $collection4 [ 'body' ][ '$id' ] . '/indexes' , [
'content-type' => 'application/json' ,
'x-appwrite-project' => $project4 [ 'body' ][ '$id' ],
'x-appwrite-key' => $key4 [ 'body' ][ 'secret' ]
]);
$this -> assertEquals ( 1 , $indexesProject4 [ 'body' ][ 'total' ]);
$this -> assertEquals ( 1 , \count ( $indexesProject4 [ 'body' ][ 'indexes' ]));
// Attempt to read cross-type resources
$collectionProject2WithProject1Key = $this -> client -> call ( Client :: METHOD_GET , '/databases/' . $database2 [ 'body' ][ '$id' ] . '/collections/' . $collection2 [ 'body' ][ '$id' ], [
'content-type' => 'application/json' ,
'x-appwrite-project' => $project1 [ 'body' ][ '$id' ],
'x-appwrite-key' => $key1 [ 'body' ][ 'secret' ]
]);
$this -> assertEquals ( 404 , $collectionProject2WithProject1Key [ 'headers' ][ 'status-code' ]);
$collectionProject1WithProject2Key = $this -> client -> call ( Client :: METHOD_GET , '/databases/' . $database1 [ 'body' ][ '$id' ] . '/collections/' . $collection1 [ 'body' ][ '$id' ], [
'content-type' => 'application/json' ,
'x-appwrite-project' => $project2 [ 'body' ][ '$id' ],
'x-appwrite-key' => $key2 [ 'body' ][ 'secret' ]
]);
$this -> assertEquals ( 404 , $collectionProject1WithProject2Key [ 'headers' ][ 'status-code' ]);
// Attempt to read cross-tenant resources
$collectionProject3WithProject1Key = $this -> client -> call ( Client :: METHOD_GET , '/databases/' . $database3 [ 'body' ][ '$id' ] . '/collections/' . $collection3 [ 'body' ][ '$id' ], [
'content-type' => 'application/json' ,
'x-appwrite-project' => $project1 [ 'body' ][ '$id' ],
'x-appwrite-key' => $key1 [ 'body' ][ 'secret' ]
]);
$this -> assertEquals ( 404 , $collectionProject3WithProject1Key [ 'headers' ][ 'status-code' ]);
$collectionProject1WithProject3Key = $this -> client -> call ( Client :: METHOD_GET , '/databases/' . $database1 [ 'body' ][ '$id' ] . '/collections/' . $collection1 [ 'body' ][ '$id' ], [
'content-type' => 'application/json' ,
'x-appwrite-project' => $project3 [ 'body' ][ '$id' ],
'x-appwrite-key' => $key3 [ 'body' ][ 'secret' ]
]);
$this -> assertEquals ( 404 , $collectionProject1WithProject3Key [ 'headers' ][ 'status-code' ]);
// Assert that shared project resources can have the same ID as they're unique on tenant + ID not just ID
$collection5 = $this -> client -> call ( Client :: METHOD_POST , '/databases/' . $database2 [ 'body' ][ '$id' ] . '/collections' , [
'content-type' => 'application/json' ,
'x-appwrite-project' => $project2 [ 'body' ][ '$id' ],
'x-appwrite-key' => $key2 [ 'body' ][ 'secret' ]
], [
'databaseId' => $database2 [ 'body' ][ '$id' ],
'collectionId' => $collection4 [ 'body' ][ '$id' ],
'name' => 'Amazing Collection' ,
]);
2024-05-07 19:53:20 +12:00
$this -> assertEquals ( 201 , $collection5 [ 'headers' ][ 'status-code' ]);
2024-05-01 16:17:02 +12:00
// Assert that users across projects on shared tables can have the same email as they're unique on tenant + email not just email
$user1 = $this -> client -> call ( Client :: METHOD_POST , '/users' , [
'content-type' => 'application/json' ,
'x-appwrite-project' => $project2 [ 'body' ][ '$id' ],
2024-05-07 18:11:30 +12:00
'x-appwrite-key' => $key2 [ 'body' ][ 'secret' ]
2024-05-01 16:17:02 +12:00
], [
'userId' => 'user' ,
2024-05-07 18:11:30 +12:00
'email' => 'test@appwrite.io' ,
2024-05-01 16:17:02 +12:00
'password' => 'password' ,
'name' => 'Test User' ,
]);
$this -> assertEquals ( 201 , $user1 [ 'headers' ][ 'status-code' ]);
$user2 = $this -> client -> call ( Client :: METHOD_POST , '/users' , [
'content-type' => 'application/json' ,
'x-appwrite-project' => $project4 [ 'body' ][ '$id' ],
2024-05-07 18:11:30 +12:00
'x-appwrite-key' => $key4 [ 'body' ][ 'secret' ]
2024-05-01 16:17:02 +12:00
], [
'userId' => 'user' ,
2024-05-07 18:11:30 +12:00
'email' => 'test@appwrite.io' ,
2024-05-01 16:17:02 +12:00
'password' => 'password' ,
'name' => 'Test User' ,
]);
$this -> assertEquals ( 201 , $user2 [ 'headers' ][ 'status-code' ]);
2023-11-28 00:30:02 +13:00
}
2020-07-12 07:40:58 +12:00
}