[Pkg-owncloud-commits] [owncloud] 32/165: fix change password if no user is logged in, occ call

David Prévot taffit at moszumanska.debian.org
Thu Apr 23 04:06:20 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch stable8
in repository owncloud.

commit 195a48b2b85ee324b98cda88a8e17546b33b895d
Author: Bjoern Schiessle <schiessle at owncloud.com>
Date:   Fri Apr 17 10:52:40 2015 +0200

    fix change password if no user is logged in, occ call
---
 apps/encryption/hooks/userhooks.php           | 10 +++++---
 apps/encryption/tests/hooks/UserHooksTest.php | 33 +++++++++++++++++++++++++--
 2 files changed, 38 insertions(+), 5 deletions(-)

diff --git a/apps/encryption/hooks/userhooks.php b/apps/encryption/hooks/userhooks.php
index e61d4f9..b09b8e7 100644
--- a/apps/encryption/hooks/userhooks.php
+++ b/apps/encryption/hooks/userhooks.php
@@ -196,7 +196,9 @@ class UserHooks implements IHook {
 	public function preSetPassphrase($params) {
 		if (App::isEnabled('encryption')) {
 
-			if (!$this->user->getUser()->canChangePassword()) {
+			$user = $this->user->getUser();
+
+			if ($user && !$user->canChangePassword()) {
 				$this->setPassphrase($params);
 			}
 		}
@@ -212,8 +214,10 @@ class UserHooks implements IHook {
 
 		// Get existing decrypted private key
 		$privateKey = $this->session->getPrivateKey();
+		$user = $this->user->getUser();
 
-		if ($params['uid'] === $this->user->getUser()->getUID() && $privateKey) {
+		// current logged in user changes his own password
+		if ($user && $params['uid'] === $user->getUID() && $privateKey) {
 
 			// Encrypt private key with new user pwd as passphrase
 			$encryptedPrivateKey = $this->crypt->symmetricEncryptFileContent($privateKey,
@@ -230,7 +234,7 @@ class UserHooks implements IHook {
 			// NOTE: Session does not need to be updated as the
 			// private key has not changed, only the passphrase
 			// used to decrypt it has changed
-		} else { // admin changed the password for a different user, create new keys and reencrypt file keys
+		} else { // admin changed the password for a different user, create new keys and re-encrypt file keys
 			$user = $params['uid'];
 			$recoveryPassword = isset($params['recoveryPassword']) ? $params['recoveryPassword'] : null;
 
diff --git a/apps/encryption/tests/hooks/UserHooksTest.php b/apps/encryption/tests/hooks/UserHooksTest.php
index 1d76e3b..bcfb33e 100644
--- a/apps/encryption/tests/hooks/UserHooksTest.php
+++ b/apps/encryption/tests/hooks/UserHooksTest.php
@@ -143,6 +143,35 @@ class UserHooksTest extends TestCase {
 		$this->assertNull($this->instance->setPassphrase($this->params));
 	}
 
+	public function testSetPasswordNoUser() {
+		$this->sessionMock->expects($this->once())
+			->method('getPrivateKey')
+			->willReturn(true);
+
+		$userSessionMock = $this->getMockBuilder('OCP\IUserSession')
+			->disableOriginalConstructor()
+			->getMock();
+
+		$userSessionMock->expects($this->any())->method('getUser')->will($this->returnValue(null));
+
+		$this->recoveryMock->expects($this->once())
+			->method('isRecoveryEnabledForUser')
+			->with('testUser')
+			->willReturn(false);
+
+		$userHooks = new UserHooks($this->keyManagerMock,
+			$this->loggerMock,
+			$this->userSetupMock,
+			$userSessionMock,
+			$this->utilMock,
+			$this->sessionMock,
+			$this->cryptMock,
+			$this->recoveryMock
+		);
+
+		$this->assertNull($userHooks->setPassphrase($this->params));
+	}
+
 	public function testPostPasswordReset() {
 		$this->keyManagerMock->expects($this->once())
 			->method('replaceUserKeys')
@@ -157,7 +186,7 @@ class UserHooksTest extends TestCase {
 
 	protected function setUp() {
 		parent::setUp();
-		$loggerMock = $this->getMock('OCP\ILogger');
+		$this->loggerMock = $this->getMock('OCP\ILogger');
 		$this->keyManagerMock = $this->getMockBuilder('OCA\Encryption\KeyManager')
 			->disableOriginalConstructor()
 			->getMock();
@@ -203,7 +232,7 @@ class UserHooksTest extends TestCase {
 		$this->recoveryMock = $recoveryMock;
 		$this->utilMock = $utilMock;
 		$this->instance = new UserHooks($this->keyManagerMock,
-			$loggerMock,
+			$this->loggerMock,
 			$this->userSetupMock,
 			$this->userSessionMock,
 			$this->utilMock,

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git



More information about the Pkg-owncloud-commits mailing list