diff --git a/lib/private/Encryption/Keys/Storage.php b/lib/private/Encryption/Keys/Storage.php index 3abdd745d034..19d947090b9c 100644 --- a/lib/private/Encryption/Keys/Storage.php +++ b/lib/private/Encryption/Keys/Storage.php @@ -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); } diff --git a/tests/lib/Encryption/Keys/StorageTest.php b/tests/lib/Encryption/Keys/StorageTest.php index eeb3e6c2fb04..3943e4f98bd5 100644 --- a/tests/lib/Encryption/Keys/StorageTest.php +++ b/tests/lib/Encryption/Keys/StorageTest.php @@ -61,6 +61,8 @@ public function setUp() { ->disableOriginalConstructor() ->getMock(); + $this->util->method('getKeyStorageRoot')->willReturn(''); + $this->view = $this->getMockBuilder('OC\Files\View') ->disableOriginalConstructor() ->getMock(); @@ -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') @@ -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 *