Correctly namespace encryption tests
This commit is contained in:
parent
e67fe0336b
commit
b85e34c1da
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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));
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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";
|
||||
|
||||
|
|
|
@ -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/'
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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');
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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!
|
||||
|
|
Loading…
Reference in New Issue