From f734fc1de2c6af105d1a688336e8b26f17c3f62f Mon Sep 17 00:00:00 2001 From: kodumbeats Date: Thu, 11 Mar 2021 13:25:46 -0500 Subject: [PATCH 1/9] Add events for functions and executions --- app/config/events.php | 37 ++++++++++++++++++++++++++++++- app/controllers/api/functions.php | 7 ++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/app/config/events.php b/app/config/events.php index 2bb3862fdf..47b902fb82 100644 --- a/app/config/events.php +++ b/app/config/events.php @@ -97,6 +97,41 @@ return [ 'model' => Response::MODEL_ANY, 'note' => '', ], + 'functions.create' => [ + 'description' => 'This event triggers when a function is created.', + 'model' => Response::MODEL_FUNCTION, + 'note' => 'version >= 0.7', + ], + 'functions.update' => [ + 'description' => 'This event triggers when a function is updated.', + 'model' => Response::MODEL_FUNCTION, + 'note' => 'version >= 0.7', + ], + 'functions.delete' => [ + 'description' => 'This event triggers when a function is deleted.', + 'model' => Response::MODEL_ANY, + 'note' => 'version >= 0.7', + ], + 'functions.tags.create' => [ + 'description' => 'This event triggers when a function tag is created.', + 'model' => Response::MODEL_TAG, + 'note' => 'version >= 0.7', + ], + 'functions.tags.update' => [ + 'description' => 'This event triggers when a function tag is updated.', + 'model' => Response::MODEL_FUNCTION, + 'note' => 'version >= 0.7', + ], + 'functions.tags.delete' => [ + 'description' => 'This event triggers when a function tag is deleted.', + 'model' => Response::MODEL_ANY, + 'note' => 'version >= 0.7', + ], + 'functions.executions.create' => [ + 'description' => 'This event triggers when a function execution is created.', + 'model' => Response::MODEL_EXECUTION, + 'note' => 'version >= 0.7', + ], 'storage.files.create' => [ 'description' => 'This event triggers when a storage file is created.', 'model' => Response::MODEL_FILE, @@ -162,4 +197,4 @@ return [ 'model' => Response::MODEL_MEMBERSHIP, 'note' => 'version >= 0.7', ], -]; \ No newline at end of file +]; diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index 7a6b11bcda..e6ff1bad59 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -27,6 +27,7 @@ App::post('/v1/functions') ->groups(['api', 'functions']) ->desc('Create Function') ->label('scope', 'functions.write') + ->label('event', 'functions.create') ->label('sdk.platform', [APP_PLATFORM_SERVER]) ->label('sdk.namespace', 'functions') ->label('sdk.method', 'create') @@ -265,6 +266,7 @@ App::put('/v1/functions/:functionId') ->groups(['api', 'functions']) ->desc('Update Function') ->label('scope', 'functions.write') + ->label('event', 'functions.update') ->label('sdk.platform', [APP_PLATFORM_SERVER]) ->label('sdk.namespace', 'functions') ->label('sdk.method', 'update') @@ -330,6 +332,7 @@ App::patch('/v1/functions/:functionId/tag') ->groups(['api', 'functions']) ->desc('Update Function Tag') ->label('scope', 'functions.write') + ->label('event', 'functions.tags.update') ->label('sdk.platform', [APP_PLATFORM_SERVER]) ->label('sdk.namespace', 'functions') ->label('sdk.method', 'updateTag') @@ -387,6 +390,7 @@ App::delete('/v1/functions/:functionId') ->groups(['api', 'functions']) ->desc('Delete Function') ->label('scope', 'functions.write') + ->label('event', 'functions.delete') ->label('sdk.platform', [APP_PLATFORM_SERVER]) ->label('sdk.namespace', 'functions') ->label('sdk.method', 'delete') @@ -424,6 +428,7 @@ App::post('/v1/functions/:functionId/tags') ->groups(['api', 'functions']) ->desc('Create Tag') ->label('scope', 'functions.write') + ->label('event', 'functions.tags.create') ->label('sdk.platform', [APP_PLATFORM_SERVER]) ->label('sdk.namespace', 'functions') ->label('sdk.method', 'createTag') @@ -601,6 +606,7 @@ App::delete('/v1/functions/:functionId/tags/:tagId') ->groups(['api', 'functions']) ->desc('Delete Tag') ->label('scope', 'functions.write') + ->label('event', 'functions.tags.delete') ->label('sdk.platform', [APP_PLATFORM_SERVER]) ->label('sdk.namespace', 'functions') ->label('sdk.method', 'deleteTag') @@ -662,6 +668,7 @@ App::post('/v1/functions/:functionId/executions') ->groups(['api', 'functions']) ->desc('Create Execution') ->label('scope', 'execution.write') + ->label('event', 'functions.executions.create') ->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER]) ->label('sdk.namespace', 'functions') ->label('sdk.method', 'createExecution') From 731c87d740be5aece651b317e032d15cbe201b19 Mon Sep 17 00:00:00 2001 From: kodumbeats Date: Fri, 12 Mar 2021 13:28:29 -0500 Subject: [PATCH 2/9] Add functions.executions.update --- app/config/events.php | 5 +++++ app/workers/functions.php | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/app/config/events.php b/app/config/events.php index 47b902fb82..8cda7d5be2 100644 --- a/app/config/events.php +++ b/app/config/events.php @@ -132,6 +132,11 @@ return [ 'model' => Response::MODEL_EXECUTION, 'note' => 'version >= 0.7', ], + 'functions.executions.update' => [ + 'description' => 'This event triggers when a function execution is updated.', + 'model' => Response::MODEL_EXECUTION, + 'note' => 'version >= 0.7', + ], 'storage.files.create' => [ 'description' => 'This event triggers when a storage file is created.', 'model' => Response::MODEL_FILE, diff --git a/app/workers/functions.php b/app/workers/functions.php index 87e3a86245..f24b556104 100644 --- a/app/workers/functions.php +++ b/app/workers/functions.php @@ -469,6 +469,28 @@ class FunctionsV1 throw new Exception('Failed saving execution to DB', 500); } + var_dump($execution); + $executionUpdate = new Event('v1-webhooks', 'WebhooksV1'); + + $executionUpdate + ->setParam('projectId', $projectId) + ->setParam('userId', '') + ->setParam('event', 'functions.executions.update') + ->setParam('payload', [ + '$id' => $execution['$id'], + 'functionId' => $execution['functionId'], + 'dateCreated' => $execution['dateCreated'], + 'trigger' => $execution['trigger'], + 'status' => $execution['status'], + 'exitCode' => $execution['exitCode'], + 'stdout' => $execution['stdout'], + 'stderr' => $execution['stderr'], + 'time' => $execution['time'] + ]); + + $executionUpdate->trigger(); + + $usage = new Event('v1-usage', 'UsageV1'); $usage From c04396b254e6a97ad0f5ac821490712d6684ab69 Mon Sep 17 00:00:00 2001 From: kodumbeats Date: Fri, 12 Mar 2021 14:01:58 -0500 Subject: [PATCH 3/9] Pass userId to function --- app/workers/functions.php | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/app/workers/functions.php b/app/workers/functions.php index f24b556104..e88c2688be 100644 --- a/app/workers/functions.php +++ b/app/workers/functions.php @@ -148,6 +148,7 @@ class FunctionsV1 $event = $this->args['event'] ?? ''; $scheduleOriginal = $this->args['scheduleOriginal'] ?? ''; $payload = (!empty($this->args['payload'])) ? json_encode($this->args['payload']) : ''; + $userId = $this->args['userId'] ?? ''; $database = new Database(); $database->setAdapter(new RedisAdapter(new MySQLAdapter($register), $register)); @@ -195,7 +196,7 @@ class FunctionsV1 Console::success('Triggered function: '.$event); - $this->execute('event', $projectId, '', $database, $function, $event, $payload); + $this->execute('event', $projectId, '', $database, $function, $event, $payload, $userId); } } break; @@ -251,8 +252,8 @@ class FunctionsV1 'scheduleOriginal' => $function->getAttribute('schedule', ''), ]); // Async task rescheduale - $this->execute($trigger, $projectId, $executionId, $database, $function); + $this->execute($trigger, $projectId, $executionId, $database, $function, $userId); break; case 'http': @@ -264,7 +265,7 @@ class FunctionsV1 throw new Exception('Function not found ('.$functionId.')'); } - $this->execute($trigger, $projectId, $executionId, $database, $function); + $this->execute($trigger, $projectId, $executionId, $database, $function, $userId); break; default: @@ -286,7 +287,7 @@ class FunctionsV1 * * @return void */ - public function execute(string $trigger, string $projectId, string $executionId, Database $database, Document $function, string $event = '', string $payload = ''): void + public function execute(string $trigger, string $projectId, string $executionId, Database $database, Document $function, string $event = '', string $payload = '', string $userId = ''): void { global $list; @@ -469,12 +470,11 @@ class FunctionsV1 throw new Exception('Failed saving execution to DB', 500); } - var_dump($execution); $executionUpdate = new Event('v1-webhooks', 'WebhooksV1'); $executionUpdate ->setParam('projectId', $projectId) - ->setParam('userId', '') + ->setParam('userId', $userId) ->setParam('event', 'functions.executions.update') ->setParam('payload', [ '$id' => $execution['$id'], @@ -490,7 +490,6 @@ class FunctionsV1 $executionUpdate->trigger(); - $usage = new Event('v1-usage', 'UsageV1'); $usage From 444994a98d5e82d4d7d54303580e89458328b857 Mon Sep 17 00:00:00 2001 From: kodumbeats Date: Fri, 12 Mar 2021 16:23:37 -0500 Subject: [PATCH 4/9] Add function webhook tests --- tests/e2e/Scopes/ProjectCustom.php | 8 ++ .../Webhooks/WebhooksCustomServerTest.php | 131 +++++++++++++++++- 2 files changed, 138 insertions(+), 1 deletion(-) diff --git a/tests/e2e/Scopes/ProjectCustom.php b/tests/e2e/Scopes/ProjectCustom.php index e1059f6afa..113415f094 100644 --- a/tests/e2e/Scopes/ProjectCustom.php +++ b/tests/e2e/Scopes/ProjectCustom.php @@ -113,6 +113,14 @@ trait ProjectCustom 'database.documents.create', 'database.documents.update', 'database.documents.delete', + 'functions.create', + 'functions.update', + 'functions.delete', + 'functions.tags.create', + 'functions.tags.update', + 'functions.tags.delete', + 'functions.executions.create', + 'functions.executions.update', 'storage.files.create', 'storage.files.update', 'storage.files.delete', diff --git a/tests/e2e/Services/Webhooks/WebhooksCustomServerTest.php b/tests/e2e/Services/Webhooks/WebhooksCustomServerTest.php index 360dee2cb3..e7ca47924e 100644 --- a/tests/e2e/Services/Webhooks/WebhooksCustomServerTest.php +++ b/tests/e2e/Services/Webhooks/WebhooksCustomServerTest.php @@ -2,6 +2,7 @@ namespace Tests\E2E\Services\Webhooks; +use CURLFile; use Tests\E2E\Client; use Tests\E2E\Scopes\ProjectCustom; use Tests\E2E\Scopes\Scope; @@ -261,4 +262,132 @@ class WebhooksCustomServerTest extends Scope return $data; } -} \ No newline at end of file + + public function testCreateFunction():array + { + /** + * 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()), [ + 'name' => 'Test', + 'env' => 'php-7.4', + 'execute' => ['*'], + 'timeout' => 10, + ]); + + $functionId = $function['body']['$id'] ?? ''; + + $this->assertEquals($function['headers']['status-code'], 201); + $this->assertNotEmpty($function['body']['$id']); + + $webhook = $this->getLastRequest(); + + $this->assertEquals($webhook['method'], 'POST'); + $this->assertEquals($webhook['headers']['Content-Type'], 'application/json'); + $this->assertEquals($webhook['headers']['User-Agent'], 'Appwrite-Server vdev. Please report abuse at security@appwrite.io'); + $this->assertEquals($webhook['headers']['X-Appwrite-Webhook-Event'], 'functions.create'); + $this->assertEquals($webhook['headers']['X-Appwrite-Webhook-Signature'], 'not-yet-implemented'); + $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 [ + 'functionId' => $functionId, + ]; + } + + /** + * @depends testCreateFunction + */ + public function testCreateTag($data):array + { + /** + * Test for SUCCESS + */ + $tag = $this->client->call(Client::METHOD_POST, '/functions/' . $data['functionId'] . '/tags', array_merge([ + 'content-type' => 'multipart/form-data', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'command' => 'php function.php', + 'code' => new CURLFile(realpath(__DIR__ . '/../../../resources/functions/php.tar.gz'), 'application/x-gzip', 'php-fx.tar.gz'), + ]); + + $tagId = $tag['body']['$id'] ?? ''; + + $this->assertEquals($tag['headers']['status-code'], 201); + $this->assertNotEmpty($tag['body']['$id']); + + $webhook = $this->getLastRequest(); + + $this->assertEquals($webhook['method'], 'POST'); + $this->assertEquals($webhook['headers']['Content-Type'], 'application/json'); + $this->assertEquals($webhook['headers']['User-Agent'], 'Appwrite-Server vdev. Please report abuse at security@appwrite.io'); + $this->assertEquals($webhook['headers']['X-Appwrite-Webhook-Event'], 'functions.tags.create'); + $this->assertEquals($webhook['headers']['X-Appwrite-Webhook-Signature'], 'not-yet-implemented'); + $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 array_merge($data, ['tagId' => $tagId]); + } + + /** + * @depends testCreateTag + */ + public function testUpdateTag($data):array + { + /** + * Test for SUCCESS + */ + $response = $this->client->call(Client::METHOD_PATCH, '/functions/'.$data['functionId'].'/tag', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'tag' => $data['tagId'], + ]); + + $this->assertEquals($response['headers']['status-code'], 200); + $this->assertNotEmpty($response['body']['$id']); + + $webhook = $this->getLastRequest(); + + $this->assertEquals($webhook['method'], 'POST'); + $this->assertEquals($webhook['headers']['Content-Type'], 'application/json'); + $this->assertEquals($webhook['headers']['User-Agent'], 'Appwrite-Server vdev. Please report abuse at security@appwrite.io'); + $this->assertEquals($webhook['headers']['X-Appwrite-Webhook-Event'], 'functions.tags.update'); + $this->assertEquals($webhook['headers']['X-Appwrite-Webhook-Signature'], 'not-yet-implemented'); + $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; + } + + /** + * @depends testUpdateTag + */ + public function testCreateExecution($data):array + { + /** + * Test for SUCCESS + */ + + /** + * Test for FAILURE + */ + + return $data; + } +} From 1bfc259247327b98560bd0020752e574187bd5f5 Mon Sep 17 00:00:00 2001 From: kodumbeats Date: Fri, 12 Mar 2021 16:55:01 -0500 Subject: [PATCH 5/9] Add function exectution webhook tests --- .../Webhooks/WebhooksCustomServerTest.php | 44 ++++++++++++++++--- 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/tests/e2e/Services/Webhooks/WebhooksCustomServerTest.php b/tests/e2e/Services/Webhooks/WebhooksCustomServerTest.php index e7ca47924e..aafbaebed5 100644 --- a/tests/e2e/Services/Webhooks/WebhooksCustomServerTest.php +++ b/tests/e2e/Services/Webhooks/WebhooksCustomServerTest.php @@ -310,12 +310,12 @@ class WebhooksCustomServerTest extends Scope /** * Test for SUCCESS */ - $tag = $this->client->call(Client::METHOD_POST, '/functions/' . $data['functionId'] . '/tags', array_merge([ + $tag = $this->client->call(Client::METHOD_POST, '/functions/'.$data['functionId'].'/tags', array_merge([ 'content-type' => 'multipart/form-data', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'command' => 'php function.php', - 'code' => new CURLFile(realpath(__DIR__ . '/../../../resources/functions/php.tar.gz'), 'application/x-gzip', 'php-fx.tar.gz'), + 'command' => 'php index.php', + 'code' => new CURLFile(realpath(__DIR__ . '/../../../resources/functions/timeout.tar.gz'), 'application/x-gzip', 'php-fx.tar.gz'), ]); $tagId = $tag['body']['$id'] ?? ''; @@ -378,16 +378,48 @@ class WebhooksCustomServerTest extends Scope /** * @depends testUpdateTag */ - public function testCreateExecution($data):array + public function testExecutions($data):array { /** * Test for SUCCESS */ - + $execution = $this->client->call(Client::METHOD_POST, '/functions/'.$data['functionId'].'/executions', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), []); + + $executionId = $execution['body']['$id'] ?? ''; + + $this->assertEquals($execution['headers']['status-code'], 201); + $this->assertNotEmpty($execution['body']['$id']); + + $webhook = $this->getLastRequest(); + + $this->assertEquals($webhook['method'], 'POST'); + $this->assertEquals($webhook['headers']['Content-Type'], 'application/json'); + $this->assertEquals($webhook['headers']['User-Agent'], 'Appwrite-Server vdev. Please report abuse at security@appwrite.io'); + $this->assertEquals($webhook['headers']['X-Appwrite-Webhook-Event'], 'functions.executions.create'); + $this->assertEquals($webhook['headers']['X-Appwrite-Webhook-Signature'], 'not-yet-implemented'); + $this->assertEquals($webhook['headers']['X-Appwrite-Webhook-Id'] ?? '', $this->getProject()['webhookId']); + $this->assertEquals($webhook['headers']['X-Appwrite-Webhook-Project-Id'] ?? '', $this->getProject()['$id']); + + // wait for timeout function to complete (sleep(5);) + sleep(6); + + $webhook = $this->getLastRequest(); + + $this->assertEquals($webhook['method'], 'POST'); + $this->assertEquals($webhook['headers']['Content-Type'], 'application/json'); + $this->assertEquals($webhook['headers']['User-Agent'], 'Appwrite-Server vdev. Please report abuse at security@appwrite.io'); + $this->assertEquals($webhook['headers']['X-Appwrite-Webhook-Event'], 'functions.executions.update'); + $this->assertEquals($webhook['headers']['X-Appwrite-Webhook-Signature'], 'not-yet-implemented'); + $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; + return array_merge($data, ['executionId' => $executionId]); } } From 3cff27a125ae641af8e97068edaf33b8f02dfb0b Mon Sep 17 00:00:00 2001 From: kodumbeats Date: Fri, 12 Mar 2021 17:13:44 -0500 Subject: [PATCH 6/9] Test for functions.tags.delete --- .../Webhooks/WebhooksCustomServerTest.php | 37 +++++++++++++++++-- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/tests/e2e/Services/Webhooks/WebhooksCustomServerTest.php b/tests/e2e/Services/Webhooks/WebhooksCustomServerTest.php index aafbaebed5..d8474c6491 100644 --- a/tests/e2e/Services/Webhooks/WebhooksCustomServerTest.php +++ b/tests/e2e/Services/Webhooks/WebhooksCustomServerTest.php @@ -388,8 +388,6 @@ class WebhooksCustomServerTest extends Scope 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), []); - $executionId = $execution['body']['$id'] ?? ''; - $this->assertEquals($execution['headers']['status-code'], 201); $this->assertNotEmpty($execution['body']['$id']); @@ -420,6 +418,39 @@ class WebhooksCustomServerTest extends Scope * Test for FAILURE */ - return array_merge($data, ['executionId' => $executionId]); + return $data; + } + + /** + * @depends testUpdateTag + */ + public function testDeleteTag($data):array + { + /** + * Test for SUCCESS + */ + $tag = $this->client->call(Client::METHOD_DELETE, '/functions/'.$data['functionId'].'/tags/'.$data['tagId'], array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders())); + + $this->assertEquals($tag['headers']['status-code'], 204); + $this->assertEmpty($tag['body']); + + $webhook = $this->getLastRequest(); + + $this->assertEquals($webhook['method'], 'POST'); + $this->assertEquals($webhook['headers']['Content-Type'], 'application/json'); + $this->assertEquals($webhook['headers']['User-Agent'], 'Appwrite-Server vdev. Please report abuse at security@appwrite.io'); + $this->assertEquals($webhook['headers']['X-Appwrite-Webhook-Event'], 'functions.tags.delete'); + $this->assertEquals($webhook['headers']['X-Appwrite-Webhook-Signature'], 'not-yet-implemented'); + $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; } } From ac7efc8d1bf1b9a7a7de69270be2b018aaa6f4a8 Mon Sep 17 00:00:00 2001 From: kodumbeats Date: Fri, 12 Mar 2021 17:48:15 -0500 Subject: [PATCH 7/9] Test for functions.update --- .../Webhooks/WebhooksCustomServerTest.php | 39 ++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/tests/e2e/Services/Webhooks/WebhooksCustomServerTest.php b/tests/e2e/Services/Webhooks/WebhooksCustomServerTest.php index d8474c6491..553c78b9a5 100644 --- a/tests/e2e/Services/Webhooks/WebhooksCustomServerTest.php +++ b/tests/e2e/Services/Webhooks/WebhooksCustomServerTest.php @@ -305,6 +305,43 @@ class WebhooksCustomServerTest extends Scope /** * @depends testCreateFunction */ + public function testUpdateFunction($data):array + { + /** + * Test for SUCCESS + */ + $function = $this->client->call(Client::METHOD_PUT, '/functions/'.$data['functionId'], array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'name' => 'Test', + 'env' => 'php-7.4', + 'execute' => ['*'], + 'vars' => [ + 'key1' => 'value1', + ] + ]); + + $this->assertEquals($function['headers']['status-code'], 200); + $this->assertEquals($function['body']['$id'], $data['functionId']); + $this->assertEquals($function['body']['vars'], ['key1' => 'value1']); + + $webhook = $this->getLastRequest(); + + $this->assertEquals($webhook['method'], 'POST'); + $this->assertEquals($webhook['headers']['Content-Type'], 'application/json'); + $this->assertEquals($webhook['headers']['User-Agent'], 'Appwrite-Server vdev. Please report abuse at security@appwrite.io'); + $this->assertEquals($webhook['headers']['X-Appwrite-Webhook-Event'], 'functions.update'); + $this->assertEquals($webhook['headers']['X-Appwrite-Webhook-Signature'], 'not-yet-implemented'); + $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; + } + + /** + * @depends testUpdateFunction + */ public function testCreateTag($data):array { /** @@ -422,7 +459,7 @@ class WebhooksCustomServerTest extends Scope } /** - * @depends testUpdateTag + * @depends testExecutions */ public function testDeleteTag($data):array { From c0b020dd076cdc909519f427fa8f1c05c5066d19 Mon Sep 17 00:00:00 2001 From: kodumbeats Date: Fri, 12 Mar 2021 17:58:33 -0500 Subject: [PATCH 8/9] Test for functions.delete --- .../Webhooks/WebhooksCustomServerTest.php | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/e2e/Services/Webhooks/WebhooksCustomServerTest.php b/tests/e2e/Services/Webhooks/WebhooksCustomServerTest.php index 553c78b9a5..5fd61f49bc 100644 --- a/tests/e2e/Services/Webhooks/WebhooksCustomServerTest.php +++ b/tests/e2e/Services/Webhooks/WebhooksCustomServerTest.php @@ -490,4 +490,37 @@ class WebhooksCustomServerTest extends Scope return $data; } + + /** + * @depends testDeleteTag + */ + public function testDeleteFunction($data):array + { + /** + * Test for SUCCESS + */ + $function = $this->client->call(Client::METHOD_DELETE, '/functions/'.$data['functionId'], array_merge([ + '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(); + + $this->assertEquals($webhook['method'], 'POST'); + $this->assertEquals($webhook['headers']['Content-Type'], 'application/json'); + $this->assertEquals($webhook['headers']['User-Agent'], 'Appwrite-Server vdev. Please report abuse at security@appwrite.io'); + $this->assertEquals($webhook['headers']['X-Appwrite-Webhook-Event'], 'functions.delete'); + $this->assertEquals($webhook['headers']['X-Appwrite-Webhook-Signature'], 'not-yet-implemented'); + $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; + } } From 04e9f4f720b3aef3d65de421c8eb03dcd76ab9ed Mon Sep 17 00:00:00 2001 From: kodumbeats Date: Fri, 12 Mar 2021 18:02:23 -0500 Subject: [PATCH 9/9] Added events for functions and executions to changelog --- CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index d0cd072bc4..6264764a3c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,8 @@ # Version 0.8.0 (Not Released Yet) +## Features - Anonymous login +- Added events for functions and executions (#971) # Version 0.7.1