diff options
author | Joas Schilling <nickvergessen@gmx.de> | 2014-12-03 16:52:44 +0100 |
---|---|---|
committer | Joas Schilling <nickvergessen@gmx.de> | 2014-12-09 09:47:26 +0100 |
commit | efac8ced90879f34919eb55055423523b146d33e (patch) | |
tree | ee2778caa0a8ddf5c181a590625d98081e0c7d63 /apps/files_encryption/tests | |
parent | 78a307995c510c0184d915fcab26baa3be815342 (diff) | |
download | nextcloud-server-efac8ced90879f34919eb55055423523b146d33e.tar.gz nextcloud-server-efac8ced90879f34919eb55055423523b146d33e.zip |
Update OCA\Encryption to OCA\Files_Encryption in the encryption app itself
Diffstat (limited to 'apps/files_encryption/tests')
-rwxr-xr-x | apps/files_encryption/tests/crypt.php | 42 | ||||
-rw-r--r-- | apps/files_encryption/tests/helper.php | 36 | ||||
-rw-r--r-- | apps/files_encryption/tests/hooks.php | 28 | ||||
-rw-r--r-- | apps/files_encryption/tests/keymanager.php | 42 | ||||
-rw-r--r-- | apps/files_encryption/tests/migration.php | 7 | ||||
-rw-r--r-- | apps/files_encryption/tests/proxy.php | 4 | ||||
-rwxr-xr-x | apps/files_encryption/tests/share.php | 31 | ||||
-rw-r--r-- | apps/files_encryption/tests/stream.php | 4 | ||||
-rw-r--r-- | apps/files_encryption/tests/testcase.php | 12 | ||||
-rwxr-xr-x | apps/files_encryption/tests/trashbin.php | 2 | ||||
-rwxr-xr-x | apps/files_encryption/tests/util.php | 38 | ||||
-rwxr-xr-x | apps/files_encryption/tests/webdav.php | 4 |
12 files changed, 126 insertions, 124 deletions
diff --git a/apps/files_encryption/tests/crypt.php b/apps/files_encryption/tests/crypt.php index ab2ce066cdb..2a603404051 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 88ba9f20d53..a7678611874 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 d5a30f5074a..b4a28dd24ab 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 21f03839430..f10940e441e 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 21c4e354c29..3abe322235c 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 72a9a9a5551..3cc668e6361 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 f827017569f..0eaff6bf87f 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 f4824935ca0..08d4ddcf5b8 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 743a876ab45..84b728d4aaa 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 de5b8bd6edb..d8af31760ee 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 2d58db2128c..8496772a135 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 a04a7621291..e3c92a4333c 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); |