summaryrefslogtreecommitdiffstats
path: root/tests/lib
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2014-09-23 00:49:30 +0200
committerMorris Jobke <hey@morrisjobke.de>2014-09-23 00:49:30 +0200
commitf970c81b1e68fa21d93d0f74a84bde300a7470af (patch)
treed34c27655eef10f399c2e4b2de603fea05426193 /tests/lib
parent051ed93e24cfba0228b01027dec4e6bcf082d0af (diff)
parent470c25eff49c38cb1a3ffbb2b0ce4007093bf26e (diff)
downloadnextcloud-server-f970c81b1e68fa21d93d0f74a84bde300a7470af.tar.gz
nextcloud-server-f970c81b1e68fa21d93d0f74a84bde300a7470af.zip
Merge pull request #11215 from owncloud/dav-throwwhendeletefailed
WebDAV now throws 403 when deletion did not work
Diffstat (limited to 'tests/lib')
-rw-r--r--tests/lib/connector/sabre/directory.php64
-rw-r--r--tests/lib/connector/sabre/file.php63
2 files changed, 122 insertions, 5 deletions
diff --git a/tests/lib/connector/sabre/directory.php b/tests/lib/connector/sabre/directory.php
index 8a1550ffa95..453d8e8d42a 100644
--- a/tests/lib/connector/sabre/directory.php
+++ b/tests/lib/connector/sabre/directory.php
@@ -8,18 +8,24 @@
*/
class Test_OC_Connector_Sabre_Directory extends PHPUnit_Framework_TestCase {
+ private $view;
+ private $info;
+
+ public function setUp() {
+ $this->view = $this->getMock('OC\Files\View', array(), array(), '', false);
+ $this->info = $this->getMock('OC\Files\FileInfo', array(), array(), '', false);
+ }
+
private function getRootDir() {
- $view = $this->getMock('OC\Files\View', array(), array(), '', false);
- $view->expects($this->once())
+ $this->view->expects($this->once())
->method('getRelativePath')
->will($this->returnValue(''));
- $info = $this->getMock('OC\Files\FileInfo', array(), array(), '', false);
- $info->expects($this->once())
+ $this->info->expects($this->once())
->method('getPath')
->will($this->returnValue(''));
- return new OC_Connector_Sabre_Directory($view, $info);
+ return new OC_Connector_Sabre_Directory($this->view, $this->info);
}
/**
@@ -45,4 +51,52 @@ class Test_OC_Connector_Sabre_Directory extends PHPUnit_Framework_TestCase {
$dir = $this->getRootDir();
$dir->delete();
}
+
+ /**
+ *
+ */
+ public function testDeleteFolderWhenAllowed() {
+ // deletion allowed
+ $this->info->expects($this->once())
+ ->method('isDeletable')
+ ->will($this->returnValue(true));
+
+ // but fails
+ $this->view->expects($this->once())
+ ->method('rmdir')
+ ->will($this->returnValue(true));
+
+ $dir = $this->getRootDir();
+ $dir->delete();
+ }
+
+ /**
+ * @expectedException \Sabre\DAV\Exception\Forbidden
+ */
+ public function testDeleteFolderFailsWhenNotAllowed() {
+ $this->info->expects($this->once())
+ ->method('isDeletable')
+ ->will($this->returnValue(false));
+
+ $dir = $this->getRootDir();
+ $dir->delete();
+ }
+
+ /**
+ * @expectedException \Sabre\DAV\Exception\Forbidden
+ */
+ public function testDeleteFolderThrowsWhenDeletionFailed() {
+ // deletion allowed
+ $this->info->expects($this->once())
+ ->method('isDeletable')
+ ->will($this->returnValue(true));
+
+ // but fails
+ $this->view->expects($this->once())
+ ->method('rmdir')
+ ->will($this->returnValue(false));
+
+ $dir = $this->getRootDir();
+ $dir->delete();
+ }
}
diff --git a/tests/lib/connector/sabre/file.php b/tests/lib/connector/sabre/file.php
index 1602c5181fe..0993a27f372 100644
--- a/tests/lib/connector/sabre/file.php
+++ b/tests/lib/connector/sabre/file.php
@@ -143,4 +143,67 @@ class Test_OC_Connector_Sabre_File extends PHPUnit_Framework_TestCase {
// action
$file->put('test data');
}
+
+ /**
+ *
+ */
+ public function testDeleteWhenAllowed() {
+ // setup
+ $view = $this->getMock('\OC\Files\View',
+ array());
+
+ $view->expects($this->once())
+ ->method('unlink')
+ ->will($this->returnValue(true));
+
+ $info = new \OC\Files\FileInfo('/test.txt', null, null, array(
+ 'permissions' => \OCP\PERMISSION_ALL
+ ));
+
+ $file = new OC_Connector_Sabre_File($view, $info);
+
+ // action
+ $file->delete();
+ }
+
+ /**
+ * @expectedException \Sabre\DAV\Exception\Forbidden
+ */
+ public function testDeleteThrowsWhenDeletionNotAllowed() {
+ // setup
+ $view = $this->getMock('\OC\Files\View',
+ array());
+
+ $info = new \OC\Files\FileInfo('/test.txt', null, null, array(
+ 'permissions' => 0
+ ));
+
+ $file = new OC_Connector_Sabre_File($view, $info);
+
+ // action
+ $file->delete();
+ }
+
+ /**
+ * @expectedException \Sabre\DAV\Exception\Forbidden
+ */
+ public function testDeleteThrowsWhenDeletionFailed() {
+ // setup
+ $view = $this->getMock('\OC\Files\View',
+ array());
+
+ // but fails
+ $view->expects($this->once())
+ ->method('unlink')
+ ->will($this->returnValue(false));
+
+ $info = new \OC\Files\FileInfo('/test.txt', null, null, array(
+ 'permissions' => \OCP\PERMISSION_ALL
+ ));
+
+ $file = new OC_Connector_Sabre_File($view, $info);
+
+ // action
+ $file->delete();
+ }
}