Add tests for uploading to locked files

This commit is contained in:
Robin Appelman 2015-09-14 15:33:34 +02:00
parent 23eaf27a5b
commit 21d02673be
1 changed files with 81 additions and 1 deletions

View File

@ -8,7 +8,9 @@
namespace OCA\DAV\Tests\Unit\Connector\Sabre\RequestTest;
use OC\AppFramework\Http;
use OC\Connector\Sabre\Exception\FileLocked;
use OCP\AppFramework\Http;
use OCP\Lock\ILockingProvider;
class UploadTest extends RequestTest {
public function testBasicUpload() {
@ -43,6 +45,34 @@ class UploadTest extends RequestTest {
$this->assertEquals(3, $info->getSize());
}
/**
* @expectedException \OC\Connector\Sabre\Exception\FileLocked
*/
public function testUploadOverWriteReadLocked() {
$user = $this->getUniqueID();
$view = $this->setupUser($user, 'pass');
$view->file_put_contents('foo.txt', 'bar');
$view->lockFile('/foo.txt', ILockingProvider::LOCK_SHARED);
$this->request($view, $user, 'pass', 'PUT', '/foo.txt', 'asd');
}
/**
* @expectedException \OC\Connector\Sabre\Exception\FileLocked
*/
public function testUploadOverWriteWriteLocked() {
$user = $this->getUniqueID();
$view = $this->setupUser($user, 'pass');
$view->file_put_contents('foo.txt', 'bar');
$view->lockFile('/foo.txt', ILockingProvider::LOCK_EXCLUSIVE);
$this->request($view, $user, 'pass', 'PUT', '/foo.txt', 'asd');
}
public function testChunkedUpload() {
$user = $this->getUniqueID();
$view = $this->setupUser($user, 'pass');
@ -107,4 +137,54 @@ class UploadTest extends RequestTest {
$this->assertInstanceOf('\OC\Files\FileInfo', $info);
$this->assertEquals(6, $info->getSize());
}
/**
* @expectedException \OC\Connector\Sabre\Exception\FileLocked
*/
public function testChunkedUploadOutOfOrderReadLocked() {
$user = $this->getUniqueID();
$view = $this->setupUser($user, 'pass');
$this->assertFalse($view->file_exists('foo.txt'));
$view->lockFile('/foo.txt', ILockingProvider::LOCK_SHARED);
try {
$response = $this->request($view, $user, 'pass', 'PUT', '/foo.txt-chunking-123-2-1', 'bar', ['OC-Chunked' => '1']);
} catch (FileLocked $e) {
$this->fail('Didn\'t expect locked error for the first chunk on read lock');
return;
}
$this->assertEquals(Http::STATUS_CREATED, $response->getStatus());
$this->assertFalse($view->file_exists('foo.txt'));
// last chunk should trigger the locked error since it tries to assemble
$this->request($view, $user, 'pass', 'PUT', '/foo.txt-chunking-123-2-0', 'asd', ['OC-Chunked' => '1']);
}
/**
* @expectedException \OC\Connector\Sabre\Exception\FileLocked
*/
public function testChunkedUploadOutOfOrderWriteLocked() {
$user = $this->getUniqueID();
$view = $this->setupUser($user, 'pass');
$this->assertFalse($view->file_exists('foo.txt'));
$view->lockFile('/foo.txt', ILockingProvider::LOCK_EXCLUSIVE);
try {
$response = $this->request($view, $user, 'pass', 'PUT', '/foo.txt-chunking-123-2-1', 'bar', ['OC-Chunked' => '1']);
} catch (FileLocked $e) {
$this->fail('Didn\'t expect locked error for the first chunk on write lock'); // maybe forbid this in the future for write locks only?
return;
}
$this->assertEquals(Http::STATUS_CREATED, $response->getStatus());
$this->assertFalse($view->file_exists('foo.txt'));
// last chunk should trigger the locked error since it tries to assemble
$this->request($view, $user, 'pass', 'PUT', '/foo.txt-chunking-123-2-0', 'asd', ['OC-Chunked' => '1']);
}
}