|
|
|
|
@ -153,6 +153,16 @@ class CacheTest extends \Test\TestCase { |
|
|
|
|
$this->assertEquals($entry->getUnencryptedSize(), 100); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function testGetUnencryptedSizeEncryptedZeroByte(): void { |
|
|
|
|
$file1 = 'encrypted_zero'; |
|
|
|
|
$this->cache->put($file1, ['size' => 8192, 'mtime' => 50, 'mimetype' => 'application/octet-stream', 'encrypted' => 1, 'unencrypted_size' => 0]); |
|
|
|
|
$entry = $this->cache->get($file1); |
|
|
|
|
|
|
|
|
|
// getUnencryptedSize() must return 0 (the true plaintext size), not 8192 (the encrypted on-disk size) |
|
|
|
|
$this->assertEquals(0, $entry->getUnencryptedSize()); |
|
|
|
|
$this->assertTrue($entry->isEncrypted()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function testPartial(): void { |
|
|
|
|
$file1 = 'foo'; |
|
|
|
|
|
|
|
|
|
@ -292,6 +302,39 @@ class CacheTest extends \Test\TestCase { |
|
|
|
|
$this->assertFalse($this->cache->inCache('folder/bar')); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function testCalculateFolderSizeWithEncryptedZeroByte(): void { |
|
|
|
|
$folder = 'enc_folder'; |
|
|
|
|
$this->cache->put($folder, ['size' => -1, 'mtime' => 20, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]); |
|
|
|
|
|
|
|
|
|
// Child 1: zero-byte encrypted file — on-disk 8192 (header only), plaintext 0 |
|
|
|
|
$child1 = $folder . '/empty.enc'; |
|
|
|
|
$this->cache->put($child1, [ |
|
|
|
|
'size' => 8192, |
|
|
|
|
'mtime' => 20, |
|
|
|
|
'mimetype' => 'application/octet-stream', |
|
|
|
|
'encrypted' => 1, |
|
|
|
|
'unencrypted_size' => 0, |
|
|
|
|
]); |
|
|
|
|
|
|
|
|
|
// Child 2: non-zero encrypted file — opens the write-back gate ($unencryptedMax > 0) |
|
|
|
|
$child2 = $folder . '/small.enc'; |
|
|
|
|
$this->cache->put($child2, [ |
|
|
|
|
'size' => 8292, |
|
|
|
|
'mtime' => 20, |
|
|
|
|
'mimetype' => 'application/octet-stream', |
|
|
|
|
'encrypted' => 1, |
|
|
|
|
'unencrypted_size' => 100, |
|
|
|
|
]); |
|
|
|
|
|
|
|
|
|
$this->cache->calculateFolderSize($folder); |
|
|
|
|
|
|
|
|
|
$entry = $this->cache->get($folder); |
|
|
|
|
// Must sum plaintext sizes (0 + 100 = 100), not fall back to on-disk size for |
|
|
|
|
// the zero-byte child (8192 + 100 = 8292 with the old buggy code) |
|
|
|
|
$this->assertEquals(100, $entry['unencrypted_size'], 'Folder unencrypted_size should sum plaintext sizes'); |
|
|
|
|
$this->assertEquals(16484, $entry['size'], 'Folder size should sum on-disk sizes (8192 + 8292)'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function testRootFolderSizeForNonHomeStorage(): void { |
|
|
|
|
$dir1 = 'knownsize'; |
|
|
|
|
$dir2 = 'unknownsize'; |
|
|
|
|
|