Skip to content

Commit

Permalink
Additional perm check in Webdav (#25453)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincent Petry authored and DeepDiver1975 committed Jul 12, 2016
1 parent 8f42a1f commit 86a71c6
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 2 deletions.
8 changes: 8 additions & 0 deletions lib/private/connector/sabre/objecttree.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,14 @@ public function copy($source, $destination) {
// this will trigger existence check
$this->getNodeForPath($source);

$destinationDir = dirname($destination);
if ($destinationDir === '.') {
$destinationDir = '';
}
if (!$this->fileView->isCreatable($destinationDir)) {
throw new \Sabre\DAV\Exception\Forbidden();
}

try {
if ($this->fileView->is_file($source)) {
$this->fileView->copy($source, $destination);
Expand Down
85 changes: 83 additions & 2 deletions tests/lib/connector/sabre/objecttree.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


use OC\Files\FileInfo;
use OC_Connector_Sabre_Directory;
use OC\Files\Storage\Temporary;
use PHPUnit_Framework_TestCase;

class TestDoubleFileView extends \OC\Files\View {
Expand Down Expand Up @@ -103,7 +103,7 @@ private function moveTest($source, $dest, $updatables, $deletables) {

$info = new FileInfo('', null, null, array(), null);

$rootDir = new OC_Connector_Sabre_Directory($view, $info);
$rootDir = new \OC_Connector_Sabre_Directory($view, $info);
$objectTree = $this->getMock('\OC\Connector\Sabre\ObjectTree',
array('nodeExists', 'getNodeForPath'),
array($rootDir, $view));
Expand All @@ -119,4 +119,85 @@ private function moveTest($source, $dest, $updatables, $deletables) {
$objectTree->move($source, $dest);
}

public function copyDataProvider() {
return [
// copy into same dir
['a', 'b', ''],
// copy into same dir
['a/a', 'a/b', 'a'],
// copy into another dir
['a', 'sub/a', 'sub'],
];
}

/**
* @dataProvider copyDataProvider
*/
public function testCopy($sourcePath, $targetPath, $targetParent) {
$view = $this->getMock('\OC\Files\View');
$view->expects($this->once())
->method('is_file')
->with($sourcePath)
->will($this->returnValue(true));
$view->expects($this->once())
->method('isCreatable')
->with($targetParent)
->will($this->returnValue(true));
$view->expects($this->once())
->method('copy')
->with($sourcePath, $targetPath)
->will($this->returnValue(true));

$info = new FileInfo('', null, null, array(), null);

$rootDir = new \OC_Connector_Sabre_Directory($view, $info);
$objectTree = $this->getMock('\OC\Connector\Sabre\ObjectTree',
array('nodeExists', 'getNodeForPath'),
array($rootDir, $view));

$objectTree->expects($this->once())
->method('getNodeForPath')
->with($this->identicalTo($sourcePath))
->will($this->returnValue(false));

/** @var $objectTree \OC\Connector\Sabre\ObjectTree */
$mountManager = \OC\Files\Filesystem::getMountManager();
$objectTree->init($rootDir, $view, $mountManager);
$objectTree->copy($sourcePath, $targetPath);
}

/**
* @dataProvider copyDataProvider
* @expectedException \Sabre\DAV\Exception\Forbidden
*/
public function testCopyFailNotCreatable($sourcePath, $targetPath, $targetParent) {
$view = $this->getMock('\OC\Files\View');
$view->expects($this->any())
->method('is_file')
->with($sourcePath)
->will($this->returnValue(true));
$view->expects($this->once())
->method('isCreatable')
->with($targetParent)
->will($this->returnValue(false));
$view->expects($this->never())
->method('copy');

$info = new FileInfo('', null, null, array(), null);

$rootDir = new \OC_Connector_Sabre_Directory($view, $info);
$objectTree = $this->getMock('\OC\Connector\Sabre\ObjectTree',
array('nodeExists', 'getNodeForPath'),
array($rootDir, $view));

$objectTree->expects($this->once())
->method('getNodeForPath')
->with($this->identicalTo($sourcePath))
->will($this->returnValue(false));

/** @var $objectTree \OC\Connector\Sabre\ObjectTree */
$mountManager = \OC\Files\Filesystem::getMountManager();
$objectTree->init($rootDir, $view, $mountManager);
$objectTree->copy($sourcePath, $targetPath);
}
}

0 comments on commit 86a71c6

Please sign in to comment.