]> source.dussan.org Git - nextcloud-server.git/commitdiff
[Sharing 2.0] Some error cases report 404 instead of 403
authorRoeland Jago Douma <rullzer@owncloud.com>
Wed, 6 Jan 2016 10:34:12 +0000 (11:34 +0100)
committerRoeland Jago Douma <rullzer@owncloud.com>
Wed, 6 Jan 2016 14:25:29 +0000 (15:25 +0100)
lib/private/share20/manager.php
tests/lib/share20/managertest.php

index 216c4b9f5c15b6e7c6bbb18a30db5942f65d2b07..8d753061c0cddf64cf85f3da0b3d00541238a756 100644 (file)
@@ -33,6 +33,7 @@ use OCP\Files\Folder;
 use OCP\IUser;
 
 use OC\Share20\Exception\ShareNotFound;
+use OC\HintException;
 
 /**
  * This class is the communication hub for all sharing related operations.
@@ -175,7 +176,8 @@ class Manager {
 
                // Check if we actually have share permissions
                if (!$share->getPath()->isShareable()) {
-                       throw new \InvalidArgumentException('Path is not shareable');
+                       $message_t = $this->l->t('You are not allowed to share %s', [$share->getPath()->getPath()]);
+                       throw new HintException($message_t, $message_t, 404);
                }
 
                // Permissions should be set
@@ -185,7 +187,8 @@ class Manager {
 
                // Check that we do not share with more permissions than we have
                if ($share->getPermissions() & ~$share->getPath()->getPermissions()) {
-                       throw new \InvalidArgumentException('Cannot increase permissions');
+                       $message_t = $this->l->t('Cannot increase permissions of %s', [$share->getPath()->getPath()]);
+                       throw new HintException($message_t, $message_t, 404);
                }
 
                // Check that read permissions are always set
index c7f4c0afdf2ac7ad9d459d86e42f4393522c688c..57e7e11071226451e40110965df5b19c2dd70357 100644 (file)
@@ -530,22 +530,24 @@ class ManagerTest extends \Test\TestCase {
 
                $nonShareAble = $this->getMock('\OCP\Files\Folder');
                $nonShareAble->method('isShareable')->willReturn(false);
+               $nonShareAble->method('getPath')->willReturn('path');
 
-               $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_USER,  $nonShareAble, $user2, $user, $user, 31, null, null), 'Path is not shareable', true];
-               $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_GROUP, $nonShareAble, $group, $user, $user, 31, null, null), 'Path is not shareable', true];
-               $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_LINK,  $nonShareAble, null, $user, $user, 31, null, null), 'Path is not shareable', true];
+               $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_USER,  $nonShareAble, $user2, $user, $user, 31, null, null), 'You are not allowed to share path', true];
+               $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_GROUP, $nonShareAble, $group, $user, $user, 31, null, null), 'You are not allowed to share path', true];
+               $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_LINK,  $nonShareAble, null, $user, $user, 31, null, null), 'You are not allowed to share path', true];
 
                $limitedPermssions = $this->getMock('\OCP\Files\File');
                $limitedPermssions->method('isShareable')->willReturn(true);
                $limitedPermssions->method('getPermissions')->willReturn(\OCP\Constants::PERMISSION_READ);
+               $limitedPermssions->method('getPath')->willReturn('path');
 
                $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_USER,  $limitedPermssions, $user2, $user, $user, null, null, null), 'A share requires permissions', true];
                $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_GROUP, $limitedPermssions, $group, $user, $user, null, null, null), 'A share requires permissions', true];
                $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_LINK,  $limitedPermssions, null, $user, $user, null, null, null), 'A share requires permissions', true];
 
-               $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_USER,  $limitedPermssions, $user2, $user, $user, 31, null, null), 'Cannot increase permissions', true];
-               $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_GROUP, $limitedPermssions, $group, $user, $user, 17, null, null), 'Cannot increase permissions', true];
-               $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_LINK,  $limitedPermssions, null, $user, $user, 3, null, null), 'Cannot increase permissions', true];
+               $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_USER,  $limitedPermssions, $user2, $user, $user, 31, null, null), 'Cannot increase permissions of path', true];
+               $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_GROUP, $limitedPermssions, $group, $user, $user, 17, null, null), 'Cannot increase permissions of path', true];
+               $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_LINK,  $limitedPermssions, null, $user, $user, 3, null, null), 'Cannot increase permissions of path', true];
 
                $allPermssions = $this->getMock('\OCP\Files\Folder');
                $allPermssions->method('isShareable')->willReturn(true);
@@ -574,6 +576,9 @@ class ManagerTest extends \Test\TestCase {
                try {
                        $this->invokePrivate($this->manager, 'generalCreateChecks', [$share]);
                        $thrown = false;
+               } catch (\OC\HintException $e) {
+                       $this->assertEquals($exceptionMessage, $e->getHint());
+                       $thrown = true;
                } catch(\InvalidArgumentException $e) {
                        $this->assertEquals($exceptionMessage, $e->getMessage());
                        $thrown = true;