From d8d53d39a4f46a6b150d13dd662195f0e9d385aa Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Tue, 10 Nov 2020 20:58:24 +0100 Subject: [PATCH 1/2] Move encryption from app.php to IBootstrap Signed-off-by: Morris Jobke --- apps/encryption/appinfo/app.php | 39 --------------------- apps/encryption/lib/AppInfo/Application.php | 21 ++++++++++- tests/lib/Traits/EncryptionTrait.php | 2 ++ 3 files changed, 22 insertions(+), 40 deletions(-) delete mode 100644 apps/encryption/appinfo/app.php diff --git a/apps/encryption/appinfo/app.php b/apps/encryption/appinfo/app.php deleted file mode 100644 index 5fd5f628de0c3..0000000000000 --- a/apps/encryption/appinfo/app.php +++ /dev/null @@ -1,39 +0,0 @@ - - * @author Christoph Wurst - * @author Clark Tomlinson - * @author Morris Jobke - * - * @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 - * - */ - -namespace OCA\Encryption\AppInfo; - -\OCP\Util::addscript('encryption', 'encryption'); - -$encryptionManager = \OC::$server->getEncryptionManager(); -$encryptionSystemReady = $encryptionManager->isReady(); - -/** @var Application $app */ -$app = \OC::$server->query(Application::class); -if ($encryptionSystemReady) { - $app->registerEncryptionModule($encryptionManager); - $app->registerHooks(\OC::$server->getConfig()); - $app->setUp($encryptionManager); -} diff --git a/apps/encryption/lib/AppInfo/Application.php b/apps/encryption/lib/AppInfo/Application.php index ac0f2ededd246..78df1183f9260 100644 --- a/apps/encryption/lib/AppInfo/Application.php +++ b/apps/encryption/lib/AppInfo/Application.php @@ -39,10 +39,14 @@ use OCA\Encryption\Session; use OCA\Encryption\Users\Setup; use OCA\Encryption\Util; +use OCP\AppFramework\Bootstrap\IBootContext; +use OCP\AppFramework\Bootstrap\IBootstrap; +use OCP\AppFramework\Bootstrap\IRegistrationContext; use OCP\Encryption\IManager; use OCP\IConfig; -class Application extends \OCP\AppFramework\App { +class Application extends \OCP\AppFramework\App implements IBootstrap { + /** * @param array $urlParams */ @@ -106,4 +110,19 @@ function () use ($container) { ); }); } + + public function register(IRegistrationContext $context): void { + } + + public function boot(IBootContext $context): void { + $encryptionManager = $context->getServerContainer()->getEncryptionManager(); + $encryptionSystemReady = $encryptionManager->isReady(); + + if ($encryptionSystemReady) { + $this->registerEncryptionModule($encryptionManager); + $this->registerHooks(\OC::$server->getConfig()); + $this->setUp($encryptionManager); + } + \OCP\Util::addScript('encryption', 'encryption'); + } } diff --git a/tests/lib/Traits/EncryptionTrait.php b/tests/lib/Traits/EncryptionTrait.php index 6b74f7ca8eee3..4a5cb11065c0f 100644 --- a/tests/lib/Traits/EncryptionTrait.php +++ b/tests/lib/Traits/EncryptionTrait.php @@ -12,6 +12,7 @@ use OC\Files\Filesystem; use OC\Memcache\ArrayCache; use OCA\Encryption\AppInfo\Application; +use OCA\Encryption\Crypto\Encryption; use OCA\Encryption\KeyManager; use OCA\Encryption\Users\Setup; use OCP\Encryption\IManager; @@ -104,5 +105,6 @@ protected function tearDownEncryptionTrait() { $this->config->setAppValue('core', 'default_encryption_module', $this->originalEncryptionModule); $this->config->deleteAppValue('encryption', 'useMasterKey'); } + \OC::$server->getEncryptionManager()->unregisterEncryptionModule(Encryption::ID); } } From 3a16762df61c16dff457c9fa69fff7ebcfdfce93 Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Sun, 22 Nov 2020 23:21:16 +0100 Subject: [PATCH 2/2] Move app loading in encryption trait below config value changes Signed-off-by: Morris Jobke --- tests/lib/Traits/EncryptionTrait.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/lib/Traits/EncryptionTrait.php b/tests/lib/Traits/EncryptionTrait.php index 4a5cb11065c0f..506a7c6050315 100644 --- a/tests/lib/Traits/EncryptionTrait.php +++ b/tests/lib/Traits/EncryptionTrait.php @@ -87,15 +87,16 @@ protected function setUpEncryptionTrait() { $this->markTestSkipped('Encryption not ready'); } - \OC_App::loadApp('encryption'); - - $this->encryptionApp = new Application([], $isReady); - $this->config = \OC::$server->getConfig(); $this->encryptionWasEnabled = $this->config->getAppValue('core', 'encryption_enabled', 'no'); $this->originalEncryptionModule = $this->config->getAppValue('core', 'default_encryption_module'); $this->config->setAppValue('core', 'default_encryption_module', \OCA\Encryption\Crypto\Encryption::ID); $this->config->setAppValue('core', 'encryption_enabled', 'yes'); + + \OC_App::loadApp('encryption'); + + $this->encryptionApp = new Application(); + $this->assertTrue(\OC::$server->getEncryptionManager()->isEnabled()); }