Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2015-04-21 17:30:56 +0300
committerThomas Müller <thomas.mueller@tmit.eu>2015-04-21 17:30:56 +0300
commit438cb27471895a93f15828e427232ae68050f119 (patch)
treef11fa1f144504d32b2dad30398f9531ce3f4c1a3
parent1ee2ee84327a23ebf089f5b719f871168d6d007d (diff)
parent9695e33e340158ead3d54811c8b99deabd49d50b (diff)
Merge pull request #15721 from oparoz/fix-readonly-cache
Fix read-only cache
-rw-r--r--apps/files_sharing/lib/readonlycache.php4
-rw-r--r--apps/files_sharing/tests/readonlycache.php93
2 files changed, 96 insertions, 1 deletions
diff --git a/apps/files_sharing/lib/readonlycache.php b/apps/files_sharing/lib/readonlycache.php
index ebef1634757..c7640f896f4 100644
--- a/apps/files_sharing/lib/readonlycache.php
+++ b/apps/files_sharing/lib/readonlycache.php
@@ -28,7 +28,9 @@ use OC\Files\Cache\Cache;
class ReadOnlyCache extends Cache {
public function get($path) {
$data = parent::get($path);
- $data['permissions'] &= (\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_SHARE);
+ if ($data !== false) {
+ $data['permissions'] &= (\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_SHARE);
+ }
return $data;
}
diff --git a/apps/files_sharing/tests/readonlycache.php b/apps/files_sharing/tests/readonlycache.php
new file mode 100644
index 00000000000..5da200fa78f
--- /dev/null
+++ b/apps/files_sharing/tests/readonlycache.php
@@ -0,0 +1,93 @@
+<?php
+/**
+ * @author Olivier Paroz <owncloud@interfasys.ch>
+ *
+ * @copyright Copyright (c) 2015, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+namespace OCA\Files_Sharing\Tests;
+
+class ReadOnlyCache extends TestCase {
+
+ /** @var \OC\Files\Storage\Storage */
+ protected $storage;
+
+ /** @var \OC\Files\Storage\StorageFactory */
+ protected $loader;
+
+ /** @var \OC\Files\Mount\MountPoint */
+ protected $readOnlyMount;
+
+ /** @var \OCA\Files_Sharing\ReadOnlyWrapper */
+ protected $readOnlyStorage;
+
+ /** @var \OC\Files\Cache\Cache */
+ protected $readOnlyCache;
+
+ protected function setUp() {
+ parent::setUp();
+
+ $this->view->mkdir('readonly');
+ $this->view->file_put_contents('readonly/foo.txt', 'foo');
+ $this->view->file_put_contents('readonly/bar.txt', 'bar');
+
+ list($this->storage) = $this->view->resolvePath('');
+ $this->loader = new \OC\Files\Storage\StorageFactory();
+ $this->readOnlyMount = new \OC\Files\Mount\MountPoint($this->storage,
+ '/readonly', [[]], $this->loader);
+ $this->readOnlyStorage = $this->loader->getInstance($this->readOnlyMount,
+ '\OCA\Files_Sharing\ReadOnlyWrapper', ['storage' => $this->storage]);
+
+ $this->readOnlyCache = $this->readOnlyStorage->getCache();
+ }
+
+ public function testSetup() {
+ $this->assertTrue($this->view->file_exists('/readonly/foo.txt'));
+
+ $perms = $this->readOnlyStorage->getPermissions('files/readonly/foo.txt');
+ $this->assertEquals(17, $perms);
+
+ $this->assertFalse($this->readOnlyStorage->unlink('files/readonly/foo.txt'));
+ $this->assertTrue($this->readOnlyStorage->file_exists('files/readonly/foo.txt'));
+
+ $this->assertInstanceOf('\OCA\Files_Sharing\ReadOnlyCache', $this->readOnlyCache);
+ }
+
+ public function testGetWhenFileExists() {
+ $result = $this->readOnlyCache->get('files/readonly/foo.txt');
+ $this->assertNotEmpty($result);
+ }
+
+ public function testGetWhenFileDoesNotExist() {
+ $result = $this->readOnlyCache->get('files/readonly/proof does not exist.md');
+ $this->assertFalse($result);
+ }
+
+ public function testGetFolderContentsWhenFolderExists() {
+ $results = $this->readOnlyCache->getFolderContents('files/readonly');
+ $this->assertNotEmpty($results);
+
+ foreach ($results as $result) {
+ $this->assertNotEmpty($result);
+ }
+ }
+
+ public function testGetFolderContentsWhenFolderDoesNotExist() {
+ $results = $this->readOnlyCache->getFolderContents('files/iamaghost');
+ $this->assertEmpty($results);
+ }
+
+}