diff options
author | Vincent Petry <pvince81@owncloud.com> | 2015-06-12 16:45:20 +0200 |
---|---|---|
committer | Vincent Petry <pvince81@owncloud.com> | 2015-06-12 16:45:20 +0200 |
commit | 446f628136532fe556757c3fe39655c6304e3cb9 (patch) | |
tree | 26d37d32ab4fa033b32f6377bc78899835fb3617 | |
parent | bb0ea6336df84d391c0d972a56f27077f632948c (diff) | |
parent | 5a5639ab763662d8105bc61c5f124fcc99a7a813 (diff) | |
download | nextcloud-server-446f628136532fe556757c3fe39655c6304e3cb9.tar.gz nextcloud-server-446f628136532fe556757c3fe39655c6304e3cb9.zip |
Merge pull request #16886 from owncloud/webdav-verify-path-again
verify path when getting a node for sabredav
-rw-r--r-- | lib/private/connector/sabre/objecttree.php | 4 | ||||
-rw-r--r-- | tests/lib/connector/sabre/objecttree.php | 62 |
2 files changed, 60 insertions, 6 deletions
diff --git a/lib/private/connector/sabre/objecttree.php b/lib/private/connector/sabre/objecttree.php index c56fd7ee4db..a73c9a860b0 100644 --- a/lib/private/connector/sabre/objecttree.php +++ b/lib/private/connector/sabre/objecttree.php @@ -105,6 +105,10 @@ class ObjectTree extends \Sabre\DAV\Tree { } $path = trim($path, '/'); + if ($path) { + $this->fileView->verifyPath($path, basename($path)); + } + if (isset($this->cache[$path])) { return $this->cache[$path]; } diff --git a/tests/lib/connector/sabre/objecttree.php b/tests/lib/connector/sabre/objecttree.php index 53e53f1e07b..b9f8591b10a 100644 --- a/tests/lib/connector/sabre/objecttree.php +++ b/tests/lib/connector/sabre/objecttree.php @@ -11,6 +11,7 @@ namespace Test\OC\Connector\Sabre; use OC\Files\FileInfo; use OC\Connector\Sabre\Directory; +use OC\Files\Storage\Temporary; class TestDoubleFileView extends \OC\Files\View { @@ -36,7 +37,7 @@ class TestDoubleFileView extends \OC\Files\View { return $this->canRename; } - public function getRelativePath($path){ + public function getRelativePath($path) { return $path; } } @@ -122,11 +123,11 @@ class ObjectTree extends \Test\TestCase { * @dataProvider nodeForPathProvider */ public function testGetNodeForPath( - $inputFileName, - $fileInfoQueryPath, - $outputFileName, - $type, - $enableChunkingHeader + $inputFileName, + $fileInfoQueryPath, + $outputFileName, + $type, + $enableChunkingHeader ) { if ($enableChunkingHeader) { @@ -237,4 +238,53 @@ class ObjectTree extends \Test\TestCase { ); } + /** + * @expectedException \OCP\Files\InvalidPathException + */ + public function testGetNodeForPathInvalidPath() { + $path = '/foo\bar'; + + + $storage = new Temporary([]); + + $view = $this->getMock('\OC\Files\View', ['resolvePath']); + $view->expects($this->once()) + ->method('resolvePath') + ->will($this->returnCallback(function($path) use ($storage){ + return [$storage, ltrim($path, '/')]; + })); + + $rootNode = $this->getMockBuilder('\OC\Connector\Sabre\Directory') + ->disableOriginalConstructor() + ->getMock(); + $mountManager = $this->getMock('\OC\Files\Mount\Manager'); + + $tree = new \OC\Connector\Sabre\ObjectTree(); + $tree->init($rootNode, $view, $mountManager); + + $tree->getNodeForPath($path); + } + public function testGetNodeForPathRoot() { + $path = '/'; + + + $storage = new Temporary([]); + + $view = $this->getMock('\OC\Files\View', ['resolvePath']); + $view->expects($this->any()) + ->method('resolvePath') + ->will($this->returnCallback(function ($path) use ($storage) { + return [$storage, ltrim($path, '/')]; + })); + + $rootNode = $this->getMockBuilder('\OC\Connector\Sabre\Directory') + ->disableOriginalConstructor() + ->getMock(); + $mountManager = $this->getMock('\OC\Files\Mount\Manager'); + + $tree = new \OC\Connector\Sabre\ObjectTree(); + $tree->init($rootNode, $view, $mountManager); + + $tree->getNodeForPath($path); + } } |