From d755f47cc9da46e02cfeed5783f758b51fb395fd Mon Sep 17 00:00:00 2001 From: Julius Knorr Date: Wed, 27 Nov 2024 13:53:48 +0100 Subject: [PATCH] test: Add feature test for force unlock of automated locks Signed-off-by: Julius Knorr --- tests/Feature/LockFeatureTest.php | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/Feature/LockFeatureTest.php b/tests/Feature/LockFeatureTest.php index 8a8e46b7..49832c2b 100644 --- a/tests/Feature/LockFeatureTest.php +++ b/tests/Feature/LockFeatureTest.php @@ -304,6 +304,35 @@ public function testLockDifferentAppsPublic() { }); } + public function testUnlockStaleClientLock() { + \OCP\Server::get(IConfig::class)->setAppValue(Application::APP_ID, ConfigService::LOCK_TIMEOUT, '0'); + + // Create a file and lock it as the desktop client would + $file = $this->loginAndGetUserFolder(self::TEST_USER1)->newFile('test-file-client', 'AAA'); + $this->shareFileWithUser($file, self::TEST_USER1, self::TEST_USER2); + + $this->lockManager->lock(new LockContext($file, ILock::TYPE_TOKEN, self::TEST_USER1)); + $locks = $this->lockManager->getLocks($file->getId()); + $this->assertCount(1, $locks); + + // Other users cannot unlock + try { + $this->lockManager->unlock(new LockContext($file, ILock::TYPE_TOKEN, self::TEST_USER2)); + $locks = []; + } catch (\OCP\PreConditionNotMetException $e) { + $locks = $this->lockManager->getLocks($file->getId()); + } + $this->assertCount(1, $locks); + + + // The owner can stil force unlock it as done through the OCS controller + \OCP\Server::get(\OCA\FilesLock\Service\LockService::class)->enableUserOverride(); + $this->lockManager->unlock(new LockContext($file, ILock::TYPE_USER, self::TEST_USER1)); + + $locks = $this->lockManager->getLocks($file->getId()); + $this->assertCount(0, $locks); + } + private function loginAndGetUserFolder(string $userId) { $this->loginAsUser($userId); return $this->rootFolder->getUserFolder($userId);