From 7f7006643f7e659c86b81720dd50b33dbbb07430 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 3 Dec 2014 10:57:16 +0100 Subject: [PATCH 1/5] Fix namespace of files_encryption classes and autoload them --- apps/files_encryption/appinfo/app.php | 15 --------------- ...ptionException.php => encryptionexception.php} | 2 +- ...Exception.php => multikeydecryptexception.php} | 2 +- ...Exception.php => multikeyencryptexception.php} | 2 +- apps/files_encryption/lib/capabilities.php | 2 +- apps/files_encryption/lib/crypt.php | 2 +- apps/files_encryption/lib/helper.php | 2 +- apps/files_encryption/{hooks => lib}/hooks.php | 2 +- apps/files_encryption/lib/keymanager.php | 2 +- apps/files_encryption/lib/proxy.php | 2 +- apps/files_encryption/lib/session.php | 2 +- apps/files_encryption/lib/stream.php | 2 +- apps/files_encryption/lib/util.php | 2 +- 13 files changed, 12 insertions(+), 27 deletions(-) rename apps/files_encryption/exception/{encryptionException.php => encryptionexception.php} (97%) rename apps/files_encryption/exception/{multiKeyDecryptException.php => multikeydecryptexception.php} (95%) rename apps/files_encryption/exception/{multiKeyEncryptException.php => multikeyencryptexception.php} (95%) rename apps/files_encryption/{hooks => lib}/hooks.php (96%) diff --git a/apps/files_encryption/appinfo/app.php b/apps/files_encryption/appinfo/app.php index 8bf422a612..7e7e6a5c85 100644 --- a/apps/files_encryption/appinfo/app.php +++ b/apps/files_encryption/appinfo/app.php @@ -1,20 +1,5 @@ Date: Wed, 3 Dec 2014 16:16:09 +0100 Subject: [PATCH 2/5] Fix namespace of Files_Encryption outside of the app --- apps/files/index.php | 2 +- apps/files_trashbin/lib/trashbin.php | 4 ++-- lib/private/connector/sabre/file.php | 4 ++-- settings/ajax/decryptall.php | 2 +- settings/changepassword/controller.php | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/apps/files/index.php b/apps/files/index.php index 4142a02b97..6635d70d00 100644 --- a/apps/files/index.php +++ b/apps/files/index.php @@ -69,7 +69,7 @@ $storageInfo=OC_Helper::getStorageInfo('/', $dirInfo); // if the encryption app is disabled, than everything is fine (INIT_SUCCESSFUL status code) $encryptionInitStatus = 2; if (OC_App::isEnabled('files_encryption')) { - $session = new \OCA\Encryption\Session(new \OC\Files\View('/')); + $session = new \OCA\Files_Encryption\Session(new \OC\Files\View('/')); $encryptionInitStatus = $session->getInitialized(); } diff --git a/apps/files_trashbin/lib/trashbin.php b/apps/files_trashbin/lib/trashbin.php index b9d7a4aa6c..1e8f31dbd2 100644 --- a/apps/files_trashbin/lib/trashbin.php +++ b/apps/files_trashbin/lib/trashbin.php @@ -274,7 +274,7 @@ class Trashbin { return 0; } - $util = new \OCA\Encryption\Util($rootView, $user); + $util = new \OCA\Files_Encryption\Util($rootView, $user); $baseDir = '/files_encryption/'; if (!$util->isSystemWideMountPoint($ownerPath)) { @@ -448,7 +448,7 @@ class Trashbin { return false; } - $util = new \OCA\Encryption\Util($rootView, $user); + $util = new \OCA\Files_Encryption\Util($rootView, $user); $baseDir = '/files_encryption/'; if (!$util->isSystemWideMountPoint($ownerPath)) { diff --git a/lib/private/connector/sabre/file.php b/lib/private/connector/sabre/file.php index d93b8e68eb..54eea54552 100644 --- a/lib/private/connector/sabre/file.php +++ b/lib/private/connector/sabre/file.php @@ -104,7 +104,7 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements \Sabre\ } catch (\OCP\Files\LockNotAcquiredException $e) { // the file is currently being written to by another process throw new OC_Connector_Sabre_Exception_FileLocked($e->getMessage(), $e->getCode(), $e); - } catch (\OCA\Encryption\Exception\EncryptionException $e) { + } catch (\OCA\Files_Encryption\Exception\EncryptionException $e) { throw new \Sabre\DAV\Exception\Forbidden($e->getMessage()); } catch (\OCP\Files\StorageNotAvailableException $e) { throw new \Sabre\DAV\Exception\ServiceUnavailable($e->getMessage()); @@ -166,7 +166,7 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements \Sabre\ } else { try { return $this->fileView->fopen(ltrim($this->path, '/'), 'rb'); - } catch (\OCA\Encryption\Exception\EncryptionException $e) { + } catch (\OCA\Files_Encryption\Exception\EncryptionException $e) { throw new \Sabre\DAV\Exception\Forbidden($e->getMessage()); } catch (\OCP\Files\StorageNotAvailableException $e) { throw new \Sabre\DAV\Exception\ServiceUnavailable($e->getMessage()); diff --git a/settings/ajax/decryptall.php b/settings/ajax/decryptall.php index 527e5b8fce..0ad2592746 100644 --- a/settings/ajax/decryptall.php +++ b/settings/ajax/decryptall.php @@ -11,7 +11,7 @@ $params = array('uid' => \OCP\User::getUser(), 'password' => $_POST['password']); $view = new OC\Files\View('/'); -$util = new \OCA\Encryption\Util($view, \OCP\User::getUser()); +$util = new \OCA\Files_Encryption\Util($view, \OCP\User::getUser()); $l = \OC::$server->getL10N('settings'); $result = $util->initEncryption($params); diff --git a/settings/changepassword/controller.php b/settings/changepassword/controller.php index ee596c3e7e..4ed907daf9 100644 --- a/settings/changepassword/controller.php +++ b/settings/changepassword/controller.php @@ -52,7 +52,7 @@ class Controller { if (\OC_App::isEnabled('files_encryption')) { //handle the recovery case - $util = new \OCA\Encryption\Util(new \OC\Files\View('/'), $username); + $util = new \OCA\Files_Encryption\Util(new \OC\Files\View('/'), $username); $recoveryAdminEnabled = \OC_Appconfig::getValue('files_encryption', 'recoveryAdminEnabled'); $validRecoveryPassword = false; From efac8ced90879f34919eb55055423523b146d33e Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 3 Dec 2014 16:52:44 +0100 Subject: [PATCH 3/5] Update OCA\Encryption to OCA\Files_Encryption in the encryption app itself --- apps/files_encryption/ajax/adminrecovery.php | 7 ++- .../ajax/changeRecoveryPassword.php | 14 ++--- .../ajax/getMigrationStatus.php | 3 +- .../ajax/updatePrivateKeyPassword.php | 16 +++-- apps/files_encryption/ajax/userrecovery.php | 4 +- apps/files_encryption/appinfo/app.php | 12 ++-- apps/files_encryption/appinfo/routes.php | 2 +- apps/files_encryption/files/error.php | 8 +-- apps/files_encryption/lib/crypt.php | 10 +-- apps/files_encryption/lib/helper.php | 62 +++++++++---------- apps/files_encryption/lib/hooks.php | 18 +++--- apps/files_encryption/lib/keymanager.php | 15 +++-- apps/files_encryption/lib/migration.php | 4 +- apps/files_encryption/lib/proxy.php | 6 +- apps/files_encryption/lib/session.php | 10 +-- apps/files_encryption/lib/stream.php | 23 +++---- apps/files_encryption/lib/util.php | 20 +++--- apps/files_encryption/settings-admin.php | 2 +- apps/files_encryption/settings-personal.php | 4 +- .../templates/invalid_private_key.php | 2 +- .../templates/settings-admin.php | 2 +- .../templates/settings-personal.php | 6 +- apps/files_encryption/tests/crypt.php | 42 ++++++------- apps/files_encryption/tests/helper.php | 36 +++++------ apps/files_encryption/tests/hooks.php | 28 +++++---- apps/files_encryption/tests/keymanager.php | 42 +++++++------ apps/files_encryption/tests/migration.php | 7 +-- apps/files_encryption/tests/proxy.php | 4 +- apps/files_encryption/tests/share.php | 31 +++++----- apps/files_encryption/tests/stream.php | 4 +- apps/files_encryption/tests/testcase.php | 12 ++-- apps/files_encryption/tests/trashbin.php | 2 - apps/files_encryption/tests/util.php | 38 ++++++------ apps/files_encryption/tests/webdav.php | 4 +- 34 files changed, 248 insertions(+), 252 deletions(-) diff --git a/apps/files_encryption/ajax/adminrecovery.php b/apps/files_encryption/ajax/adminrecovery.php index 684fd51ae1..503c15b53a 100644 --- a/apps/files_encryption/ajax/adminrecovery.php +++ b/apps/files_encryption/ajax/adminrecovery.php @@ -7,7 +7,8 @@ * * Script to handle admin settings for encrypted key recovery */ -use OCA\Encryption; + +use OCA\Files_Encryption\Helper; \OCP\JSON::checkAdminUser(); \OCP\JSON::checkAppEnabled('files_encryption'); @@ -42,7 +43,7 @@ $recoveryKeyId = \OC::$server->getAppConfig()->getValue('files_encryption', 'rec if (isset($_POST['adminEnableRecovery']) && $_POST['adminEnableRecovery'] === '1') { - $return = \OCA\Encryption\Helper::adminEnableRecovery($recoveryKeyId, $_POST['recoveryPassword']); + $return = Helper::adminEnableRecovery($recoveryKeyId, $_POST['recoveryPassword']); // Return success or failure if ($return) { @@ -56,7 +57,7 @@ if (isset($_POST['adminEnableRecovery']) && $_POST['adminEnableRecovery'] === '1 isset($_POST['adminEnableRecovery']) && '0' === $_POST['adminEnableRecovery'] ) { - $return = \OCA\Encryption\Helper::adminDisableRecovery($_POST['recoveryPassword']); + $return = Helper::adminDisableRecovery($_POST['recoveryPassword']); if ($return) { $successMessage = $l->t('Recovery key successfully disabled'); diff --git a/apps/files_encryption/ajax/changeRecoveryPassword.php b/apps/files_encryption/ajax/changeRecoveryPassword.php index 01b76a969b..3d31b12af7 100644 --- a/apps/files_encryption/ajax/changeRecoveryPassword.php +++ b/apps/files_encryption/ajax/changeRecoveryPassword.php @@ -9,8 +9,6 @@ * */ -use OCA\Encryption; - \OCP\JSON::checkAdminUser(); \OCP\JSON::checkAppEnabled('files_encryption'); \OCP\JSON::callCheck(); @@ -49,21 +47,21 @@ if ($_POST['newPassword'] !== $_POST['confirmPassword']) { } $view = new \OC\Files\View('/'); -$util = new \OCA\Encryption\Util(new \OC\Files\View('/'), \OCP\User::getUser()); +$util = new \OCA\Files_Encryption\Util(new \OC\Files\View('/'), \OCP\User::getUser()); $proxyStatus = \OC_FileProxy::$enabled; \OC_FileProxy::$enabled = false; $keyId = $util->getRecoveryKeyId(); -$encryptedRecoveryKey = Encryption\Keymanager::getPrivateSystemKey($keyId); -$decryptedRecoveryKey = $encryptedRecoveryKey ? \OCA\Encryption\Crypt::decryptPrivateKey($encryptedRecoveryKey, $oldPassword) : false; +$encryptedRecoveryKey = \OCA\Files_Encryption\Keymanager::getPrivateSystemKey($keyId); +$decryptedRecoveryKey = $encryptedRecoveryKey ? \OCA\Files_Encryption\Crypt::decryptPrivateKey($encryptedRecoveryKey, $oldPassword) : false; if ($decryptedRecoveryKey) { - $cipher = \OCA\Encryption\Helper::getCipher(); - $encryptedKey = \OCA\Encryption\Crypt::symmetricEncryptFileContent($decryptedRecoveryKey, $newPassword, $cipher); + $cipher = \OCA\Files_Encryption\Helper::getCipher(); + $encryptedKey = \OCA\Files_Encryption\Crypt::symmetricEncryptFileContent($decryptedRecoveryKey, $newPassword, $cipher); if ($encryptedKey) { - \OCA\Encryption\Keymanager::setPrivateSystemKey($encryptedKey, $keyId); + \OCA\Files_Encryption\Keymanager::setPrivateSystemKey($encryptedKey, $keyId); $return = true; } } diff --git a/apps/files_encryption/ajax/getMigrationStatus.php b/apps/files_encryption/ajax/getMigrationStatus.php index adceb94904..bb260199b1 100644 --- a/apps/files_encryption/ajax/getMigrationStatus.php +++ b/apps/files_encryption/ajax/getMigrationStatus.php @@ -6,7 +6,8 @@ * * check migration status */ -use OCA\Encryption\Util; + +use OCA\Files_Encryption\Util; \OCP\JSON::checkAppEnabled('files_encryption'); diff --git a/apps/files_encryption/ajax/updatePrivateKeyPassword.php b/apps/files_encryption/ajax/updatePrivateKeyPassword.php index 97da3811a0..7161b0cff9 100644 --- a/apps/files_encryption/ajax/updatePrivateKeyPassword.php +++ b/apps/files_encryption/ajax/updatePrivateKeyPassword.php @@ -9,8 +9,6 @@ * */ -use OCA\Encryption; - \OCP\JSON::checkLoggedIn(); \OCP\JSON::checkAppEnabled('files_encryption'); \OCP\JSON::callCheck(); @@ -24,7 +22,7 @@ $oldPassword = $_POST['oldPassword']; $newPassword = $_POST['newPassword']; $view = new \OC\Files\View('/'); -$session = new \OCA\Encryption\Session($view); +$session = new \OCA\Files_Encryption\Session($view); $user = \OCP\User::getUser(); $loginName = \OC::$server->getUserSession()->getLoginName(); @@ -36,14 +34,14 @@ if ($passwordCorrect !== false) { $proxyStatus = \OC_FileProxy::$enabled; \OC_FileProxy::$enabled = false; -$encryptedKey = Encryption\Keymanager::getPrivateKey($view, $user); -$decryptedKey = $encryptedKey ? \OCA\Encryption\Crypt::decryptPrivateKey($encryptedKey, $oldPassword) : false; +$encryptedKey = \OCA\Files_Encryption\Keymanager::getPrivateKey($view, $user); +$decryptedKey = $encryptedKey ? \OCA\Files_Encryption\Crypt::decryptPrivateKey($encryptedKey, $oldPassword) : false; if ($decryptedKey) { - $cipher = \OCA\Encryption\Helper::getCipher(); - $encryptedKey = \OCA\Encryption\Crypt::symmetricEncryptFileContent($decryptedKey, $newPassword, $cipher); + $cipher = \OCA\Files_Encryption\Helper::getCipher(); + $encryptedKey = \OCA\Files_Encryption\Crypt::symmetricEncryptFileContent($decryptedKey, $newPassword, $cipher); if ($encryptedKey) { - \OCA\Encryption\Keymanager::setPrivateKey($encryptedKey, $user); + \OCA\Files_Encryption\Keymanager::setPrivateKey($encryptedKey, $user); $session->setPrivateKey($decryptedKey); $return = true; } @@ -61,7 +59,7 @@ if ($decryptedKey) { // success or failure if ($return) { - $session->setInitialized(\OCA\Encryption\Session::INIT_SUCCESSFUL); + $session->setInitialized(\OCA\Files_Encryption\Session::INIT_SUCCESSFUL); \OCP\JSON::success(array('data' => array('message' => $l->t('Private key password successfully updated.')))); } else { \OCP\JSON::error(array('data' => array('message' => $errorMessage))); diff --git a/apps/files_encryption/ajax/userrecovery.php b/apps/files_encryption/ajax/userrecovery.php index a5b89fa723..e49fee83a3 100644 --- a/apps/files_encryption/ajax/userrecovery.php +++ b/apps/files_encryption/ajax/userrecovery.php @@ -7,8 +7,6 @@ * Script to handle admin settings for encrypted key recovery */ -use OCA\Encryption; - \OCP\JSON::checkLoggedIn(); \OCP\JSON::checkAppEnabled('files_encryption'); \OCP\JSON::callCheck(); @@ -22,7 +20,7 @@ if ( $userId = \OCP\USER::getUser(); $view = new \OC\Files\View('/'); - $util = new \OCA\Encryption\Util($view, $userId); + $util = new \OCA\Files_Encryption\Util($view, $userId); // Save recovery preference to DB $return = $util->setRecoveryForUser($_POST['userEnableRecovery']); diff --git a/apps/files_encryption/appinfo/app.php b/apps/files_encryption/appinfo/app.php index 7e7e6a5c85..f2dc63c340 100644 --- a/apps/files_encryption/appinfo/app.php +++ b/apps/files_encryption/appinfo/app.php @@ -5,22 +5,22 @@ \OCP\Util::addscript('files_encryption', 'detect-migration'); if (!OC_Config::getValue('maintenance', false)) { - OC_FileProxy::register(new OCA\Encryption\Proxy()); + OC_FileProxy::register(new OCA\Files_Encryption\Proxy()); // User related hooks - OCA\Encryption\Helper::registerUserHooks(); + OCA\Files_Encryption\Helper::registerUserHooks(); // Sharing related hooks - OCA\Encryption\Helper::registerShareHooks(); + OCA\Files_Encryption\Helper::registerShareHooks(); // Filesystem related hooks - OCA\Encryption\Helper::registerFilesystemHooks(); + OCA\Files_Encryption\Helper::registerFilesystemHooks(); // App manager related hooks - OCA\Encryption\Helper::registerAppHooks(); + OCA\Files_Encryption\Helper::registerAppHooks(); if(!in_array('crypt', stream_get_wrappers())) { - stream_wrapper_register('crypt', 'OCA\Encryption\Stream'); + stream_wrapper_register('crypt', 'OCA\Files_Encryption\Stream'); } } else { // logout user if we are in maintenance to force re-login diff --git a/apps/files_encryption/appinfo/routes.php b/apps/files_encryption/appinfo/routes.php index 97635ae123..9733c17fe9 100644 --- a/apps/files_encryption/appinfo/routes.php +++ b/apps/files_encryption/appinfo/routes.php @@ -19,4 +19,4 @@ $this->create('files_encryption_ajax_userrecovery', 'ajax/userrecovery.php') ->actionInclude('files_encryption/ajax/userrecovery.php'); // Register with the capabilities API -OC_API::register('get', '/cloud/capabilities', array('OCA\Encryption\Capabilities', 'getCapabilities'), 'files_encryption', OC_API::USER_AUTH); +OC_API::register('get', '/cloud/capabilities', array('OCA\Files_Encryption\Capabilities', 'getCapabilities'), 'files_encryption', OC_API::USER_AUTH); diff --git a/apps/files_encryption/files/error.php b/apps/files_encryption/files/error.php index b801c17bd4..4a1ed021f7 100644 --- a/apps/files_encryption/files/error.php +++ b/apps/files_encryption/files/error.php @@ -12,14 +12,14 @@ if (!isset($_)) { //also provide standalone error page if (isset($_GET['errorCode'])) { $errorCode = $_GET['errorCode']; switch ($errorCode) { - case \OCA\Encryption\Crypt::ENCRYPTION_NOT_INITIALIZED_ERROR: + case \OCA\Files_Encryption\Crypt::ENCRYPTION_NOT_INITIALIZED_ERROR: $errorMsg = $l->t('Encryption app not initialized! Maybe the encryption app was re-enabled during your session. Please try to log out and log back in to initialize the encryption app.'); break; - case \OCA\Encryption\Crypt::ENCRYPTION_PRIVATE_KEY_NOT_VALID_ERROR: + case \OCA\Files_Encryption\Crypt::ENCRYPTION_PRIVATE_KEY_NOT_VALID_ERROR: $theme = new OC_Defaults(); $errorMsg = $l->t('Your private key is not valid! Likely your password was changed outside of %s (e.g. your corporate directory). You can update your private key password in your personal settings to recover access to your encrypted files.', array($theme->getName())); break; - case \OCA\Encryption\Crypt::ENCRYPTION_NO_SHARE_KEY_FOUND: + case \OCA\Files_Encryption\Crypt::ENCRYPTION_NO_SHARE_KEY_FOUND: $errorMsg = $l->t('Can not decrypt this file, probably this is a shared file. Please ask the file owner to reshare the file with you.'); break; default: @@ -27,7 +27,7 @@ if (!isset($_)) { //also provide standalone error page break; } } else { - $errorCode = \OCA\Encryption\Crypt::ENCRYPTION_UNKNOWN_ERROR; + $errorCode = \OCA\Files_Encryption\Crypt::ENCRYPTION_UNKNOWN_ERROR; $errorMsg = $l->t("Unknown error. Please check your system settings or contact your administrator"); } diff --git a/apps/files_encryption/lib/crypt.php b/apps/files_encryption/lib/crypt.php index 34b676dba2..38993ba65b 100644 --- a/apps/files_encryption/lib/crypt.php +++ b/apps/files_encryption/lib/crypt.php @@ -133,7 +133,7 @@ class Crypt { * Check if a file's contents contains an IV and is symmetrically encrypted * @param string $content * @return boolean - * @note see also OCA\Encryption\Util->isEncryptedPath() + * @note see also \OCA\Files_Encryption\Util->isEncryptedPath() */ public static function isCatfileContent($content) { @@ -190,7 +190,7 @@ class Crypt { * @param string $passphrase * @param string $cypher used for encryption, currently we support AES-128-CFB and AES-256-CFB * @return string encrypted file content - * @throws \OCA\Encryption\Exception\EncryptionException + * @throws \OCA\Files_Encryption\Exception\EncryptionException */ private static function encrypt($plainContent, $iv, $passphrase = '', $cipher = Crypt::DEFAULT_CIPHER) { @@ -379,7 +379,7 @@ class Crypt { * @param string $plainContent content to be encrypted * @param array $publicKeys array keys must be the userId of corresponding user * @return array keys: keys (array, key = userId), data - * @throws \OCA\Encryption\Exception\MultiKeyEncryptException if encryption failed + * @throws \OCA\Files_Encryption\Exception\MultiKeyEncryptException if encryption failed * @note symmetricDecryptFileContent() can decrypt files created using this method */ public static function multiKeyEncrypt($plainContent, array $publicKeys) { @@ -425,7 +425,7 @@ class Crypt { * @param string $encryptedContent * @param string $shareKey * @param mixed $privateKey - * @throws \OCA\Encryption\Exception\MultiKeyDecryptException if decryption failed + * @throws \OCA\Files_Encryption\Exception\MultiKeyDecryptException if decryption failed * @internal param string $plainContent contains decrypted content * @return string $plainContent decrypted string * @note symmetricDecryptFileContent() can be used to decrypt files created using this method @@ -554,7 +554,7 @@ class Crypt { * get chiper from header * * @param array $header - * @throws \OCA\Encryption\Exception\EncryptionException + * @throws \OCA\Files_Encryption\Exception\EncryptionException */ public static function getCipher($header) { $cipher = isset($header['cipher']) ? $header['cipher'] : 'AES-128-CFB'; diff --git a/apps/files_encryption/lib/helper.php b/apps/files_encryption/lib/helper.php index b1147a0eb5..6a8ea25d44 100644 --- a/apps/files_encryption/lib/helper.php +++ b/apps/files_encryption/lib/helper.php @@ -27,7 +27,7 @@ namespace OCA\Files_Encryption; /** * Class to manage registration of hooks an various helper methods - * @package OCA\Encryption + * @package OCA\Files_Encryption */ class Helper { @@ -39,9 +39,9 @@ class Helper { */ public static function registerShareHooks() { - \OCP\Util::connectHook('OCP\Share', 'pre_shared', 'OCA\Encryption\Hooks', 'preShared'); - \OCP\Util::connectHook('OCP\Share', 'post_shared', 'OCA\Encryption\Hooks', 'postShared'); - \OCP\Util::connectHook('OCP\Share', 'post_unshare', 'OCA\Encryption\Hooks', 'postUnshare'); + \OCP\Util::connectHook('OCP\Share', 'pre_shared', 'OCA\Files_Encryption\Hooks', 'preShared'); + \OCP\Util::connectHook('OCP\Share', 'post_shared', 'OCA\Files_Encryption\Hooks', 'postShared'); + \OCP\Util::connectHook('OCP\Share', 'post_unshare', 'OCA\Files_Encryption\Hooks', 'postUnshare'); } /** @@ -50,12 +50,12 @@ class Helper { */ public static function registerUserHooks() { - \OCP\Util::connectHook('OC_User', 'post_login', 'OCA\Encryption\Hooks', 'login'); - \OCP\Util::connectHook('OC_User', 'logout', 'OCA\Encryption\Hooks', 'logout'); - \OCP\Util::connectHook('OC_User', 'post_setPassword', 'OCA\Encryption\Hooks', 'setPassphrase'); - \OCP\Util::connectHook('OC_User', 'pre_setPassword', 'OCA\Encryption\Hooks', 'preSetPassphrase'); - \OCP\Util::connectHook('OC_User', 'post_createUser', 'OCA\Encryption\Hooks', 'postCreateUser'); - \OCP\Util::connectHook('OC_User', 'post_deleteUser', 'OCA\Encryption\Hooks', 'postDeleteUser'); + \OCP\Util::connectHook('OC_User', 'post_login', 'OCA\Files_Encryption\Hooks', 'login'); + \OCP\Util::connectHook('OC_User', 'logout', 'OCA\Files_Encryption\Hooks', 'logout'); + \OCP\Util::connectHook('OC_User', 'post_setPassword', 'OCA\Files_Encryption\Hooks', 'setPassphrase'); + \OCP\Util::connectHook('OC_User', 'pre_setPassword', 'OCA\Files_Encryption\Hooks', 'preSetPassphrase'); + \OCP\Util::connectHook('OC_User', 'post_createUser', 'OCA\Files_Encryption\Hooks', 'postCreateUser'); + \OCP\Util::connectHook('OC_User', 'post_deleteUser', 'OCA\Files_Encryption\Hooks', 'postDeleteUser'); } /** @@ -64,15 +64,15 @@ class Helper { */ public static function registerFilesystemHooks() { - \OCP\Util::connectHook('OC_Filesystem', 'rename', 'OCA\Encryption\Hooks', 'preRename'); - \OCP\Util::connectHook('OC_Filesystem', 'post_rename', 'OCA\Encryption\Hooks', 'postRenameOrCopy'); - \OCP\Util::connectHook('OC_Filesystem', 'copy', 'OCA\Encryption\Hooks', 'preCopy'); - \OCP\Util::connectHook('OC_Filesystem', 'post_copy', 'OCA\Encryption\Hooks', 'postRenameOrCopy'); - \OCP\Util::connectHook('OC_Filesystem', 'post_delete', 'OCA\Encryption\Hooks', 'postDelete'); - \OCP\Util::connectHook('OC_Filesystem', 'delete', 'OCA\Encryption\Hooks', 'preDelete'); - \OCP\Util::connectHook('\OC\Core\LostPassword\Controller\LostController', 'post_passwordReset', 'OCA\Encryption\Hooks', 'postPasswordReset'); - \OCP\Util::connectHook('OC_Filesystem', 'post_umount', 'OCA\Encryption\Hooks', 'postUnmount'); - \OCP\Util::connectHook('OC_Filesystem', 'umount', 'OCA\Encryption\Hooks', 'preUnmount'); + \OCP\Util::connectHook('OC_Filesystem', 'rename', 'OCA\Files_Encryption\Hooks', 'preRename'); + \OCP\Util::connectHook('OC_Filesystem', 'post_rename', 'OCA\Files_Encryption\Hooks', 'postRenameOrCopy'); + \OCP\Util::connectHook('OC_Filesystem', 'copy', 'OCA\Files_Encryption\Hooks', 'preCopy'); + \OCP\Util::connectHook('OC_Filesystem', 'post_copy', 'OCA\Files_Encryption\Hooks', 'postRenameOrCopy'); + \OCP\Util::connectHook('OC_Filesystem', 'post_delete', 'OCA\Files_Encryption\Hooks', 'postDelete'); + \OCP\Util::connectHook('OC_Filesystem', 'delete', 'OCA\Files_Encryption\Hooks', 'preDelete'); + \OCP\Util::connectHook('\OC\Core\LostPassword\Controller\LostController', 'post_passwordReset', 'OCA\Files_Encryption\Hooks', 'postPasswordReset'); + \OCP\Util::connectHook('OC_Filesystem', 'post_umount', 'OCA\Files_Encryption\Hooks', 'postUnmount'); + \OCP\Util::connectHook('OC_Filesystem', 'umount', 'OCA\Files_Encryption\Hooks', 'preUnmount'); } /** @@ -81,8 +81,8 @@ class Helper { */ public static function registerAppHooks() { - \OCP\Util::connectHook('OC_App', 'pre_disable', 'OCA\Encryption\Hooks', 'preDisable'); - \OCP\Util::connectHook('OC_App', 'post_disable', 'OCA\Encryption\Hooks', 'postEnable'); + \OCP\Util::connectHook('OC_App', 'pre_disable', 'OCA\Files_Encryption\Hooks', 'preDisable'); + \OCP\Util::connectHook('OC_App', 'post_disable', 'OCA\Files_Encryption\Hooks', 'postEnable'); } /** @@ -131,8 +131,6 @@ class Helper { * * @param string $recoveryKeyId * @param string $recoveryPassword - * @internal param \OCA\Encryption\Util $util - * @internal param string $password * @return bool */ public static function adminEnableRecovery($recoveryKeyId, $recoveryPassword) { @@ -147,13 +145,13 @@ class Helper { if (!Keymanager::recoveryKeyExists($view)) { - $keypair = \OCA\Encryption\Crypt::createKeypair(); + $keypair = Crypt::createKeypair(); // Save public key Keymanager::setPublicKey($keypair['publicKey'], $recoveryKeyId); - $cipher = \OCA\Encryption\Helper::getCipher(); - $encryptedKey = \OCA\Encryption\Crypt::symmetricEncryptFileContent($keypair['privateKey'], $recoveryPassword, $cipher); + $cipher = Helper::getCipher(); + $encryptedKey = Crypt::symmetricEncryptFileContent($keypair['privateKey'], $recoveryPassword, $cipher); if ($encryptedKey) { Keymanager::setPrivateSystemKey($encryptedKey, $recoveryKeyId); // Set recoveryAdmin as enabled @@ -162,7 +160,7 @@ class Helper { } } else { // get recovery key and check the password - $util = new \OCA\Encryption\Util(new \OC\Files\View('/'), \OCP\User::getUser()); + $util = new Util(new \OC\Files\View('/'), \OCP\User::getUser()); $return = $util->checkRecoveryPassword($recoveryPassword); if ($return) { $appConfig->setValue('files_encryption', 'recoveryAdminEnabled', 1); @@ -362,14 +360,14 @@ class Helper { if ($errorCode === null) { $init = $session->getInitialized(); switch ($init) { - case \OCA\Encryption\Session::INIT_EXECUTED: - $errorCode = \OCA\Encryption\Crypt::ENCRYPTION_PRIVATE_KEY_NOT_VALID_ERROR; + case Session::INIT_EXECUTED: + $errorCode = Crypt::ENCRYPTION_PRIVATE_KEY_NOT_VALID_ERROR; break; - case \OCA\Encryption\Session::NOT_INITIALIZED: - $errorCode = \OCA\Encryption\Crypt::ENCRYPTION_NOT_INITIALIZED_ERROR; + case Session::NOT_INITIALIZED: + $errorCode = Crypt::ENCRYPTION_NOT_INITIALIZED_ERROR; break; default: - $errorCode = \OCA\Encryption\Crypt::ENCRYPTION_UNKNOWN_ERROR; + $errorCode = Crypt::ENCRYPTION_UNKNOWN_ERROR; } } diff --git a/apps/files_encryption/lib/hooks.php b/apps/files_encryption/lib/hooks.php index a22477fce9..bddfb7b254 100644 --- a/apps/files_encryption/lib/hooks.php +++ b/apps/files_encryption/lib/hooks.php @@ -59,7 +59,7 @@ class Hooks { \OC_Util::setupFS($params['uid']); } - $privateKey = \OCA\Encryption\Keymanager::getPrivateKey($view, $params['uid']); + $privateKey = Keymanager::getPrivateKey($view, $params['uid']); // if no private key exists, check server configuration if (!$privateKey) { @@ -128,7 +128,7 @@ class Hooks { * remove keys from session during logout */ public static function logout() { - $session = new \OCA\Encryption\Session(new \OC\Files\View()); + $session = new Session(new \OC\Files\View()); $session->removeKeys(); } @@ -182,7 +182,7 @@ class Hooks { if (Crypt::mode() === 'server') { $view = new \OC\Files\View('/'); - $session = new \OCA\Encryption\Session($view); + $session = new Session($view); // Get existing decrypted private key $privateKey = $session->getPrivateKey(); @@ -236,7 +236,7 @@ class Hooks { Keymanager::setPublicKey($keypair['publicKey'], $user); // Encrypt private key with new password - $encryptedKey = \OCA\Encryption\Crypt::symmetricEncryptFileContent($keypair['privateKey'], $newUserPassword, Helper::getCipher()); + $encryptedKey = Crypt::symmetricEncryptFileContent($keypair['privateKey'], $newUserPassword, Helper::getCipher()); if ($encryptedKey) { Keymanager::setPrivateKey($encryptedKey, $user); @@ -331,7 +331,7 @@ class Hooks { private static function updateKeyfiles($path) { $view = new \OC\Files\View('/'); $userId = \OCP\User::getUser(); - $session = new \OCA\Encryption\Session($view); + $session = new Session($view); $util = new Util($view, $userId); $sharingEnabled = \OCP\Share::isEnabled(); @@ -504,8 +504,8 @@ class Hooks { \OC::$server->getConfig()->deleteAppFromAllUsers('files_encryption'); - $session = new \OCA\Encryption\Session(new \OC\Files\View('/')); - $session->setInitialized(\OCA\Encryption\Session::NOT_INITIALIZED); + $session = new Session(new \OC\Files\View('/')); + $session->setInitialized(Session::NOT_INITIALIZED); } } @@ -515,8 +515,8 @@ class Hooks { */ public static function postEnable($params) { if ($params['app'] === 'files_encryption') { - $session = new \OCA\Encryption\Session(new \OC\Files\View('/')); - $session->setInitialized(\OCA\Encryption\Session::NOT_INITIALIZED); + $session = new Session(new \OC\Files\View('/')); + $session->setInitialized(Session::NOT_INITIALIZED); } } diff --git a/apps/files_encryption/lib/keymanager.php b/apps/files_encryption/lib/keymanager.php index 16f0610f01..dfde368479 100644 --- a/apps/files_encryption/lib/keymanager.php +++ b/apps/files_encryption/lib/keymanager.php @@ -141,7 +141,7 @@ class Keymanager { * store file encryption key * * @param \OC\Files\View $view - * @param \OCA\Encryption\Util $util + * @param \OCA\Files_Encryption\Util $util * @param string $path relative path of the file, including filename * @param string $catfile keyfile content * @return bool true/false @@ -158,7 +158,7 @@ class Keymanager { * get path to key folder for a given file * * @param \OC\Files\View $view relative to data directory - * @param \OCA\Encryption\Util $util + * @param \OCA\Files_Encryption\Util $util * @param string $path path to the file, relative to the users file directory * @return string */ @@ -186,7 +186,7 @@ class Keymanager { * get path to file key for a given file * * @param \OC\Files\View $view relative to data directory - * @param \OCA\Encryption\Util $util + * @param \OCA\Files_Encryption\Util $util * @param string $path path to the file, relative to the users file directory * @return string */ @@ -199,7 +199,7 @@ class Keymanager { * get path to share key for a given user * * @param \OC\Files\View $view relateive to data directory - * @param \OCA\Encryption\Util $util + * @param \OCA\Files_Encryption\Util $util * @param string $path path to file relative to the users files directoy * @param string $uid user for whom we want the share-key path * @retrun string @@ -243,9 +243,8 @@ class Keymanager { /** * retrieve keyfile for an encrypted file * @param \OC\Files\View $view - * @param \OCA\Encryption\Util $util + * @param \OCA\Files_Encryption\Util $util * @param string|false $filePath - * @internal param \OCA\Encryption\file $string name * @return string file key or false * @note The keyfile returned is asymmetrically encrypted. Decryption * of the keyfile must be performed by client code @@ -347,7 +346,7 @@ class Keymanager { /** * store multiple share keys for a single file * @param \OC\Files\View $view - * @param \OCA\Encryption\Util $util + * @param \OCA\Files_Encryption\Util $util * @param string $path * @param array $shareKeys * @return bool @@ -376,7 +375,7 @@ class Keymanager { * retrieve shareKey for an encrypted file * @param \OC\Files\View $view * @param string $userId - * @param \OCA\Encryption\Util $util + * @param \OCA\Files_Encryption\Util $util * @param string $filePath * @return string file key or false * @note The sharekey returned is encrypted. Decryption diff --git a/apps/files_encryption/lib/migration.php b/apps/files_encryption/lib/migration.php index ee2e52114c..1bab1dfe4a 100644 --- a/apps/files_encryption/lib/migration.php +++ b/apps/files_encryption/lib/migration.php @@ -35,8 +35,8 @@ class Migration { 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(); + $this->public_share_key_id = Helper::getPublicShareKeyId(); + $this->recovery_key_id = Helper::getRecoveryKeyId(); } public function reorganizeFolderStructure() { diff --git a/apps/files_encryption/lib/proxy.php b/apps/files_encryption/lib/proxy.php index 720b88c3d7..ba78c81aa3 100644 --- a/apps/files_encryption/lib/proxy.php +++ b/apps/files_encryption/lib/proxy.php @@ -34,7 +34,7 @@ namespace OCA\Files_Encryption; /** * Class Proxy - * @package OCA\Encryption + * @package OCA\Files_Encryption */ class Proxy extends \OC_FileProxy { @@ -130,7 +130,7 @@ class Proxy extends \OC_FileProxy { $view = new \OC\Files\View('/'); // get relative path - $relativePath = \OCA\Encryption\Helper::stripUserFilesPath($path); + $relativePath = Helper::stripUserFilesPath($path); if (!isset($relativePath)) { return true; @@ -338,7 +338,7 @@ class Proxy extends \OC_FileProxy { } // get relative path - $relativePath = \OCA\Encryption\Helper::stripUserFilesPath($path); + $relativePath = Helper::stripUserFilesPath($path); // if path is empty we cannot resolve anything if (empty($relativePath)) { diff --git a/apps/files_encryption/lib/session.php b/apps/files_encryption/lib/session.php index e84befb6ed..4c70bc7e8f 100644 --- a/apps/files_encryption/lib/session.php +++ b/apps/files_encryption/lib/session.php @@ -72,8 +72,8 @@ class Session { Keymanager::setPublicKey($keypair['publicKey'], $publicShareKeyId); // Encrypt private key empty passphrase - $cipher = \OCA\Encryption\Helper::getCipher(); - $encryptedKey = \OCA\Encryption\Crypt::symmetricEncryptFileContent($keypair['privateKey'], '', $cipher); + $cipher = Helper::getCipher(); + $encryptedKey = Crypt::symmetricEncryptFileContent($keypair['privateKey'], '', $cipher); if ($encryptedKey) { Keymanager::setPrivateSystemKey($encryptedKey, $publicShareKeyId); } else { @@ -82,7 +82,7 @@ class Session { } - if (\OCA\Encryption\Helper::isPublicAccess() && !self::getPublicSharePrivateKey()) { + if (Helper::isPublicAccess() && !self::getPublicSharePrivateKey()) { // Disable encryption proxy to prevent recursive calls $proxyStatus = \OC_FileProxy::$enabled; \OC_FileProxy::$enabled = false; @@ -151,7 +151,7 @@ class Session { public function getInitialized() { if (!is_null(\OC::$server->getSession()->get('encryptionInitialized'))) { return \OC::$server->getSession()->get('encryptionInitialized'); - } else if (\OCA\Encryption\Helper::isPublicAccess() && self::getPublicSharePrivateKey()) { + } else if (Helper::isPublicAccess() && self::getPublicSharePrivateKey()) { return self::INIT_SUCCESSFUL; } else { return self::NOT_INITIALIZED; @@ -165,7 +165,7 @@ class Session { */ public function getPrivateKey() { // return the public share private key if this is a public access - if (\OCA\Encryption\Helper::isPublicAccess()) { + if (Helper::isPublicAccess()) { return self::getPublicSharePrivateKey(); } else { if (!is_null(\OC::$server->getSession()->get('privateKey'))) { diff --git a/apps/files_encryption/lib/stream.php b/apps/files_encryption/lib/stream.php index 430bdb595b..17da4eb1cd 100644 --- a/apps/files_encryption/lib/stream.php +++ b/apps/files_encryption/lib/stream.php @@ -31,7 +31,8 @@ */ namespace OCA\Files_Encryption; -use OCA\Encryption\Exception\EncryptionException; + +use OCA\Files_Encryption\Exception\EncryptionException; /** * Provides 'crypt://' stream wrapper protocol. @@ -81,7 +82,7 @@ class Stream { private $rootView; // a fsview object set to '/' /** - * @var \OCA\Encryption\Session + * @var \OCA\Files_Encryption\Session */ private $session; private $privateKey; @@ -92,7 +93,7 @@ class Stream { * @param int $options * @param string $opened_path * @return bool - * @throw \OCA\Encryption\Exception\EncryptionException + * @throw \OCA\Files_Encryption\Exception\EncryptionException */ public function stream_open($path, $mode, $options, &$opened_path) { @@ -106,7 +107,7 @@ class Stream { $this->rootView = new \OC\Files\View('/'); } - $this->session = new \OCA\Encryption\Session($this->rootView); + $this->session = new Session($this->rootView); $this->privateKey = $this->session->getPrivateKey(); if ($this->privateKey === false) { @@ -162,7 +163,7 @@ class Stream { if($this->privateKey === false) { // if private key is not valid redirect user to a error page - \OCA\Encryption\Helper::redirectToErrorPage($this->session); + Helper::redirectToErrorPage($this->session); } $this->size = $this->rootView->filesize($this->rawPath); @@ -251,7 +252,7 @@ class Stream { /** * @param int $count * @return bool|string - * @throws \OCA\Encryption\Exception\EncryptionException + * @throws \OCA\Files_Encryption\Exception\EncryptionException */ public function stream_read($count) { @@ -329,7 +330,7 @@ class Stream { // Fetch and decrypt keyfile // Fetch existing keyfile - $util = new \OCA\Encryption\Util($this->rootView, $this->userId); + $util = new Util($this->rootView, $this->userId); $this->encKeyfile = Keymanager::getFileKey($this->rootView, $util, $this->relPath); // If a keyfile already exists @@ -340,13 +341,13 @@ class Stream { // if there is no valid private key return false if ($this->privateKey === false) { // if private key is not valid redirect user to a error page - \OCA\Encryption\Helper::redirectToErrorPage($this->session); + Helper::redirectToErrorPage($this->session); return false; } if ($shareKey === false) { // if no share key is available redirect user to a error page - \OCA\Encryption\Helper::redirectToErrorPage($this->session, \OCA\Encryption\Crypt::ENCRYPTION_NO_SHARE_KEY_FOUND); + Helper::redirectToErrorPage($this->session, Crypt::ENCRYPTION_NO_SHARE_KEY_FOUND); return false; } @@ -367,7 +368,7 @@ class Stream { /** * write header at beginning of encrypted file * - * @throws Exception\EncryptionException + * @throws \OCA\Files_Encryption\Exception\EncryptionException */ private function writeHeader() { @@ -589,7 +590,7 @@ class Stream { } // if private key is not valid redirect user to a error page - \OCA\Encryption\Helper::redirectToErrorPage($this->session); + Helper::redirectToErrorPage($this->session); } if ( diff --git a/apps/files_encryption/lib/util.php b/apps/files_encryption/lib/util.php index 2052a976f7..ad6948b95a 100644 --- a/apps/files_encryption/lib/util.php +++ b/apps/files_encryption/lib/util.php @@ -83,7 +83,7 @@ class Util { // make sure that the owners home is mounted \OC\Files\Filesystem::initMountPoints($userId); - if (\OCA\Encryption\Helper::isPublicAccess()) { + if (Helper::isPublicAccess()) { $this->keyId = $this->publicShareKeyId; $this->isPublic = true; } else { @@ -277,7 +277,7 @@ class Util { if ($file !== "." && $file !== "..") { $filePath = $directory . '/' . $this->view->getRelativePath('/' . $file); - $relPath = \OCA\Encryption\Helper::stripUserFilesPath($filePath); + $relPath = Helper::stripUserFilesPath($filePath); // If the path is a directory, search // its contents @@ -451,13 +451,13 @@ class Util { } } fclose($stream); - $relPath = \OCA\Encryption\Helper::stripUserFilesPath($path); + $relPath = Helper::stripUserFilesPath($path); $shareKey = Keymanager::getShareKey($this->view, $this->keyId, $this, $relPath); if($shareKey===false) { \OC_FileProxy::$enabled = $proxyStatus; return $result; } - $session = new \OCA\Encryption\Session($this->view); + $session = new Session($this->view); $privateKey = $session->getPrivateKey(); $plainKeyfile = $this->decryptKeyfile($relPath, $privateKey); $plainKey = Crypt::multiKeyDecrypt($plainKeyfile, $shareKey, $privateKey); @@ -1040,7 +1040,7 @@ class Util { // Make sure that a share key is generated for the owner too list($owner, $ownerPath) = $this->getUidAndFilename($filePath); - $ownerPath = \OCA\Encryption\Helper::stripPartialFileExtension($ownerPath); + $ownerPath = Helper::stripPartialFileExtension($ownerPath); // always add owner to the list of users with access to the file $userIds = array($owner); @@ -1402,7 +1402,7 @@ class Util { if ($this->view->is_dir($this->userFilesDir . '/' . $filePath)) { $this->addRecoveryKeys($filePath . '/'); } else { - $session = new \OCA\Encryption\Session(new \OC\Files\View('/')); + $session = new Session(new \OC\Files\View('/')); $sharingEnabled = \OCP\Share::isEnabled(); $usersSharing = $this->getSharingUsersArray($sharingEnabled, $filePath); $this->setSharedFileKeyfiles($session, $usersSharing, $filePath); @@ -1559,10 +1559,10 @@ class Util { */ public function initEncryption($params) { - $session = new \OCA\Encryption\Session($this->view); + $session = new Session($this->view); // we tried to initialize the encryption app for this session - $session->setInitialized(\OCA\Encryption\Session::INIT_EXECUTED); + $session->setInitialized(Session::INIT_EXECUTED); $encryptedKey = Keymanager::getPrivateKey($this->view, $params['uid']); @@ -1578,7 +1578,7 @@ class Util { } $session->setPrivateKey($privateKey); - $session->setInitialized(\OCA\Encryption\Session::INIT_SUCCESSFUL); + $session->setInitialized(Session::INIT_SUCCESSFUL); return $session; } @@ -1587,7 +1587,7 @@ class Util { * remove encryption related keys from the session */ public function closeEncryptionSession() { - $session = new \OCA\Encryption\Session($this->view); + $session = new Session($this->view); $session->closeSession(); } diff --git a/apps/files_encryption/settings-admin.php b/apps/files_encryption/settings-admin.php index 496a7cffb5..0f5d56a373 100644 --- a/apps/files_encryption/settings-admin.php +++ b/apps/files_encryption/settings-admin.php @@ -12,7 +12,7 @@ $tmpl = new OCP\Template('files_encryption', 'settings-admin'); // Check if an adminRecovery account is enabled for recovering files after lost pwd $recoveryAdminEnabled = \OC::$server->getAppConfig()->getValue('files_encryption', 'recoveryAdminEnabled', '0'); -$session = new \OCA\Encryption\Session(new \OC\Files\View('/')); +$session = new \OCA\Files_Encryption\Session(new \OC\Files\View('/')); $initStatus = $session->getInitialized(); $tmpl->assign('recoveryEnabled', $recoveryAdminEnabled); diff --git a/apps/files_encryption/settings-personal.php b/apps/files_encryption/settings-personal.php index e9875518f6..966556f6f9 100644 --- a/apps/files_encryption/settings-personal.php +++ b/apps/files_encryption/settings-personal.php @@ -13,8 +13,8 @@ $tmpl = new OCP\Template('files_encryption', 'settings-personal'); $user = \OCP\USER::getUser(); $view = new \OC\Files\View('/'); -$util = new \OCA\Encryption\Util($view, $user); -$session = new \OCA\Encryption\Session($view); +$util = new \OCA\Files_Encryption\Util($view, $user); +$session = new \OCA\Files_Encryption\Session($view); $privateKeySet = $session->getPrivateKey() !== false; // did we tried to initialize the keys for this session? diff --git a/apps/files_encryption/templates/invalid_private_key.php b/apps/files_encryption/templates/invalid_private_key.php index b275b9c428..b148e65b19 100644 --- a/apps/files_encryption/templates/invalid_private_key.php +++ b/apps/files_encryption/templates/invalid_private_key.php @@ -4,7 +4,7 @@
- + t('Go directly to your %spersonal settings%s.', array('', ''))); ?>
diff --git a/apps/files_encryption/templates/settings-admin.php b/apps/files_encryption/templates/settings-admin.php index d003f245bb..4c1d724b6d 100644 --- a/apps/files_encryption/templates/settings-admin.php +++ b/apps/files_encryption/templates/settings-admin.php @@ -1,7 +1,7 @@

