2020-11-21 01:35:16 +13:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\E2E\Services\Webhooks;
|
|
|
|
|
|
|
|
use CURLFile;
|
|
|
|
use Tests\E2E\Client;
|
|
|
|
|
|
|
|
trait WebhooksBase
|
|
|
|
{
|
|
|
|
public function testCreateFile():array
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
|
|
|
$file = $this->client->call(Client::METHOD_POST, '/storage/files', array_merge([
|
|
|
|
'content-type' => 'multipart/form-data',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'file' => new CURLFile(realpath(__DIR__ . '/../../../resources/logo.png'), 'image/png', 'logo.png'),
|
|
|
|
'read' => ['*'],
|
|
|
|
'write' => ['*'],
|
|
|
|
'folderId' => 'xyz',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($file['headers']['status-code'], 201);
|
|
|
|
$this->assertNotEmpty($file['body']['$id']);
|
2020-11-21 10:03:48 +13:00
|
|
|
|
2020-11-21 01:35:16 +13:00
|
|
|
$webhook = $this->getLastRequest();
|
|
|
|
|
2020-11-21 10:03:48 +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'], 'storage.files.create');
|
|
|
|
$this->assertEquals($webhook['headers']['X-Appwrite-Webhook-Signature'], 'not-yet-implemented');
|
2020-11-26 19:31:59 +13:00
|
|
|
$this->assertEquals(empty($webhook['headers']['X-Appwrite-Webhook-Userid'] ?? ''), ('server' === $this->getSide()));
|
2020-11-21 10:03:48 +13:00
|
|
|
$this->assertNotEmpty($webhook['data']['$id']);
|
|
|
|
$this->assertIsArray($webhook['data']['$permissions']);
|
|
|
|
$this->assertEquals($webhook['data']['name'], 'logo.png');
|
|
|
|
$this->assertIsInt($webhook['data']['dateCreated'], 'logo.png');
|
|
|
|
$this->assertNotEmpty($webhook['data']['signature']);
|
|
|
|
$this->assertEquals($webhook['data']['mimeType'], 'image/png');
|
|
|
|
$this->assertEquals($webhook['data']['sizeOriginal'], 47218);
|
2020-11-21 01:35:16 +13:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for FAILURE
|
|
|
|
*/
|
|
|
|
return ['fileId' => $file['body']['$id']];
|
|
|
|
}
|
|
|
|
|
2020-11-21 10:03:48 +13:00
|
|
|
/**
|
|
|
|
* @depends testCreateFile
|
|
|
|
*/
|
|
|
|
public function testUpdateFile(array $data):array
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
|
|
|
$file = $this->client->call(Client::METHOD_PUT, '/storage/files/' . $data['fileId'], array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'read' => ['*'],
|
|
|
|
'write' => ['*'],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($file['headers']['status-code'], 200);
|
|
|
|
$this->assertNotEmpty($file['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'], 'storage.files.update');
|
|
|
|
$this->assertEquals($webhook['headers']['X-Appwrite-Webhook-Signature'], 'not-yet-implemented');
|
2020-11-26 19:31:59 +13:00
|
|
|
$this->assertEquals(empty($webhook['headers']['X-Appwrite-Webhook-Userid'] ?? ''), ('server' === $this->getSide()));
|
2020-11-21 10:03:48 +13:00
|
|
|
$this->assertNotEmpty($webhook['data']['$id']);
|
|
|
|
$this->assertIsArray($webhook['data']['$permissions']);
|
|
|
|
$this->assertEquals($webhook['data']['name'], 'logo.png');
|
|
|
|
$this->assertIsInt($webhook['data']['dateCreated'], 'logo.png');
|
|
|
|
$this->assertNotEmpty($webhook['data']['signature']);
|
|
|
|
$this->assertEquals($webhook['data']['mimeType'], 'image/png');
|
|
|
|
$this->assertEquals($webhook['data']['sizeOriginal'], 47218);
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
2020-11-21 01:35:16 +13:00
|
|
|
|
2020-11-21 10:03:48 +13:00
|
|
|
/**
|
|
|
|
* @depends testUpdateFile
|
|
|
|
*/
|
|
|
|
public function testDeleteFile(array $data):array
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
|
|
|
$file = $this->client->call(Client::METHOD_DELETE, '/storage/files/' . $data['fileId'], array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()));
|
|
|
|
|
|
|
|
$this->assertEquals(204, $file['headers']['status-code']);
|
|
|
|
$this->assertEmpty($file['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'], 'storage.files.delete');
|
|
|
|
$this->assertEquals($webhook['headers']['X-Appwrite-Webhook-Signature'], 'not-yet-implemented');
|
2020-11-26 19:31:59 +13:00
|
|
|
$this->assertEquals(empty($webhook['headers']['X-Appwrite-Webhook-Userid'] ?? ''), ('server' === $this->getSide()));
|
2020-11-21 10:03:48 +13:00
|
|
|
$this->assertNotEmpty($webhook['data']['$id']);
|
|
|
|
$this->assertIsArray($webhook['data']['$permissions']);
|
|
|
|
$this->assertEquals($webhook['data']['name'], 'logo.png');
|
|
|
|
$this->assertIsInt($webhook['data']['dateCreated'], 'logo.png');
|
|
|
|
$this->assertNotEmpty($webhook['data']['signature']);
|
|
|
|
$this->assertEquals($webhook['data']['mimeType'], 'image/png');
|
|
|
|
$this->assertEquals($webhook['data']['sizeOriginal'], 47218);
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
2020-11-21 01:35:16 +13:00
|
|
|
}
|