use OC\Files\View;
use OC\HintException;
+use OCA\Encryption\Util;
use OCP\Files\IRootFolder;
use OCP\IConfig;
use OCP\ILogger;
/** @var IUserManager */
private $userManager;
+ /** @var Util */
+ private $util;
+
/** @var View */
private $view;
- public function __construct(IConfig $config, ILogger $logger, IRootFolder $rootFolder, IUserManager $userManager, View $view) {
+ public function __construct(
+ IConfig $config,
+ ILogger $logger,
+ IRootFolder $rootFolder,
+ IUserManager $userManager,
+ Util $util,
+ View $view
+ ) {
$this->config = $config;
$this->logger = $logger;
$this->rootFolder = $rootFolder;
$this->userManager = $userManager;
+ $this->util = $util;
$this->view = $view;
parent::__construct();
}
return 1;
}
+ if (!$this->util->isMasterKeyEnabled()) {
+ $output->writeln("<error>Repairing only works with master key encryption.</error>\n");
+ return 1;
+ }
+
$user = (string)$input->getArgument('user');
$pathToWalk = "/$user/files";
use OC\Files\View;
use OCA\Encryption\Command\FixEncryptedVersion;
+use OCA\Encryption\Util;
use Symfony\Component\Console\Tester\CommandTester;
use Test\TestCase;
use Test\Traits\EncryptionTrait;
/** @var CommandTester */
private $commandTester;
+ /** @var Util|\PHPUnit\Framework\MockObject\MockObject */
+ protected $util;
+
public function setUp(): void {
parent::setUp();
\OC::$server->getConfig()->setAppValue('encryption', 'useMasterKey', '1');
+ $this->util = $this->getMockBuilder(Util::class)
+ ->disableOriginalConstructor()->getMock();
+
$this->userId = $this->getUniqueId('user_');
$this->createUser($this->userId, 'foo12345678');
\OC::$server->getLogger(),
\OC::$server->getRootFolder(),
\OC::$server->getUserManager(),
+ $this->util,
new View('/')
);
$this->commandTester = new CommandTester($this->fixEncryptedVersion);
* but greater than zero
*/
public function testEncryptedVersionLessThanOriginalValue() {
+ $this->util->expects($this->once())->method('isMasterKeyEnabled')
+ ->willReturn(true);
+
$view = new View("/" . $this->userId . "/files");
$view->touch('hello.txt');
* but greater than zero
*/
public function testEncryptedVersionGreaterThanOriginalValue() {
+ $this->util->expects($this->once())->method('isMasterKeyEnabled')
+ ->willReturn(true);
+
$view = new View("/" . $this->userId . "/files");
$view->touch('hello.txt');
}
public function testVersionIsRestoredToOriginalIfNoFixIsFound() {
+ $this->util->expects($this->once())->method('isMasterKeyEnabled')
+ ->willReturn(true);
+
$view = new View("/" . $this->userId . "/files");
$view->touch('bar.txt');
* Test commands with a file path
*/
public function testExecuteWithFilePathOption() {
+ $this->util->expects($this->once())->method('isMasterKeyEnabled')
+ ->willReturn(true);
+
$view = new View("/" . $this->userId . "/files");
$view->touch('hello.txt');
* Test commands with a directory path
*/
public function testExecuteWithDirectoryPathOption() {
+ $this->util->expects($this->once())->method('isMasterKeyEnabled')
+ ->willReturn(true);
+
$view = new View("/" . $this->userId . "/files");
$view->mkdir('sub');
* Test commands with a directory path
*/
public function testExecuteWithNoUser() {
+ $this->util->expects($this->once())->method('isMasterKeyEnabled')
+ ->willReturn(true);
+
$this->commandTester->execute([
'user' => null,
'--path' => "/"
* Test commands with a directory path
*/
public function testExecuteWithNonExistentPath() {
+ $this->util->expects($this->once())->method('isMasterKeyEnabled')
+ ->willReturn(true);
+
$this->commandTester->execute([
'user' => $this->userId,
'--path' => '/non-exist'
$this->assertStringContainsString('Please provide a valid path.', $output);
}
+
+ /**
+ * Test commands without master key
+ */
+ public function testExecuteWithNoMasterKey() {
+ \OC::$server->getConfig()->setAppValue('encryption', 'useMasterKey', '0');
+ $this->util->expects($this->once())->method('isMasterKeyEnabled')
+ ->willReturn(false);
+
+ $this->commandTester->execute([
+ 'user' => $this->userId,
+ ]);
+
+ $output = $this->commandTester->getDisplay();
+
+ $this->assertStringContainsString('only works with master key', $output);
+ }
}