2020-11-20 12:35:16 +00:00
< ? php
namespace Tests\E2E\Services\Webhooks ;
2025-10-16 08:53:35 +00:00
use Appwrite\Tests\Async ;
2021-03-12 21:23:37 +00:00
use CURLFile ;
2020-11-23 15:04:02 +00:00
use Tests\E2E\Client ;
2020-11-20 12:35:16 +00:00
use Tests\E2E\Scopes\ProjectCustom ;
use Tests\E2E\Scopes\Scope ;
use Tests\E2E\Scopes\SideServer ;
2026-02-10 05:04:24 +00:00
use Utopia\Console ;
2023-02-05 20:07:46 +00:00
use Utopia\Database\Helpers\ID ;
use Utopia\Database\Helpers\Permission ;
use Utopia\Database\Helpers\Role ;
2023-03-01 12:00:36 +00:00
use Utopia\Database\Validator\Datetime as DatetimeValidator ;
2020-11-20 12:35:16 +00:00
class WebhooksCustomServerTest extends Scope
{
2025-10-16 08:53:35 +00:00
use Async ;
2020-11-20 12:35:16 +00:00
use WebhooksBase ;
use ProjectCustom ;
use SideServer ;
2020-11-23 15:04:02 +00:00
2025-05-10 05:31:36 +00:00
// Collection APIs
2020-11-30 21:41:58 +00:00
/**
2021-07-02 20:22:12 +00:00
* @ depends testCreateAttributes
2020-11-30 21:41:58 +00:00
*/
public function testUpdateCollection ( $data ) : array
{
2022-04-18 16:21:45 +00:00
$id = $data [ 'actorsId' ];
2022-06-22 10:51:49 +00:00
$databaseId = $data [ 'databaseId' ];
2022-04-18 16:21:45 +00:00
2020-11-30 21:41:58 +00:00
/**
* Test for SUCCESS
*/
2022-06-22 10:51:49 +00:00
$actors = $this -> client -> call ( Client :: METHOD_PUT , '/databases/' . $databaseId . '/collections/' . $id , array_merge ([
2020-11-30 21:41:58 +00:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
'x-appwrite-key' => $this -> getProject ()[ 'apiKey' ]
]), [
'name' => 'Actors1' ,
2022-08-03 04:17:49 +00:00
'documentSecurity' => true ,
2020-11-30 21:41:58 +00:00
]);
2022-04-18 16:21:45 +00:00
2025-05-10 05:31:36 +00:00
$this -> assertEquals ( 200 , $actors [ 'headers' ][ 'status-code' ]);
2020-11-30 21:41:58 +00:00
$this -> assertNotEmpty ( $actors [ 'body' ][ '$id' ]);
$webhook = $this -> getLastRequest ();
2022-06-08 07:19:50 +00:00
$signatureExpected = self :: getWebhookSignature ( $webhook , $this -> getProject ()[ 'signatureKey' ]);
2020-11-30 21:41:58 +00:00
2025-05-10 05:31:36 +00:00
$this -> assertEquals ( 'POST' , $webhook [ 'method' ]);
$this -> assertEquals ( 'application/json' , $webhook [ 'headers' ][ 'Content-Type' ]);
$this -> assertEquals ( 'Appwrite-Server vdev. Please report abuse at security@appwrite.io' , $webhook [ 'headers' ][ 'User-Agent' ]);
2025-05-09 09:40:44 +00:00
$this -> assertStringContainsString ( 'databases.' . $databaseId . '.collections.*' , $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Events' ]);
$this -> assertStringContainsString ( 'databases.' . $databaseId . '.collections.*.update' , $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Events' ]);
$this -> assertStringContainsString ( " databases. { $databaseId } .collections. { $id } " , $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Events' ]);
$this -> assertStringContainsString ( " databases. { $databaseId } .collections. { $id } .update " , $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Events' ]);
2022-06-07 16:02:39 +00:00
$this -> assertEquals ( $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Signature' ], $signatureExpected );
2020-12-03 17:56:07 +00:00
$this -> assertEquals ( $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Id' ] ? ? '' , $this -> getProject ()[ 'webhookId' ]);
$this -> assertEquals ( $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Project-Id' ] ? ? '' , $this -> getProject ()[ '$id' ]);
2025-05-10 05:31:36 +00:00
$this -> assertTrue ( empty ( $webhook [ 'headers' ][ 'X-Appwrite-Webhook-User-Id' ] ? ? '' ));
2020-11-30 21:41:58 +00:00
$this -> assertNotEmpty ( $webhook [ 'data' ][ '$id' ]);
2025-05-10 05:31:36 +00:00
$this -> assertEquals ( 'Actors1' , $webhook [ 'data' ][ 'name' ]);
2022-08-02 09:21:53 +00:00
$this -> assertIsArray ( $webhook [ 'data' ][ '$permissions' ]);
2022-08-13 14:10:28 +00:00
$this -> assertCount ( 4 , $webhook [ 'data' ][ '$permissions' ]);
2020-11-30 21:41:58 +00:00
return array_merge ([ 'actorsId' => $actors [ 'body' ][ '$id' ]]);
}
2021-07-02 22:48:58 +00:00
/**
* @ depends testCreateAttributes
*/
public function testCreateDeleteIndexes ( $data ) : array
{
2022-04-18 16:21:45 +00:00
$actorsId = $data [ 'actorsId' ];
2022-06-22 10:51:49 +00:00
$databaseId = $data [ 'databaseId' ];
2022-04-18 16:21:45 +00:00
2022-06-22 10:51:49 +00:00
$index = $this -> client -> call ( Client :: METHOD_POST , '/databases/' . $databaseId . '/collections/' . $data [ 'actorsId' ] . '/indexes' , array_merge ([
2021-07-02 22:48:58 +00:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
'x-appwrite-key' => $this -> getProject ()[ 'apiKey' ]
]), [
2021-12-16 16:10:01 +00:00
'key' => 'fullname' ,
2021-08-03 20:22:31 +00:00
'type' => 'key' ,
2025-05-09 09:40:44 +00:00
'attributes' => [ 'lastName' , 'firstName' ],
2021-07-02 22:48:58 +00:00
'orders' => [ 'ASC' , 'ASC' ],
]);
2022-04-18 16:21:45 +00:00
$indexKey = $index [ 'body' ][ 'key' ];
2025-05-10 05:31:36 +00:00
$this -> assertEquals ( 202 , $index [ 'headers' ][ 'status-code' ]);
$this -> assertEquals ( 'fullname' , $index [ 'body' ][ 'key' ]);
2021-07-02 22:48:58 +00:00
// wait for database worker to create index
2025-10-16 08:53:35 +00:00
$this -> assertEventually ( function () use ( $databaseId , $actorsId ) {
$webhook = $this -> getLastRequest ();
$signatureExpected = self :: getWebhookSignature ( $webhook , $this -> getProject ()[ 'signatureKey' ]);
$this -> assertEquals ( 'POST' , $webhook [ 'method' ]);
$this -> assertEquals ( 'application/json' , $webhook [ 'headers' ][ 'Content-Type' ]);
$this -> assertEquals ( 'Appwrite-Server vdev. Please report abuse at security@appwrite.io' , $webhook [ 'headers' ][ 'User-Agent' ]);
$this -> assertStringContainsString ( 'databases.' . $databaseId . '.collections.*' , $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Events' ]);
$this -> assertStringContainsString ( 'databases.' . $databaseId . '.collections.*.indexes.*' , $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Events' ]);
$this -> assertStringContainsString ( 'databases.' . $databaseId . '.collections.*.indexes.*.create' , $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Events' ]);
$this -> assertStringContainsString ( " databases. { $databaseId } .collections. { $actorsId } " , $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Events' ]);
$this -> assertStringContainsString ( " databases. { $databaseId } .collections. { $actorsId } .indexes.* " , $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Events' ]);
$this -> assertStringContainsString ( " databases. { $databaseId } .collections. { $actorsId } .indexes.*.create " , $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Events' ]);
$this -> assertEquals ( $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Signature' ], $signatureExpected );
$this -> assertEquals ( $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Id' ] ? ? '' , $this -> getProject ()[ 'webhookId' ]);
$this -> assertEquals ( $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Project-Id' ] ? ? '' , $this -> getProject ()[ '$id' ]);
$this -> assertTrue ( empty ( $webhook [ 'headers' ][ 'X-Appwrite-Webhook-User-Id' ] ? ? '' ));
}, 10000 , 500 );
2021-07-02 22:48:58 +00:00
// Remove index
2022-06-22 10:51:49 +00:00
$this -> client -> call ( Client :: METHOD_DELETE , '/databases/' . $databaseId . '/collections/' . $data [ 'actorsId' ] . '/indexes/' . $index [ 'body' ][ 'key' ], array_merge ([
2021-10-26 01:14:30 +00:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
'x-appwrite-key' => $this -> getProject ()[ 'apiKey' ]
]));
2021-07-05 18:29:21 +00:00
// // wait for database worker to remove index
2021-10-26 01:14:30 +00:00
$webhook = $this -> getLastRequest ();
2022-06-08 07:19:50 +00:00
$signatureExpected = self :: getWebhookSignature ( $webhook , $this -> getProject ()[ 'signatureKey' ]);
2021-07-05 18:29:21 +00:00
2021-10-26 01:14:30 +00:00
// $this->assertEquals($webhook['method'], 'DELETE');
2025-05-10 05:31:36 +00:00
$this -> assertEquals ( 'application/json' , $webhook [ 'headers' ][ 'Content-Type' ]);
$this -> assertEquals ( 'Appwrite-Server vdev. Please report abuse at security@appwrite.io' , $webhook [ 'headers' ][ 'User-Agent' ]);
2025-05-09 09:40:44 +00:00
$this -> assertStringContainsString ( 'databases.' . $databaseId . '.collections.*' , $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Events' ]);
$this -> assertStringContainsString ( 'databases.' . $databaseId . '.collections.*.indexes.*' , $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Events' ]);
$this -> assertStringContainsString ( 'databases.' . $databaseId . '.collections.*.indexes.*.update' , $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Events' ]);
$this -> assertStringContainsString ( " databases. { $databaseId } .collections. { $actorsId } " , $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Events' ]);
$this -> assertStringContainsString ( " databases. { $databaseId } .collections. { $actorsId } .indexes.* " , $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Events' ]);
$this -> assertStringContainsString ( " databases. { $databaseId } .collections. { $actorsId } .indexes.*.update " , $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Events' ]);
2022-06-07 16:02:39 +00:00
$this -> assertEquals ( $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Signature' ], $signatureExpected );
2021-10-26 01:14:30 +00:00
$this -> assertEquals ( $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Id' ] ? ? '' , $this -> getProject ()[ 'webhookId' ]);
$this -> assertEquals ( $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Project-Id' ] ? ? '' , $this -> getProject ()[ '$id' ]);
2025-05-10 05:31:36 +00:00
$this -> assertTrue ( empty ( $webhook [ 'headers' ][ 'X-Appwrite-Webhook-User-Id' ] ? ? '' ));
2021-07-02 22:48:58 +00:00
return $data ;
}
2020-11-30 21:41:58 +00:00
public function testDeleteCollection () : array
{
2022-06-22 10:51:49 +00:00
/**
* Create database
*/
$database = $this -> client -> call ( Client :: METHOD_POST , '/databases' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
'x-appwrite-key' => $this -> getProject ()[ 'apiKey' ]
], $this -> getHeaders ()), [
2022-08-14 10:33:36 +00:00
'databaseId' => ID :: unique (),
2022-06-22 10:51:49 +00:00
'name' => 'Actors DB' ,
]);
$databaseId = $database [ 'body' ][ '$id' ];
2020-11-30 21:41:58 +00:00
/**
* Test for SUCCESS
*/
2022-06-22 10:51:49 +00:00
$actors = $this -> client -> call ( Client :: METHOD_POST , '/databases/' . $databaseId . '/collections' , array_merge ([
2020-11-30 21:41:58 +00:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
'x-appwrite-key' => $this -> getProject ()[ 'apiKey' ]
]), [
2025-05-09 09:40:44 +00:00
'collectionId' => ID :: unique (),
2020-11-30 21:41:58 +00:00
'name' => 'Demo' ,
2022-08-03 04:17:49 +00:00
'permissions' => [
2022-08-14 05:21:11 +00:00
Permission :: read ( Role :: any ()),
Permission :: create ( Role :: any ()),
Permission :: update ( Role :: any ()),
Permission :: delete ( Role :: any ()),
2022-08-03 04:17:49 +00:00
],
'documentSecurity' => true ,
2020-11-30 21:41:58 +00:00
]);
2021-12-16 16:10:01 +00:00
2022-04-18 16:21:45 +00:00
$id = $actors [ 'body' ][ '$id' ];
2025-05-10 05:31:36 +00:00
$this -> assertEquals ( 201 , $actors [ 'headers' ][ 'status-code' ]);
2020-11-30 21:41:58 +00:00
$this -> assertNotEmpty ( $actors [ 'body' ][ '$id' ]);
2022-06-22 10:51:49 +00:00
$actors = $this -> client -> call ( Client :: METHOD_DELETE , '/databases/' . $databaseId . '/collections/' . $actors [ 'body' ][ '$id' ], array_merge ([
2020-11-30 21:41:58 +00:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
'x-appwrite-key' => $this -> getProject ()[ 'apiKey' ]
]), []);
2021-12-16 16:10:01 +00:00
2025-05-10 05:31:36 +00:00
$this -> assertEquals ( 204 , $actors [ 'headers' ][ 'status-code' ]);
2020-11-30 21:41:58 +00:00
$webhook = $this -> getLastRequest ();
2022-06-08 07:19:50 +00:00
$signatureExpected = self :: getWebhookSignature ( $webhook , $this -> getProject ()[ 'signatureKey' ]);
2020-11-30 21:41:58 +00:00
2025-05-10 05:31:36 +00:00
$this -> assertEquals ( 'POST' , $webhook [ 'method' ]);
$this -> assertEquals ( 'application/json' , $webhook [ 'headers' ][ 'Content-Type' ]);
$this -> assertEquals ( 'Appwrite-Server vdev. Please report abuse at security@appwrite.io' , $webhook [ 'headers' ][ 'User-Agent' ]);
2025-05-09 09:40:44 +00:00
$this -> assertStringContainsString ( 'databases.' . $databaseId . '.collections.*' , $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Events' ]);
$this -> assertStringContainsString ( 'databases.' . $databaseId . '.collections.*.delete' , $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Events' ]);
$this -> assertStringContainsString ( " databases. { $databaseId } .collections. { $id } " , $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Events' ]);
$this -> assertStringContainsString ( " databases. { $databaseId } .collections. { $id } .delete " , $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Events' ]);
2022-06-07 16:02:39 +00:00
$this -> assertEquals ( $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Signature' ], $signatureExpected );
2020-12-03 17:56:07 +00:00
$this -> assertEquals ( $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Id' ] ? ? '' , $this -> getProject ()[ 'webhookId' ]);
$this -> assertEquals ( $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Project-Id' ] ? ? '' , $this -> getProject ()[ '$id' ]);
2025-05-10 05:31:36 +00:00
$this -> assertTrue ( empty ( $webhook [ 'headers' ][ 'X-Appwrite-Webhook-User-Id' ] ? ? '' ));
2020-11-30 21:41:58 +00:00
$this -> assertNotEmpty ( $webhook [ 'data' ][ '$id' ]);
2025-05-10 05:31:36 +00:00
$this -> assertEquals ( 'Demo' , $webhook [ 'data' ][ 'name' ]);
$this -> assertIsArray ( $webhook [ 'data' ][ '$permissions' ]);
$this -> assertCount ( 4 , $webhook [ 'data' ][ '$permissions' ]);
return [];
}
// Table APIs
/**
* @ depends testCreateColumns
*/
public function testUpdateTable ( $data ) : array
{
$id = $data [ 'actorsId' ];
$databaseId = $data [ 'databaseId' ];
/**
* Test for SUCCESS
*/
2025-08-18 09:16:01 +00:00
$actors = $this -> client -> call ( Client :: METHOD_PUT , '/tablesdb/' . $databaseId . '/tables/' . $id , array_merge ([
2025-05-10 05:31:36 +00:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
'x-appwrite-key' => $this -> getProject ()[ 'apiKey' ]
]), [
'name' => 'Actors1' ,
'rowSecurity' => true ,
]);
$this -> assertEquals ( 200 , $actors [ 'headers' ][ 'status-code' ]);
$this -> assertNotEmpty ( $actors [ 'body' ][ '$id' ]);
$webhook = $this -> getLastRequest ();
$signatureExpected = self :: getWebhookSignature ( $webhook , $this -> getProject ()[ 'signatureKey' ]);
$this -> assertEquals ( 'POST' , $webhook [ 'method' ]);
$this -> assertEquals ( 'application/json' , $webhook [ 'headers' ][ 'Content-Type' ]);
$this -> assertEquals ( 'Appwrite-Server vdev. Please report abuse at security@appwrite.io' , $webhook [ 'headers' ][ 'User-Agent' ]);
$this -> assertStringContainsString ( 'databases.' . $databaseId . '.tables.*' , $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Events' ]);
$this -> assertStringContainsString ( 'databases.' . $databaseId . '.tables.*.update' , $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Events' ]);
$this -> assertStringContainsString ( " databases. { $databaseId } .tables. { $id } " , $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Events' ]);
$this -> assertStringContainsString ( " databases. { $databaseId } .tables. { $id } .update " , $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Events' ]);
$this -> assertEquals ( $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Signature' ], $signatureExpected );
$this -> assertEquals ( $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Id' ] ? ? '' , $this -> getProject ()[ 'webhookId' ]);
$this -> assertEquals ( $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Project-Id' ] ? ? '' , $this -> getProject ()[ '$id' ]);
$this -> assertEmpty ( $webhook [ 'headers' ][ 'X-Appwrite-Webhook-User-Id' ] ? ? '' );
$this -> assertNotEmpty ( $webhook [ 'data' ][ '$id' ]);
$this -> assertEquals ( 'Actors1' , $webhook [ 'data' ][ 'name' ]);
$this -> assertIsArray ( $webhook [ 'data' ][ '$permissions' ]);
$this -> assertCount ( 4 , $webhook [ 'data' ][ '$permissions' ]);
return array_merge ([ 'actorsId' => $actors [ 'body' ][ '$id' ]]);
}
/**
* @ depends testCreateColumns
*/
public function testCreateDeleteColumnIndexes ( $data ) : array
{
$actorsId = $data [ 'actorsId' ];
$databaseId = $data [ 'databaseId' ];
2025-08-18 09:16:01 +00:00
$index = $this -> client -> call ( Client :: METHOD_POST , '/tablesdb/' . $databaseId . '/tables/' . $data [ 'actorsId' ] . '/indexes' , array_merge ([
2025-05-10 05:31:36 +00:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
'x-appwrite-key' => $this -> getProject ()[ 'apiKey' ]
]), [
'key' => 'fullname' ,
'type' => 'key' ,
'columns' => [ 'lastName' , 'firstName' ],
'orders' => [ 'ASC' , 'ASC' ],
]);
$this -> assertEquals ( 202 , $index [ 'headers' ][ 'status-code' ]);
$this -> assertEquals ( 'fullname' , $index [ 'body' ][ 'key' ]);
// wait for database worker to create index
2025-10-16 08:53:35 +00:00
$this -> assertEventually ( function () use ( $databaseId , $actorsId ) {
$webhook = $this -> getLastRequest ();
$signatureExpected = self :: getWebhookSignature ( $webhook , $this -> getProject ()[ 'signatureKey' ]);
$this -> assertEquals ( 'POST' , $webhook [ 'method' ]);
$this -> assertEquals ( 'application/json' , $webhook [ 'headers' ][ 'Content-Type' ]);
$this -> assertEquals ( 'Appwrite-Server vdev. Please report abuse at security@appwrite.io' , $webhook [ 'headers' ][ 'User-Agent' ]);
$this -> assertStringContainsString ( 'databases.' . $databaseId . '.tables.*' , $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Events' ]);
$this -> assertStringContainsString ( 'databases.' . $databaseId . '.tables.*.indexes.*' , $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Events' ]);
$this -> assertStringContainsString ( 'databases.' . $databaseId . '.tables.*.indexes.*.create' , $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Events' ]);
$this -> assertStringContainsString ( " databases. { $databaseId } .tables. { $actorsId } " , $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Events' ]);
$this -> assertStringContainsString ( " databases. { $databaseId } .tables. { $actorsId } .indexes.* " , $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Events' ]);
$this -> assertStringContainsString ( " databases. { $databaseId } .tables. { $actorsId } .indexes.*.create " , $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Events' ]);
$this -> assertEquals ( $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Signature' ], $signatureExpected );
$this -> assertEquals ( $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Id' ] ? ? '' , $this -> getProject ()[ 'webhookId' ]);
$this -> assertEquals ( $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Project-Id' ] ? ? '' , $this -> getProject ()[ '$id' ]);
$this -> assertTrue ( empty ( $webhook [ 'headers' ][ 'X-Appwrite-Webhook-User-Id' ] ? ? '' ));
}, 10000 , 500 );
2025-05-10 05:31:36 +00:00
// Remove index
2025-08-18 09:16:01 +00:00
$this -> client -> call ( Client :: METHOD_DELETE , '/tablesdb/' . $databaseId . '/tables/' . $data [ 'actorsId' ] . '/indexes/' . $index [ 'body' ][ 'key' ], array_merge ([
2025-05-10 05:31:36 +00:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
'x-appwrite-key' => $this -> getProject ()[ 'apiKey' ]
]));
// // wait for database worker to remove index
$webhook = $this -> getLastRequest ();
$signatureExpected = self :: getWebhookSignature ( $webhook , $this -> getProject ()[ 'signatureKey' ]);
// $this->assertEquals($webhook['method'], 'DELETE');
$this -> assertEquals ( 'application/json' , $webhook [ 'headers' ][ 'Content-Type' ]);
$this -> assertEquals ( 'Appwrite-Server vdev. Please report abuse at security@appwrite.io' , $webhook [ 'headers' ][ 'User-Agent' ]);
$this -> assertStringContainsString ( 'databases.' . $databaseId . '.tables.*' , $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Events' ]);
$this -> assertStringContainsString ( 'databases.' . $databaseId . '.tables.*.indexes.*' , $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Events' ]);
$this -> assertStringContainsString ( 'databases.' . $databaseId . '.tables.*.indexes.*.update' , $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Events' ]);
$this -> assertStringContainsString ( " databases. { $databaseId } .tables. { $actorsId } " , $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Events' ]);
$this -> assertStringContainsString ( " databases. { $databaseId } .tables. { $actorsId } .indexes.* " , $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Events' ]);
$this -> assertStringContainsString ( " databases. { $databaseId } .tables. { $actorsId } .indexes.*.update " , $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Events' ]);
$this -> assertEquals ( $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Signature' ], $signatureExpected );
$this -> assertEquals ( $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Id' ] ? ? '' , $this -> getProject ()[ 'webhookId' ]);
$this -> assertEquals ( $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Project-Id' ] ? ? '' , $this -> getProject ()[ '$id' ]);
$this -> assertTrue ( empty ( $webhook [ 'headers' ][ 'X-Appwrite-Webhook-User-Id' ] ? ? '' ));
return $data ;
}
public function testDeleteTable () : array
{
/**
* Create database
*/
$database = $this -> client -> call ( Client :: METHOD_POST , '/databases' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
'x-appwrite-key' => $this -> getProject ()[ 'apiKey' ]
], $this -> getHeaders ()), [
'databaseId' => ID :: unique (),
'name' => 'Actors DB' ,
]);
$databaseId = $database [ 'body' ][ '$id' ];
/**
* Test for SUCCESS
*/
2025-08-18 09:16:01 +00:00
$actors = $this -> client -> call ( Client :: METHOD_POST , '/tablesdb/' . $databaseId . '/tables' , array_merge ([
2025-05-10 05:31:36 +00:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
'x-appwrite-key' => $this -> getProject ()[ 'apiKey' ]
]), [
'tableId' => ID :: unique (),
'name' => 'Demo' ,
'permissions' => [
Permission :: read ( Role :: any ()),
Permission :: create ( Role :: any ()),
Permission :: update ( Role :: any ()),
Permission :: delete ( Role :: any ()),
],
'rowSecurity' => true ,
]);
$id = $actors [ 'body' ][ '$id' ];
$this -> assertEquals ( 201 , $actors [ 'headers' ][ 'status-code' ]);
$this -> assertNotEmpty ( $actors [ 'body' ][ '$id' ]);
2025-08-18 09:16:01 +00:00
$actors = $this -> client -> call ( Client :: METHOD_DELETE , '/tablesdb/' . $databaseId . '/tables/' . $actors [ 'body' ][ '$id' ], array_merge ([
2025-05-10 05:31:36 +00:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
'x-appwrite-key' => $this -> getProject ()[ 'apiKey' ]
]));
$this -> assertEquals ( 204 , $actors [ 'headers' ][ 'status-code' ]);
$webhook = $this -> getLastRequest ();
$signatureExpected = self :: getWebhookSignature ( $webhook , $this -> getProject ()[ 'signatureKey' ]);
$this -> assertEquals ( 'POST' , $webhook [ 'method' ]);
$this -> assertEquals ( 'application/json' , $webhook [ 'headers' ][ 'Content-Type' ]);
$this -> assertEquals ( 'Appwrite-Server vdev. Please report abuse at security@appwrite.io' , $webhook [ 'headers' ][ 'User-Agent' ]);
$this -> assertStringContainsString ( 'databases.' . $databaseId . '.tables.*' , $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Events' ]);
$this -> assertStringContainsString ( 'databases.' . $databaseId . '.tables.*.delete' , $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Events' ]);
$this -> assertStringContainsString ( " databases. { $databaseId } .tables. { $id } " , $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Events' ]);
$this -> assertStringContainsString ( " databases. { $databaseId } .tables. { $id } .delete " , $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Events' ]);
$this -> assertEquals ( $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Signature' ], $signatureExpected );
$this -> assertEquals ( $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Id' ] ? ? '' , $this -> getProject ()[ 'webhookId' ]);
$this -> assertEquals ( $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Project-Id' ] ? ? '' , $this -> getProject ()[ '$id' ]);
$this -> assertEmpty ( $webhook [ 'headers' ][ 'X-Appwrite-Webhook-User-Id' ] ? ? '' );
$this -> assertNotEmpty ( $webhook [ 'data' ][ '$id' ]);
$this -> assertEquals ( 'Demo' , $webhook [ 'data' ][ 'name' ]);
2022-08-02 09:21:53 +00:00
$this -> assertIsArray ( $webhook [ 'data' ][ '$permissions' ]);
2022-08-13 14:10:28 +00:00
$this -> assertCount ( 4 , $webhook [ 'data' ][ '$permissions' ]);
2020-11-30 21:41:58 +00:00
2020-12-01 18:53:31 +00:00
return [];
2020-11-30 21:41:58 +00:00
}
2022-04-18 16:21:45 +00:00
public function testCreateUser () : array
2020-11-23 15:04:02 +00:00
{
2022-04-18 16:21:45 +00:00
$email = uniqid () . 'user@localhost.test' ;
2020-11-23 15:04:02 +00:00
$password = 'password' ;
$name = 'User Name' ;
/**
* Test for SUCCESS
*/
$user = $this -> client -> call ( Client :: METHOD_POST , '/users' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
2022-08-14 10:33:36 +00:00
'userId' => ID :: unique (),
2020-11-23 15:04:02 +00:00
'email' => $email ,
'password' => $password ,
'name' => $name ,
]);
2025-05-10 05:31:36 +00:00
$this -> assertEquals ( 201 , $user [ 'headers' ][ 'status-code' ]);
2020-11-23 15:04:02 +00:00
$this -> assertNotEmpty ( $user [ 'body' ][ '$id' ]);
$id = $user [ 'body' ][ '$id' ];
$webhook = $this -> getLastRequest ();
2022-06-08 07:19:50 +00:00
$signatureExpected = self :: getWebhookSignature ( $webhook , $this -> getProject ()[ 'signatureKey' ]);
2020-11-23 15:04:02 +00:00
2025-05-10 05:31:36 +00:00
$this -> assertEquals ( 'POST' , $webhook [ 'method' ]);
$this -> assertEquals ( 'application/json' , $webhook [ 'headers' ][ 'Content-Type' ]);
$this -> assertEquals ( 'Appwrite-Server vdev. Please report abuse at security@appwrite.io' , $webhook [ 'headers' ][ 'User-Agent' ]);
2022-05-10 13:25:49 +00:00
$this -> assertStringContainsString ( 'users.*' , $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Events' ]);
$this -> assertStringContainsString ( 'users.*.create' , $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Events' ]);
2022-06-02 12:14:58 +00:00
$this -> assertStringContainsString ( " users. { $id } " , $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Events' ]);
2022-05-10 13:25:49 +00:00
$this -> assertStringContainsString ( " users. { $id } .create " , $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Events' ]);
2022-06-07 16:02:39 +00:00
$this -> assertEquals ( $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Signature' ], $signatureExpected );
2020-12-03 17:56:07 +00:00
$this -> assertEquals ( $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Id' ] ? ? '' , $this -> getProject ()[ 'webhookId' ]);
$this -> assertEquals ( $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Project-Id' ] ? ? '' , $this -> getProject ()[ '$id' ]);
$this -> assertEquals ( empty ( $webhook [ 'headers' ][ 'X-Appwrite-Webhook-User-Id' ] ? ? '' ), ( 'server' === $this -> getSide ()));
2020-11-23 15:04:02 +00:00
$this -> assertNotEmpty ( $webhook [ 'data' ][ '$id' ]);
$this -> assertEquals ( $webhook [ 'data' ][ 'name' ], $name );
2025-05-10 05:31:36 +00:00
$this -> assertTrue (( new DatetimeValidator ()) -> isValid ( $webhook [ 'data' ][ 'registration' ]));
$this -> assertTrue ( $webhook [ 'data' ][ 'status' ]);
2020-11-23 15:04:02 +00:00
$this -> assertEquals ( $webhook [ 'data' ][ 'email' ], $email );
2025-05-10 05:31:36 +00:00
$this -> assertFalse ( $webhook [ 'data' ][ 'emailVerification' ]);
$this -> assertEquals ([], $webhook [ 'data' ][ 'prefs' ]);
2020-11-23 15:04:02 +00:00
/**
* Test for FAILURE
*/
return [ 'userId' => $user [ 'body' ][ '$id' ], 'name' => $user [ 'body' ][ 'name' ], 'email' => $user [ 'body' ][ 'email' ]];
}
2021-03-04 18:47:02 +00:00
2022-04-18 16:21:45 +00:00
/**
2020-11-23 15:04:02 +00:00
* @ depends testCreateUser
*/
2022-04-18 16:21:45 +00:00
public function testUpdateUserPrefs ( array $data ) : array
2021-03-04 18:47:02 +00:00
{
2022-04-18 16:21:45 +00:00
$id = $data [ 'userId' ];
2021-03-04 18:47:02 +00:00
/**
* Test for SUCCESS
*/
2022-04-18 16:21:45 +00:00
$user = $this -> client -> call ( Client :: METHOD_PATCH , '/users/' . $id . '/prefs' , array_merge ([
2021-03-04 18:47:02 +00:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
2021-03-07 13:09:45 +00:00
'prefs' => [ 'a' => 'b' ]
2021-03-04 18:47:02 +00:00
]);
2025-05-10 05:31:36 +00:00
$this -> assertEquals ( 200 , $user [ 'headers' ][ 'status-code' ]);
$this -> assertEquals ( 'b' , $user [ 'body' ][ 'a' ]);
2021-03-08 20:48:45 +00:00
2021-03-04 18:47:02 +00:00
$webhook = $this -> getLastRequest ();
2022-06-08 07:19:50 +00:00
$signatureExpected = self :: getWebhookSignature ( $webhook , $this -> getProject ()[ 'signatureKey' ]);
2021-03-04 18:47:02 +00:00
2025-05-10 05:31:36 +00:00
$this -> assertEquals ( 'POST' , $webhook [ 'method' ]);
$this -> assertEquals ( 'application/json' , $webhook [ 'headers' ][ 'Content-Type' ]);
$this -> assertEquals ( 'Appwrite-Server vdev. Please report abuse at security@appwrite.io' , $webhook [ 'headers' ][ 'User-Agent' ]);
2022-05-10 13:25:49 +00:00
$this -> assertStringContainsString ( 'users.*' , $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Events' ]);
$this -> assertStringContainsString ( 'users.*.update' , $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Events' ]);
$this -> assertStringContainsString ( 'users.*.update.prefs' , $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Events' ]);
$this -> assertStringContainsString ( " users. { $id } " , $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Events' ]);
$this -> assertStringContainsString ( " users. { $id } .update " , $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Events' ]);
$this -> assertStringContainsString ( " users. { $id } .update.prefs " , $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Events' ]);
2022-06-07 16:02:39 +00:00
$this -> assertEquals ( $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Signature' ], $signatureExpected );
2021-03-04 18:47:02 +00:00
$this -> assertEquals ( $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Id' ] ? ? '' , $this -> getProject ()[ 'webhookId' ]);
$this -> assertEquals ( $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Project-Id' ] ? ? '' , $this -> getProject ()[ '$id' ]);
$this -> assertEquals ( empty ( $webhook [ 'headers' ][ 'X-Appwrite-Webhook-User-Id' ] ? ? '' ), ( 'server' === $this -> getSide ()));
2025-05-10 05:31:36 +00:00
$this -> assertEquals ( 'b' , $webhook [ 'data' ][ 'a' ]);
2021-03-04 18:47:02 +00:00
return $data ;
}
2020-11-23 15:04:02 +00:00
/**
2021-03-08 15:16:28 +00:00
* @ depends testUpdateUserPrefs
2020-11-23 15:04:02 +00:00
*/
2022-04-18 16:21:45 +00:00
public function testUpdateUserStatus ( array $data ) : array
2020-11-23 15:04:02 +00:00
{
2022-04-18 16:21:45 +00:00
$id = $data [ 'userId' ];
2020-11-23 15:04:02 +00:00
/**
* Test for SUCCESS
*/
$user = $this -> client -> call ( Client :: METHOD_PATCH , '/users/' . $data [ 'userId' ] . '/status' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
2021-07-14 11:02:12 +00:00
'status' => false ,
2020-11-23 15:04:02 +00:00
]);
2025-05-10 05:31:36 +00:00
$this -> assertEquals ( 200 , $user [ 'headers' ][ 'status-code' ]);
2020-11-23 15:04:02 +00:00
$this -> assertNotEmpty ( $user [ 'body' ][ '$id' ]);
$webhook = $this -> getLastRequest ();
2022-06-08 07:19:50 +00:00
$signatureExpected = self :: getWebhookSignature ( $webhook , $this -> getProject ()[ 'signatureKey' ]);
2020-11-23 15:04:02 +00:00
2025-05-10 05:31:36 +00:00
$this -> assertEquals ( 'POST' , $webhook [ 'method' ]);
$this -> assertEquals ( 'application/json' , $webhook [ 'headers' ][ 'Content-Type' ]);
$this -> assertEquals ( 'Appwrite-Server vdev. Please report abuse at security@appwrite.io' , $webhook [ 'headers' ][ 'User-Agent' ]);
2022-05-10 13:25:49 +00:00
$this -> assertStringContainsString ( 'users.*' , $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Events' ]);
$this -> assertStringContainsString ( 'users.*.update' , $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Events' ]);
$this -> assertStringContainsString ( 'users.*.update.status' , $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Events' ]);
$this -> assertStringContainsString ( " users. { $id } " , $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Events' ]);
$this -> assertStringContainsString ( " users. { $id } .update " , $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Events' ]);
$this -> assertStringContainsString ( " users. { $id } .update.status " , $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Events' ]);
2022-06-07 16:02:39 +00:00
$this -> assertEquals ( $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Signature' ], $signatureExpected );
2020-12-03 17:56:07 +00:00
$this -> assertEquals ( $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Id' ] ? ? '' , $this -> getProject ()[ 'webhookId' ]);
$this -> assertEquals ( $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Project-Id' ] ? ? '' , $this -> getProject ()[ '$id' ]);
$this -> assertEquals ( empty ( $webhook [ 'headers' ][ 'X-Appwrite-Webhook-User-Id' ] ? ? '' ), ( 'server' === $this -> getSide ()));
2020-11-23 15:04:02 +00:00
$this -> assertNotEmpty ( $webhook [ 'data' ][ '$id' ]);
$this -> assertEquals ( $webhook [ 'data' ][ 'name' ], $data [ 'name' ]);
2025-05-10 05:31:36 +00:00
$this -> assertTrue (( new DatetimeValidator ()) -> isValid ( $webhook [ 'data' ][ 'registration' ]));
$this -> assertFalse ( $webhook [ 'data' ][ 'status' ]);
2020-11-23 15:04:02 +00:00
$this -> assertEquals ( $webhook [ 'data' ][ 'email' ], $data [ 'email' ]);
2025-05-10 05:31:36 +00:00
$this -> assertFalse ( $webhook [ 'data' ][ 'emailVerification' ]);
$this -> assertEquals ( 'b' , $webhook [ 'data' ][ 'prefs' ][ 'a' ]);
2020-11-23 15:04:02 +00:00
return $data ;
}
2022-04-18 16:21:45 +00:00
2020-11-23 15:04:02 +00:00
/**
* @ depends testUpdateUserStatus
*/
2022-04-18 16:21:45 +00:00
public function testDeleteUser ( array $data ) : array
2020-11-23 15:04:02 +00:00
{
2022-04-18 16:21:45 +00:00
$id = $data [ 'userId' ];
2020-11-23 15:04:02 +00:00
/**
* Test for SUCCESS
*/
$user = $this -> client -> call ( Client :: METHOD_DELETE , '/users/' . $data [ 'userId' ], array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()));
2025-05-10 05:31:36 +00:00
$this -> assertEquals ( 204 , $user [ 'headers' ][ 'status-code' ]);
2020-11-23 15:04:02 +00:00
$webhook = $this -> getLastRequest ();
2022-06-08 07:19:50 +00:00
$signatureExpected = self :: getWebhookSignature ( $webhook , $this -> getProject ()[ 'signatureKey' ]);
2020-11-23 15:04:02 +00:00
2025-05-10 05:31:36 +00:00
$this -> assertEquals ( 'POST' , $webhook [ 'method' ]);
$this -> assertEquals ( 'application/json' , $webhook [ 'headers' ][ 'Content-Type' ]);
$this -> assertEquals ( 'Appwrite-Server vdev. Please report abuse at security@appwrite.io' , $webhook [ 'headers' ][ 'User-Agent' ]);
2022-05-10 13:25:49 +00:00
$this -> assertStringContainsString ( 'users.*' , $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Events' ]);
$this -> assertStringContainsString ( 'users.*.delete' , $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Events' ]);
$this -> assertStringContainsString ( " users. { $id } " , $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Events' ]);
$this -> assertStringContainsString ( " users. { $id } .delete " , $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Events' ]);
2022-06-07 16:02:39 +00:00
$this -> assertEquals ( $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Signature' ], $signatureExpected );
2020-12-03 17:56:07 +00:00
$this -> assertEquals ( $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Id' ] ? ? '' , $this -> getProject ()[ 'webhookId' ]);
$this -> assertEquals ( $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Project-Id' ] ? ? '' , $this -> getProject ()[ '$id' ]);
$this -> assertEquals ( empty ( $webhook [ 'headers' ][ 'X-Appwrite-Webhook-User-Id' ] ? ? '' ), ( 'server' === $this -> getSide ()));
2020-11-23 15:04:02 +00:00
$this -> assertNotEmpty ( $webhook [ 'data' ][ '$id' ]);
$this -> assertEquals ( $webhook [ 'data' ][ 'name' ], $data [ 'name' ]);
2025-05-10 05:31:36 +00:00
$this -> assertTrue (( new DatetimeValidator ()) -> isValid ( $webhook [ 'data' ][ 'registration' ]));
$this -> assertFalse ( $webhook [ 'data' ][ 'status' ]);
2020-11-23 15:04:02 +00:00
$this -> assertEquals ( $webhook [ 'data' ][ 'email' ], $data [ 'email' ]);
2025-05-10 05:31:36 +00:00
$this -> assertFalse ( $webhook [ 'data' ][ 'emailVerification' ]);
$this -> assertEquals ( 'b' , $webhook [ 'data' ][ 'prefs' ][ 'a' ]);
2020-11-23 15:04:02 +00:00
return $data ;
}
2021-03-12 21:23:37 +00:00
2022-04-18 16:21:45 +00:00
public function testCreateFunction () : array
2021-03-12 21:23:37 +00:00
{
/**
* Test for SUCCESS
*/
$function = $this -> client -> call ( Client :: METHOD_POST , '/functions' , array_merge ([
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
2022-08-14 10:33:36 +00:00
'functionId' => ID :: unique (),
2021-03-12 21:23:37 +00:00
'name' => 'Test' ,
2022-08-19 04:04:33 +00:00
'execute' => [ Role :: any () -> toString ()],
2025-07-10 12:43:56 +00:00
'runtime' => 'node-22' ,
'entrypoint' => 'index.js' ,
2021-03-12 21:23:37 +00:00
'timeout' => 10 ,
]);
2022-04-18 16:21:45 +00:00
$id = $function [ 'body' ][ '$id' ] ? ? '' ;
2021-03-12 21:23:37 +00:00
2025-05-10 05:31:36 +00:00
$this -> assertEquals ( 201 , $function [ 'headers' ][ 'status-code' ]);
2021-03-12 21:23:37 +00:00
$this -> assertNotEmpty ( $function [ 'body' ][ '$id' ]);
$webhook = $this -> getLastRequest ();
2022-06-08 07:19:50 +00:00
$signatureExpected = self :: getWebhookSignature ( $webhook , $this -> getProject ()[ 'signatureKey' ]);
2021-03-12 21:23:37 +00:00
2025-05-10 05:31:36 +00:00
$this -> assertEquals ( 'POST' , $webhook [ 'method' ]);
$this -> assertEquals ( 'application/json' , $webhook [ 'headers' ][ 'Content-Type' ]);
$this -> assertEquals ( 'Appwrite-Server vdev. Please report abuse at security@appwrite.io' , $webhook [ 'headers' ][ 'User-Agent' ]);
2022-06-07 16:02:39 +00:00
$this -> assertEquals ( $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Signature' ], $signatureExpected );
2021-03-12 21:23:37 +00:00
$this -> assertEquals ( $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Id' ] ? ? '' , $this -> getProject ()[ 'webhookId' ]);
$this -> assertEquals ( $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Project-Id' ] ? ? '' , $this -> getProject ()[ '$id' ]);
return [
2022-04-18 16:21:45 +00:00
'functionId' => $id ,
2021-03-12 21:23:37 +00:00
];
}
/**
* @ depends testCreateFunction
*/
2022-04-18 16:21:45 +00:00
public function testUpdateFunction ( $data ) : array
2021-03-12 22:48:15 +00:00
{
2022-04-18 16:21:45 +00:00
$id = $data [ 'functionId' ];
/**
* Test for SUCCESS
*/
$function = $this -> client -> call ( Client :: METHOD_PUT , '/functions/' . $data [ 'functionId' ], array_merge ([
2021-03-12 22:48:15 +00:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
'name' => 'Test' ,
2025-07-10 12:43:56 +00:00
'runtime' => 'node-22' ,
'entrypoint' => 'index.js' ,
2022-08-19 04:04:33 +00:00
'execute' => [ Role :: any () -> toString ()],
2021-03-12 22:48:15 +00:00
'vars' => [
'key1' => 'value1' ,
]
]);
2025-05-10 05:31:36 +00:00
$this -> assertEquals ( 200 , $function [ 'headers' ][ 'status-code' ]);
2021-03-12 22:48:15 +00:00
$this -> assertEquals ( $function [ 'body' ][ '$id' ], $data [ 'functionId' ]);
2022-08-03 13:32:50 +00:00
// Create variable
2022-08-09 15:29:24 +00:00
$variable = $this -> client -> call ( Client :: METHOD_POST , '/functions/' . $data [ 'functionId' ] . '/variables' , array_merge ([
2022-08-03 13:32:50 +00:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
'key' => 'key1' ,
'value' => 'value1' ,
]);
2022-08-03 13:35:11 +00:00
2022-08-03 13:32:50 +00:00
$this -> assertEquals ( 201 , $variable [ 'headers' ][ 'status-code' ]);
2021-03-12 22:48:15 +00:00
$webhook = $this -> getLastRequest ();
2022-06-08 07:19:50 +00:00
$signatureExpected = self :: getWebhookSignature ( $webhook , $this -> getProject ()[ 'signatureKey' ]);
2021-03-12 22:48:15 +00:00
2025-05-10 05:31:36 +00:00
$this -> assertEquals ( 'POST' , $webhook [ 'method' ]);
$this -> assertEquals ( 'application/json' , $webhook [ 'headers' ][ 'Content-Type' ]);
$this -> assertEquals ( 'Appwrite-Server vdev. Please report abuse at security@appwrite.io' , $webhook [ 'headers' ][ 'User-Agent' ]);
2023-06-15 11:06:04 +00:00
// $this->assertStringContainsString('functions.*', $webhook['headers']['X-Appwrite-Webhook-Events']);
// $this->assertStringContainsString('functions.*.update', $webhook['headers']['X-Appwrite-Webhook-Events']);
// $this->assertStringContainsString("functions.{$id}", $webhook['headers']['X-Appwrite-Webhook-Events']);
// $this->assertStringContainsString("functions.{$id}.update", $webhook['headers']['X-Appwrite-Webhook-Events']); TODO @christyjacob4 : enable test once we allow functions.* events
2022-06-07 16:02:39 +00:00
$this -> assertEquals ( $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Signature' ], $signatureExpected );
2021-03-12 22:48:15 +00:00
$this -> assertEquals ( $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Id' ] ? ? '' , $this -> getProject ()[ 'webhookId' ]);
$this -> assertEquals ( $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Project-Id' ] ? ? '' , $this -> getProject ()[ '$id' ]);
return $data ;
}
2022-04-18 16:21:45 +00:00
2021-03-12 22:48:15 +00:00
/**
* @ depends testUpdateFunction
*/
2022-04-18 16:21:45 +00:00
public function testCreateDeployment ( $data ) : array
2021-03-12 21:23:37 +00:00
{
/**
* Test for SUCCESS
*/
2024-10-08 07:54:40 +00:00
$stderr = '' ;
$stdout = '' ;
2022-02-21 12:46:40 +00:00
$folder = 'timeout' ;
2022-04-18 16:21:45 +00:00
$code = realpath ( __DIR__ . '/../../../resources/functions' ) . " / { $folder } /code.tar.gz " ;
2024-10-08 07:54:40 +00:00
Console :: execute ( 'cd ' . realpath ( __DIR__ . " /../../../resources/functions " ) . " / { $folder } && tar --exclude code.tar.gz -czf code.tar.gz . " , '' , $stdout , $stderr );
2022-02-21 12:46:40 +00:00
2022-04-18 16:21:45 +00:00
$deployment = $this -> client -> call ( Client :: METHOD_POST , '/functions/' . $data [ 'functionId' ] . '/deployments' , array_merge ([
2021-03-12 21:23:37 +00:00
'content-type' => 'multipart/form-data' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()), [
2025-07-10 12:43:56 +00:00
'entrypoint' => 'index.js' ,
2023-03-01 12:00:36 +00:00
'code' => new CURLFile ( $code , 'application/x-gzip' , \basename ( $code )),
'activate' => true
2021-03-12 21:23:37 +00:00
]);
2024-08-22 12:15:38 +00:00
$functionId = $data [ 'functionId' ] ? ? '' ;
2022-01-24 23:48:51 +00:00
$deploymentId = $deployment [ 'body' ][ '$id' ] ? ? '' ;
2021-03-12 21:23:37 +00:00
2025-05-10 05:31:36 +00:00
$this -> assertEquals ( 202 , $deployment [ 'headers' ][ 'status-code' ]);
2022-01-24 23:48:51 +00:00
$this -> assertNotEmpty ( $deployment [ 'body' ][ '$id' ]);
2021-03-12 21:23:37 +00:00
$webhook = $this -> getLastRequest ();
2022-06-08 07:19:50 +00:00
$signatureExpected = self :: getWebhookSignature ( $webhook , $this -> getProject ()[ 'signatureKey' ]);
2021-03-12 21:23:37 +00:00
2025-05-10 05:31:36 +00:00
$this -> assertEquals ( 'POST' , $webhook [ 'method' ]);
$this -> assertEquals ( 'application/json' , $webhook [ 'headers' ][ 'Content-Type' ]);
$this -> assertEquals ( 'Appwrite-Server vdev. Please report abuse at security@appwrite.io' , $webhook [ 'headers' ][ 'User-Agent' ]);
2023-06-15 11:06:04 +00:00
// $this->assertStringContainsString('functions.*', $webhook['headers']['X-Appwrite-Webhook-Events']);
// $this->assertStringContainsString('functions.*.deployments.*', $webhook['headers']['X-Appwrite-Webhook-Events']);
// $this->assertStringContainsString("functions.*.deployments.{$deploymentId}", $webhook['headers']['X-Appwrite-Webhook-Events']);
// $this->assertStringContainsString("functions.{$id}", $webhook['headers']['X-Appwrite-Webhook-Events']);
// $this->assertStringContainsString("functions.{$id}.deployments.*", $webhook['headers']['X-Appwrite-Webhook-Events']);
// $this->assertStringContainsString("functions.{$id}.deployments.{$deploymentId}", $webhook['headers']['X-Appwrite-Webhook-Events']); TODO @christyjacob4 : enable test once we allow functions.* events
2022-06-07 16:02:39 +00:00
$this -> assertEquals ( $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Signature' ], $signatureExpected );
2021-03-12 21:23:37 +00:00
$this -> assertEquals ( $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Id' ] ? ? '' , $this -> getProject ()[ 'webhookId' ]);
$this -> assertEquals ( $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Project-Id' ] ? ? '' , $this -> getProject ()[ '$id' ]);
2024-08-22 12:15:38 +00:00
$this -> awaitDeploymentIsBuilt ( $functionId , $deploymentId );
2021-03-12 21:23:37 +00:00
2022-01-24 23:48:51 +00:00
return array_merge ( $data , [ 'deploymentId' => $deploymentId ]);
2021-03-12 21:23:37 +00:00
}
/**
2022-01-24 23:48:51 +00:00
* @ depends testCreateDeployment
2021-03-12 21:23:37 +00:00
*/
2022-04-18 16:21:45 +00:00
public function testUpdateDeployment ( $data ) : array
2021-03-12 21:23:37 +00:00
{
2022-04-18 16:21:45 +00:00
$id = $data [ 'functionId' ] ? ? '' ;
$deploymentId = $data [ 'deploymentId' ] ? ? '' ;
2021-03-12 21:23:37 +00:00
/**
* Test for SUCCESS
*/
2022-04-18 16:21:45 +00:00
$response = $this -> client -> call ( Client :: METHOD_PATCH , '/functions/' . $id . '/deployments/' . $deploymentId , array_merge ([
2021-03-12 21:23:37 +00:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
2022-02-15 09:16:32 +00:00
], $this -> getHeaders ()), []);
2021-03-12 21:23:37 +00:00
2025-05-10 05:31:36 +00:00
$this -> assertEquals ( 200 , $response [ 'headers' ][ 'status-code' ]);
2021-03-12 21:23:37 +00:00
$this -> assertNotEmpty ( $response [ 'body' ][ '$id' ]);
2022-01-24 23:48:51 +00:00
// Wait for deployment to be built.
2025-10-16 08:53:35 +00:00
$this -> assertEventually ( function () use ( $deploymentId , $id ) {
$webhook = $this -> getLastRequest ();
$signatureExpected = self :: getWebhookSignature ( $webhook , $this -> getProject ()[ 'signatureKey' ]);
$this -> assertEquals ( 'POST' , $webhook [ 'method' ]);
$this -> assertEquals ( 'application/json' , $webhook [ 'headers' ][ 'Content-Type' ]);
$this -> assertEquals ( 'Appwrite-Server vdev. Please report abuse at security@appwrite.io' , $webhook [ 'headers' ][ 'User-Agent' ]);
// $this->assertStringContainsString('functions.*', $webhook['headers']['X-Appwrite-Webhook-Events']);
// $this->assertStringContainsString('functions.*.deployments.*', $webhook['headers']['X-Appwrite-Webhook-Events']);
// $this->assertStringContainsString('functions.*.deployments.*.update', $webhook['headers']['X-Appwrite-Webhook-Events']);
// $this->assertStringContainsString("functions.*.deployments.{$deploymentId}", $webhook['headers']['X-Appwrite-Webhook-Events']);
// $this->assertStringContainsString("functions.*.deployments.{$deploymentId}.update", $webhook['headers']['X-Appwrite-Webhook-Events']);
// $this->assertStringContainsString("functions.{$id}", $webhook['headers']['X-Appwrite-Webhook-Events']);
// $this->assertStringContainsString("functions.{$id}.deployments.*", $webhook['headers']['X-Appwrite-Webhook-Events']);
// $this->assertStringContainsString("functions.{$id}.deployments.*.update", $webhook['headers']['X-Appwrite-Webhook-Events']);
// $this->assertStringContainsString("functions.{$id}.deployments.{$deploymentId}", $webhook['headers']['X-Appwrite-Webhook-Events']);
// $this->assertStringContainsString("functions.{$id}.deployments.{$deploymentId}.update", $webhook['headers']['X-Appwrite-Webhook-Events']); TODO @christyjacob4 : enable test once we allow functions.* events
$this -> assertEquals ( $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Signature' ], $signatureExpected );
$this -> assertEquals ( $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Id' ] ? ? '' , $this -> getProject ()[ 'webhookId' ]);
$this -> assertEquals ( $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Project-Id' ] ? ? '' , $this -> getProject ()[ '$id' ]);
}, 10000 , 500 );
2021-03-12 21:23:37 +00:00
/**
2022-06-02 12:14:58 +00:00
* Test for FAILURE
2021-03-12 21:23:37 +00:00
*/
return $data ;
}
/**
2022-01-24 23:48:51 +00:00
* @ depends testUpdateDeployment
2021-03-12 21:23:37 +00:00
*/
2022-04-18 16:21:45 +00:00
public function testExecutions ( $data ) : array
2021-03-12 21:23:37 +00:00
{
2022-04-18 16:21:45 +00:00
$id = $data [ 'functionId' ] ? ? '' ;
2021-03-12 21:23:37 +00:00
/**
* Test for SUCCESS
*/
2022-04-18 16:21:45 +00:00
$execution = $this -> client -> call ( Client :: METHOD_POST , '/functions/' . $id . '/executions' , array_merge ([
2021-03-12 21:55:01 +00:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
2022-09-07 08:24:49 +00:00
], $this -> getHeaders ()), [
'async' => true
]);
2021-03-12 21:55:01 +00:00
2022-04-18 16:21:45 +00:00
$executionId = $execution [ 'body' ][ '$id' ] ? ? '' ;
2025-05-10 05:31:36 +00:00
$this -> assertEquals ( 202 , $execution [ 'headers' ][ 'status-code' ]);
2021-03-12 21:55:01 +00:00
$this -> assertNotEmpty ( $execution [ 'body' ][ '$id' ]);
$webhook = $this -> getLastRequest ();
2022-06-08 07:19:50 +00:00
$signatureExpected = self :: getWebhookSignature ( $webhook , $this -> getProject ()[ 'signatureKey' ]);
2025-05-10 05:31:36 +00:00
$this -> assertEquals ( 'POST' , $webhook [ 'method' ]);
$this -> assertEquals ( 'application/json' , $webhook [ 'headers' ][ 'Content-Type' ]);
$this -> assertEquals ( 'Appwrite-Server vdev. Please report abuse at security@appwrite.io' , $webhook [ 'headers' ][ 'User-Agent' ]);
2023-06-15 11:06:04 +00:00
// $this->assertStringContainsString('functions.*', $webhook['headers']['X-Appwrite-Webhook-Events']);
// $this->assertStringContainsString('functions.*.executions.*', $webhook['headers']['X-Appwrite-Webhook-Events']);
// $this->assertStringContainsString('functions.*.executions.*.create', $webhook['headers']['X-Appwrite-Webhook-Events']);
// $this->assertStringContainsString("functions.*.executions.{$executionId}", $webhook['headers']['X-Appwrite-Webhook-Events']);
// $this->assertStringContainsString("functions.*.executions.{$executionId}.create", $webhook['headers']['X-Appwrite-Webhook-Events']);
// $this->assertStringContainsString("functions.{$id}", $webhook['headers']['X-Appwrite-Webhook-Events']);
// $this->assertStringContainsString("functions.{$id}.executions.*", $webhook['headers']['X-Appwrite-Webhook-Events']);
// $this->assertStringContainsString("functions.{$id}.executions.*.create", $webhook['headers']['X-Appwrite-Webhook-Events']);
// $this->assertStringContainsString("functions.{$id}.executions.{$executionId}", $webhook['headers']['X-Appwrite-Webhook-Events']);
// $this->assertStringContainsString("functions.{$id}.executions.{$executionId}.create", $webhook['headers']['X-Appwrite-Webhook-Events']); TODO @christyjacob4 : enable test once we allow functions.* events
2022-06-07 16:02:39 +00:00
$this -> assertEquals ( $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Signature' ], $signatureExpected );
2021-03-12 21:55:01 +00:00
$this -> assertEquals ( $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Id' ] ? ? '' , $this -> getProject ()[ 'webhookId' ]);
$this -> assertEquals ( $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Project-Id' ] ? ? '' , $this -> getProject ()[ '$id' ]);
2022-04-18 16:21:45 +00:00
// wait for timeout function to complete
2025-10-16 08:53:35 +00:00
$this -> assertEventually ( function () use ( $executionId , $id ) {
$webhook = $this -> getLastRequest ();
$signatureExpected = self :: getWebhookSignature ( $webhook , $this -> getProject ()[ 'signatureKey' ]);
$this -> assertEquals ( 'POST' , $webhook [ 'method' ]);
$this -> assertEquals ( 'application/json' , $webhook [ 'headers' ][ 'Content-Type' ]);
$this -> assertEquals ( 'Appwrite-Server vdev. Please report abuse at security@appwrite.io' , $webhook [ 'headers' ][ 'User-Agent' ]);
// $this->assertStringContainsString('functions.*', $webhook['headers']['X-Appwrite-Webhook-Events']);
// $this->assertStringContainsString('functions.*.executions.*', $webhook['headers']['X-Appwrite-Webhook-Events']);
// $this->assertStringContainsString('functions.*.executions.*.update', $webhook['headers']['X-Appwrite-Webhook-Events']);
// $this->assertStringContainsString("functions.*.executions.{$executionId}", $webhook['headers']['X-Appwrite-Webhook-Events']);
// $this->assertStringContainsString("functions.*.executions.{$executionId}.update", $webhook['headers']['X-Appwrite-Webhook-Events']);
// $this->assertStringContainsString("functions.{$id}", $webhook['headers']['X-Appwrite-Webhook-Events']);
// $this->assertStringContainsString("functions.{$id}.executions.*", $webhook['headers']['X-Appwrite-Webhook-Events']);
// $this->assertStringContainsString("functions.{$id}.executions.*.update", $webhook['headers']['X-Appwrite-Webhook-Events']);
// $this->assertStringContainsString("functions.{$id}.executions.{$executionId}", $webhook['headers']['X-Appwrite-Webhook-Events']);
// $this->assertStringContainsString("functions.{$id}.executions.{$executionId}.update", $webhook['headers']['X-Appwrite-Webhook-Events']); TODO @christyjacob4 : enable test once we allow functions.* events
$this -> assertEquals ( $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Signature' ], $signatureExpected );
$this -> assertEquals ( $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Id' ] ? ? '' , $this -> getProject ()[ 'webhookId' ]);
$this -> assertEquals ( $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Project-Id' ] ? ? '' , $this -> getProject ()[ '$id' ]);
}, 30000 , 1000 );
2021-03-12 21:55:01 +00:00
2021-03-12 21:23:37 +00:00
/**
2022-06-02 12:14:58 +00:00
* Test for FAILURE
2021-03-12 21:23:37 +00:00
*/
2021-03-12 22:13:44 +00:00
return $data ;
}
/**
2022-06-02 12:14:58 +00:00
* @ depends testExecutions
2021-03-12 22:13:44 +00:00
*/
2022-04-18 16:21:45 +00:00
public function testDeleteDeployment ( $data ) : array
2021-03-12 22:13:44 +00:00
{
2022-04-18 16:21:45 +00:00
$id = $data [ 'functionId' ] ? ? '' ;
$deploymentId = $data [ 'deploymentId' ] ? ? '' ;
2021-03-12 22:13:44 +00:00
/**
* Test for SUCCESS
*/
2022-04-18 16:21:45 +00:00
$deployment = $this -> client -> call ( Client :: METHOD_DELETE , '/functions/' . $id . '/deployments/' . $deploymentId , array_merge ([
2021-03-12 22:13:44 +00:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()));
2025-05-10 05:31:36 +00:00
$this -> assertEquals ( 204 , $deployment [ 'headers' ][ 'status-code' ]);
2022-01-24 23:48:51 +00:00
$this -> assertEmpty ( $deployment [ 'body' ]);
2021-03-12 22:13:44 +00:00
$webhook = $this -> getLastRequest ();
2022-06-08 07:19:50 +00:00
$signatureExpected = self :: getWebhookSignature ( $webhook , $this -> getProject ()[ 'signatureKey' ]);
2021-03-12 22:13:44 +00:00
2025-05-10 05:31:36 +00:00
$this -> assertEquals ( 'POST' , $webhook [ 'method' ]);
$this -> assertEquals ( 'application/json' , $webhook [ 'headers' ][ 'Content-Type' ]);
$this -> assertEquals ( 'Appwrite-Server vdev. Please report abuse at security@appwrite.io' , $webhook [ 'headers' ][ 'User-Agent' ]);
2023-06-15 11:06:04 +00:00
// $this->assertStringContainsString('functions.*', $webhook['headers']['X-Appwrite-Webhook-Events']);
// $this->assertStringContainsString('functions.*.deployments.*', $webhook['headers']['X-Appwrite-Webhook-Events']);
// $this->assertStringContainsString('functions.*.deployments.*.delete', $webhook['headers']['X-Appwrite-Webhook-Events']);
// $this->assertStringContainsString("functions.*.deployments.{$deploymentId}", $webhook['headers']['X-Appwrite-Webhook-Events']);
// $this->assertStringContainsString("functions.*.deployments.{$deploymentId}.delete", $webhook['headers']['X-Appwrite-Webhook-Events']);
// $this->assertStringContainsString("functions.{$id}", $webhook['headers']['X-Appwrite-Webhook-Events']);
// $this->assertStringContainsString("functions.{$id}.deployments.*", $webhook['headers']['X-Appwrite-Webhook-Events']);
// $this->assertStringContainsString("functions.{$id}.deployments.*.delete", $webhook['headers']['X-Appwrite-Webhook-Events']);
// $this->assertStringContainsString("functions.{$id}.deployments.{$deploymentId}", $webhook['headers']['X-Appwrite-Webhook-Events']);
// $this->assertStringContainsString("functions.{$id}.deployments.{$deploymentId}.delete", $webhook['headers']['X-Appwrite-Webhook-Events']); TODO @christyjacob4 : enable test once we allow functions.* events
2022-06-07 16:02:39 +00:00
$this -> assertEquals ( $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Signature' ], $signatureExpected );
2021-03-12 22:13:44 +00:00
$this -> assertEquals ( $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Id' ] ? ? '' , $this -> getProject ()[ 'webhookId' ]);
$this -> assertEquals ( $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Project-Id' ] ? ? '' , $this -> getProject ()[ '$id' ]);
/**
* Test for FAILURE
*/
return $data ;
2021-03-12 21:23:37 +00:00
}
2021-03-12 22:58:33 +00:00
/**
2022-01-24 23:48:51 +00:00
* @ depends testDeleteDeployment
2021-03-12 22:58:33 +00:00
*/
2022-04-18 16:21:45 +00:00
public function testDeleteFunction ( $data ) : array
2021-03-12 22:58:33 +00:00
{
2022-04-18 16:21:45 +00:00
$id = $data [ 'functionId' ];
2021-03-12 22:58:33 +00:00
/**
* Test for SUCCESS
*/
2022-04-18 16:21:45 +00:00
$function = $this -> client -> call ( Client :: METHOD_DELETE , '/functions/' . $id , array_merge ([
2021-03-12 22:58:33 +00:00
'content-type' => 'application/json' ,
'x-appwrite-project' => $this -> getProject ()[ '$id' ],
], $this -> getHeaders ()));
$this -> assertEquals ( 204 , $function [ 'headers' ][ 'status-code' ]);
$this -> assertEmpty ( $function [ 'body' ]);
$webhook = $this -> getLastRequest ();
2022-06-08 07:19:50 +00:00
$signatureExpected = self :: getWebhookSignature ( $webhook , $this -> getProject ()[ 'signatureKey' ]);
2021-03-12 22:58:33 +00:00
2025-05-10 05:31:36 +00:00
$this -> assertEquals ( 'POST' , $webhook [ 'method' ]);
$this -> assertEquals ( 'application/json' , $webhook [ 'headers' ][ 'Content-Type' ]);
$this -> assertEquals ( 'Appwrite-Server vdev. Please report abuse at security@appwrite.io' , $webhook [ 'headers' ][ 'User-Agent' ]);
2023-06-15 11:06:04 +00:00
// $this->assertStringContainsString('functions.*', $webhook['headers']['X-Appwrite-Webhook-Events']);
// $this->assertStringContainsString('functions.*.delete', $webhook['headers']['X-Appwrite-Webhook-Events']);
// $this->assertStringContainsString("functions.{$id}", $webhook['headers']['X-Appwrite-Webhook-Events']);
// $this->assertStringContainsString("functions.{$id}.delete", $webhook['headers']['X-Appwrite-Webhook-Events']); TODO @christyjacob4 : enable test once we allow functions.* events
2022-06-07 16:02:39 +00:00
$this -> assertEquals ( $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Signature' ], $signatureExpected );
2021-03-12 22:58:33 +00:00
$this -> assertEquals ( $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Id' ] ? ? '' , $this -> getProject ()[ 'webhookId' ]);
$this -> assertEquals ( $webhook [ 'headers' ][ 'X-Appwrite-Webhook-Project-Id' ] ? ? '' , $this -> getProject ()[ '$id' ]);
/**
* Test for FAILURE
*/
return $data ;
}
2021-03-12 21:23:37 +00:00
}