Skip to content

Commit 41ca989

Browse files
susnuxclaude
andcommitted
fix(encryption): keep the encryption_enabled app config untyped
decrypt-all wrote core/encryption_enabled through the typed app config while every other accessor on this branch - Manager::isEnabled(), encryption:enable, encryption:disable and the provisioning API - reads and writes it as the string "yes"/"no". The first decrypt-all therefore switched the stored type to boolean, after which encryption:enable threw an AppConfigTypeConflictException and isEnabled() no longer recognised the value. Assisted-by: ClaudeCode:claude-opus-5 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent 12773ee commit 41ca989

2 files changed

Lines changed: 26 additions & 36 deletions

File tree

‎core/Command/Encryption/DecryptAll.php‎

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

1111
use OCP\App\IAppManager;
12-
use OCP\IAppConfig;
1312
use OCP\IConfig;
1413
use Symfony\Component\Console\Command\Command;
1514
use Symfony\Component\Console\Helper\QuestionHelper;
@@ -25,7 +24,6 @@ class DecryptAll extends Command {
2524
public function __construct(
2625
protected IAppManager $appManager,
2726
protected IConfig $config,
28-
protected IAppConfig $appConfig,
2927
protected \OC\Encryption\DecryptAll $decryptAll,
3028
protected QuestionHelper $questionHelper,
3129
) {
@@ -89,11 +87,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8987
return 1;
9088
}
9189

92-
$originallyEnabled = $this->appConfig->getValueBool('core', 'encryption_enabled');
90+
$originallyEnabled = $this->config->getAppValue('core', 'encryption_enabled', 'no') === 'yes';
9391
try {
9492
if ($originallyEnabled) {
9593
$output->write('Disable server side encryption... ');
96-
$this->appConfig->setValueBool('core', 'encryption_enabled', false);
94+
$this->config->setAppValue('core', 'encryption_enabled', 'no');
9795
$output->writeln('done.');
9896
} else {
9997
$output->writeln('Server side encryption not enabled. Nothing to do.');
@@ -121,26 +119,26 @@ protected function execute(InputInterface $input, OutputInterface $output): int
121119
$output->writeln(' aborted.');
122120
if ($originallyEnabled) {
123121
$output->writeln('Server side encryption remains enabled');
124-
$this->appConfig->setValueBool('core', 'encryption_enabled', true);
122+
$this->config->setAppValue('core', 'encryption_enabled', 'yes');
125123
}
126124
} elseif (($uid !== '') && $originallyEnabled) {
127125
$output->writeln('Server side encryption remains enabled');
128-
$this->appConfig->setValueBool('core', 'encryption_enabled', true);
126+
$this->config->setAppValue('core', 'encryption_enabled', 'yes');
129127
}
130128
$this->resetMaintenanceAndTrashbin();
131129
return 0;
132130
}
133131
if ($originallyEnabled) {
134132
$output->write('Enable server side encryption... ');
135-
$this->appConfig->setValueBool('core', 'encryption_enabled', true);
133+
$this->config->setAppValue('core', 'encryption_enabled', 'yes');
136134
$output->writeln('done.');
137135
}
138136
$output->writeln('aborted');
139137
return 1;
140138
} catch (\Exception $e) {
141139
// enable server side encryption again if something went wrong
142140
if ($originallyEnabled) {
143-
$this->appConfig->setValueBool('core', 'encryption_enabled', true);
141+
$this->config->setAppValue('core', 'encryption_enabled', 'yes');
144142
}
145143
$this->resetMaintenanceAndTrashbin();
146144
throw $e;

‎tests/Core/Command/Encryption/DecryptAllTest.php‎

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
use OC\Core\Command\Encryption\DecryptAll;
1212
use OCP\App\IAppManager;
13-
use OCP\IAppConfig;
1413
use OCP\IConfig;
1514
use PHPUnit\Framework\MockObject\MockObject;
1615
use Symfony\Component\Console\Helper\QuestionHelper;
@@ -20,7 +19,6 @@
2019

2120
class DecryptAllTest extends TestCase {
2221
private MockObject&IConfig $config;
23-
private MockObject&IAppConfig $appConfig;
2422
private MockObject&IAppManager $appManager;
2523
private MockObject&InputInterface $consoleInput;
2624
private MockObject&OutputInterface $consoleOutput;
@@ -31,7 +29,6 @@ protected function setUp(): void {
3129
parent::setUp();
3230

3331
$this->config = $this->createMock(IConfig::class);
34-
$this->appConfig = $this->createMock(IAppConfig::class);
3532
$this->appManager = $this->createMock(IAppManager::class);
3633
$this->questionHelper = $this->createMock(QuestionHelper::class);
3734
$this->decryptAll = $this->createMock(\OC\Encryption\DecryptAll::class);
@@ -74,7 +71,6 @@ public function testMaintenanceAndTrashbin(): void {
7471
$instance = new DecryptAll(
7572
$this->appManager,
7673
$this->config,
77-
$this->appConfig,
7874
$this->decryptAll,
7975
$this->questionHelper
8076
);
@@ -95,15 +91,14 @@ public function testExecute($encryptionEnabled, $continue): void {
9591
$instance = new DecryptAll(
9692
$this->appManager,
9793
$this->config,
98-
$this->appConfig,
9994
$this->decryptAll,
10095
$this->questionHelper
10196
);
10297

103-
$this->appConfig->expects($this->once())
104-
->method('getValueBool')
105-
->with('core', 'encryption_enabled')
106-
->willReturn($encryptionEnabled);
98+
$this->config->expects($this->once())
99+
->method('getAppValue')
100+
->with('core', 'encryption_enabled', 'no')
101+
->willReturn($encryptionEnabled ? 'yes' : 'no');
107102

108103
$this->consoleInput->expects($this->any())
109104
->method('getArgument')
@@ -112,19 +107,18 @@ public function testExecute($encryptionEnabled, $continue): void {
112107

113108
if ($encryptionEnabled) {
114109
$calls = [
115-
['core', 'encryption_enabled', false, false],
116-
['core', 'encryption_enabled', true, false],
110+
['core', 'encryption_enabled', 'no'],
111+
['core', 'encryption_enabled', 'yes'],
117112
];
118-
$this->appConfig->expects($this->exactly(count($calls)))
119-
->method('setValueBool')
120-
->willReturnCallback(function () use (&$calls): bool {
113+
$this->config->expects($this->exactly(count($calls)))
114+
->method('setAppValue')
115+
->willReturnCallback(function () use (&$calls): void {
121116
$expected = array_shift($calls);
122117
$this->assertEquals($expected, func_get_args());
123-
return true;
124118
});
125119
} else {
126-
$this->appConfig->expects($this->never())
127-
->method('setValueBool');
120+
$this->config->expects($this->never())
121+
->method('setAppValue');
128122
}
129123
$this->questionHelper->expects($this->once())
130124
->method('ask')
@@ -156,27 +150,25 @@ public function testExecuteFailure(): void {
156150
$instance = new DecryptAll(
157151
$this->appManager,
158152
$this->config,
159-
$this->appConfig,
160153
$this->decryptAll,
161154
$this->questionHelper
162155
);
163156

164157
// make sure that we enable encryption again after a exception was thrown
165158
$calls = [
166-
['core', 'encryption_enabled', false, false],
167-
['core', 'encryption_enabled', true, false],
159+
['core', 'encryption_enabled', 'no'],
160+
['core', 'encryption_enabled', 'yes'],
168161
];
169-
$this->appConfig->expects($this->exactly(2))
170-
->method('setValuebool')
171-
->willReturnCallback(function () use (&$calls): bool {
162+
$this->config->expects($this->exactly(2))
163+
->method('setAppValue')
164+
->willReturnCallback(function () use (&$calls): void {
172165
$expected = array_shift($calls);
173166
$this->assertEquals($expected, func_get_args());
174-
return true;
175167
});
176-
$this->appConfig->expects($this->once())
177-
->method('getValueBool')
178-
->with('core', 'encryption_enabled')
179-
->willReturn(true);
168+
$this->config->expects($this->once())
169+
->method('getAppValue')
170+
->with('core', 'encryption_enabled', 'no')
171+
->willReturn('yes');
180172

181173
$this->consoleInput->expects($this->any())
182174
->method('getArgument')

0 commit comments

Comments
 (0)