Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2014-05-21 11:57:45 +0400
committerVincent Petry <pvince81@owncloud.com>2014-05-21 11:57:45 +0400
commit9b23a210c9b33c40364e207b5791e550efd2b72f (patch)
tree62d2396bbdbd51db773333c6d111e6ce51ae3ff0 /apps/files_encryption/tests/hooks.php
parent40fc1d5b4b3b05b9d2e036f3d853668a38b0e0c2 (diff)
parentd9f715bdad6ced747924567638471a7402726abf (diff)
Merge pull request #8637 from owncloud/enc_improved_error_handling
[encryption] improved error handling during password change
Diffstat (limited to 'apps/files_encryption/tests/hooks.php')
-rw-r--r--apps/files_encryption/tests/hooks.php42
1 files changed, 42 insertions, 0 deletions
diff --git a/apps/files_encryption/tests/hooks.php b/apps/files_encryption/tests/hooks.php
index fcb369c7238..43703472618 100644
--- a/apps/files_encryption/tests/hooks.php
+++ b/apps/files_encryption/tests/hooks.php
@@ -311,4 +311,46 @@ class Test_Encryption_Hooks extends \PHPUnit_Framework_TestCase {
$this->rootView->unlink('/' . self::TEST_ENCRYPTION_HOOKS_USER1 . '/files/' . $this->folder);
}
+ /**
+ * @brief replacing encryption keys during password change should be allowed
+ * until the user logged in for the first time
+ */
+ public function testSetPassphrase() {
+
+ $view = new \OC\Files\View();
+
+ // set user password for the first time
+ \OCA\Encryption\Hooks::postCreateUser(array('uid' => 'newUser', 'password' => 'newUserPassword'));
+
+ $this->assertTrue($view->file_exists('public-keys/newUser.public.key'));
+ $this->assertTrue($view->file_exists('newUser/files_encryption/newUser.private.key'));
+
+ // check if we are able to decrypt the private key
+ $encryptedKey = \OCA\Encryption\Keymanager::getPrivateKey($view, 'newUser');
+ $privateKey = \OCA\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
+ \OCA\Encryption\Hooks::setPassphrase(array('uid' => 'newUser', 'password' => 'passwordChanged'));
+
+ $encryptedKey = \OCA\Encryption\Keymanager::getPrivateKey($view, 'newUser');
+ $privateKey = \OCA\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
+ \OCA\Encryption\Hooks::setPassphrase(array('uid' => 'newUser', 'password' => 'passwordChanged2'));
+
+ $encryptedKey = \OCA\Encryption\Keymanager::getPrivateKey($view, 'newUser');
+ $privateKey = \OCA\Encryption\Crypt::decryptPrivateKey($encryptedKey, 'passwordChanged2');
+ $this->assertFalse($privateKey);
+
+ $privateKey = \OCA\Encryption\Crypt::decryptPrivateKey($encryptedKey, 'passwordChanged');
+ $this->assertTrue(is_string($privateKey));
+
+ }
+
}