summaryrefslogtreecommitdiffstats
path: root/apps/files_encryption
diff options
context:
space:
mode:
authorBjoern Schiessle <schiessle@owncloud.com>2014-11-18 17:25:36 +0100
committerBjoern Schiessle <schiessle@owncloud.com>2014-12-02 16:03:54 +0100
commit49cfc3035944956269e7264df9fbfb202b7e096d (patch)
treee37976b7b0019a2dc551952c359a2bbe3814b191 /apps/files_encryption
parenta90606fb14adc0aa149a87528d4f1ce61d0250e9 (diff)
downloadnextcloud-server-49cfc3035944956269e7264df9fbfb202b7e096d.tar.gz
nextcloud-server-49cfc3035944956269e7264df9fbfb202b7e096d.zip
upgrade to new folder structure
Diffstat (limited to 'apps/files_encryption')
-rw-r--r--apps/files_encryption/appinfo/update.php5
-rw-r--r--apps/files_encryption/appinfo/version2
-rw-r--r--apps/files_encryption/lib/keymanager.php34
-rw-r--r--apps/files_encryption/lib/migration.php261
-rw-r--r--apps/files_encryption/lib/session.php4
-rw-r--r--apps/files_encryption/lib/util.php2
-rwxr-xr-xapps/files_encryption/tests/crypt.php22
-rw-r--r--apps/files_encryption/tests/helper.php8
-rw-r--r--apps/files_encryption/tests/hooks.php32
-rw-r--r--apps/files_encryption/tests/keymanager.php23
-rw-r--r--apps/files_encryption/tests/migration.php259
-rw-r--r--apps/files_encryption/tests/proxy.php22
-rwxr-xr-xapps/files_encryption/tests/share.php31
-rw-r--r--apps/files_encryption/tests/stream.php19
-rw-r--r--apps/files_encryption/tests/testcase.php31
-rwxr-xr-xapps/files_encryption/tests/trashbin.php22
-rwxr-xr-xapps/files_encryption/tests/util.php25
-rwxr-xr-xapps/files_encryption/tests/webdav.php22
18 files changed, 483 insertions, 341 deletions
diff --git a/apps/files_encryption/appinfo/update.php b/apps/files_encryption/appinfo/update.php
index a29667ec6b6..957cf746974 100644
--- a/apps/files_encryption/appinfo/update.php
+++ b/apps/files_encryption/appinfo/update.php
@@ -4,7 +4,8 @@ use OCA\Files_Encryption\Migration;
$installedVersion=OCP\Config::getAppValue('files_encryption', 'installed_version');
-if (version_compare($installedVersion, '0.6', '<')) {
+// Migration OC7 -> OC8
+if (version_compare($installedVersion, '0.7', '<')) {
$m = new Migration();
- $m->dropTableEncryption();
+ $m->reorganizeFolderStructure();
}
diff --git a/apps/files_encryption/appinfo/version b/apps/files_encryption/appinfo/version
index ee6cdce3c29..faef31a4357 100644
--- a/apps/files_encryption/appinfo/version
+++ b/apps/files_encryption/appinfo/version
@@ -1 +1 @@
-0.6.1
+0.7.0
diff --git a/apps/files_encryption/lib/keymanager.php b/apps/files_encryption/lib/keymanager.php
index 2c340bcb23f..c8de1a73d27 100644
--- a/apps/files_encryption/lib/keymanager.php
+++ b/apps/files_encryption/lib/keymanager.php
@@ -31,7 +31,9 @@ namespace OCA\Encryption;
class Keymanager {
// base dir where all the file related keys are stored
- const KEYS_BASE_DIR = '/files_encryption/keys/';
+ private static $keys_base_dir = '/files_encryption/keys/';
+ private static $encryption_base_dir = '/files_encryption';
+ private static $public_key_dir = '/files_encryption/public_keys';
/**
* read key from hard disk
@@ -95,10 +97,14 @@ class Keymanager {
* @return string public key or false
*/
public static function getPublicKey(\OC\Files\View $view, $userId) {
- $path = '/public-keys/' . $userId . '.publicKey';
+ $path = self::$public_key_dir . '/' . $userId . '.publicKey';
return self::getKey($path, $view);
}
+ public static function getPublicKeyPath() {
+ return self::$public_key_dir;
+ }
+
/**
* Retrieve a user's public and private key
* @param \OC\Files\View $view
@@ -168,9 +174,9 @@ class Keymanager {
// in case of system wide mount points the keys are stored directly in the data directory
if ($util->isSystemWideMountPoint($filename)) {
- $keyPath = self::KEYS_BASE_DIR . $filePath_f . '/';
+ $keyPath = self::$keys_base_dir . $filePath_f . '/';
} else {
- $keyPath = '/' . $owner . self::KEYS_BASE_DIR . $filePath_f . '/';
+ $keyPath = '/' . $owner . self::$keys_base_dir . $filePath_f . '/';
}
return $keyPath;
@@ -215,7 +221,7 @@ class Keymanager {
$result = false;
if (!\OCP\User::userExists($uid)) {
- $publicKey = '/public-keys/' . $uid . '.publicKey';
+ $publicKey = self::$public_key_dir . '/' . $uid . '.publicKey';
$result = $view->unlink($publicKey);
}
@@ -229,7 +235,7 @@ class Keymanager {
* @param string $uid
*/
public static function publicKeyExists($view, $uid) {
- return $view->file_exists('/public-keys/'. $uid . '.publicKey');
+ return $view->file_exists(self::$public_key_dir . '/'. $uid . '.publicKey');
}
@@ -278,8 +284,8 @@ class Keymanager {
$recoveryKeyId = Helper::getRecoveryKeyId();
if ($recoveryKeyId) {
- $result = ($view->file_exists("/public-keys/" . $recoveryKeyId . ".publicKey")
- && $view->file_exists("/owncloud_private_key/" . $recoveryKeyId . ".privateKey"));
+ $result = ($view->file_exists(self::$public_key_dir . '/' . $recoveryKeyId . ".publicKey")
+ && $view->file_exists(self::$encryption_base_dir . '/' . $recoveryKeyId . ".privateKey"));
}
return $result;
@@ -290,8 +296,8 @@ class Keymanager {
$publicShareKeyId = Helper::getPublicShareKeyId();
if ($publicShareKeyId) {
- $result = ($view->file_exists("/public-keys/" . $publicShareKeyId . ".publicKey")
- && $view->file_exists("/owncloud_private_key/" . $publicShareKeyId . ".privateKey"));
+ $result = ($view->file_exists(self::$public_key_dir . '/' . $publicShareKeyId . ".publicKey")
+ && $view->file_exists(self::$encryption_base_dir . '/' . $publicShareKeyId . ".privateKey"));
}
@@ -308,9 +314,8 @@ class Keymanager {
public static function setPublicKey($key, $user = '') {
$user = $user === '' ? \OCP\User::getUser() : $user;
- $path = '/public-keys';
- return self::setKey($path, $user . '.publicKey', $key, new \OC\Files\View('/'));
+ return self::setKey(self::$public_key_dir, $user . '.publicKey', $key, new \OC\Files\View('/'));
}
/**
@@ -323,10 +328,9 @@ class Keymanager {
public static function setPrivateSystemKey($key, $keyName) {
$keyName = $keyName . '.privateKey';
- $path = '/owncloud_private_key';
$header = Crypt::generateHeader();
- return self::setKey($path, $keyName,$header . $key, new \OC\Files\View());
+ return self::setKey(self::$encryption_base_dir, $keyName,$header . $key, new \OC\Files\View());
}
/**
@@ -337,7 +341,7 @@ class Keymanager {
*/
public static function getPrivateSystemKey($keyName) {
$path = $keyName . '.privateKey';
- return self::getKey($path, new \OC\Files\View('/owncloud_private_key'));
+ return self::getKey($path, new \OC\Files\View(self::$encryption_base_dir));
}
/**
diff --git a/apps/files_encryption/lib/migration.php b/apps/files_encryption/lib/migration.php
index 62a765d21f4..ee2e52114cf 100644
--- a/apps/files_encryption/lib/migration.php
+++ b/apps/files_encryption/lib/migration.php
@@ -4,7 +4,7 @@
*
* @copyright (C) 2014 ownCloud, Inc.
*
- * @author Thomas Müller <deepdiver@owncloud.com>
+ * @author Bjoern Schiessle <schiessle@owncloud.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
@@ -26,26 +26,257 @@ namespace OCA\Files_Encryption;
class Migration {
- public function __construct($tableName = 'encryption') {
- $this->tableName = $tableName;
+ /**
+ * @var \OC\Files\View
+ */
+ private $view;
+ private $public_share_key_id;
+ private $recovery_key_id;
+
+ public function __construct() {
+ $this->view = new \OC\Files\View();
+ $this->public_share_key_id = \OCA\Encryption\Helper::getPublicShareKeyId();
+ $this->recovery_key_id = \OCA\Encryption\Helper::getRecoveryKeyId();
+ }
+
+ public function reorganizeFolderStructure() {
+
+ $this->createPathForKeys('/files_encryption');
+
+ // backup system wide folders
+ $this->backupSystemWideKeys();
+
+ // rename public keys
+ $this->renamePublicKeys();
+
+ // rename system wide mount point
+ $this->renameFileKeys('', '/files_encryption/keyfiles');
+
+ // rename system private keys
+ $this->renameSystemPrivateKeys();
+
+ // delete old system wide folders
+ $this->view->deleteAll('/public-keys');
+ $this->view->deleteAll('/owncloud_private_key');
+ $this->view->deleteAll('/files_encryption/share-keys');
+ $this->view->deleteAll('/files_encryption/keyfiles');
+
+ $users = \OCP\User::getUsers();
+ foreach ($users as $user) {
+ // backup all keys
+ if ($this->backupUserKeys($user)) {
+ // create new 'key' folder
+ $this->view->mkdir($user . '/files_encryption/keys');
+ // rename users private key
+ $this->renameUsersPrivateKey($user);
+ // rename file keys
+ $path = $user . '/files_encryption/keyfiles';
+ $this->renameFileKeys($user, $path);
+ $trashPath = $user . '/files_trashbin/keyfiles';
+ if (\OC_App::isEnabled('files_trashbin') && $this->view->is_dir($trashPath)) {
+ $this->renameFileKeys($user, $trashPath, true);
+ $this->view->deleteAll($trashPath);
+ $this->view->deleteAll($user . '/files_trashbin/share-keys');
+ }
+ // delete old folders
+ $this->deleteOldKeys($user);
+ }
+ }
+ }
+
+ private function backupSystemWideKeys() {
+ $backupDir = 'encryption_migration_backup_' . date("Y-m-d_H-i-s");
+ $this->view->mkdir($backupDir);
+ $this->view->copy('owncloud_private_key', $backupDir . '/owncloud_private_key');
+ $this->view->copy('public-keys', $backupDir . '/public-keys');
+ $this->view->copy('files_encryption', $backupDir . '/files_encryption');
+ }
+
+ private function backupUserKeys($user) {
+ $encryptionDir = $user . '/files_encryption';
+ if ($this->view->is_dir($encryptionDir)) {
+ $backupDir = $user . '/encryption_migration_backup_' . date("Y-m-d_H-i-s");
+ $this->view->mkdir($backupDir);
+ $this->view->copy($encryptionDir, $backupDir);
+ return true;
+ }
+ return false;
+ }
+
+ private function renamePublicKeys() {
+ $dh = $this->view->opendir('public-keys');
+
+ $this->createPathForKeys('files_encryption/public_keys');
+
+ if (is_resource($dh)) {
+ while (($oldPublicKey = readdir($dh)) !== false) {
+ if (!\OC\Files\Filesystem::isIgnoredDir($oldPublicKey)) {
+ $newPublicKey = substr($oldPublicKey, 0, strlen($oldPublicKey) - strlen('.public.key')) . '.publicKey';
+ $this->view->rename('public-keys/' . $oldPublicKey , 'files_encryption/public_keys/' . $newPublicKey);
+ }
+ }
+ closedir($dh);
+ }
}
- // migrate settings from oc_encryption to oc_preferences
- public function dropTableEncryption() {
- $tableName = $this->tableName;
- if (!\OC_DB::tableExists($tableName)) {
- return;
+ private function renameSystemPrivateKeys() {
+ $dh = $this->view->opendir('owncloud_private_key');
+
+ if (is_resource($dh)) {
+ while (($oldPrivateKey = readdir($dh)) !== false) {
+ if (!\OC\Files\Filesystem::isIgnoredDir($oldPrivateKey)) {
+ $newPrivateKey = substr($oldPrivateKey, 0, strlen($oldPrivateKey) - strlen('.private.key')) . '.privateKey';
+ $this->view->rename('owncloud_private_key/' . $oldPrivateKey , 'files_encryption/' . $newPrivateKey);
+ }
+ }
+ closedir($dh);
}
- $sql = "select `uid`, max(`recovery_enabled`) as `recovery_enabled`, min(`migration_status`) as `migration_status` from `*PREFIX*$tableName` group by `uid`";
- $query = \OCP\DB::prepare($sql);
- $result = $query->execute(array())->fetchAll();
+ }
+
+ private function renameUsersPrivateKey($user) {
+ $oldPrivateKey = $user . '/files_encryption/' . $user . '.private.key';
+ $newPrivateKey = substr($oldPrivateKey, 0, strlen($oldPrivateKey) - strlen('.private.key')) . '.privateKey';
+
+ $this->view->rename($oldPrivateKey, $newPrivateKey);
+ }
- foreach ($result as $row) {
- \OC_Preferences::setValue($row['uid'], 'files_encryption', 'recovery_enabled', $row['recovery_enabled']);
- \OC_Preferences::setValue($row['uid'], 'files_encryption', 'migration_status', $row['migration_status']);
+ private function getFileName($file, $trash) {
+
+ $extLength = strlen('.key');
+
+ if ($trash) {
+ $parts = explode('.', $file);
+ if ($parts[count($parts) - 1] !== 'key') {
+ $extLength = $extLength + strlen('.' . $parts[count($parts) - 1]);
+ }
}
- \OC_DB::dropTable($tableName);
+ $filename = substr($file, 0, strlen($file) - $extLength);
+
+ return $filename;
}
+ private function getExtension($file, $trash) {
+
+ $extension = '';
+
+ if ($trash) {
+ $parts = explode('.', $file);
+ if ($parts[count($parts) - 1] !== 'key') {
+ $extension = '.' . $parts[count($parts) - 1];
+ }
+ }
+
+ return $extension;
+ }
+
+ private function getFilePath($path, $user, $trash) {
+ $offset = $trash ? strlen($user . '/files_trashbin/keyfiles') : strlen($user . '/files_encryption/keyfiles');
+ return substr($path, $offset);
+ }
+
+ private function getTargetDir($user, $filePath, $filename, $extension, $trash) {
+ if ($trash) {
+ $targetDir = $user . '/files_trashbin/keys/' . $filePath . '/' . $filename . $extension;
+ } else {
+ $targetDir = $user . '/files_encryption/keys/' . $filePath . '/' . $filename . $extension;
+ }
+
+ return $targetDir;
+ }
+
+ private function renameFileKeys($user, $path, $trash = false) {
+
+ $dh = $this->view->opendir($path);
+
+ if (is_resource($dh)) {
+ while (($file = readdir($dh)) !== false) {
+ if (!\OC\Files\Filesystem::isIgnoredDir($file)) {
+ if ($this->view->is_dir($path . '/' . $file)) {
+ $this->renameFileKeys($user, $path . '/' . $file, $trash);
+ } else {
+ $filename = $this->getFileName($file, $trash);
+ $filePath = $this->getFilePath($path, $user, $trash);
+ $extension = $this->getExtension($file, $trash);
+ $targetDir = $this->getTargetDir($user, $filePath, $filename, $extension, $trash);
+ $this->createPathForKeys($targetDir);
+ $this->view->copy($path . '/' . $file, $targetDir . '/fileKey');
+ $this->renameShareKeys($user, $filePath, $filename, $targetDir, $trash);
+ }
+ }
+ }
+ closedir($dh);
+ }
+ }
+
+ private function getOldShareKeyPath($user, $filePath, $trash) {
+ if ($trash) {
+ $oldShareKeyPath = $user . '/files_trashbin/share-keys/' . $filePath;
+ } else {
+ $oldShareKeyPath = $user . '/files_encryption/share-keys/' . $filePath;
+ }
+
+ return $oldShareKeyPath;
+ }
+
+ private function getUidFromShareKey($file, $filename, $trash) {
+ $extLength = strlen('.shareKey');
+ if ($trash) {
+ $parts = explode('.', $file);
+ if ($parts[count($parts) - 1] !== 'shareKey') {
+ $extLength = $extLength + strlen('.' . $parts[count($parts) - 1]);
+ }
+ }
+
+ $uid = substr($file, strlen($filename) + 1, $extLength * -1);
+
+ return $uid;
+ }
+
+ private function renameShareKeys($user, $filePath, $filename, $target, $trash) {
+ $oldShareKeyPath = $this->getOldShareKeyPath($user, $filePath, $trash);
+ $dh = $this->view->opendir($oldShareKeyPath);
+
+ if (is_resource($dh)) {
+ while (($file = readdir($dh)) !== false) {
+ if (!\OC\Files\Filesystem::isIgnoredDir($file)) {
+ if ($this->view->is_dir($oldShareKeyPath . '/' . $file)) {
+ continue;
+ } else {
+ if (substr($file, 0, strlen($filename) +1) === $filename . '.') {
+
+ $uid = $this->getUidFromShareKey($file, $filename, $trash);
+ if ($uid === $this->public_share_key_id ||
+ $uid === $this->recovery_key_id ||
+ \OCP\User::userExists($uid)) {
+ $this->view->copy($oldShareKeyPath . '/' . $file, $target . '/' . $uid . '.shareKey');
+ }
+ }
+ }
+
+ }
+ }
+ closedir($dh);
+ }
+ }
+
+ private function deleteOldKeys($user) {
+ $this->view->deleteAll($user . '/files_encryption/keyfiles');
+ $this->view->deleteAll($user . '/files_encryption/share-keys');
+ }
+
+ private function createPathForKeys($path) {
+ if (!$this->view->file_exists($path)) {
+ $sub_dirs = explode('/', $path);
+ $dir = '';
+ foreach ($sub_dirs as $sub_dir) {
+ $dir .= '/' . $sub_dir;
+ if (!$this->view->is_dir($dir)) {
+ $this->view->mkdir($dir);
+ }
+ }
+ }
+ }
+
+
}
diff --git a/apps/files_encryption/lib/session.php b/apps/files_encryption/lib/session.php
index 355264a5070..7f1e0664cdc 100644
--- a/apps/files_encryption/lib/session.php
+++ b/apps/files_encryption/lib/session.php
@@ -48,9 +48,9 @@ class Session {
$this->view = $view;
- if (!$this->view->is_dir('owncloud_private_key')) {
+ if (!$this->view->is_dir('files_encryption')) {
- $this->view->mkdir('owncloud_private_key');
+ $this->view->mkdir('files_encryption');
}
diff --git a/apps/files_encryption/lib/util.php b/apps/files_encryption/lib/util.php
index 6c1b2f60d7e..42a7e20c87f 100644
--- a/apps/files_encryption/lib/util.php
+++ b/apps/files_encryption/lib/util.php
@@ -73,7 +73,7 @@ class Util {
$this->fileFolderName = 'files';
$this->userFilesDir =
'/' . $userId . '/' . $this->fileFolderName; // TODO: Does this need to be user configurable?
- $this->publicKeyDir = '/' . 'public-keys';
+ $this->publicKeyDir = Keymanager::getPublicKeyPath();
$this->encryptionDir = '/' . $this->userId . '/' . 'files_encryption';
$this->keysPath = $this->encryptionDir . '/' . 'keys';
$this->publicKeyPath =
diff --git a/apps/files_encryption/tests/crypt.php b/apps/files_encryption/tests/crypt.php
index 46a717f851e..ab2ce066cdb 100755
--- a/apps/files_encryption/tests/crypt.php
+++ b/apps/files_encryption/tests/crypt.php
@@ -33,20 +33,6 @@ class Test_Encryption_Crypt extends \OCA\Files_Encryption\Tests\TestCase {
public static function setUpBeforeClass() {
parent::setUpBeforeClass();
- // reset backend
- \OC_User::clearBackends();
- \OC_User::useBackend('database');
-
- // Filesystem related hooks
- \OCA\Encryption\Helper::registerFilesystemHooks();
-
- // Filesystem related hooks
- \OCA\Encryption\Helper::registerUserHooks();
-
- // clear and register hooks
- \OC_FileProxy::clearProxies();
- \OC_FileProxy::register(new OCA\Encryption\Proxy());
-
// create test user
self::loginHelper(\Test_Encryption_Crypt::TEST_ENCRYPTION_CRYPT_USER1, true);
}
@@ -99,14 +85,6 @@ class Test_Encryption_Crypt extends \OCA\Files_Encryption\Tests\TestCase {
// cleanup test user
\OC_User::deleteUser(\Test_Encryption_Crypt::TEST_ENCRYPTION_CRYPT_USER1);
- \OC_Hook::clear();
- \OC_FileProxy::clearProxies();
-
- // Delete keys in /data/
- $view = new \OC\Files\View('/');
- $view->rmdir('public-keys');
- $view->rmdir('owncloud_private_key');
-
parent::tearDownAfterClass();
}
diff --git a/apps/files_encryption/tests/helper.php b/apps/files_encryption/tests/helper.php
index f0e3408b2e0..88ba9f20d53 100644
--- a/apps/files_encryption/tests/helper.php
+++ b/apps/files_encryption/tests/helper.php
@@ -38,14 +38,6 @@ class Test_Encryption_Helper extends \OCA\Files_Encryption\Tests\TestCase {
}
public static function tearDownAfterClass() {
- \OC_Hook::clear();
- \OC_FileProxy::clearProxies();
-
- // Delete keys in /data/
- $view = new \OC\Files\View('/');
- $view->rmdir('public-keys');
- $view->rmdir('owncloud_private_key');
-
parent::tearDownAfterClass();
}
diff --git a/apps/files_encryption/tests/hooks.php b/apps/files_encryption/tests/hooks.php
index fc40d4cd61f..d5a30f5074a 100644
--- a/apps/files_encryption/tests/hooks.php
+++ b/apps/files_encryption/tests/hooks.php
@@ -63,28 +63,6 @@ class Test_Encryption_Hooks extends \OCA\Files_Encryption\Tests\TestCase {
'.t est.txt'
);
- // reset backend
- \OC_User::clearBackends();
- \OC_User::useBackend('database');
-
- \OC_Hook::clear('OC_Filesystem');
- \OC_Hook::clear('OC_User');
-
- // clear share hooks
- \OC_Hook::clear('OCP\\Share');
- \OC::registerShareHooks();
- \OCP\Util::connectHook('OC_Filesystem', 'setup', '\OC\Files\Storage\Shared', 'setup');
-
- // Filesystem related hooks
- \OCA\Encryption\Helper::registerFilesystemHooks();
-
- // Sharing related hooks
- \OCA\Encryption\Helper::registerShareHooks();
-
- // clear and register proxies
- \OC_FileProxy::clearProxies();
- \OC_FileProxy::register(new OCA\Encryption\Proxy());
-
// create test user
self::loginHelper(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER1, true);
self::loginHelper(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2, true);
@@ -114,14 +92,6 @@ class Test_Encryption_Hooks extends \OCA\Files_Encryption\Tests\TestCase {
\OC_User::deleteUser(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER1);
\OC_User::deleteUser(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2);
- \OC_Hook::clear();
- \OC_FileProxy::clearProxies();
-
- // Delete keys in /data/
- $view = new \OC\Files\View('/');
- $view->rmdir('public-keys');
- $view->rmdir('owncloud_private_key');
-
parent::tearDownAfterClass();
}
@@ -439,7 +409,7 @@ class Test_Encryption_Hooks extends \OCA\Files_Encryption\Tests\TestCase {
// set user password for the first time
\OCA\Encryption\Hooks::postCreateUser(array('uid' => 'newUser', 'password' => 'newUserPassword'));
- $this->assertTrue($view->file_exists('public-keys/newUser.publicKey'));
+ $this->assertTrue($view->file_exists(\OCA\Encryption\Keymanager::getPublicKeyPath() . '/newUser.publicKey'));
$this->assertTrue($view->file_exists('newUser/files_encryption/newUser.privateKey'));
// check if we are able to decrypt the private key
diff --git a/apps/files_encryption/tests/keymanager.php b/apps/files_encryption/tests/keymanager.php
index f86f7d894ce..21f03839430 100644
--- a/apps/files_encryption/tests/keymanager.php
+++ b/apps/files_encryption/tests/keymanager.php
@@ -28,17 +28,6 @@ class Test_Encryption_Keymanager extends \OCA\Files_Encryption\Tests\TestCase {
public static function setUpBeforeClass() {
parent::setUpBeforeClass();
- // reset backend
- \OC_User::clearBackends();
- \OC_User::useBackend('database');
-
- // Filesystem related hooks
- \OCA\Encryption\Helper::registerFilesystemHooks();
-
- // clear and register hooks
- \OC_FileProxy::clearProxies();
- \OC_FileProxy::register(new OCA\Encryption\Proxy());
-
// disable file proxy by default
\OC_FileProxy::$enabled = false;
@@ -92,14 +81,6 @@ class Test_Encryption_Keymanager extends \OCA\Files_Encryption\Tests\TestCase {
OC_App::enable('files_trashbin');
}
- \OC_Hook::clear();
- \OC_FileProxy::clearProxies();
-
- // Delete keys in /data/
- $view = new \OC\Files\View('/');
- $view->rmdir('public-keys');
- $view->rmdir('owncloud_private_key');
-
parent::tearDownAfterClass();
}
@@ -192,14 +173,14 @@ class Test_Encryption_Keymanager extends \OCA\Files_Encryption\Tests\TestCase {
Encryption\Keymanager::setPrivateSystemKey($key, $keyName);
- $this->assertTrue($this->view->file_exists('/owncloud_private_key/' . $keyName . '.privateKey'));
+ $this->assertTrue($this->view->file_exists('/files_encryption/' . $keyName . '.privateKey'));
$result = Encryption\Keymanager::getPrivateSystemKey($keyName);
$this->assertSame($encHeader . $key, $result);
// clean up
- $this->view->unlink('/owncloud_private_key/' . $keyName.'.privateKey');
+ $this->view->unlink('/files_encryption/' . $keyName.'.privateKey');
}
diff --git a/apps/files_encryption/tests/migration.php b/apps/files_encryption/tests/migration.php
index 8ca2e94c90a..21c4e354c29 100644
--- a/apps/files_encryption/tests/migration.php
+++ b/apps/files_encryption/tests/migration.php
@@ -2,8 +2,9 @@
/**
* ownCloud
*
- * @author Thomas Müller
- * @copyright 2014 Thomas Müller deepdiver@owncloud.com
+ * @copyright (C) 2014 ownCloud, Inc.
+ *
+ * @author Bjoern Schiessle <schiessle@owncloud.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
@@ -23,7 +24,29 @@
use OCA\Encryption;
use OCA\Files_Encryption\Migration;
-class Test_Migration extends \Test\TestCase {
+class Test_Migration extends \OCA\Files_Encryption\Tests\TestCase {
+
+ const TEST_ENCRYPTION_MIGRATION_USER1='test_encryption_user1';
+ const TEST_ENCRYPTION_MIGRATION_USER2='test_encryption_user2';
+ const TEST_ENCRYPTION_MIGRATION_USER3='test_encryption_user3';
+
+ private $view;
+ private $public_share_key_id;
+ private $recovery_key_id;
+
+ public static function setUpBeforeClass() {
+ parent::setUpBeforeClass();
+ self::loginHelper(self::TEST_ENCRYPTION_MIGRATION_USER1, true);
+ self::loginHelper(self::TEST_ENCRYPTION_MIGRATION_USER2, true);
+ self::loginHelper(self::TEST_ENCRYPTION_MIGRATION_USER3, true);
+ }
+
+ public static function tearDownAfterClass() {
+ \OC_User::deleteUser(self::TEST_ENCRYPTION_MIGRATION_USER1);
+ \OC_User::deleteUser(self::TEST_ENCRYPTION_MIGRATION_USER2);
+ \OC_User::deleteUser(self::TEST_ENCRYPTION_MIGRATION_USER3);
+ parent::tearDownAfterClass();
+ }
protected function tearDown() {
if (OC_DB::tableExists('encryption_test')) {
@@ -34,26 +57,17 @@ class Test_Migration extends \Test\TestCase {
parent::tearDown();
}
- protected function setUp() {
- parent::setUp();
-
+ public function setUp() {
+ $this->loginHelper(self::TEST_ENCRYPTION_MIGRATION_USER1);
+ $this->view = new \OC\Files\View();
+ $this->public_share_key_id = Encryption\Helper::getPublicShareKeyId();
+ $this->recovery_key_id = Encryption\Helper::getRecoveryKeyId();
if (OC_DB::tableExists('encryption_test')) {
OC_DB::dropTable('encryption_test');
}
$this->assertTableNotExist('encryption_test');
}
- public function testEncryptionTableDoesNotExist() {
-
- $this->assertTableNotExist('encryption_test');
-
- $migration = new Migration('encryption_test');
- $migration->dropTableEncryption();
-
- $this->assertTableNotExist('encryption_test');
-
- }
-
public function checkLastIndexId() {
$query = \OC_DB::prepare('INSERT INTO `*PREFIX*share` ('
.' `item_type`, `item_source`, `item_target`, `share_type`,'
@@ -91,89 +105,160 @@ class Test_Migration extends \Test\TestCase {
$this->checkLastIndexId();
}
- public function testDataMigration() {
- // TODO travis
- if (getenv('TRAVIS')) {
- $this->markTestSkipped('Fails on travis');
+ /**
+ * @param string $table
+ */
+ public function assertTableNotExist($table) {
+ $type=OC_Config::getValue( "dbtype", "sqlite" );
+ if( $type == 'sqlite' || $type == 'sqlite3' ) {
+ // sqlite removes the tables after closing the DB
+ $this->assertTrue(true);
+ } else {
+ $this->assertFalse(OC_DB::tableExists($table), 'Table ' . $table . ' exists.');
}
-
- $this->assertTableNotExist('encryption_test');
-
- // create test table
- OC_DB::createDbFromStructure(__DIR__ . '/encryption_table.xml');
- $this->assertTableExist('encryption_test');
-
- OC_DB::executeAudited('INSERT INTO `*PREFIX*encryption_test` values(?, ?, ?, ?)',
- array('user1', 'server-side', 1, 1));
-
- // preform migration
- $migration = new Migration('encryption_test');
- $migration->dropTableEncryption();
-
- // assert
- $this->assertTableNotExist('encryption_test');
-
- $rec = \OC_Preferences::getValue('user1', 'files_encryption', 'recovery_enabled');
- $mig = \OC_Preferences::getValue('user1', 'files_encryption', 'migration_status');
-
- $this->assertEquals(1, $rec);
- $this->assertEquals(1, $mig);
}
- public function testDuplicateDataMigration() {
- // TODO travis
- if (getenv('TRAVIS')) {
- $this->markTestSkipped('Fails on travis');
+ protected function createDummyShareKeys($uid) {
+ $this->view->mkdir($uid . '/files_encryption/share-keys/folder1/folder2/folder3');
+ $this->view->mkdir($uid . '/files_encryption/share-keys/folder2/');
+ $this->view->file_put_contents($uid . '/files_encryption/share-keys/folder1/folder2/folder3/file3.' . self::TEST_ENCRYPTION_MIGRATION_USER1 . '.shareKey' , 'data');
+ $this->view->file_put_contents($uid . '/files_encryption/share-keys/folder1/folder2/folder3/file3.' . self::TEST_ENCRYPTION_MIGRATION_USER2 . '.shareKey' , 'data');
+ $this->view->file_put_contents($uid . '/files_encryption/share-keys/folder1/folder2/folder3/file3.' . self::TEST_ENCRYPTION_MIGRATION_USER3 . '.shareKey' , 'data');
+ $this->view->file_put_contents($uid . '/files_encryption/share-keys/folder1/folder2/file2.' . self::TEST_ENCRYPTION_MIGRATION_USER1 . '.shareKey' , 'data');
+ $this->view->file_put_contents($uid . '/files_encryption/share-keys/folder1/folder2/file2.' . self::TEST_ENCRYPTION_MIGRATION_USER2 . '.shareKey' , 'data');
+ $this->view->file_put_contents($uid . '/files_encryption/share-keys/folder1/folder2/file2.' . self::TEST_ENCRYPTION_MIGRATION_USER3 . '.shareKey' , 'data');
+ $this->view->file_put_contents($uid . '/files_encryption/share-keys/folder1/file.1.' . self::TEST_ENCRYPTION_MIGRATION_USER1 . '.shareKey' , 'data');
+ $this->view->file_put_contents($uid . '/files_encryption/share-keys/folder1/file.1.' . self::TEST_ENCRYPTION_MIGRATION_USER2 . '.shareKey' , 'data');
+ $this->view->file_put_contents($uid . '/files_encryption/share-keys/folder1/file.1.' . self::TEST_ENCRYPTION_MIGRATION_USER3 . '.shareKey' , 'data');
+ $this->view->file_put_contents($uid . '/files_encryption/share-keys/folder2/file.2.1.' . self::TEST_ENCRYPTION_MIGRATION_USER1 . '.shareKey' , 'data');
+ $this->view->file_put_contents($uid . '/files_encryption/share-keys/folder2/file.2.1.' . self::TEST_ENCRYPTION_MIGRATION_USER2 . '.shareKey' , 'data');
+ $this->view->file_put_contents($uid . '/files_encryption/share-keys/folder2/file.2.1.' . self::TEST_ENCRYPTION_MIGRATION_USER3 . '.shareKey' , 'data');
+ if ($this->public_share_key_id) {
+ $this->view->file_put_contents($uid . '/files_encryption/share-keys/folder2/file.2.1.' . $this->public_share_key_id . '.shareKey' , 'data');
}
-
- // create test table
- OC_DB::createDbFromStructure(__DIR__ . '/encryption_table.xml');
-
- // in case of duplicate entries we want to preserve 0 on migration status and 1 on recovery
- $data = array(
- array('user1', 'server-side', 1, 1),
- array('user1', 'server-side', 1, 0),
- array('user1', 'server-side', 0, 1),
- array('user1', 'server-side', 0, 0),
- );
- foreach ($data as $d) {
- OC_DB::executeAudited(
- 'INSERT INTO `*PREFIX*encryption_test` values(?, ?, ?, ?)',
- $d);
+ if ($this->recovery_key_id) {
+ $this->view->file_put_contents($uid . '/files_encryption/share-keys/folder2/file.2.1.' . $this->recovery_key_id . '.shareKey' , 'data');
}
+ }
- // preform migration
- $migration = new Migration('encryption_test');
- $migration->dropTableEncryption();
+ protected function createDummyFileKeys($uid) {
+ $this->view->mkdir($uid . '/files_encryption/keyfiles/folder1/folder2/folder3');
+ $this->view->mkdir($uid . '/files_encryption/keyfiles/folder2/');
+ $this->view->file_put_contents($uid . '/files_encryption/keyfiles/folder1/folder2/folder3/file3.key' , 'data');
+ $this->view->file_put_contents($uid . '/files_encryption/keyfiles/folder1/folder2/file2.key' , 'data');
+ $this->view->file_put_contents($uid . '/files_encryption/keyfiles/folder1/file.1.key' , 'data');
+ $this->view->file_put_contents($uid . '/files_encryption/keyfiles/folder2/file.2.1.key' , 'data');
+ }
- // assert
- $this->assertTableNotExist('encryption_test');
+ protected function createDummyFilesInTrash($uid) {
+ $this->view->mkdir($uid . '/files_trashbin/share-keys');
+ $this->view->mkdir($uid . '/files_trashbin/share-keys/folder1.d7437648723');
+ $this->view->file_put_contents($uid . '/files_trashbin/share-keys/file1.' . self::TEST_ENCRYPTION_MIGRATION_USER1 . '.shareKey.d5457864' , 'data');
+ $this->view->file_put_contents($uid . '/files_trashbin/share-keys/file1.' . self::TEST_ENCRYPTION_MIGRATION_USER1 . '.shareKey.d5457864' , 'data');
+ $this->view->file_put_contents($uid . '/files_trashbin/share-keys/folder1.d7437648723/file2.' . self::TEST_ENCRYPTION_MIGRATION_USER1 . '.shareKey' , 'data');
+
+ $this->view->mkdir($uid . '/files_trashbin/keyfiles');
+ $this->view->mkdir($uid . '/files_trashbin/keyfiles/folder1.d7437648723');
+ $this->view->file_put_contents($uid . '/files_trashbin/keyfiles/file1.key.d5457864' , 'data');
+ $this->view->file_put_contents($uid . '/files_trashbin/keyfiles/folder1.d7437648723/file2.key' , 'data');
+ }
+
+ protected function createDummySystemWideKeys() {
+ $this->view->mkdir('owncloud_private_key');
+ $this->view->file_put_contents('owncloud_private_key/systemwide_1.private.key', 'data');
+ $this->view->file_put_contents('owncloud_private_key/systemwide_2.private.key', 'data');
+ }
- $rec = \OC_Preferences::getValue('user1', 'files_encryption', 'recovery_enabled');
- $mig = \OC_Preferences::getValue('user1', 'files_encryption', 'migration_status');
+ public function testMigrateToNewFolderStructure() {
+
+ // go back to the state before migration
+ $this->view->rename('/files_encryption/public_keys', '/public-keys');
+ $this->view->rename('/public-keys/' . self::TEST_ENCRYPTION_MIGRATION_USER1 . '.publicKey', '/public-keys/' . self::TEST_ENCRYPTION_MIGRATION_USER1 . '.public.key');
+ $this->view->rename('/public-keys/' . self::TEST_ENCRYPTION_MIGRATION_USER2 . '.publicKey', '/public-keys/' . self::TEST_ENCRYPTION_MIGRATION_USER2 . '.public.key');
+ $this->view->rename('/public-keys/' . self::TEST_ENCRYPTION_MIGRATION_USER3 . '.publicKey', '/public-keys/' . self::TEST_ENCRYPTION_MIGRATION_USER3 . '.public.key');
+ $this->view->deleteAll(self::TEST_ENCRYPTION_MIGRATION_USER1 . '/files_encryption/keys');
+ $this->view->deleteAll(self::TEST_ENCRYPTION_MIGRATION_USER2 . '/files_encryption/keys');
+ $this->view->deleteAll(self::TEST_ENCRYPTION_MIGRATION_USER3 . '/files_encryption/keys');
+ $this->view->rename(self::TEST_ENCRYPTION_MIGRATION_USER1 . '/files_encryption/' . self::TEST_ENCRYPTION_MIGRATION_USER1 . '.privateKey',
+ self::TEST_ENCRYPTION_MIGRATION_USER1 . '/files_encryption/' . self::TEST_ENCRYPTION_MIGRATION_USER1 . '.private.key');
+ $this->view->rename(self::TEST_ENCRYPTION_MIGRATION_USER2 . '/files_encryption/' . self::TEST_ENCRYPTION_MIGRATION_USER1 . '.privateKey',
+ self::TEST_ENCRYPTION_MIGRATION_USER2 . '/files_encryption/' . self::TEST_ENCRYPTION_MIGRATION_USER1 . '.private.key');
+ $this->view->rename(self::TEST_ENCRYPTION_MIGRATION_USER3 . '/files_encryption/' . self::TEST_ENCRYPTION_MIGRATION_USER1 . '.privateKey',
+ self::TEST_ENCRYPTION_MIGRATION_USER3 . '/files_encryption/' . self::TEST_ENCRYPTION_MIGRATION_USER1 . '.private.key');
+
+ $this->createDummyShareKeys(self::TEST_ENCRYPTION_MIGRATION_USER1);
+ $this->createDummyShareKeys(self::TEST_ENCRYPTION_MIGRATION_USER2);
+ $this->createDummyShareKeys(self::TEST_ENCRYPTION_MIGRATION_USER3);
+
+ $this->createDummyFileKeys(self::TEST_ENCRYPTION_MIGRATION_USER1);
+ $this->createDummyFileKeys(self::TEST_ENCRYPTION_MIGRATION_USER2);
+ $this->createDummyFileKeys(self::TEST_ENCRYPTION_MIGRATION_USER3);
+
+ $this->createDummyFilesInTrash(self::TEST_ENCRYPTION_MIGRATION_USER2);
+
+ // no user for system wide mount points
+ $this->createDummyFileKeys('');
+ $this->createDummyShareKeys('');
+
+ $this->createDummySystemWideKeys();
+
+ $m = new \OCA\Files_Encryption\Migration();
+ $m->reorganizeFolderStructure();
+
+ // TODO Verify that all files at the right place
+ $this->assertTrue($this->view->file_exists('/files_encryption/public_keys/' . self::TEST_ENCRYPTION_MIGRATION_USER1 . '.publicKey'));
+ $this->assertTrue($this->view->file_exists('/files_encryption/public_keys/' . self::TEST_ENCRYPTION_MIGRATION_USER2 . '.publicKey'));
+ $this->assertTrue($this->view->file_exists('/files_encryption/public_keys/' . self::TEST_ENCRYPTION_MIGRATION_USER3 . '.publicKey'));
+ $this->verifyNewKeyPath(self::TEST_ENCRYPTION_MIGRATION_USER1);
+ $this->verifyNewKeyPath(self::TEST_ENCRYPTION_MIGRATION_USER2);
+ $this->verifyNewKeyPath(self::TEST_ENCRYPTION_MIGRATION_USER3);
+ // system wide keys
+ $this->verifyNewKeyPath('');
+ // trash
+ $this->verifyFilesInTrash(self::TEST_ENCRYPTION_MIGRATION_USER2);
- $this->assertEquals(1, $rec);
- $this->assertEquals(0, $mig);
}
- /**
- * @param string $table
- */
- public function assertTableExist($table) {
- $this->assertTrue(OC_DB::tableExists($table), 'Table ' . $table . ' does not exist');
+ protected function verifyFilesInTrash($uid) {
+ // share keys
+ $this->view->file_exists($uid . '/files_trashbin/keys/file1.d5457864/' . self::TEST_ENCRYPTION_MIGRATION_USER1 . '.shareKey.d5457864' , 'data');
+ $this->view->file_exists($uid . '/files_trashbin/keys/file1.d5457864/' . self::TEST_ENCRYPTION_MIGRATION_USER1 . '.shareKey.d5457864' , 'data');
+ $this->view->file_exists($uid . '/files_trashbin/keys/folder1.d7437648723/file2/' . self::TEST_ENCRYPTION_MIGRATION_USER1 . '.shareKey' , 'data');
+
+ // file keys
+ $this->view->file_exists($uid . '/files_trashbin/keys/file1.d5457864/fileKey.d5457864' , 'data');
+ $this->view->file_exists($uid . '/files_trashbin/keyfiles/file1.d5457864/fileKey.d5457864' , 'data');
+ $this->view->file_exists($uid . '/files_trashbin/keyfiles/folder1.d7437648723/file2/fileKey' , 'data');
}
- /**
- * @param string $table
- */
- public function assertTableNotExist($table) {
- $type=OC_Config::getValue( "dbtype", "sqlite" );
- if( $type == 'sqlite' || $type == 'sqlite3' ) {
- // sqlite removes the tables after closing the DB
- $this->assertTrue(true);
- } else {
- $this->assertFalse(OC_DB::tableExists($table), 'Table ' . $table . ' exists.');
+ protected function verifyNewKeyPath($uid) {
+ // private key
+ if ($uid !== '') {
+ $this->assertTrue($this->view->file_exists($uid . '/files_encryption/' . $uid . '.privateKey'));
+ }
+ // file keys
+ $this->assertTrue($this->view->file_exists($uid . '/files_encryption/keys/folder1/folder2/folder3/file3/fileKey'));
+ $this->assertTrue($this->view->file_exists($uid . '/files_encryption/keys/folder1/folder2/file2/fileKey'));
+ $this->assertTrue($this->view->file_exists($uid . '/files_encryption/keys/folder1/file.1/fileKey'));
+ $this->assertTrue($this->view->file_exists($uid . '/files_encryption/keys/folder2/file.2.1/fileKey'));
+ // share keys
+ $this->assertTrue($this->view->file_exists($uid . '/files_encryption/keys/folder1/folder2/folder3/file3/' . self::TEST_ENCRYPTION_MIGRATION_USER1 . '.shareKey'));
+ $this->assertTrue($this->view->file_exists($uid . '/files_encryption/keys/folder1/folder2/folder3/file3/' . self::TEST_ENCRYPTION_MIGRATION_USER2 . '.shareKey'));
+ $this->assertTrue($this->view->file_exists($uid . '/files_encryption/keys/folder1/folder2/folder3/file3/' . self::TEST_ENCRYPTION_MIGRATION_USER3 . '.shareKey'));
+ $this->assertTrue($this->view->file_exists($uid . '/files_encryption/keys/folder1/folder2/file2/' . self::TEST_ENCRYPTION_MIGRATION_USER1 . '.shareKey'));
+ $this->assertTrue($this->view->file_exists($uid . '/files_encryption/keys/folder1/folder2/file2/' . self::TEST_ENCRYPTION_MIGRATION_USER2 . '.shareKey'));
+ $this->assertTrue($this->view->file_exists($uid . '/files_encryption/keys/folder1/folder2/file2/' . self::TEST_ENCRYPTION_MIGRATION_USER3 . '.shareKey'));
+ $this->assertTrue($this->view->file_exists($uid . '/files_encryption/keys/folder1/file.1/' . self::TEST_ENCRYPTION_MIGRATION_USER1 . '.shareKey'));
+ $this->assertTrue($this->view->file_exists($uid . '/files_encryption/keys/folder1/file.1/' . self::TEST_ENCRYPTION_MIGRATION_USER2 . '.shareKey'));
+ $this->assertTrue($this->view->file_exists($uid . '/files_encryption/keys/folder1/file.1/' . self::TEST_ENCRYPTION_MIGRATION_USER3 . '.shareKey'));
+ $this->assertTrue($this->view->file_exists($uid . '/files_encryption/keys/folder2/file.2.1/' . self::TEST_ENCRYPTION_MIGRATION_USER1 . '.shareKey'));
+ $this->assertTrue($this->view->file_exists($uid . '/files_encryption/keys/folder2/file.2.1/' . self::TEST_ENCRYPTION_MIGRATION_USER2 . '.shareKey'));
+ $this->assertTrue($this->view->file_exists($uid . '/files_encryption/keys/folder2/file.2.1/' . self::TEST_ENCRYPTION_MIGRATION_USER3 . '.shareKey'));
+ if ($this->public_share_key_id) {
+ $this->assertTrue($this->view->file_exists($uid . '/files_encryption/keys/folder2/file.2.1/' . $this->public_share_key_id . '.shareKey'));
+ }
+ if ($this->recovery_key_id) {
+ $this->assertTrue($this->view->file_exists($uid . '/files_encryption/keys/folder2/file.2.1/' . $this->recovery_key_id . '.shareKey'));
}
}
-
}
diff --git a/apps/files_encryption/tests/proxy.php b/apps/files_encryption/tests/proxy.php
index a91222327f1..72a9a9a5551 100644
--- a/apps/files_encryption/tests/proxy.php
+++ b/apps/files_encryption/tests/proxy.php
@@ -44,20 +44,6 @@ class Test_Encryption_Proxy extends \OCA\Files_Encryption\Tests\TestCase {
public static function setUpBeforeClass() {
parent::setUpBeforeClass();
- // reset backend
- \OC_User::clearBackends();
- \OC_User::useBackend('database');
-
- \OC_Hook::clear('OC_Filesystem');
- \OC_Hook::clear('OC_User');
-
- // Filesystem related hooks
- \OCA\Encryption\Helper::registerFilesystemHooks();
-
- // clear and register hooks
- \OC_FileProxy::clearProxies();
- \OC_FileProxy::register(new OCA\Encryption\Proxy());
-
// create test user
self::loginHelper(\Test_Encryption_Proxy::TEST_ENCRYPTION_PROXY_USER1, true);
}
@@ -85,14 +71,6 @@ class Test_Encryption_Proxy extends \OCA\Files_Encryption\Tests\TestCase {
// cleanup test user
\OC_User::deleteUser(\Test_Encryption_Proxy::TEST_ENCRYPTION_PROXY_USER1);
- \OC_Hook::clear();
- \OC_FileProxy::clearProxies();
-
- // Delete keys in /data/
- $view = new \OC\Files\View('/');
- $view->rmdir('public-keys');
- $view->rmdir('owncloud_private_key');
-
parent::tearDownAfterClass();
}
diff --git a/apps/files_encryption/tests/share.php b/apps/files_encryption/tests/share.php
index d7afc9e2da7..f827017569f 100755
--- a/apps/files_encryption/tests/share.php
+++ b/apps/files_encryption/tests/share.php
@@ -47,30 +47,15 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase {
public static function setUpBeforeClass() {
parent::setUpBeforeClass();
- // reset backend
- \OC_User::clearBackends();
- \OC_User::useBackend('database');
-
// enable resharing
\OC::$server->getAppConfig()->setValue('core', 'shareapi_allow_resharing', 'yes');
- // clear share hooks
- \OC_Hook::clear('OCP\\Share');
-
// register share hooks
\OC::registerShareHooks();
\OCA\Files_Sharing\Helper::registerHooks();
- // Sharing related hooks
- \OCA\Encryption\Helper::registerShareHooks();
-
- // Filesystem related hooks
- \OCA\Encryption\Helper::registerFilesystemHooks();
-
// clear and register hooks
- \OC_FileProxy::clearProxies();
\OC_FileProxy::register(new OCA\Files\Share\Proxy());
- \OC_FileProxy::register(new OCA\Encryption\Proxy());
// create users
self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1, true);
@@ -127,14 +112,6 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase {
\OC_User::deleteUser(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3);
\OC_User::deleteUser(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER4);
- \OC_Hook::clear();
- \OC_FileProxy::clearProxies();
-
- // Delete keys in /data/
- $view = new \OC\Files\View('/');
- $view->rmdir('public-keys');
- $view->rmdir('owncloud_private_key');
-
parent::tearDownAfterClass();
}
@@ -915,8 +892,8 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase {
$this->assertGreaterThan(0, $fileInfo['unencrypted_size']);
// break users public key
- $this->view->rename('/public-keys/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '.publicKey',
- '/public-keys/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '.publicKey_backup');
+ $this->view->rename(\OCA\Encryption\Keymanager::getPublicKeyPath() . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '.publicKey',
+ \OCA\Encryption\Keymanager::getPublicKeyPath() . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '.publicKey_backup');
// re-enable the file proxy
\OC_FileProxy::$enabled = $proxyStatus;
@@ -943,8 +920,8 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase {
// break user1 public key
$this->view->rename(
- '/public-keys/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '.publicKey_backup',
- '/public-keys/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '.publicKey');
+ \OCA\Encryption\Keymanager::getPublicKeyPath() . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '.publicKey_backup',
+ \OCA\Encryption\Keymanager::getPublicKeyPath() . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '.publicKey');
// remove share file
$this->view->unlink('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/'
diff --git a/apps/files_encryption/tests/stream.php b/apps/files_encryption/tests/stream.php
index b1404ca282a..f4824935ca0 100644
--- a/apps/files_encryption/tests/stream.php
+++ b/apps/files_encryption/tests/stream.php
@@ -42,17 +42,6 @@ class Test_Encryption_Stream extends \OCA\Files_Encryption\Tests\TestCase {
public static function setUpBeforeClass() {
parent::setUpBeforeClass();
- // reset backend
- \OC_User::clearBackends();
- \OC_User::useBackend('database');
-
- // Filesystem related hooks
- \OCA\Encryption\Helper::registerFilesystemHooks();
-
- // clear and register hooks
- \OC_FileProxy::clearProxies();
- \OC_FileProxy::register(new OCA\Encryption\Proxy());
-
// create test user
self::loginHelper(\Test_Encryption_Stream::TEST_ENCRYPTION_STREAM_USER1, true);
}
@@ -94,14 +83,6 @@ class Test_Encryption_Stream extends \OCA\Files_Encryption\Tests\TestCase {
// cleanup test user
\OC_User::deleteUser(\Test_Encryption_Stream::TEST_ENCRYPTION_STREAM_USER1);
- \OC_Hook::clear();
- \OC_FileProxy::clearProxies();
-
- // Delete keys in /data/
- $view = new \OC\Files\View('/');
- $view->rmdir('public-keys');
- $view->rmdir('owncloud_private_key');
-
parent::tearDownAfterClass();
}
diff --git a/apps/files_encryption/tests/testcase.php b/apps/files_encryption/tests/testcase.php
index 3106aeda8ea..743a876ab45 100644
--- a/apps/files_encryption/tests/testcase.php
+++ b/apps/files_encryption/tests/testcase.php
@@ -14,6 +14,7 @@ use OCA\Encryption;
* Class Test_Encryption_TestCase
*/
abstract class TestCase extends \Test\TestCase {
+
/**
* @param string $user
* @param bool $create
@@ -50,4 +51,34 @@ abstract class TestCase extends \Test\TestCase {
\OC_User::setUserId(false);
\OC\Files\Filesystem::tearDown();
}
+
+ public static function setUpBeforeClass() {
+ parent::setUpBeforeClass();
+
+ // reset backend
+ \OC_User::clearBackends();
+ \OC_User::useBackend('database');
+
+ \OCA\Encryption\Helper::registerFilesystemHooks();
+ \OCA\Encryption\Helper::registerUserHooks();
+ \OCA\Encryption\Helper::registerShareHooks();
+
+ \OC::registerShareHooks();
+ \OCP\Util::connectHook('OC_Filesystem', 'setup', '\OC\Files\Storage\Shared', 'setup');
+
+ // clear and register hooks
+ \OC_FileProxy::clearProxies();
+ \OC_FileProxy::register(new \OCA\Encryption\Proxy());
+ }
+
+ public static function tearDownAfterClass() {
+ \OC_Hook::clear();
+ \OC_FileProxy::clearProxies();
+
+ // Delete keys in /data/
+ $view = new \OC\Files\View('/');
+ $view->deleteAll('files_encryption');
+
+ parent::tearDownAfterClass();
+ }
}
diff --git a/apps/files_encryption/tests/trashbin.php b/apps/files_encryption/tests/trashbin.php
index 229fd084807..de5b8bd6edb 100755
--- a/apps/files_encryption/tests/trashbin.php
+++ b/apps/files_encryption/tests/trashbin.php
@@ -45,23 +45,9 @@ class Test_Encryption_Trashbin extends \OCA\Files_Encryption\Tests\TestCase {
public static function setUpBeforeClass() {
parent::setUpBeforeClass();
- // reset backend
- \OC_User::clearBackends();
- \OC_User::useBackend('database');
-
- \OC_Hook::clear('OC_Filesystem');
- \OC_Hook::clear('OC_User');
-
// trashbin hooks
\OCA\Files_Trashbin\Trashbin::registerHooks();
- // Filesystem related hooks
- \OCA\Encryption\Helper::registerFilesystemHooks();
-
- // clear and register hooks
- \OC_FileProxy::clearProxies();
- \OC_FileProxy::register(new OCA\Encryption\Proxy());
-
// create test user
self::loginHelper(self::TEST_ENCRYPTION_TRASHBIN_USER1, true);
}
@@ -107,14 +93,6 @@ class Test_Encryption_Trashbin extends \OCA\Files_Encryption\Tests\TestCase {
// cleanup test user
\OC_User::deleteUser(self::TEST_ENCRYPTION_TRASHBIN_USER1);
- \OC_Hook::clear();
- \OC_FileProxy::clearProxies();
-
- // Delete keys in /data/
- $view = new \OC\Files\View('/');
- $view->rmdir('public-keys');
- $view->rmdir('owncloud_private_key');
-
parent::tearDownAfterClass();
}
diff --git a/apps/files_encryption/tests/util.php b/apps/files_encryption/tests/util.php
index 96e8fcd81fe..8d9aba423cd 100755
--- a/apps/files_encryption/tests/util.php
+++ b/apps/files_encryption/tests/util.php
@@ -43,12 +43,6 @@ class Test_Encryption_Util extends \OCA\Files_Encryption\Tests\TestCase {
public static function setUpBeforeClass() {
parent::setUpBeforeClass();
- // reset backend
- \OC_User::clearBackends();
- \OC_User::useBackend('database');
-
- self::setupHooks();
-
// create test user
self::loginHelper(self::TEST_ENCRYPTION_UTIL_USER1, true);
self::loginHelper(self::TEST_ENCRYPTION_UTIL_USER2, true);
@@ -85,7 +79,7 @@ class Test_Encryption_Util extends \OCA\Files_Encryption\Tests\TestCase {
$this->genPublicKey = $keypair['publicKey'];
$this->genPrivateKey = $keypair['privateKey'];
- $this->publicKeyDir = '/' . 'public-keys';
+ $this->publicKeyDir = \OCA\Encryption\Keymanager::getPublicKeyPath();
$this->encryptionDir = '/' . $this->userId . '/' . 'files_encryption';
$this->keysPath = $this->encryptionDir . '/' . 'keys';
$this->publicKeyPath =
@@ -126,26 +120,9 @@ class Test_Encryption_Util extends \OCA\Files_Encryption\Tests\TestCase {
\OC_Group::deleteGroup(self::TEST_ENCRYPTION_UTIL_GROUP1);
\OC_Group::deleteGroup(self::TEST_ENCRYPTION_UTIL_GROUP2);
- \OC_Hook::clear();
- \OC_FileProxy::clearProxies();
-
- // Delete keys in /data/
- $view = new \OC\Files\View('/');
- $view->rmdir('public-keys');
- $view->rmdir('owncloud_private_key');
-
parent::tearDownAfterClass();
}
- public static function setupHooks() {
- // Filesystem related hooks
- \OCA\Encryption\Helper::registerFilesystemHooks();
-
- // clear and register hooks
- \OC_FileProxy::clearProxies();
- \OC_FileProxy::register(new OCA\Encryption\Proxy());
- }
-
/**
* @medium
* test that paths set during User construction are correct
diff --git a/apps/files_encryption/tests/webdav.php b/apps/files_encryption/tests/webdav.php
index d0caf08b2df..a04a7621291 100755
--- a/apps/files_encryption/tests/webdav.php
+++ b/apps/files_encryption/tests/webdav.php
@@ -45,20 +45,6 @@ class Test_Encryption_Webdav extends \OCA\Files_Encryption\Tests\TestCase {
public static function setUpBeforeClass() {
parent::setUpBeforeClass();
- // reset backend
- \OC_User::clearBackends();
- \OC_User::useBackend('database');
-
- // Filesystem related hooks
- \OCA\Encryption\Helper::registerFilesystemHooks();
-
- // Filesystem related hooks
- \OCA\Encryption\Helper::registerUserHooks();
-
- // clear and register hooks
- \OC_FileProxy::clearProxies();
- \OC_FileProxy::register(new OCA\Encryption\Proxy());
-
// create test user
self::loginHelper(\Test_Encryption_Webdav::TEST_ENCRYPTION_WEBDAV_USER1, true);
@@ -106,14 +92,6 @@ class Test_Encryption_Webdav extends \OCA\Files_Encryption\Tests\TestCase {
// cleanup test user
\OC_User::deleteUser(\Test_Encryption_Webdav::TEST_ENCRYPTION_WEBDAV_USER1);
- \OC_Hook::clear();
- \OC_FileProxy::clearProxies();
-
- // Delete keys in /data/
- $view = new \OC\Files\View('/');
- $view->rmdir('public-keys');
- $view->rmdir('owncloud_private_key');
-
parent::tearDownAfterClass();
}