Skip to content

Commit 4373eef

Browse files
committed
fix(encryption): Use typed IAppConfig methods to prevent type conflicts
Fixes AppConfigTypeConflictException when setting encryption configuration values. The deprecated setAppValue()/getAppValue() methods default to MIXED type, which conflicts with existing STRING type values in the database. Changes: - core/Command/Encryption/Enable: Use setValueString/getValueString - core/Command/Encryption/Disable: Use setValueString/getValueString - tests/lib/Traits/EncryptionTrait: Use typed IAppConfig methods This resolves all 29 test failures in the PRIMARY-s3 PHPUnit test group where encryption setup was throwing type conflict exceptions. Signed-off-by: Stephen Cuppett <steve@cuppett.com>
1 parent d0f93be commit 4373eef

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

core/Command/Encryption/Disable.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88
namespace OC\Core\Command\Encryption;
99

10+
use OCP\IAppConfig;
1011
use OCP\IConfig;
1112
use Symfony\Component\Console\Command\Command;
1213
use Symfony\Component\Console\Input\InputInterface;
@@ -15,6 +16,7 @@
1516
class Disable extends Command {
1617
public function __construct(
1718
protected IConfig $config,
19+
protected IAppConfig $appConfig,
1820
) {
1921
parent::__construct();
2022
}
@@ -27,10 +29,10 @@ protected function configure() {
2729
}
2830

2931
protected function execute(InputInterface $input, OutputInterface $output): int {
30-
if ($this->config->getAppValue('core', 'encryption_enabled', 'no') !== 'yes') {
32+
if ($this->appConfig->getValueString('core', 'encryption_enabled', 'no') !== 'yes') {
3133
$output->writeln('Encryption is already disabled');
3234
} else {
33-
$this->config->setAppValue('core', 'encryption_enabled', 'no');
35+
$this->appConfig->setValueString('core', 'encryption_enabled', 'no');
3436
$output->writeln('<info>Encryption disabled</info>');
3537
}
3638
return 0;

core/Command/Encryption/Enable.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace OC\Core\Command\Encryption;
99

1010
use OCP\Encryption\IManager;
11+
use OCP\IAppConfig;
1112
use OCP\IConfig;
1213
use Symfony\Component\Console\Command\Command;
1314
use Symfony\Component\Console\Input\InputInterface;
@@ -16,6 +17,7 @@
1617
class Enable extends Command {
1718
public function __construct(
1819
protected IConfig $config,
20+
protected IAppConfig $appConfig,
1921
protected IManager $encryptionManager,
2022
) {
2123
parent::__construct();
@@ -29,10 +31,10 @@ protected function configure() {
2931
}
3032

3133
protected function execute(InputInterface $input, OutputInterface $output): int {
32-
if ($this->config->getAppValue('core', 'encryption_enabled', 'no') === 'yes') {
34+
if ($this->appConfig->getValueString('core', 'encryption_enabled', 'no') === 'yes') {
3335
$output->writeln('Encryption is already enabled');
3436
} else {
35-
$this->config->setAppValue('core', 'encryption_enabled', 'yes');
37+
$this->appConfig->setValueString('core', 'encryption_enabled', 'yes');
3638
$output->writeln('<info>Encryption enabled</info>');
3739
}
3840
$output->writeln('');
@@ -42,7 +44,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
4244
$output->writeln('<error>No encryption module is loaded</error>');
4345
return 1;
4446
}
45-
$defaultModule = $this->config->getAppValue('core', 'default_encryption_module');
47+
$defaultModule = $this->appConfig->getValueString('core', 'default_encryption_module', '');
4648
if ($defaultModule === '') {
4749
$output->writeln('<error>No default module is set</error>');
4850
return 1;

tests/lib/Traits/EncryptionTrait.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,18 +109,20 @@ protected function setUpEncryptionTrait() {
109109
$this->encryptionApp = new Application([], $isReady);
110110

111111
$this->config = Server::get(IConfig::class);
112-
$this->encryptionWasEnabled = $this->config->getAppValue('core', 'encryption_enabled', 'no');
113-
$this->originalEncryptionModule = $this->config->getAppValue('core', 'default_encryption_module');
114-
$this->config->setAppValue('core', 'default_encryption_module', Encryption::ID);
115-
$this->config->setAppValue('core', 'encryption_enabled', 'yes');
112+
$appConfig = Server::get(\OCP\IAppConfig::class);
113+
$this->encryptionWasEnabled = $appConfig->getValueString('core', 'encryption_enabled', 'no');
114+
$this->originalEncryptionModule = $appConfig->getValueString('core', 'default_encryption_module', '');
115+
$appConfig->setValueString('core', 'default_encryption_module', Encryption::ID);
116+
$appConfig->setValueString('core', 'encryption_enabled', 'yes');
116117
$this->assertTrue(Server::get(\OCP\Encryption\IManager::class)->isEnabled());
117118
}
118119

119120
protected function tearDownEncryptionTrait() {
120121
if ($this->config) {
121-
$this->config->setAppValue('core', 'encryption_enabled', $this->encryptionWasEnabled);
122-
$this->config->setAppValue('core', 'default_encryption_module', $this->originalEncryptionModule);
123-
$this->config->deleteAppValue('encryption', 'useMasterKey');
122+
$appConfig = Server::get(\OCP\IAppConfig::class);
123+
$appConfig->setValueString('core', 'encryption_enabled', $this->encryptionWasEnabled);
124+
$appConfig->setValueString('core', 'default_encryption_module', $this->originalEncryptionModule);
125+
$appConfig->deleteKey('encryption', 'useMasterKey');
124126
}
125127
}
126128
}

0 commit comments

Comments
 (0)