summaryrefslogtreecommitdiffstats
path: root/apps/dav/tests/unit/connector
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2015-10-27 16:58:00 +0100
committerRobin Appelman <robin@icewind.nl>2015-10-27 16:58:00 +0100
commitc30919303990c51b78157d86b95c0f97e004233d (patch)
treeface7331dce78bcb04cd60f978d96d119d9cdfbf /apps/dav/tests/unit/connector
parent4d87276f4be55419189fb23d3c3c13f00c19f006 (diff)
parent021ed8b2bd814b2ca262209738fc039a92391660 (diff)
downloadnextcloud-server-c30919303990c51b78157d86b95c0f97e004233d.tar.gz
nextcloud-server-c30919303990c51b78157d86b95c0f97e004233d.zip
Merge pull request #17104 from owncloud/chunked-upload-locking
locking for chunked dav upload
Diffstat (limited to 'apps/dav/tests/unit/connector')
-rw-r--r--apps/dav/tests/unit/connector/sabre/file.php10
-rw-r--r--apps/dav/tests/unit/connector/sabre/requesttest/uploadtest.php82
2 files changed, 89 insertions, 3 deletions
diff --git a/apps/dav/tests/unit/connector/sabre/file.php b/apps/dav/tests/unit/connector/sabre/file.php
index 9171fc3b786..d874b7f33c2 100644
--- a/apps/dav/tests/unit/connector/sabre/file.php
+++ b/apps/dav/tests/unit/connector/sabre/file.php
@@ -200,7 +200,9 @@ class File extends \Test\TestCase {
$file = new \OCA\DAV\Connector\Sabre\File($view, $info);
// put first chunk
+ $file->acquireLock(ILockingProvider::LOCK_SHARED);
$this->assertNull($file->put('test data one'));
+ $file->releaseLock(ILockingProvider::LOCK_SHARED);
$info = new \OC\Files\FileInfo('/test.txt-chunking-12345-2-1', null, null, [
'permissions' => \OCP\Constants::PERMISSION_ALL
@@ -443,12 +445,12 @@ class File extends \Test\TestCase {
$thrown = false;
try {
// beforeMethod locks
- $view->lockFile('/test.txt', ILockingProvider::LOCK_SHARED);
+ $file->acquireLock(ILockingProvider::LOCK_SHARED);
$file->put($this->getStream('test data'));
// afterMethod unlocks
- $view->unlockFile('/test.txt', ILockingProvider::LOCK_SHARED);
+ $file->releaseLock(ILockingProvider::LOCK_SHARED);
} catch (\Sabre\DAV\Exception\BadRequest $e) {
$thrown = true;
}
@@ -505,7 +507,9 @@ class File extends \Test\TestCase {
'permissions' => \OCP\Constants::PERMISSION_ALL
], null);
$file = new \OCA\DAV\Connector\Sabre\File($view, $info);
+ $file->acquireLock(ILockingProvider::LOCK_SHARED);
$this->assertNull($file->put('test data one'));
+ $file->releaseLock(ILockingProvider::LOCK_SHARED);
$info = new \OC\Files\FileInfo('/' . $this->user . '/files/test.txt-chunking-12345-2-1', null, null, [
'permissions' => \OCP\Constants::PERMISSION_ALL
@@ -515,7 +519,9 @@ class File extends \Test\TestCase {
// action
$thrown = false;
try {
+ $file->acquireLock(ILockingProvider::LOCK_SHARED);
$file->put($this->getStream('test data'));
+ $file->releaseLock(ILockingProvider::LOCK_SHARED);
} catch (\OCA\DAV\Connector\Sabre\Exception\FileLocked $e) {
$thrown = true;
}
diff --git a/apps/dav/tests/unit/connector/sabre/requesttest/uploadtest.php b/apps/dav/tests/unit/connector/sabre/requesttest/uploadtest.php
index 9a067f230a3..a2a8326f4ff 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 \OCA\DAV\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 \OCA\DAV\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 \OCA\DAV\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 (\OCA\DAV\Connector\Sabre\Exception\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 \OCA\DAV\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 (\OCA\DAV\Connector\Sabre\Exception\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']);
+ }
}