Skip to content

Commit 655b0af

Browse files
cuppettbackportbot[bot]
authored andcommitted
test(encryption): strengthen testCalculateFolderSizeWithEncryptedZeroByte
Add a second encrypted child with unencrypted_size=100 so the write-back gate in calculateFolderSizeInner ($unencryptedMax > 0) actually opens. The original single zero-byte child left the gate closed, meaning the test passed against the DB default rather than the computed value. With two children the assertion distinguishes the fixed code (result: 100) from the old buggy code (result: 8292, falling back to on-disk size for the zero-byte child). Assisted-by: ClaudeCode:claude-opus-4-6 Signed-off-by: Stephen Cuppett <scuppett@redhat.com>
1 parent 2d6a291 commit 655b0af

1 file changed

Lines changed: 18 additions & 7 deletions

File tree

tests/lib/Files/Cache/CacheTest.php

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -306,22 +306,33 @@ public function testCalculateFolderSizeWithEncryptedZeroByte(): void {
306306
$folder = 'enc_folder';
307307
$this->cache->put($folder, ['size' => -1, 'mtime' => 20, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]);
308308

309-
// Child: a zero-byte encrypted file — on-disk size is 8192 (header), but plaintext is 0
310-
$child = $folder . '/empty.enc';
311-
$this->cache->put($child, [
309+
// Child 1: zero-byte encrypted file — on-disk 8192 (header only), plaintext 0
310+
$child1 = $folder . '/empty.enc';
311+
$this->cache->put($child1, [
312312
'size' => 8192,
313313
'mtime' => 20,
314314
'mimetype' => 'application/octet-stream',
315315
'encrypted' => 1,
316316
'unencrypted_size' => 0,
317317
]);
318318

319-
$folderSize = $this->cache->calculateFolderSize($folder);
319+
// Child 2: non-zero encrypted file — opens the write-back gate ($unencryptedMax > 0)
320+
$child2 = $folder . '/small.enc';
321+
$this->cache->put($child2, [
322+
'size' => 8292,
323+
'mtime' => 20,
324+
'mimetype' => 'application/octet-stream',
325+
'encrypted' => 1,
326+
'unencrypted_size' => 100,
327+
]);
328+
329+
$this->cache->calculateFolderSize($folder);
320330

321-
// The folder's unencrypted_size must reflect the true plaintext total (0), not the encrypted on-disk size (8192)
322331
$entry = $this->cache->get($folder);
323-
$this->assertEquals(0, $entry['unencrypted_size'], 'Folder unencrypted_size should be 0 for zero-byte encrypted children');
324-
$this->assertEquals(8192, $entry['size'], 'Folder size should equal encrypted on-disk size');
332+
// Must sum plaintext sizes (0 + 100 = 100), not fall back to on-disk size for
333+
// the zero-byte child (8192 + 100 = 8292 with the old buggy code)
334+
$this->assertEquals(100, $entry['unencrypted_size'], 'Folder unencrypted_size should sum plaintext sizes');
335+
$this->assertEquals(16484, $entry['size'], 'Folder size should sum on-disk sizes (8192 + 8292)');
325336
}
326337

327338
public function testRootFolderSizeForNonHomeStorage(): void {

0 commit comments

Comments
 (0)