t('Encryption')); ?>

- + t("Encryption App is enabled but your keys are not initialized, please log-out and log-in again")); ?>

diff --git a/apps/files_encryption/templates/settings-personal.php b/apps/files_encryption/templates/settings-personal.php index ce8cf6aec2..17123a154d 100644 --- a/apps/files_encryption/templates/settings-personal.php +++ b/apps/files_encryption/templates/settings-personal.php @@ -1,11 +1,11 @@

t( 'Encryption' ) ); ?>

- + t("Encryption App is enabled but your keys are not initialized, please log-out and log-in again")); ?> - +

- +

diff --git a/apps/files_encryption/tests/crypt.php b/apps/files_encryption/tests/crypt.php index ab2ce066cd..2a60340405 100755 --- a/apps/files_encryption/tests/crypt.php +++ b/apps/files_encryption/tests/crypt.php @@ -7,7 +7,7 @@ * See the COPYING-README file. */ -use OCA\Encryption; +use OCA\Files_Encryption\Crypt; /** * Class Test_Encryption_Crypt @@ -52,9 +52,9 @@ class Test_Encryption_Crypt extends \OCA\Files_Encryption\Tests\TestCase { $this->legacyData = __DIR__ . '/legacy-text.txt'; $this->legacyEncryptedData = __DIR__ . '/legacy-encrypted-text.txt'; $this->legacyEncryptedDataKey = __DIR__ . '/encryption.key'; - $this->randomKey = Encryption\Crypt::generateKey(); + $this->randomKey = Crypt::generateKey(); - $keypair = Encryption\Crypt::createKeypair(); + $keypair = Crypt::createKeypair(); $this->genPublicKey = $keypair['publicKey']; $this->genPrivateKey = $keypair['privateKey']; @@ -95,7 +95,7 @@ class Test_Encryption_Crypt extends \OCA\Files_Encryption\Tests\TestCase { # TODO: use more accurate (larger) string length for test confirmation - $key = Encryption\Crypt::generateKey(); + $key = Crypt::generateKey(); $this->assertTrue(strlen($key) > 16); @@ -104,16 +104,16 @@ class Test_Encryption_Crypt extends \OCA\Files_Encryption\Tests\TestCase { public function testDecryptPrivateKey() { // test successful decrypt - $crypted = Encryption\Crypt::symmetricEncryptFileContent($this->genPrivateKey, 'hat'); + $crypted = Crypt::symmetricEncryptFileContent($this->genPrivateKey, 'hat'); - $header = Encryption\Crypt::generateHeader(); + $header = Crypt::generateHeader(); - $decrypted = Encryption\Crypt::decryptPrivateKey($header . $crypted, 'hat'); + $decrypted = Crypt::decryptPrivateKey($header . $crypted, 'hat'); $this->assertEquals($this->genPrivateKey, $decrypted); //test private key decrypt with wrong password - $wrongPasswd = Encryption\Crypt::decryptPrivateKey($crypted, 'hat2'); + $wrongPasswd = Crypt::decryptPrivateKey($crypted, 'hat2'); $this->assertEquals(false, $wrongPasswd); @@ -127,12 +127,12 @@ class Test_Encryption_Crypt extends \OCA\Files_Encryption\Tests\TestCase { # TODO: search in keyfile for actual content as IV will ensure this test always passes - $crypted = Encryption\Crypt::symmetricEncryptFileContent($this->dataShort, 'hat'); + $crypted = Crypt::symmetricEncryptFileContent($this->dataShort, 'hat'); $this->assertNotEquals($this->dataShort, $crypted); - $decrypt = Encryption\Crypt::symmetricDecryptFileContent($crypted, 'hat'); + $decrypt = Crypt::symmetricDecryptFileContent($crypted, 'hat'); $this->assertEquals($this->dataShort, $decrypt); @@ -145,12 +145,12 @@ class Test_Encryption_Crypt extends \OCA\Files_Encryption\Tests\TestCase { # TODO: search in keyfile for actual content as IV will ensure this test always passes - $crypted = Encryption\Crypt::symmetricEncryptFileContent($this->dataShort, 'hat', 'AES-128-CFB'); + $crypted = Crypt::symmetricEncryptFileContent($this->dataShort, 'hat', 'AES-128-CFB'); $this->assertNotEquals($this->dataShort, $crypted); - $decrypt = Encryption\Crypt::symmetricDecryptFileContent($crypted, 'hat', 'AES-128-CFB'); + $decrypt = Crypt::symmetricDecryptFileContent($crypted, 'hat', 'AES-128-CFB'); $this->assertEquals($this->dataShort, $decrypt); @@ -348,7 +348,7 @@ class Test_Encryption_Crypt extends \OCA\Files_Encryption\Tests\TestCase { // remove the header to check if we can also decrypt old files without a header, // this files should fall back to AES-128 - $cryptedWithoutHeader = substr($retreivedCryptedFile, Encryption\Crypt::BLOCKSIZE); + $cryptedWithoutHeader = substr($retreivedCryptedFile, Crypt::BLOCKSIZE); $this->view->file_put_contents($this->userId . '/files/' . $filename, $cryptedWithoutHeader); // Re-enable proxy - our work is done @@ -367,13 +367,13 @@ class Test_Encryption_Crypt extends \OCA\Files_Encryption\Tests\TestCase { */ public function testIsEncryptedContent() { - $this->assertFalse(Encryption\Crypt::isCatfileContent($this->dataUrl)); + $this->assertFalse(Crypt::isCatfileContent($this->dataUrl)); - $this->assertFalse(Encryption\Crypt::isCatfileContent($this->legacyEncryptedData)); + $this->assertFalse(Crypt::isCatfileContent($this->legacyEncryptedData)); - $keyfileContent = Encryption\Crypt::symmetricEncryptFileContent($this->dataUrl, 'hat', 'AES-128-CFB'); + $keyfileContent = Crypt::symmetricEncryptFileContent($this->dataUrl, 'hat', 'AES-128-CFB'); - $this->assertTrue(Encryption\Crypt::isCatfileContent($keyfileContent)); + $this->assertTrue(Crypt::isCatfileContent($keyfileContent)); } @@ -384,7 +384,7 @@ class Test_Encryption_Crypt extends \OCA\Files_Encryption\Tests\TestCase { # TODO: search in keyfile for actual content as IV will ensure this test always passes - $pair1 = Encryption\Crypt::createKeypair(); + $pair1 = Crypt::createKeypair(); $this->assertEquals(2, count($pair1)); @@ -393,12 +393,12 @@ class Test_Encryption_Crypt extends \OCA\Files_Encryption\Tests\TestCase { $this->assertTrue(strlen($pair1['privateKey']) > 1); - $crypted = Encryption\Crypt::multiKeyEncrypt($this->dataShort, array($pair1['publicKey'])); + $crypted = Crypt::multiKeyEncrypt($this->dataShort, array($pair1['publicKey'])); $this->assertNotEquals($this->dataShort, $crypted['data']); - $decrypt = Encryption\Crypt::multiKeyDecrypt($crypted['data'], $crypted['keys'][0], $pair1['privateKey']); + $decrypt = Crypt::multiKeyDecrypt($crypted['data'], $crypted['keys'][0], $pair1['privateKey']); $this->assertEquals($this->dataShort, $decrypt); @@ -529,7 +529,7 @@ class Test_Encryption_Crypt extends \OCA\Files_Encryption\Tests\TestCase { // relogin $params['uid'] = $this->userId; $params['password'] = 'test'; - OCA\Encryption\Hooks::login($params); + OCA\Files_Encryption\Hooks::login($params); // Get file decrypted contents $newDecrypt = file_get_contents('crypt:///' . $this->userId . '/files/' . $filename); diff --git a/apps/files_encryption/tests/helper.php b/apps/files_encryption/tests/helper.php index 88ba9f20d5..a767861187 100644 --- a/apps/files_encryption/tests/helper.php +++ b/apps/files_encryption/tests/helper.php @@ -6,7 +6,7 @@ * See the COPYING-README file. */ -use OCA\Encryption; +use OCA\Files_Encryption\Helper; /** * Class Test_Encryption_Helper @@ -30,11 +30,11 @@ class Test_Encryption_Helper extends \OCA\Files_Encryption\Tests\TestCase { public static function setupHooks() { // Filesystem related hooks - \OCA\Encryption\Helper::registerFilesystemHooks(); + Helper::registerFilesystemHooks(); // clear and register hooks \OC_FileProxy::clearProxies(); - \OC_FileProxy::register(new OCA\Encryption\Proxy()); + \OC_FileProxy::register(new \OCA\Files_Encryption\Proxy()); } public static function tearDownAfterClass() { @@ -49,13 +49,13 @@ class Test_Encryption_Helper extends \OCA\Files_Encryption\Tests\TestCase { $partFilename = 'testfile.txt.part'; $filename = 'testfile.txt'; - $this->assertTrue(Encryption\Helper::isPartialFilePath($partFilename)); + $this->assertTrue(Helper::isPartialFilePath($partFilename)); - $this->assertEquals('testfile.txt', Encryption\Helper::stripPartialFileExtension($partFilename)); + $this->assertEquals('testfile.txt', Helper::stripPartialFileExtension($partFilename)); - $this->assertFalse(Encryption\Helper::isPartialFilePath($filename)); + $this->assertFalse(Helper::isPartialFilePath($filename)); - $this->assertEquals('testfile.txt', Encryption\Helper::stripPartialFileExtension($filename)); + $this->assertEquals('testfile.txt', Helper::stripPartialFileExtension($filename)); } @@ -67,13 +67,13 @@ class Test_Encryption_Helper extends \OCA\Files_Encryption\Tests\TestCase { $partFilename = 'testfile.txt.ocTransferId643653835.part'; $filename = 'testfile.txt'; - $this->assertTrue(Encryption\Helper::isPartialFilePath($partFilename)); + $this->assertTrue(Helper::isPartialFilePath($partFilename)); - $this->assertEquals('testfile.txt', Encryption\Helper::stripPartialFileExtension($partFilename)); + $this->assertEquals('testfile.txt', Helper::stripPartialFileExtension($partFilename)); - $this->assertFalse(Encryption\Helper::isPartialFilePath($filename)); + $this->assertFalse(Helper::isPartialFilePath($filename)); - $this->assertEquals('testfile.txt', Encryption\Helper::stripPartialFileExtension($filename)); + $this->assertEquals('testfile.txt', Helper::stripPartialFileExtension($filename)); } function testGetPathToRealFile() { @@ -85,8 +85,8 @@ class Test_Encryption_Helper extends \OCA\Files_Encryption\Tests\TestCase { $versionPath = "/user/files_versions/foo/bar/test.txt.v456756835"; $cachePath = "/user/cache/transferid636483/foo/bar/test.txt"; - $this->assertEquals($relativePath, Encryption\Helper::getPathToRealFile($versionPath)); - $this->assertEquals($relativePath, Encryption\Helper::getPathToRealFile($cachePath)); + $this->assertEquals($relativePath, Helper::getPathToRealFile($versionPath)); + $this->assertEquals($relativePath, Helper::getPathToRealFile($cachePath)); } function testGetUser() { @@ -100,17 +100,17 @@ class Test_Encryption_Helper extends \OCA\Files_Encryption\Tests\TestCase { self::loginHelper(self::TEST_ENCRYPTION_HELPER_USER1); // if we are logged-in every path should return the currently logged-in user - $this->assertEquals(self::TEST_ENCRYPTION_HELPER_USER1, Encryption\Helper::getUser($path3)); + $this->assertEquals(self::TEST_ENCRYPTION_HELPER_USER1, Helper::getUser($path3)); // now log out self::logoutHelper(); // now we should only get the user from /user/files and user/cache paths - $this->assertEquals(self::TEST_ENCRYPTION_HELPER_USER1, Encryption\Helper::getUser($path1)); - $this->assertEquals(self::TEST_ENCRYPTION_HELPER_USER1, Encryption\Helper::getUser($path2)); + $this->assertEquals(self::TEST_ENCRYPTION_HELPER_USER1, Helper::getUser($path1)); + $this->assertEquals(self::TEST_ENCRYPTION_HELPER_USER1, Helper::getUser($path2)); - $this->assertFalse(Encryption\Helper::getUser($path3)); - $this->assertFalse(Encryption\Helper::getUser($path4)); + $this->assertFalse(Helper::getUser($path3)); + $this->assertFalse(Helper::getUser($path4)); // Log-in again self::loginHelper(\Test_Encryption_Helper::TEST_ENCRYPTION_HELPER_USER1); diff --git a/apps/files_encryption/tests/hooks.php b/apps/files_encryption/tests/hooks.php index d5a30f5074..b4a28dd24a 100644 --- a/apps/files_encryption/tests/hooks.php +++ b/apps/files_encryption/tests/hooks.php @@ -20,7 +20,9 @@ * */ -use OCA\Encryption; +use OCA\Files_Encryption\Crypt; +use OCA\Files_Encryption\Hooks; +use OCA\Files_Encryption\Keymanager; /** * Class Test_Encryption_Hooks @@ -104,7 +106,7 @@ class Test_Encryption_Hooks extends \OCA\Files_Encryption\Tests\TestCase { $this->assertTrue(is_array($row)); // disabling the app should delete all user specific settings - \OCA\Encryption\Hooks::preDisable(array('app' => 'files_encryption')); + Hooks::preDisable(array('app' => 'files_encryption')); // check if user specific settings for the encryption app are really gone $query = \OC_DB::prepare('SELECT * FROM `*PREFIX*preferences` WHERE `appid` = ?'); @@ -407,35 +409,35 @@ class Test_Encryption_Hooks extends \OCA\Files_Encryption\Tests\TestCase { $view = new \OC\Files\View(); // set user password for the first time - \OCA\Encryption\Hooks::postCreateUser(array('uid' => 'newUser', 'password' => 'newUserPassword')); + Hooks::postCreateUser(array('uid' => 'newUser', 'password' => 'newUserPassword')); - $this->assertTrue($view->file_exists(\OCA\Encryption\Keymanager::getPublicKeyPath() . '/newUser.publicKey')); + $this->assertTrue($view->file_exists(Keymanager::getPublicKeyPath() . '/newUser.publicKey')); $this->assertTrue($view->file_exists('newUser/files_encryption/newUser.privateKey')); // check if we are able to decrypt the private key - $encryptedKey = \OCA\Encryption\Keymanager::getPrivateKey($view, 'newUser'); - $privateKey = \OCA\Encryption\Crypt::decryptPrivateKey($encryptedKey, 'newUserPassword'); + $encryptedKey = Keymanager::getPrivateKey($view, 'newUser'); + $privateKey = Crypt::decryptPrivateKey($encryptedKey, 'newUserPassword'); $this->assertTrue(is_string($privateKey)); // change the password before the user logged-in for the first time, // we can replace the encryption keys - \OCA\Encryption\Hooks::setPassphrase(array('uid' => 'newUser', 'password' => 'passwordChanged')); + Hooks::setPassphrase(array('uid' => 'newUser', 'password' => 'passwordChanged')); - $encryptedKey = \OCA\Encryption\Keymanager::getPrivateKey($view, 'newUser'); - $privateKey = \OCA\Encryption\Crypt::decryptPrivateKey($encryptedKey, 'passwordChanged'); + $encryptedKey = Keymanager::getPrivateKey($view, 'newUser'); + $privateKey = Crypt::decryptPrivateKey($encryptedKey, 'passwordChanged'); $this->assertTrue(is_string($privateKey)); // now create a files folder to simulate a already used account $view->mkdir('/newUser/files'); // change the password after the user logged in, now the password should not change - \OCA\Encryption\Hooks::setPassphrase(array('uid' => 'newUser', 'password' => 'passwordChanged2')); + Hooks::setPassphrase(array('uid' => 'newUser', 'password' => 'passwordChanged2')); - $encryptedKey = \OCA\Encryption\Keymanager::getPrivateKey($view, 'newUser'); - $privateKey = \OCA\Encryption\Crypt::decryptPrivateKey($encryptedKey, 'passwordChanged2'); + $encryptedKey = Keymanager::getPrivateKey($view, 'newUser'); + $privateKey = Crypt::decryptPrivateKey($encryptedKey, 'passwordChanged2'); $this->assertFalse($privateKey); - $privateKey = \OCA\Encryption\Crypt::decryptPrivateKey($encryptedKey, 'passwordChanged'); + $privateKey = Crypt::decryptPrivateKey($encryptedKey, 'passwordChanged'); $this->assertTrue(is_string($privateKey)); } diff --git a/apps/files_encryption/tests/keymanager.php b/apps/files_encryption/tests/keymanager.php index 21f0383943..f10940e441 100644 --- a/apps/files_encryption/tests/keymanager.php +++ b/apps/files_encryption/tests/keymanager.php @@ -6,7 +6,9 @@ * See the COPYING-README file. */ -use OCA\Encryption; +use OCA\Files_Encryption\Crypt; +use OCA\Files_Encryption\Keymanager; +use OCA\Files_Encryption\Util; /** * Class Test_Encryption_Keymanager @@ -50,9 +52,9 @@ class Test_Encryption_Keymanager extends \OCA\Files_Encryption\Tests\TestCase { $this->dataUrl = __DIR__ . '/../lib/crypt.php'; $this->legacyData = __DIR__ . '/legacy-text.txt'; $this->legacyEncryptedData = __DIR__ . '/legacy-encrypted-text.txt'; - $this->randomKey = Encryption\Crypt::generateKey(); + $this->randomKey = Crypt::generateKey(); - $keypair = Encryption\Crypt::createKeypair(); + $keypair = Crypt::createKeypair(); $this->genPublicKey = $keypair['publicKey']; $this->genPrivateKey = $keypair['privateKey']; @@ -89,9 +91,9 @@ class Test_Encryption_Keymanager extends \OCA\Files_Encryption\Tests\TestCase { */ function testGetPrivateKey() { - $key = Encryption\Keymanager::getPrivateKey($this->view, $this->userId); + $key = Keymanager::getPrivateKey($this->view, $this->userId); - $privateKey = Encryption\Crypt::decryptPrivateKey($key, $this->pass); + $privateKey = Crypt::decryptPrivateKey($key, $this->pass); $res = openssl_pkey_get_private($privateKey); @@ -108,7 +110,7 @@ class Test_Encryption_Keymanager extends \OCA\Files_Encryption\Tests\TestCase { */ function testGetPublicKey() { - $publiceKey = Encryption\Keymanager::getPublicKey($this->view, $this->userId); + $publiceKey = Keymanager::getPublicKey($this->view, $this->userId); $res = openssl_pkey_get_public($publiceKey); @@ -128,7 +130,7 @@ class Test_Encryption_Keymanager extends \OCA\Files_Encryption\Tests\TestCase { $file = 'unittest-' . $this->getUniqueID() . '.txt'; - $util = new Encryption\Util($this->view, $this->userId); + $util = new Util($this->view, $this->userId); // Disable encryption proxy to prevent recursive calls $proxyStatus = \OC_FileProxy::$enabled; @@ -136,7 +138,7 @@ class Test_Encryption_Keymanager extends \OCA\Files_Encryption\Tests\TestCase { $this->view->file_put_contents($this->userId . '/files/' . $file, $this->dataShort); - Encryption\Keymanager::setFileKey($this->view, $util, $file, $key); + Keymanager::setFileKey($this->view, $util, $file, $key); $this->assertTrue($this->view->file_exists('/' . $this->userId . '/files_encryption/keys/' . $file . '/fileKey')); @@ -154,7 +156,7 @@ class Test_Encryption_Keymanager extends \OCA\Files_Encryption\Tests\TestCase { $key = "dummy key"; - Encryption\Keymanager::setPrivateKey($key, 'dummyUser'); + Keymanager::setPrivateKey($key, 'dummyUser'); $this->assertTrue($this->view->file_exists('/dummyUser/files_encryption/dummyUser.privateKey')); @@ -169,13 +171,13 @@ class Test_Encryption_Keymanager extends \OCA\Files_Encryption\Tests\TestCase { $key = "dummy key"; $keyName = "myDummyKey"; - $encHeader = Encryption\Crypt::generateHeader(); + $encHeader = Crypt::generateHeader(); - Encryption\Keymanager::setPrivateSystemKey($key, $keyName); + Keymanager::setPrivateSystemKey($key, $keyName); $this->assertTrue($this->view->file_exists('/files_encryption/' . $keyName . '.privateKey')); - $result = Encryption\Keymanager::getPrivateSystemKey($keyName); + $result = Keymanager::getPrivateSystemKey($keyName); $this->assertSame($encHeader . $key, $result); @@ -189,7 +191,7 @@ class Test_Encryption_Keymanager extends \OCA\Files_Encryption\Tests\TestCase { */ function testGetUserKeys() { - $keys = Encryption\Keymanager::getUserKeys($this->view, $this->userId); + $keys = Keymanager::getUserKeys($this->view, $this->userId); $resPublic = openssl_pkey_get_public($keys['publicKey']); @@ -199,7 +201,7 @@ class Test_Encryption_Keymanager extends \OCA\Files_Encryption\Tests\TestCase { $this->assertArrayHasKey('key', $sslInfoPublic); - $privateKey = Encryption\Crypt::decryptPrivateKey($keys['privateKey'], $this->pass); + $privateKey = Crypt::decryptPrivateKey($keys['privateKey'], $this->pass); $resPrivate = openssl_pkey_get_private($privateKey); @@ -247,9 +249,9 @@ class Test_Encryption_Keymanager extends \OCA\Files_Encryption\Tests\TestCase { $this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keys/folder1/subfolder/subsubfolder/file2/user3.shareKey', 'data'); // recursive delete share keys from user1 and user2 - Encryption\Keymanager::delShareKey($this->view, + Keymanager::delShareKey($this->view, array('user1', 'user2', Test_Encryption_Keymanager::TEST_USER), - Encryption\Keymanager::getKeyPath($this->view, new Encryption\Util($this->view, Test_Encryption_Keymanager::TEST_USER), '/folder1'), + Keymanager::getKeyPath($this->view, new Util($this->view, Test_Encryption_Keymanager::TEST_USER), '/folder1'), Test_Encryption_Keymanager::TEST_USER, '/folder1'); @@ -315,9 +317,9 @@ class Test_Encryption_Keymanager extends \OCA\Files_Encryption\Tests\TestCase { $this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/existingFile.txt.' . Test_Encryption_Keymanager::TEST_USER . '.shareKey', 'data'); // recursive delete share keys from user1 and user2 - Encryption\Keymanager::delShareKey($this->view, + Keymanager::delShareKey($this->view, array('user1', 'user2', Test_Encryption_Keymanager::TEST_USER), - Encryption\Keymanager::getKeyPath($this->view, new Encryption\Util($this->view, Test_Encryption_Keymanager::TEST_USER), '/folder1/existingFile.txt'), + Keymanager::getKeyPath($this->view, new Util($this->view, Test_Encryption_Keymanager::TEST_USER), '/folder1/existingFile.txt'), Test_Encryption_Keymanager::TEST_USER, '/folder1/existingFile.txt'); @@ -356,9 +358,9 @@ class Test_Encryption_Keymanager extends \OCA\Files_Encryption\Tests\TestCase { } /** - * dummy class to access protected methods of \OCA\Encryption\Keymanager for testing + * dummy class to access protected methods of \OCA\Files_Encryption\Keymanager for testing */ -class TestProtectedKeymanagerMethods extends \OCA\Encryption\Keymanager { +class TestProtectedKeymanagerMethods extends \OCA\Files_Encryption\Keymanager { /** * @param \OC\Files\View $view relative to data/ diff --git a/apps/files_encryption/tests/migration.php b/apps/files_encryption/tests/migration.php index 21c4e354c2..3abe322235 100644 --- a/apps/files_encryption/tests/migration.php +++ b/apps/files_encryption/tests/migration.php @@ -21,8 +21,7 @@ * */ -use OCA\Encryption; -use OCA\Files_Encryption\Migration; +use OCA\Files_Encryption\Helper; class Test_Migration extends \OCA\Files_Encryption\Tests\TestCase { @@ -60,8 +59,8 @@ class Test_Migration extends \OCA\Files_Encryption\Tests\TestCase { 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(); + $this->public_share_key_id = Helper::getPublicShareKeyId(); + $this->recovery_key_id = Helper::getRecoveryKeyId(); if (OC_DB::tableExists('encryption_test')) { OC_DB::dropTable('encryption_test'); } diff --git a/apps/files_encryption/tests/proxy.php b/apps/files_encryption/tests/proxy.php index 72a9a9a555..3cc668e636 100644 --- a/apps/files_encryption/tests/proxy.php +++ b/apps/files_encryption/tests/proxy.php @@ -20,8 +20,6 @@ * */ -use OCA\Encryption; - /** * Class Test_Encryption_Proxy * this class provide basic proxy app tests @@ -153,7 +151,7 @@ class Test_Encryption_Proxy extends \OCA\Files_Encryption\Tests\TestCase { /** * Dummy class to make protected methods available for testing */ -class DummyProxy extends \OCA\Encryption\Proxy { +class DummyProxy extends \OCA\Files_Encryption\Proxy { public function isExcludedPathTesting($path, $uid) { return $this->isExcludedPath($path, $uid); } diff --git a/apps/files_encryption/tests/share.php b/apps/files_encryption/tests/share.php index f827017569..0eaff6bf87 100755 --- a/apps/files_encryption/tests/share.php +++ b/apps/files_encryption/tests/share.php @@ -20,7 +20,10 @@ * */ -use OCA\Encryption; +use OCA\Files_Encryption\Helper; +use OCA\Files_Encryption\Hooks; +use OCA\Files_Encryption\Keymanager; +use OCA\Files_Encryption\Util; /** * Class Test_Encryption_Share @@ -651,13 +654,13 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase { // login as admin self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1); - \OCA\Encryption\Helper::adminEnableRecovery(null, 'test123'); + Helper::adminEnableRecovery(null, 'test123'); $recoveryKeyId = \OC::$server->getAppConfig()->getValue('files_encryption', 'recoveryKeyId'); // login as admin self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1); - $util = new \OCA\Encryption\Util(new \OC\Files\View('/'), \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1); + $util = new Util(new \OC\Files\View('/'), \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1); // check if recovery password match $this->assertTrue($util->checkRecoveryPassword('test123')); @@ -744,8 +747,8 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase { . $this->subfolder . $this->subsubfolder . '/' . $this->filename . '/' . $recoveryKeyId . '.shareKey')); - $this->assertTrue(\OCA\Encryption\Helper::adminEnableRecovery(null, 'test123')); - $this->assertTrue(\OCA\Encryption\Helper::adminDisableRecovery('test123')); + $this->assertTrue(Helper::adminEnableRecovery(null, 'test123')); + $this->assertTrue(Helper::adminDisableRecovery('test123')); $this->assertEquals(0, \OC::$server->getAppConfig()->getValue('files_encryption', 'recoveryAdminEnabled')); } @@ -757,7 +760,7 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase { // login as admin self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1); - $result = \OCA\Encryption\Helper::adminEnableRecovery(null, 'test123'); + $result = Helper::adminEnableRecovery(null, 'test123'); $this->assertTrue($result); $recoveryKeyId = \OC::$server->getAppConfig()->getValue('files_encryption', 'recoveryKeyId'); @@ -765,7 +768,7 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase { // login as user2 self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2); - $util = new \OCA\Encryption\Util(new \OC\Files\View('/'), \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2); + $util = new Util(new \OC\Files\View('/'), \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2); // enable recovery for admin $this->assertTrue($util->setRecoveryForUser(1)); @@ -814,7 +817,7 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase { $params = array('uid' => \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2, 'password' => 'test', 'recoveryPassword' => 'test123'); - \OCA\Encryption\Hooks::setPassphrase($params); + Hooks::setPassphrase($params); // login as user2 self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2, false, 'test'); @@ -853,7 +856,7 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase { // enable recovery for admin $this->assertTrue($util->setRecoveryForUser(0)); - \OCA\Encryption\Helper::adminDisableRecovery('test123'); + Helper::adminDisableRecovery('test123'); $this->assertEquals(0, \OC::$server->getAppConfig()->getValue('files_encryption', 'recoveryAdminEnabled')); //clean up, reset passwords @@ -861,7 +864,7 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase { $params = array('uid' => \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2, 'password' => \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2, 'recoveryPassword' => 'test123'); - \OCA\Encryption\Hooks::setPassphrase($params); + Hooks::setPassphrase($params); } /** @@ -892,8 +895,8 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase { $this->assertGreaterThan(0, $fileInfo['unencrypted_size']); // break users public key - $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'); + $this->view->rename(Keymanager::getPublicKeyPath() . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '.publicKey', + Keymanager::getPublicKeyPath() . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '.publicKey_backup'); // re-enable the file proxy \OC_FileProxy::$enabled = $proxyStatus; @@ -920,8 +923,8 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase { // break user1 public key $this->view->rename( - \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'); + Keymanager::getPublicKeyPath() . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '.publicKey_backup', + 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 f4824935ca..08d4ddcf5b 100644 --- a/apps/files_encryption/tests/stream.php +++ b/apps/files_encryption/tests/stream.php @@ -20,8 +20,6 @@ * */ -use OCA\Encryption; - /** * Class Test_Encryption_Stream * this class provide basic stream tests @@ -208,7 +206,7 @@ class Test_Encryption_Stream extends \OCA\Files_Encryption\Tests\TestCase { file_put_contents($tmpFilename, $encryptedContent); - \OCA\Encryption\Helper::addTmpFileToMapper($tmpFilename, $filename); + \OCA\Files_Encryption\Helper::addTmpFileToMapper($tmpFilename, $filename); // try to read the file from /tmp $handle = fopen("crypt://".$tmpFilename, "r"); diff --git a/apps/files_encryption/tests/testcase.php b/apps/files_encryption/tests/testcase.php index 743a876ab4..84b728d4aa 100644 --- a/apps/files_encryption/tests/testcase.php +++ b/apps/files_encryption/tests/testcase.php @@ -8,7 +8,7 @@ namespace OCA\Files_Encryption\Tests; -use OCA\Encryption; +use OCA\Files_Encryption\Helper; /** * Class Test_Encryption_TestCase @@ -42,7 +42,7 @@ abstract class TestCase extends \Test\TestCase { if ($loadEncryption) { $params['uid'] = $user; $params['password'] = $password; - \OCA\Encryption\Hooks::login($params); + \OCA\Files_Encryption\Hooks::login($params); } } @@ -59,16 +59,16 @@ abstract class TestCase extends \Test\TestCase { \OC_User::clearBackends(); \OC_User::useBackend('database'); - \OCA\Encryption\Helper::registerFilesystemHooks(); - \OCA\Encryption\Helper::registerUserHooks(); - \OCA\Encryption\Helper::registerShareHooks(); + Helper::registerFilesystemHooks(); + Helper::registerUserHooks(); + 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()); + \OC_FileProxy::register(new \OCA\Files_Encryption\Proxy()); } public static function tearDownAfterClass() { diff --git a/apps/files_encryption/tests/trashbin.php b/apps/files_encryption/tests/trashbin.php index de5b8bd6ed..d8af31760e 100755 --- a/apps/files_encryption/tests/trashbin.php +++ b/apps/files_encryption/tests/trashbin.php @@ -20,8 +20,6 @@ * */ -use OCA\Encryption; - /** * Class Test_Encryption_Trashbin * this class provide basic trashbin app tests diff --git a/apps/files_encryption/tests/util.php b/apps/files_encryption/tests/util.php index 2d58db2128..8496772a13 100755 --- a/apps/files_encryption/tests/util.php +++ b/apps/files_encryption/tests/util.php @@ -6,7 +6,9 @@ * See the COPYING-README file. */ -use OCA\Encryption; +use OCA\Files_Encryption\Crypt; +use OCA\Files_Encryption\Keymanager; +use OCA\Files_Encryption\Util; /** * Class Test_Encryption_Util @@ -31,7 +33,7 @@ class Test_Encryption_Util extends \OCA\Files_Encryption\Tests\TestCase { public $publicKeyPath; public $privateKeyPath; /** - * @var \OCA\Encryption\Util + * @var \OCA\Files_Encryption\Util */ public $util; public $dataShort; @@ -74,12 +76,12 @@ class Test_Encryption_Util extends \OCA\Files_Encryption\Tests\TestCase { $this->legacyEncryptedDataKey = __DIR__ . '/encryption.key'; $this->legacyKey = "30943623843030686906\0\0\0\0"; - $keypair = Encryption\Crypt::createKeypair(); + $keypair = Crypt::createKeypair(); $this->genPublicKey = $keypair['publicKey']; $this->genPrivateKey = $keypair['privateKey']; - $this->publicKeyDir = \OCA\Encryption\Keymanager::getPublicKeyPath(); + $this->publicKeyDir = Keymanager::getPublicKeyPath(); $this->encryptionDir = '/' . $this->userId . '/' . 'files_encryption'; $this->keysPath = $this->encryptionDir . '/' . 'keys'; $this->publicKeyPath = @@ -89,7 +91,7 @@ class Test_Encryption_Util extends \OCA\Files_Encryption\Tests\TestCase { $this->view = new \OC\Files\View('/'); - $this->util = new Encryption\Util($this->view, $this->userId); + $this->util = new Util($this->view, $this->userId); // remember files_trashbin state $this->stateFilesTrashbin = OC_App::isEnabled('files_trashbin'); @@ -128,7 +130,7 @@ class Test_Encryption_Util extends \OCA\Files_Encryption\Tests\TestCase { * test that paths set during User construction are correct */ function testKeyPaths() { - $util = new Encryption\Util($this->view, $this->userId); + $util = new Util($this->view, $this->userId); $this->assertEquals($this->publicKeyDir, $util->getPath('publicKeyDir')); $this->assertEquals($this->encryptionDir, $util->getPath('encryptionDir')); @@ -144,7 +146,7 @@ class Test_Encryption_Util extends \OCA\Files_Encryption\Tests\TestCase { */ function testIsEncryptedPath() { - $util = new Encryption\Util($this->view, $this->userId); + $util = new Util($this->view, $this->userId); self::loginHelper($this->userId); @@ -197,7 +199,7 @@ class Test_Encryption_Util extends \OCA\Files_Encryption\Tests\TestCase { // // $params['uid'] = $this->userId; // $params['password'] = $this->pass; -// $this->assertFalse(OCA\Encryption\Hooks::login($params)); +// $this->assertFalse(OCA\Files_Encryption\Hooks::login($params)); // // $this->view->unlink($this->privateKeyPath); // } @@ -207,7 +209,7 @@ class Test_Encryption_Util extends \OCA\Files_Encryption\Tests\TestCase { */ function testRecoveryEnabledForUser() { - $util = new Encryption\Util($this->view, $this->userId); + $util = new Util($this->view, $this->userId); // Record the value so we can return it to it's original state later $enabled = $util->recoveryEnabledForUser(); @@ -241,7 +243,7 @@ class Test_Encryption_Util extends \OCA\Files_Encryption\Tests\TestCase { // Re-enable proxy - our work is done \OC_FileProxy::$enabled = $proxyStatus; - $util = new Encryption\Util($this->view, $this->userId); + $util = new Util($this->view, $this->userId); list($fileOwnerUid, $file) = $util->getUidAndFilename($filename); @@ -283,7 +285,7 @@ class Test_Encryption_Util extends \OCA\Files_Encryption\Tests\TestCase { function testEncryptAll() { $filename = "/encryptAll" . $this->getUniqueID() . ".txt"; - $util = new Encryption\Util($this->view, $this->userId); + $util = new Util($this->view, $this->userId); // disable encryption to upload a unencrypted file \OC_App::disable('files_encryption'); @@ -345,11 +347,11 @@ class Test_Encryption_Util extends \OCA\Files_Encryption\Tests\TestCase { 'password' => \OCP\User::getUser()); $view = new OC\Files\View('/'); - $util = new \OCA\Encryption\Util($view, \OCP\User::getUser()); + $util = new Util($view, \OCP\User::getUser()); $result = $util->initEncryption($params); - $this->assertTrue($result instanceof \OCA\Encryption\Session); + $this->assertTrue($result instanceof \OCA\Files_Encryption\Session); $successful = $util->decryptAll(); @@ -401,7 +403,7 @@ class Test_Encryption_Util extends \OCA\Files_Encryption\Tests\TestCase { $this->view->file_put_contents($encPath . '/keys/foo/fileKey', 'key'); $this->view->file_put_contents($encPath . '/keys/foo/user1.shareKey', 'share key'); - $util = new \OCA\Encryption\Util($this->view, self::TEST_ENCRYPTION_UTIL_USER1); + $util = new Util($this->view, self::TEST_ENCRYPTION_UTIL_USER1); $util->backupAllKeys('testBackupAllKeys'); @@ -427,7 +429,7 @@ class Test_Encryption_Util extends \OCA\Files_Encryption\Tests\TestCase { $file1 = "/decryptAll1" . $this->getUniqueID() . ".txt"; $file2 = "/decryptAll2" . $this->getUniqueID() . ".txt"; - $util = new Encryption\Util($this->view, $this->userId); + $util = new Util($this->view, $this->userId); $this->view->file_put_contents($this->userId . '/files/' . $file1, $this->dataShort); $this->view->file_put_contents($this->userId . '/files/' . $file2, $this->dataShort); @@ -598,7 +600,7 @@ class Test_Encryption_Util extends \OCA\Files_Encryption\Tests\TestCase { if ($loadEncryption) { $params['uid'] = $user; $params['password'] = $password; - OCA\Encryption\Hooks::login($params); + \OCA\Files_Encryption\Hooks::login($params); } } @@ -625,9 +627,9 @@ class Test_Encryption_Util extends \OCA\Files_Encryption\Tests\TestCase { } /** - * dummy class extends \OCA\Encryption\Util to access protected methods for testing + * dummy class extends \OCA\Files_Encryption\Util to access protected methods for testing */ -class DummyUtilClass extends \OCA\Encryption\Util { +class DummyUtilClass extends \OCA\Files_Encryption\Util { public function testIsMountPointApplicableToUser($mount) { return $this->isMountPointApplicableToUser($mount); } diff --git a/apps/files_encryption/tests/webdav.php b/apps/files_encryption/tests/webdav.php index a04a762129..e3c92a4333 100755 --- a/apps/files_encryption/tests/webdav.php +++ b/apps/files_encryption/tests/webdav.php @@ -20,7 +20,7 @@ * */ -use OCA\Encryption; +use OCA\Files_Encryption\Crypt; /** * Class Test_Encryption_Webdav @@ -138,7 +138,7 @@ class Test_Encryption_Webdav extends \OCA\Files_Encryption\Tests\TestCase { \OC_FileProxy::$enabled = $proxyStatus; // check if encrypted content is valid - $this->assertTrue(Encryption\Crypt::isCatfileContent($encryptedContent)); + $this->assertTrue(Crypt::isCatfileContent($encryptedContent)); // get decrypted file contents $decrypt = file_get_contents('crypt:///' . $this->userId . '/files' . $filename); From e67fe0336bde1b10c1b2ba3dc455a9106cfc4be9 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 3 Dec 2014 17:03:11 +0100 Subject: [PATCH 4/5] Use self:: instead of the class name in encryption tests --- apps/files_encryption/tests/crypt.php | 10 +- apps/files_encryption/tests/helper.php | 10 +- apps/files_encryption/tests/hooks.php | 52 +-- apps/files_encryption/tests/keymanager.php | 136 +++---- apps/files_encryption/tests/proxy.php | 26 +- apps/files_encryption/tests/share.php | 452 ++++++++++----------- apps/files_encryption/tests/stream.php | 10 +- apps/files_encryption/tests/trashbin.php | 8 +- apps/files_encryption/tests/util.php | 6 +- apps/files_encryption/tests/webdav.php | 12 +- 10 files changed, 361 insertions(+), 361 deletions(-) diff --git a/apps/files_encryption/tests/crypt.php b/apps/files_encryption/tests/crypt.php index 2a60340405..d57fec18eb 100755 --- a/apps/files_encryption/tests/crypt.php +++ b/apps/files_encryption/tests/crypt.php @@ -34,16 +34,16 @@ class Test_Encryption_Crypt extends \OCA\Files_Encryption\Tests\TestCase { parent::setUpBeforeClass(); // create test user - self::loginHelper(\Test_Encryption_Crypt::TEST_ENCRYPTION_CRYPT_USER1, true); + self::loginHelper(self::TEST_ENCRYPTION_CRYPT_USER1, true); } protected function setUp() { parent::setUp(); // set user id - self::loginHelper(\Test_Encryption_Crypt::TEST_ENCRYPTION_CRYPT_USER1); - $this->userId = \Test_Encryption_Crypt::TEST_ENCRYPTION_CRYPT_USER1; - $this->pass = \Test_Encryption_Crypt::TEST_ENCRYPTION_CRYPT_USER1; + self::loginHelper(self::TEST_ENCRYPTION_CRYPT_USER1); + $this->userId = self::TEST_ENCRYPTION_CRYPT_USER1; + $this->pass = self::TEST_ENCRYPTION_CRYPT_USER1; // set content for encrypting / decrypting in tests $this->dataLong = file_get_contents(__DIR__ . '/../lib/crypt.php'); @@ -83,7 +83,7 @@ class Test_Encryption_Crypt extends \OCA\Files_Encryption\Tests\TestCase { public static function tearDownAfterClass() { // cleanup test user - \OC_User::deleteUser(\Test_Encryption_Crypt::TEST_ENCRYPTION_CRYPT_USER1); + \OC_User::deleteUser(self::TEST_ENCRYPTION_CRYPT_USER1); parent::tearDownAfterClass(); } diff --git a/apps/files_encryption/tests/helper.php b/apps/files_encryption/tests/helper.php index a767861187..32a962f7a3 100644 --- a/apps/files_encryption/tests/helper.php +++ b/apps/files_encryption/tests/helper.php @@ -18,14 +18,14 @@ class Test_Encryption_Helper extends \OCA\Files_Encryption\Tests\TestCase { protected function setUpUsers() { // create test user - self::loginHelper(\Test_Encryption_Helper::TEST_ENCRYPTION_HELPER_USER2, true); - self::loginHelper(\Test_Encryption_Helper::TEST_ENCRYPTION_HELPER_USER1, true); + self::loginHelper(self::TEST_ENCRYPTION_HELPER_USER2, true); + self::loginHelper(self::TEST_ENCRYPTION_HELPER_USER1, true); } protected function cleanUpUsers() { // cleanup test user - \OC_User::deleteUser(\Test_Encryption_Helper::TEST_ENCRYPTION_HELPER_USER1); - \OC_User::deleteUser(\Test_Encryption_Helper::TEST_ENCRYPTION_HELPER_USER2); + \OC_User::deleteUser(self::TEST_ENCRYPTION_HELPER_USER1); + \OC_User::deleteUser(self::TEST_ENCRYPTION_HELPER_USER2); } public static function setupHooks() { @@ -113,7 +113,7 @@ class Test_Encryption_Helper extends \OCA\Files_Encryption\Tests\TestCase { $this->assertFalse(Helper::getUser($path4)); // Log-in again - self::loginHelper(\Test_Encryption_Helper::TEST_ENCRYPTION_HELPER_USER1); + self::loginHelper(self::TEST_ENCRYPTION_HELPER_USER1); self::cleanUpUsers(); } diff --git a/apps/files_encryption/tests/hooks.php b/apps/files_encryption/tests/hooks.php index b4a28dd24a..dc347d1adc 100644 --- a/apps/files_encryption/tests/hooks.php +++ b/apps/files_encryption/tests/hooks.php @@ -66,20 +66,20 @@ class Test_Encryption_Hooks extends \OCA\Files_Encryption\Tests\TestCase { ); // create test user - self::loginHelper(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER1, true); - self::loginHelper(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2, true); + self::loginHelper(self::TEST_ENCRYPTION_HOOKS_USER1, true); + self::loginHelper(self::TEST_ENCRYPTION_HOOKS_USER2, true); } protected function setUp() { parent::setUp(); // set user id - self::loginHelper(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER1); - \OC_User::setUserId(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER1); + self::loginHelper(self::TEST_ENCRYPTION_HOOKS_USER1); + \OC_User::setUserId(self::TEST_ENCRYPTION_HOOKS_USER1); // init filesystem view - $this->user1View = new \OC\Files\View('/'. \Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER1 . '/files'); - $this->user2View = new \OC\Files\View('/'. \Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2 . '/files'); + $this->user1View = new \OC\Files\View('/'. self::TEST_ENCRYPTION_HOOKS_USER1 . '/files'); + $this->user2View = new \OC\Files\View('/'. self::TEST_ENCRYPTION_HOOKS_USER2 . '/files'); $this->rootView = new \OC\Files\View('/'); // init short data @@ -91,8 +91,8 @@ class Test_Encryption_Hooks extends \OCA\Files_Encryption\Tests\TestCase { public static function tearDownAfterClass() { // cleanup test user - \OC_User::deleteUser(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER1); - \OC_User::deleteUser(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2); + \OC_User::deleteUser(self::TEST_ENCRYPTION_HOOKS_USER1); + \OC_User::deleteUser(self::TEST_ENCRYPTION_HOOKS_USER2); parent::tearDownAfterClass(); } @@ -136,14 +136,14 @@ class Test_Encryption_Hooks extends \OCA\Files_Encryption\Tests\TestCase { // check if all keys are generated $this->assertTrue($this->rootView->file_exists( self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/keys/' - . $this->filename . '/' . \Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER1 . '.shareKey')); + . $this->filename . '/' . self::TEST_ENCRYPTION_HOOKS_USER1 . '.shareKey')); $this->assertTrue($this->rootView->file_exists( self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/keys/' . $this->filename . '/fileKey')); self::logoutHelper(); - self::loginHelper(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2); - \OC_User::setUserId(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2); + self::loginHelper(self::TEST_ENCRYPTION_HOOKS_USER2); + \OC_User::setUserId(self::TEST_ENCRYPTION_HOOKS_USER2); $this->user2View->file_put_contents($this->filename, $this->data); @@ -151,7 +151,7 @@ class Test_Encryption_Hooks extends \OCA\Files_Encryption\Tests\TestCase { // check if all keys are generated $this->assertTrue($this->rootView->file_exists( self::TEST_ENCRYPTION_HOOKS_USER2 . '/files_encryption/keys/' - . $this->filename . '/' . \Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2 . '.shareKey')); + . $this->filename . '/' . self::TEST_ENCRYPTION_HOOKS_USER2 . '.shareKey')); $this->assertTrue($this->rootView->file_exists( self::TEST_ENCRYPTION_HOOKS_USER2 . '/files_encryption/keys/' . $this->filename . '/fileKey')); @@ -166,7 +166,7 @@ class Test_Encryption_Hooks extends \OCA\Files_Encryption\Tests\TestCase { // all keys should still exist $this->assertTrue($this->rootView->file_exists( self::TEST_ENCRYPTION_HOOKS_USER2 . '/files_encryption/keys/' - . $this->filename . '/' . \Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2 . '.shareKey')); + . $this->filename . '/' . self::TEST_ENCRYPTION_HOOKS_USER2 . '.shareKey')); $this->assertTrue($this->rootView->file_exists( self::TEST_ENCRYPTION_HOOKS_USER2 . '/files_encryption/keys/' . $this->filename . '/fileKey')); @@ -178,14 +178,14 @@ class Test_Encryption_Hooks extends \OCA\Files_Encryption\Tests\TestCase { // check if keys from user2 are really deleted $this->assertFalse($this->rootView->file_exists( self::TEST_ENCRYPTION_HOOKS_USER2 . '/files_encryption/keys/' - . $this->filename . '/' . \Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2 . '.shareKey')); + . $this->filename . '/' . self::TEST_ENCRYPTION_HOOKS_USER2 . '.shareKey')); $this->assertFalse($this->rootView->file_exists( self::TEST_ENCRYPTION_HOOKS_USER2 . '/files_encryption/keys/' . $this->filename . '/fileKey')); // but user1 keys should still exist $this->assertTrue($this->rootView->file_exists( self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/keys/' - . $this->filename . '/' . \Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER1 . '.shareKey')); + . $this->filename . '/' . self::TEST_ENCRYPTION_HOOKS_USER1 . '.shareKey')); $this->assertTrue($this->rootView->file_exists( self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/keys/' . $this->filename . '/fileKey')); @@ -200,8 +200,8 @@ class Test_Encryption_Hooks extends \OCA\Files_Encryption\Tests\TestCase { function testDeleteHooksForSharedFiles() { self::logoutHelper(); - self::loginHelper(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER1); - \OC_User::setUserId(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER1); + self::loginHelper(self::TEST_ENCRYPTION_HOOKS_USER1); + \OC_User::setUserId(self::TEST_ENCRYPTION_HOOKS_USER1); // remember files_trashbin state $stateFilesTrashbin = OC_App::isEnabled('files_trashbin'); @@ -217,7 +217,7 @@ class Test_Encryption_Hooks extends \OCA\Files_Encryption\Tests\TestCase { // check if all keys are generated $this->assertTrue($this->rootView->file_exists( self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/keys/' - . $this->filename . '/' . \Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER1 . '.shareKey')); + . $this->filename . '/' . self::TEST_ENCRYPTION_HOOKS_USER1 . '.shareKey')); $this->assertTrue($this->rootView->file_exists( self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/keys/' . $this->filename . '/fileKey')); @@ -233,11 +233,11 @@ class Test_Encryption_Hooks extends \OCA\Files_Encryption\Tests\TestCase { // check if new share key exists $this->assertTrue($this->rootView->file_exists( self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/keys/' - . $this->filename . '/' . \Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2 . '.shareKey')); + . $this->filename . '/' . self::TEST_ENCRYPTION_HOOKS_USER2 . '.shareKey')); self::logoutHelper(); - self::loginHelper(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2); - \OC_User::setUserId(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2); + self::loginHelper(self::TEST_ENCRYPTION_HOOKS_USER2); + \OC_User::setUserId(self::TEST_ENCRYPTION_HOOKS_USER2); // user2 update the shared file $this->user2View->file_put_contents($this->filename, $this->data); @@ -245,7 +245,7 @@ class Test_Encryption_Hooks extends \OCA\Files_Encryption\Tests\TestCase { // keys should be stored at user1s dir, not in user2s $this->assertFalse($this->rootView->file_exists( self::TEST_ENCRYPTION_HOOKS_USER2 . '/files_encryption/keys/' - . $this->filename . '/' . \Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2 . '.shareKey')); + . $this->filename . '/' . self::TEST_ENCRYPTION_HOOKS_USER2 . '.shareKey')); $this->assertFalse($this->rootView->file_exists( self::TEST_ENCRYPTION_HOOKS_USER2 . '/files_encryption/keys/' . $this->filename . '/fileKey')); @@ -257,18 +257,18 @@ class Test_Encryption_Hooks extends \OCA\Files_Encryption\Tests\TestCase { // share key for user2 from user1s home should be gone, all other keys should still exists $this->assertTrue($this->rootView->file_exists( self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/keys/' - . $this->filename . '/' . \Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER1 . '.shareKey')); + . $this->filename . '/' . self::TEST_ENCRYPTION_HOOKS_USER1 . '.shareKey')); $this->assertFalse($this->rootView->file_exists( self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/keys/' - . $this->filename . '/' . \Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2 . '.shareKey')); + . $this->filename . '/' . self::TEST_ENCRYPTION_HOOKS_USER2 . '.shareKey')); $this->assertTrue($this->rootView->file_exists( self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/keys/' . $this->filename . '/fileKey')); // cleanup self::logoutHelper(); - self::loginHelper(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER1); - \OC_User::setUserId(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER1); + self::loginHelper(self::TEST_ENCRYPTION_HOOKS_USER1); + \OC_User::setUserId(self::TEST_ENCRYPTION_HOOKS_USER1); if ($stateFilesTrashbin) { OC_App::enable('files_trashbin'); diff --git a/apps/files_encryption/tests/keymanager.php b/apps/files_encryption/tests/keymanager.php index f10940e441..b0f0abce13 100644 --- a/apps/files_encryption/tests/keymanager.php +++ b/apps/files_encryption/tests/keymanager.php @@ -40,8 +40,8 @@ class Test_Encryption_Keymanager extends \OCA\Files_Encryption\Tests\TestCase { \OC_App::disable('files_trashbin'); // create test user - \OC_User::deleteUser(\Test_Encryption_Keymanager::TEST_USER); - parent::loginHelper(\Test_Encryption_Keymanager::TEST_USER, true); + \OC_User::deleteUser(self::TEST_USER); + parent::loginHelper(self::TEST_USER, true); } protected function setUp() { @@ -60,16 +60,16 @@ class Test_Encryption_Keymanager extends \OCA\Files_Encryption\Tests\TestCase { $this->view = new \OC\Files\View('/'); - self::loginHelper(Test_Encryption_Keymanager::TEST_USER); - $this->userId = \Test_Encryption_Keymanager::TEST_USER; - $this->pass = \Test_Encryption_Keymanager::TEST_USER; + self::loginHelper(self::TEST_USER); + $this->userId = self::TEST_USER; + $this->pass = self::TEST_USER; $userHome = \OC_User::getHome($this->userId); $this->dataDir = str_replace('/' . $this->userId, '', $userHome); } function tearDown() { - $this->view->deleteAll('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keys'); + $this->view->deleteAll('/' . self::TEST_USER . '/files_encryption/keys'); parent::tearDown(); } @@ -77,7 +77,7 @@ class Test_Encryption_Keymanager extends \OCA\Files_Encryption\Tests\TestCase { \OC_FileProxy::$enabled = true; // cleanup test user - \OC_User::deleteUser(\Test_Encryption_Keymanager::TEST_USER); + \OC_User::deleteUser(self::TEST_USER); // reset app files_trashbin if (self::$stateFilesTrashbin) { OC_App::enable('files_trashbin'); @@ -217,85 +217,85 @@ class Test_Encryption_Keymanager extends \OCA\Files_Encryption\Tests\TestCase { */ function testRecursiveDelShareKeysFolder() { - $this->view->mkdir('/'.Test_Encryption_Keymanager::TEST_USER.'/files/folder1'); - $this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files/folder1/existingFile.txt', 'data'); + $this->view->mkdir('/' . self::TEST_USER . '/files/folder1'); + $this->view->file_put_contents('/' . self::TEST_USER . '/files/folder1/existingFile.txt', 'data'); // create folder structure for some dummy share key files - $this->view->mkdir('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keys/folder1'); - $this->view->mkdir('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keys/folder1/existingFile.txt'); - $this->view->mkdir('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keys/folder1/file1'); - $this->view->mkdir('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keys/folder1/file2'); - $this->view->mkdir('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keys/folder1/subfolder'); - $this->view->mkdir('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keys/folder1/subfolder/file2'); - $this->view->mkdir('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keys/folder1/subfolder/subsubfolder'); - $this->view->mkdir('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keys/folder1/subfolder/subsubfolder/file1'); - $this->view->mkdir('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keys/folder1/subfolder/subsubfolder/file2'); + $this->view->mkdir('/' . self::TEST_USER . '/files_encryption/keys/folder1'); + $this->view->mkdir('/' . self::TEST_USER . '/files_encryption/keys/folder1/existingFile.txt'); + $this->view->mkdir('/' . self::TEST_USER . '/files_encryption/keys/folder1/file1'); + $this->view->mkdir('/' . self::TEST_USER . '/files_encryption/keys/folder1/file2'); + $this->view->mkdir('/' . self::TEST_USER . '/files_encryption/keys/folder1/subfolder'); + $this->view->mkdir('/' . self::TEST_USER . '/files_encryption/keys/folder1/subfolder/file2'); + $this->view->mkdir('/' . self::TEST_USER . '/files_encryption/keys/folder1/subfolder/subsubfolder'); + $this->view->mkdir('/' . self::TEST_USER . '/files_encryption/keys/folder1/subfolder/subsubfolder/file1'); + $this->view->mkdir('/' . self::TEST_USER . '/files_encryption/keys/folder1/subfolder/subsubfolder/file2'); // create some dummy share keys - $this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keys/folder1/existingFile.txt/user1.shareKey', 'data'); - $this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keys/folder1/existingFile.txt/' . Test_Encryption_Keymanager::TEST_USER . '.shareKey', 'data'); - $this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keys/folder1/file1/user1.shareKey', 'data'); - $this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keys/folder1/file1/user1.test.shareKey', 'data'); - $this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keys/folder1/file1/test-keymanager-userxdot.shareKey', 'data'); - $this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keys/folder1/file1/userx.' . Test_Encryption_Keymanager::TEST_USER . '.shareKey', 'data'); - $this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keys/folder1/file1/' . Test_Encryption_Keymanager::TEST_USER . '.userx.shareKey', 'data'); - $this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keys/folder1/file1/user1.' . Test_Encryption_Keymanager::TEST_USER . '.shareKey', 'data'); - $this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keys/folder1/file1/' . Test_Encryption_Keymanager::TEST_USER . '.user1.shareKey', 'data'); - $this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keys/folder1/file2/user2.shareKey', 'data'); - $this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keys/folder1/file2/user3.shareKey', 'data'); - $this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keys/folder1/subfolder/file2/user3.shareKey', 'data'); - $this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keys/folder1/subfolder/subsubfolder/file1/user1.shareKey', 'data'); - $this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keys/folder1/subfolder/subsubfolder/file2/user2.shareKey', 'data'); - $this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keys/folder1/subfolder/subsubfolder/file2/user3.shareKey', 'data'); + $this->view->file_put_contents('/' . self::TEST_USER . '/files_encryption/keys/folder1/existingFile.txt/user1.shareKey', 'data'); + $this->view->file_put_contents('/' . self::TEST_USER . '/files_encryption/keys/folder1/existingFile.txt/' . self::TEST_USER . '.shareKey', 'data'); + $this->view->file_put_contents('/' . self::TEST_USER . '/files_encryption/keys/folder1/file1/user1.shareKey', 'data'); + $this->view->file_put_contents('/' . self::TEST_USER . '/files_encryption/keys/folder1/file1/user1.test.shareKey', 'data'); + $this->view->file_put_contents('/' . self::TEST_USER . '/files_encryption/keys/folder1/file1/test-keymanager-userxdot.shareKey', 'data'); + $this->view->file_put_contents('/' . self::TEST_USER . '/files_encryption/keys/folder1/file1/userx.' . self::TEST_USER . '.shareKey', 'data'); + $this->view->file_put_contents('/' . self::TEST_USER . '/files_encryption/keys/folder1/file1/' . self::TEST_USER . '.userx.shareKey', 'data'); + $this->view->file_put_contents('/' . self::TEST_USER . '/files_encryption/keys/folder1/file1/user1.' . self::TEST_USER . '.shareKey', 'data'); + $this->view->file_put_contents('/' . self::TEST_USER . '/files_encryption/keys/folder1/file1/' . self::TEST_USER . '.user1.shareKey', 'data'); + $this->view->file_put_contents('/' . self::TEST_USER . '/files_encryption/keys/folder1/file2/user2.shareKey', 'data'); + $this->view->file_put_contents('/' . self::TEST_USER . '/files_encryption/keys/folder1/file2/user3.shareKey', 'data'); + $this->view->file_put_contents('/' . self::TEST_USER . '/files_encryption/keys/folder1/subfolder/file2/user3.shareKey', 'data'); + $this->view->file_put_contents('/' . self::TEST_USER . '/files_encryption/keys/folder1/subfolder/subsubfolder/file1/user1.shareKey', 'data'); + $this->view->file_put_contents('/' . self::TEST_USER . '/files_encryption/keys/folder1/subfolder/subsubfolder/file2/user2.shareKey', 'data'); + $this->view->file_put_contents('/' . self::TEST_USER . '/files_encryption/keys/folder1/subfolder/subsubfolder/file2/user3.shareKey', 'data'); // recursive delete share keys from user1 and user2 Keymanager::delShareKey($this->view, - array('user1', 'user2', Test_Encryption_Keymanager::TEST_USER), - Keymanager::getKeyPath($this->view, new Util($this->view, Test_Encryption_Keymanager::TEST_USER), '/folder1'), - Test_Encryption_Keymanager::TEST_USER, + array('user1', 'user2', self::TEST_USER), + Keymanager::getKeyPath($this->view, new Util($this->view, self::TEST_USER), '/folder1'), + self::TEST_USER, '/folder1'); // check if share keys from user1 and user2 are deleted $this->assertFalse($this->view->file_exists( - '/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keys/folder1/existingFile.txt/user1.shareKey')); + '/' . self::TEST_USER . '/files_encryption/keys/folder1/existingFile.txt/user1.shareKey')); $this->assertFalse($this->view->file_exists( - '/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/file1/user1.shareKey')); + '/' . self::TEST_USER . '/files_encryption/share-keys/folder1/file1/user1.shareKey')); $this->assertFalse($this->view->file_exists( - '/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/file2/user2.shareKey')); + '/' . self::TEST_USER . '/files_encryption/share-keys/folder1/file2/user2.shareKey')); $this->assertFalse($this->view->file_exists( - '/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/subfolder/subsubfolder/file1/user1.shareKey')); + '/' . self::TEST_USER . '/files_encryption/share-keys/folder1/subfolder/subsubfolder/file1/user1.shareKey')); $this->assertFalse($this->view->file_exists( - '/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/subfolder/subsubfolder/file2/user2.shareKey')); + '/' . self::TEST_USER . '/files_encryption/share-keys/folder1/subfolder/subsubfolder/file2/user2.shareKey')); // check if share keys from user3 still exists $this->assertTrue($this->view->file_exists( - '/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keys/folder1/file2/user3.shareKey')); + '/' . self::TEST_USER . '/files_encryption/keys/folder1/file2/user3.shareKey')); $this->assertTrue($this->view->file_exists( - '/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keys/folder1/subfolder/subsubfolder/file2/user3.shareKey')); + '/' . self::TEST_USER . '/files_encryption/keys/folder1/subfolder/subsubfolder/file2/user3.shareKey')); $this->assertTrue($this->view->file_exists( - '/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keys/folder1/subfolder/file2/user3.shareKey')); + '/' . self::TEST_USER . '/files_encryption/keys/folder1/subfolder/file2/user3.shareKey')); // check if share keys for user or file with similar name $this->assertTrue($this->view->file_exists( - '/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keys/folder1/file1/user1.test.shareKey')); + '/' . self::TEST_USER . '/files_encryption/keys/folder1/file1/user1.test.shareKey')); $this->assertTrue($this->view->file_exists( - '/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keys/folder1/file1/test-keymanager-userxdot.shareKey')); + '/' . self::TEST_USER . '/files_encryption/keys/folder1/file1/test-keymanager-userxdot.shareKey')); $this->assertTrue($this->view->file_exists( - '/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keys/folder1/file1/' . Test_Encryption_Keymanager::TEST_USER . '.userx.shareKey')); + '/' . self::TEST_USER . '/files_encryption/keys/folder1/file1/' . self::TEST_USER . '.userx.shareKey')); // FIXME: this case currently cannot be distinguished, needs further fixing $this->assertTrue($this->view->file_exists( - '/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keys/folder1/file1/userx.' . Test_Encryption_Keymanager::TEST_USER . '.shareKey')); + '/' . self::TEST_USER . '/files_encryption/keys/folder1/file1/userx.' . self::TEST_USER . '.shareKey')); $this->assertTrue($this->view->file_exists( - '/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keys/folder1/file1/user1.' . Test_Encryption_Keymanager::TEST_USER . '.shareKey')); + '/' . self::TEST_USER . '/files_encryption/keys/folder1/file1/user1.' . self::TEST_USER . '.shareKey')); $this->assertTrue($this->view->file_exists( - '/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keys/folder1/file1/' . Test_Encryption_Keymanager::TEST_USER . '.user1.shareKey')); + '/' . self::TEST_USER . '/files_encryption/keys/folder1/file1/' . self::TEST_USER . '.user1.shareKey')); // owner key from existing file should still exists because the file is still there $this->assertTrue($this->view->file_exists( - '/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keys/folder1/existingFile.txt/' . Test_Encryption_Keymanager::TEST_USER . '.shareKey')); + '/' . self::TEST_USER . '/files_encryption/keys/folder1/existingFile.txt/' . self::TEST_USER . '.shareKey')); // cleanup - $this->view->deleteAll('/'.Test_Encryption_Keymanager::TEST_USER.'/files/folder1'); + $this->view->deleteAll('/' . self::TEST_USER . '/files/folder1'); } @@ -304,44 +304,44 @@ class Test_Encryption_Keymanager extends \OCA\Files_Encryption\Tests\TestCase { */ function testRecursiveDelShareKeysFile() { - $this->view->mkdir('/'.Test_Encryption_Keymanager::TEST_USER.'/files/folder1'); - $this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files/folder1/existingFile.txt', 'data'); + $this->view->mkdir('/' . self::TEST_USER . '/files/folder1'); + $this->view->file_put_contents('/' . self::TEST_USER . '/files/folder1/existingFile.txt', 'data'); // create folder structure for some dummy share key files - $this->view->mkdir('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1'); + $this->view->mkdir('/' . self::TEST_USER . '/files_encryption/share-keys/folder1'); // create some dummy share keys - $this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/existingFile.txt.user1.shareKey', 'data'); - $this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/existingFile.txt.user2.shareKey', 'data'); - $this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/existingFile.txt.user3.shareKey', 'data'); - $this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/existingFile.txt.' . Test_Encryption_Keymanager::TEST_USER . '.shareKey', 'data'); + $this->view->file_put_contents('/' . self::TEST_USER . '/files_encryption/share-keys/folder1/existingFile.txt.user1.shareKey', 'data'); + $this->view->file_put_contents('/' . self::TEST_USER . '/files_encryption/share-keys/folder1/existingFile.txt.user2.shareKey', 'data'); + $this->view->file_put_contents('/' . self::TEST_USER . '/files_encryption/share-keys/folder1/existingFile.txt.user3.shareKey', 'data'); + $this->view->file_put_contents('/' . self::TEST_USER . '/files_encryption/share-keys/folder1/existingFile.txt.' . self::TEST_USER . '.shareKey', 'data'); // recursive delete share keys from user1 and user2 Keymanager::delShareKey($this->view, - array('user1', 'user2', Test_Encryption_Keymanager::TEST_USER), - Keymanager::getKeyPath($this->view, new Util($this->view, Test_Encryption_Keymanager::TEST_USER), '/folder1/existingFile.txt'), - Test_Encryption_Keymanager::TEST_USER, + array('user1', 'user2', self::TEST_USER), + Keymanager::getKeyPath($this->view, new Util($this->view, self::TEST_USER), '/folder1/existingFile.txt'), + self::TEST_USER, '/folder1/existingFile.txt'); // check if share keys from user1 and user2 are deleted $this->assertFalse($this->view->file_exists( - '/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/existingFile.user1.shareKey')); + '/' . self::TEST_USER . '/files_encryption/share-keys/folder1/existingFile.user1.shareKey')); $this->assertFalse($this->view->file_exists( - '/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/existingFile.user2.shareKey')); + '/' . self::TEST_USER . '/files_encryption/share-keys/folder1/existingFile.user2.shareKey')); // check if share keys for user3 and owner $this->assertTrue($this->view->file_exists( - '/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/existingFile.txt.' . Test_Encryption_Keymanager::TEST_USER . '.shareKey')); + '/' . self::TEST_USER . '/files_encryption/share-keys/folder1/existingFile.txt.' . self::TEST_USER . '.shareKey')); $this->assertTrue($this->view->file_exists( - '/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/existingFile.txt.user3.shareKey')); + '/' . self::TEST_USER . '/files_encryption/share-keys/folder1/existingFile.txt.user3.shareKey')); // cleanup - $this->view->deleteAll('/'.Test_Encryption_Keymanager::TEST_USER.'/files/folder1'); + $this->view->deleteAll('/' . self::TEST_USER . '/files/folder1'); } function testKeySetPreperation() { - $basePath = '/'.Test_Encryption_Keymanager::TEST_USER.'/files'; + $basePath = '/' . self::TEST_USER . '/files'; $path = '/folder1/subfolder/subsubfolder/file.txt'; $this->assertFalse($this->view->is_dir($basePath . '/testKeySetPreperation')); diff --git a/apps/files_encryption/tests/proxy.php b/apps/files_encryption/tests/proxy.php index 3cc668e636..72f223123e 100644 --- a/apps/files_encryption/tests/proxy.php +++ b/apps/files_encryption/tests/proxy.php @@ -43,20 +43,20 @@ class Test_Encryption_Proxy extends \OCA\Files_Encryption\Tests\TestCase { parent::setUpBeforeClass(); // create test user - self::loginHelper(\Test_Encryption_Proxy::TEST_ENCRYPTION_PROXY_USER1, true); + self::loginHelper(self::TEST_ENCRYPTION_PROXY_USER1, true); } protected function setUp() { parent::setUp(); // set user id - \OC_User::setUserId(\Test_Encryption_Proxy::TEST_ENCRYPTION_PROXY_USER1); - $this->userId = \Test_Encryption_Proxy::TEST_ENCRYPTION_PROXY_USER1; - $this->pass = \Test_Encryption_Proxy::TEST_ENCRYPTION_PROXY_USER1; + \OC_User::setUserId(self::TEST_ENCRYPTION_PROXY_USER1); + $this->userId = self::TEST_ENCRYPTION_PROXY_USER1; + $this->pass = self::TEST_ENCRYPTION_PROXY_USER1; // init filesystem view - $this->view = new \OC\Files\View('/'. \Test_Encryption_Proxy::TEST_ENCRYPTION_PROXY_USER1 . '/files'); - $this->rootView = new \OC\Files\View('/'. \Test_Encryption_Proxy::TEST_ENCRYPTION_PROXY_USER1 ); + $this->view = new \OC\Files\View('/'. self::TEST_ENCRYPTION_PROXY_USER1 . '/files'); + $this->rootView = new \OC\Files\View('/'. self::TEST_ENCRYPTION_PROXY_USER1 ); // init short data $this->data = 'hats'; @@ -67,7 +67,7 @@ class Test_Encryption_Proxy extends \OCA\Files_Encryption\Tests\TestCase { public static function tearDownAfterClass() { // cleanup test user - \OC_User::deleteUser(\Test_Encryption_Proxy::TEST_ENCRYPTION_PROXY_USER1); + \OC_User::deleteUser(self::TEST_ENCRYPTION_PROXY_USER1); parent::tearDownAfterClass(); } @@ -135,13 +135,13 @@ class Test_Encryption_Proxy extends \OCA\Files_Encryption\Tests\TestCase { public function isExcludedPathProvider() { return array( - array ('/' . \Test_Encryption_Proxy::TEST_ENCRYPTION_PROXY_USER1 . '/files/test.txt', false), - array (\Test_Encryption_Proxy::TEST_ENCRYPTION_PROXY_USER1 . '/files/test.txt', false), + array ('/' . self::TEST_ENCRYPTION_PROXY_USER1 . '/files/test.txt', false), + array (self::TEST_ENCRYPTION_PROXY_USER1 . '/files/test.txt', false), array ('/files/test.txt', true), - array ('/' . \Test_Encryption_Proxy::TEST_ENCRYPTION_PROXY_USER1 . '/files/versions/test.txt', false), - array ('/' . \Test_Encryption_Proxy::TEST_ENCRYPTION_PROXY_USER1 . '/files_versions/test.txt', false), - array ('/' . \Test_Encryption_Proxy::TEST_ENCRYPTION_PROXY_USER1 . '/files_trashbin/test.txt', true), - array ('/' . \Test_Encryption_Proxy::TEST_ENCRYPTION_PROXY_USER1 . '/file/test.txt', true), + array ('/' . self::TEST_ENCRYPTION_PROXY_USER1 . '/files/versions/test.txt', false), + array ('/' . self::TEST_ENCRYPTION_PROXY_USER1 . '/files_versions/test.txt', false), + array ('/' . self::TEST_ENCRYPTION_PROXY_USER1 . '/files_trashbin/test.txt', true), + array ('/' . self::TEST_ENCRYPTION_PROXY_USER1 . '/file/test.txt', true), ); } diff --git a/apps/files_encryption/tests/share.php b/apps/files_encryption/tests/share.php index 0eaff6bf87..3dd7dadcb4 100755 --- a/apps/files_encryption/tests/share.php +++ b/apps/files_encryption/tests/share.php @@ -61,15 +61,15 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase { \OC_FileProxy::register(new OCA\Files\Share\Proxy()); // create users - self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1, true); - self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2, true); - self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3, true); - self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER4, true); + self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1, true); + self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER2, true); + self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER3, true); + self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER4, true); // create group and assign users - \OC_Group::createGroup(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_GROUP1); - \OC_Group::addToGroup(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_GROUP1); - \OC_Group::addToGroup(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER4, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_GROUP1); + \OC_Group::createGroup(self::TEST_ENCRYPTION_SHARE_GROUP1); + \OC_Group::addToGroup(self::TEST_ENCRYPTION_SHARE_USER3, self::TEST_ENCRYPTION_SHARE_GROUP1); + \OC_Group::addToGroup(self::TEST_ENCRYPTION_SHARE_USER4, self::TEST_ENCRYPTION_SHARE_GROUP1); } protected function setUp() { @@ -91,7 +91,7 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase { \OC_App::disable('files_trashbin'); // login as first user - self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1); + self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1); } protected function tearDown() { @@ -107,13 +107,13 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase { public static function tearDownAfterClass() { // clean group - \OC_Group::deleteGroup(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_GROUP1); + \OC_Group::deleteGroup(self::TEST_ENCRYPTION_SHARE_GROUP1); // cleanup users - \OC_User::deleteUser(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1); - \OC_User::deleteUser(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2); - \OC_User::deleteUser(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3); - \OC_User::deleteUser(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER4); + \OC_User::deleteUser(self::TEST_ENCRYPTION_SHARE_USER1); + \OC_User::deleteUser(self::TEST_ENCRYPTION_SHARE_USER2); + \OC_User::deleteUser(self::TEST_ENCRYPTION_SHARE_USER3); + \OC_User::deleteUser(self::TEST_ENCRYPTION_SHARE_USER4); parent::tearDownAfterClass(); } @@ -125,10 +125,10 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase { */ function testShareFile($withTeardown = true) { // login as admin - self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1); + self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1); // save file with content - $cryptedFile = file_put_contents('crypt:///' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename, $this->dataShort); + $cryptedFile = file_put_contents('crypt:///' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename, $this->dataShort); // test that data was successfully written $this->assertTrue(is_int($cryptedFile)); @@ -139,7 +139,7 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase { // get the file info from previous created file $fileInfo = $this->view->getFileInfo( - '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename); + '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename); // check if we have a valid file info $this->assertTrue($fileInfo instanceof \OC\Files\FileInfo); @@ -151,22 +151,22 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase { \OC_FileProxy::$enabled = $proxyStatus; // share the file - \OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2, \OCP\Constants::PERMISSION_ALL); + \OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_ENCRYPTION_SHARE_USER2, \OCP\Constants::PERMISSION_ALL); // login as admin - self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1); + self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1); // check if share key for user1 exists $this->assertTrue($this->view->file_exists( - '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' - . $this->filename . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey')); + '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' + . $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey')); // login as user1 - self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2); + self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER2); // get file contents $retrievedCryptedFile = $this->view->file_get_contents( - '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files/' . $this->filename); + '/' . self::TEST_ENCRYPTION_SHARE_USER2 . '/files/' . $this->filename); // check if data is the same as we previously written $this->assertEquals($this->dataShort, $retrievedCryptedFile); @@ -175,25 +175,25 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase { if ($withTeardown) { // login as admin - self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1); + self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1); // unshare the file - \OCP\Share::unshare('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2); + \OCP\Share::unshare('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_ENCRYPTION_SHARE_USER2); // check if share key not exists $this->assertFalse($this->view->file_exists( - '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' - . $this->filename . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey')); + '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' + . $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey')); // cleanup - $this->view->chroot('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/'); + $this->view->chroot('/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files/'); $this->view->unlink($this->filename); $this->view->chroot('/'); // check if share key not exists $this->assertFalse($this->view->file_exists( - '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' - . $this->filename . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey')); + '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' + . $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey')); } } @@ -205,29 +205,29 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase { $this->testShareFile(false); // login as user2 - self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2); + self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER2); // get the file info $fileInfo = $this->view->getFileInfo( - '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files/' . $this->filename); + '/' . self::TEST_ENCRYPTION_SHARE_USER2 . '/files/' . $this->filename); // share the file with user3 - \OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3, \OCP\Constants::PERMISSION_ALL); + \OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_ENCRYPTION_SHARE_USER3, \OCP\Constants::PERMISSION_ALL); // login as admin - self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1); + self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1); // check if share key for user2 exists $this->assertTrue($this->view->file_exists( - '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' - . $this->filename . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '.shareKey')); + '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' + . $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER3 . '.shareKey')); // login as user2 - self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3); + self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER3); // get file contents $retrievedCryptedFile = $this->view->file_get_contents( - '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '/files/' . $this->filename); + '/' . self::TEST_ENCRYPTION_SHARE_USER3 . '/files/' . $this->filename); // check if data is the same as previously written $this->assertEquals($this->dataShort, $retrievedCryptedFile); @@ -236,36 +236,36 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase { if ($withTeardown) { // login as user1 - self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2); + self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER2); // unshare the file with user2 - \OCP\Share::unshare('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3); + \OCP\Share::unshare('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_ENCRYPTION_SHARE_USER3); // login as admin - self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1); + self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1); // check if share key not exists $this->assertFalse($this->view->file_exists( - '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' - . $this->filename . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '.shareKey')); + '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' + . $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER3 . '.shareKey')); // unshare the file with user1 - \OCP\Share::unshare('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2); + \OCP\Share::unshare('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_ENCRYPTION_SHARE_USER2); // check if share key not exists $this->assertFalse($this->view->file_exists( - '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' - . $this->filename . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey')); + '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' + . $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey')); // cleanup - $this->view->chroot('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/'); + $this->view->chroot('/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files/'); $this->view->unlink($this->filename); $this->view->chroot('/'); // check if share key not exists $this->assertFalse($this->view->file_exists( - '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' - . $this->filename . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey')); + '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' + . $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey')); } } @@ -276,18 +276,18 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase { */ function testShareFolder($withTeardown = true) { // login as admin - self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1); + self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1); // create folder structure - $this->view->mkdir('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files' . $this->folder1); + $this->view->mkdir('/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files' . $this->folder1); $this->view->mkdir( - '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files' . $this->folder1 . $this->subfolder); + '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files' . $this->folder1 . $this->subfolder); $this->view->mkdir( - '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files' . $this->folder1 . $this->subfolder + '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files' . $this->folder1 . $this->subfolder . $this->subsubfolder); // save file with content - $cryptedFile = file_put_contents('crypt:///' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->folder1 . $this->subfolder . $this->subsubfolder . '/' + $cryptedFile = file_put_contents('crypt:///' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->folder1 . $this->subfolder . $this->subsubfolder . '/' . $this->filename, $this->dataShort); // test that data was successfully written @@ -299,7 +299,7 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase { // get the file info from previous created folder $fileInfo = $this->view->getFileInfo( - '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files' . $this->folder1); + '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files' . $this->folder1); // check if we have a valid file info $this->assertTrue($fileInfo instanceof \OC\Files\FileInfo); @@ -308,23 +308,23 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase { \OC_FileProxy::$enabled = $proxyStatus; // share the folder with user1 - \OCP\Share::shareItem('folder', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2, \OCP\Constants::PERMISSION_ALL); + \OCP\Share::shareItem('folder', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_ENCRYPTION_SHARE_USER2, \OCP\Constants::PERMISSION_ALL); // login as admin - self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1); + self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1); // check if share key for user1 exists $this->assertTrue($this->view->file_exists( - '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys' . $this->folder1 + '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys' . $this->folder1 . $this->subfolder . $this->subsubfolder . '/' - . $this->filename . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey')); + . $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey')); // login as user1 - self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2); + self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER2); // get file contents $retrievedCryptedFile = $this->view->file_get_contents( - '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files/' . $this->folder1 + '/' . self::TEST_ENCRYPTION_SHARE_USER2 . '/files/' . $this->folder1 . $this->subfolder . $this->subsubfolder . '/' . $this->filename); // check if data is the same @@ -334,27 +334,27 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase { if ($withTeardown) { // login as admin - self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1); + self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1); // unshare the folder with user1 - \OCP\Share::unshare('folder', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2); + \OCP\Share::unshare('folder', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_ENCRYPTION_SHARE_USER2); // check if share key not exists $this->assertFalse($this->view->file_exists( - '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys' + '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys' . $this->folder1 . $this->subfolder . $this->subsubfolder . '/' - . $this->filename . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey')); + . $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey')); // cleanup - $this->view->chroot('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files'); + $this->view->chroot('/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files'); $this->view->unlink($this->folder1); $this->view->chroot('/'); // check if share key not exists $this->assertFalse($this->view->file_exists( - '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys' + '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys' . $this->folder1 . $this->subfolder . $this->subsubfolder . '/' - . $this->filename . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey')); + . $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey')); } return $fileInfo; @@ -368,7 +368,7 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase { $fileInfoFolder1 = $this->testShareFolder(false); // login as user2 - self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2); + self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER2); // disable encryption proxy to prevent recursive calls $proxyStatus = \OC_FileProxy::$enabled; @@ -376,7 +376,7 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase { // get the file info from previous created folder $fileInfoSubFolder = $this->view->getFileInfo( - '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files/' . $this->folder1 + '/' . self::TEST_ENCRYPTION_SHARE_USER2 . '/files/' . $this->folder1 . $this->subfolder); // check if we have a valid file info @@ -386,23 +386,23 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase { \OC_FileProxy::$enabled = $proxyStatus; // share the file with user3 - \OCP\Share::shareItem('folder', $fileInfoSubFolder['fileid'], \OCP\Share::SHARE_TYPE_USER, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3, \OCP\Constants::PERMISSION_ALL); + \OCP\Share::shareItem('folder', $fileInfoSubFolder['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_ENCRYPTION_SHARE_USER3, \OCP\Constants::PERMISSION_ALL); // login as admin - self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1); + self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1); // check if share key for user3 exists $this->assertTrue($this->view->file_exists( - '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys' . $this->folder1 + '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys' . $this->folder1 . $this->subfolder . $this->subsubfolder . '/' - . $this->filename . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '.shareKey')); + . $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER3 . '.shareKey')); // login as user3 - self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3); + self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER3); // get file contents $retrievedCryptedFile = $this->view->file_get_contents( - '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '/files/' . $this->subfolder + '/' . self::TEST_ENCRYPTION_SHARE_USER3 . '/files/' . $this->subfolder . $this->subsubfolder . '/' . $this->filename); // check if data is the same @@ -410,30 +410,30 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase { // get the file info $fileInfo = $this->view->getFileInfo( - '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '/files/' . $this->subfolder + '/' . self::TEST_ENCRYPTION_SHARE_USER3 . '/files/' . $this->subfolder . $this->subsubfolder . '/' . $this->filename); // check if we have fileInfos $this->assertTrue($fileInfo instanceof \OC\Files\FileInfo); // share the file with user3 - \OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER4, \OCP\Constants::PERMISSION_ALL); + \OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_ENCRYPTION_SHARE_USER4, \OCP\Constants::PERMISSION_ALL); // login as admin - self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1); + self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1); // check if share key for user3 exists $this->assertTrue($this->view->file_exists( - '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys' . $this->folder1 + '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys' . $this->folder1 . $this->subfolder . $this->subsubfolder . '/' - . $this->filename . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER4 . '.shareKey')); + . $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER4 . '.shareKey')); // login as user3 - self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER4); + self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER4); // get file contents $retrievedCryptedFile = $this->view->file_get_contents( - '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER4 . '/files/' . $this->filename); + '/' . self::TEST_ENCRYPTION_SHARE_USER4 . '/files/' . $this->filename); // check if data is the same $this->assertEquals($this->dataShort, $retrievedCryptedFile); @@ -442,61 +442,61 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase { if ($withTeardown) { // login as user2 - self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3); + self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER3); // unshare the file with user3 - \OCP\Share::unshare('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER4); + \OCP\Share::unshare('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_ENCRYPTION_SHARE_USER4); // check if share key not exists $this->assertFalse($this->view->file_exists( - '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys' + '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys' . $this->folder1 . $this->subfolder . $this->subsubfolder . '/' - . $this->filename . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER4 . '.shareKey')); + . $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER4 . '.shareKey')); // login as user1 - self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2); + self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER2); // unshare the folder with user2 - \OCP\Share::unshare('folder', $fileInfoSubFolder['fileid'], \OCP\Share::SHARE_TYPE_USER, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3); + \OCP\Share::unshare('folder', $fileInfoSubFolder['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_ENCRYPTION_SHARE_USER3); // check if share key not exists $this->assertFalse($this->view->file_exists( - '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys' + '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys' . $this->folder1 . $this->subfolder . $this->subsubfolder . '/' - . $this->filename . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '.shareKey')); + . $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER3 . '.shareKey')); // login as admin - self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1); + self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1); // unshare the folder1 with user1 - \OCP\Share::unshare('folder', $fileInfoFolder1['fileid'], \OCP\Share::SHARE_TYPE_USER, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2); + \OCP\Share::unshare('folder', $fileInfoFolder1['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_ENCRYPTION_SHARE_USER2); // check if share key not exists $this->assertFalse($this->view->file_exists( - '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys' + '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys' . $this->folder1 . $this->subfolder . $this->subsubfolder . '/' - . $this->filename . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey')); + . $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey')); // cleanup - $this->view->chroot('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files'); + $this->view->chroot('/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files'); $this->view->unlink($this->folder1 . $this->subfolder . $this->subsubfolder . '/' . $this->filename); $this->view->chroot('/'); // check if share key not exists $this->assertFalse($this->view->file_exists( - '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys' + '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys' . $this->folder1 . $this->subfolder . $this->subsubfolder . '/' - . $this->filename . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey')); + . $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey')); } } function testPublicShareFile() { // login as admin - self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1); + self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1); // save file with content - $cryptedFile = file_put_contents('crypt:///' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename, $this->dataShort); + $cryptedFile = file_put_contents('crypt:///' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename, $this->dataShort); // test that data was successfully written $this->assertTrue(is_int($cryptedFile)); @@ -507,7 +507,7 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase { // get the file info from previous created file $fileInfo = $this->view->getFileInfo( - '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename); + '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename); // check if we have a valid file info $this->assertTrue($fileInfo instanceof \OC\Files\FileInfo); @@ -522,22 +522,22 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase { \OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_LINK, false, \OCP\Constants::PERMISSION_ALL); // login as admin - self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1); + self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1); $publicShareKeyId = \OC::$server->getAppConfig()->getValue('files_encryption', 'publicShareKeyId'); // check if share key for public exists $this->assertTrue($this->view->file_exists( - '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' + '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' . $this->filename . '/' . $publicShareKeyId . '.shareKey')); // some hacking to simulate public link //$GLOBALS['app'] = 'files_sharing'; - //$GLOBALS['fileOwner'] = \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1; + //$GLOBALS['fileOwner'] = self::TEST_ENCRYPTION_SHARE_USER1; self::logoutHelper(); // get file contents - $retrievedCryptedFile = file_get_contents('crypt:///' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename); + $retrievedCryptedFile = file_get_contents('crypt:///' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename); // check if data is the same as we previously written $this->assertEquals($this->dataShort, $retrievedCryptedFile); @@ -545,25 +545,25 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase { // tear down // login as admin - self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1); + self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1); // unshare the file \OCP\Share::unshare('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_LINK, null); // check if share key not exists $this->assertFalse($this->view->file_exists( - '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' + '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' . $this->filename . '/' . $publicShareKeyId . '.shareKey')); // cleanup - $this->view->chroot('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/'); + $this->view->chroot('/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files/'); $this->view->unlink($this->filename); $this->view->chroot('/'); // check if share key not exists $this->assertFalse($this->view->file_exists( - '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' - . $this->filename . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey')); + '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' + . $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey')); } /** @@ -571,10 +571,10 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase { */ function testShareFileWithGroup() { // login as admin - self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1); + self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1); // save file with content - $cryptedFile = file_put_contents('crypt:///' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename, $this->dataShort); + $cryptedFile = file_put_contents('crypt:///' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename, $this->dataShort); // test that data was successfully written $this->assertTrue(is_int($cryptedFile)); @@ -585,7 +585,7 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase { // get the file info from previous created file $fileInfo = $this->view->getFileInfo( - '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename); + '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename); // check if we have a valid file info $this->assertTrue($fileInfo instanceof \OC\Files\FileInfo); @@ -597,52 +597,52 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase { \OC_FileProxy::$enabled = $proxyStatus; // share the file - \OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_GROUP1, \OCP\Constants::PERMISSION_ALL); + \OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP, self::TEST_ENCRYPTION_SHARE_GROUP1, \OCP\Constants::PERMISSION_ALL); // login as admin - self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1); + self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1); // check if share key for user2 and user3 exists $this->assertTrue($this->view->file_exists( - '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' - . $this->filename . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '.shareKey')); + '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' + . $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER3 . '.shareKey')); $this->assertTrue($this->view->file_exists( - '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' - . $this->filename . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER4 . '.shareKey')); + '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' + . $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER4 . '.shareKey')); // login as user1 - self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3); + self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER3); // get file contents $retrievedCryptedFile = $this->view->file_get_contents( - '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '/files/' . $this->filename); + '/' . self::TEST_ENCRYPTION_SHARE_USER3 . '/files/' . $this->filename); // check if data is the same as we previously written $this->assertEquals($this->dataShort, $retrievedCryptedFile); // login as admin - self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1); + self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1); // unshare the file - \OCP\Share::unshare('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_GROUP1); + \OCP\Share::unshare('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP, self::TEST_ENCRYPTION_SHARE_GROUP1); // check if share key not exists $this->assertFalse($this->view->file_exists( - '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' - . $this->filename . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '.shareKey')); + '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' + . $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER3 . '.shareKey')); $this->assertFalse($this->view->file_exists( - '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' - . $this->filename . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER4 . '.shareKey')); + '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' + . $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER4 . '.shareKey')); // cleanup - $this->view->chroot('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/'); + $this->view->chroot('/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files/'); $this->view->unlink($this->filename); $this->view->chroot('/'); // check if share key not exists $this->assertFalse($this->view->file_exists( - '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' - . $this->filename . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey')); + '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' + . $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey')); } @@ -652,15 +652,15 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase { function testRecoveryFile() { // login as admin - self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1); + self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1); Helper::adminEnableRecovery(null, 'test123'); $recoveryKeyId = \OC::$server->getAppConfig()->getValue('files_encryption', 'recoveryKeyId'); // login as admin - self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1); + self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1); - $util = new Util(new \OC\Files\View('/'), \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1); + $util = new Util(new \OC\Files\View('/'), self::TEST_ENCRYPTION_SHARE_USER1); // check if recovery password match $this->assertTrue($util->checkRecoveryPassword('test123')); @@ -670,16 +670,16 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase { $util->addRecoveryKeys(); // create folder structure - $this->view->mkdir('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files' . $this->folder1); + $this->view->mkdir('/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files' . $this->folder1); $this->view->mkdir( - '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files' . $this->folder1 . $this->subfolder); + '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files' . $this->folder1 . $this->subfolder); $this->view->mkdir( - '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files' . $this->folder1 . $this->subfolder + '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files' . $this->folder1 . $this->subfolder . $this->subsubfolder); // save file with content - $cryptedFile1 = file_put_contents('crypt:///' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename, $this->dataShort); - $cryptedFile2 = file_put_contents('crypt:///' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->folder1 . $this->subfolder . $this->subsubfolder . '/' + $cryptedFile1 = file_put_contents('crypt:///' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename, $this->dataShort); + $cryptedFile2 = file_put_contents('crypt:///' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->folder1 . $this->subfolder . $this->subsubfolder . '/' . $this->filename, $this->dataShort); // test that data was successfully written @@ -688,17 +688,17 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase { // check if share key for admin and recovery exists $this->assertTrue($this->view->file_exists( - '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' - . $this->filename . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey')); + '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' + . $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey')); $this->assertTrue($this->view->file_exists( - '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' + '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' . $this->filename . '/' . $recoveryKeyId . '.shareKey')); $this->assertTrue($this->view->file_exists( - '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' . $this->folder1 + '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' . $this->folder1 . $this->subfolder . $this->subsubfolder . '/' - . $this->filename . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey')); + . $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey')); $this->assertTrue($this->view->file_exists( - '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' . $this->folder1 + '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' . $this->folder1 . $this->subfolder . $this->subsubfolder . '/' . $this->filename . '/' . $recoveryKeyId . '.shareKey')); @@ -710,10 +710,10 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase { // check if share key for recovery not exists $this->assertFalse($this->view->file_exists( - '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' + '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' . $this->filename . '/' . $recoveryKeyId . '.shareKey')); $this->assertFalse($this->view->file_exists( - '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' . $this->folder1 + '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' . $this->folder1 . $this->subfolder . $this->subsubfolder . '/' . $this->filename . '/' . $recoveryKeyId . '.shareKey')); @@ -725,25 +725,25 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase { // check if share key for admin and recovery exists $this->assertTrue($this->view->file_exists( - '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' + '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' . $this->filename . '/' . $recoveryKeyId . '.shareKey')); $this->assertTrue($this->view->file_exists( - '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' . $this->folder1 + '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' . $this->folder1 . $this->subfolder . $this->subsubfolder . '/' . $this->filename . '/' . $recoveryKeyId . '.shareKey')); // cleanup - $this->view->chroot('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/'); + $this->view->chroot('/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files/'); $this->view->unlink($this->filename); $this->view->unlink($this->folder1); $this->view->chroot('/'); // check if share key for recovery not exists $this->assertFalse($this->view->file_exists( - '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' + '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' . $this->filename . '/' . $recoveryKeyId . '.shareKey')); $this->assertFalse($this->view->file_exists( - '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' . $this->folder1 + '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' . $this->folder1 . $this->subfolder . $this->subsubfolder . '/' . $this->filename . '/' . $recoveryKeyId . '.shareKey')); @@ -758,7 +758,7 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase { function testRecoveryForUser() { // login as admin - self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1); + self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1); $result = Helper::adminEnableRecovery(null, 'test123'); $this->assertTrue($result); @@ -766,9 +766,9 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase { $recoveryKeyId = \OC::$server->getAppConfig()->getValue('files_encryption', 'recoveryKeyId'); // login as user2 - self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2); + self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER2); - $util = new Util(new \OC\Files\View('/'), \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2); + $util = new Util(new \OC\Files\View('/'), self::TEST_ENCRYPTION_SHARE_USER2); // enable recovery for admin $this->assertTrue($util->setRecoveryForUser(1)); @@ -777,16 +777,16 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase { $util->addRecoveryKeys(); // create folder structure - $this->view->mkdir('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files' . $this->folder1); + $this->view->mkdir('/' . self::TEST_ENCRYPTION_SHARE_USER2 . '/files' . $this->folder1); $this->view->mkdir( - '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files' . $this->folder1 . $this->subfolder); + '/' . self::TEST_ENCRYPTION_SHARE_USER2 . '/files' . $this->folder1 . $this->subfolder); $this->view->mkdir( - '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files' . $this->folder1 . $this->subfolder + '/' . self::TEST_ENCRYPTION_SHARE_USER2 . '/files' . $this->folder1 . $this->subfolder . $this->subsubfolder); // save file with content - $cryptedFile1 = file_put_contents('crypt:///' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2. '/files/' . $this->filename, $this->dataShort); - $cryptedFile2 = file_put_contents('crypt:///' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files/' . $this->folder1 . $this->subfolder . $this->subsubfolder . '/' + $cryptedFile1 = file_put_contents('crypt:///' . self::TEST_ENCRYPTION_SHARE_USER2. '/files/' . $this->filename, $this->dataShort); + $cryptedFile2 = file_put_contents('crypt:///' . self::TEST_ENCRYPTION_SHARE_USER2 . '/files/' . $this->folder1 . $this->subfolder . $this->subsubfolder . '/' . $this->filename, $this->dataShort); // test that data was successfully written @@ -795,61 +795,61 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase { // check if share key for user and recovery exists $this->assertTrue($this->view->file_exists( - '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files_encryption/keys/' - . $this->filename . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey')); + '/' . self::TEST_ENCRYPTION_SHARE_USER2 . '/files_encryption/keys/' + . $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey')); $this->assertTrue($this->view->file_exists( - '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files_encryption/keys/' + '/' . self::TEST_ENCRYPTION_SHARE_USER2 . '/files_encryption/keys/' . $this->filename . '/' . $recoveryKeyId . '.shareKey')); $this->assertTrue($this->view->file_exists( - '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files_encryption/keys/' . $this->folder1 + '/' . self::TEST_ENCRYPTION_SHARE_USER2 . '/files_encryption/keys/' . $this->folder1 . $this->subfolder . $this->subsubfolder . '/' - . $this->filename . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey')); + . $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey')); $this->assertTrue($this->view->file_exists( - '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files_encryption/keys/' . $this->folder1 + '/' . self::TEST_ENCRYPTION_SHARE_USER2 . '/files_encryption/keys/' . $this->folder1 . $this->subfolder . $this->subsubfolder . '/' . $this->filename . '/' . $recoveryKeyId . '.shareKey')); // login as admin - self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1); + self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1); // change password - \OC_User::setPassword(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2, 'test', 'test123'); - $params = array('uid' => \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2, + \OC_User::setPassword(self::TEST_ENCRYPTION_SHARE_USER2, 'test', 'test123'); + $params = array('uid' => self::TEST_ENCRYPTION_SHARE_USER2, 'password' => 'test', 'recoveryPassword' => 'test123'); Hooks::setPassphrase($params); // login as user2 - self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2, false, 'test'); + self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER2, false, 'test'); // get file contents - $retrievedCryptedFile1 = file_get_contents('crypt:///' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files/' . $this->filename); + $retrievedCryptedFile1 = file_get_contents('crypt:///' . self::TEST_ENCRYPTION_SHARE_USER2 . '/files/' . $this->filename); $retrievedCryptedFile2 = file_get_contents( - 'crypt:///' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files' . $this->folder1 . $this->subfolder . $this->subsubfolder . '/' . $this->filename); + 'crypt:///' . self::TEST_ENCRYPTION_SHARE_USER2 . '/files' . $this->folder1 . $this->subfolder . $this->subsubfolder . '/' . $this->filename); // check if data is the same as we previously written $this->assertEquals($this->dataShort, $retrievedCryptedFile1); $this->assertEquals($this->dataShort, $retrievedCryptedFile2); // cleanup - $this->view->chroot('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files/'); + $this->view->chroot('/' . self::TEST_ENCRYPTION_SHARE_USER2 . '/files/'); $this->view->unlink($this->folder1); $this->view->unlink($this->filename); $this->view->chroot('/'); // check if share key for user and recovery exists $this->assertFalse($this->view->file_exists( - '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files_encryption/keys/' - . $this->filename . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey')); + '/' . self::TEST_ENCRYPTION_SHARE_USER2 . '/files_encryption/keys/' + . $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey')); $this->assertFalse($this->view->file_exists( - '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files_encryption/keys/' + '/' . self::TEST_ENCRYPTION_SHARE_USER2 . '/files_encryption/keys/' . $this->filename . '/' . $recoveryKeyId . '.shareKey')); $this->assertFalse($this->view->file_exists( - '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files_encryption/keys/' . $this->folder1 + '/' . self::TEST_ENCRYPTION_SHARE_USER2 . '/files_encryption/keys/' . $this->folder1 . $this->subfolder . $this->subsubfolder . '/' - . $this->filename . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey')); + . $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey')); $this->assertFalse($this->view->file_exists( - '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files_encryption/keys/' . $this->folder1 + '/' . self::TEST_ENCRYPTION_SHARE_USER2 . '/files_encryption/keys/' . $this->folder1 . $this->subfolder . $this->subsubfolder . '/' . $this->filename . '/' . $recoveryKeyId . '.shareKey')); @@ -860,9 +860,9 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase { $this->assertEquals(0, \OC::$server->getAppConfig()->getValue('files_encryption', 'recoveryAdminEnabled')); //clean up, reset passwords - \OC_User::setPassword(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2, 'test123'); - $params = array('uid' => \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2, - 'password' => \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2, + \OC_User::setPassword(self::TEST_ENCRYPTION_SHARE_USER2, self::TEST_ENCRYPTION_SHARE_USER2, 'test123'); + $params = array('uid' => self::TEST_ENCRYPTION_SHARE_USER2, + 'password' => self::TEST_ENCRYPTION_SHARE_USER2, 'recoveryPassword' => 'test123'); Hooks::setPassphrase($params); } @@ -872,10 +872,10 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase { */ function testFailShareFile() { // login as admin - self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1); + self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1); // save file with content - $cryptedFile = file_put_contents('crypt:///' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename, $this->dataShort); + $cryptedFile = file_put_contents('crypt:///' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename, $this->dataShort); // test that data was successfully written $this->assertTrue(is_int($cryptedFile)); @@ -886,7 +886,7 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase { // get the file info from previous created file $fileInfo = $this->view->getFileInfo( - '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename); + '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename); // check if we have a valid file info $this->assertTrue($fileInfo instanceof \OC\Files\FileInfo); @@ -895,27 +895,27 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase { $this->assertGreaterThan(0, $fileInfo['unencrypted_size']); // break users public key - $this->view->rename(Keymanager::getPublicKeyPath() . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '.publicKey', - Keymanager::getPublicKeyPath() . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '.publicKey_backup'); + $this->view->rename(Keymanager::getPublicKeyPath() . '/' . self::TEST_ENCRYPTION_SHARE_USER3 . '.publicKey', + Keymanager::getPublicKeyPath() . '/' . self::TEST_ENCRYPTION_SHARE_USER3 . '.publicKey_backup'); // re-enable the file proxy \OC_FileProxy::$enabled = $proxyStatus; // share the file try { - \OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_GROUP1, \OCP\Constants::PERMISSION_ALL); + \OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP, self::TEST_ENCRYPTION_SHARE_GROUP1, \OCP\Constants::PERMISSION_ALL); } catch (Exception $e) { $this->assertEquals(0, strpos($e->getMessage(), "Following users are not set up for encryption")); } // login as admin - self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1); + self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1); // check if share key for user1 not exists $this->assertFalse($this->view->file_exists( - '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' - . $this->filename . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '.shareKey')); + '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' + . $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER3 . '.shareKey')); // disable encryption proxy to prevent recursive calls $proxyStatus = \OC_FileProxy::$enabled; @@ -923,27 +923,27 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase { // break user1 public key $this->view->rename( - Keymanager::getPublicKeyPath() . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '.publicKey_backup', - Keymanager::getPublicKeyPath() . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '.publicKey'); + Keymanager::getPublicKeyPath() . '/' . self::TEST_ENCRYPTION_SHARE_USER3 . '.publicKey_backup', + Keymanager::getPublicKeyPath() . '/' . self::TEST_ENCRYPTION_SHARE_USER3 . '.publicKey'); // remove share file - $this->view->unlink('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' - . $this->filename . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 + $this->view->unlink('/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' + . $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER3 . '.shareKey'); // re-enable the file proxy \OC_FileProxy::$enabled = $proxyStatus; // unshare the file with user1 - \OCP\Share::unshare('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_GROUP1); + \OCP\Share::unshare('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP, self::TEST_ENCRYPTION_SHARE_GROUP1); // check if share key not exists $this->assertFalse($this->view->file_exists( - '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' - . $this->filename . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '.shareKey')); + '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' + . $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER3 . '.shareKey')); // cleanup - $this->view->chroot('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/'); + $this->view->chroot('/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files/'); $this->view->unlink($this->filename); $this->view->chroot('/'); } @@ -955,56 +955,56 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase { function testRename() { // login as admin - self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1); + self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1); // save file with content - $cryptedFile = file_put_contents('crypt:///' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename, $this->dataShort); + $cryptedFile = file_put_contents('crypt:///' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename, $this->dataShort); // test that data was successfully written $this->assertTrue(is_int($cryptedFile)); // get the file info from previous created file $fileInfo = $this->view->getFileInfo( - '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename); + '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename); // check if we have a valid file info $this->assertTrue($fileInfo instanceof \OC\Files\FileInfo); // share the file - \OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2, \OCP\Constants::PERMISSION_ALL); + \OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_ENCRYPTION_SHARE_USER2, \OCP\Constants::PERMISSION_ALL); // check if share key for user2 exists $this->assertTrue($this->view->file_exists( - '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' - . $this->filename . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey')); + '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' + . $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey')); // login as user2 - self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2); + self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER2); - $this->assertTrue($this->view->file_exists('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files/' . $this->filename)); + $this->assertTrue($this->view->file_exists('/' . self::TEST_ENCRYPTION_SHARE_USER2 . '/files/' . $this->filename)); // get file contents $retrievedCryptedFile = $this->view->file_get_contents( - '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files/' . $this->filename); + '/' . self::TEST_ENCRYPTION_SHARE_USER2 . '/files/' . $this->filename); // check if data is the same as we previously written $this->assertEquals($this->dataShort, $retrievedCryptedFile); // move the file to a subfolder - $this->view->rename('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files/' . $this->filename, - '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files/' . $this->folder1 . $this->filename); + $this->view->rename('/' . self::TEST_ENCRYPTION_SHARE_USER2 . '/files/' . $this->filename, + '/' . self::TEST_ENCRYPTION_SHARE_USER2 . '/files/' . $this->folder1 . $this->filename); // check if we can read the moved file $retrievedRenamedFile = $this->view->file_get_contents( - '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files/' . $this->folder1 . $this->filename); + '/' . self::TEST_ENCRYPTION_SHARE_USER2 . '/files/' . $this->folder1 . $this->filename); // check if data is the same as we previously written $this->assertEquals($this->dataShort, $retrievedRenamedFile); // cleanup - self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1); - $this->view->unlink('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename); + self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1); + $this->view->unlink('/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename); } /** @@ -1013,7 +1013,7 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase { */ function testMoveFolder() { - $view = new \OC\Files\View('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1); + $view = new \OC\Files\View('/' . self::TEST_ENCRYPTION_SHARE_USER1); $filename = '/tmp-' . $this->getUniqueID(); $folder = '/folder' . $this->getUniqueID(); @@ -1039,7 +1039,7 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase { $this->assertTrue($fileInfo instanceof \OC\Files\FileInfo); // share the folder - \OCP\Share::shareItem('folder', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2, \OCP\Constants::PERMISSION_ALL); + \OCP\Share::shareItem('folder', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_ENCRYPTION_SHARE_USER2, \OCP\Constants::PERMISSION_ALL); \OC\Files\Filesystem::rename($folder, $newFolder); @@ -1048,10 +1048,10 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase { $this->assertEquals($this->dataShort, $newDecrypt); // check if additional share key for user2 exists - $this->assertTrue($view->file_exists('files_encryption/keys' . $newFolder . '/' . $filename . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey')); + $this->assertTrue($view->file_exists('files_encryption/keys' . $newFolder . '/' . $filename . '/' . self::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey')); // check that old keys were removed/moved properly - $this->assertFalse($view->file_exists('files_encryption/keys' . $folder . '/' . $filename . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey')); + $this->assertFalse($view->file_exists('files_encryption/keys' . $folder . '/' . $filename . '/' . self::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey')); // tear down \OC\Files\Filesystem::unlink($newFolder); @@ -1061,9 +1061,9 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase { function usersProvider() { return array( // test as owner - array(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1), + array(self::TEST_ENCRYPTION_SHARE_USER1), // test as share receiver - array(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2), + array(self::TEST_ENCRYPTION_SHARE_USER2), ); } @@ -1071,7 +1071,7 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase { * @dataProvider usersProvider */ function testMoveFileToFolder($userId) { - $view = new \OC\Files\View('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1); + $view = new \OC\Files\View('/' . self::TEST_ENCRYPTION_SHARE_USER1); $filename = '/tmp-' . $this->getUniqueID(); $folder = '/folder' . $this->getUniqueID(); @@ -1097,28 +1097,28 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase { $this->assertTrue($fileInfo instanceof \OC\Files\FileInfo); // share the folder - \OCP\Share::shareItem('folder', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2, \OCP\Constants::PERMISSION_ALL); + \OCP\Share::shareItem('folder', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_ENCRYPTION_SHARE_USER2, \OCP\Constants::PERMISSION_ALL); // check that the share keys exist - $this->assertTrue($view->file_exists('files_encryption/keys' . $folder . '/' . $filename . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey')); - $this->assertTrue($view->file_exists('files_encryption/keys' . $folder . '/' . $filename . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey')); + $this->assertTrue($view->file_exists('files_encryption/keys' . $folder . '/' . $filename . '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey')); + $this->assertTrue($view->file_exists('files_encryption/keys' . $folder . '/' . $filename . '/' . self::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey')); // move the file into the subfolder as the test user self::loginHelper($userId); \OC\Files\Filesystem::rename($folder . $filename, $subFolder . $filename); - self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1); + self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1); // Get file decrypted contents $newDecrypt = \OC\Files\Filesystem::file_get_contents($subFolder . $filename); $this->assertEquals($this->dataShort, $newDecrypt); // check if additional share key for user2 exists - $this->assertTrue($view->file_exists('files_encryption/keys' . $subFolder . '/' . $filename . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey')); - $this->assertTrue($view->file_exists('files_encryption/keys' . $subFolder . '/' . $filename . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey')); + $this->assertTrue($view->file_exists('files_encryption/keys' . $subFolder . '/' . $filename . '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey')); + $this->assertTrue($view->file_exists('files_encryption/keys' . $subFolder . '/' . $filename . '/' . self::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey')); // check that old keys were removed/moved properly - $this->assertFalse($view->file_exists('files_encryption/keys' . $folder . '/' . $filename . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey')); - $this->assertFalse($view->file_exists('files_encryption/keys' . $folder . '/' . $filename . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey')); + $this->assertFalse($view->file_exists('files_encryption/keys' . $folder . '/' . $filename . '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey')); + $this->assertFalse($view->file_exists('files_encryption/keys' . $folder . '/' . $filename . '/' . self::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey')); // tear down \OC\Files\Filesystem::unlink($subFolder); diff --git a/apps/files_encryption/tests/stream.php b/apps/files_encryption/tests/stream.php index 08d4ddcf5b..7afe8a8850 100644 --- a/apps/files_encryption/tests/stream.php +++ b/apps/files_encryption/tests/stream.php @@ -41,16 +41,16 @@ class Test_Encryption_Stream extends \OCA\Files_Encryption\Tests\TestCase { parent::setUpBeforeClass(); // create test user - self::loginHelper(\Test_Encryption_Stream::TEST_ENCRYPTION_STREAM_USER1, true); + self::loginHelper(self::TEST_ENCRYPTION_STREAM_USER1, true); } protected function setUp() { parent::setUp(); // set user id - \OC_User::setUserId(\Test_Encryption_Stream::TEST_ENCRYPTION_STREAM_USER1); - $this->userId = \Test_Encryption_Stream::TEST_ENCRYPTION_STREAM_USER1; - $this->pass = \Test_Encryption_Stream::TEST_ENCRYPTION_STREAM_USER1; + \OC_User::setUserId(self::TEST_ENCRYPTION_STREAM_USER1); + $this->userId = self::TEST_ENCRYPTION_STREAM_USER1; + $this->pass = self::TEST_ENCRYPTION_STREAM_USER1; // init filesystem view $this->view = new \OC\Files\View('/'); @@ -79,7 +79,7 @@ class Test_Encryption_Stream extends \OCA\Files_Encryption\Tests\TestCase { public static function tearDownAfterClass() { // cleanup test user - \OC_User::deleteUser(\Test_Encryption_Stream::TEST_ENCRYPTION_STREAM_USER1); + \OC_User::deleteUser(self::TEST_ENCRYPTION_STREAM_USER1); parent::tearDownAfterClass(); } diff --git a/apps/files_encryption/tests/trashbin.php b/apps/files_encryption/tests/trashbin.php index d8af31760e..9b2d3039f9 100755 --- a/apps/files_encryption/tests/trashbin.php +++ b/apps/files_encryption/tests/trashbin.php @@ -171,7 +171,7 @@ class Test_Encryption_Trashbin extends \OCA\Files_Encryption\Tests\TestCase { // check if we found the file we created $this->assertNotNull($trashFileSuffix); - $this->assertTrue($this->view->is_dir('/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_trashbin/keys/' . $filename . '.' . $trashFileSuffix)); + $this->assertTrue($this->view->is_dir('/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_trashbin/keys/' . $filename . '.' . $trashFileSuffix)); // check if key for admin not exists $this->assertTrue($this->view->file_exists( @@ -217,10 +217,10 @@ class Test_Encryption_Trashbin extends \OCA\Files_Encryption\Tests\TestCase { // before calling the restore operation the keys shouldn't be there $this->assertFalse($this->view->file_exists( - '/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/keys/' . $filename . '/fileKey')); + '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/keys/' . $filename . '/fileKey')); $this->assertFalse($this->view->file_exists( - '/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/keys/' - . $filename . '/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '.shareKey')); + '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/keys/' + . $filename . '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '.shareKey')); // restore first file $this->assertTrue(\OCA\Files_Trashbin\Trashbin::restore($filename . '.' . $trashFileSuffix, $filename, $timestamp)); diff --git a/apps/files_encryption/tests/util.php b/apps/files_encryption/tests/util.php index 8496772a13..9d8b45213d 100755 --- a/apps/files_encryption/tests/util.php +++ b/apps/files_encryption/tests/util.php @@ -553,13 +553,13 @@ class Test_Encryption_Util extends \OCA\Files_Encryption\Tests\TestCase { $publicShareKeyId, $recoveryKeyId, ); - \Test_Encryption_Util::loginHelper('readyUser', true); - \Test_Encryption_Util::loginHelper('notReadyUser', true); + self::loginHelper('readyUser', true); + self::loginHelper('notReadyUser', true); // delete encryption dir to make it not ready $this->view->unlink('notReadyUser/files_encryption/'); // login as user1 - \Test_Encryption_Util::loginHelper(\Test_Encryption_Util::TEST_ENCRYPTION_UTIL_USER1); + self::loginHelper(self::TEST_ENCRYPTION_UTIL_USER1); $result = $this->util->filterShareReadyUsers($usersToTest); $this->assertEquals( diff --git a/apps/files_encryption/tests/webdav.php b/apps/files_encryption/tests/webdav.php index e3c92a4333..d32cb628f8 100755 --- a/apps/files_encryption/tests/webdav.php +++ b/apps/files_encryption/tests/webdav.php @@ -46,7 +46,7 @@ class Test_Encryption_Webdav extends \OCA\Files_Encryption\Tests\TestCase { parent::setUpBeforeClass(); // create test user - self::loginHelper(\Test_Encryption_Webdav::TEST_ENCRYPTION_WEBDAV_USER1, true); + self::loginHelper(self::TEST_ENCRYPTION_WEBDAV_USER1, true); } @@ -57,9 +57,9 @@ class Test_Encryption_Webdav extends \OCA\Files_Encryption\Tests\TestCase { \OC_User::useBackend('database'); // set user id - \OC_User::setUserId(\Test_Encryption_Webdav::TEST_ENCRYPTION_WEBDAV_USER1); - $this->userId = \Test_Encryption_Webdav::TEST_ENCRYPTION_WEBDAV_USER1; - $this->pass = \Test_Encryption_Webdav::TEST_ENCRYPTION_WEBDAV_USER1; + \OC_User::setUserId(self::TEST_ENCRYPTION_WEBDAV_USER1); + $this->userId = self::TEST_ENCRYPTION_WEBDAV_USER1; + $this->pass = self::TEST_ENCRYPTION_WEBDAV_USER1; // init filesystem view $this->view = new \OC\Files\View('/'); @@ -74,7 +74,7 @@ class Test_Encryption_Webdav extends \OCA\Files_Encryption\Tests\TestCase { \OC_App::disable('files_trashbin'); // create test user - self::loginHelper(\Test_Encryption_Webdav::TEST_ENCRYPTION_WEBDAV_USER1); + self::loginHelper(self::TEST_ENCRYPTION_WEBDAV_USER1); } protected function tearDown() { @@ -90,7 +90,7 @@ class Test_Encryption_Webdav extends \OCA\Files_Encryption\Tests\TestCase { public static function tearDownAfterClass() { // cleanup test user - \OC_User::deleteUser(\Test_Encryption_Webdav::TEST_ENCRYPTION_WEBDAV_USER1); + \OC_User::deleteUser(self::TEST_ENCRYPTION_WEBDAV_USER1); parent::tearDownAfterClass(); } From b85e34c1da075ad551321541a4e75d0d3a7015a5 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 3 Dec 2014 17:20:04 +0100 Subject: [PATCH 5/5] Correctly namespace encryption tests --- apps/files_encryption/tests/crypt.php | 54 +++++++++++----------- apps/files_encryption/tests/helper.php | 38 +++++++-------- apps/files_encryption/tests/hooks.php | 44 +++++++++--------- apps/files_encryption/tests/keymanager.php | 50 ++++++++++---------- apps/files_encryption/tests/migration.php | 23 ++++----- apps/files_encryption/tests/proxy.php | 6 ++- apps/files_encryption/tests/share.php | 47 +++++++++---------- apps/files_encryption/tests/stream.php | 12 +++-- apps/files_encryption/tests/testcase.php | 10 ++-- apps/files_encryption/tests/trashbin.php | 12 +++-- apps/files_encryption/tests/util.php | 44 +++++++++--------- apps/files_encryption/tests/webdav.php | 26 +++++------ 12 files changed, 181 insertions(+), 185 deletions(-) diff --git a/apps/files_encryption/tests/crypt.php b/apps/files_encryption/tests/crypt.php index d57fec18eb..451fa62fe5 100755 --- a/apps/files_encryption/tests/crypt.php +++ b/apps/files_encryption/tests/crypt.php @@ -7,12 +7,12 @@ * See the COPYING-README file. */ -use OCA\Files_Encryption\Crypt; +namespace OCA\Files_Encryption\Tests; /** - * Class Test_Encryption_Crypt + * Class Crypt */ -class Test_Encryption_Crypt extends \OCA\Files_Encryption\Tests\TestCase { +class Crypt extends TestCase { const TEST_ENCRYPTION_CRYPT_USER1 = "test-crypt-user1"; @@ -23,7 +23,7 @@ class Test_Encryption_Crypt extends \OCA\Files_Encryption\Tests\TestCase { public $dataUrl; public $dataShort; /** - * @var OC\Files\View + * @var \OC\Files\View */ public $view; public $legacyEncryptedData; @@ -52,16 +52,16 @@ class Test_Encryption_Crypt extends \OCA\Files_Encryption\Tests\TestCase { $this->legacyData = __DIR__ . '/legacy-text.txt'; $this->legacyEncryptedData = __DIR__ . '/legacy-encrypted-text.txt'; $this->legacyEncryptedDataKey = __DIR__ . '/encryption.key'; - $this->randomKey = Crypt::generateKey(); + $this->randomKey = \OCA\Files_Encryption\Crypt::generateKey(); - $keypair = Crypt::createKeypair(); + $keypair = \OCA\Files_Encryption\Crypt::createKeypair(); $this->genPublicKey = $keypair['publicKey']; $this->genPrivateKey = $keypair['privateKey']; $this->view = new \OC\Files\View('/'); // remember files_trashbin state - $this->stateFilesTrashbin = OC_App::isEnabled('files_trashbin'); + $this->stateFilesTrashbin = \OC_App::isEnabled('files_trashbin'); // we don't want to tests with app files_trashbin enabled \OC_App::disable('files_trashbin'); @@ -70,9 +70,9 @@ class Test_Encryption_Crypt extends \OCA\Files_Encryption\Tests\TestCase { protected function tearDown() { // reset app files_trashbin if ($this->stateFilesTrashbin) { - OC_App::enable('files_trashbin'); + \OC_App::enable('files_trashbin'); } else { - OC_App::disable('files_trashbin'); + \OC_App::disable('files_trashbin'); } $this->assertTrue(\OC_FileProxy::$enabled); @@ -95,7 +95,7 @@ class Test_Encryption_Crypt extends \OCA\Files_Encryption\Tests\TestCase { # TODO: use more accurate (larger) string length for test confirmation - $key = Crypt::generateKey(); + $key = \OCA\Files_Encryption\Crypt::generateKey(); $this->assertTrue(strlen($key) > 16); @@ -104,16 +104,16 @@ class Test_Encryption_Crypt extends \OCA\Files_Encryption\Tests\TestCase { public function testDecryptPrivateKey() { // test successful decrypt - $crypted = Crypt::symmetricEncryptFileContent($this->genPrivateKey, 'hat'); + $crypted = \OCA\Files_Encryption\Crypt::symmetricEncryptFileContent($this->genPrivateKey, 'hat'); - $header = Crypt::generateHeader(); + $header = \OCA\Files_Encryption\Crypt::generateHeader(); - $decrypted = Crypt::decryptPrivateKey($header . $crypted, 'hat'); + $decrypted = \OCA\Files_Encryption\Crypt::decryptPrivateKey($header . $crypted, 'hat'); $this->assertEquals($this->genPrivateKey, $decrypted); //test private key decrypt with wrong password - $wrongPasswd = Crypt::decryptPrivateKey($crypted, 'hat2'); + $wrongPasswd = \OCA\Files_Encryption\Crypt::decryptPrivateKey($crypted, 'hat2'); $this->assertEquals(false, $wrongPasswd); @@ -127,12 +127,12 @@ class Test_Encryption_Crypt extends \OCA\Files_Encryption\Tests\TestCase { # TODO: search in keyfile for actual content as IV will ensure this test always passes - $crypted = Crypt::symmetricEncryptFileContent($this->dataShort, 'hat'); + $crypted = \OCA\Files_Encryption\Crypt::symmetricEncryptFileContent($this->dataShort, 'hat'); $this->assertNotEquals($this->dataShort, $crypted); - $decrypt = Crypt::symmetricDecryptFileContent($crypted, 'hat'); + $decrypt = \OCA\Files_Encryption\Crypt::symmetricDecryptFileContent($crypted, 'hat'); $this->assertEquals($this->dataShort, $decrypt); @@ -145,12 +145,12 @@ class Test_Encryption_Crypt extends \OCA\Files_Encryption\Tests\TestCase { # TODO: search in keyfile for actual content as IV will ensure this test always passes - $crypted = Crypt::symmetricEncryptFileContent($this->dataShort, 'hat', 'AES-128-CFB'); + $crypted = \OCA\Files_Encryption\Crypt::symmetricEncryptFileContent($this->dataShort, 'hat', 'AES-128-CFB'); $this->assertNotEquals($this->dataShort, $crypted); - $decrypt = Crypt::symmetricDecryptFileContent($crypted, 'hat', 'AES-128-CFB'); + $decrypt = \OCA\Files_Encryption\Crypt::symmetricDecryptFileContent($crypted, 'hat', 'AES-128-CFB'); $this->assertEquals($this->dataShort, $decrypt); @@ -348,7 +348,7 @@ class Test_Encryption_Crypt extends \OCA\Files_Encryption\Tests\TestCase { // remove the header to check if we can also decrypt old files without a header, // this files should fall back to AES-128 - $cryptedWithoutHeader = substr($retreivedCryptedFile, Crypt::BLOCKSIZE); + $cryptedWithoutHeader = substr($retreivedCryptedFile, \OCA\Files_Encryption\Crypt::BLOCKSIZE); $this->view->file_put_contents($this->userId . '/files/' . $filename, $cryptedWithoutHeader); // Re-enable proxy - our work is done @@ -367,13 +367,13 @@ class Test_Encryption_Crypt extends \OCA\Files_Encryption\Tests\TestCase { */ public function testIsEncryptedContent() { - $this->assertFalse(Crypt::isCatfileContent($this->dataUrl)); + $this->assertFalse(\OCA\Files_Encryption\Crypt::isCatfileContent($this->dataUrl)); - $this->assertFalse(Crypt::isCatfileContent($this->legacyEncryptedData)); + $this->assertFalse(\OCA\Files_Encryption\Crypt::isCatfileContent($this->legacyEncryptedData)); - $keyfileContent = Crypt::symmetricEncryptFileContent($this->dataUrl, 'hat', 'AES-128-CFB'); + $keyfileContent = \OCA\Files_Encryption\Crypt::symmetricEncryptFileContent($this->dataUrl, 'hat', 'AES-128-CFB'); - $this->assertTrue(Crypt::isCatfileContent($keyfileContent)); + $this->assertTrue(\OCA\Files_Encryption\Crypt::isCatfileContent($keyfileContent)); } @@ -384,7 +384,7 @@ class Test_Encryption_Crypt extends \OCA\Files_Encryption\Tests\TestCase { # TODO: search in keyfile for actual content as IV will ensure this test always passes - $pair1 = Crypt::createKeypair(); + $pair1 = \OCA\Files_Encryption\Crypt::createKeypair(); $this->assertEquals(2, count($pair1)); @@ -393,12 +393,12 @@ class Test_Encryption_Crypt extends \OCA\Files_Encryption\Tests\TestCase { $this->assertTrue(strlen($pair1['privateKey']) > 1); - $crypted = Crypt::multiKeyEncrypt($this->dataShort, array($pair1['publicKey'])); + $crypted = \OCA\Files_Encryption\Crypt::multiKeyEncrypt($this->dataShort, array($pair1['publicKey'])); $this->assertNotEquals($this->dataShort, $crypted['data']); - $decrypt = Crypt::multiKeyDecrypt($crypted['data'], $crypted['keys'][0], $pair1['privateKey']); + $decrypt = \OCA\Files_Encryption\Crypt::multiKeyDecrypt($crypted['data'], $crypted['keys'][0], $pair1['privateKey']); $this->assertEquals($this->dataShort, $decrypt); @@ -529,7 +529,7 @@ class Test_Encryption_Crypt extends \OCA\Files_Encryption\Tests\TestCase { // relogin $params['uid'] = $this->userId; $params['password'] = 'test'; - OCA\Files_Encryption\Hooks::login($params); + \OCA\Files_Encryption\Hooks::login($params); // Get file decrypted contents $newDecrypt = file_get_contents('crypt:///' . $this->userId . '/files/' . $filename); diff --git a/apps/files_encryption/tests/helper.php b/apps/files_encryption/tests/helper.php index 32a962f7a3..bf86860125 100644 --- a/apps/files_encryption/tests/helper.php +++ b/apps/files_encryption/tests/helper.php @@ -6,12 +6,12 @@ * See the COPYING-README file. */ -use OCA\Files_Encryption\Helper; +namespace OCA\Files_Encryption\Tests; /** - * Class Test_Encryption_Helper + * Class Helper */ -class Test_Encryption_Helper extends \OCA\Files_Encryption\Tests\TestCase { +class Helper extends TestCase { const TEST_ENCRYPTION_HELPER_USER1 = "test-helper-user1"; const TEST_ENCRYPTION_HELPER_USER2 = "test-helper-user2"; @@ -30,7 +30,7 @@ class Test_Encryption_Helper extends \OCA\Files_Encryption\Tests\TestCase { public static function setupHooks() { // Filesystem related hooks - Helper::registerFilesystemHooks(); + \OCA\Files_Encryption\Helper::registerFilesystemHooks(); // clear and register hooks \OC_FileProxy::clearProxies(); @@ -49,13 +49,13 @@ class Test_Encryption_Helper extends \OCA\Files_Encryption\Tests\TestCase { $partFilename = 'testfile.txt.part'; $filename = 'testfile.txt'; - $this->assertTrue(Helper::isPartialFilePath($partFilename)); + $this->assertTrue(\OCA\Files_Encryption\Helper::isPartialFilePath($partFilename)); - $this->assertEquals('testfile.txt', Helper::stripPartialFileExtension($partFilename)); + $this->assertEquals('testfile.txt', \OCA\Files_Encryption\Helper::stripPartialFileExtension($partFilename)); - $this->assertFalse(Helper::isPartialFilePath($filename)); + $this->assertFalse(\OCA\Files_Encryption\Helper::isPartialFilePath($filename)); - $this->assertEquals('testfile.txt', Helper::stripPartialFileExtension($filename)); + $this->assertEquals('testfile.txt', \OCA\Files_Encryption\Helper::stripPartialFileExtension($filename)); } @@ -67,13 +67,13 @@ class Test_Encryption_Helper extends \OCA\Files_Encryption\Tests\TestCase { $partFilename = 'testfile.txt.ocTransferId643653835.part'; $filename = 'testfile.txt'; - $this->assertTrue(Helper::isPartialFilePath($partFilename)); + $this->assertTrue(\OCA\Files_Encryption\Helper::isPartialFilePath($partFilename)); - $this->assertEquals('testfile.txt', Helper::stripPartialFileExtension($partFilename)); + $this->assertEquals('testfile.txt', \OCA\Files_Encryption\Helper::stripPartialFileExtension($partFilename)); - $this->assertFalse(Helper::isPartialFilePath($filename)); + $this->assertFalse(\OCA\Files_Encryption\Helper::isPartialFilePath($filename)); - $this->assertEquals('testfile.txt', Helper::stripPartialFileExtension($filename)); + $this->assertEquals('testfile.txt', \OCA\Files_Encryption\Helper::stripPartialFileExtension($filename)); } function testGetPathToRealFile() { @@ -85,8 +85,8 @@ class Test_Encryption_Helper extends \OCA\Files_Encryption\Tests\TestCase { $versionPath = "/user/files_versions/foo/bar/test.txt.v456756835"; $cachePath = "/user/cache/transferid636483/foo/bar/test.txt"; - $this->assertEquals($relativePath, Helper::getPathToRealFile($versionPath)); - $this->assertEquals($relativePath, Helper::getPathToRealFile($cachePath)); + $this->assertEquals($relativePath, \OCA\Files_Encryption\Helper::getPathToRealFile($versionPath)); + $this->assertEquals($relativePath, \OCA\Files_Encryption\Helper::getPathToRealFile($cachePath)); } function testGetUser() { @@ -100,17 +100,17 @@ class Test_Encryption_Helper extends \OCA\Files_Encryption\Tests\TestCase { self::loginHelper(self::TEST_ENCRYPTION_HELPER_USER1); // if we are logged-in every path should return the currently logged-in user - $this->assertEquals(self::TEST_ENCRYPTION_HELPER_USER1, Helper::getUser($path3)); + $this->assertEquals(self::TEST_ENCRYPTION_HELPER_USER1, \OCA\Files_Encryption\Helper::getUser($path3)); // now log out self::logoutHelper(); // now we should only get the user from /user/files and user/cache paths - $this->assertEquals(self::TEST_ENCRYPTION_HELPER_USER1, Helper::getUser($path1)); - $this->assertEquals(self::TEST_ENCRYPTION_HELPER_USER1, Helper::getUser($path2)); + $this->assertEquals(self::TEST_ENCRYPTION_HELPER_USER1, \OCA\Files_Encryption\Helper::getUser($path1)); + $this->assertEquals(self::TEST_ENCRYPTION_HELPER_USER1, \OCA\Files_Encryption\Helper::getUser($path2)); - $this->assertFalse(Helper::getUser($path3)); - $this->assertFalse(Helper::getUser($path4)); + $this->assertFalse(\OCA\Files_Encryption\Helper::getUser($path3)); + $this->assertFalse(\OCA\Files_Encryption\Helper::getUser($path4)); // Log-in again self::loginHelper(self::TEST_ENCRYPTION_HELPER_USER1); diff --git a/apps/files_encryption/tests/hooks.php b/apps/files_encryption/tests/hooks.php index dc347d1adc..7c60024d63 100644 --- a/apps/files_encryption/tests/hooks.php +++ b/apps/files_encryption/tests/hooks.php @@ -20,15 +20,13 @@ * */ -use OCA\Files_Encryption\Crypt; -use OCA\Files_Encryption\Hooks; -use OCA\Files_Encryption\Keymanager; +namespace OCA\Files_Encryption\Tests; /** - * Class Test_Encryption_Hooks + * Class Hooks * this class provide basic hook app tests */ -class Test_Encryption_Hooks extends \OCA\Files_Encryption\Tests\TestCase { +class Hooks extends TestCase { const TEST_ENCRYPTION_HOOKS_USER1 = "test-encryption-hooks-user1.dot"; const TEST_ENCRYPTION_HOOKS_USER2 = "test-encryption-hooks-user2.dot"; @@ -106,7 +104,7 @@ class Test_Encryption_Hooks extends \OCA\Files_Encryption\Tests\TestCase { $this->assertTrue(is_array($row)); // disabling the app should delete all user specific settings - Hooks::preDisable(array('app' => 'files_encryption')); + \OCA\Files_Encryption\Hooks::preDisable(array('app' => 'files_encryption')); // check if user specific settings for the encryption app are really gone $query = \OC_DB::prepare('SELECT * FROM `*PREFIX*preferences` WHERE `appid` = ?'); @@ -123,7 +121,7 @@ class Test_Encryption_Hooks extends \OCA\Files_Encryption\Tests\TestCase { function testDeleteHooks() { // remember files_trashbin state - $stateFilesTrashbin = OC_App::isEnabled('files_trashbin'); + $stateFilesTrashbin = \OC_App::isEnabled('files_trashbin'); // we want to tests with app files_trashbin disabled \OC_App::disable('files_trashbin'); @@ -190,10 +188,10 @@ class Test_Encryption_Hooks extends \OCA\Files_Encryption\Tests\TestCase { self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/keys/' . $this->filename . '/fileKey')); if ($stateFilesTrashbin) { - OC_App::enable('files_trashbin'); + \OC_App::enable('files_trashbin'); } else { - OC_App::disable('files_trashbin'); + \OC_App::disable('files_trashbin'); } } @@ -204,7 +202,7 @@ class Test_Encryption_Hooks extends \OCA\Files_Encryption\Tests\TestCase { \OC_User::setUserId(self::TEST_ENCRYPTION_HOOKS_USER1); // remember files_trashbin state - $stateFilesTrashbin = OC_App::isEnabled('files_trashbin'); + $stateFilesTrashbin = \OC_App::isEnabled('files_trashbin'); // we want to tests with app files_trashbin disabled \OC_App::disable('files_trashbin'); @@ -271,10 +269,10 @@ class Test_Encryption_Hooks extends \OCA\Files_Encryption\Tests\TestCase { \OC_User::setUserId(self::TEST_ENCRYPTION_HOOKS_USER1); if ($stateFilesTrashbin) { - OC_App::enable('files_trashbin'); + \OC_App::enable('files_trashbin'); } else { - OC_App::disable('files_trashbin'); + \OC_App::disable('files_trashbin'); } } @@ -409,35 +407,35 @@ class Test_Encryption_Hooks extends \OCA\Files_Encryption\Tests\TestCase { $view = new \OC\Files\View(); // set user password for the first time - Hooks::postCreateUser(array('uid' => 'newUser', 'password' => 'newUserPassword')); + \OCA\Files_Encryption\Hooks::postCreateUser(array('uid' => 'newUser', 'password' => 'newUserPassword')); - $this->assertTrue($view->file_exists(Keymanager::getPublicKeyPath() . '/newUser.publicKey')); + $this->assertTrue($view->file_exists(\OCA\Files_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 - $encryptedKey = Keymanager::getPrivateKey($view, 'newUser'); - $privateKey = Crypt::decryptPrivateKey($encryptedKey, 'newUserPassword'); + $encryptedKey = \OCA\Files_Encryption\Keymanager::getPrivateKey($view, 'newUser'); + $privateKey = \OCA\Files_Encryption\Crypt::decryptPrivateKey($encryptedKey, 'newUserPassword'); $this->assertTrue(is_string($privateKey)); // change the password before the user logged-in for the first time, // we can replace the encryption keys - Hooks::setPassphrase(array('uid' => 'newUser', 'password' => 'passwordChanged')); + \OCA\Files_Encryption\Hooks::setPassphrase(array('uid' => 'newUser', 'password' => 'passwordChanged')); - $encryptedKey = Keymanager::getPrivateKey($view, 'newUser'); - $privateKey = Crypt::decryptPrivateKey($encryptedKey, 'passwordChanged'); + $encryptedKey = \OCA\Files_Encryption\Keymanager::getPrivateKey($view, 'newUser'); + $privateKey = \OCA\Files_Encryption\Crypt::decryptPrivateKey($encryptedKey, 'passwordChanged'); $this->assertTrue(is_string($privateKey)); // now create a files folder to simulate a already used account $view->mkdir('/newUser/files'); // change the password after the user logged in, now the password should not change - Hooks::setPassphrase(array('uid' => 'newUser', 'password' => 'passwordChanged2')); + \OCA\Files_Encryption\Hooks::setPassphrase(array('uid' => 'newUser', 'password' => 'passwordChanged2')); - $encryptedKey = Keymanager::getPrivateKey($view, 'newUser'); - $privateKey = Crypt::decryptPrivateKey($encryptedKey, 'passwordChanged2'); + $encryptedKey = \OCA\Files_Encryption\Keymanager::getPrivateKey($view, 'newUser'); + $privateKey = \OCA\Files_Encryption\Crypt::decryptPrivateKey($encryptedKey, 'passwordChanged2'); $this->assertFalse($privateKey); - $privateKey = Crypt::decryptPrivateKey($encryptedKey, 'passwordChanged'); + $privateKey = \OCA\Files_Encryption\Crypt::decryptPrivateKey($encryptedKey, 'passwordChanged'); $this->assertTrue(is_string($privateKey)); } diff --git a/apps/files_encryption/tests/keymanager.php b/apps/files_encryption/tests/keymanager.php index b0f0abce13..82df9350d4 100644 --- a/apps/files_encryption/tests/keymanager.php +++ b/apps/files_encryption/tests/keymanager.php @@ -6,14 +6,12 @@ * See the COPYING-README file. */ -use OCA\Files_Encryption\Crypt; -use OCA\Files_Encryption\Keymanager; -use OCA\Files_Encryption\Util; +namespace OCA\Files_Encryption\Tests; /** - * Class Test_Encryption_Keymanager + * Class Keymanager */ -class Test_Encryption_Keymanager extends \OCA\Files_Encryption\Tests\TestCase { +class Keymanager extends TestCase { const TEST_USER = "test-keymanager-user.dot"; @@ -21,7 +19,7 @@ class Test_Encryption_Keymanager extends \OCA\Files_Encryption\Tests\TestCase { public $pass; public static $stateFilesTrashbin; /** - * @var OC\Files\View + * @var \OC\Files\View */ public $view; public $randomKey; @@ -34,7 +32,7 @@ class Test_Encryption_Keymanager extends \OCA\Files_Encryption\Tests\TestCase { \OC_FileProxy::$enabled = false; // remember files_trashbin state - self::$stateFilesTrashbin = OC_App::isEnabled('files_trashbin'); + self::$stateFilesTrashbin = \OC_App::isEnabled('files_trashbin'); // we don't want to tests with app files_trashbin enabled \OC_App::disable('files_trashbin'); @@ -52,9 +50,9 @@ class Test_Encryption_Keymanager extends \OCA\Files_Encryption\Tests\TestCase { $this->dataUrl = __DIR__ . '/../lib/crypt.php'; $this->legacyData = __DIR__ . '/legacy-text.txt'; $this->legacyEncryptedData = __DIR__ . '/legacy-encrypted-text.txt'; - $this->randomKey = Crypt::generateKey(); + $this->randomKey = \OCA\Files_Encryption\Crypt::generateKey(); - $keypair = Crypt::createKeypair(); + $keypair = \OCA\Files_Encryption\Crypt::createKeypair(); $this->genPublicKey = $keypair['publicKey']; $this->genPrivateKey = $keypair['privateKey']; @@ -80,7 +78,7 @@ class Test_Encryption_Keymanager extends \OCA\Files_Encryption\Tests\TestCase { \OC_User::deleteUser(self::TEST_USER); // reset app files_trashbin if (self::$stateFilesTrashbin) { - OC_App::enable('files_trashbin'); + \OC_App::enable('files_trashbin'); } parent::tearDownAfterClass(); @@ -91,9 +89,9 @@ class Test_Encryption_Keymanager extends \OCA\Files_Encryption\Tests\TestCase { */ function testGetPrivateKey() { - $key = Keymanager::getPrivateKey($this->view, $this->userId); + $key = \OCA\Files_Encryption\Keymanager::getPrivateKey($this->view, $this->userId); - $privateKey = Crypt::decryptPrivateKey($key, $this->pass); + $privateKey = \OCA\Files_Encryption\Crypt::decryptPrivateKey($key, $this->pass); $res = openssl_pkey_get_private($privateKey); @@ -110,7 +108,7 @@ class Test_Encryption_Keymanager extends \OCA\Files_Encryption\Tests\TestCase { */ function testGetPublicKey() { - $publiceKey = Keymanager::getPublicKey($this->view, $this->userId); + $publiceKey = \OCA\Files_Encryption\Keymanager::getPublicKey($this->view, $this->userId); $res = openssl_pkey_get_public($publiceKey); @@ -130,7 +128,7 @@ class Test_Encryption_Keymanager extends \OCA\Files_Encryption\Tests\TestCase { $file = 'unittest-' . $this->getUniqueID() . '.txt'; - $util = new Util($this->view, $this->userId); + $util = new \OCA\Files_Encryption\Util($this->view, $this->userId); // Disable encryption proxy to prevent recursive calls $proxyStatus = \OC_FileProxy::$enabled; @@ -138,7 +136,7 @@ class Test_Encryption_Keymanager extends \OCA\Files_Encryption\Tests\TestCase { $this->view->file_put_contents($this->userId . '/files/' . $file, $this->dataShort); - Keymanager::setFileKey($this->view, $util, $file, $key); + \OCA\Files_Encryption\Keymanager::setFileKey($this->view, $util, $file, $key); $this->assertTrue($this->view->file_exists('/' . $this->userId . '/files_encryption/keys/' . $file . '/fileKey')); @@ -156,7 +154,7 @@ class Test_Encryption_Keymanager extends \OCA\Files_Encryption\Tests\TestCase { $key = "dummy key"; - Keymanager::setPrivateKey($key, 'dummyUser'); + \OCA\Files_Encryption\Keymanager::setPrivateKey($key, 'dummyUser'); $this->assertTrue($this->view->file_exists('/dummyUser/files_encryption/dummyUser.privateKey')); @@ -171,13 +169,13 @@ class Test_Encryption_Keymanager extends \OCA\Files_Encryption\Tests\TestCase { $key = "dummy key"; $keyName = "myDummyKey"; - $encHeader = Crypt::generateHeader(); + $encHeader = \OCA\Files_Encryption\Crypt::generateHeader(); - Keymanager::setPrivateSystemKey($key, $keyName); + \OCA\Files_Encryption\Keymanager::setPrivateSystemKey($key, $keyName); $this->assertTrue($this->view->file_exists('/files_encryption/' . $keyName . '.privateKey')); - $result = Keymanager::getPrivateSystemKey($keyName); + $result = \OCA\Files_Encryption\Keymanager::getPrivateSystemKey($keyName); $this->assertSame($encHeader . $key, $result); @@ -191,7 +189,7 @@ class Test_Encryption_Keymanager extends \OCA\Files_Encryption\Tests\TestCase { */ function testGetUserKeys() { - $keys = Keymanager::getUserKeys($this->view, $this->userId); + $keys = \OCA\Files_Encryption\Keymanager::getUserKeys($this->view, $this->userId); $resPublic = openssl_pkey_get_public($keys['publicKey']); @@ -201,7 +199,7 @@ class Test_Encryption_Keymanager extends \OCA\Files_Encryption\Tests\TestCase { $this->assertArrayHasKey('key', $sslInfoPublic); - $privateKey = Crypt::decryptPrivateKey($keys['privateKey'], $this->pass); + $privateKey = \OCA\Files_Encryption\Crypt::decryptPrivateKey($keys['privateKey'], $this->pass); $resPrivate = openssl_pkey_get_private($privateKey); @@ -249,9 +247,9 @@ class Test_Encryption_Keymanager extends \OCA\Files_Encryption\Tests\TestCase { $this->view->file_put_contents('/' . self::TEST_USER . '/files_encryption/keys/folder1/subfolder/subsubfolder/file2/user3.shareKey', 'data'); // recursive delete share keys from user1 and user2 - Keymanager::delShareKey($this->view, + \OCA\Files_Encryption\Keymanager::delShareKey($this->view, array('user1', 'user2', self::TEST_USER), - Keymanager::getKeyPath($this->view, new Util($this->view, self::TEST_USER), '/folder1'), + \OCA\Files_Encryption\Keymanager::getKeyPath($this->view, new \OCA\Files_Encryption\Util($this->view, self::TEST_USER), '/folder1'), self::TEST_USER, '/folder1'); @@ -317,9 +315,9 @@ class Test_Encryption_Keymanager extends \OCA\Files_Encryption\Tests\TestCase { $this->view->file_put_contents('/' . self::TEST_USER . '/files_encryption/share-keys/folder1/existingFile.txt.' . self::TEST_USER . '.shareKey', 'data'); // recursive delete share keys from user1 and user2 - Keymanager::delShareKey($this->view, + \OCA\Files_Encryption\Keymanager::delShareKey($this->view, array('user1', 'user2', self::TEST_USER), - Keymanager::getKeyPath($this->view, new Util($this->view, self::TEST_USER), '/folder1/existingFile.txt'), + \OCA\Files_Encryption\Keymanager::getKeyPath($this->view, new \OCA\Files_Encryption\Util($this->view, self::TEST_USER), '/folder1/existingFile.txt'), self::TEST_USER, '/folder1/existingFile.txt'); @@ -368,6 +366,6 @@ class TestProtectedKeymanagerMethods extends \OCA\Files_Encryption\Keymanager { * @param string $basePath */ public static function testKeySetPreperation($view, $path) { - return self::keySetPreparation($view, $path); + self::keySetPreparation($view, $path); } } diff --git a/apps/files_encryption/tests/migration.php b/apps/files_encryption/tests/migration.php index 3abe322235..f0d1ba202e 100644 --- a/apps/files_encryption/tests/migration.php +++ b/apps/files_encryption/tests/migration.php @@ -21,14 +21,15 @@ * */ -use OCA\Files_Encryption\Helper; +namespace OCA\Files_Encryption\Tests; -class Test_Migration extends \OCA\Files_Encryption\Tests\TestCase { +class Migration extends 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'; + /** @var \OC\Files\View */ private $view; private $public_share_key_id; private $recovery_key_id; @@ -48,8 +49,8 @@ class Test_Migration extends \OCA\Files_Encryption\Tests\TestCase { } protected function tearDown() { - if (OC_DB::tableExists('encryption_test')) { - OC_DB::dropTable('encryption_test'); + if (\OC_DB::tableExists('encryption_test')) { + \OC_DB::dropTable('encryption_test'); } $this->assertTableNotExist('encryption_test'); @@ -59,10 +60,10 @@ class Test_Migration extends \OCA\Files_Encryption\Tests\TestCase { public function setUp() { $this->loginHelper(self::TEST_ENCRYPTION_MIGRATION_USER1); $this->view = new \OC\Files\View(); - $this->public_share_key_id = Helper::getPublicShareKeyId(); - $this->recovery_key_id = Helper::getRecoveryKeyId(); - if (OC_DB::tableExists('encryption_test')) { - OC_DB::dropTable('encryption_test'); + $this->public_share_key_id = \OCA\Files_Encryption\Helper::getPublicShareKeyId(); + $this->recovery_key_id = \OCA\Files_Encryption\Helper::getRecoveryKeyId(); + if (\OC_DB::tableExists('encryption_test')) { + \OC_DB::dropTable('encryption_test'); } $this->assertTableNotExist('encryption_test'); } @@ -100,7 +101,7 @@ class Test_Migration extends \OCA\Files_Encryption\Tests\TestCase { // create test table $this->checkLastIndexId(); - OC_DB::createDbFromStructure(__DIR__ . '/encryption_table.xml'); + \OC_DB::createDbFromStructure(__DIR__ . '/encryption_table.xml'); $this->checkLastIndexId(); } @@ -108,12 +109,12 @@ class Test_Migration extends \OCA\Files_Encryption\Tests\TestCase { * @param string $table */ public function assertTableNotExist($table) { - $type=OC_Config::getValue( "dbtype", "sqlite" ); + $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->assertFalse(\OC_DB::tableExists($table), 'Table ' . $table . ' exists.'); } } diff --git a/apps/files_encryption/tests/proxy.php b/apps/files_encryption/tests/proxy.php index 72f223123e..d5d9cc7dae 100644 --- a/apps/files_encryption/tests/proxy.php +++ b/apps/files_encryption/tests/proxy.php @@ -20,11 +20,13 @@ * */ +namespace OCA\Files_Encryption\Tests; + /** - * Class Test_Encryption_Proxy + * Class Proxy * this class provide basic proxy app tests */ -class Test_Encryption_Proxy extends \OCA\Files_Encryption\Tests\TestCase { +class Proxy extends TestCase { const TEST_ENCRYPTION_PROXY_USER1 = "test-proxy-user1"; diff --git a/apps/files_encryption/tests/share.php b/apps/files_encryption/tests/share.php index 3dd7dadcb4..9c53c73aaf 100755 --- a/apps/files_encryption/tests/share.php +++ b/apps/files_encryption/tests/share.php @@ -20,15 +20,12 @@ * */ -use OCA\Files_Encryption\Helper; -use OCA\Files_Encryption\Hooks; -use OCA\Files_Encryption\Keymanager; -use OCA\Files_Encryption\Util; +namespace OCA\Files_Encryption\Tests; /** - * Class Test_Encryption_Share + * Class Share */ -class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase { +class Share extends TestCase { const TEST_ENCRYPTION_SHARE_USER1 = "test-share-user1"; const TEST_ENCRYPTION_SHARE_USER2 = "test-share-user2"; @@ -40,7 +37,7 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase { public $filename; public $dataShort; /** - * @var OC\Files\View + * @var \OC\Files\View */ public $view; public $folder1; @@ -58,7 +55,7 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase { \OCA\Files_Sharing\Helper::registerHooks(); // clear and register hooks - \OC_FileProxy::register(new OCA\Files\Share\Proxy()); + \OC_FileProxy::register(new \OCA\Files\Share\Proxy()); // create users self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1, true); @@ -85,7 +82,7 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase { $this->filename = 'share-tmp.test'; // remember files_trashbin state - $this->stateFilesTrashbin = OC_App::isEnabled('files_trashbin'); + $this->stateFilesTrashbin = \OC_App::isEnabled('files_trashbin'); // we don't want to tests with app files_trashbin enabled \OC_App::disable('files_trashbin'); @@ -97,9 +94,9 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase { protected function tearDown() { // reset app files_trashbin if ($this->stateFilesTrashbin) { - OC_App::enable('files_trashbin'); + \OC_App::enable('files_trashbin'); } else { - OC_App::disable('files_trashbin'); + \OC_App::disable('files_trashbin'); } parent::tearDown(); @@ -654,13 +651,13 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase { // login as admin self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1); - Helper::adminEnableRecovery(null, 'test123'); + \OCA\Files_Encryption\Helper::adminEnableRecovery(null, 'test123'); $recoveryKeyId = \OC::$server->getAppConfig()->getValue('files_encryption', 'recoveryKeyId'); // login as admin self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1); - $util = new Util(new \OC\Files\View('/'), self::TEST_ENCRYPTION_SHARE_USER1); + $util = new \OCA\Files_Encryption\Util(new \OC\Files\View('/'), self::TEST_ENCRYPTION_SHARE_USER1); // check if recovery password match $this->assertTrue($util->checkRecoveryPassword('test123')); @@ -747,8 +744,8 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase { . $this->subfolder . $this->subsubfolder . '/' . $this->filename . '/' . $recoveryKeyId . '.shareKey')); - $this->assertTrue(Helper::adminEnableRecovery(null, 'test123')); - $this->assertTrue(Helper::adminDisableRecovery('test123')); + $this->assertTrue(\OCA\Files_Encryption\Helper::adminEnableRecovery(null, 'test123')); + $this->assertTrue(\OCA\Files_Encryption\Helper::adminDisableRecovery('test123')); $this->assertEquals(0, \OC::$server->getAppConfig()->getValue('files_encryption', 'recoveryAdminEnabled')); } @@ -760,7 +757,7 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase { // login as admin self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1); - $result = Helper::adminEnableRecovery(null, 'test123'); + $result = \OCA\Files_Encryption\Helper::adminEnableRecovery(null, 'test123'); $this->assertTrue($result); $recoveryKeyId = \OC::$server->getAppConfig()->getValue('files_encryption', 'recoveryKeyId'); @@ -768,7 +765,7 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase { // login as user2 self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER2); - $util = new Util(new \OC\Files\View('/'), self::TEST_ENCRYPTION_SHARE_USER2); + $util = new \OCA\Files_Encryption\Util(new \OC\Files\View('/'), self::TEST_ENCRYPTION_SHARE_USER2); // enable recovery for admin $this->assertTrue($util->setRecoveryForUser(1)); @@ -817,7 +814,7 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase { $params = array('uid' => self::TEST_ENCRYPTION_SHARE_USER2, 'password' => 'test', 'recoveryPassword' => 'test123'); - Hooks::setPassphrase($params); + \OCA\Files_Encryption\Hooks::setPassphrase($params); // login as user2 self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER2, false, 'test'); @@ -856,7 +853,7 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase { // enable recovery for admin $this->assertTrue($util->setRecoveryForUser(0)); - Helper::adminDisableRecovery('test123'); + \OCA\Files_Encryption\Helper::adminDisableRecovery('test123'); $this->assertEquals(0, \OC::$server->getAppConfig()->getValue('files_encryption', 'recoveryAdminEnabled')); //clean up, reset passwords @@ -864,7 +861,7 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase { $params = array('uid' => self::TEST_ENCRYPTION_SHARE_USER2, 'password' => self::TEST_ENCRYPTION_SHARE_USER2, 'recoveryPassword' => 'test123'); - Hooks::setPassphrase($params); + \OCA\Files_Encryption\Hooks::setPassphrase($params); } /** @@ -895,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(Keymanager::getPublicKeyPath() . '/' . self::TEST_ENCRYPTION_SHARE_USER3 . '.publicKey', - Keymanager::getPublicKeyPath() . '/' . self::TEST_ENCRYPTION_SHARE_USER3 . '.publicKey_backup'); + $this->view->rename(\OCA\Files_Encryption\Keymanager::getPublicKeyPath() . '/' . self::TEST_ENCRYPTION_SHARE_USER3 . '.publicKey', + \OCA\Files_Encryption\Keymanager::getPublicKeyPath() . '/' . self::TEST_ENCRYPTION_SHARE_USER3 . '.publicKey_backup'); // re-enable the file proxy \OC_FileProxy::$enabled = $proxyStatus; @@ -904,7 +901,7 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase { // share the file try { \OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP, self::TEST_ENCRYPTION_SHARE_GROUP1, \OCP\Constants::PERMISSION_ALL); - } catch (Exception $e) { + } catch (\Exception $e) { $this->assertEquals(0, strpos($e->getMessage(), "Following users are not set up for encryption")); } @@ -923,8 +920,8 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase { // break user1 public key $this->view->rename( - Keymanager::getPublicKeyPath() . '/' . self::TEST_ENCRYPTION_SHARE_USER3 . '.publicKey_backup', - Keymanager::getPublicKeyPath() . '/' . self::TEST_ENCRYPTION_SHARE_USER3 . '.publicKey'); + \OCA\Files_Encryption\Keymanager::getPublicKeyPath() . '/' . self::TEST_ENCRYPTION_SHARE_USER3 . '.publicKey_backup', + \OCA\Files_Encryption\Keymanager::getPublicKeyPath() . '/' . self::TEST_ENCRYPTION_SHARE_USER3 . '.publicKey'); // remove share file $this->view->unlink('/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' diff --git a/apps/files_encryption/tests/stream.php b/apps/files_encryption/tests/stream.php index 7afe8a8850..8295ddd952 100644 --- a/apps/files_encryption/tests/stream.php +++ b/apps/files_encryption/tests/stream.php @@ -20,11 +20,13 @@ * */ +namespace OCA\Files_Encryption\Tests; + /** - * Class Test_Encryption_Stream + * Class Stream * this class provide basic stream tests */ -class Test_Encryption_Stream extends \OCA\Files_Encryption\Tests\TestCase { +class Stream extends TestCase { const TEST_ENCRYPTION_STREAM_USER1 = "test-stream-user1"; @@ -59,7 +61,7 @@ class Test_Encryption_Stream extends \OCA\Files_Encryption\Tests\TestCase { $this->dataShort = 'hats'; // remember files_trashbin state - $this->stateFilesTrashbin = OC_App::isEnabled('files_trashbin'); + $this->stateFilesTrashbin = \OC_App::isEnabled('files_trashbin'); // we don't want to tests with app files_trashbin enabled \OC_App::disable('files_trashbin'); @@ -68,10 +70,10 @@ class Test_Encryption_Stream extends \OCA\Files_Encryption\Tests\TestCase { protected function tearDown() { // reset app files_trashbin if ($this->stateFilesTrashbin) { - OC_App::enable('files_trashbin'); + \OC_App::enable('files_trashbin'); } else { - OC_App::disable('files_trashbin'); + \OC_App::disable('files_trashbin'); } parent::tearDown(); diff --git a/apps/files_encryption/tests/testcase.php b/apps/files_encryption/tests/testcase.php index 84b728d4aa..9cb724648c 100644 --- a/apps/files_encryption/tests/testcase.php +++ b/apps/files_encryption/tests/testcase.php @@ -8,10 +8,8 @@ namespace OCA\Files_Encryption\Tests; -use OCA\Files_Encryption\Helper; - /** - * Class Test_Encryption_TestCase + * Class TestCase */ abstract class TestCase extends \Test\TestCase { @@ -59,9 +57,9 @@ abstract class TestCase extends \Test\TestCase { \OC_User::clearBackends(); \OC_User::useBackend('database'); - Helper::registerFilesystemHooks(); - Helper::registerUserHooks(); - Helper::registerShareHooks(); + \OCA\Files_Encryption\Helper::registerFilesystemHooks(); + \OCA\Files_Encryption\Helper::registerUserHooks(); + \OCA\Files_Encryption\Helper::registerShareHooks(); \OC::registerShareHooks(); \OCP\Util::connectHook('OC_Filesystem', 'setup', '\OC\Files\Storage\Shared', 'setup'); diff --git a/apps/files_encryption/tests/trashbin.php b/apps/files_encryption/tests/trashbin.php index 9b2d3039f9..d924b8ac77 100755 --- a/apps/files_encryption/tests/trashbin.php +++ b/apps/files_encryption/tests/trashbin.php @@ -20,11 +20,13 @@ * */ +namespace OCA\Files_Encryption\Tests; + /** - * Class Test_Encryption_Trashbin + * Class Trashbin * this class provide basic trashbin app tests */ -class Test_Encryption_Trashbin extends \OCA\Files_Encryption\Tests\TestCase { +class Trashbin extends TestCase { const TEST_ENCRYPTION_TRASHBIN_USER1 = "test-trashbin-user1"; @@ -69,7 +71,7 @@ class Test_Encryption_Trashbin extends \OCA\Files_Encryption\Tests\TestCase { $this->subsubfolder = '/subsubfolder1'; // remember files_trashbin state - $this->stateFilesTrashbin = OC_App::isEnabled('files_trashbin'); + $this->stateFilesTrashbin = \OC_App::isEnabled('files_trashbin'); // we want to tests with app files_trashbin enabled \OC_App::enable('files_trashbin'); @@ -78,10 +80,10 @@ class Test_Encryption_Trashbin extends \OCA\Files_Encryption\Tests\TestCase { protected function tearDown() { // reset app files_trashbin if ($this->stateFilesTrashbin) { - OC_App::enable('files_trashbin'); + \OC_App::enable('files_trashbin'); } else { - OC_App::disable('files_trashbin'); + \OC_App::disable('files_trashbin'); } parent::tearDown(); diff --git a/apps/files_encryption/tests/util.php b/apps/files_encryption/tests/util.php index 9d8b45213d..c71b9a0481 100755 --- a/apps/files_encryption/tests/util.php +++ b/apps/files_encryption/tests/util.php @@ -6,14 +6,12 @@ * See the COPYING-README file. */ -use OCA\Files_Encryption\Crypt; -use OCA\Files_Encryption\Keymanager; -use OCA\Files_Encryption\Util; +namespace OCA\Files_Encryption\Tests; /** - * Class Test_Encryption_Util + * Class Util */ -class Test_Encryption_Util extends \OCA\Files_Encryption\Tests\TestCase { +class Util extends TestCase { const TEST_ENCRYPTION_UTIL_USER1 = "test-util-user1"; const TEST_ENCRYPTION_UTIL_USER2 = "test-util-user2"; @@ -26,7 +24,7 @@ class Test_Encryption_Util extends \OCA\Files_Encryption\Tests\TestCase { public $publicKeyDir; public $pass; /** - * @var OC\Files\View + * @var \OC\Files\View */ public $view; public $keyfilesPath; @@ -76,12 +74,12 @@ class Test_Encryption_Util extends \OCA\Files_Encryption\Tests\TestCase { $this->legacyEncryptedDataKey = __DIR__ . '/encryption.key'; $this->legacyKey = "30943623843030686906\0\0\0\0"; - $keypair = Crypt::createKeypair(); + $keypair = \OCA\Files_Encryption\Crypt::createKeypair(); $this->genPublicKey = $keypair['publicKey']; $this->genPrivateKey = $keypair['privateKey']; - $this->publicKeyDir = Keymanager::getPublicKeyPath(); + $this->publicKeyDir = \OCA\Files_Encryption\Keymanager::getPublicKeyPath(); $this->encryptionDir = '/' . $this->userId . '/' . 'files_encryption'; $this->keysPath = $this->encryptionDir . '/' . 'keys'; $this->publicKeyPath = @@ -91,10 +89,10 @@ class Test_Encryption_Util extends \OCA\Files_Encryption\Tests\TestCase { $this->view = new \OC\Files\View('/'); - $this->util = new Util($this->view, $this->userId); + $this->util = new \OCA\Files_Encryption\Util($this->view, $this->userId); // remember files_trashbin state - $this->stateFilesTrashbin = OC_App::isEnabled('files_trashbin'); + $this->stateFilesTrashbin = \OC_App::isEnabled('files_trashbin'); // we don't want to tests with app files_trashbin enabled \OC_App::disable('files_trashbin'); @@ -103,10 +101,10 @@ class Test_Encryption_Util extends \OCA\Files_Encryption\Tests\TestCase { protected function tearDown() { // reset app files_trashbin if ($this->stateFilesTrashbin) { - OC_App::enable('files_trashbin'); + \OC_App::enable('files_trashbin'); } else { - OC_App::disable('files_trashbin'); + \OC_App::disable('files_trashbin'); } parent::tearDown(); @@ -130,7 +128,7 @@ class Test_Encryption_Util extends \OCA\Files_Encryption\Tests\TestCase { * test that paths set during User construction are correct */ function testKeyPaths() { - $util = new Util($this->view, $this->userId); + $util = new \OCA\Files_Encryption\Util($this->view, $this->userId); $this->assertEquals($this->publicKeyDir, $util->getPath('publicKeyDir')); $this->assertEquals($this->encryptionDir, $util->getPath('encryptionDir')); @@ -146,7 +144,7 @@ class Test_Encryption_Util extends \OCA\Files_Encryption\Tests\TestCase { */ function testIsEncryptedPath() { - $util = new Util($this->view, $this->userId); + $util = new \OCA\Files_Encryption\Util($this->view, $this->userId); self::loginHelper($this->userId); @@ -209,7 +207,7 @@ class Test_Encryption_Util extends \OCA\Files_Encryption\Tests\TestCase { */ function testRecoveryEnabledForUser() { - $util = new Util($this->view, $this->userId); + $util = new \OCA\Files_Encryption\Util($this->view, $this->userId); // Record the value so we can return it to it's original state later $enabled = $util->recoveryEnabledForUser(); @@ -243,7 +241,7 @@ class Test_Encryption_Util extends \OCA\Files_Encryption\Tests\TestCase { // Re-enable proxy - our work is done \OC_FileProxy::$enabled = $proxyStatus; - $util = new Util($this->view, $this->userId); + $util = new \OCA\Files_Encryption\Util($this->view, $this->userId); list($fileOwnerUid, $file) = $util->getUidAndFilename($filename); @@ -285,7 +283,7 @@ class Test_Encryption_Util extends \OCA\Files_Encryption\Tests\TestCase { function testEncryptAll() { $filename = "/encryptAll" . $this->getUniqueID() . ".txt"; - $util = new Util($this->view, $this->userId); + $util = new \OCA\Files_Encryption\Util($this->view, $this->userId); // disable encryption to upload a unencrypted file \OC_App::disable('files_encryption'); @@ -340,14 +338,14 @@ class Test_Encryption_Util extends \OCA\Files_Encryption\Tests\TestCase { $this->assertSame($encContent, $content); // now we load the encryption app again - OC_App::loadApp('files_encryption'); + \OC_App::loadApp('files_encryption'); // init encryption app $params = array('uid' => \OCP\User::getUser(), 'password' => \OCP\User::getUser()); - $view = new OC\Files\View('/'); - $util = new Util($view, \OCP\User::getUser()); + $view = new \OC\Files\View('/'); + $util = new \OCA\Files_Encryption\Util($view, \OCP\User::getUser()); $result = $util->initEncryption($params); @@ -387,7 +385,7 @@ class Test_Encryption_Util extends \OCA\Files_Encryption\Tests\TestCase { // cleanup $this->view->unlink($this->userId . '/files/' . $filename); $this->view->deleteAll($backupPath); - OC_App::enable('files_encryption'); + \OC_App::enable('files_encryption'); } @@ -403,7 +401,7 @@ class Test_Encryption_Util extends \OCA\Files_Encryption\Tests\TestCase { $this->view->file_put_contents($encPath . '/keys/foo/fileKey', 'key'); $this->view->file_put_contents($encPath . '/keys/foo/user1.shareKey', 'share key'); - $util = new Util($this->view, self::TEST_ENCRYPTION_UTIL_USER1); + $util = new \OCA\Files_Encryption\Util($this->view, self::TEST_ENCRYPTION_UTIL_USER1); $util->backupAllKeys('testBackupAllKeys'); @@ -429,7 +427,7 @@ class Test_Encryption_Util extends \OCA\Files_Encryption\Tests\TestCase { $file1 = "/decryptAll1" . $this->getUniqueID() . ".txt"; $file2 = "/decryptAll2" . $this->getUniqueID() . ".txt"; - $util = new Util($this->view, $this->userId); + $util = new \OCA\Files_Encryption\Util($this->view, $this->userId); $this->view->file_put_contents($this->userId . '/files/' . $file1, $this->dataShort); $this->view->file_put_contents($this->userId . '/files/' . $file2, $this->dataShort); diff --git a/apps/files_encryption/tests/webdav.php b/apps/files_encryption/tests/webdav.php index d32cb628f8..83f4c0a77d 100755 --- a/apps/files_encryption/tests/webdav.php +++ b/apps/files_encryption/tests/webdav.php @@ -20,14 +20,14 @@ * */ -use OCA\Files_Encryption\Crypt; +namespace OCA\Files_Encryption\Tests; /** - * Class Test_Encryption_Webdav + * Class Webdav * * this class provide basic webdav tests for PUT,GET and DELETE */ -class Test_Encryption_Webdav extends \OCA\Files_Encryption\Tests\TestCase { +class Webdav extends TestCase { const TEST_ENCRYPTION_WEBDAV_USER1 = "test-webdav-user1"; @@ -68,7 +68,7 @@ class Test_Encryption_Webdav extends \OCA\Files_Encryption\Tests\TestCase { $this->dataShort = 'hats'; // remember files_trashbin state - $this->stateFilesTrashbin = OC_App::isEnabled('files_trashbin'); + $this->stateFilesTrashbin = \OC_App::isEnabled('files_trashbin'); // we don't want to tests with app files_trashbin enabled \OC_App::disable('files_trashbin'); @@ -80,9 +80,9 @@ class Test_Encryption_Webdav extends \OCA\Files_Encryption\Tests\TestCase { protected function tearDown() { // reset app files_trashbin if ($this->stateFilesTrashbin) { - OC_App::enable('files_trashbin'); + \OC_App::enable('files_trashbin'); } else { - OC_App::disable('files_trashbin'); + \OC_App::disable('files_trashbin'); } parent::tearDown(); @@ -138,7 +138,7 @@ class Test_Encryption_Webdav extends \OCA\Files_Encryption\Tests\TestCase { \OC_FileProxy::$enabled = $proxyStatus; // check if encrypted content is valid - $this->assertTrue(Crypt::isCatfileContent($encryptedContent)); + $this->assertTrue(\OCA\Files_Encryption\Crypt::isCatfileContent($encryptedContent)); // get decrypted file contents $decrypt = file_get_contents('crypt:///' . $this->userId . '/files' . $filename); @@ -211,14 +211,14 @@ class Test_Encryption_Webdav extends \OCA\Files_Encryption\Tests\TestCase { */ function handleWebdavRequest($body = false) { // Backends - $authBackend = new OC_Connector_Sabre_Auth(); - $lockBackend = new OC_Connector_Sabre_Locks(); - $requestBackend = new OC_Connector_Sabre_Request(); + $authBackend = new \OC_Connector_Sabre_Auth(); + $lockBackend = new \OC_Connector_Sabre_Locks(); + $requestBackend = new \OC_Connector_Sabre_Request(); // Create ownCloud Dir $root = '/' . $this->userId . '/files'; $view = new \OC\Files\View($root); - $publicDir = new OC_Connector_Sabre_Directory($view, $view->getFileInfo('')); + $publicDir = new \OC_Connector_Sabre_Directory($view, $view->getFileInfo('')); $objectTree = new \OC\Connector\Sabre\ObjectTree(); $mountManager = \OC\Files\Filesystem::getMountManager(); $objectTree->init($publicDir, $view, $mountManager); @@ -232,8 +232,8 @@ class Test_Encryption_Webdav extends \OCA\Files_Encryption\Tests\TestCase { $server->addPlugin(new \Sabre\DAV\Auth\Plugin($authBackend, 'ownCloud')); $server->addPlugin(new \Sabre\DAV\Locks\Plugin($lockBackend)); $server->addPlugin(new \Sabre\DAV\Browser\Plugin(false)); // Show something in the Browser, but no upload - $server->addPlugin(new OC_Connector_Sabre_QuotaPlugin($view)); - $server->addPlugin(new OC_Connector_Sabre_MaintenancePlugin()); + $server->addPlugin(new \OC_Connector_Sabre_QuotaPlugin($view)); + $server->addPlugin(new \OC_Connector_Sabre_MaintenancePlugin()); $server->debugExceptions = true; // And off we go!