Browse Source

we need to initialize the mount points of the given user before we recover

access to his files
tags/v9.1.0beta1
Björn Schießle 8 years ago
parent
commit
a3381b1d0c
No account linked to committer's email address
2 changed files with 48 additions and 10 deletions
  1. 11
    0
      apps/encryption/hooks/userhooks.php
  2. 37
    10
      apps/encryption/tests/hooks/UserHooksTest.php

+ 11
- 0
apps/encryption/hooks/userhooks.php View File

namespace OCA\Encryption\Hooks; namespace OCA\Encryption\Hooks;




use OC\Files\Filesystem;
use OCP\IUserManager; use OCP\IUserManager;
use OCP\Util as OCUtil; use OCP\Util as OCUtil;
use OCA\Encryption\Hooks\Contracts\IHook; use OCA\Encryption\Hooks\Contracts\IHook;
// used to decrypt it has changed // used to decrypt it has changed
} else { // admin changed the password for a different user, create new keys and re-encrypt file keys } else { // admin changed the password for a different user, create new keys and re-encrypt file keys
$user = $params['uid']; $user = $params['uid'];
$this->initMountPoints($user);
$recoveryPassword = isset($params['recoveryPassword']) ? $params['recoveryPassword'] : null; $recoveryPassword = isset($params['recoveryPassword']) ? $params['recoveryPassword'] : null;


// we generate new keys if... // we generate new keys if...
} }
} }


/**
* init mount points for given user
*
* @param string $user
* @throws \OC\User\NoUserException
*/
protected function initMountPoints($user) {
Filesystem::initMountPoints($user);
}




/** /**

+ 37
- 10
apps/encryption/tests/hooks/UserHooksTest.php View File

use OCA\Encryption\Hooks\UserHooks; use OCA\Encryption\Hooks\UserHooks;
use Test\TestCase; use Test\TestCase;


/**
* Class UserHooksTest
*
* @group DB
* @package OCA\Encryption\Tests\Hooks
*/
class UserHooksTest extends TestCase { class UserHooksTest extends TestCase {
/** /**
* @var \PHPUnit_Framework_MockObject_MockObject * @var \PHPUnit_Framework_MockObject_MockObject
->willReturnOnConsecutiveCalls(true, false); ->willReturnOnConsecutiveCalls(true, false);




$this->instance = $this->getMockBuilder('OCA\Encryption\Hooks\UserHooks')
->setConstructorArgs(
[
$this->keyManagerMock,
$this->userManagerMock,
$this->loggerMock,
$this->userSetupMock,
$this->userSessionMock,
$this->utilMock,
$this->sessionMock,
$this->cryptMock,
$this->recoveryMock
]
)->setMethods(['initMountPoints'])->getMock();

$this->instance->expects($this->exactly(3))->method('initMountPoints');

// Test first if statement // Test first if statement
$this->assertNull($this->instance->setPassphrase($this->params)); $this->assertNull($this->instance->setPassphrase($this->params));


->with('testUser') ->with('testUser')
->willReturn(false); ->willReturn(false);


$userHooks = new UserHooks($this->keyManagerMock,
$this->userManagerMock,
$this->loggerMock,
$this->userSetupMock,
$userSessionMock,
$this->utilMock,
$this->sessionMock,
$this->cryptMock,
$this->recoveryMock
);
$userHooks = $this->getMockBuilder('OCA\Encryption\Hooks\UserHooks')
->setConstructorArgs(
[
$this->keyManagerMock,
$this->userManagerMock,
$this->loggerMock,
$this->userSetupMock,
$userSessionMock,
$this->utilMock,
$this->sessionMock,
$this->cryptMock,
$this->recoveryMock
]
)->setMethods(['initMountPoints'])->getMock();


$this->assertNull($userHooks->setPassphrase($this->params)); $this->assertNull($userHooks->setPassphrase($this->params));
} }

Loading…
Cancel
Save