summaryrefslogtreecommitdiffstats
path: root/apps/dav/tests
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2017-07-31 22:46:19 +0200
committerDaniel Calviño Sánchez <danxuliu@gmail.com>2017-12-15 14:46:36 +0100
commit8c5d656f3b605a8cedbf412b7498b936e12866e6 (patch)
treef6d87ef4c5d7240ec03107856428e5c452be1a82 /apps/dav/tests
parentb19b1379699cf7790a13575f27a05b2f6db14f6a (diff)
downloadnextcloud-server-8c5d656f3b605a8cedbf412b7498b936e12866e6.tar.gz
nextcloud-server-8c5d656f3b605a8cedbf412b7498b936e12866e6.zip
Handle OC-Total-Length in new chunking
Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
Diffstat (limited to 'apps/dav/tests')
-rw-r--r--apps/dav/tests/unit/Connector/Sabre/FileTest.php4
-rw-r--r--apps/dav/tests/unit/Connector/Sabre/FilesPluginTest.php57
-rw-r--r--apps/dav/tests/unit/Upload/ChunkingPluginTest.php167
3 files changed, 171 insertions, 57 deletions
diff --git a/apps/dav/tests/unit/Connector/Sabre/FileTest.php b/apps/dav/tests/unit/Connector/Sabre/FileTest.php
index 1db9b7948e3..5e7a6374206 100644
--- a/apps/dav/tests/unit/Connector/Sabre/FileTest.php
+++ b/apps/dav/tests/unit/Connector/Sabre/FileTest.php
@@ -78,6 +78,9 @@ class FileTest extends \Test\TestCase {
parent::tearDown();
}
+ /**
+ * @return \PHPUnit_Framework_MockObject_MockObject | Storage
+ */
private function getMockStorage() {
$storage = $this->getMockBuilder(Storage::class)
->disableOriginalConstructor()
@@ -165,6 +168,7 @@ class FileTest extends \Test\TestCase {
->setConstructorArgs([['datadir' => \OC::$server->getTempManager()->getTemporaryFolder()]])
->getMock();
\OC\Files\Filesystem::mount($storage, [], $this->user . '/');
+ /** @var View | \PHPUnit_Framework_MockObject_MockObject $view */
$view = $this->getMockBuilder(View::class)
->setMethods(['getRelativePath', 'resolvePath'])
->getMock();
diff --git a/apps/dav/tests/unit/Connector/Sabre/FilesPluginTest.php b/apps/dav/tests/unit/Connector/Sabre/FilesPluginTest.php
index 3372f99e957..800bdfd3598 100644
--- a/apps/dav/tests/unit/Connector/Sabre/FilesPluginTest.php
+++ b/apps/dav/tests/unit/Connector/Sabre/FilesPluginTest.php
@@ -43,8 +43,6 @@ use Sabre\DAV\Tree;
use Sabre\HTTP\RequestInterface;
use Sabre\HTTP\ResponseInterface;
use Test\TestCase;
-use OCA\DAV\Upload\FutureFile;
-use OCA\DAV\Connector\Sabre\Directory;
use OCP\Files\FileInfo;
/**
@@ -600,59 +598,4 @@ class FilesPluginTest extends TestCase {
$this->assertEquals("false", $propFind->get(self::HAS_PREVIEW_PROPERTYNAME));
}
-
- public function testBeforeMoveFutureFileSkip() {
- $node = $this->createMock(Directory::class);
-
- $this->tree->expects($this->any())
- ->method('getNodeForPath')
- ->with('source')
- ->will($this->returnValue($node));
- $this->server->httpResponse->expects($this->never())
- ->method('setStatus');
-
- $this->assertNull($this->plugin->beforeMoveFutureFile('source', 'target'));
- }
-
- public function testBeforeMoveFutureFileSkipNonExisting() {
- $sourceNode = $this->createMock(FutureFile::class);
-
- $this->tree->expects($this->any())
- ->method('getNodeForPath')
- ->with('source')
- ->will($this->returnValue($sourceNode));
- $this->tree->expects($this->any())
- ->method('nodeExists')
- ->with('target')
- ->will($this->returnValue(false));
- $this->server->httpResponse->expects($this->never())
- ->method('setStatus');
-
- $this->assertNull($this->plugin->beforeMoveFutureFile('source', 'target'));
- }
-
- public function testBeforeMoveFutureFileMoveIt() {
- $sourceNode = $this->createMock(FutureFile::class);
-
- $this->tree->expects($this->any())
- ->method('getNodeForPath')
- ->with('source')
- ->will($this->returnValue($sourceNode));
- $this->tree->expects($this->any())
- ->method('nodeExists')
- ->with('target')
- ->will($this->returnValue(true));
- $this->tree->expects($this->once())
- ->method('move')
- ->with('source', 'target');
-
- $this->server->httpResponse->expects($this->once())
- ->method('setHeader')
- ->with('Content-Length', '0');
- $this->server->httpResponse->expects($this->once())
- ->method('setStatus')
- ->with(204);
-
- $this->assertFalse($this->plugin->beforeMoveFutureFile('source', 'target'));
- }
}
diff --git a/apps/dav/tests/unit/Upload/ChunkingPluginTest.php b/apps/dav/tests/unit/Upload/ChunkingPluginTest.php
new file mode 100644
index 00000000000..3951d1f1795
--- /dev/null
+++ b/apps/dav/tests/unit/Upload/ChunkingPluginTest.php
@@ -0,0 +1,167 @@
+<?php
+/**
+ * @author Thomas Müller <thomas.mueller@tmit.eu>
+ *
+ * @copyright Copyright (c) 2017, ownCloud GmbH
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+
+namespace OCA\DAV\Tests\unit\Upload;
+
+
+use OCA\DAV\Upload\ChunkingPlugin;
+use Sabre\HTTP\RequestInterface;
+use Sabre\HTTP\ResponseInterface;
+use Test\TestCase;
+use OCA\DAV\Upload\FutureFile;
+use OCA\DAV\Connector\Sabre\Directory;
+
+class ChunkingPluginTest extends TestCase {
+
+
+ /**
+ * @var \Sabre\DAV\Server | \PHPUnit_Framework_MockObject_MockObject
+ */
+ private $server;
+
+ /**
+ * @var \Sabre\DAV\Tree | \PHPUnit_Framework_MockObject_MockObject
+ */
+ private $tree;
+
+ /**
+ * @var ChunkingPlugin
+ */
+ private $plugin;
+ /** @var RequestInterface | \PHPUnit_Framework_MockObject_MockObject */
+ private $request;
+ /** @var ResponseInterface | \PHPUnit_Framework_MockObject_MockObject */
+ private $response;
+
+ public function setUp() {
+ parent::setUp();
+
+ $this->server = $this->getMockBuilder('\Sabre\DAV\Server')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $this->tree = $this->getMockBuilder('\Sabre\DAV\Tree')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $this->server->tree = $this->tree;
+ $this->plugin = new ChunkingPlugin();
+
+ $this->request = $this->createMock(RequestInterface::class);
+ $this->response = $this->createMock(ResponseInterface::class);
+ $this->server->httpRequest = $this->request;
+ $this->server->httpResponse = $this->response;
+
+ $this->plugin->initialize($this->server);
+ }
+
+ public function testBeforeMoveFutureFileSkip() {
+ $node = $this->createMock(Directory::class);
+
+ $this->tree->expects($this->any())
+ ->method('getNodeForPath')
+ ->with('source')
+ ->will($this->returnValue($node));
+ $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())
+ ->method('getNodeForPath')
+ ->with('source')
+ ->will($this->returnValue($sourceNode));
+ $this->tree->expects($this->any())
+ ->method('nodeExists')
+ ->with('target')
+ ->will($this->returnValue(false));
+ $this->response->expects($this->never())
+ ->method('setStatus');
+ $this->request->expects($this->once())
+ ->method('getHeader')
+ ->with('OC-Total-Length')
+ ->willReturn(4);
+
+ $this->assertNull($this->plugin->beforeMove('source', 'target'));
+ }
+
+ public function testBeforeMoveFutureFileMoveIt() {
+ $sourceNode = $this->createMock(FutureFile::class);
+ $sourceNode->expects($this->once())
+ ->method('getSize')
+ ->willReturn(4);
+
+ $this->tree->expects($this->any())
+ ->method('getNodeForPath')
+ ->with('source')
+ ->will($this->returnValue($sourceNode));
+ $this->tree->expects($this->any())
+ ->method('nodeExists')
+ ->with('target')
+ ->will($this->returnValue(true));
+ $this->tree->expects($this->once())
+ ->method('move')
+ ->with('source', 'target');
+
+ $this->response->expects($this->once())
+ ->method('setHeader')
+ ->with('Content-Length', '0');
+ $this->response->expects($this->once())
+ ->method('setStatus')
+ ->with(204);
+ $this->request->expects($this->once())
+ ->method('getHeader')
+ ->with('OC-Total-Length')
+ ->willReturn('4');
+
+ $this->assertFalse($this->plugin->beforeMove('source', 'target'));
+ }
+
+ /**
+ * @expectedException \Sabre\DAV\Exception\BadRequest
+ * @expectedExceptionMessage Chunks on server do not sum up to 4 but to 3 bytes
+ */
+ public function testBeforeMoveSizeIsWrong() {
+ $sourceNode = $this->createMock(FutureFile::class);
+ $sourceNode->expects($this->once())
+ ->method('getSize')
+ ->willReturn(3);
+
+ $this->tree->expects($this->any())
+ ->method('getNodeForPath')
+ ->with('source')
+ ->will($this->returnValue($sourceNode));
+ $this->request->expects($this->once())
+ ->method('getHeader')
+ ->with('OC-Total-Length')
+ ->willReturn('4');
+
+ $this->assertFalse($this->plugin->beforeMove('source', 'target'));
+ }
+
+}