Skip to content
Draft
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
2 changes: 2 additions & 0 deletions apps/dav/appinfo/v1/publicwebdav.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use OCP\Constants;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\IRootFolder;
use OCP\Files\ISetupManager;
use OCP\Files\Mount\IMountManager;
use OCP\Files\Storage\IStorage;
use OCP\IConfig;
Expand Down Expand Up @@ -56,6 +57,7 @@
Server::get(ISession::class),
Server::get(IRequest::class),
Server::get(IConfig::class),
Server::get(ISetupManager::class),
allowOcmAccessToken: true,
);
$authPlugin = new \Sabre\DAV\Auth\Plugin($authBackend);
Expand Down
2 changes: 2 additions & 0 deletions apps/dav/appinfo/v1/webdav.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use OCA\DAV\Connector\Sabre\ServerFactory;
use OCA\DAV\Events\SabrePluginAddEvent;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\ISetupManager;
use OCP\Files\Mount\IMountManager;
use OCP\IConfig;
use OCP\IDBConnection;
Expand Down Expand Up @@ -66,6 +67,7 @@
Server::get(ISession::class),
Server::get(IRequest::class),
Server::get(IConfig::class),
Server::get(ISetupManager::class),
);
$authPlugin->addBackend($bearerAuthPlugin);

Expand Down
2 changes: 2 additions & 0 deletions apps/dav/appinfo/v2/publicremote.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\IHomeStorage;
use OCP\Files\IRootFolder;
use OCP\Files\ISetupManager;
use OCP\Files\Mount\IMountManager;
use OCP\Files\Storage\IStorage;
use OCP\ICacheFactory;
Expand Down Expand Up @@ -74,6 +75,7 @@
$session,
$request,
Server::get(IConfig::class),
Server::get(ISetupManager::class),
allowOcmAccessToken: true,
);
$authPlugin = new \Sabre\DAV\Auth\Plugin($authBackend);
Expand Down
13 changes: 8 additions & 5 deletions apps/dav/lib/Connector/Sabre/BearerAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@

