summaryrefslogtreecommitdiffstats
path: root/apps/dav/tests
diff options
context:
space:
mode:
authorDaniel Kesselberg <mail@danielkesselberg.de>2020-04-14 11:48:43 +0200
committerDaniel Kesselberg <mail@danielkesselberg.de>2020-04-14 12:52:12 +0200
commit91ab8118244e2baa0135db4f8c40f8af0bc3dd6b (patch)
tree242616668f1fad085571b56d01959e884591237a /apps/dav/tests
parent09bb8ac6e269befda5833556d59d269699ca17b6 (diff)
downloadnextcloud-server-91ab8118244e2baa0135db4f8c40f8af0bc3dd6b.tar.gz
nextcloud-server-91ab8118244e2baa0135db4f8c40f8af0bc3dd6b.zip
Verify that destination is not a directory.
Otherwise file_put_contents will fail later. Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
Diffstat (limited to 'apps/dav/tests')
-rw-r--r--apps/dav/tests/unit/Upload/ChunkingPluginTest.php42
1 files changed, 38 insertions, 4 deletions
diff --git a/apps/dav/tests/unit/Upload/ChunkingPluginTest.php b/apps/dav/tests/unit/Upload/ChunkingPluginTest.php
index abbded089db..3a3fcec66d6 100644
--- a/apps/dav/tests/unit/Upload/ChunkingPluginTest.php
+++ b/apps/dav/tests/unit/Upload/ChunkingPluginTest.php
@@ -27,6 +27,7 @@ namespace OCA\DAV\Tests\unit\Upload;
use OCA\DAV\Connector\Sabre\Directory;
use OCA\DAV\Upload\ChunkingPlugin;
use OCA\DAV\Upload\FutureFile;
+use Sabre\DAV\Exception\NotFound;
use Sabre\HTTP\RequestInterface;
use Sabre\HTTP\ResponseInterface;
use Test\TestCase;
@@ -87,16 +88,41 @@ class ChunkingPluginTest extends TestCase {
$this->assertNull($this->plugin->beforeMove('source', 'target'));
}
+ public function testBeforeMoveDestinationIsDirectory() {
+ $this->expectException(\Sabre\DAV\Exception\BadRequest::class);
+ $this->expectExceptionMessage('The given destination target is a directory.');
+
+ $sourceNode = $this->createMock(FutureFile::class);
+ $targetNode = $this->createMock(Directory::class);
+
+ $this->tree->expects($this->at(0))
+ ->method('getNodeForPath')
+ ->with('source')
+ ->willReturn($sourceNode);
+ $this->tree->expects($this->at(1))
+ ->method('getNodeForPath')
+ ->with('target')
+ ->willReturn($targetNode);
+ $this->response->expects($this->never())
+ ->method('setStatus');
+
+ $this->assertNull($this->plugin->beforeMove('source', 'target'));
+ }
+
public function testBeforeMoveFutureFileSkipNonExisting() {
$sourceNode = $this->createMock(FutureFile::class);
$sourceNode->expects($this->once())
->method('getSize')
->willReturn(4);
- $this->tree->expects($this->any())
+ $this->tree->expects($this->at(0))
->method('getNodeForPath')
->with('source')
->willReturn($sourceNode);
+ $this->tree->expects($this->at(1))
+ ->method('getNodeForPath')
+ ->with('target')
+ ->willThrowException(new NotFound());
$this->tree->expects($this->any())
->method('nodeExists')
->with('target')
@@ -117,10 +143,14 @@ class ChunkingPluginTest extends TestCase {
->method('getSize')
->willReturn(4);
- $this->tree->expects($this->any())
+ $this->tree->expects($this->at(0))
->method('getNodeForPath')
->with('source')
->willReturn($sourceNode);
+ $this->tree->expects($this->at(1))
+ ->method('getNodeForPath')
+ ->with('target')
+ ->willThrowException(new NotFound());
$this->tree->expects($this->any())
->method('nodeExists')
->with('target')
@@ -143,7 +173,7 @@ class ChunkingPluginTest extends TestCase {
$this->assertFalse($this->plugin->beforeMove('source', 'target'));
}
-
+
public function testBeforeMoveSizeIsWrong() {
$this->expectException(\Sabre\DAV\Exception\BadRequest::class);
$this->expectExceptionMessage('Chunks on server do not sum up to 4 but to 3 bytes');
@@ -153,10 +183,14 @@ class ChunkingPluginTest extends TestCase {
->method('getSize')
->willReturn(3);
- $this->tree->expects($this->any())
+ $this->tree->expects($this->at(0))
->method('getNodeForPath')
->with('source')
->willReturn($sourceNode);
+ $this->tree->expects($this->at(1))
+ ->method('getNodeForPath')
+ ->with('target')
+ ->willThrowException(new NotFound());
$this->request->expects($this->once())
->method('getHeader')
->with('OC-Total-Length')