mirror of
https://github.com/nextcloud/server.git
synced 2026-04-22 23:03:00 -04:00
Merge pull request #27733 from PhrozenByte/enhancement/noid/IURLGenerator-linkToDefaultPageUrl
This commit is contained in:
commit
d68f028251
14 changed files with 228 additions and 178 deletions
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -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'));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -267,6 +273,49 @@ class URLGenerator implements IURLGenerator {
|
|||
return $theme->buildDocLinkToKey($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -97,6 +97,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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
$this->urlGenerator
|
||||
->expects($this->once())
|
||||
->method('linkToDefaultPageUrl')
|
||||
->willReturn('/default/foo');
|
||||
|
||||
$response = $this->loginController->tryLogin($user, $password);
|
||||
|
||||
$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(
|
||||
|
|
|
|||
|
|
@ -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'));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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/',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@
|
|||
namespace Test;
|
||||
|
||||
use OC_Util;
|
||||
use OCP\App\IAppManager;
|
||||
|
||||
/**
|
||||
* Class UtilTest
|
||||
|
|
@ -169,96 +168,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
|
||||
*/
|
||||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue