From d1977b8d25030181ee7e115005f35b25654b1ecc Mon Sep 17 00:00:00 2001 From: provokateurin Date: Tue, 1 Oct 2024 15:07:36 +0200 Subject: refactor(Stream\Encryption): Migrate to strong types Signed-off-by: provokateurin --- tests/lib/Files/Stream/EncryptionTest.php | 64 ++++++++++++++++++------------- 1 file changed, 38 insertions(+), 26 deletions(-) (limited to 'tests/lib') diff --git a/tests/lib/Files/Stream/EncryptionTest.php b/tests/lib/Files/Stream/EncryptionTest.php index 419c1a752d0..36e72ea764a 100644 --- a/tests/lib/Files/Stream/EncryptionTest.php +++ b/tests/lib/Files/Stream/EncryptionTest.php @@ -1,4 +1,7 @@ $wrapper * @return resource */ - protected function getStream($fileName, $mode, $unencryptedSize, $wrapper = self::DEFAULT_WRAPPER, $unencryptedSizeOnClose = 0) { + protected function getStream(string $fileName, string $mode, int $unencryptedSize, string $wrapper = self::DEFAULT_WRAPPER, int $unencryptedSizeOnClose = 0) { clearstatcache(); $size = filesize($fileName); $source = fopen($fileName, $mode); @@ -74,23 +77,39 @@ class EncryptionTest extends \Test\TestCase { $cache->expects($this->any())->method('get')->willReturn($entry); $cache->expects($this->any())->method('update')->with(5, ['encrypted' => 3, 'encryptedVersion' => 3, 'unencrypted_size' => $unencryptedSizeOnClose]); - - return $wrapper::wrap($source, $internalPath, - $fullPath, $header, $uid, $this->encryptionModule, $storage, $encStorage, - $util, $file, $mode, $size, $unencryptedSize, 8192, $wrapper); + return $wrapper::wrap( + $source, + $internalPath, + $fullPath, + $header, + $uid, + $this->encryptionModule, + $storage, + $encStorage, + $util, + $file, + $mode, + $size, + $unencryptedSize, + 8192, + true, + $wrapper, + ); } /** * @dataProvider dataProviderStreamOpen() */ - public function testStreamOpen($isMasterKeyUsed, + public function testStreamOpen( + $isMasterKeyUsed, $mode, $fullPath, $fileExists, $expectedSharePath, $expectedSize, $expectedUnencryptedSize, - $expectedReadOnly): void { + $expectedReadOnly, + ): void { // build mocks $encryptionModuleMock = $this->getMockBuilder('\OCP\Encryption\IEncryptionModule') ->disableOriginalConstructor()->getMock(); @@ -98,7 +117,7 @@ class EncryptionTest extends \Test\TestCase { $encryptionModuleMock->expects($this->once()) ->method('getUnencryptedBlockSize')->willReturn(99); $encryptionModuleMock->expects($this->once()) - ->method('begin')->willReturn(true); + ->method('begin')->willReturn([]); $storageMock = $this->getMockBuilder('\OC\Files\Storage\Storage') ->disableOriginalConstructor()->getMock(); @@ -152,6 +171,8 @@ class EncryptionTest extends \Test\TestCase { $header->setValue($streamWrapper, []); $header->setAccessible(false); $this->invokePrivate($streamWrapper, 'signed', [true]); + $this->invokePrivate($streamWrapper, 'internalPath', [$fullPath]); + $this->invokePrivate($streamWrapper, 'uid', ['test']); // call stream_open, that's the method we want to test $dummyVar = 'foo'; @@ -160,23 +181,17 @@ class EncryptionTest extends \Test\TestCase { // check internal properties $size = $stream->getProperty('size'); $size->setAccessible(true); - $this->assertSame($expectedSize, - $size->getValue($streamWrapper) - ); + $this->assertSame($expectedSize, $size->getValue($streamWrapper)); $size->setAccessible(false); $unencryptedSize = $stream->getProperty('unencryptedSize'); $unencryptedSize->setAccessible(true); - $this->assertSame($expectedUnencryptedSize, - $unencryptedSize->getValue($streamWrapper) - ); + $this->assertSame($expectedUnencryptedSize, $unencryptedSize->getValue($streamWrapper)); $unencryptedSize->setAccessible(false); $readOnly = $stream->getProperty('readOnly'); $readOnly->setAccessible(true); - $this->assertSame($expectedReadOnly, - $readOnly->getValue($streamWrapper) - ); + $this->assertSame($expectedReadOnly, $readOnly->getValue($streamWrapper)); $readOnly->setAccessible(false); } @@ -335,10 +350,7 @@ class EncryptionTest extends \Test\TestCase { unlink($fileName); } - /** - * @return \PHPUnit\Framework\MockObject\MockObject - */ - protected function buildMockModule() { + protected function buildMockModule(): IEncryptionModule&MockObject { $encryptionModule = $this->getMockBuilder('\OCP\Encryption\IEncryptionModule') ->disableOriginalConstructor() ->setMethods(['getId', 'getDisplayName', 'begin', 'end', 'encrypt', 'decrypt', 'update', 'shouldEncrypt', 'getUnencryptedBlockSize', 'isReadable', 'encryptAll', 'prepareDecryptAll', 'isReadyForUser', 'needDetailedAccessList']) -- cgit v1.2.3