Fix checkMove() implementation for dav v2 - fixes #24776 (#24971)

This commit is contained in:
Thomas Müller 2016-06-06 17:01:27 +02:00 committed by Arthur Schiwon
parent 3b5c169869
commit c4b80b86db
No known key found for this signature in database
GPG Key ID: 7424F1874854DF23
3 changed files with 46 additions and 27 deletions

View File

@ -168,20 +168,19 @@ class FilesPlugin extends ServerPlugin {
*/ */
function checkMove($source, $destination) { function checkMove($source, $destination) {
$sourceNode = $this->tree->getNodeForPath($source); $sourceNode = $this->tree->getNodeForPath($source);
if ($sourceNode instanceof FutureFile) { if (!$sourceNode instanceof Node) {
return; return;
} }
list($sourceDir,) = \Sabre\HTTP\URLUtil::splitPath($source); list($sourceDir,) = \Sabre\HTTP\URLUtil::splitPath($source);
list($destinationDir,) = \Sabre\HTTP\URLUtil::splitPath($destination); list($destinationDir,) = \Sabre\HTTP\URLUtil::splitPath($destination);
if ($sourceDir !== $destinationDir) { if ($sourceDir !== $destinationDir) {
$sourceFileInfo = $this->fileView->getFileInfo($source); $sourceNodeFileInfo = $sourceNode->getFileInfo();
if (is_null($sourceNodeFileInfo)) {
if ($sourceFileInfo === false) {
throw new NotFound($source . ' does not exist'); throw new NotFound($source . ' does not exist');
} }
if (!$sourceFileInfo->isDeletable()) { if (!$sourceNodeFileInfo->isDeletable()) {
throw new Forbidden($source . " cannot be deleted"); throw new Forbidden($source . " cannot be deleted");
} }
} }

View File

@ -347,4 +347,8 @@ abstract class Node implements \Sabre\DAV\INode {
public function changeLock($type) { public function changeLock($type) {
$this->fileView->changeLock($this->path, $type); $this->fileView->changeLock($this->path, $type);
} }
public function getFileInfo() {
return $this->info;
}
} }

View File

@ -24,6 +24,7 @@
*/ */
namespace OCA\DAV\Tests\unit\Connector\Sabre; namespace OCA\DAV\Tests\unit\Connector\Sabre;
use OCA\DAV\Connector\Sabre\FilesPlugin;
use OCP\Files\StorageNotAvailableException; use OCP\Files\StorageNotAvailableException;
use Sabre\DAV\PropFind; use Sabre\DAV\PropFind;
use Sabre\DAV\PropPatch; use Sabre\DAV\PropPatch;
@ -36,16 +37,16 @@ use Test\TestCase;
* See the COPYING-README file. * See the COPYING-README file.
*/ */
class FilesPluginTest extends TestCase { class FilesPluginTest extends TestCase {
const GETETAG_PROPERTYNAME = \OCA\DAV\Connector\Sabre\FilesPlugin::GETETAG_PROPERTYNAME; const GETETAG_PROPERTYNAME = FilesPlugin::GETETAG_PROPERTYNAME;
const FILEID_PROPERTYNAME = \OCA\DAV\Connector\Sabre\FilesPlugin::FILEID_PROPERTYNAME; const FILEID_PROPERTYNAME = FilesPlugin::FILEID_PROPERTYNAME;
const INTERNAL_FILEID_PROPERTYNAME = \OCA\DAV\Connector\Sabre\FilesPlugin::INTERNAL_FILEID_PROPERTYNAME; const INTERNAL_FILEID_PROPERTYNAME = FilesPlugin::INTERNAL_FILEID_PROPERTYNAME;
const SIZE_PROPERTYNAME = \OCA\DAV\Connector\Sabre\FilesPlugin::SIZE_PROPERTYNAME; const SIZE_PROPERTYNAME = FilesPlugin::SIZE_PROPERTYNAME;
const PERMISSIONS_PROPERTYNAME = \OCA\DAV\Connector\Sabre\FilesPlugin::PERMISSIONS_PROPERTYNAME; const PERMISSIONS_PROPERTYNAME = FilesPlugin::PERMISSIONS_PROPERTYNAME;
const LASTMODIFIED_PROPERTYNAME = \OCA\DAV\Connector\Sabre\FilesPlugin::LASTMODIFIED_PROPERTYNAME; const LASTMODIFIED_PROPERTYNAME = FilesPlugin::LASTMODIFIED_PROPERTYNAME;
const DOWNLOADURL_PROPERTYNAME = \OCA\DAV\Connector\Sabre\FilesPlugin::DOWNLOADURL_PROPERTYNAME; const DOWNLOADURL_PROPERTYNAME = FilesPlugin::DOWNLOADURL_PROPERTYNAME;
const OWNER_ID_PROPERTYNAME = \OCA\DAV\Connector\Sabre\FilesPlugin::OWNER_ID_PROPERTYNAME; const OWNER_ID_PROPERTYNAME = FilesPlugin::OWNER_ID_PROPERTYNAME;
const OWNER_DISPLAY_NAME_PROPERTYNAME = \OCA\DAV\Connector\Sabre\FilesPlugin::OWNER_DISPLAY_NAME_PROPERTYNAME; const OWNER_DISPLAY_NAME_PROPERTYNAME = FilesPlugin::OWNER_DISPLAY_NAME_PROPERTYNAME;
const DATA_FINGERPRINT_PROPERTYNAME = \OCA\DAV\Connector\Sabre\FilesPlugin::DATA_FINGERPRINT_PROPERTYNAME; const DATA_FINGERPRINT_PROPERTYNAME = FilesPlugin::DATA_FINGERPRINT_PROPERTYNAME;
/** /**
* @var \Sabre\DAV\Server | \PHPUnit_Framework_MockObject_MockObject * @var \Sabre\DAV\Server | \PHPUnit_Framework_MockObject_MockObject
@ -58,7 +59,7 @@ class FilesPluginTest extends TestCase {
private $tree; private $tree;
/** /**
* @var \OCA\DAV\Connector\Sabre\FilesPlugin * @var FilesPlugin
*/ */
private $plugin; private $plugin;
@ -84,11 +85,11 @@ class FilesPluginTest extends TestCase {
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$this->config = $this->getMock('\OCP\IConfig'); $this->config = $this->getMock('\OCP\IConfig');
$this->config->method('getSystemValue') $this->config->expects($this->any())->method('getSystemValue')
->with($this->equalTo('data-fingerprint'), $this->equalTo('')) ->with($this->equalTo('data-fingerprint'), $this->equalTo(''))
->willReturn('my_fingerprint'); ->willReturn('my_fingerprint');
$this->plugin = new \OCA\DAV\Connector\Sabre\FilesPlugin( $this->plugin = new FilesPlugin(
$this->tree, $this->tree,
$this->view, $this->view,
$this->config $this->config
@ -263,7 +264,7 @@ class FilesPluginTest extends TestCase {
} }
public function testGetPublicPermissions() { public function testGetPublicPermissions() {
$this->plugin = new \OCA\DAV\Connector\Sabre\FilesPlugin( $this->plugin = new FilesPlugin(
$this->tree, $this->tree,
$this->view, $this->view,
$this->config, $this->config,
@ -331,7 +332,7 @@ class FilesPluginTest extends TestCase {
$node = $this->getMockBuilder('\OCA\DAV\Connector\Sabre\Directory') $node = $this->getMockBuilder('\OCA\DAV\Connector\Sabre\Directory')
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$node->method('getPath')->willReturn('/'); $node->expects($this->any())->method('getPath')->willReturn('/');
$propFind = new PropFind( $propFind = new PropFind(
'/', '/',
@ -432,11 +433,16 @@ class FilesPluginTest extends TestCase {
->method('isDeletable') ->method('isDeletable')
->willReturn(false); ->willReturn(false);
$this->view->expects($this->once()) $node = $this->getMockBuilder('\OCA\DAV\Connector\Sabre\Node')
->disableOriginalConstructor()
->getMock();
$node->expects($this->once())
->method('getFileInfo') ->method('getFileInfo')
->with('FolderA/test.txt')
->willReturn($fileInfoFolderATestTXT); ->willReturn($fileInfoFolderATestTXT);
$this->tree->expects($this->once())->method('getNodeForPath')
->willReturn($node);
$this->plugin->checkMove('FolderA/test.txt', 'test.txt'); $this->plugin->checkMove('FolderA/test.txt', 'test.txt');
} }
@ -448,11 +454,16 @@ class FilesPluginTest extends TestCase {
->method('isDeletable') ->method('isDeletable')
->willReturn(true); ->willReturn(true);
$this->view->expects($this->once()) $node = $this->getMockBuilder('\OCA\DAV\Connector\Sabre\Node')
->disableOriginalConstructor()
->getMock();
$node->expects($this->once())
->method('getFileInfo') ->method('getFileInfo')
->with('FolderA/test.txt')
->willReturn($fileInfoFolderATestTXT); ->willReturn($fileInfoFolderATestTXT);
$this->tree->expects($this->once())->method('getNodeForPath')
->willReturn($node);
$this->plugin->checkMove('FolderA/test.txt', 'test.txt'); $this->plugin->checkMove('FolderA/test.txt', 'test.txt');
} }
@ -461,10 +472,15 @@ class FilesPluginTest extends TestCase {
* @expectedExceptionMessage FolderA/test.txt does not exist * @expectedExceptionMessage FolderA/test.txt does not exist
*/ */
public function testMoveSrcNotExist() { public function testMoveSrcNotExist() {
$this->view->expects($this->once()) $node = $this->getMockBuilder('\OCA\DAV\Connector\Sabre\Node')
->disableOriginalConstructor()
->getMock();
$node->expects($this->once())
->method('getFileInfo') ->method('getFileInfo')
->with('FolderA/test.txt') ->willReturn(null);
->willReturn(false);
$this->tree->expects($this->once())->method('getNodeForPath')
->willReturn($node);
$this->plugin->checkMove('FolderA/test.txt', 'test.txt'); $this->plugin->checkMove('FolderA/test.txt', 'test.txt');
} }