From fc36120a510ced559ec83d6b63eaf8e0b9c25f6f Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Sun, 7 May 2023 11:33:27 +0545 Subject: [PATCH 1/2] get file hash before encryption and compression --- app/controllers/api/storage.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/storage.php b/app/controllers/api/storage.php index de19590f25..d59d950d93 100644 --- a/app/controllers/api/storage.php +++ b/app/controllers/api/storage.php @@ -515,6 +515,7 @@ App::post('/v1/storage/buckets/:bucketId/files') } $mimeType = $deviceFiles->getFileMimeType($path); // Get mime-type before compression and encryption + $fileHash = $deviceFiles->getFileHash($path); // Get file hash before compression and encryption $data = ''; // Compression $algorithm = $bucket->getAttribute('compression', COMPRESSION_TYPE_NONE); @@ -548,7 +549,6 @@ App::post('/v1/storage/buckets/:bucketId/files') } $sizeActual = $deviceFiles->getFileSize($path); - $fileHash = $deviceFiles->getFileHash($path); $openSSLVersion = null; $openSSLCipher = null; From 0592384d840bae5a4d3ba7a6478dd313cf8ec696 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Wed, 10 May 2023 06:31:12 +0000 Subject: [PATCH 2/2] fix test --- tests/e2e/Services/Storage/StorageBase.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/e2e/Services/Storage/StorageBase.php b/tests/e2e/Services/Storage/StorageBase.php index baef838979..3169077f99 100644 --- a/tests/e2e/Services/Storage/StorageBase.php +++ b/tests/e2e/Services/Storage/StorageBase.php @@ -57,8 +57,7 @@ trait StorageBase $this->assertEquals('logo.png', $file['body']['name']); $this->assertEquals('image/png', $file['body']['mimeType']); $this->assertEquals(47218, $file['body']['sizeOriginal']); - $this->assertTrue(md5_file(realpath(__DIR__ . '/../../../resources/logo.png')) != $file['body']['signature']); // should validate that the file is encrypted - + $this->assertTrue(md5_file(realpath(__DIR__ . '/../../../resources/logo.png')) == $file['body']['signature']); /** * Test for Large File above 20MB * This should also validate the test for when Bucket encryption @@ -289,7 +288,7 @@ trait StorageBase $this->assertEquals('logo.png', $file['body']['name']); $this->assertEquals('image/png', $file['body']['mimeType']); $this->assertEquals(47218, $file['body']['sizeOriginal']); - $this->assertTrue(md5_file(realpath(__DIR__ . '/../../../resources/logo.png')) != $file['body']['signature']); // should validate that the file is encrypted + $this->assertTrue(md5_file(realpath(__DIR__ . '/../../../resources/logo.png')) == $file['body']['signature']); return ['bucketId' => $bucketId]; }