Skip to content

Commit 5531957

Browse files
committed
test: add tests for encryptedVersion cache entry preservation
Signed-off-by: Kent Delante <kent@delante.me> Assisted-by: ClaudeCode:claude-sonnet-5
1 parent 3c0c332 commit 5531957

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
@@ -540,6 +540,49 @@ public function testMoveFromCacheJail(): void {
540540
$this->assertEquals($this->cache->getId(''), $this->cache->get('targetsub')->getParentId());
541541
}
542542

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

0 commit comments

Comments
 (0)