2020-11-21 01:35:16 +13:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\E2E\Services\Webhooks;
|
|
|
|
|
2021-03-13 10:23:37 +13:00
|
|
|
use CURLFile;
|
2020-11-24 04:04:02 +13:00
|
|
|
use Tests\E2E\Client;
|
2020-11-21 01:35:16 +13:00
|
|
|
use Tests\E2E\Scopes\ProjectCustom;
|
|
|
|
use Tests\E2E\Scopes\Scope;
|
|
|
|
use Tests\E2E\Scopes\SideServer;
|
|
|
|
|
|
|
|
class WebhooksCustomServerTest extends Scope
|
|
|
|
{
|
|
|
|
use WebhooksBase;
|
|
|
|
use ProjectCustom;
|
|
|
|
use SideServer;
|
2020-11-24 04:04:02 +13:00
|
|
|
|
2020-12-01 10:41:58 +13:00
|
|
|
/**
|
|
|
|
* @depends testCreateCollection
|
|
|
|
*/
|
|
|
|
public function testUpdateCollection($data): array
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
|
|
|
$actors = $this->client->call(Client::METHOD_PUT, '/database/collections/'.$data['actorsId'], array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'x-appwrite-key' => $this->getProject()['apiKey']
|
|
|
|
]), [
|
|
|
|
'name' => 'Actors1',
|
|
|
|
'read' => ['*'],
|
|
|
|
'write' => ['*'],
|
|
|
|
'rules' => [
|
|
|
|
[
|
|
|
|
'label' => 'First Name',
|
|
|
|
'key' => 'firstName',
|
|
|
|
'type' => 'text',
|
|
|
|
'default' => '',
|
|
|
|
'required' => true,
|
|
|
|
'array' => false
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'label' => 'Last Name',
|
|
|
|
'key' => 'lastName',
|
|
|
|
'type' => 'text',
|
|
|
|
'default' => '',
|
|
|
|
'required' => true,
|
|
|
|
'array' => false
|
|
|
|
],
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($actors['headers']['status-code'], 200);
|
|
|
|
$this->assertNotEmpty($actors['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'], 'database.collections.update');
|
|
|
|
$this->assertEquals($webhook['headers']['X-Appwrite-Webhook-Signature'], 'not-yet-implemented');
|
2020-12-04 06:56:07 +13: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'] ?? ''), true);
|
2020-12-01 10:41:58 +13:00
|
|
|
$this->assertNotEmpty($webhook['data']['$id']);
|
|
|
|
$this->assertEquals($webhook['data']['name'], 'Actors1');
|
|
|
|
$this->assertIsArray($webhook['data']['$permissions']);
|
|
|
|
$this->assertIsArray($webhook['data']['$permissions']['read']);
|
|
|
|
$this->assertIsArray($webhook['data']['$permissions']['write']);
|
|
|
|
$this->assertCount(1, $webhook['data']['$permissions']['read']);
|
|
|
|
$this->assertCount(1, $webhook['data']['$permissions']['write']);
|
|
|
|
$this->assertCount(2, $webhook['data']['rules']);
|
|
|
|
|
|
|
|
return array_merge(['actorsId' => $actors['body']['$id']]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testDeleteCollection(): array
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
|
|
|
$actors = $this->client->call(Client::METHOD_POST, '/database/collections', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'x-appwrite-key' => $this->getProject()['apiKey']
|
|
|
|
]), [
|
|
|
|
'name' => 'Demo',
|
|
|
|
'read' => ['*'],
|
|
|
|
'write' => ['*'],
|
|
|
|
'rules' => [
|
|
|
|
[
|
|
|
|
'label' => 'First Name',
|
|
|
|
'key' => 'firstName',
|
|
|
|
'type' => 'text',
|
|
|
|
'default' => '',
|
|
|
|
'required' => true,
|
|
|
|
'array' => false
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'label' => 'Last Name',
|
|
|
|
'key' => 'lastName',
|
|
|
|
'type' => 'text',
|
|
|
|
'default' => '',
|
|
|
|
'required' => true,
|
|
|
|
'array' => false
|
|
|
|
],
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($actors['headers']['status-code'], 201);
|
|
|
|
$this->assertNotEmpty($actors['body']['$id']);
|
|
|
|
|
2020-12-02 07:53:31 +13:00
|
|
|
$actors = $this->client->call(Client::METHOD_DELETE, '/database/collections/'.$actors['body']['$id'], array_merge([
|
2020-12-01 10:41:58 +13:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'x-appwrite-key' => $this->getProject()['apiKey']
|
|
|
|
]), []);
|
|
|
|
|
|
|
|
$this->assertEquals($actors['headers']['status-code'], 204);
|
|
|
|
|
|
|
|
$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'], 'database.collections.delete');
|
|
|
|
$this->assertEquals($webhook['headers']['X-Appwrite-Webhook-Signature'], 'not-yet-implemented');
|
2020-12-04 06:56:07 +13: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'] ?? ''), true);
|
2020-12-01 10:41:58 +13:00
|
|
|
$this->assertNotEmpty($webhook['data']['$id']);
|
|
|
|
$this->assertEquals($webhook['data']['name'], 'Demo');
|
|
|
|
$this->assertIsArray($webhook['data']['$permissions']);
|
|
|
|
$this->assertIsArray($webhook['data']['$permissions']['read']);
|
|
|
|
$this->assertIsArray($webhook['data']['$permissions']['write']);
|
|
|
|
$this->assertCount(1, $webhook['data']['$permissions']['read']);
|
|
|
|
$this->assertCount(1, $webhook['data']['$permissions']['write']);
|
|
|
|
$this->assertCount(2, $webhook['data']['rules']);
|
|
|
|
|
2020-12-02 07:53:31 +13:00
|
|
|
return [];
|
2020-12-01 10:41:58 +13:00
|
|
|
}
|
|
|
|
|
2020-11-24 04:04:02 +13:00
|
|
|
public function testCreateUser():array
|
|
|
|
{
|
|
|
|
$email = uniqid().'user@localhost.test';
|
|
|
|
$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()), [
|
|
|
|
'email' => $email,
|
|
|
|
'password' => $password,
|
|
|
|
'name' => $name,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($user['headers']['status-code'], 201);
|
|
|
|
$this->assertNotEmpty($user['body']['$id']);
|
|
|
|
|
|
|
|
$id = $user['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'], 'users.create');
|
|
|
|
$this->assertEquals($webhook['headers']['X-Appwrite-Webhook-Signature'], 'not-yet-implemented');
|
2020-12-04 06:56:07 +13: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-24 04:04:02 +13:00
|
|
|
$this->assertNotEmpty($webhook['data']['$id']);
|
|
|
|
$this->assertEquals($webhook['data']['name'], $name);
|
|
|
|
$this->assertIsInt($webhook['data']['registration']);
|
|
|
|
$this->assertEquals($webhook['data']['status'], 0);
|
|
|
|
$this->assertEquals($webhook['data']['email'], $email);
|
|
|
|
$this->assertEquals($webhook['data']['emailVerification'], false);
|
|
|
|
$this->assertEquals($webhook['data']['prefs'], []);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for FAILURE
|
|
|
|
*/
|
|
|
|
return ['userId' => $user['body']['$id'], 'name' => $user['body']['name'], 'email' => $user['body']['email']];
|
|
|
|
}
|
2021-03-05 07:47:02 +13:00
|
|
|
|
|
|
|
/**
|
2020-11-24 04:04:02 +13:00
|
|
|
* @depends testCreateUser
|
|
|
|
*/
|
2021-03-05 07:47:02 +13:00
|
|
|
public function testUpdateUserPrefs(array $data):array
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
|
|
|
$user = $this->client->call(Client::METHOD_PATCH, '/users/' . $data['userId'] . '/prefs', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
2021-03-08 02:09:45 +13:00
|
|
|
'prefs' => ['a' => 'b']
|
2021-03-05 07:47:02 +13:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($user['headers']['status-code'], 200);
|
2021-03-09 09:48:45 +13:00
|
|
|
$this->assertEquals($user['body']['a'], 'b');
|
|
|
|
|
2021-03-05 07:47:02 +13:00
|
|
|
$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'], 'users.update.prefs');
|
|
|
|
$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']);
|
|
|
|
$this->assertEquals(empty($webhook['headers']['X-Appwrite-Webhook-User-Id'] ?? ''), ('server' === $this->getSide()));
|
2021-03-08 02:09:45 +13:00
|
|
|
$this->assertEquals($webhook['data']['a'], 'b');
|
2021-03-05 07:47:02 +13:00
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
2020-11-24 04:04:02 +13:00
|
|
|
/**
|
2021-03-09 04:16:28 +13:00
|
|
|
* @depends testUpdateUserPrefs
|
2020-11-24 04:04:02 +13:00
|
|
|
*/
|
|
|
|
public function testUpdateUserStatus(array $data):array
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* 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()), [
|
|
|
|
'status' => 2,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($user['headers']['status-code'], 200);
|
|
|
|
$this->assertNotEmpty($user['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'], 'users.update.status');
|
|
|
|
$this->assertEquals($webhook['headers']['X-Appwrite-Webhook-Signature'], 'not-yet-implemented');
|
2020-12-04 06:56:07 +13: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-24 04:04:02 +13:00
|
|
|
$this->assertNotEmpty($webhook['data']['$id']);
|
|
|
|
$this->assertEquals($webhook['data']['name'], $data['name']);
|
|
|
|
$this->assertIsInt($webhook['data']['registration']);
|
|
|
|
$this->assertEquals($webhook['data']['status'], 2);
|
|
|
|
$this->assertEquals($webhook['data']['email'], $data['email']);
|
|
|
|
$this->assertEquals($webhook['data']['emailVerification'], false);
|
2021-03-08 02:09:45 +13:00
|
|
|
$this->assertEquals($webhook['data']['prefs']['a'], 'b');
|
2020-11-24 04:04:02 +13:00
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testUpdateUserStatus
|
|
|
|
*/
|
|
|
|
public function testDeleteUser(array $data):array
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* 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()));
|
|
|
|
|
|
|
|
$this->assertEquals($user['headers']['status-code'], 204);
|
|
|
|
|
|
|
|
$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'], 'users.delete');
|
|
|
|
$this->assertEquals($webhook['headers']['X-Appwrite-Webhook-Signature'], 'not-yet-implemented');
|
2020-12-04 06:56:07 +13: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-24 04:04:02 +13:00
|
|
|
$this->assertNotEmpty($webhook['data']['$id']);
|
|
|
|
$this->assertEquals($webhook['data']['name'], $data['name']);
|
|
|
|
$this->assertIsInt($webhook['data']['registration']);
|
|
|
|
$this->assertEquals($webhook['data']['status'], 2);
|
|
|
|
$this->assertEquals($webhook['data']['email'], $data['email']);
|
|
|
|
$this->assertEquals($webhook['data']['emailVerification'], false);
|
2021-03-08 02:09:45 +13:00
|
|
|
$this->assertEquals($webhook['data']['prefs']['a'], 'b');
|
2020-11-24 04:04:02 +13:00
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
2021-03-13 10:23:37 +13:00
|
|
|
|
|
|
|
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',
|
2021-06-23 03:56:05 +12:00
|
|
|
'runtime' => 'php-8.0',
|
2021-03-13 10:23:37 +13:00
|
|
|
'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
|
|
|
|
*/
|
2021-03-13 11:48:15 +13:00
|
|
|
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',
|
2021-06-23 03:56:05 +12:00
|
|
|
'runtime' => 'php-8.0',
|
2021-03-13 11:48:15 +13:00
|
|
|
'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
|
|
|
|
*/
|
2021-03-13 10:23:37 +13:00
|
|
|
public function testCreateTag($data):array
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
2021-03-13 10:55:01 +13:00
|
|
|
$tag = $this->client->call(Client::METHOD_POST, '/functions/'.$data['functionId'].'/tags', array_merge([
|
2021-03-13 10:23:37 +13:00
|
|
|
'content-type' => 'multipart/form-data',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
2021-03-13 10:55:01 +13:00
|
|
|
'command' => 'php index.php',
|
|
|
|
'code' => new CURLFile(realpath(__DIR__ . '/../../../resources/functions/timeout.tar.gz'), 'application/x-gzip', 'php-fx.tar.gz'),
|
2021-03-13 10:23:37 +13:00
|
|
|
]);
|
|
|
|
|
|
|
|
$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
|
|
|
|
*/
|
2021-03-13 10:55:01 +13:00
|
|
|
public function testExecutions($data):array
|
2021-03-13 10:23:37 +13:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
2021-04-27 02:39:53 +12:00
|
|
|
|
2021-03-13 10:55:01 +13:00
|
|
|
$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()), []);
|
|
|
|
|
|
|
|
$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']);
|
|
|
|
|
2021-04-20 22:28:30 +12:00
|
|
|
// wait for timeout function to complete (sleep(5);)
|
2021-04-27 02:28:48 +12:00
|
|
|
sleep(10);
|
2021-03-13 10:55:01 +13:00
|
|
|
|
|
|
|
$webhook = $this->getLastRequest();
|
2021-04-26 22:29:12 +12:00
|
|
|
|
2021-03-13 10:55:01 +13:00
|
|
|
$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']);
|
|
|
|
|
2021-03-13 10:23:37 +13:00
|
|
|
/**
|
|
|
|
* Test for FAILURE
|
|
|
|
*/
|
|
|
|
|
2021-03-13 11:13:44 +13:00
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-03-13 11:48:15 +13:00
|
|
|
* @depends testExecutions
|
2021-03-13 11:13:44 +13:00
|
|
|
*/
|
|
|
|
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;
|
2021-03-13 10:23:37 +13:00
|
|
|
}
|
2021-03-13 11:58:33 +13:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @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;
|
|
|
|
}
|
2021-03-13 10:23:37 +13:00
|
|
|
}
|