Skip to content

Commit

Permalink
test: Add feature test for force unlock of automated locks
Browse files Browse the repository at this point in the history
Signed-off-by: Julius Knorr <jus@bitgrid.net>
  • Loading branch information
juliusknorr committed Dec 4, 2024
1 parent 341d2a0 commit aae426a
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions tests/Feature/LockFeatureTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit aae426a

Please sign in to comment.