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 Nov 27, 2024
1 parent 258a756 commit d755f47
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/Feature/LockFeatureTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit d755f47

Please sign in to comment.