From d6f56ea609c41431458c0b565042caf945ab56cc Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 29 Jun 2015 19:13:39 +0200 Subject: lock parent folders for the owner when locking a shared file as recipient --- apps/files_sharing/tests/locking.php | 90 ++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 apps/files_sharing/tests/locking.php (limited to 'apps/files_sharing/tests') diff --git a/apps/files_sharing/tests/locking.php b/apps/files_sharing/tests/locking.php new file mode 100644 index 00000000000..46afbf294be --- /dev/null +++ b/apps/files_sharing/tests/locking.php @@ -0,0 +1,90 @@ + + * @author Robin Appelman + * @author Vincent Petry + * + * @copyright Copyright (c) 2015, ownCloud, Inc. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see + * + */ + +namespace OCA\Files_sharing\Tests; + +use OC\Files\Filesystem; +use OC\Files\View; +use OC\Lock\MemcacheLockingProvider; +use OCP\Lock\ILockingProvider; + +class Locking extends TestCase { + /** + * @var \OC_User_Dummy + */ + private $userBackend; + + private $ownerUid; + private $recipientUid; + + public function setUp() { + parent::setUp(); + + $this->userBackend = new \OC_User_Dummy(); + \OC::$server->getUserManager()->registerBackend($this->userBackend); + + $this->ownerUid = $this->getUniqueID('owner_'); + $this->recipientUid = $this->getUniqueID('recipient_'); + $this->userBackend->createUser($this->ownerUid, ''); + $this->userBackend->createUser($this->recipientUid, ''); + + $this->loginAsUser($this->ownerUid); + Filesystem::mkdir('/foo'); + Filesystem::file_put_contents('/foo/bar.txt', 'asd'); + $fileId = Filesystem::getFileInfo('/foo/bar.txt')->getId(); + + \OCP\Share::shareItem('file', $fileId, \OCP\Share::SHARE_TYPE_USER, $this->recipientUid, 31); + + $this->loginAsUser($this->recipientUid); + $this->assertTrue(Filesystem::file_exists('bar.txt')); + } + + public function tearDown() { + \OC::$server->getUserManager()->removeBackend($this->userBackend); + parent::tearDown(); + } + + /** + * @expectedException \OCP\Lock\LockedException + */ + public function testLockAsRecipient() { + $this->loginAsUser($this->ownerUid); + + Filesystem::initMountPoints($this->recipientUid); + $recipientView = new View('/' . $this->recipientUid . '/files'); + $recipientView->lockFile('bar.txt', ILockingProvider::LOCK_EXCLUSIVE); + + Filesystem::rename('/foo', '/asd'); + } + + public function testUnLockAsRecipient() { + $this->loginAsUser($this->ownerUid); + + Filesystem::initMountPoints($this->recipientUid); + $recipientView = new View('/' . $this->recipientUid . '/files'); + $recipientView->lockFile('bar.txt', ILockingProvider::LOCK_EXCLUSIVE); + $recipientView->unlockFile('bar.txt', ILockingProvider::LOCK_EXCLUSIVE); + + $this->assertTrue(Filesystem::rename('/foo', '/asd')); + } +} -- cgit v1.2.3 From 3c0be7d126b4cff840c0e6b1b386c20b4eff1721 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 30 Jun 2015 13:49:54 +0200 Subject: only lock the parent folders --- apps/files_sharing/lib/sharedstorage.php | 4 ++-- apps/files_sharing/tests/locking.php | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) (limited to 'apps/files_sharing/tests') diff --git a/apps/files_sharing/lib/sharedstorage.php b/apps/files_sharing/lib/sharedstorage.php index e54f747d3ba..ff01489d77b 100644 --- a/apps/files_sharing/lib/sharedstorage.php +++ b/apps/files_sharing/lib/sharedstorage.php @@ -632,7 +632,7 @@ class Shared extends \OC\Files\Storage\Common implements ISharedStorage { // lock the parent folders of the owner when locking the share as recipient if ($path === '') { $sourcePath = $this->ownerView->getPath($this->share['file_source']); - $this->ownerView->lockFile($sourcePath, ILockingProvider::LOCK_SHARED, true); + $this->ownerView->lockFile(dirname($sourcePath), ILockingProvider::LOCK_SHARED, true); } } @@ -648,7 +648,7 @@ class Shared extends \OC\Files\Storage\Common implements ISharedStorage { // unlock the parent folders of the owner when unlocking the share as recipient if ($path === '') { $sourcePath = $this->ownerView->getPath($this->share['file_source']); - $this->ownerView->unlockFile($sourcePath, ILockingProvider::LOCK_SHARED, true); + $this->ownerView->unlockFile(dirname($sourcePath), ILockingProvider::LOCK_SHARED, true); } } diff --git a/apps/files_sharing/tests/locking.php b/apps/files_sharing/tests/locking.php index 46afbf294be..6d13fc1cda5 100644 --- a/apps/files_sharing/tests/locking.php +++ b/apps/files_sharing/tests/locking.php @@ -87,4 +87,15 @@ class Locking extends TestCase { $this->assertTrue(Filesystem::rename('/foo', '/asd')); } + + public function testChangeLock() { + + Filesystem::initMountPoints($this->recipientUid); + $recipientView = new View('/' . $this->recipientUid . '/files'); + $recipientView->lockFile('bar.txt', ILockingProvider::LOCK_SHARED); + $recipientView->changeLock('bar.txt', ILockingProvider::LOCK_EXCLUSIVE); + $recipientView->unlockFile('bar.txt', ILockingProvider::LOCK_EXCLUSIVE); + + $this->assertTrue(true); + } } -- cgit v1.2.3