diff --git a/apps/files_sharing/lib/Middleware/OCSShareAPIMiddleware.php b/apps/files_sharing/lib/Middleware/OCSShareAPIMiddleware.php index 46e4cf6cba171..d96906823650d 100644 --- a/apps/files_sharing/lib/Middleware/OCSShareAPIMiddleware.php +++ b/apps/files_sharing/lib/Middleware/OCSShareAPIMiddleware.php @@ -19,19 +19,16 @@ class OCSShareAPIMiddleware extends Middleware { public function __construct( - private IManager $shareManager, - private IL10N $l, + private readonly IManager $shareManager, + private readonly IL10N $l, ) { } /** - * @param Controller $controller - * @param string $methodName - * * @throws OCSNotFoundException */ #[\Override] - public function beforeController($controller, $methodName) { + public function beforeController(Controller $controller, string $methodName): void { if ($controller instanceof ShareAPIController) { if (!$this->shareManager->shareApiEnabled()) { throw new OCSNotFoundException($this->l->t('Share API is disabled')); @@ -39,14 +36,8 @@ public function beforeController($controller, $methodName) { } } - /** - * @param Controller $controller - * @param string $methodName - * @param Response $response - * @return Response - */ #[\Override] - public function afterController($controller, $methodName, Response $response) { + public function afterController(Controller $controller, string $methodName, Response $response): Response { if ($controller instanceof ShareAPIController) { /** @var ShareAPIController $controller */ $controller->cleanup(); diff --git a/apps/files_sharing/lib/Middleware/ShareInfoMiddleware.php b/apps/files_sharing/lib/Middleware/ShareInfoMiddleware.php index 5931f3d48fc04..2b8ddf0e0f0db 100644 --- a/apps/files_sharing/lib/Middleware/ShareInfoMiddleware.php +++ b/apps/files_sharing/lib/Middleware/ShareInfoMiddleware.php @@ -24,13 +24,8 @@ public function __construct( ) { } - /** - * @param Controller $controller - * @param string $methodName - * @throws S2SException - */ #[\Override] - public function beforeController($controller, $methodName) { + public function beforeController(Controller $controller, string $methodName): void { if (!($controller instanceof ShareInfoController)) { return; } @@ -40,15 +35,8 @@ public function beforeController($controller, $methodName) { } } - /** - * @param Controller $controller - * @param string $methodName - * @param \Exception $exception - * @throws \Exception - * @return Response - */ #[\Override] - public function afterException($controller, $methodName, \Exception $exception) { + public function afterException(Controller $controller, string $methodName, \Exception $exception): JSONResponse { if (!($controller instanceof ShareInfoController)) { throw $exception; } @@ -60,14 +48,8 @@ public function afterException($controller, $methodName, \Exception $exception) throw $exception; } - /** - * @param Controller $controller - * @param string $methodName - * @param Response $response - * @return Response - */ #[\Override] - public function afterController($controller, $methodName, Response $response) { + public function afterController(Controller $controller, string $methodName, Response $response) { if (!($controller instanceof ShareInfoController)) { return $response; } diff --git a/apps/files_sharing/lib/Middleware/SharingCheckMiddleware.php b/apps/files_sharing/lib/Middleware/SharingCheckMiddleware.php index b60297f1e822d..cd3b452a19003 100644 --- a/apps/files_sharing/lib/Middleware/SharingCheckMiddleware.php +++ b/apps/files_sharing/lib/Middleware/SharingCheckMiddleware.php @@ -49,7 +49,7 @@ public function __construct( * @throws S2SException */ #[\Override] - public function beforeController($controller, $methodName): void { + public function beforeController(Controller $controller, string $methodName): void { if (!$this->isSharingEnabled()) { throw new NotFoundException('Sharing is disabled.'); } @@ -70,7 +70,7 @@ public function beforeController($controller, $methodName): void { * @throws \Exception */ #[\Override] - public function afterException($controller, $methodName, \Exception $exception): Response { + public function afterException(Controller $controller, string $methodName, \Exception $exception): Response { if (is_a($exception, NotFoundException::class)) { return new NotFoundResponse(); } diff --git a/apps/provisioning_api/lib/Middleware/ProvisioningApiMiddleware.php b/apps/provisioning_api/lib/Middleware/ProvisioningApiMiddleware.php index f3184c48c11ba..9f8f28d9197c6 100644 --- a/apps/provisioning_api/lib/Middleware/ProvisioningApiMiddleware.php +++ b/apps/provisioning_api/lib/Middleware/ProvisioningApiMiddleware.php @@ -41,7 +41,7 @@ public function __construct( * @throws NotSubAdminException */ #[\Override] - public function beforeController($controller, $methodName) { + public function beforeController(Controller $controller, string $methodName): void { // If AuthorizedAdminSetting, the check will be done in the SecurityMiddleware if (!$this->isAdmin && !$this->reflector->hasAnnotation('NoSubAdminRequired') && !$this->isSubAdmin && !$this->reflector->hasAnnotationOrAttribute('AuthorizedAdminSetting', AuthorizedAdminSetting::class)) { throw new NotSubAdminException(); @@ -56,7 +56,7 @@ public function beforeController($controller, $methodName) { * @return Response */ #[\Override] - public function afterException($controller, $methodName, \Exception $exception) { + public function afterException(Controller $controller, string $methodName, \Exception $exception) { if ($exception instanceof NotSubAdminException) { throw new OCSException($exception->getMessage(), Http::STATUS_FORBIDDEN); } diff --git a/core/Middleware/TwoFactorMiddleware.php b/core/Middleware/TwoFactorMiddleware.php index ec4fdb5219f4a..54d774b493951 100644 --- a/core/Middleware/TwoFactorMiddleware.php +++ b/core/Middleware/TwoFactorMiddleware.php @@ -47,13 +47,14 @@ public function __construct( * @param string $methodName */ #[\Override] - public function beforeController($controller, $methodName) { + public function beforeController(Controller $controller, string $methodName): void { if ($this->reflector->hasAnnotationOrAttribute('NoTwoFactorRequired', NoTwoFactorRequired::class)) { // Route handler explicitly marked to work without finished 2FA are // not blocked return; } + /** @psalm-suppress TypeDoesNotContainType The class is defined in a different app */ if ($controller instanceof APIController && $methodName === 'poll') { // Allow polling the twofactor nextcloud notifications state return; @@ -121,7 +122,7 @@ private function checkTwoFactor(Controller $controller, IUser $user) { } #[\Override] - public function afterException($controller, $methodName, Exception $exception) { + public function afterException(Controller $controller, string $methodName, Exception $exception) { if ($exception instanceof TwoFactorAuthRequiredException) { $params = [ 'redirect_url' => $this->request->getParam('redirect_url'), diff --git a/lib/private/AppFramework/Middleware/AdditionalScriptsMiddleware.php b/lib/private/AppFramework/Middleware/AdditionalScriptsMiddleware.php index ea252ac410964..a2ca1091d5c4c 100644 --- a/lib/private/AppFramework/Middleware/AdditionalScriptsMiddleware.php +++ b/lib/private/AppFramework/Middleware/AdditionalScriptsMiddleware.php @@ -10,6 +10,7 @@ namespace OC\AppFramework\Middleware; use OC\Core\Controller\LoginController; +use OCP\AppFramework\Controller; use OCP\AppFramework\Http\Events\BeforeLoginTemplateRenderedEvent; use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent; use OCP\AppFramework\Http\Response; @@ -27,7 +28,7 @@ public function __construct( } #[\Override] - public function afterController($controller, $methodName, Response $response): Response { + public function afterController(Controller $controller, string $methodName, Response $response): Response { if ($response instanceof TemplateResponse) { if ($controller instanceof LoginController) { $this->dispatcher->dispatchTyped(new BeforeLoginTemplateRenderedEvent($response)); diff --git a/lib/private/AppFramework/Middleware/CompressionMiddleware.php b/lib/private/AppFramework/Middleware/CompressionMiddleware.php index 796c998c66ffc..7ebf7be261d80 100644 --- a/lib/private/AppFramework/Middleware/CompressionMiddleware.php +++ b/lib/private/AppFramework/Middleware/CompressionMiddleware.php @@ -10,6 +10,7 @@ namespace OC\AppFramework\Middleware; use OC\AppFramework\OCS\BaseResponse; +use OCP\AppFramework\Controller; use OCP\AppFramework\Http; use OCP\AppFramework\Http\JSONResponse; use OCP\AppFramework\Http\Response; @@ -18,18 +19,16 @@ use OCP\IRequest; class CompressionMiddleware extends Middleware { - /** @var bool */ - private $useGZip; + private bool $useGZip = false; public function __construct( private IRequest $request, ) { - $this->useGZip = false; } #[\Override] - public function afterController($controller, $methodName, Response $response) { - // By default we do not gzip + public function afterController(Controller $controller, string $methodName, Response $response): Response { + // By default, we do not gzip $allowGzip = false; // Only return gzipped content for 200 responses @@ -63,7 +62,7 @@ public function afterController($controller, $methodName, Response $response) { } #[\Override] - public function beforeOutput($controller, $methodName, $output) { + public function beforeOutput(Controller $controller, string $methodName, string $output): string { if (!$this->useGZip) { return $output; } diff --git a/lib/private/AppFramework/Middleware/NotModifiedMiddleware.php b/lib/private/AppFramework/Middleware/NotModifiedMiddleware.php index 5278bae128d53..b8d3ad4a913cd 100644 --- a/lib/private/AppFramework/Middleware/NotModifiedMiddleware.php +++ b/lib/private/AppFramework/Middleware/NotModifiedMiddleware.php @@ -9,6 +9,7 @@ namespace OC\AppFramework\Middleware; +use OCP\AppFramework\Controller; use OCP\AppFramework\Http; use OCP\AppFramework\Http\Response; use OCP\AppFramework\Middleware; @@ -22,7 +23,7 @@ public function __construct( } #[\Override] - public function afterController($controller, $methodName, Response $response) { + public function afterController(Controller $controller, string $methodName, Response $response) { $etagHeader = $this->request->getHeader('IF_NONE_MATCH'); if ($etagHeader !== '' && $response->getETag() !== null && trim($etagHeader) === '"' . $response->getETag() . '"') { $response->setStatus(Http::STATUS_NOT_MODIFIED); diff --git a/lib/private/AppFramework/Middleware/OCSMiddleware.php b/lib/private/AppFramework/Middleware/OCSMiddleware.php index 042990e3c12d0..0315b3590e4bc 100644 --- a/lib/private/AppFramework/Middleware/OCSMiddleware.php +++ b/lib/private/AppFramework/Middleware/OCSMiddleware.php @@ -21,23 +21,15 @@ use OCP\IRequest; class OCSMiddleware extends Middleware { - /** @var int */ - private $ocsVersion; + private int $ocsVersion = 2; - /** - * @param IRequest $request - */ public function __construct( - private IRequest $request, + private readonly IRequest $request, ) { } - /** - * @param Controller $controller - * @param string $methodName - */ #[\Override] - public function beforeController($controller, $methodName) { + public function beforeController(Controller $controller, string $methodName): void { if ($controller instanceof OCSController) { if (substr_compare($this->request->getScriptName(), '/ocs/v2.php', -strlen('/ocs/v2.php')) === 0) { $this->ocsVersion = 2; @@ -48,15 +40,8 @@ public function beforeController($controller, $methodName) { } } - /** - * @param Controller $controller - * @param string $methodName - * @param \Exception $exception - * @throws \Exception - * @return BaseResponse - */ #[\Override] - public function afterException($controller, $methodName, \Exception $exception) { + public function afterException(Controller $controller, string $methodName, \Exception $exception): Response { if ($controller instanceof OCSController && $exception instanceof OCSException) { $code = $exception->getCode(); if ($code === 0) { @@ -69,14 +54,8 @@ public function afterException($controller, $methodName, \Exception $exception) throw $exception; } - /** - * @param Controller $controller - * @param string $methodName - * @param Response $response - * @return Response - */ #[\Override] - public function afterController($controller, $methodName, Response $response) { + public function afterController(Controller $controller, string $methodName, Response $response): Response { /* * If a different middleware has detected that a request unauthorized or forbidden * we need to catch the response and convert it to a proper OCS response. @@ -105,13 +84,7 @@ public function afterController($controller, $methodName, Response $response) { return $response; } - /** - * @param Controller $controller - * @param int $code - * @param string $message - * @return V1Response|V2Response - */ - private function buildNewResponse(Controller $controller, $code, $message) { + private function buildNewResponse(Controller $controller, int $code, string $message): V1Response|V2Response { $format = $this->request->getFormat(); if ($format === null || !$controller->isResponderRegistered($format)) { $format = 'xml'; diff --git a/lib/private/AppFramework/Middleware/PublicShare/PublicShareMiddleware.php b/lib/private/AppFramework/Middleware/PublicShare/PublicShareMiddleware.php index 5d52217e30054..b91a115f0bc33 100644 --- a/lib/private/AppFramework/Middleware/PublicShare/PublicShareMiddleware.php +++ b/lib/private/AppFramework/Middleware/PublicShare/PublicShareMiddleware.php @@ -1,5 +1,7 @@ config->getAppValue('core', 'shareapi_enabled', 'yes') !== 'yes') { - return false; - } - - // Check whether public sharing is enabled - if ($this->config->getAppValue('core', 'shareapi_allow_links', 'yes') !== 'yes') { - return false; - } - - return true; + // Check if the shareAPI and public sharing is enabled + return $this->appConfig->getValueBool('core', 'shareapi_enabled', true) + && $this->appConfig->getValueBool('core', 'shareapi_allow_links', true); } - private function throttle($bruteforceProtectionAction, $token): void { + private function throttle(string $bruteforceProtectionAction, string $token): void { $ip = $this->request->getRemoteAddress(); $this->throttler->sleepDelayOrThrowOnMax($ip, $bruteforceProtectionAction); $this->throttler->registerAttempt($bruteforceProtectionAction, $ip, ['token' => $token]); diff --git a/lib/private/AppFramework/Middleware/Security/BruteForceMiddleware.php b/lib/private/AppFramework/Middleware/Security/BruteForceMiddleware.php index 401490bf13b49..91465a3feed0c 100644 --- a/lib/private/AppFramework/Middleware/Security/BruteForceMiddleware.php +++ b/lib/private/AppFramework/Middleware/Security/BruteForceMiddleware.php @@ -46,7 +46,7 @@ public function __construct( * {@inheritDoc} */ #[\Override] - public function beforeController($controller, $methodName) { + public function beforeController(Controller $controller, string $methodName): void { parent::beforeController($controller, $methodName); if ($this->reflector->hasAnnotation('BruteForceProtection')) { @@ -73,7 +73,7 @@ public function beforeController($controller, $methodName) { * {@inheritDoc} */ #[\Override] - public function afterController($controller, $methodName, Response $response) { + public function afterController(Controller $controller, string $methodName, Response $response) { if ($response->isThrottled()) { try { if ($this->reflector->hasAnnotation('BruteForceProtection')) { @@ -127,7 +127,7 @@ public function afterController($controller, $methodName, Response $response) { * @return Response */ #[\Override] - public function afterException($controller, $methodName, \Exception $exception): Response { + public function afterException(Controller $controller, string $methodName, \Exception $exception): Response { if ($exception instanceof MaxDelayReached) { if ($controller instanceof OCSController) { throw new OCSException($exception->getMessage(), Http::STATUS_TOO_MANY_REQUESTS); diff --git a/lib/private/AppFramework/Middleware/Security/CSPMiddleware.php b/lib/private/AppFramework/Middleware/Security/CSPMiddleware.php index 94f56e08b432b..3f53398675078 100644 --- a/lib/private/AppFramework/Middleware/Security/CSPMiddleware.php +++ b/lib/private/AppFramework/Middleware/Security/CSPMiddleware.php @@ -35,7 +35,7 @@ public function __construct( * @return Response */ #[\Override] - public function afterController($controller, $methodName, Response $response): Response { + public function afterController(Controller $controller, string $methodName, Response $response): Response { $policy = !is_null($response->getContentSecurityPolicy()) ? $response->getContentSecurityPolicy() : new ContentSecurityPolicy(); if (get_class($policy) === EmptyContentSecurityPolicy::class) { diff --git a/lib/private/AppFramework/Middleware/Security/FeaturePolicyMiddleware.php b/lib/private/AppFramework/Middleware/Security/FeaturePolicyMiddleware.php index 396115a82f9a6..134933150bbe0 100644 --- a/lib/private/AppFramework/Middleware/Security/FeaturePolicyMiddleware.php +++ b/lib/private/AppFramework/Middleware/Security/FeaturePolicyMiddleware.php @@ -32,7 +32,7 @@ public function __construct( * @return Response */ #[\Override] - public function afterController($controller, $methodName, Response $response): Response { + public function afterController(Controller $controller, string $methodName, Response $response): Response { $policy = !is_null($response->getFeaturePolicy()) ? $response->getFeaturePolicy() : new FeaturePolicy(); if (get_class($policy) === EmptyFeaturePolicy::class) { diff --git a/lib/private/AppFramework/Middleware/Security/PasswordConfirmationMiddleware.php b/lib/private/AppFramework/Middleware/Security/PasswordConfirmationMiddleware.php index f9bd5c3dd3af5..0d29c38a26ca7 100644 --- a/lib/private/AppFramework/Middleware/Security/PasswordConfirmationMiddleware.php +++ b/lib/private/AppFramework/Middleware/Security/PasswordConfirmationMiddleware.php @@ -24,7 +24,6 @@ use OCP\IUserSession; use OCP\Session\Exceptions\SessionNotAvailableException; use OCP\User\Backend\IPasswordConfirmationBackend; -use Psr\Log\LoggerInterface; use ReflectionAttribute; use ReflectionMethod; @@ -37,7 +36,6 @@ public function __construct( private IUserSession $userSession, private ITimeFactory $timeFactory, private IProvider $tokenProvider, - private readonly LoggerInterface $logger, private readonly IRequest $request, private readonly Manager $userManager, ) { @@ -47,7 +45,7 @@ public function __construct( * @throws NotConfirmedException */ #[\Override] - public function beforeController(Controller $controller, string $methodName) { + public function beforeController(Controller $controller, string $methodName): void { if (!$this->needsPasswordConfirmation()) { return; } diff --git a/lib/private/AppFramework/Middleware/Security/SameSiteCookieMiddleware.php b/lib/private/AppFramework/Middleware/Security/SameSiteCookieMiddleware.php index f25d49f8996b0..d6420607ee6b7 100644 --- a/lib/private/AppFramework/Middleware/Security/SameSiteCookieMiddleware.php +++ b/lib/private/AppFramework/Middleware/Security/SameSiteCookieMiddleware.php @@ -12,6 +12,7 @@ use OC\AppFramework\Http\Request; use OC\AppFramework\Middleware\MiddlewareUtils; use OC\AppFramework\Middleware\Security\Exceptions\LaxSameSiteCookieFailedException; +use OCP\AppFramework\Controller; use OCP\AppFramework\Http; use OCP\AppFramework\Http\Attribute\NoSameSiteCookieRequired; use OCP\AppFramework\Http\Response; @@ -26,7 +27,7 @@ public function __construct( } #[\Override] - public function beforeController($controller, $methodName) { + public function beforeController(Controller $controller, string $methodName): void { $requestUri = $this->request->getScriptName(); $processingScript = explode('/', $requestUri); $processingScript = $processingScript[count($processingScript) - 1]; @@ -47,7 +48,7 @@ public function beforeController($controller, $methodName) { } #[\Override] - public function afterException($controller, $methodName, \Exception $exception) { + public function afterException(Controller $controller, string $methodName, \Exception $exception) { if ($exception instanceof LaxSameSiteCookieFailedException) { $response = new Response(); $response->setStatus(Http::STATUS_FOUND); diff --git a/lib/private/AppFramework/Middleware/Security/SecurityMiddleware.php b/lib/private/AppFramework/Middleware/Security/SecurityMiddleware.php index 3b3028c0a20d7..5456d2ab940cc 100644 --- a/lib/private/AppFramework/Middleware/Security/SecurityMiddleware.php +++ b/lib/private/AppFramework/Middleware/Security/SecurityMiddleware.php @@ -108,7 +108,7 @@ private function isSubAdmin(): bool { * @suppress PhanUndeclaredClassConstant */ #[\Override] - public function beforeController($controller, $methodName) { + public function beforeController(Controller $controller, string $methodName): void { // this will set the current navigation entry of the app, use this only // for normal HTML requests and not for AJAX requests $this->navigationManager->setActiveEntry($this->appName); @@ -254,7 +254,7 @@ private function isValidOCSRequest(): bool { * @throws \Exception the passed in exception if it can't handle it */ #[\Override] - public function afterException($controller, $methodName, \Exception $exception): Response { + public function afterException(Controller $controller, string $methodName, \Exception $exception): Response { if ($exception instanceof SecurityException) { if ($exception instanceof StrictCookieMissingException) { return new RedirectResponse(\OC::$WEBROOT . '/'); diff --git a/lib/private/AppFramework/Middleware/SessionMiddleware.php b/lib/private/AppFramework/Middleware/SessionMiddleware.php index c0bb256777046..b0bb591d151d8 100644 --- a/lib/private/AppFramework/Middleware/SessionMiddleware.php +++ b/lib/private/AppFramework/Middleware/SessionMiddleware.php @@ -23,25 +23,15 @@ public function __construct( ) { } - /** - * @param Controller $controller - * @param string $methodName - */ #[\Override] - public function beforeController($controller, $methodName) { + public function beforeController(Controller $controller, string $methodName): void { if ($this->reflector->hasAnnotationOrAttribute('UseSession', UseSession::class)) { $this->session->reopen(); } } - /** - * @param Controller $controller - * @param string $methodName - * @param Response $response - * @return Response - */ #[\Override] - public function afterController($controller, $methodName, Response $response) { + public function afterController(Controller $controller, string $methodName, Response $response): Response { if ($this->reflector->hasAnnotationOrAttribute('UseSession', UseSession::class)) { $this->session->close(); } diff --git a/lib/public/AppFramework/Middleware.php b/lib/public/AppFramework/Middleware.php index 47eec0d729b09..7330396d68ae8 100644 --- a/lib/public/AppFramework/Middleware.php +++ b/lib/public/AppFramework/Middleware.php @@ -9,6 +9,7 @@ namespace OCP\AppFramework; use Exception; +use OCP\AppFramework\Attribute\Implementable; use OCP\AppFramework\Http\Response; /** @@ -18,6 +19,7 @@ * https://docs.djangoproject.com/en/dev/topics/http/middleware/ * @since 6.0.0 */ +#[Implementable(since: '6.0.0')] abstract class Middleware { /** * This is being run in normal order before the controller is being diff --git a/tests/lib/AppFramework/Middleware/MiddlewareDispatcherTest.php b/tests/lib/AppFramework/Middleware/MiddlewareDispatcherTest.php index 52f4ff8c120a9..ad1908bb61e8f 100644 --- a/tests/lib/AppFramework/Middleware/MiddlewareDispatcherTest.php +++ b/tests/lib/AppFramework/Middleware/MiddlewareDispatcherTest.php @@ -34,11 +34,8 @@ class TestMiddleware extends Middleware { public $response; public $output; - /** - * @param boolean $beforeControllerThrowsEx - */ public function __construct( - private $beforeControllerThrowsEx, + private bool $beforeControllerThrowsEx, ) { self::$beforeControllerCalled = 0; self::$afterControllerCalled = 0; @@ -47,7 +44,7 @@ public function __construct( } #[\Override] - public function beforeController($controller, $methodName) { + public function beforeController(Controller $controller, string $methodName): void { self::$beforeControllerCalled++; $this->beforeControllerOrder = self::$beforeControllerCalled; $this->controller = $controller; @@ -58,7 +55,7 @@ public function beforeController($controller, $methodName) { } #[\Override] - public function afterException($controller, $methodName, \Exception $exception) { + public function afterException(Controller $controller, string $methodName, \Exception $exception): void { self::$afterExceptionCalled++; $this->afterExceptionOrder = self::$afterExceptionCalled; $this->controller = $controller; @@ -68,7 +65,7 @@ public function afterException($controller, $methodName, \Exception $exception) } #[\Override] - public function afterController($controller, $methodName, Response $response) { + public function afterController(Controller $controller, string $methodName, Response $response): Response { self::$afterControllerCalled++; $this->afterControllerOrder = self::$afterControllerCalled; $this->controller = $controller; @@ -78,7 +75,7 @@ public function afterController($controller, $methodName, Response $response) { } #[\Override] - public function beforeOutput($controller, $methodName, $output) { + public function beforeOutput(Controller $controller, string $methodName, string $output): string { self::$beforeOutputCalled++; $this->beforeOutputOrder = self::$beforeOutputCalled; $this->controller = $controller; diff --git a/tests/lib/AppFramework/Middleware/MiddlewareTest.php b/tests/lib/AppFramework/Middleware/MiddlewareTest.php index a4712dbe86e0f..36acf40ad4284 100644 --- a/tests/lib/AppFramework/Middleware/MiddlewareTest.php +++ b/tests/lib/AppFramework/Middleware/MiddlewareTest.php @@ -1,5 +1,7 @@ request = $this->createMock(IRequest::class); $this->session = $this->createMock(ISession::class); - $this->config = $this->createMock(IConfig::class); + $this->appConfig = $this->createMock(IAppConfig::class); $this->throttler = $this->createMock(IThrottler::class); $this->middleware = new PublicShareMiddleware( $this->request, $this->session, - $this->config, + $this->appConfig, $this->throttler ); } @@ -61,20 +58,20 @@ public function testBeforeControllerNoPublicShareController(): void { public static function dataShareApi(): array { return [ - ['no', 'no',], - ['no', 'yes',], - ['yes', 'no',], + [false, false], + [false, true], + [true, false], ]; } #[\PHPUnit\Framework\Attributes\DataProvider('dataShareApi')] - public function testBeforeControllerShareApiDisabled(string $shareApi, string $shareLinks): void { + public function testBeforeControllerShareApiDisabled(bool $shareApi, bool $shareLinks): void { $controller = $this->createMock(PublicShareController::class); - $this->config->method('getAppValue') + $this->appConfig->method('getValueBool') ->willReturnMap([ - ['core', 'shareapi_enabled', 'yes', $shareApi], - ['core', 'shareapi_allow_links', 'yes', $shareLinks], + ['core', 'shareapi_enabled', true, $shareApi], + ['core', 'shareapi_allow_links', true, $shareLinks], ]); $this->expectException(NotFoundException::class); @@ -84,10 +81,10 @@ public function testBeforeControllerShareApiDisabled(string $shareApi, string $s public function testBeforeControllerNoTokenParam(): void { $controller = $this->createMock(PublicShareController::class); - $this->config->method('getAppValue') + $this->appConfig->method('getValueBool') ->willReturnMap([ - ['core', 'shareapi_enabled', 'yes', 'yes'], - ['core', 'shareapi_allow_links', 'yes', 'yes'], + ['core', 'shareapi_enabled', true, true], + ['core', 'shareapi_allow_links', true, true], ]); $this->expectException(NotFoundException::class); @@ -97,10 +94,10 @@ public function testBeforeControllerNoTokenParam(): void { public function testBeforeControllerInvalidToken(): void { $controller = $this->createMock(PublicShareController::class); - $this->config->method('getAppValue') + $this->appConfig->method('getValueBool') ->willReturnMap([ - ['core', 'shareapi_enabled', 'yes', 'yes'], - ['core', 'shareapi_allow_links', 'yes', 'yes'], + ['core', 'shareapi_enabled', true, true], + ['core', 'shareapi_allow_links', true, true], ]); $this->request->method('getParam') @@ -121,10 +118,10 @@ public function testBeforeControllerValidTokenNotAuthenticated(): void { ->setConstructorArgs(['app', $this->request, $this->session]) ->getMock(); - $this->config->method('getAppValue') + $this->appConfig->method('getValueBool') ->willReturnMap([ - ['core', 'shareapi_enabled', 'yes', 'yes'], - ['core', 'shareapi_allow_links', 'yes', 'yes'], + ['core', 'shareapi_enabled', true, true], + ['core', 'shareapi_allow_links', true, true], ]); $this->request->method('getParam') @@ -146,10 +143,10 @@ public function testBeforeControllerValidTokenAuthenticateMethod(): void { ->setConstructorArgs(['app', $this->request, $this->session]) ->getMock(); - $this->config->method('getAppValue') + $this->appConfig->method('getValueBool') ->willReturnMap([ - ['core', 'shareapi_enabled', 'yes', 'yes'], - ['core', 'shareapi_allow_links', 'yes', 'yes'], + ['core', 'shareapi_enabled', true, true], + ['core', 'shareapi_allow_links', true, true], ]); $this->request->method('getParam') @@ -168,10 +165,10 @@ public function testBeforeControllerValidTokenShowAuthenticateMethod(): void { ->setConstructorArgs(['app', $this->request, $this->session]) ->getMock(); - $this->config->method('getAppValue') + $this->appConfig->method('getValueBool') ->willReturnMap([ - ['core', 'shareapi_enabled', 'yes', 'yes'], - ['core', 'shareapi_allow_links', 'yes', 'yes'], + ['core', 'shareapi_enabled', true, true], + ['core', 'shareapi_allow_links', true, true], ]); $this->request->method('getParam') @@ -190,10 +187,10 @@ public function testBeforeControllerAuthPublicShareController(): void { ->setConstructorArgs(['app', $this->request, $this->session, $this->createMock(IURLGenerator::class)]) ->getMock(); - $this->config->method('getAppValue') + $this->appConfig->method('getValueBool') ->willReturnMap([ - ['core', 'shareapi_enabled', 'yes', 'yes'], - ['core', 'shareapi_allow_links', 'yes', 'yes'], + ['core', 'shareapi_enabled', true, true], + ['core', 'shareapi_allow_links', true, true], ]); $this->request->method('getParam') diff --git a/tests/lib/AppFramework/Middleware/Security/PasswordConfirmationMiddlewareTest.php b/tests/lib/AppFramework/Middleware/Security/PasswordConfirmationMiddlewareTest.php index ed37e6f327920..1968e5abb5062 100644 --- a/tests/lib/AppFramework/Middleware/Security/PasswordConfirmationMiddlewareTest.php +++ b/tests/lib/AppFramework/Middleware/Security/PasswordConfirmationMiddlewareTest.php @@ -39,7 +39,6 @@ class PasswordConfirmationMiddlewareTest extends TestCase { /** @var ITimeFactory&\PHPUnit\Framework\MockObject\MockObject */ private $timeFactory; private IProvider&\PHPUnit\Framework\MockObject\MockObject $tokenProvider; - private LoggerInterface $logger; /** @var IRequest&\PHPUnit\Framework\MockObject\MockObject */ private IRequest $request; /** @var Manager&\PHPUnit\Framework\MockObject\MockObject */ @@ -55,7 +54,6 @@ protected function setUp(): void { $this->user = $this->createMock(IUser::class); $this->timeFactory = $this->createMock(ITimeFactory::class); $this->tokenProvider = $this->createMock(IProvider::class); - $this->logger = $this->createMock(LoggerInterface::class); $this->request = $this->createMock(IRequest::class); $this->userManager = $this->createMock(Manager::class); $this->controller = new PasswordConfirmationMiddlewareController( @@ -69,7 +67,6 @@ protected function setUp(): void { $this->userSession, $this->timeFactory, $this->tokenProvider, - $this->logger, $this->request, $this->userManager, );