From c2e2b5704dfa5ee2a1196e8bea9fe447e5be1297 Mon Sep 17 00:00:00 2001 From: Stephen Cuppett Date: Wed, 29 Apr 2026 11:59:09 -0400 Subject: [PATCH] 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) Signed-off-by: Stephen Cuppett --- tests/lib/TestCase.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/lib/TestCase.php b/tests/lib/TestCase.php index aed919a1e6fe0..b9e5dfc5500e3 100644 --- a/tests/lib/TestCase.php +++ b/tests/lib/TestCase.php @@ -27,6 +27,7 @@ use OCP\Command\IBus; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\Files\IRootFolder; +use OCP\IAppConfig; use OCP\IConfig; use OCP\IDBConnection; use OCP\IUserManager; @@ -195,6 +196,22 @@ protected function tearDown(): void { call_user_func([$this, $methodName]); } } + + // Clean up encryption state to prevent test pollution + // This ensures encryption_enabled is reset after each test, preventing + // MultiKeyEncryptException failures in subsequent tests when encryption + // is left enabled but user keys don't exist + try { + $appConfig = Server::get(IAppConfig::class); + $currentValue = $appConfig->getValueBool('core', 'encryption_enabled', false); + if ($currentValue) { + $appConfig->setValueBool('core', 'encryption_enabled', false); + $appConfig->deleteKey('core', 'default_encryption_module'); + $appConfig->deleteKey('encryption', 'useMasterKey'); + } + } catch (\Throwable $e) { + // Ignore - may be called before bootstrap completes + } } /**