Commit 703496cd authored by Vincent Petry's avatar Vincent Petry Committed by GitHub
Browse files

Merge pull request #26937 from owncloud/enc-keyroot-fix

Don't mount user home with alternate keys root
parents bedccbb8 f879b16f
......@@ -345,6 +345,11 @@ class Storage implements IStorage {
* @param string $uid user id
*/
protected function setupUserMounts($uid) {
if ($this->root_dir !== '') {
// this means that the keys are stored outside of the user's homes,
// so we don't need to mount anything
return;
}
if (!is_null($uid) && $uid !== '' && $uid !== $this->currentUser) {
\OC\Files\Filesystem::initMountPoints($uid);
}
......
......@@ -61,6 +61,8 @@ class StorageTest extends TestCase {
->disableOriginalConstructor()
->getMock();
$this->util->method('getKeyStorageRoot')->willReturn('');
$this->view = $this->getMockBuilder('OC\Files\View')
->disableOriginalConstructor()
->getMock();
......@@ -79,6 +81,10 @@ class StorageTest extends TestCase {
$this->storage = new Storage($this->view, $this->util, $userSession);
}
public function tearDown() {
\OC\Files\Filesystem::tearDown();
}
public function testSetFileKey() {
$this->util->expects($this->any())
->method('getUidAndFilename')
......@@ -277,6 +283,33 @@ class StorageTest extends TestCase {
$this->assertTrue($this->isUserHomeMounted('user2'));
}
public function testGetUserKeyWhenKeyStorageIsOutsideHome() {
$this->view->expects($this->once())
->method('file_get_contents')
->with($this->equalTo('/enckeys/user2/files_encryption/encModule/user2.publicKey'))
->willReturn('key');
$this->view->expects($this->once())
->method('file_exists')
->with($this->equalTo('/enckeys/user2/files_encryption/encModule/user2.publicKey'))
->willReturn(true);
$user = $this->createMock(IUser::class);
$user->method('getUID')->willReturn('user1');
$userSession = $this->createMock(IUserSession::class);
$userSession->method('getUser')->willReturn($user);
$util = $this->createMock(\OC\Encryption\Util::class);
$util->method('getKeyStorageRoot')->willReturn('enckeys');
$storage = new Storage($this->view, $util, $userSession);
$this->assertFalse($this->isUserHomeMounted('user2'));
$this->assertSame('key',
$storage->getUserKey('user2', 'publicKey', 'encModule')
);
$this->assertFalse($this->isUserHomeMounted('user2'), 'mounting was not necessary');
}
/**
* Returns whether the home of the given user was mounted
*
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment