Merge pull request #917 from nextcloud/share_api_use_parameters

Share API use parameters
This commit is contained in:
Lukas Reschke 2016-08-18 11:03:09 +02:00 committed by GitHub
commit 021f708274
3 changed files with 210 additions and 578 deletions

View File

@ -246,17 +246,32 @@ class Share20OCS extends OCSController {
/**
* @NoAdminRequired
*
* @param string $path
* @param int $permissions
* @param int $shareType
* @param string $shareWith
* @param string $publicUpload
* @param string $password
* @param string $expireDate
*
* @return DataResponse
* @throws OCSNotFoundException
* @throws OCSForbiddenException
* @throws OCSBadRequestException
* @throws OCSException
*/
public function createShare() {
public function createShare(
$path = null,
$permissions = \OCP\Constants::PERMISSION_ALL,
$shareType = -1,
$shareWith = null,
$publicUpload = 'false',
$password = '',
$expireDate = ''
) {
$share = $this->shareManager->newShare();
// Verify path
$path = $this->request->getParam('path', null);
if ($path === null) {
throw new OCSNotFoundException($this->l->t('Please specify a file or folder path'));
}
@ -276,14 +291,6 @@ class Share20OCS extends OCSController {
throw new OCSNotFoundException($this->l->t('Could not create share'));
}
// Parse permissions (if available)
$permissions = $this->request->getParam('permissions', null);
if ($permissions === null) {
$permissions = \OCP\Constants::PERMISSION_ALL;
} else {
$permissions = (int)$permissions;
}
if ($permissions < 0 || $permissions > \OCP\Constants::PERMISSION_ALL) {
throw new OCSNotFoundException($this->l->t('invalid permissions'));
}
@ -306,9 +313,6 @@ class Share20OCS extends OCSController {
$permissions &= ~($permissions & ~$path->getPermissions());
}
$shareWith = $this->request->getParam('shareWith', null);
$shareType = (int)$this->request->getParam('shareType', '-1');
if ($shareType === \OCP\Share::SHARE_TYPE_USER) {
// Valid user is required to share
if ($shareWith === null || !$this->userManager->userExists($shareWith)) {
@ -342,7 +346,6 @@ class Share20OCS extends OCSController {
return new DataResponse($this->formatShare($existingShares[0]));
}
$publicUpload = $this->request->getParam('publicUpload', null);
if ($publicUpload === 'true') {
// Check if public upload is allowed
if (!$this->shareManager->shareApiLinkAllowPublicUpload()) {
@ -365,15 +368,11 @@ class Share20OCS extends OCSController {
}
// Set password
$password = $this->request->getParam('password', '');
if ($password !== '') {
$share->setPassword($password);
}
//Expire date
$expireDate = $this->request->getParam('expireDate', '');
if ($expireDate !== '') {
try {
$expireDate = $this->parseDate($expireDate);
@ -474,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)
@ -483,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());
@ -501,7 +506,7 @@ class Share20OCS extends OCSController {
}
}
if ($sharedWithMe === 'true') {
if ($shared_with_me === 'true') {
$result = $this->getSharedWithMe($path);
return $result;
}
@ -544,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) {
@ -562,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
*/

View File

@ -46,31 +46,31 @@ class Share20OCSTest extends \Test\TestCase {
/** @var string */
private $appName = 'files_sharing';
/** @var \OC\Share20\Manager | \PHPUnit_Framework_MockObject_MockObject */
/** @var \OC\Share20\Manager|\PHPUnit_Framework_MockObject_MockObject */
private $shareManager;
/** @var IGroupManager | \PHPUnit_Framework_MockObject_MockObject */
/** @var IGroupManager|\PHPUnit_Framework_MockObject_MockObject */
private $groupManager;
/** @var IUserManager | \PHPUnit_Framework_MockObject_MockObject */
/** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */
private $userManager;
/** @var IRequest | \PHPUnit_Framework_MockObject_MockObject */
/** @var IRequest|\PHPUnit_Framework_MockObject_MockObject */
private $request;
/** @var IRootFolder | \PHPUnit_Framework_MockObject_MockObject */
/** @var IRootFolder|\PHPUnit_Framework_MockObject_MockObject */
private $rootFolder;
/** @var IURLGenerator */
/** @var IURLGenerator|\PHPUnit_Framework_MockObject_MockObject */
private $urlGenerator;
/** @var IUser */
/** @var IUser|\PHPUnit_Framework_MockObject_MockObject */
private $currentUser;
/** @var Share20OCS */
private $ocs;
/** @var IL10N */
/** @var IL10N|\PHPUnit_Framework_MockObject_MockObject */
private $l;
protected function setUp() {
@ -89,8 +89,6 @@ class Share20OCSTest extends \Test\TestCase {
$this->currentUser = $this->getMockBuilder('OCP\IUser')->getMock();
$this->currentUser->method('getUID')->willReturn('currentUser');
$this->userManager->expects($this->any())->method('userExists')->willReturn(true);
$this->l = $this->getMockBuilder('\OCP\IL10N')->getMock();
$this->l->method('t')
->will($this->returnCallback(function($text, $parameters = []) {
@ -565,12 +563,6 @@ class Share20OCSTest extends \Test\TestCase {
* @expectedExceptionMessage Wrong path, file/folder doesn't exist
*/
public function testCreateShareInvalidPath() {
$this->request
->method('getParam')
->will($this->returnValueMap([
['path', null, 'invalid-path'],
]));
$userFolder = $this->getMockBuilder('\OCP\Files\Folder')->getMock();
$this->rootFolder->expects($this->once())
->method('getUserFolder')
@ -582,7 +574,7 @@ class Share20OCSTest extends \Test\TestCase {
->with('invalid-path')
->will($this->throwException(new \OCP\Files\NotFoundException()));
$this->ocs->createShare();
$this->ocs->createShare('invalid-path');
}
/**
@ -593,13 +585,6 @@ class Share20OCSTest extends \Test\TestCase {
$share = $this->newShare();
$this->shareManager->method('newShare')->willReturn($share);
$this->request
->method('getParam')
->will($this->returnValueMap([
['path', null, 'valid-path'],
['permissions', null, 32],
]));
$userFolder = $this->getMockBuilder('\OCP\Files\Folder')->getMock();
$this->rootFolder->expects($this->once())
->method('getUserFolder')
@ -616,7 +601,7 @@ class Share20OCSTest extends \Test\TestCase {
->method('lock')
->with(\OCP\Lock\ILockingProvider::LOCK_SHARED);
$this->ocs->createShare();
$this->ocs->createShare('valid-path', 32);
}
/**
@ -627,14 +612,6 @@ class Share20OCSTest extends \Test\TestCase {
$share = $this->newShare();
$this->shareManager->method('newShare')->willReturn($share);
$this->request
->method('getParam')
->will($this->returnValueMap([
['path', null, 'valid-path'],
['permissions', null, \OCP\Constants::PERMISSION_ALL],
['shareType', $this->any(), \OCP\Share::SHARE_TYPE_USER],
]));
$userFolder = $this->getMockBuilder('\OCP\Files\Folder')->getMock();
$this->rootFolder->expects($this->once())
->method('getUserFolder')
@ -656,7 +633,7 @@ class Share20OCSTest extends \Test\TestCase {
->method('lock')
->with(\OCP\Lock\ILockingProvider::LOCK_SHARED);
$this->ocs->createShare();
$this->ocs->createShare('valid-path', \OCP\Constants::PERMISSION_ALL, \OCP\Share::SHARE_TYPE_USER);
}
/**
@ -667,15 +644,6 @@ class Share20OCSTest extends \Test\TestCase {
$share = $this->newShare();
$this->shareManager->method('newShare')->willReturn($share);
$this->request
->method('getParam')
->will($this->returnValueMap([
['path', null, 'valid-path'],
['permissions', null, \OCP\Constants::PERMISSION_ALL],
['shareType', $this->any(), \OCP\Share::SHARE_TYPE_USER],
['shareWith', $this->any(), 'invalidUser'],
]));
$userFolder = $this->getMockBuilder('\OCP\Files\Folder')->getMock();
$this->rootFolder->expects($this->once())
->method('getUserFolder')
@ -692,12 +660,14 @@ class Share20OCSTest extends \Test\TestCase {
->method('get')
->with('valid-path')
->willReturn($path);
$path->expects($this->once())
->method('lock')
->with(\OCP\Lock\ILockingProvider::LOCK_SHARED);
$this->userManager->method('userExists')
->with('invalidUser')
->willReturn(false);
$this->ocs->createShare();
$this->ocs->createShare('valid-path', \OCP\Constants::PERMISSION_ALL, \OCP\Share::SHARE_TYPE_USER, 'invalidUser');
}
public function testCreateShareUser() {
@ -719,15 +689,6 @@ class Share20OCSTest extends \Test\TestCase {
])->setMethods(['formatShare'])
->getMock();
$this->request
->method('getParam')
->will($this->returnValueMap([
['path', null, 'valid-path'],
['permissions', null, \OCP\Constants::PERMISSION_ALL],
['shareType', $this->any(), \OCP\Share::SHARE_TYPE_USER],
['shareWith', null, 'validUser'],
]));
$userFolder = $this->getMockBuilder('\OCP\Files\Folder')->getMock();
$this->rootFolder->expects($this->once())
->method('getUserFolder')
@ -766,7 +727,7 @@ class Share20OCSTest extends \Test\TestCase {
->will($this->returnArgument(0));
$expected = new DataResponse(null);
$result = $ocs->createShare();
$result = $ocs->createShare('valid-path', \OCP\Constants::PERMISSION_ALL, \OCP\Share::SHARE_TYPE_USER, 'validUser');
$this->assertInstanceOf(get_class($expected), $result);
$this->assertEquals($expected->getData(), $result->getData());
@ -774,21 +735,13 @@ class Share20OCSTest extends \Test\TestCase {
/**
* @expectedException \OCP\AppFramework\OCS\OCSNotFoundException
* @expectedExceptionMessage Please specify a valid user
* @expectedExceptionMessage Please specify a valid group
*/
public function testCreateShareGroupNoValidShareWith() {
$share = $this->newShare();
$this->shareManager->method('newShare')->willReturn($share);
$this->shareManager->method('createShare')->will($this->returnArgument(0));
$this->request
->method('getParam')
->will($this->returnValueMap([
['path', null, 'valid-path'],
['permissions', null, \OCP\Constants::PERMISSION_ALL],
['shareType', $this->any(), \OCP\Share::SHARE_TYPE_GROUP],
['shareWith', $this->any(), 'invalidGroup'],
]));
$this->shareManager->method('allowGroupSharing')->willReturn(true);
$userFolder = $this->getMockBuilder('\OCP\Files\Folder')->getMock();
$this->rootFolder->expects($this->once())
@ -811,7 +764,7 @@ class Share20OCSTest extends \Test\TestCase {
->method('lock')
->with(\OCP\Lock\ILockingProvider::LOCK_SHARED);
$this->ocs->createShare();
$this->ocs->createShare('valid-path', \OCP\Constants::PERMISSION_ALL, \OCP\Share::SHARE_TYPE_GROUP, 'invalidGroup');
}
public function testCreateShareGroup() {
@ -879,7 +832,7 @@ class Share20OCSTest extends \Test\TestCase {
->will($this->returnArgument(0));
$expected = new DataResponse(null);
$result = $ocs->createShare();
$result = $ocs->createShare('valid-path', \OCP\Constants::PERMISSION_ALL, \OCP\Share::SHARE_TYPE_GROUP, 'validGroup');
$this->assertInstanceOf(get_class($expected), $result);
$this->assertEquals($expected->getData(), $result->getData());
@ -893,15 +846,6 @@ class Share20OCSTest extends \Test\TestCase {
$share = $this->newShare();
$this->shareManager->method('newShare')->willReturn($share);
$this->request
->method('getParam')
->will($this->returnValueMap([
['path', null, 'valid-path'],
['permissions', null, \OCP\Constants::PERMISSION_ALL],
['shareType', '-1', \OCP\Share::SHARE_TYPE_GROUP],
['shareWith', null, 'validGroup'],
]));
$userFolder = $this->getMockBuilder('\OCP\Files\Folder')->getMock();
$this->rootFolder->expects($this->once())
->method('getUserFolder')
@ -925,7 +869,7 @@ class Share20OCSTest extends \Test\TestCase {
->method('allowGroupSharing')
->willReturn(false);
$this->ocs->createShare();
$this->ocs->createShare('valid-path', \OCP\Constants::PERMISSION_ALL, \OCP\Share::SHARE_TYPE_GROUP, 'invalidGroup');
}
/**
@ -951,7 +895,7 @@ class Share20OCSTest extends \Test\TestCase {
$this->shareManager->method('newShare')->willReturn(\OC::$server->getShareManager()->newShare());
$this->ocs->createShare();
$this->ocs->createShare('valid-path', \OCP\Constants::PERMISSION_ALL, \OCP\Share::SHARE_TYPE_LINK);
}
/**
@ -959,14 +903,6 @@ class Share20OCSTest extends \Test\TestCase {
* @expectedExceptionMessage Public upload disabled by the administrator
*/
public function testCreateShareLinkNoPublicUpload() {
$this->request
->method('getParam')
->will($this->returnValueMap([
['path', null, 'valid-path'],
['shareType', '-1', \OCP\Share::SHARE_TYPE_LINK],
['publicUpload', null, 'true'],
]));
$path = $this->getMockBuilder('\OCP\Files\Folder')->getMock();
$storage = $this->getMockBuilder('OCP\Files\Storage')->getMock();
$storage->method('instanceOfStorage')
@ -979,7 +915,7 @@ class Share20OCSTest extends \Test\TestCase {
$this->shareManager->method('newShare')->willReturn(\OC::$server->getShareManager()->newShare());
$this->shareManager->method('shareApiAllowLinks')->willReturn(true);
$this->ocs->createShare();
$this->ocs->createShare('valid-path', \OCP\Constants::PERMISSION_ALL, \OCP\Share::SHARE_TYPE_LINK, null, 'true');
}
/**
@ -987,14 +923,6 @@ class Share20OCSTest extends \Test\TestCase {
* @expectedExceptionMessage Public upload is only possible for publicly shared folders
*/
public function testCreateShareLinkPublicUploadFile() {
$this->request
->method('getParam')
->will($this->returnValueMap([
['path', null, 'valid-path'],
['shareType', '-1', \OCP\Share::SHARE_TYPE_LINK],
['publicUpload', null, 'true'],
]));
$path = $this->getMockBuilder('\OCP\Files\File')->getMock();
$storage = $this->getMockBuilder('OCP\Files\Storage')->getMock();
$storage->method('instanceOfStorage')
@ -1008,22 +936,12 @@ class Share20OCSTest extends \Test\TestCase {
$this->shareManager->method('shareApiAllowLinks')->willReturn(true);
$this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true);
$this->ocs->createShare();
$this->ocs->createShare('valid-path', \OCP\Constants::PERMISSION_ALL, \OCP\Share::SHARE_TYPE_LINK, null, 'true');
}
public function testCreateShareLinkPublicUploadFolder() {
$ocs = $this->mockFormatShare();
$this->request
->method('getParam')
->will($this->returnValueMap([
['path', null, 'valid-path'],
['shareType', '-1', \OCP\Share::SHARE_TYPE_LINK],
['publicUpload', null, 'true'],
['expireDate', '', ''],
['password', '', ''],
]));
$path = $this->getMockBuilder('\OCP\Files\Folder')->getMock();
$storage = $this->getMockBuilder('OCP\Files\Storage')->getMock();
$storage->method('instanceOfStorage')
@ -1049,7 +967,7 @@ class Share20OCSTest extends \Test\TestCase {
)->will($this->returnArgument(0));
$expected = new DataResponse(null);
$result = $ocs->createShare();
$result = $ocs->createShare('valid-path', \OCP\Constants::PERMISSION_ALL, \OCP\Share::SHARE_TYPE_LINK, null, 'true', '', '');
$this->assertInstanceOf(get_class($expected), $result);
$this->assertEquals($expected->getData(), $result->getData());
@ -1058,16 +976,6 @@ class Share20OCSTest extends \Test\TestCase {
public function testCreateShareLinkPassword() {
$ocs = $this->mockFormatShare();
$this->request
->method('getParam')
->will($this->returnValueMap([
['path', null, 'valid-path'],
['shareType', '-1', \OCP\Share::SHARE_TYPE_LINK],
['publicUpload', null, 'false'],
['expireDate', '', ''],
['password', '', 'password'],
]));
$path = $this->getMockBuilder('\OCP\Files\Folder')->getMock();
$storage = $this->getMockBuilder('OCP\Files\Storage')->getMock();
$storage->method('instanceOfStorage')
@ -1093,7 +1001,7 @@ class Share20OCSTest extends \Test\TestCase {
)->will($this->returnArgument(0));
$expected = new DataResponse(null);
$result = $ocs->createShare();
$result = $ocs->createShare('valid-path', \OCP\Constants::PERMISSION_ALL, \OCP\Share::SHARE_TYPE_LINK, null, 'false', 'password', '');
$this->assertInstanceOf(get_class($expected), $result);
$this->assertEquals($expected->getData(), $result->getData());
@ -1140,7 +1048,7 @@ class Share20OCSTest extends \Test\TestCase {
)->will($this->returnArgument(0));
$expected = new DataResponse(null);
$result = $ocs->createShare();
$result = $ocs->createShare('valid-path', \OCP\Constants::PERMISSION_ALL, \OCP\Share::SHARE_TYPE_LINK, null, 'false', '', '2000-01-01');
$this->assertInstanceOf(get_class($expected), $result);
$this->assertEquals($expected->getData(), $result->getData());
@ -1153,16 +1061,6 @@ class Share20OCSTest extends \Test\TestCase {
public function testCreateShareInvalidExpireDate() {
$ocs = $this->mockFormatShare();
$this->request
->method('getParam')
->will($this->returnValueMap([
['path', null, 'valid-path'],
['shareType', '-1', \OCP\Share::SHARE_TYPE_LINK],
['publicUpload', null, 'false'],
['expireDate', '', 'a1b2d3'],
['password', '', ''],
]));
$path = $this->getMockBuilder('\OCP\Files\Folder')->getMock();
$storage = $this->getMockBuilder('OCP\Files\Storage')->getMock();
$storage->method('instanceOfStorage')
@ -1176,7 +1074,7 @@ class Share20OCSTest extends \Test\TestCase {
$this->shareManager->method('shareApiAllowLinks')->willReturn(true);
$this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true);
$ocs->createShare();
$ocs->createShare('valid-path', \OCP\Constants::PERMISSION_ALL, \OCP\Share::SHARE_TYPE_LINK, null, 'false', '', 'a1b2d3');
}
/**
@ -1201,15 +1099,6 @@ class Share20OCSTest extends \Test\TestCase {
])->setMethods(['formatShare'])
->getMock();
$this->request
->method('getParam')
->will($this->returnValueMap([
['path', null, 'valid-path'],
['permissions', null, \OCP\Constants::PERMISSION_ALL],
['shareType', $this->any(), \OCP\Share::SHARE_TYPE_USER],
['shareWith', null, 'validUser'],
]));
$userFolder = $this->getMockBuilder('\OCP\Files\Folder')->getMock();
$this->rootFolder->expects($this->once())
->method('getUserFolder')
@ -1238,7 +1127,7 @@ class Share20OCSTest extends \Test\TestCase {
}))
->will($this->returnArgument(0));
$ocs->createShare();
$ocs->createShare('valid-path', \OCP\Constants::PERMISSION_ALL, \OCP\Share::SHARE_TYPE_USER, 'validUser');
}
/**
@ -1318,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(
@ -1337,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());
@ -1354,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);
@ -1377,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());
@ -1386,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();
@ -1398,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([]);
@ -1415,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());
@ -1436,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'
],
];
}
@ -1475,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();
@ -1486,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);
}
/**
@ -1511,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() {
@ -1545,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(
@ -1562,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());
@ -1581,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);
@ -1605,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());
@ -1627,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);
@ -1645,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());
@ -1667,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);
@ -1687,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());
@ -1713,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() {
@ -1736,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);
@ -1754,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());

View File

@ -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();
@ -84,27 +88,10 @@ class ApiTest extends TestCase {
}
/**
* @param array $data
* @return \OCP\IRequest
*/
private function createRequest(array $data) {
$request = $this->getMockBuilder('\OCP\IRequest')->getMock();
$request->method('getParam')
->will($this->returnCallback(function($param, $default = null) use ($data) {
if (isset($data[$param])) {
return $data[$param];
}
return $default;
}));
return $request;
}
/**
* @param \OCP\IRequest $request
* @param string $userId The userId of the caller
* @return \OCA\Files_Sharing\API\Share20OCS
*/
private function createOCS($request, $userId) {
private function createOCS($userId) {
$currentUser = \OC::$server->getUserManager()->get($userId);
$l = $this->getMockBuilder('\OCP\IL10N')->getMock();
@ -115,7 +102,7 @@ class ApiTest extends TestCase {
return new \OCA\Files_Sharing\API\Share20OCS(
self::APP_NAME,
$request,
$this->getMockBuilder('OCP\IRequest')->getMock(),
$this->shareManager,
\OC::$server->getGroupManager(),
\OC::$server->getUserManager(),
@ -130,14 +117,8 @@ class ApiTest extends TestCase {
* @medium
*/
function testCreateShareUserFile() {
// simulate a post request
$data['path'] = $this->filename;
$data['shareWith'] = self::TEST_FILES_SHARING_API_USER2;
$data['shareType'] = \OCP\Share::SHARE_TYPE_USER;
$request = $this->createRequest($data);
$ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER1);
$result = $ocs->createShare();
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$result = $ocs->createShare($this->filename, \OCP\Constants::PERMISSION_ALL, \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2);
$ocs->cleanup();
$data = $result->getData();
@ -146,22 +127,15 @@ class ApiTest extends TestCase {
$this->shareManager->getShareById('ocinternal:'.$data['id']);
$request = $this->createRequest([]);
$ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER1);
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$ocs->deleteShare($data['id']);
$ocs->cleanup();
}
function testCreateShareUserFolder() {
// simulate a post request
$data['path'] = $this->folder;
$data['shareWith'] = self::TEST_FILES_SHARING_API_USER2;
$data['shareType'] = \OCP\Share::SHARE_TYPE_USER;
$request = $this->createRequest($data);
$ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER1);
$result = $ocs->createShare();
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$result = $ocs->createShare($this->folder, \OCP\Constants::PERMISSION_ALL, \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2);
$ocs->cleanup();
$data = $result->getData();
@ -170,8 +144,7 @@ class ApiTest extends TestCase {
$this->shareManager->getShareById('ocinternal:'.$data['id']);
$request = $this->createRequest([]);
$ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER1);
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$ocs->deleteShare($data['id']);
$ocs->cleanup();
@ -179,14 +152,8 @@ class ApiTest extends TestCase {
function testCreateShareGroupFile() {
// simulate a post request
$data['path'] = $this->filename;
$data['shareWith'] = self::TEST_FILES_SHARING_API_GROUP1;
$data['shareType'] = \OCP\Share::SHARE_TYPE_GROUP;
$request = $this->createRequest($data);
$ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER1);
$result = $ocs->createShare();
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$result = $ocs->createShare($this->filename, \OCP\Constants::PERMISSION_ALL, \OCP\Share::SHARE_TYPE_GROUP, self::TEST_FILES_SHARING_API_GROUP1);
$ocs->cleanup();
$data = $result->getData();
@ -195,21 +162,14 @@ class ApiTest extends TestCase {
$this->shareManager->getShareById('ocinternal:'.$data['id']);
$request = $this->createRequest([]);
$ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER1);
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$ocs->deleteShare($data['id']);
$ocs->cleanup();
}
function testCreateShareGroupFolder() {
// simulate a post request
$data['path'] = $this->folder;
$data['shareWith'] = self::TEST_FILES_SHARING_API_GROUP1;
$data['shareType'] = \OCP\Share::SHARE_TYPE_GROUP;
$request = $this->createRequest($data);
$ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER1);
$result = $ocs->createShare();
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$result = $ocs->createShare($this->folder, \OCP\Constants::PERMISSION_ALL, \OCP\Share::SHARE_TYPE_GROUP, self::TEST_FILES_SHARING_API_GROUP1);
$ocs->cleanup();
$data = $result->getData();
@ -218,21 +178,15 @@ class ApiTest extends TestCase {
$this->shareManager->getShareById('ocinternal:'.$data['id']);
$request = $this->createRequest([]);
$ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER1);
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$ocs->deleteShare($data['id']);
$ocs->cleanup();
}
public function testCreateShareLink() {
// simulate a post request
$data['path'] = $this->folder;
$data['shareType'] = \OCP\Share::SHARE_TYPE_LINK;
$request = $this->createRequest($data);
$ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER1);
$result = $ocs->createShare();
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$result = $ocs->createShare($this->folder, \OCP\Constants::PERMISSION_ALL, \OCP\Share::SHARE_TYPE_LINK);
$ocs->cleanup();
$data = $result->getData();
@ -246,21 +200,14 @@ class ApiTest extends TestCase {
$this->shareManager->getShareById('ocinternal:'.$data['id']);
$request = $this->createRequest([]);
$ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER1);
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$ocs->deleteShare($data['id']);
$ocs->cleanup();
}
public function testCreateShareLinkPublicUpload() {
// simulate a post request
$data['path'] = $this->folder;
$data['shareType'] = \OCP\Share::SHARE_TYPE_LINK;
$data['publicUpload'] = 'true';
$request = $this->createRequest($data);
$ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER1);
$result = $ocs->createShare();
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$result = $ocs->createShare($this->folder, \OCP\Constants::PERMISSION_ALL, \OCP\Share::SHARE_TYPE_LINK, null, 'true');
$ocs->cleanup();
$data = $result->getData();
@ -280,8 +227,7 @@ class ApiTest extends TestCase {
$this->shareManager->getShareById('ocinternal:'.$data['id']);
$request = $this->createRequest([]);
$ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER1);
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$ocs->deleteShare($data['id']);
$ocs->cleanup();
}
@ -291,30 +237,18 @@ class ApiTest extends TestCase {
$appConfig = \OC::$server->getAppConfig();
$appConfig->setValue('core', 'shareapi_enforce_links_password', 'yes');
// don't allow to share link without a password
$data['path'] = $this->folder;
$data['shareType'] = \OCP\Share::SHARE_TYPE_LINK;
$request = $this->createRequest($data);
$ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER1);
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
try {
$ocs->createShare();
$ocs->createShare($this->folder, \OCP\Constants::PERMISSION_ALL, \OCP\Share::SHARE_TYPE_LINK);
$this->fail();
} catch (OCSForbiddenException $e) {
}
$ocs->cleanup();
// don't allow to share link without a empty password
$data = [];
$data['path'] = $this->folder;
$data['shareType'] = \OCP\Share::SHARE_TYPE_LINK;
$data['password'] = '';
$request = $this->createRequest($data);
$ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER1);
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
try {
$ocs->createShare();
$ocs->createShare($this->folder, \OCP\Constants::PERMISSION_ALL, \OCP\Share::SHARE_TYPE_LINK, null, 'false', '');
$this->fail();
} catch (OCSForbiddenException $e) {
@ -322,33 +256,19 @@ class ApiTest extends TestCase {
$ocs->cleanup();
// share with password should succeed
$data = [];
$data['path'] = $this->folder;
$data['shareType'] = \OCP\Share::SHARE_TYPE_LINK;
$data['password'] = 'foo';
$request = $this->createRequest($data);
$ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER1);
$result = $ocs->createShare();
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$result = $ocs->createShare($this->folder, \OCP\Constants::PERMISSION_ALL, \OCP\Share::SHARE_TYPE_LINK, null, 'false', 'bar');
$ocs->cleanup();
$data = $result->getData();
// setting new password should succeed
$data2 = [
'password' => 'bar',
];
$request = $this->createRequest($data2);
$ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER1);
$result = $ocs->updateShare($data['id']);
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$ocs->updateShare($data['id'], null, 'bar');
$ocs->cleanup();
// removing password should fail
$data2 = [
'password' => '',
];
$request = $this->createRequest($data2);
$ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER1);
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
try {
$ocs->updateShare($data['id']);
$this->fail();
@ -358,8 +278,7 @@ class ApiTest extends TestCase {
$ocs->cleanup();
// cleanup
$request = $this->createRequest([]);
$ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER1);
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$ocs->deleteShare($data['id']);
$ocs->cleanup();
@ -373,58 +292,40 @@ class ApiTest extends TestCase {
// sharing file to a user should work if shareapi_exclude_groups is set
// to no
\OC::$server->getAppConfig()->setValue('core', 'shareapi_exclude_groups', 'no');
$post['path'] = $this->filename;
$post['shareWith'] = self::TEST_FILES_SHARING_API_USER2;
$post['shareType'] = \OCP\Share::SHARE_TYPE_USER;
$request = $this->createRequest($post);
$ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER1);
$result = $ocs->createShare();
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$result = $ocs->createShare($this->filename, \OCP\Constants::PERMISSION_ALL, \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2);
$ocs->cleanup();
$data = $result->getData();
$this->shareManager->getShareById('ocinternal:'.$data['id']);
$request = $this->createRequest([]);
$ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER1);
$result = $ocs->deleteShare($data['id']);
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$ocs->deleteShare($data['id']);
$ocs->cleanup();
// exclude groups, but not the group the user belongs to. Sharing should still work
\OC::$server->getAppConfig()->setValue('core', 'shareapi_exclude_groups', 'yes');
\OC::$server->getAppConfig()->setValue('core', 'shareapi_exclude_groups_list', 'admin,group1,group2');
$post = [];
$post['path'] = $this->filename;
$post['shareWith'] = self::TEST_FILES_SHARING_API_USER2;
$post['shareType'] = \OCP\Share::SHARE_TYPE_USER;
$request = $this->createRequest($post);
$ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER1);
$result = $ocs->createShare();
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$result = $ocs->createShare($this->filename, \OCP\Constants::PERMISSION_ALL, \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2);
$ocs->cleanup();
$data = $result->getData();
$this->shareManager->getShareById('ocinternal:' . $data['id']);
$request = $this->createRequest([]);
$ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER1);
$result = $ocs->deleteShare($data['id']);
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$ocs->deleteShare($data['id']);
$ocs->cleanup();
// now we exclude the group the user belongs to ('group'), sharing should fail now
\OC::$server->getAppConfig()->setValue('core', 'shareapi_exclude_groups_list', 'admin,group');
$post = [];
$post['path'] = $this->filename;
$post['shareWith'] = self::TEST_FILES_SHARING_API_USER2;
$post['shareType'] = \OCP\Share::SHARE_TYPE_USER;
$request = $this->createRequest($post);
$ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER1);
$ocs->createShare();
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$ocs->createShare($this->filename, \OCP\Constants::PERMISSION_ALL, \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2);
$ocs->cleanup();
// cleanup
@ -448,8 +349,7 @@ class ApiTest extends TestCase {
$share = $this->shareManager->createShare($share);
$request = $this->createRequest([]);
$ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER1);
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$result = $ocs->getShares();
$ocs->cleanup();
@ -477,12 +377,11 @@ class ApiTest extends TestCase {
->setPermissions(31);
$share2 = $this->shareManager->createShare($share2);
$request = $this->createRequest(['shared_with_me' => 'true']);
$ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER2);
$result = $ocs->getShares();
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER2);
$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);
@ -492,13 +391,8 @@ class ApiTest extends TestCase {
* @medium
*/
function testPublicLinkUrl() {
// simulate a post request
$post['path'] = $this->folder;
$post['shareType'] = \OCP\Share::SHARE_TYPE_LINK;
$request = $this->createRequest($post);
$ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER1);
$result = $ocs->createShare();
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$result = $ocs->createShare($this->folder, \OCP\Constants::PERMISSION_ALL, \OCP\Share::SHARE_TYPE_LINK);
$ocs->cleanup();
$data = $result->getData();
@ -512,8 +406,7 @@ class ApiTest extends TestCase {
$this->assertEquals($url, $data['url']);
// check for link in getall shares
$request = $this->createRequest([]);
$ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER1);
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$result = $ocs->getShares();
$ocs->cleanup();
@ -521,8 +414,7 @@ class ApiTest extends TestCase {
$this->assertEquals($url, current($data)['url']);
// check for path
$request = $this->createRequest(['path' => $this->folder]);
$ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER1);
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$result = $ocs->getShares();
$ocs->cleanup();
@ -530,16 +422,14 @@ class ApiTest extends TestCase {
$this->assertEquals($url, current($data)['url']);
// check in share id
$request = $this->createRequest([]);
$ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER1);
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$result = $ocs->getShare($id);
$ocs->cleanup();
$data = $result->getData();
$this->assertEquals($url, current($data)['url']);
$request = $this->createRequest([]);
$ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER1);
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$ocs->deleteShare($id);
$ocs->cleanup();
}
@ -566,8 +456,7 @@ class ApiTest extends TestCase {
->setPermissions(1);
$share2 = $this->shareManager->createShare($share);
$request = $this->createRequest(['path' => $this->filename]);
$ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER1);
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$result = $ocs->getShares();
$ocs->cleanup();
@ -601,8 +490,7 @@ class ApiTest extends TestCase {
->setPermissions(19);
$share2 = $this->shareManager->createShare($share2);
$request = $this->createRequest(['path' => $this->filename]);
$ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER1);
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$result = $ocs->getShares();
$ocs->cleanup();
@ -610,9 +498,8 @@ class ApiTest extends TestCase {
$this->assertTrue(count($result->getData()) === 1);
// now also ask for the reshares
$request = $this->createRequest(['path' => $this->filename, 'reshares' => 'true']);
$ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER1);
$result = $ocs->getShares();
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$result = $ocs->getShares('false', 'true', 'false', $this->filename);
$ocs->cleanup();
// now we should get two shares, the initial share and the reshare
@ -637,8 +524,7 @@ class ApiTest extends TestCase {
$share1 = $this->shareManager->createShare($share1);
// call getShare() with share ID
$request = $this->createRequest([]);
$ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER1);
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$result = $ocs->getShare($share1->getId());
$ocs->cleanup();
@ -670,9 +556,8 @@ class ApiTest extends TestCase {
$share2 = $this->shareManager->createShare($share2);
$request = $this->createRequest(['path' => $this->folder, 'subfiles' => 'true']);
$ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER1);
$result = $ocs->getShares();
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$result = $ocs->getShares('false', 'false', 'true', $this->folder);
$ocs->cleanup();
// test should return one share within $this->folder
@ -692,10 +577,9 @@ class ApiTest extends TestCase {
->setPermissions(19);
$share1 = $this->shareManager->createShare($share1);
$request = $this->createRequest(['path' => $this->filename, 'subfiles' => 'true']);
$ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER1);
$ocs = $this->createOCS(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());
@ -743,9 +627,8 @@ class ApiTest extends TestCase {
);
foreach ($testValues as $value) {
$request = $this->createRequest(['path' => $value['query'], 'subfiles' => 'true']);
$ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER2);
$result = $ocs->getShares();
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER2);
$result = $ocs->getShares('false', 'false', 'true', $value['query']);
$ocs->cleanup();
// test should return one share within $this->folder
@ -782,8 +665,7 @@ class ApiTest extends TestCase {
->setPermissions(1);
$share2 = $this->shareManager->createShare($share2);
$request = $this->createRequest(['path' => '/', 'subfiles' => 'true']);
$ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER2);
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER2);
$result = $ocs->getShares();
$ocs->cleanup();
@ -833,7 +715,7 @@ class ApiTest extends TestCase {
* Test as recipient
*/
$request = $this->createRequest(['path' => '/', 'subfiles' => 'true']);
$ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER3);
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER3);
$result = $ocs->getShares();
$ocs->cleanup();
@ -847,8 +729,7 @@ class ApiTest extends TestCase {
/*
* Test for first owner/initiator
*/
$request = $this->createRequest([]);
$ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER1);
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$result = $ocs->getShares();
$ocs->cleanup();
@ -862,8 +743,7 @@ class ApiTest extends TestCase {
/*
* Test for second initiator
*/
$request = $this->createRequest([]);
$ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER2);
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER2);
$result = $ocs->getShares();
$ocs->cleanup();
@ -909,8 +789,7 @@ class ApiTest extends TestCase {
->setPermissions(1);
$share3 = $this->shareManager->createShare($share3);
$request = $this->createRequest(['path' => $this->subfolder]);
$ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER2);
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER2);
$result1 = $ocs->getShares();
$ocs->cleanup();
@ -919,8 +798,7 @@ class ApiTest extends TestCase {
$this->assertCount(1, $data1);
$s1 = reset($data1);
$request = $this->createRequest(['path' => $this->folder.$this->subfolder]);
$ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER2);
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER2);
$result2 = $ocs->getShares();
$ocs->cleanup();
@ -970,8 +848,7 @@ class ApiTest extends TestCase {
->setPermissions(1);
$share3 = $this->shareManager->createShare($share3);
$request = $this->createRequest(['path' => '/', 'subfiles' => 'true']);
$ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER3);
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER3);
$result = $ocs->getShares();
$ocs->cleanup();
@ -992,8 +869,7 @@ class ApiTest extends TestCase {
* @medium
*/
function testGetShareFromUnknownId() {
$request = $this->createRequest(['path' => '/', 'subfiles' => 'true']);
$ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER3);
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER3);
try {
$ocs->getShare(0);
$this->fail();
@ -1026,12 +902,8 @@ class ApiTest extends TestCase {
$share2 = $this->shareManager->createShare($share2);
// update permissions
$params = array();
$params['permissions'] = 1;
$request = $this->createRequest(['permissions' => 1]);
$ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER1);
$result = $ocs->updateShare($share1->getId());
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$ocs->updateShare($share1->getId(), 1);
$ocs->cleanup();
$share1 = $this->shareManager->getShareById('ocinternal:' . $share1->getId());
@ -1040,17 +912,15 @@ class ApiTest extends TestCase {
// update password for link share
$this->assertNull($share2->getPassword());
$request = $this->createRequest(['password' => 'foo']);
$ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER1);
$ocs->updateShare($share2->getId());
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$ocs->updateShare($share2->getId(), null, 'foo');
$ocs->cleanup();
$share2 = $this->shareManager->getShareById('ocinternal:' . $share2->getId());
$this->assertNotNull($share2->getPassword());
$request = $this->createRequest(['password' => '']);
$ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER1);
$ocs->updateShare($share2->getId());
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$ocs->updateShare($share2->getId(), null, '');
$ocs->cleanup();
$share2 = $this->shareManager->getShareById('ocinternal:' . $share2->getId());
@ -1074,8 +944,7 @@ class ApiTest extends TestCase {
->setPermissions(19);
$share1 = $this->shareManager->createShare($share1);
$request = $this->createRequest(['permissions' => \OCP\Constants::PERMISSION_ALL]);
$ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER1);
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
try {
$ocs->updateShare($share1->getId());
$this->fail();
@ -1104,9 +973,8 @@ class ApiTest extends TestCase {
$share1 = $this->shareManager->createShare($share1);
// update public upload
$request = $this->createRequest(['publicUpload' => 'true']);
$ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER1);
$result = $ocs->updateShare($share1->getId());
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$ocs->updateShare($share1->getId(), null, null, 'true');
$ocs->cleanup();
$share1 = $this->shareManager->getShareById($share1->getFullId());
@ -1148,9 +1016,8 @@ 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')]);
$ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER1);
$result = $ocs->updateShare($share1->getId());
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$ocs->updateShare($share1->getId(), null, null, null, $dateWithinRange->format('Y-m-d'));
$ocs->cleanup();
$share1 = $this->shareManager->getShareById($share1->getFullId());
@ -1159,8 +1026,7 @@ class ApiTest extends TestCase {
$this->assertEquals($dateWithinRange, $share1->getExpirationDate());
// update expire date to a value out of range
$request = $this->createRequest(['expireDate' => $dateOutOfRange->format('Y-m-d')]);
$ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER1);
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
try {
$ocs->updateShare($share1->getId());
$this->fail();
@ -1175,8 +1041,7 @@ class ApiTest extends TestCase {
$this->assertEquals($dateWithinRange, $share1->getExpirationDate());
// Try to remove expire date
$request = $this->createRequest(['expireDate' => '']);
$ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER1);
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
try {
$ocs->updateShare($share1->getId());
$this->fail();
@ -1217,14 +1082,12 @@ class ApiTest extends TestCase {
->setPermissions(1);
$share2 = $this->shareManager->createShare($share1);
$request = $this->createRequest([]);
$ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER1);
$result = $ocs->deleteShare($share1->getId());
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$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 = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$ocs->deleteShare($share2->getId());
$ocs->cleanup();
$this->assertEmpty($this->shareManager->getSharesBy(self::TEST_FILES_SHARING_API_USER2, \OCP\Share::SHARE_TYPE_USER));
@ -1254,9 +1117,8 @@ class ApiTest extends TestCase {
$share2 = $this->shareManager->createShare($share2);
// 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 = $this->createOCS(self::TEST_FILES_SHARING_API_USER2);
$ocs->deleteShare($share2->getId());
$ocs->cleanup();
$this->shareManager->deleteShare($share1);
@ -1269,8 +1131,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,
@ -1345,8 +1205,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,
@ -1368,7 +1226,8 @@ class ApiTest extends TestCase {
$this->shareManager->deleteShare($share);
\OC_Hook::clear('OC_Filesystem', 'post_initMountPoints', '\OCA\Files_Sharing\Tests\ApiTest', 'initTestMountPointsHook');
\OC_Hook::clear('OC_Filesystem', 'post_initMountPoints');
\OC_Hook::clear('\OCA\Files_Sharing\Tests\ApiTest', 'initTestMountPointsHook');
}
/**
* @expectedException \Exception
@ -1473,15 +1332,10 @@ class ApiTest extends TestCase {
* @dataProvider datesProvider
*/
public function testPublicLinkExpireDate($date, $valid) {
$request = $this->createRequest([
'path' => $this->folder,
'shareType' => \OCP\Share::SHARE_TYPE_LINK,
'expireDate' => $date,
]);
$ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER1);
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
try {
$result = $ocs->createShare();
$result = $ocs->createShare($this->folder, \OCP\Constants::PERMISSION_ALL, \OCP\Share::SHARE_TYPE_LINK, null, 'false', '', $date);
$this->assertTrue($valid);
} catch (OCSNotFoundException $e) {
$this->assertFalse($valid);
@ -1516,13 +1370,8 @@ class ApiTest extends TestCase {
$date = new \DateTime();
$date->add(new \DateInterval('P5D'));
$request = $this->createRequest([
'path' => $this->folder,
'shareType' => \OCP\Share::SHARE_TYPE_LINK,
'expireDate' => $date->format('Y-m-d'),
]);
$ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER1);
$result = $ocs->createShare();
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$result = $ocs->createShare($this->filename, \OCP\Constants::PERMISSION_ALL, \OCP\Share::SHARE_TYPE_LINK, null, 'false', '', $date->format('Y-m-d'));
$ocs->cleanup();
$data = $result->getData();
@ -1553,15 +1402,10 @@ class ApiTest extends TestCase {
$date = new \DateTime();
$date->add(new \DateInterval('P8D'));
$request = $this->createRequest([
'path' => $this->folder,
'shareType' => \OCP\Share::SHARE_TYPE_LINK,
'expireDate' => $date->format('Y-m-d'),
]);
$ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER1);
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
try {
$ocs->createShare();
$ocs->createShare($this->filename, \OCP\Constants::PERMISSION_ALL, \OCP\Share::SHARE_TYPE_LINK, null, 'false', '', $date->format('Y-m-d'));
$this->fail();
} catch (OCSException $e) {
$this->assertEquals(404, $e->getCode());
@ -1579,15 +1423,10 @@ class ApiTest extends TestCase {
$date = new \DateTime();
$date->sub(new \DateInterval('P8D'));
$request = $this->createRequest([
'path' => $this->folder,
'shareType' => \OCP\Share::SHARE_TYPE_LINK,
'expireDate' => $date->format('Y-m-d'),
]);
$ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER1);
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
try {
$result = $ocs->createShare();
$ocs->createShare($this->filename, \OCP\Constants::PERMISSION_ALL, \OCP\Share::SHARE_TYPE_LINK, null, 'false', '', $date->format('Y-m-d'));
$this->fail();
} catch(OCSException $e) {
$this->assertEquals(404, $e->getCode());
@ -1605,35 +1444,22 @@ class ApiTest extends TestCase {
*/
public function testInvisibleSharesUser() {
// simulate a post request
$request = $this->createRequest([
'path' => $this->folder,
'shareWith' => self::TEST_FILES_SHARING_API_USER2,
'shareType' => \OCP\Share::SHARE_TYPE_USER
]);
$ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER1);
$result = $ocs->createShare();
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$result = $ocs->createShare($this->folder, \OCP\Constants::PERMISSION_ALL, \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2);
$ocs->cleanup();
$data = $result->getData();
$topId = $data['id'];
$request = $this->createRequest([
'path' => $this->folder . $this->subfolder,
'shareType' => \OCP\Share::SHARE_TYPE_LINK,
]);
$ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER2);
$result = $ocs->createShare();
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER2);
$ocs->createShare($this->folder, \OCP\Constants::PERMISSION_ALL, \OCP\Share::SHARE_TYPE_LINK);
$ocs->cleanup();
$request = $this->createRequest([]);
$ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER1);
$result = $ocs->deleteShare($topId);
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$ocs->deleteShare($topId);
$ocs->cleanup();
$request = $this->createRequest([
'reshares' => 'true',
]);
$ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER1);
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$result = $ocs->getShares();
$ocs->cleanup();
@ -1646,35 +1472,22 @@ class ApiTest extends TestCase {
*/
public function testInvisibleSharesGroup() {
// simulate a post request
$request = $this->createRequest([
'path' => $this->folder,
'shareWith' => self::TEST_FILES_SHARING_API_GROUP1,
'shareType' => \OCP\Share::SHARE_TYPE_GROUP
]);
$ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER1);
$result = $ocs->createShare();
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$result = $ocs->createShare($this->folder, \OCP\Constants::PERMISSION_ALL, \OCP\Share::SHARE_TYPE_GROUP, self::TEST_FILES_SHARING_API_GROUP1);
$ocs->cleanup();
$data = $result->getData();
$topId = $data['id'];
$request = $this->createRequest([
'path' => $this->folder . $this->subfolder,
'shareType' => \OCP\Share::SHARE_TYPE_LINK,
]);
$ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER2);
$result = $ocs->createShare();
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER2);
$ocs->createShare($this->folder, \OCP\Constants::PERMISSION_ALL, \OCP\Share::SHARE_TYPE_LINK);
$ocs->cleanup();
$request = $this->createRequest([]);
$ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER1);
$result = $ocs->deleteShare($topId);
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$ocs->deleteShare($topId);
$ocs->cleanup();
$request = $this->createRequest([
'reshares' => 'true',
]);
$ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER1);
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$result = $ocs->getShares();
$ocs->cleanup();