2014-09-24 19:50:33 +04:00
|
|
|
<?php
|
|
|
|
/**
|
2016-07-22 10:45:36 +03:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
*
|
2016-05-26 20:56:05 +03:00
|
|
|
* @author Björn Schießle <bjoern@schiessle.org>
|
2016-07-22 10:45:36 +03:00
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
|
|
|
* @author Robin Appelman <robin@icewind.nl>
|
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
2016-01-12 17:02:16 +03:00
|
|
|
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
|
|
|
*
|
|
|
|
* @license AGPL-3.0
|
|
|
|
*
|
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3,
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
*
|
2014-09-24 19:50:33 +04:00
|
|
|
*/
|
|
|
|
|
2016-05-25 17:04:15 +03:00
|
|
|
namespace OCA\DAV\Tests\unit\Connector\Sabre;
|
2014-09-24 19:50:33 +04:00
|
|
|
|
2016-04-13 18:31:01 +03:00
|
|
|
/**
|
2016-05-25 17:04:15 +03:00
|
|
|
* Class NodeTest
|
2016-04-13 18:31:01 +03:00
|
|
|
*
|
|
|
|
* @group DB
|
2016-05-25 17:04:15 +03:00
|
|
|
* @package OCA\DAV\Tests\unit\Connector\Sabre
|
2016-04-13 18:31:01 +03:00
|
|
|
*/
|
2016-05-25 17:04:15 +03:00
|
|
|
class NodeTest extends \Test\TestCase {
|
2014-09-24 19:50:33 +04:00
|
|
|
public function davPermissionsProvider() {
|
|
|
|
return array(
|
2014-11-25 18:28:41 +03:00
|
|
|
array(\OCP\Constants::PERMISSION_ALL, 'file', false, false, 'RDNVW'),
|
|
|
|
array(\OCP\Constants::PERMISSION_ALL, 'dir', false, false, 'RDNVCK'),
|
|
|
|
array(\OCP\Constants::PERMISSION_ALL, 'file', true, false, 'SRDNVW'),
|
|
|
|
array(\OCP\Constants::PERMISSION_ALL, 'file', true, true, 'SRMDNVW'),
|
|
|
|
array(\OCP\Constants::PERMISSION_ALL - \OCP\Constants::PERMISSION_SHARE, 'file', true, false, 'SDNVW'),
|
2016-03-03 21:47:35 +03:00
|
|
|
array(\OCP\Constants::PERMISSION_ALL - \OCP\Constants::PERMISSION_UPDATE, 'file', false, false, 'RD'),
|
|
|
|
array(\OCP\Constants::PERMISSION_ALL - \OCP\Constants::PERMISSION_DELETE, 'file', false, false, 'RNVW'),
|
2014-11-25 18:28:41 +03:00
|
|
|
array(\OCP\Constants::PERMISSION_ALL - \OCP\Constants::PERMISSION_CREATE, 'file', false, false, 'RDNVW'),
|
|
|
|
array(\OCP\Constants::PERMISSION_ALL - \OCP\Constants::PERMISSION_CREATE, 'dir', false, false, 'RDNV'),
|
2014-09-24 19:50:33 +04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider davPermissionsProvider
|
|
|
|
*/
|
|
|
|
public function testDavPermissions($permissions, $type, $shared, $mounted, $expected) {
|
|
|
|
$info = $this->getMockBuilder('\OC\Files\FileInfo')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->setMethods(array('getPermissions', 'isShared', 'isMounted', 'getType'))
|
|
|
|
->getMock();
|
|
|
|
$info->expects($this->any())
|
|
|
|
->method('getPermissions')
|
|
|
|
->will($this->returnValue($permissions));
|
|
|
|
$info->expects($this->any())
|
|
|
|
->method('isShared')
|
|
|
|
->will($this->returnValue($shared));
|
|
|
|
$info->expects($this->any())
|
|
|
|
->method('isMounted')
|
|
|
|
->will($this->returnValue($mounted));
|
|
|
|
$info->expects($this->any())
|
|
|
|
->method('getType')
|
|
|
|
->will($this->returnValue($type));
|
2016-07-15 10:52:46 +03:00
|
|
|
$view = $this->getMockBuilder('\OC\Files\View')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2014-09-24 19:50:33 +04:00
|
|
|
|
2015-08-30 20:13:01 +03:00
|
|
|
$node = new \OCA\DAV\Connector\Sabre\File($view, $info);
|
2014-09-24 19:50:33 +04:00
|
|
|
$this->assertEquals($expected, $node->getDavPermissions());
|
|
|
|
}
|
2016-03-03 22:58:18 +03:00
|
|
|
|
|
|
|
public function sharePermissionsProvider() {
|
|
|
|
return [
|
2016-04-13 18:31:01 +03:00
|
|
|
[\OCP\Files\FileInfo::TYPE_FILE, null, 1, 1],
|
|
|
|
[\OCP\Files\FileInfo::TYPE_FILE, null, 3, 3],
|
|
|
|
[\OCP\Files\FileInfo::TYPE_FILE, null, 5, 1],
|
|
|
|
[\OCP\Files\FileInfo::TYPE_FILE, null, 7, 3],
|
|
|
|
[\OCP\Files\FileInfo::TYPE_FILE, null, 9, 1],
|
|
|
|
[\OCP\Files\FileInfo::TYPE_FILE, null, 11, 3],
|
|
|
|
[\OCP\Files\FileInfo::TYPE_FILE, null, 13, 1],
|
|
|
|
[\OCP\Files\FileInfo::TYPE_FILE, null, 15, 3],
|
|
|
|
[\OCP\Files\FileInfo::TYPE_FILE, null, 17, 17],
|
|
|
|
[\OCP\Files\FileInfo::TYPE_FILE, null, 19, 19],
|
|
|
|
[\OCP\Files\FileInfo::TYPE_FILE, null, 21, 17],
|
|
|
|
[\OCP\Files\FileInfo::TYPE_FILE, null, 23, 19],
|
|
|
|
[\OCP\Files\FileInfo::TYPE_FILE, null, 25, 17],
|
|
|
|
[\OCP\Files\FileInfo::TYPE_FILE, null, 27, 19],
|
|
|
|
[\OCP\Files\FileInfo::TYPE_FILE, null, 29, 17],
|
|
|
|
[\OCP\Files\FileInfo::TYPE_FILE, null, 30, 18],
|
|
|
|
[\OCP\Files\FileInfo::TYPE_FILE, null, 31, 19],
|
|
|
|
[\OCP\Files\FileInfo::TYPE_FOLDER, null, 1, 1],
|
|
|
|
[\OCP\Files\FileInfo::TYPE_FOLDER, null, 3, 3],
|
|
|
|
[\OCP\Files\FileInfo::TYPE_FOLDER, null, 5, 5],
|
|
|
|
[\OCP\Files\FileInfo::TYPE_FOLDER, null, 7, 7],
|
|
|
|
[\OCP\Files\FileInfo::TYPE_FOLDER, null, 9, 9],
|
|
|
|
[\OCP\Files\FileInfo::TYPE_FOLDER, null, 11, 11],
|
|
|
|
[\OCP\Files\FileInfo::TYPE_FOLDER, null, 13, 13],
|
|
|
|
[\OCP\Files\FileInfo::TYPE_FOLDER, null, 15, 15],
|
|
|
|
[\OCP\Files\FileInfo::TYPE_FOLDER, null, 17, 17],
|
|
|
|
[\OCP\Files\FileInfo::TYPE_FOLDER, null, 19, 19],
|
|
|
|
[\OCP\Files\FileInfo::TYPE_FOLDER, null, 21, 21],
|
|
|
|
[\OCP\Files\FileInfo::TYPE_FOLDER, null, 23, 23],
|
|
|
|
[\OCP\Files\FileInfo::TYPE_FOLDER, null, 25, 25],
|
|
|
|
[\OCP\Files\FileInfo::TYPE_FOLDER, null, 27, 27],
|
|
|
|
[\OCP\Files\FileInfo::TYPE_FOLDER, null, 29, 29],
|
|
|
|
[\OCP\Files\FileInfo::TYPE_FOLDER, null, 30, 30],
|
|
|
|
[\OCP\Files\FileInfo::TYPE_FOLDER, null, 31, 31],
|
|
|
|
[\OCP\Files\FileInfo::TYPE_FOLDER, 'shareToken', 7, 7],
|
2016-03-03 22:58:18 +03:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider sharePermissionsProvider
|
|
|
|
*/
|
2016-04-13 18:31:01 +03:00
|
|
|
public function testSharePermissions($type, $user, $permissions, $expected) {
|
2016-07-15 10:52:46 +03:00
|
|
|
$storage = $this->getMockBuilder('\OCP\Files\Storage')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2016-03-03 22:58:18 +03:00
|
|
|
$storage->method('getPermissions')->willReturn($permissions);
|
|
|
|
|
2016-07-15 10:52:46 +03:00
|
|
|
$mountpoint = $this->getMockBuilder('\OCP\Files\Mount\IMountPoint')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2016-03-31 22:25:23 +03:00
|
|
|
$mountpoint->method('getMountPoint')->willReturn('myPath');
|
2016-04-13 18:31:01 +03:00
|
|
|
$shareManager = $this->getMockBuilder('OCP\Share\IManager')->disableOriginalConstructor()->getMock();
|
|
|
|
$share = $this->getMockBuilder('OCP\Share\IShare')->disableOriginalConstructor()->getMock();
|
|
|
|
|
|
|
|
if ($user === null) {
|
|
|
|
$shareManager->expects($this->never())->method('getShareByToken');
|
|
|
|
$share->expects($this->never())->method('getPermissions');
|
|
|
|
} else {
|
|
|
|
$shareManager->expects($this->once())->method('getShareByToken')->with($user)
|
|
|
|
->willReturn($share);
|
|
|
|
$share->expects($this->once())->method('getPermissions')->willReturn($permissions);
|
|
|
|
}
|
2016-03-31 22:25:23 +03:00
|
|
|
|
2016-03-03 22:58:18 +03:00
|
|
|
$info = $this->getMockBuilder('\OC\Files\FileInfo')
|
|
|
|
->disableOriginalConstructor()
|
2016-03-31 22:25:23 +03:00
|
|
|
->setMethods(['getStorage', 'getType', 'getMountPoint'])
|
2016-03-03 22:58:18 +03:00
|
|
|
->getMock();
|
|
|
|
|
|
|
|
$info->method('getStorage')->willReturn($storage);
|
|
|
|
$info->method('getType')->willReturn($type);
|
2016-03-31 22:25:23 +03:00
|
|
|
$info->method('getMountPoint')->willReturn($mountpoint);
|
2016-03-03 22:58:18 +03:00
|
|
|
|
2016-07-15 10:52:46 +03:00
|
|
|
$view = $this->getMockBuilder('\OC\Files\View')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2016-03-03 22:58:18 +03:00
|
|
|
|
|
|
|
$node = new \OCA\DAV\Connector\Sabre\File($view, $info);
|
2016-04-13 18:31:01 +03:00
|
|
|
$this->invokePrivate($node, 'shareManager', [$shareManager]);
|
|
|
|
$this->assertEquals($expected, $node->getSharePermissions($user));
|
2016-03-03 22:58:18 +03:00
|
|
|
}
|
2014-09-24 19:50:33 +04:00
|
|
|
}
|