From aae426a26ee8a67402af7fe2214857b62fc58fd4 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 | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tests/Feature/LockFeatureTest.php b/tests/Feature/LockFeatureTest.php index 37706d95..aa0497e7 100644 --- a/tests/Feature/LockFeatureTest.php +++ b/tests/Feature/LockFeatureTest.php @@ -318,6 +318,33 @@ public function testLockDifferentAppsPublic() { }); } + public function testUnlockStaleClientLock() { + // 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);