aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib
diff options
context:
space:
mode:
authorprovokateurin <kate@provokateurin.de>2024-10-01 15:07:36 +0200
committerprovokateurin <kate@provokateurin.de>2024-10-07 14:02:27 +0200
commitd1977b8d25030181ee7e115005f35b25654b1ecc (patch)
treee5346b25d520580e05e8a48973687c7f3e1c47b4 /tests/lib
parentbbb6cb2eb01937ca5346b30b44e1969eb1eb0807 (diff)
downloadnextcloud-server-d1977b8d25030181ee7e115005f35b25654b1ecc.tar.gz
nextcloud-server-d1977b8d25030181ee7e115005f35b25654b1ecc.zip
refactor(Stream\Encryption): Migrate to strong types
Signed-off-by: provokateurin <kate@provokateurin.de>
Diffstat (limited to 'tests/lib')
-rw-r--r--tests/lib/Files/Stream/EncryptionTest.php64
1 files changed, 38 insertions, 26 deletions
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 @@
<?php
+
+declare(strict_types=1);
+
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -7,27 +10,27 @@
namespace Test\Files\Stream;
use OC\Files\Cache\CacheEntry;
+use OC\Files\Storage\Wrapper\Wrapper;
use OC\Files\View;
use OC\Memcache\ArrayCache;
+use OCP\Encryption\IEncryptionModule;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Cache\ICache;
use OCP\ICacheFactory;
use OCP\IConfig;
+use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
class EncryptionTest extends \Test\TestCase {
public const DEFAULT_WRAPPER = '\OC\Files\Stream\Encryption';
- /** @var \OCP\Encryption\IEncryptionModule | \PHPUnit\Framework\MockObject\MockObject */
- private $encryptionModule;
+ private IEncryptionModule&MockObject $encryptionModule;
/**
- * @param string $fileName
- * @param string $mode
- * @param integer $unencryptedSize
+ * @param class-string<Wrapper> $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'])