fix tests

This commit is contained in:
Damodar Lohani
2021-12-14 15:27:39 +05:45
parent 786f5bfeb4
commit ca2db44c32
2 changed files with 18 additions and 15 deletions
+6 -6
View File
@@ -339,8 +339,8 @@ trait StorageBase
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'read' => ['role:all', 'user:x'],
'write' => ['role:all', 'user:x'],
'read' => ['user:'.$this->getUser()['$id']],
'write' => ['user:'.$this->getUser()['$id']],
]);
$this->assertEquals(200, $file['headers']['status-code']);
@@ -357,8 +357,8 @@ trait StorageBase
//$this->assertNotEmpty($file['body']['fileOpenSSLIV']);
$this->assertIsArray($file['body']['$read']);
$this->assertIsArray($file['body']['$write']);
$this->assertCount(2, $file['body']['$read']);
$this->assertCount(2, $file['body']['$write']);
$this->assertCount(1, $file['body']['$read']);
$this->assertCount(1, $file['body']['$write']);
/**
* Test for FAILURE unknown Bucket
@@ -368,8 +368,8 @@ trait StorageBase
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'read' => ['role:all', 'user:x'],
'write' => ['role:all', 'user:x'],
'read' => ['user:'.$this->getUser()['$id']],
'write' => ['user:'.$this->getUser()['$id']],
]);
$this->assertEquals(404, $file['headers']['status-code']);
@@ -53,15 +53,18 @@ class StorageCustomClientTest extends Scope
$this->assertEquals('image/png', $file['body']['mimeType']);
$this->assertEquals(47218, $file['body']['sizeOriginal']);
return $file['body'];
return ['fileId' => $file['body']['$id'], 'bucketId' => $bucket['body']['$id']];
}
public function testCreateFileAbusePermissions(): void
/**
* @depends testCreateFileDefaultPermissions
*/
public function testCreateFileAbusePermissions(array $data): void
{
/**
* Test for FAILURE
*/
$file = $this->client->call(Client::METHOD_POST, '/storage/files', array_merge([
$file = $this->client->call(Client::METHOD_POST, '/storage/buckets/' . $data['bucketId'] . '/files', array_merge([
'content-type' => 'multipart/form-data',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
@@ -71,13 +74,13 @@ class StorageCustomClientTest extends Scope
'read' => ['user:notme']
]);
$this->assertEquals($file['headers']['status-code'], 400);
$this->assertEquals(400, $file['headers']['status-code']);
$this->assertStringStartsWith('Read permissions must be one of:', $file['body']['message']);
$this->assertStringContainsString('role:all', $file['body']['message']);
$this->assertStringContainsString('role:member', $file['body']['message']);
$this->assertStringContainsString('user:'.$this->getUser()['$id'], $file['body']['message']);
$file = $this->client->call(Client::METHOD_POST, '/storage/files', array_merge([
$file = $this->client->call(Client::METHOD_POST, '/storage/buckets/' . $data['bucketId'] . '/files', array_merge([
'content-type' => 'multipart/form-data',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
@@ -93,7 +96,7 @@ class StorageCustomClientTest extends Scope
$this->assertStringContainsString('role:member', $file['body']['message']);
$this->assertStringContainsString('user:'.$this->getUser()['$id'], $file['body']['message']);
$file = $this->client->call(Client::METHOD_POST, '/storage/files', array_merge([
$file = $this->client->call(Client::METHOD_POST, '/storage/buckets/' . $data['bucketId'] . '/files', array_merge([
'content-type' => 'multipart/form-data',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
@@ -119,7 +122,7 @@ class StorageCustomClientTest extends Scope
/**
* Test for FAILURE
*/
$file = $this->client->call(Client::METHOD_PUT, '/storage/files/' . $data['$id'], array_merge([
$file = $this->client->call(Client::METHOD_PUT, '/storage/buckets/' . $data['bucketId'] . '/files/' . $data['fileId'], array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
@@ -132,7 +135,7 @@ class StorageCustomClientTest extends Scope
$this->assertStringContainsString('role:member', $file['body']['message']);
$this->assertStringContainsString('user:'.$this->getUser()['$id'], $file['body']['message']);
$file = $this->client->call(Client::METHOD_PUT, '/storage/files/' . $data['$id'], array_merge([
$file = $this->client->call(Client::METHOD_PUT, '/storage/buckets/' . $data['bucketId'] . '/files/' . $data['fileId'], array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
@@ -145,7 +148,7 @@ class StorageCustomClientTest extends Scope
$this->assertStringContainsString('role:member', $file['body']['message']);
$this->assertStringContainsString('user:'.$this->getUser()['$id'], $file['body']['message']);
$file = $this->client->call(Client::METHOD_PUT, '/storage/files/' . $data['$id'], array_merge([
$file = $this->client->call(Client::METHOD_PUT, '/storage/buckets/' . $data['bucketId'] . '/files/' . $data['fileId'], array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [