From ca2db44c32944aed70e2d743692a4712ceea1eab Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Tue, 14 Dec 2021 15:27:39 +0545 Subject: [PATCH] fix tests --- tests/e2e/Services/Storage/StorageBase.php | 12 +++++------ .../Storage/StorageCustomClientTest.php | 21 +++++++++++-------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/tests/e2e/Services/Storage/StorageBase.php b/tests/e2e/Services/Storage/StorageBase.php index fe74bc178b..e6eabe9384 100644 --- a/tests/e2e/Services/Storage/StorageBase.php +++ b/tests/e2e/Services/Storage/StorageBase.php @@ -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']); diff --git a/tests/e2e/Services/Storage/StorageCustomClientTest.php b/tests/e2e/Services/Storage/StorageCustomClientTest.php index c4fa130cac..01d410f1a9 100644 --- a/tests/e2e/Services/Storage/StorageCustomClientTest.php +++ b/tests/e2e/Services/Storage/StorageCustomClientTest.php @@ -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()), [