Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/private/Encryption/Keys/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,11 @@ protected function keySetPreparation($path) {
* @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);
}
Expand Down
33 changes: 33 additions & 0 deletions tests/lib/Encryption/Keys/StorageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public function setUp() {
->disableOriginalConstructor()
->getMock();

$this->util->method('getKeyStorageRoot')->willReturn('');

$this->view = $this->getMockBuilder('OC\Files\View')
->disableOriginalConstructor()
->getMock();
Expand All @@ -79,6 +81,10 @@ public function setUp() {
$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')
Expand Down Expand Up @@ -277,6 +283,33 @@ public function testGetUserKeyShared() {
$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
*
Expand Down