From 8213d5df4f40410f851da31082bbb1fb8d84dd1e Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Thu, 25 Feb 2016 20:22:35 +0100 Subject: Do not allow sharing of the root folder Sharing of the users root folder should not be allowed as it is very weird UX. Also many of our clients have no proper way of displaying this. Added unit test Also added intergration tests to make sure we won't allow it in the future. --- tests/lib/share20/managertest.php | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'tests/lib') diff --git a/tests/lib/share20/managertest.php b/tests/lib/share20/managertest.php index c41f0754396..df688f782c4 100644 --- a/tests/lib/share20/managertest.php +++ b/tests/lib/share20/managertest.php @@ -677,6 +677,9 @@ class ManagerTest extends \Test\TestCase { ['group0', true], ])); + $userFolder = $this->getMock('\OCP\Files\Folder'); + $this->rootFolder->method('getUserFolder')->willReturn($userFolder); + try { $this->invokePrivate($this->manager, 'generalCreateChecks', [$share]); $thrown = false; @@ -691,6 +694,32 @@ class ManagerTest extends \Test\TestCase { $this->assertSame($exception, $thrown); } + /** + * @expectedException \InvalidArgumentException + * @expectedExceptionMessage You can't share your root folder + */ + public function testGeneralCheckShareRoot() { + $thrown = null; + + $this->userManager->method('userExists')->will($this->returnValueMap([ + ['user0', true], + ['user1', true], + ])); + + $userFolder = $this->getMock('\OCP\Files\Folder'); + $userFolder->method('isSubNode')->with($userFolder)->willReturn(false); + $this->rootFolder->method('getUserFolder')->willReturn($userFolder); + + $share = $this->manager->newShare(); + + $share->setShareType(\OCP\Share::SHARE_TYPE_USER) + ->setSharedWith('user0') + ->setSharedBy('user1') + ->setNode($userFolder); + + $this->invokePrivate($this->manager, 'generalCreateChecks', [$share]); + } + /** * @expectedException \OCP\Share\Exceptions\GenericShareException * @expectedExceptionMessage Expiration date is in the past -- cgit v1.2.3