upload abortion detection only for PUT

e.g. LOCK would break with this approach
This commit is contained in:
Thomas Müller 2013-10-04 16:09:07 +02:00
parent 7337b34110
commit 414b2eb4b6
2 changed files with 19 additions and 9 deletions

View File

@ -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) {

View File

@ -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));