public function preSetPassphrase($params) {
if (App::isEnabled('encryption')) {
- if (!$this->user->getUser()->canChangePassword()) {
+ $user = $this->user->getUser();
+
+ if ($user && !$user->canChangePassword()) {
$this->setPassphrase($params);
}
}
// 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,
// 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;
$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')
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();
$this->recoveryMock = $recoveryMock;
$this->utilMock = $utilMock;
$this->instance = new UserHooks($this->keyManagerMock,
- $loggerMock,
+ $this->loggerMock,
$this->userSetupMock,
$this->userSessionMock,
$this->utilMock,