diff options
author | Robin Appelman <icewind@owncloud.com> | 2015-09-14 15:33:34 +0200 |
---|---|---|
committer | Robin Appelman <icewind@owncloud.com> | 2015-10-20 14:14:56 +0200 |
commit | 21d02673becc2bc9f7312eae18c3150778a94364 (patch) | |
tree | 5c5077358e4dfce92c6910784e4be436bac220c4 /apps/dav | |
parent | 23eaf27a5b630cbbf0b9a664ef1945a3a5b30c31 (diff) | |
download | nextcloud-server-21d02673becc2bc9f7312eae18c3150778a94364.tar.gz nextcloud-server-21d02673becc2bc9f7312eae18c3150778a94364.zip |
Add tests for uploading to locked files
Diffstat (limited to 'apps/dav')
-rw-r--r-- | apps/dav/tests/unit/connector/sabre/requesttest/uploadtest.php | 82 |
1 files changed, 81 insertions, 1 deletions
diff --git a/apps/dav/tests/unit/connector/sabre/requesttest/uploadtest.php b/apps/dav/tests/unit/connector/sabre/requesttest/uploadtest.php index 9a067f230a3..557e247b3b0 100644 --- a/apps/dav/tests/unit/connector/sabre/requesttest/uploadtest.php +++ b/apps/dav/tests/unit/connector/sabre/requesttest/uploadtest.php @@ -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']); + } } |