Skip to content

Commit c2e2b57

Browse files
cuppettclaude
andcommitted
fix(tests): Fix encryption test isolation between test runs
Add global encryption teardown to TestCase base class so encryption state does not leak between test suites regardless of which tests ran earlier. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Stephen Cuppett <steve@cuppett.com>
1 parent b81a45b commit c2e2b57

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

tests/lib/TestCase.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
use OCP\Command\IBus;
2828
use OCP\DB\QueryBuilder\IQueryBuilder;
2929
use OCP\Files\IRootFolder;
30+
use OCP\IAppConfig;
3031
use OCP\IConfig;
3132
use OCP\IDBConnection;
3233
use OCP\IUserManager;
@@ -195,6 +196,22 @@ protected function tearDown(): void {
195196
call_user_func([$this, $methodName]);
196197
}
197198
}
199+
200+
// Clean up encryption state to prevent test pollution
201+
// This ensures encryption_enabled is reset after each test, preventing
202+
// MultiKeyEncryptException failures in subsequent tests when encryption
203+
// is left enabled but user keys don't exist
204+
try {
205+
$appConfig = Server::get(IAppConfig::class);
206+
$currentValue = $appConfig->getValueBool('core', 'encryption_enabled', false);
207+
if ($currentValue) {
208+
$appConfig->setValueBool('core', 'encryption_enabled', false);
209+
$appConfig->deleteKey('core', 'default_encryption_module');
210+
$appConfig->deleteKey('encryption', 'useMasterKey');
211+
}
212+
} catch (\Throwable $e) {
213+
// Ignore - may be called before bootstrap completes
214+
}
198215
}
199216

200217
/**

0 commit comments

Comments
 (0)