summaryrefslogtreecommitdiffstats
path: root/apps/files_encryption/tests/util.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_encryption/tests/util.php')
-rwxr-xr-xapps/files_encryption/tests/util.php64
1 files changed, 33 insertions, 31 deletions
diff --git a/apps/files_encryption/tests/util.php b/apps/files_encryption/tests/util.php
index 8d9aba423cd..c71b9a0481f 100755
--- a/apps/files_encryption/tests/util.php
+++ b/apps/files_encryption/tests/util.php
@@ -6,12 +6,12 @@
* See the COPYING-README file.
*/
-use OCA\Encryption;
+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";
@@ -24,14 +24,14 @@ 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;
public $publicKeyPath;
public $privateKeyPath;
/**
- * @var \OCA\Encryption\Util
+ * @var \OCA\Files_Encryption\Util
*/
public $util;
public $dataShort;
@@ -74,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 = Encryption\Crypt::createKeypair();
+ $keypair = \OCA\Files_Encryption\Crypt::createKeypair();
$this->genPublicKey = $keypair['publicKey'];
$this->genPrivateKey = $keypair['privateKey'];
- $this->publicKeyDir = \OCA\Encryption\Keymanager::getPublicKeyPath();
+ $this->publicKeyDir = \OCA\Files_Encryption\Keymanager::getPublicKeyPath();
$this->encryptionDir = '/' . $this->userId . '/' . 'files_encryption';
$this->keysPath = $this->encryptionDir . '/' . 'keys';
$this->publicKeyPath =
@@ -89,10 +89,10 @@ 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 \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');
@@ -101,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();
@@ -128,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 Encryption\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'));
@@ -144,7 +144,7 @@ class Test_Encryption_Util extends \OCA\Files_Encryption\Tests\TestCase {
*/
function testIsEncryptedPath() {
- $util = new Encryption\Util($this->view, $this->userId);
+ $util = new \OCA\Files_Encryption\Util($this->view, $this->userId);
self::loginHelper($this->userId);
@@ -197,7 +197,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 +207,7 @@ class Test_Encryption_Util extends \OCA\Files_Encryption\Tests\TestCase {
*/
function testRecoveryEnabledForUser() {
- $util = new Encryption\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();
@@ -241,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 Encryption\Util($this->view, $this->userId);
+ $util = new \OCA\Files_Encryption\Util($this->view, $this->userId);
list($fileOwnerUid, $file) = $util->getUidAndFilename($filename);
@@ -283,7 +283,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 \OCA\Files_Encryption\Util($this->view, $this->userId);
// disable encryption to upload a unencrypted file
\OC_App::disable('files_encryption');
@@ -338,18 +338,18 @@ 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 \OCA\Encryption\Util($view, \OCP\User::getUser());
+ $view = new \OC\Files\View('/');
+ $util = new \OCA\Files_Encryption\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();
@@ -385,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');
}
@@ -401,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 \OCA\Encryption\Util($this->view, self::TEST_ENCRYPTION_UTIL_USER1);
+ $util = new \OCA\Files_Encryption\Util($this->view, self::TEST_ENCRYPTION_UTIL_USER1);
$util->backupAllKeys('testBackupAllKeys');
@@ -427,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 Encryption\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);
@@ -551,13 +551,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(
@@ -598,7 +598,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);
}
}
@@ -617,15 +617,17 @@ class Test_Encryption_Util extends \OCA\Files_Encryption\Tests\TestCase {
* @return boolean
*/
private function setMigrationStatus($status, $user) {
- return \OC_Preferences::setValue($user, 'files_encryption', 'migration_status', (string)$status);
+ \OC::$server->getConfig()->setUserValue($user, 'files_encryption', 'migration_status', (string)$status);
+ // the update will definitely be executed -> return value is always true
+ return true;
}
}
/**
- * 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);
}