diff --git a/tests/e2e/Services/Storage/StorageBase.php b/tests/e2e/Services/Storage/StorageBase.php index d5a9765c60..3f823c38e9 100644 --- a/tests/e2e/Services/Storage/StorageBase.php +++ b/tests/e2e/Services/Storage/StorageBase.php @@ -24,6 +24,38 @@ trait StorageBase */ private static array $cachedZstdBucket = []; + /** + * Valid signatures for a chunk-uploaded file: the content MD5 on local + * devices, or the composite multipart ETag (md5 of part MD5s suffixed + * with the part count) on S3 devices. + */ + protected function getChunkedFileSignatures(string $path, int $chunkSize = 5 * 1024 * 1024): array + { + $signatures = [\md5_file($path)]; + + $handle = \fopen($path, 'rb'); + if ($handle === false) { + return $signatures; + } + $binary = ''; + $parts = 0; + while (!\feof($handle)) { + $chunk = \fread($handle, $chunkSize); + if ($chunk === '' || $chunk === false) { + break; + } + $binary .= \md5($chunk, true); + $parts++; + } + \fclose($handle); + + if ($parts > 1) { + $signatures[] = \md5($binary) . '-' . $parts; + } + + return $signatures; + } + /** * Helper method to set up bucket and file data for tests. * Uses static caching to avoid recreating resources. @@ -287,7 +319,7 @@ trait StorageBase $this->assertEquals('large-file.mp4', $largeFile['body']['name']); $this->assertEquals('video/mp4', $largeFile['body']['mimeType']); $this->assertEquals($totalSize, $largeFile['body']['sizeOriginal']); - $this->assertEquals(md5_file(realpath(__DIR__ . '/../../../resources/disk-a/large-file.mp4')), $largeFile['body']['signature']); // should validate that the file is not encrypted + $this->assertContains($largeFile['body']['signature'], $this->getChunkedFileSignatures(realpath(__DIR__ . '/../../../resources/disk-a/large-file.mp4'))); // should validate that the file is not encrypted /** * Failure