Commit 8213d5df authored by Roeland Jago Douma's avatar Roeland Jago Douma
Browse files

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

Added unit test

Also added intergration tests to make sure we won't allow it in the
parent 3772a8ac
......@@ -506,3 +506,11 @@ Feature: sharing
And file "myfile.txt" of user "user0" is shared with user "user1"
When User "user1" uploads file "data/textfile.txt" to "/myfile.txt"
Then the HTTP status code should be "204"
Scenario: Don't allow sharing of the root
Given user "user0" exists
And As an "user0"
When creating a share with
| path | / |
| shareType | 3 |
Then the OCS status code should be "403"
\ No newline at end of file
......@@ -197,6 +197,11 @@ class Manager implements IManager {
throw new \InvalidArgumentException('Path should be either a file or a folder');
// And you can't share your rootfolder
if ($this->rootFolder->getUserFolder($share->getSharedBy())->isSubNode($share->getNode()) === false) {
throw new \InvalidArgumentException('You can\'t share your root folder');
// Check if we actually have share permissions
if (!$share->getNode()->isShareable()) {
$message_t = $this->l->t('You are not allowed to share %s', [$share->getNode()->getPath()]);
......@@ -677,6 +677,9 @@ class ManagerTest extends \Test\TestCase {
['group0', true],
$userFolder = $this->getMock('\OCP\Files\Folder');
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;
['user0', true],
['user1', true],
$userFolder = $this->getMock('\OCP\Files\Folder');
$share = $this->manager->newShare();
$this->invokePrivate($this->manager, 'generalCreateChecks', [$share]);
* @expectedException \OCP\Share\Exceptions\GenericShareException
* @expectedExceptionMessage Expiration date is in the past
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment