Throw NoUserException when attempting to init mount point for null user

In some scenarios initMountPoints is called with an empty user, and
also there is no user in the session.

In such cases, it is unsafe to let the code move on with an empty user.
remotes/origin/ldap-integration-tests-1up
Vincent Petry 10 years ago
parent 7be1094ba5
commit 085bcd7da2
No known key found for this signature in database
GPG Key ID: AF8F9EFC56562186
  1. 3
      lib/private/files/filesystem.php
  2. 22
      tests/lib/files/filesystem.php

@ -372,6 +372,9 @@ class Filesystem {
if ($user == '') {
$user = \OC_User::getUser();
}
if ($user === null || $user === false || $user === '') {
throw new \OC\User\NoUserException('Attempted to initialize mount points for null user and no user in session');
}
if (isset(self::$usersSetup[$user])) {
return;
}

@ -319,6 +319,28 @@ class Filesystem extends \Test\TestCase {
\OC\Files\Filesystem::initMountPoints($userId);
}
/**
* @expectedException \OC\User\NoUserException
*/
public function testNullUserThrows() {
\OC\Files\Filesystem::initMountPoints(null);
}
public function testNullUserThrowsTwice() {
$thrown = 0;
try {
\OC\Files\Filesystem::initMountPoints(null);
} catch (NoUserException $e) {
$thrown++;
}
try {
\OC\Files\Filesystem::initMountPoints(null);
} catch (NoUserException $e) {
$thrown++;
}
$this->assertEquals(2, $thrown);
}
/**
* Tests that the home storage is used for the user's mount point
*/

Loading…
Cancel
Save