From aab226cef76cd4e391182eac58689c83b20e1b29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Tue, 14 Jul 2015 15:12:27 +0200 Subject: [PATCH 01/19] don't move files in cache twice, fixes renaming for objectstores --- lib/private/files/cache/updater.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/private/files/cache/updater.php b/lib/private/files/cache/updater.php index 1e180e7993a4..2de0c8fe0679 100644 --- a/lib/private/files/cache/updater.php +++ b/lib/private/files/cache/updater.php @@ -171,13 +171,15 @@ public function rename($source, $target) { if ($sourceStorage && $targetStorage) { $targetCache = $targetStorage->getCache($sourceInternalPath); - if ($targetCache->inCache($targetInternalPath)) { - $targetCache->remove($targetInternalPath); - } - if ($sourceStorage === $targetStorage) { - $targetCache->move($sourceInternalPath, $targetInternalPath); - } else { - $targetCache->moveFromCache($sourceStorage->getCache(), $sourceInternalPath, $targetInternalPath); + if ($sourceStorage->getCache($sourceInternalPath)->inCache($sourceInternalPath)) { + if ($targetCache->inCache($targetInternalPath)) { + $targetCache->remove($targetInternalPath); + } + if ($sourceStorage === $targetStorage) { + $targetCache->move($sourceInternalPath, $targetInternalPath); + } else { + $targetCache->moveFromCache($sourceStorage->getCache(), $sourceInternalPath, $targetInternalPath); + } } if (pathinfo($sourceInternalPath, PATHINFO_EXTENSION) !== pathinfo($targetInternalPath, PATHINFO_EXTENSION)) { From a87368acb9a2d43bc18fd03cc149e25bd6a79cdc Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 12 Oct 2015 16:50:56 +0200 Subject: [PATCH 02/19] Skip checkupdate test for swift --- tests/lib/files/objectstore/swift.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/lib/files/objectstore/swift.php b/tests/lib/files/objectstore/swift.php index 136d8d18039f..6d59078aa7cd 100644 --- a/tests/lib/files/objectstore/swift.php +++ b/tests/lib/files/objectstore/swift.php @@ -99,6 +99,10 @@ public function testStat() { } } + public function testCheckUpdate() { + $this->markTestSkipped('Detecting external changes is not supported on object storages'); + } + /** * @dataProvider copyAndMoveProvider */ From ef179331bbcb5acce487882d579753573d5bf84a Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 12 Oct 2015 17:11:16 +0200 Subject: [PATCH 03/19] Add tests for double cache rename --- tests/lib/files/cache/updater.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/lib/files/cache/updater.php b/tests/lib/files/cache/updater.php index ea75c8dcd722..e3fa26829b43 100644 --- a/tests/lib/files/cache/updater.php +++ b/tests/lib/files/cache/updater.php @@ -143,6 +143,24 @@ public function testMove() { $this->assertEquals($cached['fileid'], $cachedTarget['fileid']); } + public function testMoveNonExistingOverwrite() { + $this->storage->file_put_contents('bar.txt', 'qwerty'); + $this->updater->update('bar.txt'); + + $cached = $this->cache->get('bar.txt'); + + $this->updater->rename('foo.txt', 'bar.txt'); + + $this->assertFalse($this->cache->inCache('foo.txt')); + $this->assertTrue($this->cache->inCache('bar.txt')); + + $cachedTarget = $this->cache->get('bar.txt'); + $this->assertEquals($cached['etag'], $cachedTarget['etag']); + $this->assertEquals($cached['mtime'], $cachedTarget['mtime']); + $this->assertEquals($cached['size'], $cachedTarget['size']); + $this->assertEquals($cached['fileid'], $cachedTarget['fileid']); + } + public function testNewFileDisabled() { $this->storage->file_put_contents('foo.txt', 'bar'); $this->assertFalse($this->cache->inCache('foo.txt')); From 0cdd46de60a7784d610aae61b9e6d52df611f91f Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 12 Oct 2015 17:21:54 +0200 Subject: [PATCH 04/19] fix sabre connector tests when using a non local home storage --- apps/dav/tests/unit/connector/sabre/file.php | 15 +++++++++------ apps/files_sharing/tests/sharedstorage.php | 7 +++++-- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/apps/dav/tests/unit/connector/sabre/file.php b/apps/dav/tests/unit/connector/sabre/file.php index 9ca8c994a04f..9171fc3b786a 100644 --- a/apps/dav/tests/unit/connector/sabre/file.php +++ b/apps/dav/tests/unit/connector/sabre/file.php @@ -8,6 +8,7 @@ namespace Test\Connector\Sabre; +use OC\Files\Storage\Local; use Test\HookHelper; use OC\Files\Filesystem; use OCP\Lock\ILockingProvider; @@ -798,14 +799,16 @@ private function listPartFiles(\OC\Files\View $userView = null, $path = '') { } $files = []; list($storage, $internalPath) = $userView->resolvePath($path); - $realPath = $storage->getSourcePath($internalPath); - $dh = opendir($realPath); - while (($file = readdir($dh)) !== false) { - if (substr($file, strlen($file) - 5, 5) === '.part') { - $files[] = $file; + if($storage instanceof Local) { + $realPath = $storage->getSourcePath($internalPath); + $dh = opendir($realPath); + while (($file = readdir($dh)) !== false) { + if (substr($file, strlen($file) - 5, 5) === '.part') { + $files[] = $file; + } } + closedir($dh); } - closedir($dh); return $files; } diff --git a/apps/files_sharing/tests/sharedstorage.php b/apps/files_sharing/tests/sharedstorage.php index de510cf1eec3..de36d6dbd424 100644 --- a/apps/files_sharing/tests/sharedstorage.php +++ b/apps/files_sharing/tests/sharedstorage.php @@ -47,8 +47,10 @@ protected function setUp() { } protected function tearDown() { - $this->view->unlink($this->folder); - $this->view->unlink($this->filename); + if ($this->view) { + $this->view->unlink($this->folder); + $this->view->unlink($this->filename); + } \OC\Files\Filesystem::getLoader()->removeStorageWrapper('oc_trashbin'); @@ -85,6 +87,7 @@ function testParentOfMountPointIsGone() { $this->assertFalse($user2View->is_dir($this->folder)); // delete the local folder +// list($storage, $internalPa) $fullPath = \OC_Config::getValue('datadirectory') . '/' . self::TEST_FILES_SHARING_API_USER2 . '/files/localfolder'; rmdir($fullPath); From e7f75484f87df41be5ef8dedce670bd2ccd12dc2 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 12 Oct 2015 17:27:26 +0200 Subject: [PATCH 05/19] Fix shared storage tests for non local home storage --- apps/files_sharing/tests/sharedstorage.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/files_sharing/tests/sharedstorage.php b/apps/files_sharing/tests/sharedstorage.php index de36d6dbd424..3361d2cbd121 100644 --- a/apps/files_sharing/tests/sharedstorage.php +++ b/apps/files_sharing/tests/sharedstorage.php @@ -87,9 +87,9 @@ function testParentOfMountPointIsGone() { $this->assertFalse($user2View->is_dir($this->folder)); // delete the local folder -// list($storage, $internalPa) - $fullPath = \OC_Config::getValue('datadirectory') . '/' . self::TEST_FILES_SHARING_API_USER2 . '/files/localfolder'; - rmdir($fullPath); + /** @var \OC\Files\Storage\Storage $storage */ + list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath('/' . self::TEST_FILES_SHARING_API_USER2 . '/files/localfolder'); + $storage->rmdir($internalPath); //enforce reload of the mount points self::loginHelper(self::TEST_FILES_SHARING_API_USER2); From e46741cf5d222088cc20256462a6d93f85ac27c5 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 12 Oct 2015 17:34:51 +0200 Subject: [PATCH 06/19] detect object homestorage in share code --- lib/private/share/share.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/private/share/share.php b/lib/private/share/share.php index f2ba33bd16b8..b015d7738b58 100644 --- a/lib/private/share/share.php +++ b/lib/private/share/share.php @@ -2636,7 +2636,9 @@ public static function getExpireInterval() { */ private static function isFileReachable($path, $ownerStorageId) { // if outside the home storage, file is always considered reachable - if (!(substr($ownerStorageId, 0, 6) === 'home::')) { + if (!(substr($ownerStorageId, 0, 6) === 'home::' || + substr($ownerStorageId, 0, 13) === 'object::user:' + )) { return true; } From 8efd037eb89bfc7d4793ce856e4a429141ffe222 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 12 Oct 2015 17:43:44 +0200 Subject: [PATCH 07/19] Make shared folder size propagation test work with object home storage --- apps/encryption/tests/lib/MigrationTest.php | 2 +- apps/files_sharing/tests/watcher.php | 10 ++++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/apps/encryption/tests/lib/MigrationTest.php b/apps/encryption/tests/lib/MigrationTest.php index 6146e4e7cfb6..d701aaff0d32 100644 --- a/apps/encryption/tests/lib/MigrationTest.php +++ b/apps/encryption/tests/lib/MigrationTest.php @@ -176,7 +176,7 @@ public function testMigrateToNewFolderStructure() { )->setMethods(['getSystemMountPoints'])->getMock(); $m->expects($this->any())->method('getSystemMountPoints') - ->willReturn([['mountpoint' => 'folder1'], ['mountpoint' => 'folder2']]); + ->will($this->returnValue([['mountpoint' => 'folder1'], ['mountpoint' => 'folder2']])); $m->reorganizeFolderStructure(); // even if it runs twice folder should always move only once diff --git a/apps/files_sharing/tests/watcher.php b/apps/files_sharing/tests/watcher.php index 488792db4ef4..5e96a3fe68e4 100644 --- a/apps/files_sharing/tests/watcher.php +++ b/apps/files_sharing/tests/watcher.php @@ -108,9 +108,8 @@ function testFolderSizePropagationToOwnerStorage() { $this->sharedCache->put('', array('mtime' => 10, 'storage_mtime' => 10, 'size' => '-1', 'mimetype' => 'httpd/unix-directory')); // run the propagation code - $result = $this->sharedStorage->getWatcher()->checkUpdate(''); - - $this->assertTrue($result); + $this->sharedStorage->getWatcher()->checkUpdate(''); + $this->sharedStorage->getCache()->correctFolderSize(''); // the owner's parent dirs must have increase size $newSizes = self::getOwnerDirSizes('files/container/shareddir'); @@ -139,9 +138,8 @@ function testSubFolderSizePropagationToOwnerStorage() { $this->sharedCache->put('subdir', array('mtime' => 10, 'storage_mtime' => 10, 'size' => $dataLen, 'mimetype' => 'text/plain')); // run the propagation code - $result = $this->sharedStorage->getWatcher()->checkUpdate('subdir'); - - $this->assertTrue($result); + $this->sharedStorage->getWatcher()->checkUpdate('subdir'); + $this->sharedStorage->getCache()->correctFolderSize('subdir'); // the owner's parent dirs must have increase size $newSizes = self::getOwnerDirSizes('files/container/shareddir/subdir'); From a87b34a059ee4bf15359abe39328344ef6433910 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 13 Oct 2015 12:19:07 +0200 Subject: [PATCH 08/19] dont assume home storage is local in trash test --- apps/files_trashbin/tests/trashbin.php | 28 ++++++++++++++------------ 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/apps/files_trashbin/tests/trashbin.php b/apps/files_trashbin/tests/trashbin.php index 757239b8cc4b..f8e11b018674 100644 --- a/apps/files_trashbin/tests/trashbin.php +++ b/apps/files_trashbin/tests/trashbin.php @@ -600,22 +600,24 @@ public function testRestoreFileIntoReadOnlySourceFolder() { // delete source folder list($storage, $internalPath) = $this->rootView->resolvePath('/' . self::TEST_TRASHBIN_USER1 . '/files/folder'); - $folderAbsPath = $storage->getSourcePath($internalPath); - // make folder read-only - chmod($folderAbsPath, 0555); + if ($storage instanceof \OC\Files\Storage\Local) { + $folderAbsPath = $storage->getSourcePath($internalPath); + // make folder read-only + chmod($folderAbsPath, 0555); - $this->assertTrue( - OCA\Files_Trashbin\Trashbin::restore( - 'file1.txt.d' . $trashedFile->getMtime(), - $trashedFile->getName(), - $trashedFile->getMtime() - ) - ); + $this->assertTrue( + OCA\Files_Trashbin\Trashbin::restore( + 'file1.txt.d' . $trashedFile->getMtime(), + $trashedFile->getName(), + $trashedFile->getMtime() + ) + ); - $file = $userFolder->get('file1.txt'); - $this->assertEquals('foo', $file->getContent()); + $file = $userFolder->get('file1.txt'); + $this->assertEquals('foo', $file->getContent()); - chmod($folderAbsPath, 0755); + chmod($folderAbsPath, 0755); + } } /** From 0c6c36d0c547187dd2c46bdd45f6a718462a8853 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 13 Oct 2015 12:25:59 +0200 Subject: [PATCH 09/19] fix objectstore files having create permissions --- lib/private/files/objectstore/objectstorestorage.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/private/files/objectstore/objectstorestorage.php b/lib/private/files/objectstore/objectstorestorage.php index 40d52feb893a..e108d7662d4b 100644 --- a/lib/private/files/objectstore/objectstorestorage.php +++ b/lib/private/files/objectstore/objectstorestorage.php @@ -337,7 +337,7 @@ public function touch($path, $mtime = null) { 'size' => 0, 'mtime' => $mtime, 'storage_mtime' => $mtime, - 'permissions' => \OCP\Constants::PERMISSION_ALL, + 'permissions' => \OCP\Constants::PERMISSION_ALL - \OCP\Constants::PERMISSION_CREATE, ); $fileId = $this->getCache()->put($path, $stat); try { @@ -362,7 +362,7 @@ public function writeBack($tmpFile) { if (empty($stat)) { // create new file $stat = array( - 'permissions' => \OCP\Constants::PERMISSION_ALL, + 'permissions' => \OCP\Constants::PERMISSION_ALL - \OCP\Constants::PERMISSION_CREATE, ); } // update stat with new data From 54cea05271b887f1c8062c034741df869bc0f055 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 13 Oct 2015 16:15:00 +0200 Subject: [PATCH 10/19] Fix preserving file ids when restoring a file with object storage --- apps/files_versions/lib/storage.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/apps/files_versions/lib/storage.php b/apps/files_versions/lib/storage.php index fd51a54b108b..ae86b6741b5b 100644 --- a/apps/files_versions/lib/storage.php +++ b/apps/files_versions/lib/storage.php @@ -347,7 +347,20 @@ private static function copyFileContents($view, $path1, $path2) { $view->lockFile($path1, ILockingProvider::LOCK_EXCLUSIVE); $view->lockFile($path2, ILockingProvider::LOCK_EXCLUSIVE); - $result = $storage2->moveFromStorage($storage1, $internalPath1, $internalPath2); + // TODO add a proper way of overwriting a file while maintaining file ids + if ($storage1->instanceOfStorage('\OC\Files\ObjectStore\ObjectStoreStorage') || $storage2->instanceOfStorage('\OC\Files\ObjectStore\ObjectStoreStorage')) { + $source = $storage1->fopen($internalPath1, 'r'); + $target = $storage2->fopen($internalPath2, 'w'); + list(, $result) = \OC_Helper::streamCopy($source, $target); + fclose($source); + fclose($target); + + if ($result !== false) { + $storage1->unlink($internalPath1); + } + } else { + $result = $storage2->moveFromStorage($storage1, $internalPath1, $internalPath2); + } $view->unlockFile($path1, ILockingProvider::LOCK_EXCLUSIVE); $view->unlockFile($path2, ILockingProvider::LOCK_EXCLUSIVE); From 416da0dfe9af2701f0298a9ef2f9c24600deb1ab Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 14 Oct 2015 13:27:05 +0200 Subject: [PATCH 11/19] fix delete orphan shares test with object home storage --- apps/files/tests/command/deleteorphanedfilestest.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/apps/files/tests/command/deleteorphanedfilestest.php b/apps/files/tests/command/deleteorphanedfilestest.php index 76fe9dbdfa03..3a1a541d8f16 100644 --- a/apps/files/tests/command/deleteorphanedfilestest.php +++ b/apps/files/tests/command/deleteorphanedfilestest.php @@ -22,6 +22,7 @@ namespace OCA\Files\Tests\Command; use OCA\Files\Command\DeleteOrphanedFiles; +use OCP\Files\StorageNotAvailableException; class DeleteOrphanedFilesTest extends \Test\TestCase { @@ -110,7 +111,11 @@ public function testClearFiles() { $this->assertCount(0, $this->getFile($fileInfo->getId()), 'Asserts that file gets cleaned up'); - $view->unlink('files/test'); + // since we deleted the storage it might throw a (valid) StorageNotAvailableException + try { + $view->unlink('files/test'); + } catch (StorageNotAvailableException $e) { + } } } From 22c5c19376e4933aa667ca5a684418b29b183979 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 14 Oct 2015 13:51:20 +0200 Subject: [PATCH 12/19] handle versions expire for home storages with unlimited quota --- apps/files_versions/lib/storage.php | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/apps/files_versions/lib/storage.php b/apps/files_versions/lib/storage.php index ae86b6741b5b..dd8af1b8d18d 100644 --- a/apps/files_versions/lib/storage.php +++ b/apps/files_versions/lib/storage.php @@ -676,17 +676,21 @@ public static function expire($filename, $versionsSize = null, $offset = 0) { // calculate available space for version history // subtract size of files and current versions size from quota - if ($softQuota) { - $files_view = new \OC\Files\View('/'.$uid.'/files'); - $rootInfo = $files_view->getFileInfo('/', false); - $free = $quota-$rootInfo['size']; // remaining free space for user - if ( $free > 0 ) { - $availableSpace = ($free * self::DEFAULTMAXSIZE / 100) - ($versionsSize + $offset); // how much space can be used for versions + if ($quota >= 0) { + if ($softQuota) { + $files_view = new \OC\Files\View('/' . $uid . '/files'); + $rootInfo = $files_view->getFileInfo('/', false); + $free = $quota - $rootInfo['size']; // remaining free space for user + if ($free > 0) { + $availableSpace = ($free * self::DEFAULTMAXSIZE / 100) - ($versionsSize + $offset); // how much space can be used for versions + } else { + $availableSpace = $free - $versionsSize - $offset; + } } else { - $availableSpace = $free - $versionsSize - $offset; + $availableSpace = $quota - $offset; } } else { - $availableSpace = $quota - $offset; + $availableSpace = PHP_INT_MAX; } $allVersions = Storage::getVersions($uid, $filename); From d749b9a5ac434418a081149ab056a2db4caf9a55 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 15 Oct 2015 15:39:38 +0200 Subject: [PATCH 13/19] Fix rename shared versions test --- apps/files_versions/tests/versions.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/apps/files_versions/tests/versions.php b/apps/files_versions/tests/versions.php index 00d2b75b7a94..2979de2ac980 100644 --- a/apps/files_versions/tests/versions.php +++ b/apps/files_versions/tests/versions.php @@ -301,11 +301,10 @@ public function testRenameInSharedFolder() { // execute rename hook of versions app \OC\Files\Filesystem::rename('/folder1/test.txt', '/folder1/folder2/test.txt'); - - self::loginHelper(self::TEST_VERSIONS_USER2); - $this->runCommands(); + self::loginHelper(self::TEST_VERSIONS_USER); + $this->assertFalse($this->rootView->file_exists($v1)); $this->assertFalse($this->rootView->file_exists($v2)); From 2e8232e80393cb88ba96dd4f3027fcfd4c4f64e3 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 15 Oct 2015 15:46:26 +0200 Subject: [PATCH 14/19] Fix trashbin handling of unknown/unlimited free space --- apps/files_trashbin/lib/trashbin.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/apps/files_trashbin/lib/trashbin.php b/apps/files_trashbin/lib/trashbin.php index ef015c3566ac..839a47a7bf25 100644 --- a/apps/files_trashbin/lib/trashbin.php +++ b/apps/files_trashbin/lib/trashbin.php @@ -581,8 +581,9 @@ private static function calculateFreeSpace($trashbinSize, $user) { if ($quota === null || $quota === 'none') { $quota = \OC\Files\Filesystem::free_space('/'); $softQuota = false; - if ($quota === \OCP\Files\FileInfo::SPACE_UNKNOWN) { - $quota = 0; + // inf or unknown free space + if ($quota < 0) { + $quota = PHP_INT_MAX; } } else { $quota = \OCP\Util::computerFileSize($quota); From e4364426e237b58b7769d2a289a2e63d246b2e9c Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 15 Oct 2015 15:47:13 +0200 Subject: [PATCH 15/19] Fix listing of trash files in test --- apps/files_trashbin/tests/trashbin.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/apps/files_trashbin/tests/trashbin.php b/apps/files_trashbin/tests/trashbin.php index f8e11b018674..e28b854ca1fb 100644 --- a/apps/files_trashbin/tests/trashbin.php +++ b/apps/files_trashbin/tests/trashbin.php @@ -236,6 +236,8 @@ public function testExpireOldFilesShared() { // user2-1.txt should have been expired $this->verifyArray($filesInTrashUser2AfterDelete, array('user2-2.txt', 'user1-4.txt')); + self::loginHelper(self::TEST_TRASHBIN_USER1); + // user1-1.txt and user1-3.txt should have been expired $filesInTrashUser1AfterDelete = OCA\Files_Trashbin\Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER1); From d636bce8a478f7077589c56eba5d38d701e105b0 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 15 Oct 2015 16:20:54 +0200 Subject: [PATCH 16/19] fix encryption migration test --- apps/encryption/tests/lib/MigrationTest.php | 25 +++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/apps/encryption/tests/lib/MigrationTest.php b/apps/encryption/tests/lib/MigrationTest.php index d701aaff0d32..be37020660ce 100644 --- a/apps/encryption/tests/lib/MigrationTest.php +++ b/apps/encryption/tests/lib/MigrationTest.php @@ -62,6 +62,8 @@ public function setUp() { } protected function createDummyShareKeys($uid) { + $this->loginAsUser($uid); + $this->view->mkdir($uid . '/files_encryption/keys/folder1/folder2/folder3/file3'); $this->view->mkdir($uid . '/files_encryption/keys/folder1/folder2/file2'); $this->view->mkdir($uid . '/files_encryption/keys/folder1/file.1'); @@ -87,6 +89,8 @@ protected function createDummyShareKeys($uid) { } protected function createDummyUserKeys($uid) { + $this->loginAsUser($uid); + $this->view->mkdir($uid . '/files_encryption/'); $this->view->mkdir('/files_encryption/public_keys'); $this->view->file_put_contents($uid . '/files_encryption/' . $uid . '.privateKey', 'privateKey'); @@ -94,6 +98,8 @@ protected function createDummyUserKeys($uid) { } protected function createDummyFileKeys($uid) { + $this->loginAsUser($uid); + $this->view->mkdir($uid . '/files_encryption/keys/folder1/folder2/folder3/file3'); $this->view->mkdir($uid . '/files_encryption/keys/folder1/folder2/file2'); $this->view->mkdir($uid . '/files_encryption/keys/folder1/file.1'); @@ -105,6 +111,8 @@ protected function createDummyFileKeys($uid) { } protected function createDummyFiles($uid) { + $this->loginAsUser($uid); + $this->view->mkdir($uid . '/files/folder1/folder2/folder3/file3'); $this->view->mkdir($uid . '/files/folder1/folder2/file2'); $this->view->mkdir($uid . '/files/folder1/file.1'); @@ -116,6 +124,8 @@ protected function createDummyFiles($uid) { } protected function createDummyFilesInTrash($uid) { + $this->loginAsUser($uid); + $this->view->mkdir($uid . '/files_trashbin/keys/file1.d5457864'); $this->view->mkdir($uid . '/files_trashbin/keys/folder1.d7437648723/file2'); $this->view->file_put_contents($uid . '/files_trashbin/keys/file1.d5457864/' . self::TEST_ENCRYPTION_MIGRATION_USER1 . '.shareKey' , 'data'); @@ -165,6 +175,7 @@ public function testMigrateToNewFolderStructure() { $this->createDummySystemWideKeys(); + /** @var \PHPUnit_Framework_MockObject_MockObject|\OCA\Encryption\Migration $m */ $m = $this->getMockBuilder('OCA\Encryption\Migration') ->setConstructorArgs( [ @@ -182,21 +193,32 @@ public function testMigrateToNewFolderStructure() { // even if it runs twice folder should always move only once $m->reorganizeFolderStructure(); + $this->loginAsUser(self::TEST_ENCRYPTION_MIGRATION_USER1); + $this->assertTrue( $this->view->file_exists( self::TEST_ENCRYPTION_MIGRATION_USER1 . '/files_encryption/' . $this->moduleId . '/' . self::TEST_ENCRYPTION_MIGRATION_USER1 . '.publicKey') ); + + $this->loginAsUser(self::TEST_ENCRYPTION_MIGRATION_USER2); + $this->assertTrue( $this->view->file_exists( self::TEST_ENCRYPTION_MIGRATION_USER2 . '/files_encryption/' . $this->moduleId . '/' . self::TEST_ENCRYPTION_MIGRATION_USER2 . '.publicKey') ); + + $this->loginAsUser(self::TEST_ENCRYPTION_MIGRATION_USER3); + $this->assertTrue( $this->view->file_exists( self::TEST_ENCRYPTION_MIGRATION_USER3 . '/files_encryption/' . $this->moduleId . '/' . self::TEST_ENCRYPTION_MIGRATION_USER3 . '.publicKey') ); + + $this->loginAsUser(self::TEST_ENCRYPTION_MIGRATION_USER1); + $this->assertTrue( $this->view->file_exists( '/files_encryption/' . $this->moduleId . '/systemwide_1.publicKey') @@ -217,6 +239,8 @@ public function testMigrateToNewFolderStructure() { } protected function verifyFilesInTrash($uid) { + $this->loginAsUser($uid); + // share keys $this->assertTrue( $this->view->file_exists($uid . '/files_encryption/keys/files_trashbin/file1.d5457864/' . $this->moduleId . '/' . self::TEST_ENCRYPTION_MIGRATION_USER1 . '.shareKey') @@ -244,6 +268,7 @@ protected function verifyFilesInTrash($uid) { protected function verifyNewKeyPath($uid) { // private key if ($uid !== '') { + $this->loginAsUser($uid); $this->assertTrue($this->view->file_exists($uid . '/files_encryption/' . $this->moduleId . '/'. $uid . '.privateKey')); } // file keys From b04e0deccc8f616dbdba175a31a1c6e5b723dc99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Fri, 16 Oct 2015 13:27:27 +0200 Subject: [PATCH 17/19] Fix termination of the ceph docker --- autotest.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autotest.sh b/autotest.sh index 42807b83e119..73ba74009f2a 100755 --- a/autotest.sh +++ b/autotest.sh @@ -271,7 +271,7 @@ function execute_tests { if [ "$PRIMARY_STORAGE_CONFIG" == "swift" ] ; then echo "Kill the swift docker" - tests/objectstore/stop-swift-ceph.sh + objectstore/stop-swift-ceph.sh fi if [ ! -z "$DOCKER_CONTAINER_ID" ] ; then From fed3994cdbcbd58852f82ced1cf5f0d34eed83d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Fri, 16 Oct 2015 15:57:50 +0200 Subject: [PATCH 18/19] Fix termination of the ceph docker --- autotest.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/autotest.sh b/autotest.sh index 73ba74009f2a..460fa9e38b17 100755 --- a/autotest.sh +++ b/autotest.sh @@ -270,8 +270,9 @@ function execute_tests { fi if [ "$PRIMARY_STORAGE_CONFIG" == "swift" ] ; then + cd .. echo "Kill the swift docker" - objectstore/stop-swift-ceph.sh + tests/objectstore/stop-swift-ceph.sh fi if [ ! -z "$DOCKER_CONTAINER_ID" ] ; then From de55f6afbf1eb4bf858ff61e07c6fa475269bea1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Fri, 16 Oct 2015 21:54:09 +0200 Subject: [PATCH 19/19] Fix error in stop script --- tests/objectstore/stop-swift-ceph.sh | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/tests/objectstore/stop-swift-ceph.sh b/tests/objectstore/stop-swift-ceph.sh index fcf5fdfdcd7a..400db8925e92 100755 --- a/tests/objectstore/stop-swift-ceph.sh +++ b/tests/objectstore/stop-swift-ceph.sh @@ -23,16 +23,18 @@ if [ -z "$thisFolder" ]; then thisFolder="." fi; -# stopping and removing docker containers -for container in `cat $thisFolder/dockerContainerCeph.$EXECUTOR_NUMBER.swift`; do - if [ -n "$DEBUG" ]; then - docker logs $container - fi - echo "Stopping and removing docker container $container" - # kills running container and removes it - docker rm -f $container -done; +if [ -e $thisFolder/dockerContainerCeph.$EXECUTOR_NUMBER.swift ]; then + # stopping and removing docker containers + for container in `cat $thisFolder/dockerContainerCeph.$EXECUTOR_NUMBER.swift`; do + if [ -n "$DEBUG" ]; then + docker logs $container + fi + echo "Stopping and removing docker container $container" + # kills running container and removes it + docker rm -f $container + done; +fi; # cleanup -rm $thisFolder/swift.config.php -rm $thisFolder/dockerContainerCeph.$EXECUTOR_NUMBER.swift \ No newline at end of file +rm -rf $thisFolder/swift.config.php +rm -rf $thisFolder/dockerContainerCeph.$EXECUTOR_NUMBER.swift