summaryrefslogtreecommitdiffstats
path: root/apps/files_encryption/tests
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_encryption/tests')
-rwxr-xr-xapps/files_encryption/tests/crypt.php2
-rw-r--r--apps/files_encryption/tests/hooks.php2
-rw-r--r--apps/files_encryption/tests/keymanager.php4
-rwxr-xr-xapps/files_encryption/tests/share.php26
-rwxr-xr-xapps/files_encryption/tests/util.php91
5 files changed, 103 insertions, 22 deletions
diff --git a/apps/files_encryption/tests/crypt.php b/apps/files_encryption/tests/crypt.php
index 388980ad4fd..123943ea26a 100755
--- a/apps/files_encryption/tests/crypt.php
+++ b/apps/files_encryption/tests/crypt.php
@@ -661,7 +661,7 @@ class Test_Encryption_Crypt extends \PHPUnit_Framework_TestCase {
/**
* @brief encryption using legacy blowfish method
- * @param $data string data to encrypt
+ * @param string $data data to encrypt
* @param $passwd string password
* @return string
*/
diff --git a/apps/files_encryption/tests/hooks.php b/apps/files_encryption/tests/hooks.php
index 44525791743..7d926caea1b 100644
--- a/apps/files_encryption/tests/hooks.php
+++ b/apps/files_encryption/tests/hooks.php
@@ -203,7 +203,7 @@ class Test_Encryption_Hooks extends \PHPUnit_Framework_TestCase {
$fileInfo = $this->user1View->getFileInfo($this->filename);
// check if we have a valid file info
- $this->assertTrue(is_array($fileInfo));
+ $this->assertTrue($fileInfo instanceof \OC\Files\FileInfo);
// share the file with user2
\OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_ENCRYPTION_HOOKS_USER2, OCP\PERMISSION_ALL);
diff --git a/apps/files_encryption/tests/keymanager.php b/apps/files_encryption/tests/keymanager.php
index 6f32c50743c..0caf12e91a3 100644
--- a/apps/files_encryption/tests/keymanager.php
+++ b/apps/files_encryption/tests/keymanager.php
@@ -250,6 +250,10 @@ class Test_Encryption_Keymanager extends \PHPUnit_Framework_TestCase {
* dummy class to access protected methods of \OCA\Encryption\Keymanager for testing
*/
class TestProtectedKeymanagerMethods extends \OCA\Encryption\Keymanager {
+
+ /**
+ * @param string $sharekey
+ */
public static function testGetFilenameFromShareKey($sharekey) {
return self::getFilenameFromShareKey($sharekey);
}
diff --git a/apps/files_encryption/tests/share.php b/apps/files_encryption/tests/share.php
index acf408a07f0..46a21dd55cd 100755
--- a/apps/files_encryption/tests/share.php
+++ b/apps/files_encryption/tests/share.php
@@ -61,7 +61,7 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase {
\OC_User::useBackend('database');
// enable resharing
- \OC_Appconfig::setValue('core', 'shareapi_allow_resharing', 'yes');
+ \OC::$server->getAppConfig()->setValue('core', 'shareapi_allow_resharing', 'yes');
// clear share hooks
\OC_Hook::clear('OCP\\Share');
@@ -150,7 +150,7 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase {
'/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename);
// check if we have a valid file info
- $this->assertTrue(is_array($fileInfo));
+ $this->assertTrue($fileInfo instanceof \OC\Files\FileInfo);
// check if the unencrypted file size is stored
$this->assertGreaterThan(0, $fileInfo['unencrypted_size']);
@@ -310,7 +310,7 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase {
'/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files' . $this->folder1);
// check if we have a valid file info
- $this->assertTrue(is_array($fileInfo));
+ $this->assertTrue($fileInfo instanceof \OC\Files\FileInfo);
// re-enable the file proxy
\OC_FileProxy::$enabled = $proxyStatus;
@@ -388,7 +388,7 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase {
. $this->subfolder);
// check if we have a valid file info
- $this->assertTrue(is_array($fileInfoSubFolder));
+ $this->assertTrue($fileInfoSubFolder instanceof \OC\Files\FileInfo);
// re-enable the file proxy
\OC_FileProxy::$enabled = $proxyStatus;
@@ -422,7 +422,7 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase {
. $this->subsubfolder . '/' . $this->filename);
// check if we have fileInfos
- $this->assertTrue(is_array($fileInfo));
+ $this->assertTrue($fileInfo instanceof \OC\Files\FileInfo);
// share the file with user3
\OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER4, OCP\PERMISSION_ALL);
@@ -517,7 +517,7 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase {
'/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename);
// check if we have a valid file info
- $this->assertTrue(is_array($fileInfo));
+ $this->assertTrue($fileInfo instanceof \OC\Files\FileInfo);
// check if the unencrypted file size is stored
$this->assertGreaterThan(0, $fileInfo['unencrypted_size']);
@@ -531,7 +531,7 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase {
// login as admin
\Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
- $publicShareKeyId = \OC_Appconfig::getValue('files_encryption', 'publicShareKeyId');
+ $publicShareKeyId = \OC::$server->getAppConfig()->getValue('files_encryption', 'publicShareKeyId');
// check if share key for public exists
$this->assertTrue($this->view->file_exists(
@@ -595,7 +595,7 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase {
'/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename);
// check if we have a valid file info
- $this->assertTrue(is_array($fileInfo));
+ $this->assertTrue($fileInfo instanceof \OC\Files\FileInfo);
// check if the unencrypted file size is stored
$this->assertGreaterThan(0, $fileInfo['unencrypted_size']);
@@ -662,7 +662,7 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase {
\Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
\OCA\Encryption\Helper::adminEnableRecovery(null, 'test123');
- $recoveryKeyId = OC_Appconfig::getValue('files_encryption', 'recoveryKeyId');
+ $recoveryKeyId = \OC::$server->getAppConfig()->getValue('files_encryption', 'recoveryKeyId');
// login as admin
\Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
@@ -755,7 +755,7 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase {
$this->assertTrue(\OCA\Encryption\Helper::adminEnableRecovery(null, 'test123'));
$this->assertTrue(\OCA\Encryption\Helper::adminDisableRecovery('test123'));
- $this->assertEquals(0, \OC_Appconfig::getValue('files_encryption', 'recoveryAdminEnabled'));
+ $this->assertEquals(0, \OC::$server->getAppConfig()->getValue('files_encryption', 'recoveryAdminEnabled'));
}
/**
@@ -769,7 +769,7 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase {
$result = \OCA\Encryption\Helper::adminEnableRecovery(null, 'test123');
$this->assertTrue($result);
- $recoveryKeyId = OC_Appconfig::getValue('files_encryption', 'recoveryKeyId');
+ $recoveryKeyId = \OC::$server->getAppConfig()->getValue('files_encryption', 'recoveryKeyId');
// login as user2
\Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2);
@@ -863,7 +863,7 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase {
$this->assertTrue($util->setRecoveryForUser(0));
\OCA\Encryption\Helper::adminDisableRecovery('test123');
- $this->assertEquals(0, \OC_Appconfig::getValue('files_encryption', 'recoveryAdminEnabled'));
+ $this->assertEquals(0, \OC::$server->getAppConfig()->getValue('files_encryption', 'recoveryAdminEnabled'));
}
/**
@@ -888,7 +888,7 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase {
'/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename);
// check if we have a valid file info
- $this->assertTrue(is_array($fileInfo));
+ $this->assertTrue($fileInfo instanceof \OC\Files\FileInfo);
// check if the unencrypted file size is stored
$this->assertGreaterThan(0, $fileInfo['unencrypted_size']);
diff --git a/apps/files_encryption/tests/util.php b/apps/files_encryption/tests/util.php
index 97e3c518dac..f70e30c4d73 100755
--- a/apps/files_encryption/tests/util.php
+++ b/apps/files_encryption/tests/util.php
@@ -64,6 +64,8 @@ class Test_Encryption_Util extends \PHPUnit_Framework_TestCase {
function setUp() {
+ // login user
+ \Test_Encryption_Util::loginHelper(\Test_Encryption_Util::TEST_ENCRYPTION_UTIL_USER1);
\OC_User::setUserId(\Test_Encryption_Util::TEST_ENCRYPTION_UTIL_USER1);
$this->userId = \Test_Encryption_Util::TEST_ENCRYPTION_UTIL_USER1;
$this->pass = \Test_Encryption_Util::TEST_ENCRYPTION_UTIL_USER1;
@@ -328,7 +330,7 @@ class Test_Encryption_Util extends \PHPUnit_Framework_TestCase {
$fileInfoUnencrypted = $this->view->getFileInfo($this->userId . '/files/' . $filename);
- $this->assertTrue(is_array($fileInfoUnencrypted));
+ $this->assertTrue($fileInfoUnencrypted instanceof \OC\Files\FileInfo);
// enable file encryption again
\OC_App::enable('files_encryption');
@@ -338,7 +340,7 @@ class Test_Encryption_Util extends \PHPUnit_Framework_TestCase {
$fileInfoEncrypted = $this->view->getFileInfo($this->userId . '/files/' . $filename);
- $this->assertTrue(is_array($fileInfoEncrypted));
+ $this->assertTrue($fileInfoEncrypted instanceof \OC\Files\FileInfo);
// check if mtime and etags unchanged
$this->assertEquals($fileInfoEncrypted['mtime'], $fileInfoUnencrypted['mtime']);
@@ -357,23 +359,98 @@ class Test_Encryption_Util extends \PHPUnit_Framework_TestCase {
$fileInfoEncrypted = $this->view->getFileInfo($this->userId . '/files/' . $filename);
- $this->assertTrue(is_array($fileInfoEncrypted));
+ $this->assertTrue($fileInfoEncrypted instanceof \OC\Files\FileInfo);
+ $this->assertEquals($fileInfoEncrypted['encrypted'], 1);
- // encrypt all unencrypted files
- $util->decryptAll('/' . $this->userId . '/' . 'files');
+ // decrypt all encrypted files
+ $result = $util->decryptAll('/' . $this->userId . '/' . 'files');
+
+ $this->assertTrue($result);
$fileInfoUnencrypted = $this->view->getFileInfo($this->userId . '/files/' . $filename);
- $this->assertTrue(is_array($fileInfoUnencrypted));
+ $this->assertTrue($fileInfoUnencrypted instanceof \OC\Files\FileInfo);
// check if mtime and etags unchanged
$this->assertEquals($fileInfoEncrypted['mtime'], $fileInfoUnencrypted['mtime']);
$this->assertEquals($fileInfoEncrypted['etag'], $fileInfoUnencrypted['etag']);
+ // file should no longer be encrypted
+ $this->assertEquals(0, $fileInfoUnencrypted['encrypted']);
$this->view->unlink($this->userId . '/files/' . $filename);
}
+ function testDescryptAllWithBrokenFiles() {
+
+ $file1 = "/decryptAll1" . uniqid() . ".txt";
+ $file2 = "/decryptAll2" . uniqid() . ".txt";
+
+ $util = new 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);
+
+ $fileInfoEncrypted1 = $this->view->getFileInfo($this->userId . '/files/' . $file1);
+ $fileInfoEncrypted2 = $this->view->getFileInfo($this->userId . '/files/' . $file2);
+
+ $this->assertTrue($fileInfoEncrypted1 instanceof \OC\Files\FileInfo);
+ $this->assertTrue($fileInfoEncrypted2 instanceof \OC\Files\FileInfo);
+ $this->assertEquals($fileInfoEncrypted1['encrypted'], 1);
+ $this->assertEquals($fileInfoEncrypted2['encrypted'], 1);
+
+ // rename keyfile for file1 so that the decryption for file1 fails
+ // Expected behaviour: decryptAll() returns false, file2 gets decrypted anyway
+ $this->view->rename($this->userId . '/files_encryption/keyfiles/' . $file1 . '.key',
+ $this->userId . '/files_encryption/keyfiles/' . $file1 . '.key.moved');
+
+ // decrypt all encrypted files
+ $result = $util->decryptAll('/' . $this->userId . '/' . 'files');
+
+ $this->assertFalse($result);
+
+ $fileInfoUnencrypted1 = $this->view->getFileInfo($this->userId . '/files/' . $file1);
+ $fileInfoUnencrypted2 = $this->view->getFileInfo($this->userId . '/files/' . $file2);
+
+ $this->assertTrue($fileInfoUnencrypted1 instanceof \OC\Files\FileInfo);
+ $this->assertTrue($fileInfoUnencrypted2 instanceof \OC\Files\FileInfo);
+
+ // file1 should be still encrypted; file2 should be decrypted
+ $this->assertEquals(1, $fileInfoUnencrypted1['encrypted']);
+ $this->assertEquals(0, $fileInfoUnencrypted2['encrypted']);
+
+ // keyfiles and share keys should still exist
+ $this->assertTrue($this->view->is_dir($this->userId . '/files_encryption/keyfiles/'));
+ $this->assertTrue($this->view->is_dir($this->userId . '/files_encryption/share-keys/'));
+
+ // rename the keyfile for file1 back
+ $this->view->rename($this->userId . '/files_encryption/keyfiles/' . $file1 . '.key.moved',
+ $this->userId . '/files_encryption/keyfiles/' . $file1 . '.key');
+
+ // try again to decrypt all encrypted files
+ $result = $util->decryptAll('/' . $this->userId . '/' . 'files');
+
+ $this->assertTrue($result);
+
+ $fileInfoUnencrypted1 = $this->view->getFileInfo($this->userId . '/files/' . $file1);
+ $fileInfoUnencrypted2 = $this->view->getFileInfo($this->userId . '/files/' . $file2);
+
+ $this->assertTrue($fileInfoUnencrypted1 instanceof \OC\Files\FileInfo);
+ $this->assertTrue($fileInfoUnencrypted2 instanceof \OC\Files\FileInfo);
+
+ // now both files should be decrypted
+ $this->assertEquals(0, $fileInfoUnencrypted1['encrypted']);
+ $this->assertEquals(0, $fileInfoUnencrypted2['encrypted']);
+
+ // keyfiles and share keys should be deleted
+ $this->assertFalse($this->view->is_dir($this->userId . '/files_encryption/keyfiles/'));
+ $this->assertFalse($this->view->is_dir($this->userId . '/files_encryption/share-keys/'));
+
+ $this->view->unlink($this->userId . '/files/' . $file1);
+ $this->view->unlink($this->userId . '/files/' . $file2);
+
+ }
+
/**
* @large
*/
@@ -461,7 +538,7 @@ class Test_Encryption_Util extends \PHPUnit_Framework_TestCase {
* helper function to set migration status to the right value
* to be able to test the migration path
*
- * @param $status needed migration status for test
+ * @param integer $status needed migration status for test
* @param $user for which user the status should be set
* @return boolean
*/