summaryrefslogtreecommitdiffstats
path: root/apps/files_encryption/tests
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2014-02-18 18:31:33 +0100
committerThomas Müller <thomas.mueller@tmit.eu>2014-02-18 18:31:33 +0100
commitc6f4f85e27a10459422ab9789c894d13f0cd34c7 (patch)
tree6b4cf7a304242c5891952b428b3bca950924f309 /apps/files_encryption/tests
parent9fac95c2ab46a734607657bbad6f164aaa61286f (diff)
parent8991e4505adba2dae8afe7b7941ec744bfe78712 (diff)
downloadnextcloud-server-c6f4f85e27a10459422ab9789c894d13f0cd34c7.tar.gz
nextcloud-server-c6f4f85e27a10459422ab9789c894d13f0cd34c7.zip
Merge branch 'master' into scrutinizer_documentation_patches
Conflicts: lib/private/migration/content.php
Diffstat (limited to 'apps/files_encryption/tests')
-rwxr-xr-xapps/files_encryption/tests/share.php12
-rwxr-xr-xapps/files_encryption/tests/util.php81
2 files changed, 85 insertions, 8 deletions
diff --git a/apps/files_encryption/tests/share.php b/apps/files_encryption/tests/share.php
index 5c6569f20e7..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');
@@ -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(
@@ -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'));
}
/**
diff --git a/apps/files_encryption/tests/util.php b/apps/files_encryption/tests/util.php
index f87502e6cab..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;
@@ -358,9 +360,12 @@ class Test_Encryption_Util extends \PHPUnit_Framework_TestCase {
$fileInfoEncrypted = $this->view->getFileInfo($this->userId . '/files/' . $filename);
$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);
@@ -369,11 +374,83 @@ class Test_Encryption_Util extends \PHPUnit_Framework_TestCase {
// 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
*/