summaryrefslogtreecommitdiffstats
path: root/tests/lib
diff options
context:
space:
mode:
authorRobin Appelman <icewind@owncloud.com>2014-11-10 16:00:08 +0100
committerRobin Appelman <icewind@owncloud.com>2014-11-27 15:25:53 +0100
commitabb6e89c5d83102c2838bd6a48b5bf6e73e9660d (patch)
treeb2fab37864f6f904c4560bf111dcbf6d72e69401 /tests/lib
parenta2172786a8cbdcac58906df03713f21a98694119 (diff)
downloadnextcloud-server-abb6e89c5d83102c2838bd6a48b5bf6e73e9660d.tar.gz
nextcloud-server-abb6e89c5d83102c2838bd6a48b5bf6e73e9660d.zip
Add storage and cache wrappers to jail a storage to a subfolder
Diffstat (limited to 'tests/lib')
-rw-r--r--tests/lib/files/cache/cache.php8
-rw-r--r--tests/lib/files/cache/wrapper/cachejail.php67
-rw-r--r--tests/lib/files/storage/wrapper/jail.php55
3 files changed, 126 insertions, 4 deletions
diff --git a/tests/lib/files/cache/cache.php b/tests/lib/files/cache/cache.php
index 02c45a16571..7360e9885c1 100644
--- a/tests/lib/files/cache/cache.php
+++ b/tests/lib/files/cache/cache.php
@@ -20,20 +20,20 @@ class Cache extends \Test\TestCase {
/**
* @var \OC\Files\Storage\Temporary $storage ;
*/
- private $storage;
+ protected $storage;
/**
* @var \OC\Files\Storage\Temporary $storage2 ;
*/
- private $storage2;
+ protected $storage2;
/**
* @var \OC\Files\Cache\Cache $cache
*/
- private $cache;
+ protected $cache;
/**
* @var \OC\Files\Cache\Cache $cache2
*/
- private $cache2;
+ protected $cache2;
public function testSimple() {
$file1 = 'foo';
diff --git a/tests/lib/files/cache/wrapper/cachejail.php b/tests/lib/files/cache/wrapper/cachejail.php
new file mode 100644
index 00000000000..13f3dc8858e
--- /dev/null
+++ b/tests/lib/files/cache/wrapper/cachejail.php
@@ -0,0 +1,67 @@
+<?php
+/**
+ * Copyright (c) 2014 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace Test\Files\Cache\Wrapper;
+
+use Test\Files\Cache\Cache;
+
+class CacheJail extends Cache {
+ /**
+ * @var \OC\Files\Cache\Cache $sourceCache
+ */
+ protected $sourceCache;
+
+ public function setUp() {
+ parent::setUp();
+ $this->storage->mkdir('foo');
+ $this->sourceCache = $this->cache;
+ $this->cache = new \OC\Files\Cache\Wrapper\CacheJail($this->sourceCache, 'foo');
+ }
+
+ function testSearchOutsideJail() {
+ $file1 = 'foo/foobar';
+ $file2 = 'folder/foobar';
+ $data1 = array('size' => 100, 'mtime' => 50, 'mimetype' => 'foo/folder');
+
+ $this->sourceCache->put($file1, $data1);
+ $this->sourceCache->put($file2, $data1);
+
+ $this->assertCount(2, $this->sourceCache->search('%foobar'));
+
+ $result = $this->cache->search('%foobar%');
+ $this->assertCount(1, $result);
+ $this->assertEquals('foobar', $result[0]['path']);
+ }
+
+ function testClearKeepEntriesOutsideJail() {
+ $file1 = 'foo/foobar';
+ $file2 = 'foo/foobar/asd';
+ $file3 = 'folder/foobar';
+ $data1 = array('size' => 100, 'mtime' => 50, 'mimetype' => 'httpd/unix-directory');
+
+ $this->sourceCache->put('foo', $data1);
+ $this->sourceCache->put($file1, $data1);
+ $this->sourceCache->put($file2, $data1);
+ $this->sourceCache->put($file3, $data1);
+
+ $this->cache->clear();
+
+ $this->assertFalse($this->cache->inCache('foobar'));
+ $this->assertTrue($this->sourceCache->inCache('folder/foobar'));
+ }
+
+ function testGetById() {
+ //not supported
+ $this->assertTrue(true);
+ }
+
+ function testGetIncomplete() {
+ //not supported
+ $this->assertTrue(true);
+ }
+}
diff --git a/tests/lib/files/storage/wrapper/jail.php b/tests/lib/files/storage/wrapper/jail.php
new file mode 100644
index 00000000000..270ce750ecf
--- /dev/null
+++ b/tests/lib/files/storage/wrapper/jail.php
@@ -0,0 +1,55 @@
+<?php
+/**
+ * Copyright (c) 2014 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace Test\Files\Storage\Wrapper;
+
+class Jail extends \Test\Files\Storage\Storage {
+ /**
+ * @var string tmpDir
+ */
+ private $tmpDir;
+
+ /**
+ * @var \OC\Files\Storage\Temporary
+ */
+ private $sourceStorage;
+
+ public function setUp() {
+ parent::setUp();
+ $this->sourceStorage = new \OC\Files\Storage\Temporary(array());
+ $this->sourceStorage->mkdir('foo');
+ $this->instance = new \OC\Files\Storage\Wrapper\Jail(array(
+ 'storage' => $this->sourceStorage,
+ 'root' => 'foo'
+ ));
+ }
+
+ public function tearDown() {
+ // test that nothing outside our jail is touched
+ $contents = array();
+ $dh = $this->sourceStorage->opendir('');
+ while ($file = readdir($dh)) {
+ if ($file !== '.' and $file !== '..') {
+ $contents[] = $file;
+ }
+ }
+ $this->assertEquals(array('foo'), $contents);
+ $this->sourceStorage->cleanUp();
+ parent::tearDown();
+ }
+
+ public function testMkDirRooted() {
+ $this->instance->mkdir('bar');
+ $this->assertTrue($this->sourceStorage->is_dir('foo/bar'));
+ }
+
+ public function testFilePutContentsRooted() {
+ $this->instance->file_put_contents('bar', 'asd');
+ $this->assertEquals('asd', $this->sourceStorage->file_get_contents('foo/bar'));
+ }
+}