use OCP\AppFramework\Http;
use OCP\Defaults;
use OCP\Files\ISetupManager;
use OCP\IConfig;
use OCP\IRequest;
use OCP\ISession;
use OCP\IUser;
use OCP\IUserSession;
use OCP\Server;
use OCP\Share\IManager;
Expand All @@ -26,6 +28,7 @@ public function __construct(
private ISession $session,
private IRequest $request,
private IConfig $config,
private ISetupManager $setupManager,
private string $principalPrefix = 'principals/users/',
private string $token = '',
private bool $allowOcmAccessToken = false,
Expand All @@ -35,18 +38,18 @@ public function __construct(
$this->realm = $defaults->getName() ?: 'Nextcloud';
}

private function setupUserFs($userId) {
\OC_Util::setupFS($userId);
private function setupUserFs(IUser $user) {
$this->setupManager->setupForUser($user);
$this->session->close();
return $this->principalPrefix . $userId;
return $this->principalPrefix . $user->getUID();
}

/**
* {@inheritdoc}
*/
#[\Override]
public function validateBearerToken($bearerToken) {
\OC_Util::setupFS();
$this->setupManager->setupRoot();
$this->token = $bearerToken;

// public.php sets incognito mode for anonymous share access, which makes
Expand All @@ -61,7 +64,7 @@ public function validateBearerToken($bearerToken) {
$this->userSession->tryTokenLogin($this->request, $this->allowOcmAccessToken);
}
if ($this->userSession->isLoggedIn()) {
return $this->setupUserFs($this->userSession->getUser()->getUID());
return $this->setupUserFs($this->userSession->getUser());
}

return false;
Expand Down
2 changes: 2 additions & 0 deletions apps/dav/lib/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\IFilenameValidator;
use OCP\Files\IRootFolder;
use OCP\Files\ISetupManager;
use OCP\FilesMetadata\IFilesMetadataManager;
use OCP\IAppConfig;
use OCP\ICacheFactory;
Expand Down Expand Up @@ -174,6 +175,7 @@ public function __construct(
\OCP\Server::get(ISession::class),
\OCP\Server::get(IRequest::class),
\OCP\Server::get(IConfig::class),
\OCP\Server::get(ISetupManager::class),
);
$authPlugin->addBackend($bearerAuthBackend);
// because we are throwing exceptions this plugin has to be the last one
Expand Down
8 changes: 7 additions & 1 deletion apps/dav/tests/unit/Connector/LegacyPublicAuthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@
namespace OCA\DAV\Tests\unit\Connector;

use OCA\DAV\Connector\LegacyPublicAuth;
use OCP\Files\ISetupManager;
use OCP\IRequest;
use OCP\ISession;
use OCP\IUserManager;
use OCP\Security\Bruteforce\IThrottler;
use OCP\Server;
use OCP\Share\Exceptions\ShareNotFound;
use OCP\Share\IManager;
use OCP\Share\IShare;
Expand Down Expand Up @@ -54,7 +57,10 @@ protected function tearDown(): void {
// Set old user
\OC_User::setUserId($this->oldUser ?: null);
if ($this->oldUser !== false) {
\OC_Util::setupFS($this->oldUser);
$userObj = Server::get(IUserManager::class)->get($this->oldUser);
if ($userObj !== null) {
Server::get(ISetupManager::class)->setupForUser($userObj);
}
}

parent::tearDown();
Expand Down
7 changes: 5 additions & 2 deletions apps/dav/tests/unit/Connector/Sabre/BearerAuthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use OC\User\Session;
use OCA\DAV\Connector\Sabre\BearerAuth;
use OCP\Files\ISetupManager;
use OCP\IConfig;
use OCP\IRequest;
use OCP\ISession;
Expand All @@ -26,6 +27,7 @@ class BearerAuthTest extends TestCase {
private ISession&MockObject $session;
private IRequest&MockObject $request;
private BearerAuth $bearerAuth;
private ISetupManager&MockObject $setupManager;

private IConfig&MockObject $config;

Expand All @@ -36,12 +38,14 @@ protected function setUp(): void {
$this->session = $this->createMock(ISession::class);
$this->request = $this->createMock(IRequest::class);
$this->config = $this->createMock(IConfig::class);
$this->setupManager = $this->createMock(ISetupManager::class);

$this->bearerAuth = new BearerAuth(
$this->userSession,
$this->session,
$this->request,
$this->config,
$this->setupManager,
);
}

Expand Down Expand Up @@ -88,6 +92,7 @@ public function testValidateBearerTokenPassesOcmFlagWhenAllowed(): void {
$this->session,
$this->request,
$this->config,
$this->setupManager,
allowOcmAccessToken: true,
);
$this->userSession
Expand All @@ -105,9 +110,7 @@ public function testValidateBearerTokenPassesOcmFlagWhenAllowed(): void {
}

public function testChallenge(): void {
/** @var RequestInterface&MockObject $request */
$request = $this->createMock(RequestInterface::class);
/** @var ResponseInterface&MockObject $response */
$response = $this->createMock(ResponseInterface::class);
$this->bearerAuth->challenge($request, $response);
$this->assertTrue(true);
Expand Down
10 changes: 8 additions & 2 deletions apps/dav/tests/unit/Connector/Sabre/PublicAuthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@
namespace OCA\DAV\Tests\unit\Connector;

use OCA\DAV\Connector\Sabre\PublicAuth;
use OCP\Files\ISetupManager;
use OCP\IRequest;
use OCP\ISession;
use OCP\IURLGenerator;
use OCP\IUserManager;
use OCP\Security\Bruteforce\IThrottler;
use OCP\Server;
use OCP\Share\Exceptions\ShareNotFound;
use OCP\Share\IManager;
use OCP\Share\IShare;
Expand Down Expand Up @@ -66,9 +69,12 @@ protected function tearDown(): void {
\OC_User::setIncognitoMode(false);

// Set old user
\OC_User::setUserId($this->oldUser);
\OC_User::setUserId($this->oldUser ?: null);
if ($this->oldUser !== false) {
\OC_Util::setupFS($this->oldUser);
$userObj = Server::get(IUserManager::class)->get($this->oldUser);
if ($userObj !== null) {
Server::get(ISetupManager::class)->setupForUser($userObj);
}
}

parent::tearDown();
Expand Down
6 changes: 4 additions & 2 deletions apps/dav/tests/unit/Connector/Sabre/RequestTest/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace OCA\DAV\Tests\unit\Connector\Sabre\RequestTest;

use OCP\Files\ISetupManager;
use OCP\IUserSession;
use OCP\Server;
use Sabre\DAV\Auth\Backend\BackendInterface;
Expand Down Expand Up @@ -61,8 +62,9 @@ public function check(RequestInterface $request, ResponseInterface $response) {
$result = $userSession->login($this->user, $this->password);
if ($result) {
//we need to pass the user name, which may differ from login name
$user = $userSession->getUser()->getUID();
\OC_Util::setupFS($user);
$userObj = $userSession->getUser();
$user = $userObj->getUID();
Server::get(ISetupManager::class)->setupForUser($userObj);
//trigger creation of user home and /files folder
\OC::$server->getUserFolder($user);
return [true, "principals/$user"];
Expand Down
9 changes: 6 additions & 3 deletions apps/federatedfilesharing/tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use OC\Files\Filesystem;
use OC\Group\Database;
use OCP\Files\IRootFolder;
use OCP\Files\ISetupManager;
use OCP\IGroupManager;
use OCP\IUserManager;
use OCP\IUserSession;
Expand Down Expand Up @@ -57,7 +58,6 @@ public static function tearDownAfterClass(): void {
$user->delete();
}

\OC_Util::tearDownFS();
\OC_User::setUserId('');
Filesystem::tearDown();

Expand Down Expand Up @@ -87,12 +87,15 @@ protected static function loginHelper(string $user, bool $create = false, bool $
}
}

\OC_Util::tearDownFS();
Server::get(ISetupManager::class)->tearDown();
Server::get(IUserSession::class)->setUser(null);
Filesystem::tearDown();
Server::get(IUserSession::class)->login($user, $password);
Server::get(IRootFolder::class)->getUserFolder($user);

\OC_Util::setupFS($user);
$userObj = Server::get(IUserManager::class)->get($user);
if ($userObj !== null) {
Server::get(ISetupManager::class)->setupForUser($userObj);
}
}
}
25 changes: 13 additions & 12 deletions apps/files/lib/Service/OwnershipTransferService.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Config\IHomeMountProvider;
use OCP\Files\Config\IUserMountCache;
use OCP\Files\File;
use OCP\Files\FileInfo;
use OCP\Files\InvalidPathException;
use OCP\Files\IRootFolder;
use OCP\Files\ISetupManager;
use OCP\Files\Mount\IMountManager;
use OCP\Files\NotFoundException;
use OCP\IUser;
Expand All @@ -48,14 +48,15 @@
class OwnershipTransferService {

public function __construct(
private IEncryptionManager $encryptionManager,
private IShareManager $shareManager,
private IMountManager $mountManager,
private IUserMountCache $userMountCache,
private IUserManager $userManager,
private IFactory $l10nFactory,
private IRootFolder $rootFolder,
private IEventDispatcher $eventDispatcher,
private readonly IEncryptionManager $encryptionManager,
private readonly IShareManager $shareManager,
private readonly IMountManager $mountManager,
private readonly IUserMountCache $userMountCache,
private readonly IUserManager $userManager,
private readonly IFactory $l10nFactory,
private readonly IRootFolder $rootFolder,
private readonly IEventDispatcher $eventDispatcher,
private readonly ISetupManager $setupManager,
) {
}

Expand Down Expand Up @@ -94,8 +95,8 @@ public function transfer(
// Requesting the user folder will set it up if the user hasn't logged in before
// We need a setupFS for the full filesystem setup before as otherwise we will just return
// a lazy root folder which does not create the destination users folder
\OC_Util::setupFS($sourceUser->getUID());
\OC_Util::setupFS($destinationUser->getUID());
$this->setupManager->setupForUser($sourceUser);
$this->setupManager->setupForUser($destinationUser);
$this->rootFolder->getUserFolder($sourceUser->getUID());
$this->rootFolder->getUserFolder($destinationUser->getUID());
Filesystem::initMountPoints($sourceUid);
Expand Down Expand Up @@ -132,7 +133,7 @@ public function transfer(

if ($move && !$view->is_dir($finalTarget)) {
// Initialize storage
\OC_Util::setupFS($destinationUser->getUID());
$this->setupManager->setupForUser($destinationUser);
}

if ($move && !$firstLogin && count($view->getDirectoryContent($finalTarget)) > 0) {
Expand Down
6 changes: 5 additions & 1 deletion apps/files/tests/Service/TagServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use OCP\Activity\IManager;
use OCP\Files\Folder;
use OCP\Files\IRootFolder;
use OCP\Files\ISetupManager;
use OCP\Files\NotFoundException;
use OCP\ITagManager;
use OCP\ITags;
Expand Down Expand Up @@ -43,7 +44,10 @@ protected function setUp(): void {
$this->activityManager = $this->createMock(IManager::class);
Server::get(IUserManager::class)->createUser($this->user, 'test');
\OC_User::setUserId($this->user);
\OC_Util::setupFS($this->user);
$userObj = Server::get(IUserManager::class)->get($this->user);
if ($userObj !== null) {
Server::get(ISetupManager::class)->setupForUser($userObj);
}
$user = $this->createMock(IUser::class);
$user->expects($this->any())
->method('getUID')
Expand Down
3 changes: 2 additions & 1 deletion apps/files_sharing/tests/ApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use OCP\Constants;
use OCP\Files\Folder;
use OCP\Files\IRootFolder;
use OCP\Files\ISetupManager;
use OCP\IAppConfig;
use OCP\IConfig;
use OCP\IDateTimeZone;
Expand Down Expand Up @@ -1437,7 +1438,7 @@ public function testInvisibleSharesGroup(): void {
$ocs->acceptShare($topId);
$ocs->cleanup();

\OC_Util::tearDownFS();
Server::get(ISetupManager::class)->tearDown();

$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER2);
$ocs->createShare($this->folder, Constants::PERMISSION_ALL, IShare::TYPE_LINK);
Expand Down
Loading
Loading