aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--build/psalm-baseline-ocp.xml5
-rw-r--r--core/Controller/LoginController.php5
-rw-r--r--core/Controller/RecommendedAppsController.php8
-rw-r--r--core/Controller/SetupController.php8
-rw-r--r--core/Controller/TwoFactorChallengeController.php5
-rw-r--r--lib/base.php6
-rw-r--r--lib/private/URLGenerator.php49
-rw-r--r--lib/private/legacy/OC_Util.php45
-rw-r--r--lib/public/AppFramework/Http/RedirectToDefaultAppResponse.php12
-rw-r--r--lib/public/IURLGenerator.php8
-rw-r--r--tests/Core/Controller/LoginControllerTest.php32
-rw-r--r--tests/Core/Controller/TwoFactorChallengeControllerTest.php7
-rw-r--r--tests/lib/UrlGeneratorTest.php111
-rw-r--r--tests/lib/UtilTest.php105
14 files changed, 228 insertions, 178 deletions
diff --git a/build/psalm-baseline-ocp.xml b/build/psalm-baseline-ocp.xml
index 3306f76e2ce..6f6aa5b85e3 100644
--- a/build/psalm-baseline-ocp.xml
+++ b/build/psalm-baseline-ocp.xml
@@ -50,6 +50,11 @@
<code>array</code>
</InvalidReturnType>
</file>
+ <file src="lib/public/AppFramework/Http/RedirectToDefaultAppResponse.php">
+ <UndefinedClass occurrences="1">
+ <code>\OC</code>
+ </UndefinedClass>
+ </file>
<file src="lib/public/AppFramework/Http/Response.php">
<UndefinedClass occurrences="2">
<code>\OC</code>
diff --git a/core/Controller/LoginController.php b/core/Controller/LoginController.php
index 8a96db97c9e..15ec8365c19 100644
--- a/core/Controller/LoginController.php
+++ b/core/Controller/LoginController.php
@@ -38,7 +38,6 @@ use OC\Authentication\WebAuthn\Manager as WebAuthnManager;
use OC\Security\Bruteforce\Throttler;
use OC\User\Session;
use OC_App;
-use OC_Util;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
@@ -150,7 +149,7 @@ class LoginController extends Controller {
*/
public function showLoginForm(string $user = null, string $redirect_url = null): Http\Response {
if ($this->userSession->isLoggedIn()) {
- return new RedirectResponse(OC_Util::getDefaultPageUrl());
+ return new RedirectResponse($this->urlGenerator->linkToDefaultPageUrl());
}
$loginMessages = $this->session->get('loginMessages');
@@ -274,7 +273,7 @@ class LoginController extends Controller {
return new RedirectResponse($location);
}
}
- return new RedirectResponse(OC_Util::getDefaultPageUrl());
+ return new RedirectResponse($this->urlGenerator->linkToDefaultPageUrl());
}
/**
diff --git a/core/Controller/RecommendedAppsController.php b/core/Controller/RecommendedAppsController.php
index 1b6650ed902..b38aaa31fca 100644
--- a/core/Controller/RecommendedAppsController.php
+++ b/core/Controller/RecommendedAppsController.php
@@ -30,15 +30,20 @@ use OCP\AppFramework\Http\Response;
use OCP\AppFramework\Http\StandaloneTemplateResponse;
use OCP\IInitialStateService;
use OCP\IRequest;
+use OCP\IURLGenerator;
class RecommendedAppsController extends Controller {
+ /** @var IURLGenerator */
+ public $urlGenerator;
/** @var IInitialStateService */
private $initialStateService;
public function __construct(IRequest $request,
+ IURLGenerator $urlGenerator,
IInitialStateService $initialStateService) {
parent::__construct('core', $request);
+ $this->urlGenerator = $urlGenerator;
$this->initialStateService = $initialStateService;
}
@@ -47,7 +52,8 @@ class RecommendedAppsController extends Controller {
* @return Response
*/
public function index(): Response {
- $this->initialStateService->provideInitialState('core', 'defaultPageUrl', \OC_Util::getDefaultPageUrl());
+ $defaultPageUrl = $this->urlGenerator->linkToDefaultPageUrl();
+ $this->initialStateService->provideInitialState('core', 'defaultPageUrl', $defaultPageUrl);
return new StandaloneTemplateResponse($this->appName, 'recommendedapps', [], 'guest');
}
}
diff --git a/core/Controller/SetupController.php b/core/Controller/SetupController.php
index 704a2507b5a..c89709012d1 100644
--- a/core/Controller/SetupController.php
+++ b/core/Controller/SetupController.php
@@ -119,12 +119,12 @@ class SetupController {
}
if ($installRecommended) {
- $urlGenerator = \OC::$server->getURLGenerator();
- $location = $urlGenerator->getAbsoluteURL('index.php/core/apps/recommended');
- header('Location: ' . $location);
+ header('Location: ' . \OC::$server->getURLGenerator()->getAbsoluteURL('index.php/core/apps/recommended'));
+ exit();
+ } else {
+ header('Location: ' . \OC::$server->getURLGenerator()->linkToDefaultPageUrl());
exit();
}
- \OC_Util::redirectToDefaultPage();
}
public function loadAutoConfig($post) {
diff --git a/core/Controller/TwoFactorChallengeController.php b/core/Controller/TwoFactorChallengeController.php
index 30f33230d8f..8f82346c050 100644
--- a/core/Controller/TwoFactorChallengeController.php
+++ b/core/Controller/TwoFactorChallengeController.php
@@ -27,7 +27,6 @@ namespace OC\Core\Controller;
use OC\Authentication\TwoFactorAuth\Manager;
use OC_User;
-use OC_Util;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\RedirectResponse;
use OCP\AppFramework\Http\StandaloneTemplateResponse;
@@ -83,7 +82,7 @@ class TwoFactorChallengeController extends Controller {
protected function getLogoutUrl() {
return OC_User::getLogoutUrl($this->urlGenerator);
}
-
+
/**
* @param IProvider[] $providers
*/
@@ -203,7 +202,7 @@ class TwoFactorChallengeController extends Controller {
if (!is_null($redirect_url)) {
return new RedirectResponse($this->urlGenerator->getAbsoluteURL(urldecode($redirect_url)));
}
- return new RedirectResponse(OC_Util::getDefaultPageUrl());
+ return new RedirectResponse($this->urlGenerator->linkToDefaultPageUrl());
}
} catch (TwoFactorException $e) {
/*
diff --git a/lib/base.php b/lib/base.php
index 45d06da0303..94610576fce 100644
--- a/lib/base.php
+++ b/lib/base.php
@@ -1021,12 +1021,10 @@ class OC {
OC_App::loadApps();
OC_User::setupBackends();
OC_Util::setupFS();
- // FIXME
- // Redirect to default application
- OC_Util::redirectToDefaultPage();
+ header('Location: ' . \OC::$server->getURLGenerator()->linkToDefaultPageUrl());
} else {
// Not handled and not logged in
- header('Location: '.\OC::$server->getURLGenerator()->linkToRouteAbsolute('core.login.showLoginForm'));
+ header('Location: ' . \OC::$server->getURLGenerator()->linkToRouteAbsolute('core.login.showLoginForm'));
}
}
diff --git a/lib/private/URLGenerator.php b/lib/private/URLGenerator.php
index 511c37d2624..382179b23e0 100644
--- a/lib/private/URLGenerator.php
+++ b/lib/private/URLGenerator.php
@@ -8,6 +8,7 @@ declare(strict_types=1);
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
* @author Bart Visscher <bartv@thisnet.nl>
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
+ * @author Daniel Rudolf <github.com@daniel-rudolf.de>
* @author Felix Epp <work@felixepp.de>
* @author Joas Schilling <coding@schilljs.com>
* @author Jörn Friedrich Dreyer <jfd@butonic.de>
@@ -45,6 +46,7 @@ use OCP\ICacheFactory;
use OCP\IConfig;
use OCP\IRequest;
use OCP\IURLGenerator;
+use OCP\IUserSession;
use RuntimeException;
/**
@@ -53,6 +55,8 @@ use RuntimeException;
class URLGenerator implements IURLGenerator {
/** @var IConfig */
private $config;
+ /** @var IUserSession */
+ public $userSession;
/** @var ICacheFactory */
private $cacheFactory;
/** @var IRequest */
@@ -63,10 +67,12 @@ class URLGenerator implements IURLGenerator {
private $baseUrl = null;
public function __construct(IConfig $config,
+ IUserSession $userSession,
ICacheFactory $cacheFactory,
IRequest $request,
Router $router) {
$this->config = $config;
+ $this->userSession = $userSession;
$this->cacheFactory = $cacheFactory;
$this->request = $request;
$this->router = $router;
@@ -268,6 +274,49 @@ class URLGenerator implements IURLGenerator {
}
/**
+ * Returns the URL of the default page based on the system configuration
+ * and the apps visible for the current user
+ * @return string
+ */
+ public function linkToDefaultPageUrl(): string {
+ // Deny the redirect if the URL contains a @
+ // This prevents unvalidated redirects like ?redirect_url=:user@domain.com
+ if (isset($_REQUEST['redirect_url']) && strpos($_REQUEST['redirect_url'], '@') === false) {
+ return $this->getAbsoluteURL(urldecode($_REQUEST['redirect_url']));
+ }
+
+ $defaultPage = $this->config->getAppValue('core', 'defaultpage');
+ if ($defaultPage) {
+ return $this->getAbsoluteURL($defaultPage);
+ }
+
+ $appId = 'files';
+ $defaultApps = explode(',', $this->config->getSystemValue('defaultapp', 'dashboard,files'));
+
+ $userId = $this->userSession->isLoggedIn() ? $this->userSession->getUser()->getUID() : null;
+ if ($userId !== null) {
+ $userDefaultApps = explode(',', $this->config->getUserValue($userId, 'core', 'defaultapp'));
+ $defaultApps = array_filter(array_merge($userDefaultApps, $defaultApps));
+ }
+
+ // find the first app that is enabled for the current user
+ foreach ($defaultApps as $defaultApp) {
+ $defaultApp = \OC_App::cleanAppId(strip_tags($defaultApp));
+ if (\OC::$server->getAppManager()->isEnabledForUser($defaultApp)) {
+ $appId = $defaultApp;
+ break;
+ }
+ }
+
+ if ($this->config->getSystemValue('htaccess.IgnoreFrontController', false) === true
+ || getenv('front_controller_active') === 'true') {
+ return $this->getAbsoluteURL('/apps/' . $appId . '/');
+ }
+
+ return $this->getAbsoluteURL('/index.php/apps/' . $appId . '/');
+ }
+
+ /**
* @return string base url of the current request
*/
public function getBaseUrl(): string {
diff --git a/lib/private/legacy/OC_Util.php b/lib/private/legacy/OC_Util.php
index 333b621e359..35c81dd34e6 100644
--- a/lib/private/legacy/OC_Util.php
+++ b/lib/private/legacy/OC_Util.php
@@ -71,8 +71,8 @@ use OCP\Files\Template\ITemplateManager;
use OCP\IConfig;
use OCP\IGroupManager;
use OCP\ILogger;
+use OCP\IURLGenerator;
use OCP\IUser;
-use OCP\IUserSession;
use OCP\Share\IManager;
use Psr\Log\LoggerInterface;
@@ -1090,46 +1090,9 @@ class OC_Util {
* @suppress PhanDeprecatedFunction
*/
public static function getDefaultPageUrl() {
- /** @var IConfig $config */
- $config = \OC::$server->get(IConfig::class);
- $urlGenerator = \OC::$server->getURLGenerator();
- // Deny the redirect if the URL contains a @
- // This prevents unvalidated redirects like ?redirect_url=:user@domain.com
- if (isset($_REQUEST['redirect_url']) && strpos($_REQUEST['redirect_url'], '@') === false) {
- $location = $urlGenerator->getAbsoluteURL(urldecode($_REQUEST['redirect_url']));
- } else {
- $defaultPage = \OC::$server->getConfig()->getAppValue('core', 'defaultpage');
- if ($defaultPage) {
- $location = $urlGenerator->getAbsoluteURL($defaultPage);
- } else {
- $appId = 'files';
- $defaultApps = explode(',', $config->getSystemValue('defaultapp', 'dashboard,files'));
-
- /** @var IUserSession $userSession */
- $userSession = \OC::$server->get(IUserSession::class);
- $user = $userSession->getUser();
- if ($user) {
- $userDefaultApps = explode(',', $config->getUserValue($user->getUID(), 'core', 'defaultapp'));
- $defaultApps = array_filter(array_merge($userDefaultApps, $defaultApps));
- }
-
- // find the first app that is enabled for the current user
- foreach ($defaultApps as $defaultApp) {
- $defaultApp = OC_App::cleanAppId(strip_tags($defaultApp));
- if (static::getAppManager()->isEnabledForUser($defaultApp)) {
- $appId = $defaultApp;
- break;
- }
- }
-
- if ($config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true') {
- $location = $urlGenerator->getAbsoluteURL('/apps/' . $appId . '/');
- } else {
- $location = $urlGenerator->getAbsoluteURL('/index.php/apps/' . $appId . '/');
- }
- }
- }
- return $location;
+ /** @var IURLGenerator $urlGenerator */
+ $urlGenerator = \OC::$server->get(IURLGenerator::class);
+ return $urlGenerator->linkToDefaultPageUrl();
}
/**
diff --git a/lib/public/AppFramework/Http/RedirectToDefaultAppResponse.php b/lib/public/AppFramework/Http/RedirectToDefaultAppResponse.php
index 36e629d6342..e957b245e53 100644
--- a/lib/public/AppFramework/Http/RedirectToDefaultAppResponse.php
+++ b/lib/public/AppFramework/Http/RedirectToDefaultAppResponse.php
@@ -26,18 +26,24 @@ declare(strict_types=1);
*/
namespace OCP\AppFramework\Http;
+use OCP\IURLGenerator;
+
/**
* Redirects to the default app
+ *
* @since 16.0.0
+ * @depreacted 23.0.0 Use RedirectResponse() with IURLGenerator::linkToDefaultPageUrl() instead
*/
class RedirectToDefaultAppResponse extends RedirectResponse {
-
-
/**
* Creates a response that redirects to the default app
+ *
* @since 16.0.0
+ * @depreacted 23.0.0 Use RedirectResponse() with IURLGenerator::linkToDefaultPageUrl() instead
*/
public function __construct() {
- parent::__construct(\OC_Util::getDefaultPageUrl());
+ /** @var IURLGenerator $urlGenerator */
+ $urlGenerator = \OC::$server->get(IURLGenerator::class);
+ parent::__construct($urlGenerator->linkToDefaultPageUrl());
}
}
diff --git a/lib/public/IURLGenerator.php b/lib/public/IURLGenerator.php
index 9f1a6447eb4..580536b8b5f 100644
--- a/lib/public/IURLGenerator.php
+++ b/lib/public/IURLGenerator.php
@@ -98,6 +98,14 @@ interface IURLGenerator {
public function linkToDocs(string $key): string;
/**
+ * Returns the URL of the default page based on the system configuration
+ * and the apps visible for the current user
+ * @return string
+ * @since 23.0.0
+ */
+ public function linkToDefaultPageUrl(): string;
+
+ /**
* @return string base url of the current request
* @since 13.0.0
*/
diff --git a/tests/Core/Controller/LoginControllerTest.php b/tests/Core/Controller/LoginControllerTest.php
index e3469621eec..fe42b55db15 100644
--- a/tests/Core/Controller/LoginControllerTest.php
+++ b/tests/Core/Controller/LoginControllerTest.php
@@ -211,8 +211,12 @@ class LoginControllerTest extends TestCase {
->expects($this->once())
->method('isLoggedIn')
->willReturn(true);
+ $this->urlGenerator
+ ->expects($this->once())
+ ->method('linkToDefaultPageUrl')
+ ->willReturn('/default/foo');
- $expectedResponse = new RedirectResponse(\OC_Util::getDefaultPageUrl());
+ $expectedResponse = new RedirectResponse('/default/foo');
$this->assertEquals($expectedResponse, $this->loginController->showLoginForm('', '', ''));
}
@@ -443,7 +447,7 @@ class LoginControllerTest extends TestCase {
'direct' => 1,
])
->willReturn($loginPageUrl);
- $expected = new \OCP\AppFramework\Http\RedirectResponse($loginPageUrl);
+ $expected = new RedirectResponse($loginPageUrl);
$expected->throttle(['user' => 'MyUserName']);
$response = $this->loginController->tryLogin($user, $password, '/apps/files');
@@ -454,7 +458,6 @@ class LoginControllerTest extends TestCase {
public function testLoginWithValidCredentials() {
$user = 'MyUserName';
$password = 'secret';
- $indexPageUrl = \OC_Util::getDefaultPageUrl();
$this->request
->expects($this->once())
@@ -470,11 +473,13 @@ class LoginControllerTest extends TestCase {
->method('process')
->with($this->equalTo($loginData))
->willReturn($loginResult);
- $expected = new \OCP\AppFramework\Http\RedirectResponse($indexPageUrl);
-
- $response = $this->loginController->tryLogin($user, $password);
+ $this->urlGenerator
+ ->expects($this->once())
+ ->method('linkToDefaultPageUrl')
+ ->willReturn('/default/foo');
- $this->assertEquals($expected, $response);
+ $expected = new RedirectResponse('/default/foo');
+ $this->assertEquals($expected, $this->loginController->tryLogin($user, $password));
}
public function testLoginWithoutPassedCsrfCheckAndNotLoggedIn() {
@@ -498,8 +503,12 @@ class LoginControllerTest extends TestCase {
->method('deleteUserValue');
$this->userSession->expects($this->never())
->method('createRememberMeToken');
+ $this->urlGenerator
+ ->expects($this->once())
+ ->method('linkToDefaultPageUrl')
+ ->willReturn('/default/foo');
- $expected = new \OCP\AppFramework\Http\RedirectResponse(\OC_Util::getDefaultPageUrl());
+ $expected = new RedirectResponse('/default/foo');
$this->assertEquals($expected, $this->loginController->tryLogin('Jane', $password, $originalUrl));
}
@@ -534,14 +543,13 @@ class LoginControllerTest extends TestCase {
->with('remember_login_cookie_lifetime')
->willReturn(1234);
- $expected = new \OCP\AppFramework\Http\RedirectResponse($redirectUrl);
+ $expected = new RedirectResponse($redirectUrl);
$this->assertEquals($expected, $this->loginController->tryLogin('Jane', $password, $originalUrl));
}
public function testLoginWithValidCredentialsAndRedirectUrl() {
$user = 'MyUserName';
$password = 'secret';
- $indexPageUrl = \OC_Util::getDefaultPageUrl();
$redirectUrl = 'https://next.cloud/apps/mail';
$this->request
@@ -566,7 +574,7 @@ class LoginControllerTest extends TestCase {
->method('getAbsoluteURL')
->with('/apps/mail')
->willReturn($redirectUrl);
- $expected = new \OCP\AppFramework\Http\RedirectResponse($redirectUrl);
+ $expected = new RedirectResponse($redirectUrl);
$response = $this->loginController->tryLogin($user, $password, '/apps/mail');
@@ -601,7 +609,7 @@ class LoginControllerTest extends TestCase {
'direct' => 1,
])
->willReturn($loginPageUrl);
- $expected = new \OCP\AppFramework\Http\RedirectResponse($loginPageUrl);
+ $expected = new RedirectResponse($loginPageUrl);
$expected->throttle(['user' => 'john']);
$response = $this->loginController->tryLogin(
diff --git a/tests/Core/Controller/TwoFactorChallengeControllerTest.php b/tests/Core/Controller/TwoFactorChallengeControllerTest.php
index b899a1b236a..2cb8d4bd50f 100644
--- a/tests/Core/Controller/TwoFactorChallengeControllerTest.php
+++ b/tests/Core/Controller/TwoFactorChallengeControllerTest.php
@@ -25,7 +25,6 @@ namespace Test\Core\Controller;
use OC\Authentication\TwoFactorAuth\Manager;
use OC\Authentication\TwoFactorAuth\ProviderSet;
use OC\Core\Controller\TwoFactorChallengeController;
-use OC_Util;
use OCP\AppFramework\Http\RedirectResponse;
use OCP\AppFramework\Http\StandaloneTemplateResponse;
use OCP\Authentication\TwoFactorAuth\IActivatableAtLogin;
@@ -212,8 +211,12 @@ class TwoFactorChallengeControllerTest extends TestCase {
->method('verifyChallenge')
->with('myprovider', $user, 'token')
->willReturn(true);
+ $this->urlGenerator
+ ->expects($this->once())
+ ->method('linkToDefaultPageUrl')
+ ->willReturn('/default/foo');
- $expected = new RedirectResponse(OC_Util::getDefaultPageUrl());
+ $expected = new RedirectResponse('/default/foo');
$this->assertEquals($expected, $this->controller->solveChallenge('myprovider', 'token'));
}
diff --git a/tests/lib/UrlGeneratorTest.php b/tests/lib/UrlGeneratorTest.php
index 761f4b42eea..9e5795fc41e 100644
--- a/tests/lib/UrlGeneratorTest.php
+++ b/tests/lib/UrlGeneratorTest.php
@@ -13,6 +13,8 @@ use OCP\ICacheFactory;
use OCP\IConfig;
use OCP\IRequest;
use OCP\IURLGenerator;
+use OCP\IUser;
+use OCP\IUserSession;
/**
* Class UrlGeneratorTest
@@ -23,6 +25,8 @@ class UrlGeneratorTest extends \Test\TestCase {
/** @var \PHPUnit\Framework\MockObject\MockObject|IConfig */
private $config;
+ /** @var \PHPUnit\Framework\MockObject\MockObject|IUserSession */
+ private $userSession;
/** @var \PHPUnit\Framework\MockObject\MockObject|ICacheFactory */
private $cacheFactory;
/** @var \PHPUnit\Framework\MockObject\MockObject|IRequest */
@@ -37,11 +41,13 @@ class UrlGeneratorTest extends \Test\TestCase {
protected function setUp(): void {
parent::setUp();
$this->config = $this->createMock(IConfig::class);
+ $this->userSession = $this->createMock(IUserSession::class);
$this->cacheFactory = $this->createMock(ICacheFactory::class);
$this->request = $this->createMock(IRequest::class);
$this->router = $this->createMock(Router::class);
$this->urlGenerator = new \OC\URLGenerator(
$this->config,
+ $this->userSession,
$this->cacheFactory,
$this->request,
$this->router
@@ -210,4 +216,109 @@ class UrlGeneratorTest extends \Test\TestCase {
['core.WhatsNew.dismiss', 'http://localhost/nextcloud/ocs/v2.php/core/whatsnew'],
];
}
+
+ private function mockLinkToDefaultPageUrl(string $defaultAppConfig = '', bool $ignoreFrontControllerConfig = false) {
+ $this->config->expects($this->exactly(2))
+ ->method('getSystemValue')
+ ->withConsecutive(
+ ['defaultapp', $this->anything()],
+ ['htaccess.IgnoreFrontController', $this->anything()],
+ )
+ ->will($this->onConsecutiveCalls(
+ $defaultAppConfig,
+ $ignoreFrontControllerConfig
+ ));
+ $this->config->expects($this->once())
+ ->method('getAppValue')
+ ->with('core', 'defaultpage')
+ ->willReturn('');
+ }
+
+ public function testLinkToDefaultPageUrlWithRedirectUrlWithoutFrontController() {
+ $this->mockBaseUrl();
+
+ $_REQUEST['redirect_url'] = 'myRedirectUrl.com';
+ $this->assertSame('http://localhost' . \OC::$WEBROOT . '/myRedirectUrl.com', $this->urlGenerator->linkToDefaultPageUrl());
+ }
+
+ public function testLinkToDefaultPageUrlWithRedirectUrlRedirectBypassWithoutFrontController() {
+ $this->mockBaseUrl();
+ $this->mockLinkToDefaultPageUrl();
+ putenv('front_controller_active=false');
+
+ $_REQUEST['redirect_url'] = 'myRedirectUrl.com@foo.com:a';
+ $this->assertSame('http://localhost' . \OC::$WEBROOT . '/index.php/apps/files/', $this->urlGenerator->linkToDefaultPageUrl());
+ }
+
+ public function testLinkToDefaultPageUrlWithRedirectUrlRedirectBypassWithFrontController() {
+ $this->mockBaseUrl();
+ $this->mockLinkToDefaultPageUrl();
+ putenv('front_controller_active=true');
+
+ $_REQUEST['redirect_url'] = 'myRedirectUrl.com@foo.com:a';
+ $this->assertSame('http://localhost' . \OC::$WEBROOT . '/apps/files/', $this->urlGenerator->linkToDefaultPageUrl());
+ }
+
+ public function testLinkToDefaultPageUrlWithRedirectUrlWithIgnoreFrontController() {
+ $this->mockBaseUrl();
+ $this->mockLinkToDefaultPageUrl('', true);
+ putenv('front_controller_active=false');
+
+ $_REQUEST['redirect_url'] = 'myRedirectUrl.com@foo.com:a';
+ $this->assertSame('http://localhost' . \OC::$WEBROOT . '/apps/files/', $this->urlGenerator->linkToDefaultPageUrl());
+ }
+
+ /**
+ * @dataProvider provideDefaultApps
+ */
+ public function testLinkToDefaultPageUrlWithDefaultApps($defaultAppConfig, $expectedPath) {
+ $userId = $this->getUniqueID();
+
+ /** @var \PHPUnit\Framework\MockObject\MockObject|IUser $userMock */
+ $userMock = $this->createMock(IUser::class);
+ $userMock->expects($this->once())
+ ->method('getUID')
+ ->willReturn($userId);
+
+ $this->mockBaseUrl();
+ $this->mockLinkToDefaultPageUrl($defaultAppConfig);
+
+ $this->config->expects($this->once())
+ ->method('getUserValue')
+ ->with($userId, 'core', 'defaultapp')
+ ->willReturn('');
+ $this->userSession->expects($this->once())
+ ->method('isLoggedIn')
+ ->willReturn(true);
+ $this->userSession->expects($this->once())
+ ->method('getUser')
+ ->willReturn($userMock);
+
+ $this->assertEquals('http://localhost' . \OC::$WEBROOT . $expectedPath, $this->urlGenerator->linkToDefaultPageUrl());
+ }
+
+ public function provideDefaultApps() {
+ return [
+ // none specified, default to files
+ [
+ '',
+ '/index.php/apps/files/',
+ ],
+ // unexisting or inaccessible app specified, default to files
+ [
+ 'unexist',
+ '/index.php/apps/files/',
+ ],
+ // non-standard app
+ [
+ 'settings',
+ '/index.php/apps/settings/',
+ ],
+ // non-standard app with fallback
+ [
+ 'unexist,settings',
+ '/index.php/apps/settings/',
+ ],
+ ];
+ }
}
diff --git a/tests/lib/UtilTest.php b/tests/lib/UtilTest.php
index e21a5323b1b..04d4858fb26 100644
--- a/tests/lib/UtilTest.php
+++ b/tests/lib/UtilTest.php
@@ -9,7 +9,6 @@
namespace Test;
use OC_Util;
-use OCP\App\IAppManager;
/**
* Class UtilTest
@@ -170,96 +169,6 @@ class UtilTest extends \Test\TestCase {
}
/**
- * Test default apps
- *
- * @dataProvider defaultAppsProvider
- * @group DB
- */
- public function testDefaultApps($defaultAppConfig, $expectedPath, $enabledApps) {
- $oldDefaultApps = \OC::$server->getConfig()->getSystemValue('defaultapp', '');
- // CLI is doing messy stuff with the webroot, so need to work it around
- $oldWebRoot = \OC::$WEBROOT;
- \OC::$WEBROOT = '';
-
- $appManager = $this->createMock(IAppManager::class);
- $appManager->expects($this->any())
- ->method('isEnabledForUser')
- ->willReturnCallback(function ($appId) use ($enabledApps) {
- return in_array($appId, $enabledApps);
- });
- Dummy_OC_Util::$appManager = $appManager;
-
- // need to set a user id to make sure enabled apps are read from cache
- \OC_User::setUserId($this->getUniqueID());
- \OC::$server->getConfig()->setSystemValue('defaultapp', $defaultAppConfig);
- $this->assertEquals('http://localhost/' . $expectedPath, Dummy_OC_Util::getDefaultPageUrl());
-
- // restore old state
- \OC::$WEBROOT = $oldWebRoot;
- \OC::$server->getConfig()->setSystemValue('defaultapp', $oldDefaultApps);
- \OC_User::setUserId(null);
- }
-
- public function defaultAppsProvider() {
- return [
- // none specified, default to files
- [
- '',
- 'index.php/apps/files/',
- ['files'],
- ],
- // unexisting or inaccessible app specified, default to files
- [
- 'unexist',
- 'index.php/apps/files/',
- ['files'],
- ],
- // non-standard app
- [
- 'calendar',
- 'index.php/apps/calendar/',
- ['files', 'calendar'],
- ],
- // non-standard app with fallback
- [
- 'contacts,calendar',
- 'index.php/apps/calendar/',
- ['files', 'calendar'],
- ],
- ];
- }
-
- public function testGetDefaultPageUrlWithRedirectUrlWithoutFrontController() {
- putenv('front_controller_active=false');
- \OC::$server->getConfig()->deleteSystemValue('htaccess.IgnoreFrontController');
-
- $_REQUEST['redirect_url'] = 'myRedirectUrl.com';
- $this->assertSame('http://localhost'.\OC::$WEBROOT.'/myRedirectUrl.com', OC_Util::getDefaultPageUrl());
- }
-
- public function testGetDefaultPageUrlWithRedirectUrlRedirectBypassWithoutFrontController() {
- putenv('front_controller_active=false');
- \OC::$server->getConfig()->deleteSystemValue('htaccess.IgnoreFrontController');
-
- $_REQUEST['redirect_url'] = 'myRedirectUrl.com@foo.com:a';
- $this->assertSame('http://localhost'.\OC::$WEBROOT.'/index.php/apps/files/', OC_Util::getDefaultPageUrl());
- }
-
- public function testGetDefaultPageUrlWithRedirectUrlRedirectBypassWithFrontController() {
- putenv('front_controller_active=true');
- $_REQUEST['redirect_url'] = 'myRedirectUrl.com@foo.com:a';
- $this->assertSame('http://localhost'.\OC::$WEBROOT.'/apps/files/', OC_Util::getDefaultPageUrl());
- }
-
- public function testGetDefaultPageUrlWithRedirectUrlWithIgnoreFrontController() {
- putenv('front_controller_active=false');
- \OC::$server->getConfig()->setSystemValue('htaccess.IgnoreFrontController', true);
-
- $_REQUEST['redirect_url'] = 'myRedirectUrl.com@foo.com:a';
- $this->assertSame('http://localhost'.\OC::$WEBROOT.'/apps/files/', OC_Util::getDefaultPageUrl());
- }
-
- /**
* Test needUpgrade() when the core version is increased
*/
public function testNeedUpgradeCore() {
@@ -390,17 +299,3 @@ class UtilTest extends \Test\TestCase {
], \OC_Util::$styles);
}
}
-
-/**
- * Dummy OC Util class to make it possible to override the app manager
- */
-class Dummy_OC_Util extends OC_Util {
- /**
- * @var \OCP\App\IAppManager
- */
- public static $appManager;
-
- protected static function getAppManager() {
- return self::$appManager;
- }
-}