summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLukas Reschke <lukas@owncloud.com>2015-06-05 19:56:20 +0200
committerLukas Reschke <lukas@owncloud.com>2015-06-05 19:56:20 +0200
commitcbb15f3cbd8812ba1e3c2cfe6bf4285286266fd5 (patch)
treee750fdd5b9a1ca6e25705712e7114a4a09bea726
parentbd5aebe256e65e5bd1478d95370c380922488b0e (diff)
parentb97be0ea02a62a8ed4c58d254714f280e071d16a (diff)
downloadnextcloud-server-cbb15f3cbd8812ba1e3c2cfe6bf4285286266fd5.tar.gz
nextcloud-server-cbb15f3cbd8812ba1e3c2cfe6bf4285286266fd5.zip
Merge pull request #16767 from owncloud/webdav-preventdeleteroot
Prevent deleting Webdav root
-rw-r--r--lib/private/connector/sabre/directory.php2
-rw-r--r--tests/lib/connector/sabre/directory.php39
2 files changed, 16 insertions, 25 deletions
diff --git a/lib/private/connector/sabre/directory.php b/lib/private/connector/sabre/directory.php
index 6e028ca9daa..85756f112e7 100644
--- a/lib/private/connector/sabre/directory.php
+++ b/lib/private/connector/sabre/directory.php
@@ -230,7 +230,7 @@ class Directory extends \OC\Connector\Sabre\Node
*/
public function delete() {
- if (!$this->info->isDeletable()) {
+ if ($this->path === '' || $this->path === '/' || !$this->info->isDeletable()) {
throw new \Sabre\DAV\Exception\Forbidden();
}
diff --git a/tests/lib/connector/sabre/directory.php b/tests/lib/connector/sabre/directory.php
index a048c7ab30a..c846f109d87 100644
--- a/tests/lib/connector/sabre/directory.php
+++ b/tests/lib/connector/sabre/directory.php
@@ -20,14 +20,14 @@ class Test_OC_Connector_Sabre_Directory extends \Test\TestCase {
$this->info = $this->getMock('OC\Files\FileInfo', array(), array(), '', false);
}
- private function getRootDir() {
+ private function getDir($path = '/') {
$this->view->expects($this->once())
->method('getRelativePath')
- ->will($this->returnValue(''));
+ ->will($this->returnValue($path));
$this->info->expects($this->once())
->method('getPath')
- ->will($this->returnValue(''));
+ ->will($this->returnValue($path));
return new \OC\Connector\Sabre\Directory($this->view, $this->info);
}
@@ -35,24 +35,13 @@ class Test_OC_Connector_Sabre_Directory extends \Test\TestCase {
/**
* @expectedException \Sabre\DAV\Exception\Forbidden
*/
- public function testCreateSharedFileFails() {
- $dir = $this->getRootDir();
- $dir->createFile('Shared');
- }
-
- /**
- * @expectedException \Sabre\DAV\Exception\Forbidden
- */
- public function testCreateSharedFolderFails() {
- $dir = $this->getRootDir();
- $dir->createDirectory('Shared');
- }
-
- /**
- * @expectedException \Sabre\DAV\Exception\Forbidden
- */
- public function testDeleteSharedFolderFails() {
- $dir = $this->getRootDir();
+ public function testDeleteRootFolderFails() {
+ $this->info->expects($this->any())
+ ->method('isDeletable')
+ ->will($this->returnValue(true));
+ $this->view->expects($this->never())
+ ->method('rmdir');
+ $dir = $this->getDir();
$dir->delete();
}
@@ -68,9 +57,10 @@ class Test_OC_Connector_Sabre_Directory extends \Test\TestCase {
// but fails
$this->view->expects($this->once())
->method('rmdir')
+ ->with('sub')
->will($this->returnValue(true));
- $dir = $this->getRootDir();
+ $dir = $this->getDir('sub');
$dir->delete();
}
@@ -82,7 +72,7 @@ class Test_OC_Connector_Sabre_Directory extends \Test\TestCase {
->method('isDeletable')
->will($this->returnValue(false));
- $dir = $this->getRootDir();
+ $dir = $this->getDir('sub');
$dir->delete();
}
@@ -98,9 +88,10 @@ class Test_OC_Connector_Sabre_Directory extends \Test\TestCase {
// but fails
$this->view->expects($this->once())
->method('rmdir')
+ ->with('sub')
->will($this->returnValue(false));
- $dir = $this->getRootDir();
+ $dir = $this->getDir('sub');
$dir->delete();
}