diff options
-rw-r--r-- | apps/files/templates/part.breadcrumb.php | 12 | ||||
-rw-r--r-- | apps/files_encryption/lib/proxy.php | 16 | ||||
-rw-r--r-- | apps/files_encryption/tests/proxy.php | 69 | ||||
-rwxr-xr-x | apps/files_encryption/tests/share.php | 27 | ||||
-rw-r--r-- | apps/files_trashbin/templates/part.breadcrumb.php | 8 | ||||
-rw-r--r-- | core/js/js.js | 8 | ||||
-rw-r--r-- | lib/private/group/group.php | 25 | ||||
-rw-r--r-- | lib/private/tags.php | 2 |
8 files changed, 124 insertions, 43 deletions
diff --git a/apps/files/templates/part.breadcrumb.php b/apps/files/templates/part.breadcrumb.php index 9db27eb9b29..90d07d4336c 100644 --- a/apps/files/templates/part.breadcrumb.php +++ b/apps/files/templates/part.breadcrumb.php @@ -1,10 +1,8 @@ -<?php if(count($_["breadcrumb"])):?> - <div class="crumb" data-dir=''> - <a href="<?php print_unescaped($_['baseURL']); ?>"> - <img src="<?php print_unescaped(OCP\image_path('core', 'places/home.svg'));?>" class="svg" /> - </a> - </div> -<?php endif;?> +<div class="crumb <?php if(!count($_["breadcrumb"])) p('last');?>" data-dir=''> + <a href="<?php print_unescaped($_['baseURL']); ?>"> + <img src="<?php print_unescaped(OCP\image_path('core', 'places/home.svg'));?>" class="svg" /> + </a> +</div> <?php for($i=0; $i<count($_["breadcrumb"]); $i++): $crumb = $_["breadcrumb"][$i]; $dir = \OCP\Util::encodePath($crumb["dir"]); ?> diff --git a/apps/files_encryption/lib/proxy.php b/apps/files_encryption/lib/proxy.php index 5ba3bfa784f..96667493a51 100644 --- a/apps/files_encryption/lib/proxy.php +++ b/apps/files_encryption/lib/proxy.php @@ -114,6 +114,15 @@ class Proxy extends \OC_FileProxy { // get encrypted content $data = $view->file_get_contents($tmpPath); + // update file cache for target file + $tmpFileInfo = $view->getFileInfo($tmpPath); + $fileInfo = $view->getFileInfo($path); + if (is_array($fileInfo) && is_array($tmpFileInfo)) { + $fileInfo['encrypted'] = true; + $fileInfo['unencrypted_size'] = $tmpFileInfo['size']; + $view->putFileInfo($path, $fileInfo); + } + // remove our temp file $view->deleteAll('/' . \OCP\User::getUser() . '/cache/' . $cacheFolder); @@ -182,8 +191,11 @@ class Proxy extends \OC_FileProxy { */ public function preUnlink($path) { - // let the trashbin handle this - if (\OCP\App::isEnabled('files_trashbin')) { + $relPath = Helper::stripUserFilesPath($path); + + // skip this method if the trash bin is enabled or if we delete a file + // outside of /data/user/files + if (\OCP\App::isEnabled('files_trashbin') || $relPath === false) { return true; } diff --git a/apps/files_encryption/tests/proxy.php b/apps/files_encryption/tests/proxy.php index a22f12411f4..419f95e1a38 100644 --- a/apps/files_encryption/tests/proxy.php +++ b/apps/files_encryption/tests/proxy.php @@ -44,8 +44,10 @@ class Test_Encryption_Proxy extends \PHPUnit_Framework_TestCase { /** * @var \OC_FilesystemView */ - public $view; + public $view; // view in /data/user/files + public $rootView; // view on /data/user public $data; + public $filename; public static function setUpBeforeClass() { // reset backend @@ -74,9 +76,12 @@ class Test_Encryption_Proxy extends \PHPUnit_Framework_TestCase { // init filesystem view $this->view = new \OC_FilesystemView('/'. \Test_Encryption_Proxy::TEST_ENCRYPTION_PROXY_USER1 . '/files'); + $this->rootView = new \OC_FilesystemView('/'. \Test_Encryption_Proxy::TEST_ENCRYPTION_PROXY_USER1 ); // init short data $this->data = 'hats'; + $this->filename = 'enc_proxy_tests-' . time() . '.txt'; + } public static function tearDownAfterClass() { @@ -90,21 +95,71 @@ class Test_Encryption_Proxy extends \PHPUnit_Framework_TestCase { */ function testPostFileSize() { - // generate filename - $filename = 'tmp-' . time() . '.txt'; - - $this->view->file_put_contents($filename, $this->data); + $this->view->file_put_contents($this->filename, $this->data); \OC_FileProxy::$enabled = false; - $unencryptedSize = $this->view->filesize($filename); + $unencryptedSize = $this->view->filesize($this->filename); \OC_FileProxy::$enabled = true; - $encryptedSize = $this->view->filesize($filename); + $encryptedSize = $this->view->filesize($this->filename); $this->assertTrue($encryptedSize !== $unencryptedSize); + // cleanup + $this->view->unlink($this->filename); + + } + + function testPreUnlinkWithoutTrash() { + + // remember files_trashbin state + $stateFilesTrashbin = OC_App::isEnabled('files_trashbin'); + + // we want to tests with app files_trashbin enabled + \OC_App::disable('files_trashbin'); + + $this->view->file_put_contents($this->filename, $this->data); + + // create a dummy file that we can delete something outside of data/user/files + $this->rootView->file_put_contents("dummy.txt", $this->data); + + // check if all keys are generated + $this->assertTrue($this->rootView->file_exists( + '/files_encryption/share-keys/' + . $this->filename . '.' . \Test_Encryption_Proxy::TEST_ENCRYPTION_PROXY_USER1 . '.shareKey')); + $this->assertTrue($this->rootView->file_exists( + '/files_encryption/keyfiles/' . $this->filename . '.key')); + + + // delete dummy file outside of data/user/files + $this->rootView->unlink("dummy.txt"); + + // all keys should still exist + $this->assertTrue($this->rootView->file_exists( + '/files_encryption/share-keys/' + . $this->filename . '.' . \Test_Encryption_Proxy::TEST_ENCRYPTION_PROXY_USER1 . '.shareKey')); + $this->assertTrue($this->rootView->file_exists( + '/files_encryption/keyfiles/' . $this->filename . '.key')); + + + // delete the file in data/user/files + $this->view->unlink($this->filename); + + // now also the keys should be gone + $this->assertFalse($this->rootView->file_exists( + '/files_encryption/share-keys/' + . $this->filename . '.' . \Test_Encryption_Proxy::TEST_ENCRYPTION_PROXY_USER1 . '.shareKey')); + $this->assertFalse($this->rootView->file_exists( + '/files_encryption/keyfiles/' . $this->filename . '.key')); + + if ($stateFilesTrashbin) { + OC_App::enable('files_trashbin'); + } + else { + OC_App::disable('files_trashbin'); + } } } diff --git a/apps/files_encryption/tests/share.php b/apps/files_encryption/tests/share.php index 6a29d2428dc..e55427620a6 100755 --- a/apps/files_encryption/tests/share.php +++ b/apps/files_encryption/tests/share.php @@ -649,9 +649,7 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase { * @large */ function testRecoveryFile() { - $this->markTestIncomplete( - 'No idea what\'s wrong here, this works perfectly in real-world. removeRecoveryKeys(\'/\') L709 removes correctly the keys, but for some reasons afterwards also the top-level folder "share-keys" is gone...' - ); + // login as admin \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1); @@ -754,13 +752,13 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase { * @large */ function testRecoveryForUser() { - $this->markTestIncomplete( - 'This test drives Jenkins crazy - "Cannot modify header information - headers already sent" - line 811' - ); + // login as admin \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1); - \OCA\Encryption\Helper::adminEnableRecovery(null, 'test123'); + $result = \OCA\Encryption\Helper::adminEnableRecovery(null, 'test123'); + $this->assertTrue($result); + $recoveryKeyId = OC_Appconfig::getValue('files_encryption', 'recoveryKeyId'); // login as user2 @@ -771,6 +769,9 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase { // enable recovery for admin $this->assertTrue($util->setRecoveryForUser(1)); + // add recovery keys for existing files (e.g. the auto-generated welcome.txt) + $util->addRecoveryKeys(); + // create folder structure $this->view->mkdir('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files' . $this->folder1); $this->view->mkdir( @@ -809,6 +810,10 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase { // change password \OC_User::setPassword(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2, 'test', 'test123'); + $params = array('uid' => \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2, + 'password' => 'test', + 'recoveryPassword' => 'test123'); + \OCA\Encryption\Hooks::setPassphrase($params); // login as user2 \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2, false, 'test'); @@ -823,8 +828,8 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase { $this->assertEquals($this->dataShort, $retrievedCryptedFile2); // cleanup - $this->view->unlink('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files' . $this->folder1); - $this->view->unlink('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files' . $this->filename); + $this->view->unlink('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files/' . $this->folder1); + $this->view->unlink('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files/' . $this->filename); // check if share key for user and recovery exists $this->assertFalse($this->view->file_exists( @@ -889,8 +894,8 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase { } catch (Exception $e) { $this->assertEquals(0, strpos($e->getMessage(), "Following users are not set up for encryption")); } - - + + // login as admin \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1); diff --git a/apps/files_trashbin/templates/part.breadcrumb.php b/apps/files_trashbin/templates/part.breadcrumb.php index 4acc298adbe..fdf78c190d0 100644 --- a/apps/files_trashbin/templates/part.breadcrumb.php +++ b/apps/files_trashbin/templates/part.breadcrumb.php @@ -3,11 +3,11 @@ <img src="<?php print_unescaped(OCP\image_path('core', 'places/home.svg'));?>" class="svg" /> </a> </div> -<?php if(count($_["breadcrumb"])):?> - <div class="crumb svg" - data-dir='/'> +<div class="crumb svg" + data-dir='/'> <a href="<?php p($_['baseURL']); ?>"><?php p($l->t("Deleted Files")); ?></a> - </div> +</div> +<?php if(count($_["breadcrumb"])):?> <?php endif;?> <?php for($i=0; $i<count($_["breadcrumb"]); $i++): $crumb = $_["breadcrumb"][$i]; diff --git a/core/js/js.js b/core/js/js.js index 5442039c294..54b4d51a707 100644 --- a/core/js/js.js +++ b/core/js/js.js @@ -478,11 +478,11 @@ OC.Breadcrumb={ }, _show:function(container, dir, leafname, leaflink){ var self = this; - + this._clear(container); - + // show home + path in subdirectories - if (dir && dir !== '/') { + if (dir) { //add home var link = OC.linkTo('files','index.php'); @@ -509,7 +509,7 @@ OC.Breadcrumb={ } }); } - + //add leafname if (leafname && leaflink) { this._push(container, leafname, leaflink); diff --git a/lib/private/group/group.php b/lib/private/group/group.php index bcd2419b309..8d2aa87a788 100644 --- a/lib/private/group/group.php +++ b/lib/private/group/group.php @@ -18,7 +18,12 @@ class Group { /** * @var \OC\User\User[] $users */ - private $users; + private $users = array(); + + /** + * @var bool $usersLoaded + */ + private $usersLoaded; /** * @var \OC_Group_Backend[] | \OC_Group_Database[] $backend @@ -26,7 +31,7 @@ class Group { private $backends; /** - * @var \OC\Hooks\PublicEmitter $emitter; + * @var \OC\Hooks\PublicEmitter $emitter */ private $emitter; @@ -58,7 +63,7 @@ class Group { * @return \OC\User\User[] */ public function getUsers() { - if ($this->users) { + if ($this->usersLoaded) { return $this->users; } @@ -74,6 +79,7 @@ class Group { } $this->users = $this->getVerifiedUsers($userIds); + $this->usersLoaded = true; return $this->users; } @@ -84,8 +90,12 @@ class Group { * @return bool */ public function inGroup($user) { + if (isset($this->users[$user->getUID()])) { + return true; + } foreach ($this->backends as $backend) { if ($backend->inGroup($user->getUID(), $this->gid)) { + $this->users[$user->getUID()] = $user; return true; } } @@ -185,6 +195,7 @@ class Group { * @return \OC\User\User[] */ public function searchDisplayName($search, $limit = null, $offset = null) { + $users = array(); foreach ($this->backends as $backend) { if ($backend->implementsActions(OC_GROUP_BACKEND_GET_DISPLAYNAME)) { $userIds = array_keys($backend->displayNamesInGroup($this->gid, $search, $limit, $offset)); @@ -229,17 +240,17 @@ class Group { /** * @brief returns all the Users from an array that really exists - * @param $userIds an array containing user IDs - * @return an Array with the userId as Key and \OC\User\User as value + * @param string[] $userIds an array containing user IDs + * @return \OC\User\User[] an Array with the userId as Key and \OC\User\User as value */ private function getVerifiedUsers($userIds) { - if(!is_array($userIds)) { + if (!is_array($userIds)) { return array(); } $users = array(); foreach ($userIds as $userId) { $user = $this->userManager->get($userId); - if(!is_null($user)) { + if (!is_null($user)) { $users[$userId] = $user; } } diff --git a/lib/private/tags.php b/lib/private/tags.php index 9fdb35a7d6e..fe7de1073a0 100644 --- a/lib/private/tags.php +++ b/lib/private/tags.php @@ -480,7 +480,7 @@ class Tags implements \OCP\ITags { return $this->getIdsForTag(self::TAG_FAVORITE); } catch(\Exception $e) { \OCP\Util::writeLog('core', __METHOD__.', exception: ' . $e->getMessage(), - \OCP\Util::ERROR); + \OCP\Util::DEBUG); return array(); } } |