diff --git a/lib/private/connector/sabre/aborteduploaddetectionplugin.php b/lib/private/connector/sabre/aborteduploaddetectionplugin.php index 15dca3a680..10cca647e8 100644 --- a/lib/private/connector/sabre/aborteduploaddetectionplugin.php +++ b/lib/private/connector/sabre/aborteduploaddetectionplugin.php @@ -53,6 +53,12 @@ class OC_Connector_Sabre_AbortedUploadDetectionPlugin extends Sabre_DAV_ServerPl */ public function verifyContentLength($filePath, Sabre_DAV_INode $node = null) { + // we should only react on PUT which is used for upload + // e.g. with LOCK this will not work, but LOCK uses createFile() as well + if ($this->server->httpRequest->getMethod() !== 'PUT' ) { + return; + } + // ownCloud chunked upload will be handled in its own plugin $chunkHeader = $this->server->httpRequest->getHeader('OC-Chunked'); if ($chunkHeader) { diff --git a/tests/lib/connector/sabre/aborteduploaddetectionplugin.php b/tests/lib/connector/sabre/aborteduploaddetectionplugin.php index bef0e4c4d7..201f126386 100644 --- a/tests/lib/connector/sabre/aborteduploaddetectionplugin.php +++ b/tests/lib/connector/sabre/aborteduploaddetectionplugin.php @@ -37,10 +37,11 @@ class Test_OC_Connector_Sabre_AbortedUploadDetectionPlugin extends PHPUnit_Frame /** * @dataProvider verifyContentLengthProvider */ - public function testVerifyContentLength($fileSize, $headers) + public function testVerifyContentLength($method, $fileSize, $headers) { $this->plugin->fileView = $this->buildFileViewMock($fileSize); + $headers['REQUEST_METHOD'] = $method; $this->server->httpRequest = new Sabre_HTTP_Request($headers); $this->plugin->verifyContentLength('foo.txt'); $this->assertTrue(true); @@ -50,30 +51,33 @@ class Test_OC_Connector_Sabre_AbortedUploadDetectionPlugin extends PHPUnit_Frame * @dataProvider verifyContentLengthFailedProvider * @expectedException Sabre_DAV_Exception_BadRequest */ - public function testVerifyContentLengthFailed($fileSize, $headers) + public function testVerifyContentLengthFailed($method, $fileSize, $headers) { $this->plugin->fileView = $this->buildFileViewMock($fileSize); // we expect unlink to be called $this->plugin->fileView->expects($this->once())->method('unlink'); - + $headers['REQUEST_METHOD'] = $method; $this->server->httpRequest = new Sabre_HTTP_Request($headers); $this->plugin->verifyContentLength('foo.txt'); } public function verifyContentLengthProvider() { return array( - array(1024, array()), - array(1024, array('HTTP_X_EXPECTED_ENTITY_LENGTH' => '1024')), - array(512, array('HTTP_CONTENT_LENGTH' => '512')), + array('PUT', 1024, array()), + array('PUT', 1024, array('HTTP_X_EXPECTED_ENTITY_LENGTH' => '1024')), + array('PUT', 512, array('HTTP_CONTENT_LENGTH' => '512')), + array('LOCK', 1024, array()), + array('LOCK', 1024, array('HTTP_X_EXPECTED_ENTITY_LENGTH' => '1024')), + array('LOCK', 512, array('HTTP_CONTENT_LENGTH' => '512')), ); } public function verifyContentLengthFailedProvider() { return array( - array(1025, array('HTTP_X_EXPECTED_ENTITY_LENGTH' => '1024')), - array(525, array('HTTP_CONTENT_LENGTH' => '512')), + array('PUT', 1025, array('HTTP_X_EXPECTED_ENTITY_LENGTH' => '1024')), + array('PUT', 525, array('HTTP_CONTENT_LENGTH' => '512')), ); } @@ -87,7 +91,7 @@ class Test_OC_Connector_Sabre_AbortedUploadDetectionPlugin extends PHPUnit_Frame } private function buildFileViewMock($fileSize) { - // mock filesysten + // mock filesystem $view = $this->getMock('\OC\Files\View', array('filesize', 'unlink'), array(), '', FALSE); $view->expects($this->any())->method('filesize')->withAnyParameters()->will($this->returnValue($fileSize));