aboutsummaryrefslogtreecommitdiffstats
path: root/apps/encryption/tests/Command
diff options
context:
space:
mode:
Diffstat (limited to 'apps/encryption/tests/Command')
-rw-r--r--apps/encryption/tests/Command/FixEncryptedVersionTest.php104
-rw-r--r--apps/encryption/tests/Command/TestEnableMasterKey.php43
2 files changed, 62 insertions, 85 deletions
diff --git a/apps/encryption/tests/Command/FixEncryptedVersionTest.php b/apps/encryption/tests/Command/FixEncryptedVersionTest.php
index 54e8b41ed6c..d0af359183b 100644
--- a/apps/encryption/tests/Command/FixEncryptedVersionTest.php
+++ b/apps/encryption/tests/Command/FixEncryptedVersionTest.php
@@ -1,22 +1,11 @@
<?php
+
+declare(strict_types=1);
+
/**
- * @author Sujith Haridasan <sharidasan@owncloud.com>
- *
- * @copyright Copyright (c) 2019, ownCloud GmbH
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2021-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2019 ownCloud GmbH
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OCA\Encryption\Tests\Command;
@@ -24,6 +13,12 @@ namespace OCA\Encryption\Tests\Command;
use OC\Files\View;
use OCA\Encryption\Command\FixEncryptedVersion;
use OCA\Encryption\Util;
+use OCP\Files\IRootFolder;
+use OCP\IConfig;
+use OCP\ITempManager;
+use OCP\IUserManager;
+use OCP\Server;
+use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Tester\CommandTester;
use Test\TestCase;
@@ -42,21 +37,18 @@ class FixEncryptedVersionTest extends TestCase {
use EncryptionTrait;
use UserTrait;
- private $userId;
+ private string $userId;
- /** @var FixEncryptedVersion */
- private $fixEncryptedVersion;
+ private FixEncryptedVersion $fixEncryptedVersion;
- /** @var CommandTester */
- private $commandTester;
+ private CommandTester $commandTester;
- /** @var Util|\PHPUnit\Framework\MockObject\MockObject */
- protected $util;
+ protected Util&MockObject $util;
public function setUp(): void {
parent::setUp();
- \OC::$server->getConfig()->setAppValue('encryption', 'useMasterKey', '1');
+ Server::get(IConfig::class)->setAppValue('encryption', 'useMasterKey', '1');
$this->util = $this->getMockBuilder(Util::class)
->disableOriginalConstructor()->getMock();
@@ -64,35 +56,35 @@ class FixEncryptedVersionTest extends TestCase {
$this->userId = $this->getUniqueId('user_');
$this->createUser($this->userId, 'foo12345678');
- $tmpFolder = \OC::$server->getTempManager()->getTemporaryFolder();
+ $tmpFolder = Server::get(ITempManager::class)->getTemporaryFolder();
$this->registerMount($this->userId, '\OC\Files\Storage\Local', '/' . $this->userId, ['datadir' => $tmpFolder]);
$this->setupForUser($this->userId, 'foo12345678');
$this->loginWithEncryption($this->userId);
$this->fixEncryptedVersion = new FixEncryptedVersion(
- \OC::$server->getConfig(),
- \OC::$server->get(LoggerInterface::class),
- \OC::$server->getRootFolder(),
- \OC::$server->getUserManager(),
+ Server::get(IConfig::class),
+ Server::get(LoggerInterface::class),
+ Server::get(IRootFolder::class),
+ Server::get(IUserManager::class),
$this->util,
new View('/')
);
$this->commandTester = new CommandTester($this->fixEncryptedVersion);
- $this->assertTrue(\OC::$server->getEncryptionManager()->isEnabled());
- $this->assertTrue(\OC::$server->getEncryptionManager()->isReady());
- $this->assertTrue(\OC::$server->getEncryptionManager()->isReadyForUser($this->userId));
+ $this->assertTrue(Server::get(\OCP\Encryption\IManager::class)->isEnabled());
+ $this->assertTrue(Server::get(\OCP\Encryption\IManager::class)->isReady());
+ $this->assertTrue(Server::get(\OCP\Encryption\IManager::class)->isReadyForUser($this->userId));
}
/**
* In this test the encrypted version of the file is less than the original value
* but greater than zero
*/
- public function testEncryptedVersionLessThanOriginalValue() {
+ public function testEncryptedVersionLessThanOriginalValue(): void {
$this->util->expects($this->once())->method('isMasterKeyEnabled')
->willReturn(true);
- $view = new View("/" . $this->userId . "/files");
+ $view = new View('/' . $this->userId . '/files');
$view->touch('hello.txt');
$view->touch('world.txt');
@@ -156,11 +148,11 @@ Fixed the file: \"/$this->userId/files/world.txt\" with version 4", $output);
* In this test the encrypted version of the file is greater than the original value
* but greater than zero
*/
- public function testEncryptedVersionGreaterThanOriginalValue() {
+ public function testEncryptedVersionGreaterThanOriginalValue(): void {
$this->util->expects($this->once())->method('isMasterKeyEnabled')
->willReturn(true);
- $view = new View("/" . $this->userId . "/files");
+ $view = new View('/' . $this->userId . '/files');
$view->touch('hello.txt');
$view->touch('world.txt');
@@ -215,11 +207,11 @@ The file \"/$this->userId/files/world.txt\" is: OK
Fixed the file: \"/$this->userId/files/world.txt\" with version 4", $output);
}
- public function testVersionIsRestoredToOriginalIfNoFixIsFound() {
+ public function testVersionIsRestoredToOriginalIfNoFixIsFound(): void {
$this->util->expects($this->once())->method('isMasterKeyEnabled')
->willReturn(true);
- $view = new View("/" . $this->userId . "/files");
+ $view = new View('/' . $this->userId . '/files');
$view->touch('bar.txt');
for ($i = 0; $i < 40; $i++) {
@@ -240,16 +232,16 @@ Fixed the file: \"/$this->userId/files/world.txt\" with version 4", $output);
]);
$cacheInfo = $cache->get($fileInfo->getId());
- $encryptedVersion = $cacheInfo["encryptedVersion"];
+ $encryptedVersion = $cacheInfo['encryptedVersion'];
$this->assertEquals(15, $encryptedVersion);
}
- public function testRepairUnencryptedFileWhenVersionIsSet() {
+ public function testRepairUnencryptedFileWhenVersionIsSet(): void {
$this->util->expects($this->once())->method('isMasterKeyEnabled')
->willReturn(true);
- $view = new View("/" . $this->userId . "/files");
+ $view = new View('/' . $this->userId . '/files');
// create a file, it's encrypted and also the version is set in the database
$view->touch('hello.txt');
@@ -264,7 +256,7 @@ Fixed the file: \"/$this->userId/files/world.txt\" with version 4", $output);
$cacheInfo = ['encryptedVersion' => 1, 'encrypted' => 1];
$cache1->put($fileCache1->getPath(), $cacheInfo);
- $absPath = $storage1->getSourcePath('').$fileInfo1->getInternalPath();
+ $absPath = $storage1->getSourcePath('') . $fileInfo1->getInternalPath();
// create unencrypted file on disk, the version stays
file_put_contents($absPath, 'hello contents');
@@ -288,18 +280,18 @@ Fixed the file: \"/$this->userId/files/hello.txt\" with version 0 (unencrypted)"
/**
* Test commands with a file path
*/
- public function testExecuteWithFilePathOption() {
+ public function testExecuteWithFilePathOption(): void {
$this->util->expects($this->once())->method('isMasterKeyEnabled')
->willReturn(true);
- $view = new View("/" . $this->userId . "/files");
+ $view = new View('/' . $this->userId . '/files');
$view->touch('hello.txt');
$view->touch('world.txt');
$this->commandTester->execute([
'user' => $this->userId,
- '--path' => "/hello.txt"
+ '--path' => '/hello.txt'
]);
$output = $this->commandTester->getDisplay();
@@ -312,11 +304,11 @@ The file \"/$this->userId/files/hello.txt\" is: OK", $output);
/**
* Test commands with a directory path
*/
- public function testExecuteWithDirectoryPathOption() {
+ public function testExecuteWithDirectoryPathOption(): void {
$this->util->expects($this->once())->method('isMasterKeyEnabled')
->willReturn(true);
- $view = new View("/" . $this->userId . "/files");
+ $view = new View('/' . $this->userId . '/files');
$view->mkdir('sub');
$view->touch('sub/hello.txt');
@@ -324,7 +316,7 @@ The file \"/$this->userId/files/hello.txt\" is: OK", $output);
$this->commandTester->execute([
'user' => $this->userId,
- '--path' => "/sub"
+ '--path' => '/sub'
]);
$output = $this->commandTester->getDisplay();
@@ -334,13 +326,13 @@ The file \"/$this->userId/files/sub/hello.txt\" is: OK", $output);
$this->assertStringNotContainsString('world.txt', $output);
}
- public function testExecuteWithNoUser() {
+ public function testExecuteWithNoUser(): void {
$this->util->expects($this->once())->method('isMasterKeyEnabled')
->willReturn(true);
$this->commandTester->execute([
'user' => null,
- '--path' => "/"
+ '--path' => '/'
]);
$output = $this->commandTester->getDisplay();
@@ -348,13 +340,13 @@ The file \"/$this->userId/files/sub/hello.txt\" is: OK", $output);
$this->assertStringContainsString('Either a user id or --all needs to be provided', $output);
}
- public function testExecuteWithBadUser() {
+ public function testExecuteWithBadUser(): void {
$this->util->expects($this->once())->method('isMasterKeyEnabled')
->willReturn(true);
$this->commandTester->execute([
'user' => 'nonexisting',
- '--path' => "/"
+ '--path' => '/'
]);
$output = $this->commandTester->getDisplay();
@@ -365,7 +357,7 @@ The file \"/$this->userId/files/sub/hello.txt\" is: OK", $output);
/**
* Test commands with a directory path
*/
- public function testExecuteWithNonExistentPath() {
+ public function testExecuteWithNonExistentPath(): void {
$this->util->expects($this->once())->method('isMasterKeyEnabled')
->willReturn(true);
@@ -382,8 +374,8 @@ The file \"/$this->userId/files/sub/hello.txt\" is: OK", $output);
/**
* Test commands without master key
*/
- public function testExecuteWithNoMasterKey() {
- \OC::$server->getConfig()->setAppValue('encryption', 'useMasterKey', '0');
+ public function testExecuteWithNoMasterKey(): void {
+ Server::get(IConfig::class)->setAppValue('encryption', 'useMasterKey', '0');
$this->util->expects($this->once())->method('isMasterKeyEnabled')
->willReturn(false);
diff --git a/apps/encryption/tests/Command/TestEnableMasterKey.php b/apps/encryption/tests/Command/TestEnableMasterKey.php
index 269e99eae4b..ead3dfd0195 100644
--- a/apps/encryption/tests/Command/TestEnableMasterKey.php
+++ b/apps/encryption/tests/Command/TestEnableMasterKey.php
@@ -1,26 +1,11 @@
<?php
+
+declare(strict_types=1);
+
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Björn Schießle <bjoern@schiessle.org>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OCA\Encryption\Tests\Command;
@@ -34,22 +19,22 @@ use Test\TestCase;
class TestEnableMasterKey extends TestCase {
- /** @var EnableMasterKey */
+ /** @var EnableMasterKey */
protected $enableMasterKey;
- /** @var Util | \PHPUnit\Framework\MockObject\MockObject */
+ /** @var Util | \PHPUnit\Framework\MockObject\MockObject */
protected $util;
- /** @var \OCP\IConfig | \PHPUnit\Framework\MockObject\MockObject */
+ /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
protected $config;
/** @var \Symfony\Component\Console\Helper\QuestionHelper | \PHPUnit\Framework\MockObject\MockObject */
protected $questionHelper;
- /** @var \Symfony\Component\Console\Output\OutputInterface | \PHPUnit\Framework\MockObject\MockObject */
+ /** @var \Symfony\Component\Console\Output\OutputInterface | \PHPUnit\Framework\MockObject\MockObject */
protected $output;
- /** @var \Symfony\Component\Console\Input\InputInterface | \PHPUnit\Framework\MockObject\MockObject */
+ /** @var \Symfony\Component\Console\Input\InputInterface | \PHPUnit\Framework\MockObject\MockObject */
protected $input;
protected function setUp(): void {
@@ -70,12 +55,12 @@ class TestEnableMasterKey extends TestCase {
}
/**
- * @dataProvider dataTestExecute
*
* @param bool $isAlreadyEnabled
* @param string $answer
*/
- public function testExecute($isAlreadyEnabled, $answer) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataTestExecute')]
+ public function testExecute($isAlreadyEnabled, $answer): void {
$this->util->expects($this->once())->method('isMasterKeyEnabled')
->willReturn($isAlreadyEnabled);
@@ -96,7 +81,7 @@ class TestEnableMasterKey extends TestCase {
$this->invokePrivate($this->enableMasterKey, 'execute', [$this->input, $this->output]);
}
- public function dataTestExecute() {
+ public static function dataTestExecute() {
return [
[true, ''],
[false, 'y'],