Skip to content

Commit dfd115e

Browse files
leftybournesbackportbot[bot]
authored andcommitted
test: add tests for encryptedVersion cache entry preservation
Signed-off-by: Kent Delante <kent@delante.me> Assisted-by: ClaudeCode:claude-sonnet-5
1 parent e69a7f6 commit dfd115e

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

tests/lib/Files/Cache/CacheTest.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,49 @@ public function testMoveFromCacheJail(): void {
543543
$this->assertEquals($this->cache->getId(''), $this->cache->get('targetsub')->getParentId());
544544
}
545545

546+
public function testCopyFromCachePreservesEncryptedVersion(): void {
547+
$data = [
548+
'size' => 100, 'mtime' => 50, 'mimetype' => 'foo/bar',
549+
'encrypted' => true, 'encryptedVersion' => 3,
550+
];
551+
$this->cache->put('source', $data);
552+
$sourceEntry = $this->cache->get('source');
553+
$this->assertSame(3, $sourceEntry['encryptedVersion']);
554+
555+
$this->cache->copyFromCache($this->cache, $sourceEntry, 'target');
556+
557+
$targetEntry = $this->cache->get('target');
558+
$this->assertTrue($targetEntry->isEncrypted());
559+
$this->assertSame(3, $targetEntry['encryptedVersion']);
560+
}
561+
562+
public function testCopyFromCacheClearsEncryptedVersionWhenCopyingToNonEncryptedStorage(): void {
563+
$data = [
564+
'size' => 100, 'mtime' => 50, 'mimetype' => 'foo/bar',
565+
'encrypted' => true, 'encryptedVersion' => 3,
566+
];
567+
$this->cache2->put('source', $data);
568+
$sourceEntry = $this->cache2->get('source');
569+
570+
$sourceCache = $this->getMockBuilder(Cache::class)
571+
->setConstructorArgs([$this->storage2])
572+
->onlyMethods(['hasEncryptionWrapper'])
573+
->getMock();
574+
$sourceCache->method('hasEncryptionWrapper')->willReturn(true);
575+
576+
$targetCache = $this->getMockBuilder(Cache::class)
577+
->setConstructorArgs([$this->storage])
578+
->onlyMethods(['shouldEncrypt'])
579+
->getMock();
580+
$targetCache->method('shouldEncrypt')->willReturn(false);
581+
582+
$targetCache->copyFromCache($sourceCache, $sourceEntry, 'target');
583+
584+
$targetEntry = $targetCache->get('target');
585+
$this->assertFalse($targetEntry->isEncrypted());
586+
$this->assertSame(0, $targetEntry['encryptedVersion']);
587+
}
588+
546589
public function testGetIncomplete(): void {
547590
$file1 = 'folder1';
548591
$file2 = 'folder2';

0 commit comments

Comments
 (0)