summaryrefslogtreecommitdiffstats
path: root/apps/files_encryption/tests/crypt.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_encryption/tests/crypt.php')
-rwxr-xr-xapps/files_encryption/tests/crypt.php64
1 files changed, 32 insertions, 32 deletions
diff --git a/apps/files_encryption/tests/crypt.php b/apps/files_encryption/tests/crypt.php
index ab2ce066cdb..451fa62fe57 100755
--- a/apps/files_encryption/tests/crypt.php
+++ b/apps/files_encryption/tests/crypt.php
@@ -7,12 +7,12 @@
* See the COPYING-README file.
*/
-use OCA\Encryption;
+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;
@@ -34,16 +34,16 @@ class Test_Encryption_Crypt extends \OCA\Files_Encryption\Tests\TestCase {
parent::setUpBeforeClass();
// create test user
- self::loginHelper(\Test_Encryption_Crypt::TEST_ENCRYPTION_CRYPT_USER1, true);
+ self::loginHelper(self::TEST_ENCRYPTION_CRYPT_USER1, true);
}
protected function setUp() {
parent::setUp();
// set user id
- self::loginHelper(\Test_Encryption_Crypt::TEST_ENCRYPTION_CRYPT_USER1);
- $this->userId = \Test_Encryption_Crypt::TEST_ENCRYPTION_CRYPT_USER1;
- $this->pass = \Test_Encryption_Crypt::TEST_ENCRYPTION_CRYPT_USER1;
+ self::loginHelper(self::TEST_ENCRYPTION_CRYPT_USER1);
+ $this->userId = self::TEST_ENCRYPTION_CRYPT_USER1;
+ $this->pass = self::TEST_ENCRYPTION_CRYPT_USER1;
// set content for encrypting / decrypting in tests
$this->dataLong = file_get_contents(__DIR__ . '/../lib/crypt.php');
@@ -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 = Encryption\Crypt::generateKey();
+ $this->randomKey = \OCA\Files_Encryption\Crypt::generateKey();
- $keypair = Encryption\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);
@@ -83,7 +83,7 @@ class Test_Encryption_Crypt extends \OCA\Files_Encryption\Tests\TestCase {
public static function tearDownAfterClass() {
// cleanup test user
- \OC_User::deleteUser(\Test_Encryption_Crypt::TEST_ENCRYPTION_CRYPT_USER1);
+ \OC_User::deleteUser(self::TEST_ENCRYPTION_CRYPT_USER1);
parent::tearDownAfterClass();
}
@@ -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 = \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 = Encryption\Crypt::symmetricEncryptFileContent($this->genPrivateKey, 'hat');
+ $crypted = \OCA\Files_Encryption\Crypt::symmetricEncryptFileContent($this->genPrivateKey, 'hat');
- $header = Encryption\Crypt::generateHeader();
+ $header = \OCA\Files_Encryption\Crypt::generateHeader();
- $decrypted = Encryption\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 = Encryption\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 = Encryption\Crypt::symmetricEncryptFileContent($this->dataShort, 'hat');
+ $crypted = \OCA\Files_Encryption\Crypt::symmetricEncryptFileContent($this->dataShort, 'hat');
$this->assertNotEquals($this->dataShort, $crypted);
- $decrypt = Encryption\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 = Encryption\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 = Encryption\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, Encryption\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(Encryption\Crypt::isCatfileContent($this->dataUrl));
+ $this->assertFalse(\OCA\Files_Encryption\Crypt::isCatfileContent($this->dataUrl));
- $this->assertFalse(Encryption\Crypt::isCatfileContent($this->legacyEncryptedData));
+ $this->assertFalse(\OCA\Files_Encryption\Crypt::isCatfileContent($this->legacyEncryptedData));
- $keyfileContent = Encryption\Crypt::symmetricEncryptFileContent($this->dataUrl, 'hat', 'AES-128-CFB');
+ $keyfileContent = \OCA\Files_Encryption\Crypt::symmetricEncryptFileContent($this->dataUrl, 'hat', 'AES-128-CFB');
- $this->assertTrue(Encryption\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 = Encryption\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 = Encryption\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 = Encryption\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\Encryption\Hooks::login($params);
+ \OCA\Files_Encryption\Hooks::login($params);
// Get file decrypted contents
$newDecrypt = file_get_contents('crypt:///' . $this->userId . '/files/' . $filename);