diff options
author | Roeland Jago Douma <roeland@famdouma.nl> | 2016-08-17 10:05:09 +0200 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2016-08-17 20:45:29 +0200 |
commit | af074eb2b7c0e69fc918a4f3c8abe47b4ea698dd (patch) | |
tree | fc088df1701a5d17b18f3f33435bd7e6bdf15e1a | |
parent | 22e23f304570e3eef1e56f73b7c15ba29025bcdd (diff) | |
download | nextcloud-server-af074eb2b7c0e69fc918a4f3c8abe47b4ea698dd.tar.gz nextcloud-server-af074eb2b7c0e69fc918a4f3c8abe47b4ea698dd.zip |
Move updateShare and getShares over to use proper parameters
* Update tests
-rw-r--r-- | apps/files_sharing/lib/API/Share20OCS.php | 35 | ||||
-rw-r--r-- | apps/files_sharing/tests/API/Share20OCSTest.php | 130 | ||||
-rw-r--r-- | apps/files_sharing/tests/ApiTest.php | 72 |
3 files changed, 81 insertions, 156 deletions
diff --git a/apps/files_sharing/lib/API/Share20OCS.php b/apps/files_sharing/lib/API/Share20OCS.php index b8b259ee430..3e91da37a7d 100644 --- a/apps/files_sharing/lib/API/Share20OCS.php +++ b/apps/files_sharing/lib/API/Share20OCS.php @@ -473,6 +473,11 @@ class Share20OCS extends OCSController { * * @NoAdminRequired * + * @param string $shared_with_me + * @param string $reshares + * @param string $subfiles + * @param string $path + * * - Get shares by the current user * - Get shares by the current user and reshares (?reshares=true) * - Get shares with the current user (?shared_with_me=true) @@ -482,11 +487,12 @@ class Share20OCS extends OCSController { * @return DataResponse * @throws OCSNotFoundException */ - public function getShares() { - $sharedWithMe = $this->request->getParam('shared_with_me', null); - $reshares = $this->request->getParam('reshares', null); - $subfiles = $this->request->getParam('subfiles'); - $path = $this->request->getParam('path', null); + public function getShares( + $shared_with_me = 'false', + $reshares = 'false', + $subfiles = 'false', + $path = null + ) { if ($path !== null) { $userFolder = $this->rootFolder->getUserFolder($this->currentUser->getUID()); @@ -500,7 +506,7 @@ class Share20OCS extends OCSController { } } - if ($sharedWithMe === 'true') { + if ($shared_with_me === 'true') { $result = $this->getSharedWithMe($path); return $result; } @@ -543,12 +549,22 @@ class Share20OCS extends OCSController { * @NoAdminRequired * * @param int $id + * @param int $permissions + * @param string $password + * @param string $publicUpload + * @param string $expireDate * @return DataResponse * @throws OCSNotFoundException * @throws OCSBadRequestException * @throws OCSForbiddenException */ - public function updateShare($id) { + public function updateShare( + $id, + $permissions = null, + $password = null, + $publicUpload = null, + $expireDate = null + ) { try { $share = $this->getShareById($id); } catch (ShareNotFound $e) { @@ -561,11 +577,6 @@ class Share20OCS extends OCSController { throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist')); } - $permissions = $this->request->getParam('permissions', null); - $password = $this->request->getParam('password', null); - $publicUpload = $this->request->getParam('publicUpload', null); - $expireDate = $this->request->getParam('expireDate', null); - /* * expirationdate, password and publicUpload only make sense for link shares */ diff --git a/apps/files_sharing/tests/API/Share20OCSTest.php b/apps/files_sharing/tests/API/Share20OCSTest.php index c6b5a36512e..95af8420061 100644 --- a/apps/files_sharing/tests/API/Share20OCSTest.php +++ b/apps/files_sharing/tests/API/Share20OCSTest.php @@ -1207,14 +1207,6 @@ class Share20OCSTest extends \Test\TestCase { ->method('lock') ->with(\OCP\Lock\ILockingProvider::LOCK_SHARED); - $this->request - ->method('getParam') - ->will($this->returnValueMap([ - ['publicUpload', null, 'false'], - ['expireDate', null, ''], - ['password', null, ''], - ])); - $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share); $this->shareManager->expects($this->once())->method('updateShare')->with( @@ -1226,7 +1218,7 @@ class Share20OCSTest extends \Test\TestCase { )->will($this->returnArgument(0)); $expected = new DataResponse(null); - $result = $ocs->updateShare(42); + $result = $ocs->updateShare(42, null, '', 'false', ''); $this->assertInstanceOf(get_class($expected), $result); $this->assertEquals($expected->getData(), $result->getData()); @@ -1243,14 +1235,6 @@ class Share20OCSTest extends \Test\TestCase { ->setShareType(\OCP\Share::SHARE_TYPE_LINK) ->setNode($folder); - $this->request - ->method('getParam') - ->will($this->returnValueMap([ - ['publicUpload', null, 'true'], - ['expireDate', null, '2000-01-01'], - ['password', null, 'password'], - ])); - $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share); $this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true); @@ -1266,7 +1250,7 @@ class Share20OCSTest extends \Test\TestCase { )->will($this->returnArgument(0)); $expected = new DataResponse(null); - $result = $ocs->updateShare(42); + $result = $ocs->updateShare(42, null, 'password', 'true', '2000-01-01'); $this->assertInstanceOf(get_class($expected), $result); $this->assertEquals($expected->getData(), $result->getData()); @@ -1275,7 +1259,7 @@ class Share20OCSTest extends \Test\TestCase { /** * @dataProvider publicUploadParamsProvider */ - public function testUpdateLinkShareEnablePublicUpload($params) { + public function testUpdateLinkShareEnablePublicUpload($permissions, $publicUpload, $expireDate, $password) { $ocs = $this->mockFormatShare(); $folder = $this->getMockBuilder('\OCP\Files\Folder')->getMock(); @@ -1287,10 +1271,6 @@ class Share20OCSTest extends \Test\TestCase { ->setPassword('password') ->setNode($folder); - $this->request - ->method('getParam') - ->will($this->returnValueMap($params)); - $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share); $this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true); $this->shareManager->method('getSharedWith')->willReturn([]); @@ -1304,7 +1284,7 @@ class Share20OCSTest extends \Test\TestCase { )->will($this->returnArgument(0)); $expected = new DataResponse(null); - $result = $ocs->updateShare(42); + $result = $ocs->updateShare(42, $permissions, $password, $publicUpload, $expireDate); $this->assertInstanceOf(get_class($expected), $result); $this->assertEquals($expected->getData(), $result->getData()); @@ -1325,37 +1305,25 @@ class Share20OCSTest extends \Test\TestCase { ->setShareType(\OCP\Share::SHARE_TYPE_LINK) ->setNode($folder); - $this->request - ->method('getParam') - ->will($this->returnValueMap([ - ['publicUpload', null, 'true'], - ['expireDate', null, '2000-01-a'], - ['password', null, 'password'], - ])); - $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share); $this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true); - $ocs->updateShare(42); + $ocs->updateShare(42, null, 'password', 'true', '2000-01-a'); } public function publicUploadParamsProvider() { return [ - [[ - ['publicUpload', null, 'true'], - ['expireDate', '', null], - ['password', '', 'password'], - ]], [[ - // legacy had no delete - ['permissions', null, \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE], - ['expireDate', '', null], - ['password', '', 'password'], - ]], [[ - // correct - ['permissions', null, \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_DELETE], - ['expireDate', '', null], - ['password', '', 'password'], - ]], + [null, 'true', null, 'password'], + // legacy had no delete + [ + \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE, + null, null, 'password' + ], + // correct + [ + \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_DELETE, + null, null, 'password' + ], ]; } @@ -1364,7 +1332,7 @@ class Share20OCSTest extends \Test\TestCase { * @expectedException \OCP\AppFramework\OCS\OCSForbiddenException * @expectedExceptionMessage Public upload disabled by the administrator */ - public function testUpdateLinkSharePublicUploadNotAllowed($params) { + public function testUpdateLinkSharePublicUploadNotAllowed($permissions, $publicUpload, $expireDate, $password) { $ocs = $this->mockFormatShare(); $folder = $this->getMockBuilder('\OCP\Files\Folder')->getMock(); @@ -1375,14 +1343,10 @@ class Share20OCSTest extends \Test\TestCase { ->setShareType(\OCP\Share::SHARE_TYPE_LINK) ->setNode($folder); - $this->request - ->method('getParam') - ->will($this->returnValueMap($params)); - $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share); $this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(false); - $ocs->updateShare(42); + $ocs->updateShare(42, $permissions, $password, $publicUpload, $expireDate); } /** @@ -1400,18 +1364,10 @@ class Share20OCSTest extends \Test\TestCase { ->setShareType(\OCP\Share::SHARE_TYPE_LINK) ->setNode($file); - $this->request - ->method('getParam') - ->will($this->returnValueMap([ - ['publicUpload', null, 'true'], - ['expireDate', '', ''], - ['password', '', 'password'], - ])); - $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share); $this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true); - $ocs->updateShare(42); + $ocs->updateShare(42, null, 'password', 'true', ''); } public function testUpdateLinkSharePasswordDoesNotChangeOther() { @@ -1434,12 +1390,6 @@ class Share20OCSTest extends \Test\TestCase { ->method('lock') ->with(\OCP\Lock\ILockingProvider::LOCK_SHARED); - $this->request - ->method('getParam') - ->will($this->returnValueMap([ - ['password', null, 'newpassword'], - ])); - $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share); $this->shareManager->expects($this->once())->method('updateShare')->with( @@ -1451,7 +1401,7 @@ class Share20OCSTest extends \Test\TestCase { )->will($this->returnArgument(0)); $expected = new DataResponse(null); - $result = $ocs->updateShare(42); + $result = $ocs->updateShare(42, null, 'newpassword', null, null); $this->assertInstanceOf(get_class($expected), $result); $this->assertEquals($expected->getData(), $result->getData()); @@ -1470,12 +1420,6 @@ class Share20OCSTest extends \Test\TestCase { ->setPermissions(\OCP\Constants::PERMISSION_ALL) ->setNode($node); - $this->request - ->method('getParam') - ->will($this->returnValueMap([ - ['expireDate', null, '2010-12-23'], - ])); - $node->expects($this->once()) ->method('lock') ->with(\OCP\Lock\ILockingProvider::LOCK_SHARED); @@ -1494,7 +1438,7 @@ class Share20OCSTest extends \Test\TestCase { )->will($this->returnArgument(0)); $expected = new DataResponse(null); - $result = $ocs->updateShare(42); + $result = $ocs->updateShare(42, null, null, null, '2010-12-23'); $this->assertInstanceOf(get_class($expected), $result); $this->assertEquals($expected->getData(), $result->getData()); @@ -1516,12 +1460,6 @@ class Share20OCSTest extends \Test\TestCase { ->setPermissions(\OCP\Constants::PERMISSION_ALL) ->setNode($folder); - $this->request - ->method('getParam') - ->will($this->returnValueMap([ - ['publicUpload', null, 'true'], - ])); - $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share); $this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true); @@ -1534,7 +1472,7 @@ class Share20OCSTest extends \Test\TestCase { )->will($this->returnArgument(0)); $expected = new DataResponse(null); - $result = $ocs->updateShare(42); + $result = $ocs->updateShare(42, null, null, 'true', null); $this->assertInstanceOf(get_class($expected), $result); $this->assertEquals($expected->getData(), $result->getData()); @@ -1556,12 +1494,6 @@ class Share20OCSTest extends \Test\TestCase { ->setPermissions(\OCP\Constants::PERMISSION_ALL) ->setNode($folder); - $this->request - ->method('getParam') - ->will($this->returnValueMap([ - ['permissions', null, '7'], - ])); - $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share); $this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true); @@ -1576,7 +1508,7 @@ class Share20OCSTest extends \Test\TestCase { $this->shareManager->method('getSharedWith')->willReturn([]); $expected = new DataResponse(null); - $result = $ocs->updateShare(42); + $result = $ocs->updateShare(42, 7, null, null, null); $this->assertInstanceOf(get_class($expected), $result); $this->assertEquals($expected->getData(), $result->getData()); @@ -1602,16 +1534,10 @@ class Share20OCSTest extends \Test\TestCase { ->setPermissions(\OCP\Constants::PERMISSION_ALL) ->setNode($folder); - $this->request - ->method('getParam') - ->will($this->returnValueMap([ - ['permissions', null, '31'], - ])); - $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share); $this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true); - $ocs->updateShare(42); + $ocs->updateShare(42, 31); } public function testUpdateOtherPermissions() { @@ -1625,12 +1551,6 @@ class Share20OCSTest extends \Test\TestCase { ->setShareType(\OCP\Share::SHARE_TYPE_USER) ->setNode($file); - $this->request - ->method('getParam') - ->will($this->returnValueMap([ - ['permissions', null, '31'], - ])); - $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share); $this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true); @@ -1643,7 +1563,7 @@ class Share20OCSTest extends \Test\TestCase { $this->shareManager->method('getSharedWith')->willReturn([]); $expected = new DataResponse(null); - $result = $ocs->updateShare(42); + $result = $ocs->updateShare(42, 31, null, null, null); $this->assertInstanceOf(get_class($expected), $result); $this->assertEquals($expected->getData(), $result->getData()); diff --git a/apps/files_sharing/tests/ApiTest.php b/apps/files_sharing/tests/ApiTest.php index 1417be3a904..11e39b7ddd7 100644 --- a/apps/files_sharing/tests/ApiTest.php +++ b/apps/files_sharing/tests/ApiTest.php @@ -28,6 +28,7 @@ */ namespace OCA\Files_Sharing\Tests; + use OCP\AppFramework\OCS\OCSBadRequestException; use OCP\AppFramework\OCS\OCSException; use OCP\AppFramework\OCS\OCSForbiddenException; @@ -49,6 +50,9 @@ class ApiTest extends TestCase { /** @var \OCP\Files\Folder */ private $userFolder; + /** @var string */ + private $subsubfolder; + protected function setUp() { parent::setUp(); @@ -291,12 +295,9 @@ class ApiTest extends TestCase { $data = $result->getData(); // setting new password should succeed - $data2 = [ - 'password' => 'bar', - ]; - $request = $this->createRequest($data2); + $request = $this->createRequest([]); $ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER1); - $result = $ocs->updateShare($data['id']); + $ocs->updateShare($data['id'], null, 'bar'); $ocs->cleanup(); // removing password should fail @@ -359,7 +360,7 @@ class ApiTest extends TestCase { $request = $this->createRequest([]); $ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER1); - $result = $ocs->deleteShare($data['id']); + $ocs->deleteShare($data['id']); $ocs->cleanup(); // now we exclude the group the user belongs to ('group'), sharing should fail now @@ -420,12 +421,12 @@ class ApiTest extends TestCase { ->setPermissions(31); $share2 = $this->shareManager->createShare($share2); - $request = $this->createRequest(['shared_with_me' => 'true']); + $request = $this->createRequest([]); $ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER2); - $result = $ocs->getShares(); + $result = $ocs->getShares('true'); $ocs->cleanup(); - $this->assertTrue(count($result->getData()) === 2); + $this->assertCount(2, $result->getData()); $this->shareManager->deleteShare($share1); $this->shareManager->deleteShare($share2); @@ -549,9 +550,9 @@ class ApiTest extends TestCase { $this->assertTrue(count($result->getData()) === 1); // now also ask for the reshares - $request = $this->createRequest(['path' => $this->filename, 'reshares' => 'true']); + $request = $this->createRequest([]); $ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER1); - $result = $ocs->getShares(); + $result = $ocs->getShares('false', 'true', 'false', $this->filename); $ocs->cleanup(); // now we should get two shares, the initial share and the reshare @@ -609,9 +610,9 @@ class ApiTest extends TestCase { $share2 = $this->shareManager->createShare($share2); - $request = $this->createRequest(['path' => $this->folder, 'subfiles' => 'true']); + $request = $this->createRequest([]); $ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER1); - $result = $ocs->getShares(); + $result = $ocs->getShares('false', 'false', 'true', $this->folder); $ocs->cleanup(); // test should return one share within $this->folder @@ -631,10 +632,10 @@ class ApiTest extends TestCase { ->setPermissions(19); $share1 = $this->shareManager->createShare($share1); - $request = $this->createRequest(['path' => $this->filename, 'subfiles' => 'true']); + $request = $this->createRequest([]); $ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER1); try { - $ocs->getShares(); + $ocs->getShares('false', 'false', 'true', $this->filename); $this->fail(); } catch (OCSBadRequestException $e) { $this->assertEquals('Not a directory', $e->getMessage()); @@ -682,9 +683,9 @@ class ApiTest extends TestCase { ); foreach ($testValues as $value) { - $request = $this->createRequest(['path' => $value['query'], 'subfiles' => 'true']); + $request = $this->createRequest([]); $ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER2); - $result = $ocs->getShares(); + $result = $ocs->getShares('false', 'false', 'true', $value['query']); $ocs->cleanup(); // test should return one share within $this->folder @@ -965,12 +966,9 @@ class ApiTest extends TestCase { $share2 = $this->shareManager->createShare($share2); // update permissions - $params = array(); - $params['permissions'] = 1; - - $request = $this->createRequest(['permissions' => 1]); + $request = $this->createRequest([]); $ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER1); - $result = $ocs->updateShare($share1->getId()); + $ocs->updateShare($share1->getId(), 1); $ocs->cleanup(); $share1 = $this->shareManager->getShareById('ocinternal:' . $share1->getId()); @@ -979,17 +977,17 @@ class ApiTest extends TestCase { // update password for link share $this->assertNull($share2->getPassword()); - $request = $this->createRequest(['password' => 'foo']); + $request = $this->createRequest([]); $ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER1); - $ocs->updateShare($share2->getId()); + $ocs->updateShare($share2->getId(), null, 'foo'); $ocs->cleanup(); $share2 = $this->shareManager->getShareById('ocinternal:' . $share2->getId()); $this->assertNotNull($share2->getPassword()); - $request = $this->createRequest(['password' => '']); + $request = $this->createRequest([]); $ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER1); - $ocs->updateShare($share2->getId()); + $ocs->updateShare($share2->getId(), null, ''); $ocs->cleanup(); $share2 = $this->shareManager->getShareById('ocinternal:' . $share2->getId()); @@ -1043,9 +1041,9 @@ class ApiTest extends TestCase { $share1 = $this->shareManager->createShare($share1); // update public upload - $request = $this->createRequest(['publicUpload' => 'true']); + $request = $this->createRequest([]); $ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER1); - $result = $ocs->updateShare($share1->getId()); + $ocs->updateShare($share1->getId(), null, null, 'true'); $ocs->cleanup(); $share1 = $this->shareManager->getShareById($share1->getFullId()); @@ -1087,9 +1085,9 @@ class ApiTest extends TestCase { $dateOutOfRange->add(new \DateInterval('P8D')); // update expire date to a valid value - $request = $this->createRequest(['expireDate' => $dateWithinRange->format('Y-m-d')]); + $request = $this->createRequest([]); $ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER1); - $result = $ocs->updateShare($share1->getId()); + $ocs->updateShare($share1->getId(), null, null, null, $dateWithinRange->format('Y-m-d')); $ocs->cleanup(); $share1 = $this->shareManager->getShareById($share1->getFullId()); @@ -1158,12 +1156,12 @@ class ApiTest extends TestCase { $request = $this->createRequest([]); $ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER1); - $result = $ocs->deleteShare($share1->getId()); + $ocs->deleteShare($share1->getId()); $ocs->cleanup(); $request = $this->createRequest([]); $ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER1); - $result = $ocs->deleteShare($share2->getId()); + $ocs->deleteShare($share2->getId()); $ocs->cleanup(); $this->assertEmpty($this->shareManager->getSharesBy(self::TEST_FILES_SHARING_API_USER2, \OCP\Share::SHARE_TYPE_USER)); @@ -1195,7 +1193,7 @@ class ApiTest extends TestCase { // test if we can unshare the link again $request = $this->createRequest([]); $ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER2); - $result = $ocs->deleteShare($share2->getId()); + $ocs->deleteShare($share2->getId()); $ocs->cleanup(); $this->shareManager->deleteShare($share1); @@ -1208,8 +1206,6 @@ class ApiTest extends TestCase { // user 1 shares a folder with user2 self::loginHelper(self::TEST_FILES_SHARING_API_USER1); - $fileInfo = $this->view->getFileInfo($this->folder); - $share = $this->share( \OCP\Share::SHARE_TYPE_USER, $this->folder, @@ -1284,8 +1280,6 @@ class ApiTest extends TestCase { // logging in will auto-mount the temp storage for user1 as well self::loginHelper(self::TEST_FILES_SHARING_API_USER1); - $fileInfo = $this->view->getFileInfo($this->folder); - // user 1 shares the mount point folder with user2 $share = $this->share( \OCP\Share::SHARE_TYPE_USER, @@ -1546,7 +1540,7 @@ class ApiTest extends TestCase { $request = $this->createRequest([]); $ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER1); - $result = $ocs->deleteShare($topId); + $ocs->deleteShare($topId); $ocs->cleanup(); $request = $this->createRequest([ @@ -1580,7 +1574,7 @@ class ApiTest extends TestCase { $request = $this->createRequest([]); $ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER1); - $result = $ocs->deleteShare($topId); + $ocs->deleteShare($topId); $ocs->cleanup(); $request = $this->createRequest([ |