Skip to content
Open
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
3 changes: 2 additions & 1 deletion apps/dav/appinfo/v1/publicwebdav.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
Server::get(IRequest::class),
Server::get(\OCP\Share\IManager::class),
Server::get(ISession::class),
Server::get(IThrottler::class)
Server::get(IThrottler::class),
Server::get(IUserSession::class),
);
$authPlugin = new \Sabre\DAV\Auth\Plugin($authBackend);

Expand Down
1 change: 1 addition & 0 deletions apps/dav/appinfo/v2/publicremote.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
Server::get(IThrottler::class),
Server::get(LoggerInterface::class),
Server::get(IURLGenerator::class),
Server::get(IUserSession::class),
);
$authPlugin = new \Sabre\DAV\Auth\Plugin($authBackend);

Expand Down
12 changes: 7 additions & 5 deletions apps/dav/lib/Connector/LegacyPublicAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use OCP\Defaults;
use OCP\IRequest;
use OCP\ISession;
use OCP\IUserSession;
use OCP\Security\Bruteforce\IThrottler;
use OCP\Share\Exceptions\ShareNotFound;
use OCP\Share\IManager;
Expand All @@ -28,10 +29,11 @@ class LegacyPublicAuth extends AbstractBasic {
private ?IShare $share = null;

public function __construct(
private IRequest $request,
private IManager $shareManager,
private ISession $session,
private IThrottler $throttler,
private readonly IRequest $request,
private readonly IManager $shareManager,
private readonly ISession $session,
private readonly IThrottler $throttler,
private readonly IUserSession $userSession,
) {
// setup realm
$defaults = new Defaults();
Expand Down Expand Up @@ -62,7 +64,7 @@ protected function validateUserPass($username, $password) {

$this->share = $share;

\OC_User::setIncognitoMode(true);
$this->userSession->setIncognitoMode(true);

// check if the share is password protected
if ($share->getPassword() !== null) {
Expand Down
18 changes: 10 additions & 8 deletions apps/dav/lib/Connector/Sabre/PublicAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use OCP\IRequest;
use OCP\ISession;
use OCP\IURLGenerator;
use OCP\IUserSession;
use OCP\Security\Bruteforce\IThrottler;
use OCP\Security\Bruteforce\MaxDelayReached;
use OCP\Share\Exceptions\ShareNotFound;
Expand Down Expand Up @@ -42,12 +43,13 @@ class PublicAuth extends AbstractBasic {
private ?IShare $share = null;

public function __construct(
private IRequest $request,
private IManager $shareManager,
private ISession $session,
private IThrottler $throttler,
private LoggerInterface $logger,
private IURLGenerator $urlGenerator,
private readonly IRequest $request,
private readonly IManager $shareManager,
private readonly ISession $session,
private readonly IThrottler $throttler,
private readonly LoggerInterface $logger,
private readonly IURLGenerator $urlGenerator,
private readonly IUserSession $userSession,
) {
// setup realm
$defaults = new Defaults();
Expand Down Expand Up @@ -134,7 +136,7 @@ private function checkToken(): array {
}

$this->share = $share;
\OC_User::setIncognitoMode(true);
$this->userSession->setIncognitoMode(true);

// If already authenticated
if ($this->isShareInSession($share)) {
Expand Down Expand Up @@ -172,7 +174,7 @@ protected function validateUserPass($username, $password) {
return false;
}

\OC_User::setIncognitoMode(true);
$this->userSession->setIncognitoMode(true);

// check if the share is password protected
if ($share->getPassword() !== null) {
Expand Down
19 changes: 12 additions & 7 deletions apps/dav/tests/unit/Connector/LegacyPublicAuthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@
namespace OCA\DAV\Tests\unit\Connector;

use OCA\DAV\Connector\LegacyPublicAuth;
use OCP\Files\ISetupManager;
use OCP\IRequest;
use OCP\ISession;
use OCP\IUser;
use OCP\IUserSession;
use OCP\Security\Bruteforce\IThrottler;
use OCP\Server;
use OCP\Share\Exceptions\ShareNotFound;
use OCP\Share\IManager;
use OCP\Share\IShare;
Expand All @@ -26,7 +30,7 @@ class LegacyPublicAuthTest extends TestCase {
private IManager&MockObject $shareManager;
private IThrottler&MockObject $throttler;
private LegacyPublicAuth $auth;
private string|false $oldUser;
private ?IUser $oldUser;

protected function setUp(): void {
parent::setUp();
Expand All @@ -40,20 +44,21 @@ protected function setUp(): void {
$this->request,
$this->shareManager,
$this->session,
$this->throttler
$this->throttler,
$this->createMock(IUserSession::class),
);

// Store current user
$this->oldUser = \OC_User::getUser();
$this->oldUser = Server::get(IUserSession::class)->getUser() ?? null;
}

protected function tearDown(): void {
\OC_User::setIncognitoMode(false);
Server::get(IUserSession::class)->setIncognitoMode(false);

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

parent::tearDown();
Expand Down
18 changes: 11 additions & 7 deletions apps/dav/tests/unit/Connector/Sabre/PublicAuthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@
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\IUser;
use OCP\IUserSession;
use OCP\Security\Bruteforce\IThrottler;
use OCP\Server;
use OCP\Share\Exceptions\ShareNotFound;
use OCP\Share\IManager;
use OCP\Share\IShare;
Expand All @@ -35,8 +39,7 @@ class PublicAuthTest extends \Test\TestCase {
private LoggerInterface&MockObject $logger;
private IURLGenerator&MockObject $urlGenerator;
private PublicAuth $auth;

private bool|string $oldUser;
private ?IUser $oldUser;

protected function setUp(): void {
parent::setUp();
Expand All @@ -55,19 +58,20 @@ protected function setUp(): void {
$this->throttler,
$this->logger,
$this->urlGenerator,
$this->createMock(IUserSession::class),
);

// Store current user
$this->oldUser = \OC_User::getUser();
$this->oldUser = Server::get(IUserSession::class)->getUser() ?? null;
}

protected function tearDown(): void {
\OC_User::setIncognitoMode(false);
Server::get(IUserSession::class)->setIncognitoMode(false);

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

parent::tearDown();
Expand Down
18 changes: 11 additions & 7 deletions apps/federatedfilesharing/tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,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 @@ -56,8 +57,9 @@ public static function tearDownAfterClass(): void {
$user->delete();
}

\OC_Util::tearDownFS();
\OC_User::setUserId('');
$setupManager = Server::get(ISetupManager::class);
$setupManager->tearDown();
self::setUserId('');
Filesystem::tearDown();

// reset backend
Expand All @@ -69,13 +71,13 @@ public static function tearDownAfterClass(): void {
parent::tearDownAfterClass();
}

protected static function loginHelper(string $user, bool $create = false, bool $password = false) {
protected static function loginHelper(string $user, bool $create = false, bool $password = false): void {
if ($password === false) {
$password = $user;
}

$userManager = Server::get(IUserManager::class);
if ($create) {
$userManager = Server::get(IUserManager::class);
$groupManager = Server::get(IGroupManager::class);

$userObject = $userManager->createUser($user, $password);
Expand All @@ -84,14 +86,16 @@ protected static function loginHelper(string $user, bool $create = false, bool $
if ($group && $userObject) {
$group->addUser($userObject);
}
} else {
$userObject = $userManager->get($user);
}

\OC_Util::tearDownFS();
$setupManager = Server::get(ISetupManager::class);
$setupManager->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);
$setupManager->setupForUser($userObject);
}
}
4 changes: 2 additions & 2 deletions apps/files/tests/Service/TagServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ protected function setUp(): void {
$this->user = static::getUniqueID('user');
$this->activityManager = $this->createMock(IManager::class);
Server::get(IUserManager::class)->createUser($this->user, 'test');
\OC_User::setUserId($this->user);
self::setUserId($this->user);
\OC_Util::setupFS($this->user);
$user = $this->createMock(IUser::class);
$this->userSession = $this->createMock(IUserSession::class);
Expand Down Expand Up @@ -69,7 +69,7 @@ protected function getTagService(array $methods = []): TagService&MockObject {
}

protected function tearDown(): void {
\OC_User::setUserId('');
self::setUserId('');
$user = Server::get(IUserManager::class)->get($this->user);
if ($user !== null) {
$user->delete();
Expand Down
8 changes: 4 additions & 4 deletions apps/files_external/lib/Lib/Storage/SFTP.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use OCP\Constants;
use OCP\Files\FileInfo;
use OCP\Files\IMimeTypeDetector;
use OCP\IUserSession;
use OCP\Server;
use phpseclib\Net\SFTP\Stream;

Expand Down Expand Up @@ -182,13 +183,12 @@ private function absPath(string $path): string {

private function hostKeysPath(): string|false {
try {
$userId = \OC_User::getUser();
if ($userId === false) {
$user = Server::get(IUserSession::class)->getUser();
if ($user === null) {
return false;
}

$view = new View('/' . $userId . '/files_external');

$view = new View('/' . $user->getUID() . '/files_external');
return $view->getLocalFile('ssh_hostKeys');
} catch (\Exception $e) {
}
Expand Down
10 changes: 10 additions & 0 deletions apps/files_external/lib/Migration/DummyUserSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

use OCP\IUser;
use OCP\IUserSession;
use Override;

class DummyUserSession implements IUserSession {

Expand Down Expand Up @@ -54,4 +55,13 @@ public function getImpersonatingUserID() : ?string {
public function setImpersonatingUserID(bool $useCurrentUser = true): void {
//no OP
}

#[Override]
public function setIncognitoMode(bool $incognitoMode): void {
}

#[Override]
public function isIncognitoMode(): bool {
return false;
}
}
6 changes: 4 additions & 2 deletions apps/files_sharing/lib/Controller/ShareController.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
use OCP\ISession;
use OCP\IURLGenerator;
use OCP\IUserManager;
use OCP\IUserSession;
use OCP\Security\Events\GenerateSecurePasswordEvent;
use OCP\Security\ISecureRandom;
use OCP\Security\PasswordContext;
Expand Down Expand Up @@ -78,6 +79,7 @@ public function __construct(
protected ISecureRandom $secureRandom,
protected Defaults $defaults,
private IPublicShareTemplateFactory $publicShareTemplateFactory,
private IUserSession $userSession,
) {
parent::__construct($appName, $request, $session, $urlGenerator);
}
Expand Down Expand Up @@ -299,7 +301,7 @@ private function validateShare(IShare $share) {
#[PublicPage]
#[NoCSRFRequired]
public function showShare($path = ''): TemplateResponse {
\OC_User::setIncognitoMode(true);
$this->userSession->setIncognitoMode(true);

// Check whether share exists
try {
Expand Down Expand Up @@ -353,7 +355,7 @@ public function showShare($path = ''): TemplateResponse {
#[NoCSRFRequired]
#[NoSameSiteCookieRequired]
public function downloadShare(string $token, ?string $files = null, string $path = ''): NotFoundResponse|RedirectResponse|DataResponse {
\OC_User::setIncognitoMode(true);
$this->userSession->setIncognitoMode(true);

$share = $this->shareManager->getShareByToken($token);

Expand Down
14 changes: 10 additions & 4 deletions apps/files_sharing/lib/Updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
use OCP\Files\Folder;
use OCP\Files\Mount\IMountManager;
use OCP\Files\NotFoundException;
use OCP\IUserSession;
use OCP\Server;
use OCP\Share\IShare;
use RuntimeException;

class Updater {

Expand Down Expand Up @@ -139,14 +141,18 @@ private static function moveShareInOrOutOfShare($path): void {
* @param string $newPath new path relative to data/user/files
*/
private static function renameChildren($oldPath, $newPath) {
$absNewPath = Filesystem::normalizePath('/' . \OC_User::getUser() . '/files/' . $newPath);
$absOldPath = Filesystem::normalizePath('/' . \OC_User::getUser() . '/files/' . $oldPath);
$user = Server::get(IUserSession::class)->getUser();
if ($user === null) {
throw new RuntimeException('Unable to find current user');
}
$absNewPath = Filesystem::normalizePath('/' . $user->getUID() . '/files/' . $newPath);
$absOldPath = Filesystem::normalizePath('/' . $user->getUID() . '/files/' . $oldPath);

$mountManager = Filesystem::getMountManager();
$mountedShares = $mountManager->findIn('/' . \OC_User::getUser() . '/files/' . $oldPath);
$mountedShares = $mountManager->findIn('/' . $user->getUID() . '/files/' . $oldPath);
foreach ($mountedShares as $mount) {
/** @var MountPoint $mount */
if ($mount->getStorage()->instanceOfStorage(ISharedStorage::class)) {
if ($mount->getStorage()->instanceOfStorage(\OCP\Files\Storage\ISharedStorage::class)) {
$mountPoint = $mount->getMountPoint();
$target = str_replace($absOldPath, $absNewPath, $mountPoint);
$mount->moveMount($target);
Expand Down
Loading
Loading