From 8166aaf82c1e96090e32eb2d8479bd150c12d166 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Wed, 23 Oct 2013 15:41:15 +0200 Subject: Some tests for OC_L10N::findLanguage() --- tests/lib/l10n.php | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'tests') diff --git a/tests/lib/l10n.php b/tests/lib/l10n.php index 12eac818f84..5ddf2290c35 100644 --- a/tests/lib/l10n.php +++ b/tests/lib/l10n.php @@ -64,4 +64,45 @@ class Test_L10n extends PHPUnit_Framework_TestCase { $l = new OC_L10N('test'); $this->assertSame('February 13, 2009 23:31', $l->l('datetime', 1234567890)); } + + /** + * @dataProvider findLanguageData + */ + public function testFindLanguage($default, $preference, $expected) { + OC_User::setUserId(null); + if (is_null($default)) { + OC_Config::deleteKey('default_language'); + } else { + OC_Config::setValue('default_language', $default); + } + $_SERVER['HTTP_ACCEPT_LANGUAGE'] = $preference; + + $reflection = new \ReflectionClass('OC_L10N'); + $prop = $reflection->getProperty('language'); + $prop->setAccessible(1); + $prop->setValue(''); + $prop->setAccessible(0); + + $this->assertSame($expected, OC_L10N::findLanguage()); + } + + public function findLanguageData() { + return array( + // Exact match + array(null, 'de-DE,en;q=0.5', 'de_DE'), + array(null, 'de-DE,en-US;q=0.8,en;q=0.6', 'de_DE'), + + // Best match + array(null, 'de-US,en;q=0.5', 'de'), + array(null, 'de-US,en-US;q=0.8,en;q=0.6', 'de'), + + // The default_language config setting overrides browser preferences. + array('es_AR', 'de-DE,en;q=0.5', 'es_AR'), + array('es_AR', 'de-DE,en-US;q=0.8,en;q=0.6', 'es_AR'), + + // Worst case default to english + array(null, '', 'en'), + array(null, null, 'en'), + ); + } } -- cgit v1.2.3 From b3626f34cd0df127d742f7a8cb2a4ddf929ff886 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 29 Oct 2013 14:18:57 +0100 Subject: Update the parent folders storage_mtime on write and delete to prevent rescans --- lib/private/files/cache/updater.php | 22 +++++++++++++++++++++- tests/lib/files/cache/updater.php | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/lib/private/files/cache/updater.php b/lib/private/files/cache/updater.php index 1f30173a8f8..b491b60b0d0 100644 --- a/lib/private/files/cache/updater.php +++ b/lib/private/files/cache/updater.php @@ -7,6 +7,7 @@ */ namespace OC\Files\Cache; + use OCP\Util; /** @@ -42,6 +43,7 @@ class Updater { $scanner->scan($internalPath, Scanner::SCAN_SHALLOW); $cache->correctFolderSize($internalPath); self::correctFolder($path, $storage->filemtime($internalPath)); + self::correctParentStorageMtime($storage, $internalPath); } } @@ -61,6 +63,7 @@ class Updater { $cache->remove($internalPath); $cache->correctFolderSize($internalPath); self::correctFolder($path, time()); + self::correctParentStorageMtime($storage, $internalPath); } } @@ -87,6 +90,8 @@ class Updater { $cache->correctFolderSize($internalTo); self::correctFolder($from, time()); self::correctFolder($to, time()); + self::correctParentStorageMtime($storageFrom, $internalFrom); + self::correctParentStorageMtime($storageTo, $internalTo); } else { self::deleteUpdate($from); self::writeUpdate($to); @@ -118,12 +123,27 @@ class Updater { $cache->update($id, array('mtime' => $time, 'etag' => $storage->getETag($internalPath))); self::correctFolder($parent, $time); } else { - Util::writeLog('core', 'Path not in cache: '.$internalPath, Util::ERROR); + Util::writeLog('core', 'Path not in cache: ' . $internalPath, Util::ERROR); } } } } + /** + * update the storage_mtime of the parent + * + * @param \OC\Files\Storage\Storage $storage + * @param string $internalPath + */ + static private function correctParentStorageMtime($storage, $internalPath) { + $cache = $storage->getCache(); + $parentId = $cache->getParentId($internalPath); + $parent = dirname($internalPath); + if ($parentId != -1) { + $cache->update($parentId, array('storage_mtime' => $storage->filemtime($parent))); + } + } + /** * @param array $params */ diff --git a/tests/lib/files/cache/updater.php b/tests/lib/files/cache/updater.php index 5d7997b0544..a891f2560c4 100644 --- a/tests/lib/files/cache/updater.php +++ b/tests/lib/files/cache/updater.php @@ -9,6 +9,7 @@ namespace Test\Files\Cache; use \OC\Files\Filesystem as Filesystem; +use OC\Files\Storage\Temporary; class Updater extends \PHPUnit_Framework_TestCase { /** @@ -265,4 +266,35 @@ class Updater extends \PHPUnit_Framework_TestCase { $this->assertEquals($time, $cachedData['mtime']); } + public function testUpdatePermissionsOnRescanOnlyForUpdatedFile() { + $permissionsCache = $this->storage->getPermissionsCache(); + $scanner = $this->storage->getScanner(); + $scanner->scan(''); + $cache = $this->storage->getCache(); + $loggedInUser = \OC_User::getUser(); + \OC_User::setUserId(self::$user); + FileSystem::getDirectoryContent('/'); + $past = time() - 600; + $cache->put('', array('storage_mtime' => $past)); + + $this->assertNotEquals(-1, $permissionsCache->get($cache->getId('foo.txt'), self::$user)); + $this->assertNotEquals(-1, $permissionsCache->get($cache->getId('foo.png'), self::$user)); + + $permissionsCache->set($cache->getId('foo.png'), self::$user, 15); + FileSystem::file_put_contents('/foo.txt', 'asd'); + + $this->assertEquals(-1, $permissionsCache->get($cache->getId('foo.txt'), self::$user)); + $this->assertEquals(15, $permissionsCache->get($cache->getId('foo.png'), self::$user)); + + FileSystem::getDirectoryContent('/'); + + $this->assertEquals(15, $permissionsCache->get($cache->getId('foo.png'), self::$user)); + + FileSystem::file_put_contents('/qwerty.txt', 'asd'); + FileSystem::getDirectoryContent('/'); + + $this->assertEquals(15, $permissionsCache->get($cache->getId('foo.png'), self::$user)); + + \OC_User::setUserId($loggedInUser); + } } -- cgit v1.2.3 From 654b0daf0145b216d81347325b17cf522a49ec81 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 29 Oct 2013 14:22:13 +0100 Subject: update touch tests for updated behaviour --- tests/lib/files/cache/updater.php | 2 -- 1 file changed, 2 deletions(-) (limited to 'tests') diff --git a/tests/lib/files/cache/updater.php b/tests/lib/files/cache/updater.php index a891f2560c4..d8414dadbec 100644 --- a/tests/lib/files/cache/updater.php +++ b/tests/lib/files/cache/updater.php @@ -234,7 +234,6 @@ class Updater extends \PHPUnit_Framework_TestCase { $cachedData = $this->cache->get('folder'); $this->assertNotEquals($folderCachedData['etag'], $cachedData['etag']); - $this->assertEquals($time, $cachedData['mtime']); $cachedData = $this->cache->get(''); $this->assertNotEquals($rootCachedData['etag'], $cachedData['etag']); @@ -259,7 +258,6 @@ class Updater extends \PHPUnit_Framework_TestCase { $cachedData = $cache2->get(''); $this->assertNotEquals($substorageCachedData['etag'], $cachedData['etag']); - $this->assertEquals($time, $cachedData['mtime']); $cachedData = $this->cache->get('folder'); $this->assertNotEquals($folderCachedData['etag'], $cachedData['etag']); -- cgit v1.2.3 From fcfac51aa18bdd81be004e63fb98683e2cc780a0 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Tue, 29 Oct 2013 15:08:12 +0100 Subject: backport of https://github.com/owncloud/core/pull/5513 --- apps/files_encryption/hooks/hooks.php | 62 +++++++++++++++++++++++++++-------- apps/files_sharing/lib/updater.php | 7 ---- lib/private/files/cache/updater.php | 48 ++++++++++++++++++++------- tests/lib/files/cache/updater.php | 18 ++++++++++ 4 files changed, 102 insertions(+), 33 deletions(-) (limited to 'tests') diff --git a/apps/files_encryption/hooks/hooks.php b/apps/files_encryption/hooks/hooks.php index 6e2d360917b..35574b8e5b9 100644 --- a/apps/files_encryption/hooks/hooks.php +++ b/apps/files_encryption/hooks/hooks.php @@ -35,6 +35,12 @@ class Hooks { * @note This method should never be called for users using client side encryption */ public static function login($params) { + + if (\OCP\App::isEnabled('files_encryption') === false) { + return true; + } + + $l = new \OC_L10N('files_encryption'); $view = new \OC_FilesystemView('/'); @@ -117,11 +123,12 @@ class Hooks { * @note This method should never be called for users using client side encryption */ public static function postCreateUser($params) { - $view = new \OC_FilesystemView('/'); - - $util = new Util($view, $params['uid']); - Helper::setupUser($util, $params['password']); + if (\OCP\App::isEnabled('files_encryption')) { + $view = new \OC_FilesystemView('/'); + $util = new Util($view, $params['uid']); + Helper::setupUser($util, $params['password']); + } } /** @@ -129,26 +136,31 @@ class Hooks { * @note This method should never be called for users using client side encryption */ public static function postDeleteUser($params) { - $view = new \OC_FilesystemView('/'); - // cleanup public key - $publicKey = '/public-keys/' . $params['uid'] . '.public.key'; + if (\OCP\App::isEnabled('files_encryption')) { + $view = new \OC_FilesystemView('/'); - // Disable encryption proxy to prevent recursive calls - $proxyStatus = \OC_FileProxy::$enabled; - \OC_FileProxy::$enabled = false; + // cleanup public key + $publicKey = '/public-keys/' . $params['uid'] . '.public.key'; - $view->unlink($publicKey); + // Disable encryption proxy to prevent recursive calls + $proxyStatus = \OC_FileProxy::$enabled; + \OC_FileProxy::$enabled = false; - \OC_FileProxy::$enabled = $proxyStatus; + $view->unlink($publicKey); + + \OC_FileProxy::$enabled = $proxyStatus; + } } /** * @brief If the password can't be changed within ownCloud, than update the key password in advance. */ public static function preSetPassphrase($params) { - if ( ! \OC_User::canUserChangePassword($params['uid']) ) { - self::setPassphrase($params); + if (\OCP\App::isEnabled('files_encryption')) { + if ( ! \OC_User::canUserChangePassword($params['uid']) ) { + self::setPassphrase($params); + } } } @@ -157,6 +169,11 @@ class Hooks { * @param array $params keys: uid, password */ public static function setPassphrase($params) { + + if (\OCP\App::isEnabled('files_encryption') === false) { + return true; + } + // Only attempt to change passphrase if server-side encryption // is in use (client-side encryption does not have access to // the necessary keys) @@ -227,6 +244,10 @@ class Hooks { */ public static function preShared($params) { + if (\OCP\App::isEnabled('files_encryption') === false) { + return true; + } + $l = new \OC_L10N('files_encryption'); $users = array(); $view = new \OC\Files\View('/public-keys/'); @@ -278,6 +299,10 @@ class Hooks { // [run] => whether emitting script should continue to run // TODO: Should other kinds of item be encrypted too? + if (\OCP\App::isEnabled('files_encryption') === false) { + return true; + } + if ($params['itemType'] === 'file' || $params['itemType'] === 'folder') { $view = new \OC_FilesystemView('/'); @@ -372,6 +397,10 @@ class Hooks { // [shareWith] => test1 // [itemParent] => + if (\OCP\App::isEnabled('files_encryption') === false) { + return true; + } + if ($params['itemType'] === 'file' || $params['itemType'] === 'folder') { $view = new \OC_FilesystemView('/'); @@ -453,6 +482,11 @@ class Hooks { * of the stored versions along the actual file */ public static function postRename($params) { + + if (\OCP\App::isEnabled('files_encryption') === false) { + return true; + } + // Disable encryption proxy to prevent recursive calls $proxyStatus = \OC_FileProxy::$enabled; \OC_FileProxy::$enabled = false; diff --git a/apps/files_sharing/lib/updater.php b/apps/files_sharing/lib/updater.php index 3381f75f16d..171999ea652 100644 --- a/apps/files_sharing/lib/updater.php +++ b/apps/files_sharing/lib/updater.php @@ -49,13 +49,6 @@ class Shared_Updater { } $users = $reshareUsers; } - // Correct folders of shared file owner - $target = substr($target, 8); - if ($uidOwner !== $uid && $source = \OC_Share_Backend_File::getSource($target)) { - \OC\Files\Filesystem::initMountPoints($uidOwner); - $source = '/'.$uidOwner.'/'.$source['path']; - \OC\Files\Cache\Updater::correctFolder($source, $info['mtime']); - } } } diff --git a/lib/private/files/cache/updater.php b/lib/private/files/cache/updater.php index 1f30173a8f8..6d016f9deac 100644 --- a/lib/private/files/cache/updater.php +++ b/lib/private/files/cache/updater.php @@ -94,6 +94,24 @@ class Updater { } } + /** + * @brief get file owner and path + * @param string $filename + * @return array with the oweners uid and the owners path + */ + public static function getUidAndFilename($filename) { + + $uid = \OC\Files\Filesystem::getOwner($filename); + \OC\Files\Filesystem::initMountPoints($uid); + + if ($uid != \OCP\User::getUser()) { + $info = \OC\Files\Filesystem::getFileInfo($filename); + $ownerView = new \OC\Files\View('/' . $uid . '/files'); + $filename = $ownerView->getPath($info['fileid']); + } + return array($uid, '/files/' . $filename); + } + /** * Update the mtime and ETag of all parent folders * @@ -102,23 +120,29 @@ class Updater { */ static public function correctFolder($path, $time) { if ($path !== '' && $path !== '/') { - $parent = dirname($path); - if ($parent === '.' || $parent === '\\') { - $parent = ''; - } + + list($owner, $realPath) = self::getUidAndFilename(dirname($path)); + /** * @var \OC\Files\Storage\Storage $storage * @var string $internalPath */ - list($storage, $internalPath) = self::resolvePath($parent); - if ($storage) { - $cache = $storage->getCache(); - $id = $cache->getId($internalPath); - if ($id !== -1) { - $cache->update($id, array('mtime' => $time, 'etag' => $storage->getETag($internalPath))); - self::correctFolder($parent, $time); + $view = new \OC\Files\View('/' . $owner); + + list($storage, $internalPath) = $view->resolvePath($realPath); + $cache = $storage->getCache(); + $id = $cache->getId($internalPath); + + while ($id !== -1) { + $cache->update($id, array('mtime' => $time, 'etag' => $storage->getETag($internalPath))); + $realPath = dirname($realPath); + // check storage for parent in case we change the storage in this step + list($storage, $internalPath) = $view->resolvePath($realPath); + if ($internalPath) { + $cache = $storage->getCache(); + $id = $cache->getId($internalPath); } else { - Util::writeLog('core', 'Path not in cache: '.$internalPath, Util::ERROR); + $id = -1; } } } diff --git a/tests/lib/files/cache/updater.php b/tests/lib/files/cache/updater.php index 5d7997b0544..9c1c6f8d18f 100644 --- a/tests/lib/files/cache/updater.php +++ b/tests/lib/files/cache/updater.php @@ -21,6 +21,8 @@ class Updater extends \PHPUnit_Framework_TestCase { */ private $scanner; + private $stateFilesEncryption; + /** * @var \OC\Files\Cache\Cache $cache */ @@ -29,6 +31,12 @@ class Updater extends \PHPUnit_Framework_TestCase { private static $user; public function setUp() { + + // remember files_encryption state + $this->stateFilesEncryption = \OC_App::isEnabled('files_encryption'); + // we want to tests with the encryption app disabled + \OC_App::disable('files_encryption'); + $this->storage = new \OC\Files\Storage\Temporary(array()); $textData = "dummy file data\n"; $imgData = file_get_contents(\OC::$SERVERROOT . '/core/img/logo.png'); @@ -46,6 +54,10 @@ class Updater extends \PHPUnit_Framework_TestCase { if (!self::$user) { self::$user = uniqid(); } + + \OC_User::createUser(self::$user, 'password'); + \OC_User::setUserId(self::$user); + \OC\Files\Filesystem::init(self::$user, '/' . self::$user . '/files'); Filesystem::clearMounts(); @@ -63,7 +75,13 @@ class Updater extends \PHPUnit_Framework_TestCase { if ($this->cache) { $this->cache->clear(); } + $result = \OC_User::deleteUser(self::$user); + $this->assertTrue($result); Filesystem::tearDown(); + // reset app files_encryption + if ($this->stateFilesEncryption) { + \OC_App::enable('files_encryption'); + } } public function testWrite() { -- cgit v1.2.3 From b65b7965ae18cbad09b8feda512f85354dd77bf0 Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Wed, 30 Oct 2013 15:39:55 +0100 Subject: fix failing preview test on master --- tests/lib/preview.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'tests') diff --git a/tests/lib/preview.php b/tests/lib/preview.php index d0cdd2c44fb..353b66fd6d6 100644 --- a/tests/lib/preview.php +++ b/tests/lib/preview.php @@ -134,13 +134,11 @@ class Preview extends \PHPUnit_Framework_TestCase { } private function initFS() { - if(\OC\Files\Filesystem::getView()){ - $user = \OC_User::getUser(); - }else{ - $user=uniqid(); - \OC_User::setUserId($user); - \OC\Files\Filesystem::init($user, '/'.$user.'/files'); - } + // create a new user with his own filesystem view + // this gets called by each test in this test class + $user=uniqid(); + \OC_User::setUserId($user); + \OC\Files\Filesystem::init($user, '/'.$user.'/files'); \OC\Files\Filesystem::mount('OC\Files\Storage\Temporary', array(), '/'); -- cgit v1.2.3