aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib')
-rw-r--r--tests/lib/avatar.php13
-rw-r--r--tests/lib/cache/file.php7
-rw-r--r--tests/lib/cache/usercache.php7
-rw-r--r--tests/lib/encryption/keys/storage.php153
-rw-r--r--tests/lib/encryption/managertest.php58
-rw-r--r--tests/lib/encryption/utiltest.php18
-rw-r--r--tests/lib/files/cache/cache.php9
-rw-r--r--tests/lib/files/cache/updaterlegacy.php11
-rw-r--r--tests/lib/files/storage/storage.php2
-rw-r--r--tests/lib/files/storage/wrapper/encryption.php125
-rw-r--r--tests/lib/files/storage/wrapper/jail.php4
-rw-r--r--tests/lib/files/storage/wrapper/quota.php8
-rw-r--r--tests/lib/files/stream/encryption.php104
-rw-r--r--tests/lib/streamwrappers.php14
-rw-r--r--tests/lib/testcase.php11
15 files changed, 452 insertions, 92 deletions
diff --git a/tests/lib/avatar.php b/tests/lib/avatar.php
index e852a7fc6ff..9e1f367108d 100644
--- a/tests/lib/avatar.php
+++ b/tests/lib/avatar.php
@@ -10,7 +10,9 @@
use OC\Avatar;
class Test_Avatar extends \Test\TestCase {
+ private static $trashBinStatus;
+ /** @var @var string */
private $user;
protected function setUp() {
@@ -21,6 +23,17 @@ class Test_Avatar extends \Test\TestCase {
\OC\Files\Filesystem::mount($storage, array(), '/' . $this->user . '/');
}
+ public static function setUpBeforeClass() {
+ self::$trashBinStatus = \OC_App::isEnabled('files_trashbin');
+ \OC_App::disable('files_trashbin');
+ }
+
+ public static function tearDownAfterClass() {
+ if (self::$trashBinStatus) {
+ \OC_App::enable('files_trashbin');
+ }
+ }
+
public function testAvatar() {
$avatar = new Avatar($this->user);
diff --git a/tests/lib/cache/file.php b/tests/lib/cache/file.php
index d51322036c8..153cb198f13 100644
--- a/tests/lib/cache/file.php
+++ b/tests/lib/cache/file.php
@@ -38,15 +38,8 @@ class FileCache extends \Test_Cache {
parent::setUp();
//clear all proxies and hooks so we can do clean testing
- \OC_FileProxy::clearProxies();
\OC_Hook::clear('OC_Filesystem');
- //disabled atm
- //enable only the encryption hook if needed
- //if(OC_App::isEnabled('files_encryption')) {
- // OC_FileProxy::register(new OC_FileProxy_Encryption());
- //}
-
//set up temporary storage
$this->storage = \OC\Files\Filesystem::getStorage('/');
\OC\Files\Filesystem::clearMounts();
diff --git a/tests/lib/cache/usercache.php b/tests/lib/cache/usercache.php
index 3822a714d5a..26a9158ab3a 100644
--- a/tests/lib/cache/usercache.php
+++ b/tests/lib/cache/usercache.php
@@ -34,15 +34,8 @@ class UserCache extends \Test_Cache {
parent::setUp();
//clear all proxies and hooks so we can do clean testing
- \OC_FileProxy::clearProxies();
\OC_Hook::clear('OC_Filesystem');
- //disabled atm
- //enable only the encryption hook if needed
- //if(OC_App::isEnabled('files_encryption')) {
- // OC_FileProxy::register(new OC_FileProxy_Encryption());
- //}
-
//set up temporary storage
$this->storage = \OC\Files\Filesystem::getStorage('/');
\OC\Files\Filesystem::clearMounts();
diff --git a/tests/lib/encryption/keys/storage.php b/tests/lib/encryption/keys/storage.php
index c2e5bdbd3d1..8ab46987f8c 100644
--- a/tests/lib/encryption/keys/storage.php
+++ b/tests/lib/encryption/keys/storage.php
@@ -28,6 +28,9 @@ use Test\TestCase;
class StorageTest extends TestCase {
+ /** @var Storage */
+ protected $storage;
+
/** @var \PHPUnit_Framework_MockObject_MockObject */
protected $util;
@@ -45,6 +48,8 @@ class StorageTest extends TestCase {
->disableOriginalConstructor()
->getMock();
+ $this->storage = new Storage('encModule', $this->view, $this->util);
+
}
public function testSetFileKey() {
@@ -63,10 +68,8 @@ class StorageTest extends TestCase {
$this->equalTo('key'))
->willReturn(strlen('key'));
- $storage = new Storage('encModule', $this->view, $this->util);
-
$this->assertTrue(
- $storage->setFileKey('user1/files/foo.txt', 'fileKey', 'key')
+ $this->storage->setFileKey('user1/files/foo.txt', 'fileKey', 'key')
);
}
@@ -89,10 +92,8 @@ class StorageTest extends TestCase {
->with($this->equalTo('/user1/files_encryption/keys/files/foo.txt/encModule/fileKey'))
->willReturn(true);
- $storage = new Storage('encModule', $this->view, $this->util);
-
$this->assertSame('key',
- $storage->getFileKey('user1/files/foo.txt', 'fileKey')
+ $this->storage->getFileKey('user1/files/foo.txt', 'fileKey')
);
}
@@ -112,10 +113,8 @@ class StorageTest extends TestCase {
$this->equalTo('key'))
->willReturn(strlen('key'));
- $storage = new Storage('encModule', $this->view, $this->util);
-
$this->assertTrue(
- $storage->setFileKey('user1/files/foo.txt', 'fileKey', 'key')
+ $this->storage->setFileKey('user1/files/foo.txt', 'fileKey', 'key')
);
}
@@ -138,10 +137,8 @@ class StorageTest extends TestCase {
->with($this->equalTo('/files_encryption/keys/files/foo.txt/encModule/fileKey'))
->willReturn(true);
- $storage = new Storage('encModule', $this->view, $this->util);
-
$this->assertSame('key',
- $storage->getFileKey('user1/files/foo.txt', 'fileKey')
+ $this->storage->getFileKey('user1/files/foo.txt', 'fileKey')
);
}
@@ -152,10 +149,8 @@ class StorageTest extends TestCase {
$this->equalTo('key'))
->willReturn(strlen('key'));
- $storage = new Storage('encModule', $this->view, $this->util);
-
$this->assertTrue(
- $storage->setSystemUserKey('shareKey_56884', 'key')
+ $this->storage->setSystemUserKey('shareKey_56884', 'key')
);
}
@@ -166,10 +161,8 @@ class StorageTest extends TestCase {
$this->equalTo('key'))
->willReturn(strlen('key'));
- $storage = new Storage('encModule', $this->view, $this->util);
-
$this->assertTrue(
- $storage->setUserKey('user1', 'publicKey', 'key')
+ $this->storage->setUserKey('user1', 'publicKey', 'key')
);
}
@@ -183,10 +176,8 @@ class StorageTest extends TestCase {
->with($this->equalTo('/files_encryption/encModule/shareKey_56884'))
->willReturn(true);
- $storage = new Storage('encModule', $this->view, $this->util);
-
$this->assertSame('key',
- $storage->getSystemUserKey('shareKey_56884')
+ $this->storage->getSystemUserKey('shareKey_56884')
);
}
@@ -200,10 +191,8 @@ class StorageTest extends TestCase {
->with($this->equalTo('/user1/files_encryption/encModule/user1.publicKey'))
->willReturn(true);
- $storage = new Storage('encModule', $this->view, $this->util);
-
$this->assertSame('key',
- $storage->getUserKey('user1', 'publicKey')
+ $this->storage->getUserKey('user1', 'publicKey')
);
}
@@ -213,10 +202,8 @@ class StorageTest extends TestCase {
->with($this->equalTo('/user1/files_encryption/encModule/user1.publicKey'))
->willReturn(true);
- $storage = new Storage('encModule', $this->view, $this->util);
-
$this->assertTrue(
- $storage->deleteUserKey('user1', 'publicKey')
+ $this->storage->deleteUserKey('user1', 'publicKey')
);
}
@@ -226,10 +213,8 @@ class StorageTest extends TestCase {
->with($this->equalTo('/files_encryption/encModule/shareKey_56884'))
->willReturn(true);
- $storage = new Storage('encModule', $this->view, $this->util);
-
$this->assertTrue(
- $storage->deleteSystemUserKey('shareKey_56884')
+ $this->storage->deleteSystemUserKey('shareKey_56884')
);
}
@@ -248,10 +233,8 @@ class StorageTest extends TestCase {
->with($this->equalTo('/files_encryption/keys/files/foo.txt/encModule/fileKey'))
->willReturn(true);
- $storage = new Storage('encModule', $this->view, $this->util);
-
$this->assertTrue(
- $storage->deleteFileKey('user1/files/foo.txt', 'fileKey')
+ $this->storage->deleteFileKey('user1/files/foo.txt', 'fileKey')
);
}
@@ -270,11 +253,109 @@ class StorageTest extends TestCase {
->with($this->equalTo('/user1/files_encryption/keys/files/foo.txt/encModule/fileKey'))
->willReturn(true);
- $storage = new Storage('encModule', $this->view, $this->util);
-
$this->assertTrue(
- $storage->deleteFileKey('user1/files/foo.txt', 'fileKey')
+ $this->storage->deleteFileKey('user1/files/foo.txt', 'fileKey')
+ );
+ }
+
+ /**
+ * @dataProvider dataProviderCopyRename
+ */
+ public function testRenameKeys($source, $target, $systemWideMount, $expectedSource, $expectedTarget) {
+ $this->view->expects($this->any())
+ ->method('file_exists')
+ ->willReturn(true);
+ $this->view->expects($this->any())
+ ->method('is_dir')
+ ->willReturn(true);
+ $this->view->expects($this->once())
+ ->method('rename')
+ ->with(
+ $this->equalTo($expectedSource),
+ $this->equalTo($expectedTarget))
+ ->willReturn(true);
+ $this->util->expects($this->any())
+ ->method('getUidAndFilename')
+ ->will($this->returnCallback(array($this, 'getUidAndFilenameCallback')));
+ $this->util->expects($this->any())
+ ->method('isSystemWideMountPoint')
+ ->willReturn($systemWideMount);
+
+ $this->storage->renameKeys($source, $target);
+ }
+
+ /**
+ * @dataProvider dataProviderCopyRename
+ */
+ public function testCopyKeys($source, $target, $systemWideMount, $expectedSource, $expectedTarget) {
+ $this->view->expects($this->any())
+ ->method('file_exists')
+ ->willReturn(true);
+ $this->view->expects($this->any())
+ ->method('is_dir')
+ ->willReturn(true);
+ $this->view->expects($this->once())
+ ->method('copy')
+ ->with(
+ $this->equalTo($expectedSource),
+ $this->equalTo($expectedTarget))
+ ->willReturn(true);
+ $this->util->expects($this->any())
+ ->method('getUidAndFilename')
+ ->will($this->returnCallback(array($this, 'getUidAndFilenameCallback')));
+ $this->util->expects($this->any())
+ ->method('isSystemWideMountPoint')
+ ->willReturn($systemWideMount);
+
+ $this->storage->copyKeys($source, $target);
+ }
+
+ public function getUidAndFilenameCallback() {
+ $args = func_get_args();
+
+ $path = $args[0];
+ $parts = explode('/', $path);
+
+ return array($parts[1], '/' . implode('/', array_slice($parts, 2)));
+ }
+
+ public function dataProviderCopyRename() {
+ return array(
+ array('/user1/files/foo.txt', '/user1/files/bar.txt', false,
+ '/user1/files_encryption/keys/files/foo.txt/', '/user1/files_encryption/keys/files/bar.txt/'),
+ array('/user1/files/foo/foo.txt', '/user1/files/bar.txt', false,
+ '/user1/files_encryption/keys/files/foo/foo.txt/', '/user1/files_encryption/keys/files/bar.txt/'),
+ array('/user1/files/foo.txt', '/user1/files/foo/bar.txt', false,
+ '/user1/files_encryption/keys/files/foo.txt/', '/user1/files_encryption/keys/files/foo/bar.txt/'),
+ array('/user1/files/foo.txt', '/user1/files/foo/bar.txt', true,
+ '/files_encryption/keys/files/foo.txt/', '/files_encryption/keys/files/foo/bar.txt/'),
);
}
+ public function testKeySetPreparation() {
+ $this->view->expects($this->any())
+ ->method('file_exists')
+ ->willReturn(false);
+ $this->view->expects($this->any())
+ ->method('is_dir')
+ ->willReturn(false);
+ $this->view->expects($this->any())
+ ->method('mkdir')
+ ->will($this->returnCallback(array($this, 'mkdirCallback')));
+
+ $this->mkdirStack = array(
+ '/user1/files_encryption/keys/foo',
+ '/user1/files_encryption/keys',
+ '/user1/files_encryption',
+ '/user1');
+
+ \Test_Helper::invokePrivate($this->storage, 'keySetPreparation', array('/user1/files_encryption/keys/foo'));
+ }
+
+ public function mkdirCallback() {
+ $args = func_get_args();
+ $expected = array_pop($this->mkdirStack);
+ $this->assertSame($expected, $args[0]);
+ }
+
}
diff --git a/tests/lib/encryption/managertest.php b/tests/lib/encryption/managertest.php
index ab297bae0cb..4fcbc3b9983 100644
--- a/tests/lib/encryption/managertest.php
+++ b/tests/lib/encryption/managertest.php
@@ -111,4 +111,62 @@ class ManagerTest extends TestCase {
$en0 = $m->getEncryptionModule(0);
$this->assertEquals(0, $en0->getId());
}
+
+// /**
+// * @expectedException \OC\Encryption\Exceptions\ModuleAlreadyExistsException
+// * @expectedExceptionMessage Id "0" already used by encryption module "TestDummyModule0"
+// */
+// public function testModuleRegistration() {
+// $config = $this->getMock('\OCP\IConfig');
+// $config->expects($this->any())->method('getSystemValue')->willReturn(true);
+// $em = $this->getMock('\OCP\Encryption\IEncryptionModule');
+// $em->expects($this->any())->method('getId')->willReturn(0);
+// $em->expects($this->any())->method('getDisplayName')->willReturn('TestDummyModule0');
+// $m = new Manager($config);
+// $m->registerEncryptionModule($em);
+// $this->assertTrue($m->isEnabled());
+// $m->registerEncryptionModule($em);
+// }
+//
+// public function testModuleUnRegistration() {
+// $config = $this->getMock('\OCP\IConfig');
+// $config->expects($this->any())->method('getSystemValue')->willReturn(true);
+// $em = $this->getMock('\OCP\Encryption\IEncryptionModule');
+// $em->expects($this->any())->method('getId')->willReturn(0);
+// $em->expects($this->any())->method('getDisplayName')->willReturn('TestDummyModule0');
+// $m = new Manager($config);
+// $m->registerEncryptionModule($em);
+// $this->assertTrue($m->isEnabled());
+// $m->unregisterEncryptionModule($em);
+// $this->assertFalse($m->isEnabled());
+// }
+//
+// /**
+// * @expectedException \OC\Encryption\Exceptions\ModuleDoesNotExistsException
+// * @expectedExceptionMessage Module with id: unknown does not exists.
+// */
+// public function testGetEncryptionModuleUnknown() {
+// $config = $this->getMock('\OCP\IConfig');
+// $config->expects($this->any())->method('getSystemValue')->willReturn(true);
+// $em = $this->getMock('\OCP\Encryption\IEncryptionModule');
+// $em->expects($this->any())->method('getId')->willReturn(0);
+// $em->expects($this->any())->method('getDisplayName')->willReturn('TestDummyModule0');
+// $m = new Manager($config);
+// $m->registerEncryptionModule($em);
+// $this->assertTrue($m->isEnabled());
+// $m->getEncryptionModule('unknown');
+// }
+//
+// public function testGetEncryptionModule() {
+// $config = $this->getMock('\OCP\IConfig');
+// $config->expects($this->any())->method('getSystemValue')->willReturn(true);
+// $em = $this->getMock('\OCP\Encryption\IEncryptionModule');
+// $em->expects($this->any())->method('getId')->willReturn(0);
+// $em->expects($this->any())->method('getDisplayName')->willReturn('TestDummyModule0');
+// $m = new Manager($config);
+// $m->registerEncryptionModule($em);
+// $this->assertTrue($m->isEnabled());
+// $en0 = $m->getEncryptionModule(0);
+// $this->assertEquals(0, $en0->getId());
+// }
}
diff --git a/tests/lib/encryption/utiltest.php b/tests/lib/encryption/utiltest.php
index 672f9ff5e97..03aefe61151 100644
--- a/tests/lib/encryption/utiltest.php
+++ b/tests/lib/encryption/utiltest.php
@@ -20,6 +20,9 @@ class UtilTest extends TestCase {
/** @var \PHPUnit_Framework_MockObject_MockObject */
protected $userManager;
+ /** @var \PHPUnit_Framework_MockObject_MockObject */
+ private $config;
+
public function setUp() {
parent::setUp();
$this->view = $this->getMockBuilder('OC\Files\View')
@@ -29,13 +32,18 @@ class UtilTest extends TestCase {
$this->userManager = $this->getMockBuilder('OC\User\Manager')
->disableOriginalConstructor()
->getMock();
+
+ $this->config = $this->getMockBuilder('OCP\IConfig')
+ ->disableOriginalConstructor()
+ ->getMock();
+
}
/**
* @dataProvider providesHeadersForEncryptionModule
*/
public function testGetEncryptionModuleId($expected, $header) {
- $u = new Util($this->view, $this->userManager);
+ $u = new Util($this->view, $this->userManager, $this->config);
$id = $u->getEncryptionModuleId($header);
$this->assertEquals($expected, $id);
}
@@ -53,7 +61,7 @@ class UtilTest extends TestCase {
*/
public function testReadHeader($header, $expected, $moduleId) {
$expected['oc_encryption_module'] = $moduleId;
- $u = new Util($this->view, $this->userManager);
+ $u = new Util($this->view, $this->userManager, $this->config);
$result = $u->readHeader($header);
$this->assertSameSize($expected, $result);
foreach ($expected as $key => $value) {
@@ -70,7 +78,7 @@ class UtilTest extends TestCase {
$em = $this->getMock('\OCP\Encryption\IEncryptionModule');
$em->expects($this->any())->method('getId')->willReturn($moduleId);
- $u = new Util($this->view, $this->userManager);
+ $u = new Util($this->view, $this->userManager, $this->config);
$result = $u->createHeader($header, $em);
$this->assertEquals($expected, $result);
}
@@ -94,7 +102,7 @@ class UtilTest extends TestCase {
$em = $this->getMock('\OCP\Encryption\IEncryptionModule');
$em->expects($this->any())->method('getId')->willReturn('moduleId');
- $u = new Util($this->view, $this->userManager);
+ $u = new Util($this->view, $this->userManager, $this->config);
$u->createHeader($header, $em);
}
@@ -107,7 +115,7 @@ class UtilTest extends TestCase {
->method('userExists')
->will($this->returnCallback(array($this, 'isExcludedCallback')));
- $u = new Util($this->view, $this->userManager);
+ $u = new Util($this->view, $this->userManager, $this->config);
$this->assertSame($expected,
$u->isExcluded($path)
diff --git a/tests/lib/files/cache/cache.php b/tests/lib/files/cache/cache.php
index f0ad6cf3ab1..9a64375f4e3 100644
--- a/tests/lib/files/cache/cache.php
+++ b/tests/lib/files/cache/cache.php
@@ -183,8 +183,8 @@ class Cache extends \Test\TestCase {
$file3 = 'folder/foo';
$data1 = array('size' => 100, 'mtime' => 50, 'mimetype' => 'httpd/unix-directory');
$fileData = array();
- $fileData['bar'] = array('size' => 1000, 'unencrypted_size' => 900, 'encrypted' => 1, 'mtime' => 20, 'mimetype' => 'foo/file');
- $fileData['foo'] = array('size' => 20, 'unencrypted_size' => 16, 'encrypted' => 1, 'mtime' => 25, 'mimetype' => 'foo/file');
+ $fileData['bar'] = array('size' => 1000, 'encrypted' => 1, 'mtime' => 20, 'mimetype' => 'foo/file');
+ $fileData['foo'] = array('size' => 20, 'encrypted' => 1, 'mtime' => 25, 'mimetype' => 'foo/file');
$this->cache->put($file1, $data1);
$this->cache->put($file2, $fileData['bar']);
@@ -194,8 +194,6 @@ class Cache extends \Test\TestCase {
$this->assertEquals(count($content), 2);
foreach ($content as $cachedData) {
$data = $fileData[$cachedData['name']];
- // indirect retrieval swaps unencrypted_size and size
- $this->assertEquals($data['unencrypted_size'], $cachedData['size']);
}
$file4 = 'folder/unkownSize';
@@ -207,11 +205,10 @@ class Cache extends \Test\TestCase {
$fileData['unkownSize'] = array('size' => 5, 'mtime' => 25, 'mimetype' => 'foo/file');
$this->cache->put($file4, $fileData['unkownSize']);
- $this->assertEquals(916, $this->cache->calculateFolderSize($file1));
+ $this->assertEquals(1025, $this->cache->calculateFolderSize($file1));
// direct cache entry retrieval returns the original values
$entry = $this->cache->get($file1);
$this->assertEquals(1025, $entry['size']);
- $this->assertEquals(916, $entry['unencrypted_size']);
$this->cache->remove($file2);
$this->cache->remove($file3);
diff --git a/tests/lib/files/cache/updaterlegacy.php b/tests/lib/files/cache/updaterlegacy.php
index 99cacca8e95..6bdacbe34fe 100644
--- a/tests/lib/files/cache/updaterlegacy.php
+++ b/tests/lib/files/cache/updaterlegacy.php
@@ -22,8 +22,6 @@ class UpdaterLegacy extends \Test\TestCase {
*/
private $scanner;
- private $stateFilesEncryption;
-
/**
* @var \OC\Files\Cache\Cache $cache
*/
@@ -37,11 +35,6 @@ class UpdaterLegacy extends \Test\TestCase {
protected function setUp() {
parent::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');
@@ -80,10 +73,6 @@ class UpdaterLegacy extends \Test\TestCase {
$this->assertTrue($result);
Filesystem::tearDown();
Filesystem::mount($this->originalStorage, array(), '/');
- // reset app files_encryption
- if ($this->stateFilesEncryption) {
- \OC_App::enable('files_encryption');
- }
parent::tearDown();
}
diff --git a/tests/lib/files/storage/storage.php b/tests/lib/files/storage/storage.php
index ad7522f1ea8..938fecb5bf3 100644
--- a/tests/lib/files/storage/storage.php
+++ b/tests/lib/files/storage/storage.php
@@ -253,7 +253,7 @@ abstract class Storage extends \Test\TestCase {
$this->instance->file_put_contents('/lorem.txt', file_get_contents($textFile));
$localFile = $this->instance->getLocalFile('/lorem.txt');
$this->assertTrue(file_exists($localFile));
- $this->assertEquals(file_get_contents($localFile), file_get_contents($textFile));
+ $this->assertEquals(file_get_contents($textFile), file_get_contents($localFile));
$this->instance->mkdir('/folder');
$this->instance->file_put_contents('/folder/lorem.txt', file_get_contents($textFile));
diff --git a/tests/lib/files/storage/wrapper/encryption.php b/tests/lib/files/storage/wrapper/encryption.php
new file mode 100644
index 00000000000..bf4464f0eb9
--- /dev/null
+++ b/tests/lib/files/storage/wrapper/encryption.php
@@ -0,0 +1,125 @@
+<?php
+
+namespace Test\Files\Storage\Wrapper;
+
+use OC\Files\Storage\Temporary;
+use OC\Files\View;
+
+class Encryption extends \Test\Files\Storage\Storage {
+
+ /**
+ * @var Temporary
+ */
+ private $sourceStorage;
+
+ public function setUp() {
+
+ parent::setUp();
+
+ $mockModule = $this->buildMockModule();
+ $encryptionManager = $this->getMockBuilder('\OC\Encryption\Manager')
+ ->disableOriginalConstructor()
+ ->setMethods(['getDefaultEncryptionModule', 'getEncryptionModule', 'isEnabled'])
+ ->getMock();
+ $encryptionManager->expects($this->any())
+ ->method('getDefaultEncryptionModule')
+ ->willReturn($mockModule);
+ $encryptionManager->expects($this->any())
+ ->method('getEncryptionModule')
+ ->willReturn($mockModule);
+ $encryptionManager->expects($this->any())
+ ->method('isEnabled')
+ ->willReturn(true);
+
+ $config = $this->getMockBuilder('\OCP\IConfig')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $util = $this->getMock('\OC\Encryption\Util', ['getUidAndFilename'], [new View(), new \OC\User\Manager(), $config]);
+ $util->expects($this->any())
+ ->method('getUidAndFilename')
+ ->willReturnCallback(function ($path) {
+ return ['user1', $path];
+ });
+
+ $file = $this->getMockBuilder('\OC\Encryption\File')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $logger = $this->getMock('\OC\Log');
+
+ $this->sourceStorage = new Temporary(array());
+ $keyStore = $this->getMockBuilder('\OC\Encryption\Keys\Storage')
+ ->disableOriginalConstructor()->getMock();
+ $mount = $this->getMockBuilder('\OC\Files\Mount\MountPoint')
+ ->disableOriginalConstructor()
+ ->setMethods(['getOption'])
+ ->getMock();
+ $mount->expects($this->any())->method('getOption')->willReturn(true);
+ $this->instance = new EncryptionWrapper([
+ 'storage' => $this->sourceStorage,
+ 'root' => 'foo',
+ 'mountPoint' => '/',
+ 'mount' => $mount
+ ],
+ $encryptionManager, $util, $logger, $file, null, $keyStore
+ );
+ }
+
+ /**
+ * @return \PHPUnit_Framework_MockObject_MockObject
+ */
+ protected function buildMockModule() {
+ $encryptionModule = $this->getMockBuilder('\OCP\Encryption\IEncryptionModule')
+ ->disableOriginalConstructor()
+ ->setMethods(['getId', 'getDisplayName', 'begin', 'end', 'encrypt', 'decrypt', 'update', 'shouldEncrypt', 'calculateUnencryptedSize', 'getUnencryptedBlockSize'])
+ ->getMock();
+
+ $encryptionModule->expects($this->any())->method('getId')->willReturn('UNIT_TEST_MODULE');
+ $encryptionModule->expects($this->any())->method('getDisplayName')->willReturn('Unit test module');
+ $encryptionModule->expects($this->any())->method('begin')->willReturn([]);
+ $encryptionModule->expects($this->any())->method('end')->willReturn('');
+ $encryptionModule->expects($this->any())->method('encrypt')->willReturnArgument(0);
+ $encryptionModule->expects($this->any())->method('decrypt')->willReturnArgument(0);
+ $encryptionModule->expects($this->any())->method('update')->willReturn(true);
+ $encryptionModule->expects($this->any())->method('shouldEncrypt')->willReturn(true);
+ $encryptionModule->expects($this->any())->method('calculateUnencryptedSize')->willReturn(42);
+ $encryptionModule->expects($this->any())->method('getUnencryptedBlockSize')->willReturn(8192);
+ return $encryptionModule;
+ }
+
+// 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'));
+// }
+}
+
+//
+// FIXME: this is too bad and needs adjustment
+//
+class EncryptionWrapper extends \OC\Files\Storage\Wrapper\Encryption {
+ private $keyStore;
+
+ public function __construct(
+ $parameters,
+ \OC\Encryption\Manager $encryptionManager = null,
+ \OC\Encryption\Util $util = null,
+ \OC\Log $logger = null,
+ \OC\Encryption\File $fileHelper = null,
+ $uid = null,
+ $keyStore = null
+ ) {
+ $this->keyStore = $keyStore;
+ parent::__construct($parameters, $encryptionManager, $util, $logger, $fileHelper, $uid);
+ }
+
+ protected function getKeyStorage($encryptionModuleId) {
+ return $this->keyStore;
+ }
+
+}
diff --git a/tests/lib/files/storage/wrapper/jail.php b/tests/lib/files/storage/wrapper/jail.php
index 270ce750ecf..a7bd684df44 100644
--- a/tests/lib/files/storage/wrapper/jail.php
+++ b/tests/lib/files/storage/wrapper/jail.php
@@ -9,10 +9,6 @@
namespace Test\Files\Storage\Wrapper;
class Jail extends \Test\Files\Storage\Storage {
- /**
- * @var string tmpDir
- */
- private $tmpDir;
/**
* @var \OC\Files\Storage\Temporary
diff --git a/tests/lib/files/storage/wrapper/quota.php b/tests/lib/files/storage/wrapper/quota.php
index 8ca8f308b71..a5828296be9 100644
--- a/tests/lib/files/storage/wrapper/quota.php
+++ b/tests/lib/files/storage/wrapper/quota.php
@@ -59,7 +59,7 @@ class Quota extends \Test\Files\Storage\Storage {
public function testFreeSpaceWithUsedSpace() {
$instance = $this->getLimitedStorage(9);
$instance->getCache()->put(
- '', array('size' => 3, 'unencrypted_size' => 0)
+ '', array('size' => 3)
);
$this->assertEquals(6, $instance->free_space(''));
}
@@ -77,7 +77,7 @@ class Quota extends \Test\Files\Storage\Storage {
$instance = new \OC\Files\Storage\Wrapper\Quota(array('storage' => $storage, 'quota' => 9));
$instance->getCache()->put(
- '', array('size' => 3, 'unencrypted_size' => 0)
+ '', array('size' => 3)
);
$this->assertEquals(6, $instance->free_space(''));
}
@@ -85,9 +85,9 @@ class Quota extends \Test\Files\Storage\Storage {
public function testFreeSpaceWithUsedSpaceAndEncryption() {
$instance = $this->getLimitedStorage(9);
$instance->getCache()->put(
- '', array('size' => 7, 'unencrypted_size' => 3)
+ '', array('size' => 7)
);
- $this->assertEquals(6, $instance->free_space(''));
+ $this->assertEquals(2, $instance->free_space(''));
}
public function testFWriteNotEnoughSpace() {
diff --git a/tests/lib/files/stream/encryption.php b/tests/lib/files/stream/encryption.php
new file mode 100644
index 00000000000..84156337ad7
--- /dev/null
+++ b/tests/lib/files/stream/encryption.php
@@ -0,0 +1,104 @@
+<?php
+
+namespace Test\Files\Stream;
+
+use OC\Files\View;
+use OCA\Encryption_Dummy\DummyModule;
+
+class Encryption extends \Test\TestCase {
+
+ /**
+ * @param string $mode
+ * @param integer $limit
+ */
+ protected function getStream($fileName, $mode, $unencryptedSize) {
+
+ $size = filesize($fileName);
+ $source = fopen($fileName, $mode);
+ $internalPath = $fileName;
+ $fullPath = $fileName;
+ $header = [];
+ $uid = '';
+ $encryptionModule = $this->buildMockModule();
+ $storage = $this->getMockBuilder('\OC\Files\Storage\Storage')
+ ->disableOriginalConstructor()->getMock();
+ $encStorage = $this->getMockBuilder('\OC\Files\Storage\Wrapper\Encryption')
+ ->disableOriginalConstructor()->getMock();
+ $config = $this->getMockBuilder('\OCP\IConfig')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $file = $this->getMockBuilder('\OC\Encryption\File')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $util = $this->getMock('\OC\Encryption\Util', ['getUidAndFilename'], [new View(), new \OC\User\Manager(), $config]);
+ $util->expects($this->any())
+ ->method('getUidAndFilename')
+ ->willReturn(['user1', $internalPath]);
+
+ return \OC\Files\Stream\Encryption::wrap($source, $internalPath,
+ $fullPath, $header, $uid, $encryptionModule, $storage, $encStorage,
+ $util, $file, $mode, $size, $unencryptedSize);
+ }
+
+ public function testWriteRead() {
+ $fileName = tempnam("/tmp", "FOO");
+ $stream = $this->getStream($fileName, 'w+', 0);
+ $this->assertEquals(6, fwrite($stream, 'foobar'));
+ fclose($stream);
+
+ $stream = $this->getStream($fileName, 'r', 6);
+ $this->assertEquals('foobar', fread($stream, 100));
+ fclose($stream);
+ }
+
+ public function testSeek() {
+ $fileName = tempnam("/tmp", "FOO");
+ $stream = $this->getStream($fileName, 'w+', 0);
+ $this->assertEquals(6, fwrite($stream, 'foobar'));
+ $this->assertEquals(0, fseek($stream, 3));
+ $this->assertEquals(6, fwrite($stream, 'foobar'));
+ fclose($stream);
+
+ $stream = $this->getStream($fileName, 'r', 9);
+ $this->assertEquals('foofoobar', fread($stream, 100));
+ fclose($stream);
+ }
+
+ public function testWriteReadBigFile() {
+ $expectedData = file_get_contents(\OC::$SERVERROOT . '/tests/data/lorem-big.txt');
+ // write it
+ $fileName = tempnam("/tmp", "FOO");
+ $stream = $this->getStream($fileName, 'w+', 0);
+ fwrite($stream, $expectedData);
+ fclose($stream);
+
+ // read it all
+ $stream = $this->getStream($fileName, 'r', strlen($expectedData));
+ $data = stream_get_contents($stream);
+ fclose($stream);
+
+ $this->assertEquals($expectedData, $data);
+ }
+
+ /**
+ * @return \PHPUnit_Framework_MockObject_MockObject
+ */
+ protected function buildMockModule() {
+ $encryptionModule = $this->getMockBuilder('\OCP\Encryption\IEncryptionModule')
+ ->disableOriginalConstructor()
+ ->setMethods(['getId', 'getDisplayName', 'begin', 'end', 'encrypt', 'decrypt', 'update', 'shouldEncrypt', 'calculateUnencryptedSize', 'getUnencryptedBlockSize'])
+ ->getMock();
+
+ $encryptionModule->expects($this->any())->method('getId')->willReturn('UNIT_TEST_MODULE');
+ $encryptionModule->expects($this->any())->method('getDisplayName')->willReturn('Unit test module');
+ $encryptionModule->expects($this->any())->method('begin')->willReturn([]);
+ $encryptionModule->expects($this->any())->method('end')->willReturn('');
+ $encryptionModule->expects($this->any())->method('encrypt')->willReturnArgument(0);
+ $encryptionModule->expects($this->any())->method('decrypt')->willReturnArgument(0);
+ $encryptionModule->expects($this->any())->method('update')->willReturn(true);
+ $encryptionModule->expects($this->any())->method('shouldEncrypt')->willReturn(true);
+ $encryptionModule->expects($this->any())->method('calculateUnencryptedSize')->willReturn(42);
+ $encryptionModule->expects($this->any())->method('getUnencryptedBlockSize')->willReturn(8192);
+ return $encryptionModule;
+ }
+}
diff --git a/tests/lib/streamwrappers.php b/tests/lib/streamwrappers.php
index 2a8c8676c16..fc3d02acae7 100644
--- a/tests/lib/streamwrappers.php
+++ b/tests/lib/streamwrappers.php
@@ -21,6 +21,20 @@
*/
class Test_StreamWrappers extends \Test\TestCase {
+
+ private static $trashBinStatus;
+
+ public static function setUpBeforeClass() {
+ self::$trashBinStatus = \OC_App::isEnabled('files_trashbin');
+ \OC_App::disable('files_trashbin');
+ }
+
+ public static function tearDownAfterClass() {
+ if (self::$trashBinStatus) {
+ \OC_App::enable('files_trashbin');
+ }
+ }
+
public function testFakeDir() {
$items = array('foo', 'bar');
\OC\Files\Stream\Dir::register('test', $items);
diff --git a/tests/lib/testcase.php b/tests/lib/testcase.php
index d532a3b01c0..a83be713194 100644
--- a/tests/lib/testcase.php
+++ b/tests/lib/testcase.php
@@ -71,7 +71,6 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase {
self::tearDownAfterClassCleanFileCache();
self::tearDownAfterClassCleanStrayDataFiles($dataDir);
self::tearDownAfterClassCleanStrayHooks();
- self::tearDownAfterClassCleanProxies();
parent::tearDownAfterClass();
}
@@ -165,16 +164,6 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase {
}
/**
- * Clean up the list of file proxies
- *
- * Also reenables file proxies, in case a test disabled them
- */
- static protected function tearDownAfterClassCleanProxies() {
- \OC_FileProxy::$enabled = true;
- \OC_FileProxy::clearProxies();
- }
-
- /**
* Login and setup FS as a given user,
* sets the given user as the current user.
*