diff --git a/REUSE.toml b/REUSE.toml index 05a49bd80e46b..b799a0f76adbe 100644 --- a/REUSE.toml +++ b/REUSE.toml @@ -250,7 +250,7 @@ SPDX-FileCopyrightText = "2023 Nextcloud GmbH and Nextcloud contributors" SPDX-License-Identifier = "AGPL-3.0-or-later" [[annotations]] -path = ["apps/dav/lib/ExampleContentFiles/exampleContact.vcf", "tests/data/testvideo-remote-file.mp4"] +path = ["apps/dav/lib/ExampleContentFiles/exampleContact.vcf", "tests/data/testvideo-remote-file.mp4", "tests/lib/AppFramework/Middleware/Mock/UseSessionController.php", "tests/lib/AppFramework/Middleware/Security/Mock/BruteForceMiddlewareController.php", "tests/lib/AppFramework/Middleware/Security/Mock/RateLimitingMiddlewareController.php"] precedence = "aggregate" SPDX-FileCopyrightText = "2025 Nextcloud GmbH and Nextcloud contributors" SPDX-License-Identifier = "AGPL-3.0-or-later" diff --git a/apps/comments/lib/Search/Result.php b/apps/comments/lib/Search/Result.php index 13907757954eb..2931ff4113bf1 100644 --- a/apps/comments/lib/Search/Result.php +++ b/apps/comments/lib/Search/Result.php @@ -34,10 +34,6 @@ class Result extends BaseResult { * @deprecated 20.0.0 */ public $fileName; - /** - * @deprecated 20.0.0 - */ - public int $fileId; /** * @throws NotFoundException @@ -51,7 +47,10 @@ public function __construct( */ public string $authorName, string $path, - int $fileId, + /** + * @deprecated 20.0.0 + */ + public int $fileId, ) { parent::__construct( $comment->getId(), @@ -63,7 +62,6 @@ public function __construct( $this->authorId = $comment->getActorId(); $this->fileName = basename($path); $this->path = $this->getVisiblePath($path); - $this->fileId = $fileId; } /** diff --git a/apps/dav/appinfo/v1/caldav.php b/apps/dav/appinfo/v1/caldav.php index ff66274909d61..6cfb712984f99 100644 --- a/apps/dav/appinfo/v1/caldav.php +++ b/apps/dav/appinfo/v1/caldav.php @@ -24,6 +24,7 @@ use OCP\Accounts\IAccountManager; use OCP\App\IAppManager; use OCP\EventDispatcher\IEventDispatcher; +use OCP\ICacheFactory; use OCP\IConfig; use OCP\IDBConnection; use OCP\IGroupManager; @@ -78,7 +79,7 @@ $config, Server::get(\OCA\DAV\CalDAV\Sharing\Backend::class), Server::get(FederatedCalendarMapper::class), - Server::get(\OCP\ICacheFactory::class), + Server::get(ICacheFactory::class), true ); diff --git a/apps/dav/lib/CalDAV/Federation/CalendarFederationProvider.php b/apps/dav/lib/CalDAV/Federation/CalendarFederationProvider.php index de5f5b987d218..05d9ea9d6ecfd 100644 --- a/apps/dav/lib/CalDAV/Federation/CalendarFederationProvider.php +++ b/apps/dav/lib/CalDAV/Federation/CalendarFederationProvider.php @@ -11,6 +11,7 @@ use OCA\DAV\BackgroundJob\FederatedCalendarSyncJob; use OCA\DAV\CalDAV\Federation\Protocol\CalendarFederationProtocolV1; +use OCA\DAV\CalDAV\Federation\Protocol\CalendarProtocolParseException; use OCA\DAV\CalDAV\Federation\Protocol\ICalendarFederationProtocol; use OCA\DAV\DAV\Sharing\Backend as DavSharingBackend; use OCP\AppFramework\Http; @@ -74,7 +75,7 @@ public function shareReceived(ICloudFederationShare $share): string { case CalendarFederationProtocolV1::VERSION: try { $protocol = CalendarFederationProtocolV1::parse($rawProtocol); - } catch (Protocol\CalendarProtocolParseException $e) { + } catch (CalendarProtocolParseException $e) { throw new ProviderCouldNotAddShareException( 'Invalid protocol data (v1)', '', diff --git a/apps/dav/lib/DAV/RemoteUserPrincipalBackend.php b/apps/dav/lib/DAV/RemoteUserPrincipalBackend.php index ec9874427bae9..20fbd0194ce9a 100644 --- a/apps/dav/lib/DAV/RemoteUserPrincipalBackend.php +++ b/apps/dav/lib/DAV/RemoteUserPrincipalBackend.php @@ -10,6 +10,7 @@ namespace OCA\DAV\DAV; use OCA\DAV\DAV\Sharing\SharingMapper; +use OCP\Federation\ICloudId; use OCP\Federation\ICloudIdManager; use Sabre\DAVACL\PrincipalBackend\BackendInterface; @@ -102,7 +103,7 @@ public function setGroupMemberSet($principal, array $members) { } /** - * @return array{'{DAV:}displayname': string, '{http://nextcloud.com/ns}cloud-id': \OCP\Federation\ICloudId, uri: string} + * @return array{'{DAV:}displayname': string, '{http://nextcloud.com/ns}cloud-id': ICloudId, uri: string} */ private function principalUriToPrincipal(string $principalUri): array { [, $name] = \Sabre\Uri\split($principalUri); diff --git a/apps/dav/tests/unit/Connector/Sabre/PropFindMonitorPluginTest.php b/apps/dav/tests/unit/Connector/Sabre/PropFindMonitorPluginTest.php index 9d22befa201fa..60b162116cdcb 100644 --- a/apps/dav/tests/unit/Connector/Sabre/PropFindMonitorPluginTest.php +++ b/apps/dav/tests/unit/Connector/Sabre/PropFindMonitorPluginTest.php @@ -105,9 +105,7 @@ public static function dataTest(): array { ]; } - /** - * @dataProvider dataTest - */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataTest')] public function test(array $queries, $expectedLogCalls): void { $this->plugin->initialize($this->server); $this->server->expects($this->once())->method('getPluginQueries') diff --git a/apps/encryption/lib/Controller/RecoveryController.php b/apps/encryption/lib/Controller/RecoveryController.php index d75406e6319d6..e7fb6bafb672d 100644 --- a/apps/encryption/lib/Controller/RecoveryController.php +++ b/apps/encryption/lib/Controller/RecoveryController.php @@ -25,13 +25,13 @@ class RecoveryController extends Controller { * @param Recovery $recovery */ public function __construct( - $AppName, + $appName, IRequest $request, private IConfig $config, private IL10N $l, private Recovery $recovery, ) { - parent::__construct($AppName, $request); + parent::__construct($appName, $request); } /** diff --git a/apps/encryption/lib/Controller/SettingsController.php b/apps/encryption/lib/Controller/SettingsController.php index 8548ea51c043f..fd3637e0d7963 100644 --- a/apps/encryption/lib/Controller/SettingsController.php +++ b/apps/encryption/lib/Controller/SettingsController.php @@ -37,7 +37,7 @@ class SettingsController extends Controller { * @param Util $util */ public function __construct( - $AppName, + $appName, IRequest $request, private IL10N $l, private IUserManager $userManager, @@ -48,7 +48,7 @@ public function __construct( private ISession $ocSession, private Util $util, ) { - parent::__construct($AppName, $request); + parent::__construct($appName, $request); } diff --git a/apps/encryption/lib/Controller/StatusController.php b/apps/encryption/lib/Controller/StatusController.php index 341ad6bc49f15..914432f78a321 100644 --- a/apps/encryption/lib/Controller/StatusController.php +++ b/apps/encryption/lib/Controller/StatusController.php @@ -25,13 +25,13 @@ class StatusController extends Controller { * @param IManager $encryptionManager */ public function __construct( - $AppName, + $appName, IRequest $request, private IL10N $l, private Session $session, private IManager $encryptionManager, ) { - parent::__construct($AppName, $request); + parent::__construct($appName, $request); } /** diff --git a/apps/federation/lib/Controller/SettingsController.php b/apps/federation/lib/Controller/SettingsController.php index 27341eba81535..541c821d56986 100644 --- a/apps/federation/lib/Controller/SettingsController.php +++ b/apps/federation/lib/Controller/SettingsController.php @@ -22,13 +22,13 @@ class SettingsController extends OCSController { public function __construct( - string $AppName, + string $appName, IRequest $request, private IL10N $l, private TrustedServers $trustedServers, private LoggerInterface $logger, ) { - parent::__construct($AppName, $request); + parent::__construct($appName, $request); } diff --git a/apps/files_external/lib/Controller/GlobalStoragesController.php b/apps/files_external/lib/Controller/GlobalStoragesController.php index e7274c9cfb64c..0f9326ef464ed 100644 --- a/apps/files_external/lib/Controller/GlobalStoragesController.php +++ b/apps/files_external/lib/Controller/GlobalStoragesController.php @@ -36,7 +36,7 @@ class GlobalStoragesController extends StoragesController { * @param IConfig $config */ public function __construct( - $AppName, + $appName, IRequest $request, IL10N $l10n, GlobalStoragesService $globalStoragesService, @@ -46,7 +46,7 @@ public function __construct( IConfig $config, ) { parent::__construct( - $AppName, + $appName, $request, $l10n, $globalStoragesService, diff --git a/apps/files_external/lib/Controller/StoragesController.php b/apps/files_external/lib/Controller/StoragesController.php index df3a45280549a..cf3fbc2d24fd1 100644 --- a/apps/files_external/lib/Controller/StoragesController.php +++ b/apps/files_external/lib/Controller/StoragesController.php @@ -40,7 +40,7 @@ abstract class StoragesController extends Controller { * @param LoggerInterface $logger */ public function __construct( - $AppName, + $appName, IRequest $request, protected IL10N $l10n, protected StoragesService $service, @@ -49,7 +49,7 @@ public function __construct( protected IGroupManager $groupManager, protected IConfig $config, ) { - parent::__construct($AppName, $request); + parent::__construct($appName, $request); } /** diff --git a/apps/files_external/lib/Controller/UserGlobalStoragesController.php b/apps/files_external/lib/Controller/UserGlobalStoragesController.php index 88a9f936401b0..d1f231a870fe5 100644 --- a/apps/files_external/lib/Controller/UserGlobalStoragesController.php +++ b/apps/files_external/lib/Controller/UserGlobalStoragesController.php @@ -42,7 +42,7 @@ class UserGlobalStoragesController extends StoragesController { * @param IGroupManager $groupManager */ public function __construct( - $AppName, + $appName, IRequest $request, IL10N $l10n, UserGlobalStoragesService $userGlobalStoragesService, @@ -52,7 +52,7 @@ public function __construct( IConfig $config, ) { parent::__construct( - $AppName, + $appName, $request, $l10n, $userGlobalStoragesService, diff --git a/apps/files_external/lib/Controller/UserStoragesController.php b/apps/files_external/lib/Controller/UserStoragesController.php index 7b564d57f7ede..f724718aaa585 100644 --- a/apps/files_external/lib/Controller/UserStoragesController.php +++ b/apps/files_external/lib/Controller/UserStoragesController.php @@ -39,7 +39,7 @@ class UserStoragesController extends StoragesController { * @param IGroupManager $groupManager */ public function __construct( - $AppName, + $appName, IRequest $request, IL10N $l10n, UserStoragesService $userStoragesService, @@ -49,7 +49,7 @@ public function __construct( IConfig $config, ) { parent::__construct( - $AppName, + $appName, $request, $l10n, $userStoragesService, diff --git a/apps/files_sharing/tests/ApiTest.php b/apps/files_sharing/tests/ApiTest.php index 960f29224bb9e..abb72793bc0c9 100644 --- a/apps/files_sharing/tests/ApiTest.php +++ b/apps/files_sharing/tests/ApiTest.php @@ -240,8 +240,8 @@ public function testCreateShareLink(): void { /** * @group RoutingWeirdness - * @dataProvider dataAllowFederationOnPublicShares */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataAllowFederationOnPublicShares')] public function testCreateShareLinkPublicUpload(array $appConfig, int $permissions): void { $this->appConfig->method('getValueBool') ->willReturnMap([$appConfig]); @@ -1016,8 +1016,8 @@ public function testUpdateShare(): void { /** * @medium - * @dataProvider dataAllowFederationOnPublicShares */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataAllowFederationOnPublicShares')] public function testUpdateShareUpload(array $appConfig, int $permissions): void { $this->appConfig->method('getValueBool')->willReturnMap([ $appConfig, diff --git a/apps/files_trashbin/lib/BackgroundJob/ExpireTrash.php b/apps/files_trashbin/lib/BackgroundJob/ExpireTrash.php index bbdf0b899bdd6..9a2186d79a496 100644 --- a/apps/files_trashbin/lib/BackgroundJob/ExpireTrash.php +++ b/apps/files_trashbin/lib/BackgroundJob/ExpireTrash.php @@ -19,6 +19,7 @@ use OCP\IUser; use OCP\IUserManager; use OCP\Lock\ILockingProvider; +use OCP\Lock\LockedException; use Psr\Log\LoggerInterface; class ExpireTrash extends TimedJob { @@ -111,7 +112,7 @@ private function getNextOffset(): int { } private function resetOffset() { - $this->runMutexOperation(function () { + $this->runMutexOperation(function (): void { $this->appConfig->setValueInt(Application::APP_ID, self::OFFSET_CONFIG_KEY_NAME, 0); }); } @@ -123,7 +124,7 @@ private function runMutexOperation($operation): mixed { try { $this->lockingProvider->acquireLock(self::OFFSET_CONFIG_KEY_NAME, ILockingProvider::LOCK_EXCLUSIVE, 'Expire trashbin background job offset'); $acquired = true; - } catch (\OCP\Lock\LockedException $e) { + } catch (LockedException $e) { // wait a bit and try again usleep(100000); } diff --git a/apps/files_trashbin/tests/Command/ExpireTrashTest.php b/apps/files_trashbin/tests/Command/ExpireTrashTest.php index 0d0ee98ca7a23..edad8bfbd957b 100644 --- a/apps/files_trashbin/tests/Command/ExpireTrashTest.php +++ b/apps/files_trashbin/tests/Command/ExpireTrashTest.php @@ -64,9 +64,7 @@ protected function tearDown(): void { parent::tearDown(); } - /** - * @dataProvider retentionObligationProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('retentionObligationProvider')] public function testRetentionObligation(string $obligation, string $quota, int $elapsed, int $fileSize, bool $shouldExpire): void { $this->config->setSystemValues(['trashbin_retention_obligation' => $obligation]); $this->expiration->setRetentionObligation($obligation); diff --git a/apps/settings/lib/Controller/AuthorizedGroupController.php b/apps/settings/lib/Controller/AuthorizedGroupController.php index 82a1ca4703e73..9ff0f2cb2158a 100644 --- a/apps/settings/lib/Controller/AuthorizedGroupController.php +++ b/apps/settings/lib/Controller/AuthorizedGroupController.php @@ -16,11 +16,11 @@ class AuthorizedGroupController extends Controller { public function __construct( - string $AppName, + string $appName, IRequest $request, private AuthorizedGroupService $authorizedGroupService, ) { - parent::__construct($AppName, $request); + parent::__construct($appName, $request); } /** diff --git a/apps/settings/lib/Controller/CheckSetupController.php b/apps/settings/lib/Controller/CheckSetupController.php index 82a46bea4fb58..3335dede58bef 100644 --- a/apps/settings/lib/Controller/CheckSetupController.php +++ b/apps/settings/lib/Controller/CheckSetupController.php @@ -31,7 +31,7 @@ class CheckSetupController extends Controller { private $checker; public function __construct( - $AppName, + $appName, IRequest $request, private IConfig $config, private IURLGenerator $urlGenerator, @@ -40,7 +40,7 @@ public function __construct( private LoggerInterface $logger, private ISetupCheckManager $setupCheckManager, ) { - parent::__construct($AppName, $request); + parent::__construct($appName, $request); $this->checker = $checker; } diff --git a/build/psalm-baseline.xml b/build/psalm-baseline.xml index 950aaf92acbed..8f95f1415a1e5 100644 --- a/build/psalm-baseline.xml +++ b/build/psalm-baseline.xml @@ -71,8 +71,6 @@ authorId]]> authorId]]> authorId]]> - fileId]]> - fileId]]> name]]> path]]> @@ -111,7 +109,6 @@ authorId]]> comment]]> - fileId]]> fileName]]> path]]> diff --git a/build/rector.php b/build/rector.php index 246741bb34fa5..90b33bad6ff75 100644 --- a/build/rector.php +++ b/build/rector.php @@ -77,6 +77,9 @@ public function shouldSkip(File $file, FullyQualifiedObjectType $fullyQualifiedO $nextcloudDir . '/apps/*/build/stubs/*', $nextcloudDir . '/apps/*/composer/*', $nextcloudDir . '/apps/*/config/*', + // The mock classes are excluded, as the tests explicitly test the annotations which should not be migrated to attributes + $nextcloudDir . '/tests/lib/AppFramework/Middleware/Mock/*', + $nextcloudDir . '/tests/lib/AppFramework/Middleware/Security/Mock/*', ]) // uncomment to reach your current PHP version // ->withPhpSets() @@ -92,7 +95,7 @@ public function shouldSkip(File $file, FullyQualifiedObjectType $fullyQualifiedO 'rename_property' => true, ]) ->withSets([ - NextcloudSets::NEXTCLOUD_25, + NextcloudSets::NEXTCLOUD_27, ]); $config->registerService(NextcloudNamespaceSkipVoter::class, tag:ClassNameImportSkipVoterInterface::class); diff --git a/console.php b/console.php index 10de07dd489b5..b5a000e8873a0 100644 --- a/console.php +++ b/console.php @@ -3,6 +3,7 @@ declare(strict_types=1); use OCP\IConfig; +use OCP\IURLGenerator; use OCP\Server; /** @@ -100,7 +101,7 @@ function exceptionHandler($exception) { $profile->setUrl(implode(' ', $argv)); $profiler->saveProfile($profile); - $urlGenerator = Server::get(\OCP\IURLGenerator::class); + $urlGenerator = Server::get(IURLGenerator::class); $url = $urlGenerator->linkToRouteAbsolute('profiler.main.profiler', [ 'profiler' => 'db', 'token' => $profile->getToken(), diff --git a/core/Command/Base.php b/core/Command/Base.php index 8f94c1d473aba..138f3ca613bf7 100644 --- a/core/Command/Base.php +++ b/core/Command/Base.php @@ -8,6 +8,8 @@ namespace OC\Core\Command; use OC\Core\Command\User\ListCommand; +use OCP\Defaults; +use OCP\Server; use Stecman\Component\Symfony\Console\BashCompletion\Completion\CompletionAwareInterface; use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext; use Symfony\Component\Console\Command\Command; @@ -27,7 +29,7 @@ class Base extends Command implements CompletionAwareInterface { protected function configure() { // Some of our commands do not extend this class; and some of those that do do not call parent::configure() - $defaultHelp = 'More extensive and thorough documentation may be found at ' . \OCP\Server::get(\OCP\Defaults::class)->getDocBaseUrl() . PHP_EOL; + $defaultHelp = 'More extensive and thorough documentation may be found at ' . Server::get(Defaults::class)->getDocBaseUrl() . PHP_EOL; $this ->setHelp($defaultHelp) ->addOption( diff --git a/core/Controller/TwoFactorChallengeController.php b/core/Controller/TwoFactorChallengeController.php index 4791139bb12d2..8072bb8e92a04 100644 --- a/core/Controller/TwoFactorChallengeController.php +++ b/core/Controller/TwoFactorChallengeController.php @@ -14,6 +14,7 @@ use OCP\AppFramework\Http\Attribute\NoAdminRequired; use OCP\AppFramework\Http\Attribute\NoCSRFRequired; use OCP\AppFramework\Http\Attribute\OpenAPI; +use OCP\AppFramework\Http\Attribute\UserRateLimit; use OCP\AppFramework\Http\Attribute\UseSession; use OCP\AppFramework\Http\RedirectResponse; use OCP\AppFramework\Http\StandaloneTemplateResponse; @@ -150,7 +151,6 @@ public function showChallenge($challengeProviderId, $redirect_url) { /** * @TwoFactorSetUpDoneRequired * - * @UserRateThrottle(limit=5, period=100) * * @param string $challengeProviderId * @param string $challenge @@ -161,6 +161,7 @@ public function showChallenge($challengeProviderId, $redirect_url) { #[NoCSRFRequired] #[UseSession] #[FrontpageRoute(verb: 'POST', url: '/login/challenge/{challengeProviderId}')] + #[UserRateLimit(limit: 5, period: 100)] public function solveChallenge($challengeProviderId, $challenge, $redirect_url = null) { $user = $this->userSession->getUser(); $provider = $this->twoFactorManager->getProvider($user, $challengeProviderId); diff --git a/tests/lib/AppFramework/Middleware/Mock/UseSessionController.php b/tests/lib/AppFramework/Middleware/Mock/UseSessionController.php new file mode 100644 index 0000000000000..d5ee95dfe4c06 --- /dev/null +++ b/tests/lib/AppFramework/Middleware/Mock/UseSessionController.php @@ -0,0 +1,19 @@ +method('sleepDelayOrThrowOnMax') ->with('127.0.0.1', 'login'); - $controller = new TestController('test', $this->request); + $controller = new BruteForceMiddlewareController('test', $this->request); $this->reflector->reflect($controller, 'testMethodWithAnnotation'); $this->bruteForceMiddleware->beforeController($controller, 'testMethodWithAnnotation'); } @@ -89,7 +68,7 @@ public function testBeforeControllerWithSingleAttribute(): void { ->method('sleepDelayOrThrowOnMax') ->with('::1', 'single'); - $controller = new TestController('test', $this->request); + $controller = new BruteForceMiddlewareController('test', $this->request); $this->reflector->reflect($controller, 'singleAttribute'); $this->bruteForceMiddleware->beforeController($controller, 'singleAttribute'); } @@ -113,7 +92,7 @@ public function testBeforeControllerWithMultipleAttributes(): void { return 0; }); - $controller = new TestController('test', $this->request); + $controller = new BruteForceMiddlewareController('test', $this->request); $this->reflector->reflect($controller, 'multipleAttributes'); $this->bruteForceMiddleware->beforeController($controller, 'multipleAttributes'); } @@ -126,7 +105,7 @@ public function testBeforeControllerWithoutAnnotation(): void { ->expects($this->never()) ->method('sleepDelayOrThrowOnMax'); - $controller = new TestController('test', $this->request); + $controller = new BruteForceMiddlewareController('test', $this->request); $this->reflector->reflect($controller, 'testMethodWithoutAnnotation'); $this->bruteForceMiddleware->beforeController($controller, 'testMethodWithoutAnnotation'); } @@ -155,7 +134,7 @@ public function testAfterControllerWithAnnotationAndThrottledRequest(): void { ->method('registerAttempt') ->with('login', '127.0.0.1'); - $controller = new TestController('test', $this->request); + $controller = new BruteForceMiddlewareController('test', $this->request); $this->reflector->reflect($controller, 'testMethodWithAnnotation'); $this->bruteForceMiddleware->afterController($controller, 'testMethodWithAnnotation', $response); } @@ -177,7 +156,7 @@ public function testAfterControllerWithAnnotationAndNotThrottledRequest(): void ->expects($this->never()) ->method('registerAttempt'); - $controller = new TestController('test', $this->request); + $controller = new BruteForceMiddlewareController('test', $this->request); $this->reflector->reflect($controller, 'testMethodWithAnnotation'); $this->bruteForceMiddleware->afterController($controller, 'testMethodWithAnnotation', $response); } @@ -207,7 +186,7 @@ public function testAfterControllerWithSingleAttribute(): void { ->method('registerAttempt') ->with('single', '::1'); - $controller = new TestController('test', $this->request); + $controller = new BruteForceMiddlewareController('test', $this->request); $this->reflector->reflect($controller, 'singleAttribute'); $this->bruteForceMiddleware->afterController($controller, 'singleAttribute', $response); } @@ -254,7 +233,7 @@ public function testAfterControllerWithMultipleAttributesGeneralMatch(): void { $this->assertEquals($expected, func_get_args()); }); - $controller = new TestController('test', $this->request); + $controller = new BruteForceMiddlewareController('test', $this->request); $this->reflector->reflect($controller, 'multipleAttributes'); $this->bruteForceMiddleware->afterController($controller, 'multipleAttributes', $response); } @@ -284,7 +263,7 @@ public function testAfterControllerWithMultipleAttributesSpecificMatch(): void { ->method('registerAttempt') ->with('second', '::1'); - $controller = new TestController('test', $this->request); + $controller = new BruteForceMiddlewareController('test', $this->request); $this->reflector->reflect($controller, 'multipleAttributes'); $this->bruteForceMiddleware->afterController($controller, 'multipleAttributes', $response); } @@ -297,7 +276,7 @@ public function testAfterControllerWithoutAnnotation(): void { ->expects($this->never()) ->method('sleepDelayOrThrowOnMax'); - $controller = new TestController('test', $this->request); + $controller = new BruteForceMiddlewareController('test', $this->request); $this->reflector->reflect($controller, 'testMethodWithoutAnnotation'); /** @var Response|\PHPUnit\Framework\MockObject\MockObject $response */ $response = $this->createMock(Response::class); @@ -312,7 +291,7 @@ public function testAfterControllerWithThrottledResponseButUnhandled(): void { ->expects($this->never()) ->method('sleepDelayOrThrowOnMax'); - $controller = new TestController('test', $this->request); + $controller = new BruteForceMiddlewareController('test', $this->request); $this->reflector->reflect($controller, 'testMethodWithoutAnnotation'); /** @var Response|\PHPUnit\Framework\MockObject\MockObject $response */ $response = $this->createMock(Response::class); @@ -321,7 +300,7 @@ public function testAfterControllerWithThrottledResponseButUnhandled(): void { $this->logger->expects($this->once()) ->method('debug') - ->with('Response for Test\AppFramework\Middleware\Security\TestController::testMethodWithoutAnnotation got bruteforce throttled but has no annotation nor attribute defined.'); + ->with('Response for Test\AppFramework\Middleware\Security\Mock\BruteForceMiddlewareController::testMethodWithoutAnnotation got bruteforce throttled but has no annotation nor attribute defined.'); $this->bruteForceMiddleware->afterController($controller, 'testMethodWithoutAnnotation', $response); } diff --git a/tests/lib/AppFramework/Middleware/Security/Mock/BruteForceMiddlewareController.php b/tests/lib/AppFramework/Middleware/Security/Mock/BruteForceMiddlewareController.php new file mode 100644 index 0000000000000..a5091004fcbb4 --- /dev/null +++ b/tests/lib/AppFramework/Middleware/Security/Mock/BruteForceMiddlewareController.php @@ -0,0 +1,26 @@ +method('isLoggedIn') ->willReturn(false); - /** @var TestRateLimitController|MockObject $controller */ - $controller = $this->createMock(TestRateLimitController::class); + /** @var RateLimitingMiddlewareController|MockObject $controller */ + $controller = $this->createMock(RateLimitingMiddlewareController::class); $this->reflector->reflect($controller, 'testMethodWithoutAnnotation'); $this->rateLimitingMiddleware->beforeController($controller, 'testMethodWithoutAnnotation'); } @@ -119,14 +90,14 @@ public function testBeforeControllerWithoutAnnotationForLoggedIn(): void { ->method('isLoggedIn') ->willReturn(true); - /** @var TestRateLimitController|MockObject $controller */ - $controller = $this->createMock(TestRateLimitController::class); + /** @var RateLimitingMiddlewareController|MockObject $controller */ + $controller = $this->createMock(RateLimitingMiddlewareController::class); $this->reflector->reflect($controller, 'testMethodWithoutAnnotation'); $this->rateLimitingMiddleware->beforeController($controller, 'testMethodWithoutAnnotation'); } public function testBeforeControllerForAnon(): void { - $controller = new TestRateLimitController('test', $this->request); + $controller = new RateLimitingMiddlewareController('test', $this->request); $this->request ->method('getRemoteAddress') @@ -150,7 +121,7 @@ public function testBeforeControllerForAnon(): void { } public function testBeforeControllerForLoggedIn(): void { - $controller = new TestRateLimitController('test', $this->request); + $controller = new RateLimitingMiddlewareController('test', $this->request); /** @var IUser|MockObject $user */ $user = $this->createMock(IUser::class); @@ -177,7 +148,7 @@ public function testBeforeControllerForLoggedIn(): void { } public function testBeforeControllerAnonWithFallback(): void { - $controller = new TestRateLimitController('test', $this->request); + $controller = new RateLimitingMiddlewareController('test', $this->request); $this->request ->expects($this->once()) ->method('getRemoteAddress') @@ -202,7 +173,7 @@ public function testBeforeControllerAnonWithFallback(): void { } public function testBeforeControllerAttributesForAnon(): void { - $controller = new TestRateLimitController('test', $this->request); + $controller = new RateLimitingMiddlewareController('test', $this->request); $this->request ->method('getRemoteAddress') @@ -226,7 +197,7 @@ public function testBeforeControllerAttributesForAnon(): void { } public function testBeforeControllerAttributesForLoggedIn(): void { - $controller = new TestRateLimitController('test', $this->request); + $controller = new RateLimitingMiddlewareController('test', $this->request); /** @var IUser|MockObject $user */ $user = $this->createMock(IUser::class); @@ -253,7 +224,7 @@ public function testBeforeControllerAttributesForLoggedIn(): void { } public function testBeforeControllerAttributesAnonWithFallback(): void { - $controller = new TestRateLimitController('test', $this->request); + $controller = new RateLimitingMiddlewareController('test', $this->request); $this->request ->expects($this->once()) ->method('getRemoteAddress') @@ -281,13 +252,13 @@ public function testAfterExceptionWithOtherException(): void { $this->expectException(\Exception::class); $this->expectExceptionMessage('My test exception'); - $controller = new TestRateLimitController('test', $this->request); + $controller = new RateLimitingMiddlewareController('test', $this->request); $this->rateLimitingMiddleware->afterException($controller, 'testMethod', new \Exception('My test exception')); } public function testAfterExceptionWithJsonBody(): void { - $controller = new TestRateLimitController('test', $this->request); + $controller = new RateLimitingMiddlewareController('test', $this->request); $this->request ->expects($this->once()) ->method('getHeader') @@ -301,7 +272,7 @@ public function testAfterExceptionWithJsonBody(): void { } public function testAfterExceptionWithHtmlBody(): void { - $controller = new TestRateLimitController('test', $this->request); + $controller = new RateLimitingMiddlewareController('test', $this->request); $this->request ->expects($this->once()) ->method('getHeader') diff --git a/tests/lib/AppFramework/Middleware/SessionMiddlewareTest.php b/tests/lib/AppFramework/Middleware/SessionMiddlewareTest.php index 8ecc73791c902..234696ddcf1f1 100644 --- a/tests/lib/AppFramework/Middleware/SessionMiddlewareTest.php +++ b/tests/lib/AppFramework/Middleware/SessionMiddlewareTest.php @@ -11,11 +11,11 @@ use OC\AppFramework\Middleware\SessionMiddleware; use OC\AppFramework\Utility\ControllerMethodReflector; use OCP\AppFramework\Controller; -use OCP\AppFramework\Http\Attribute\UseSession; use OCP\AppFramework\Http\Response; use OCP\IRequest; use OCP\ISession; use PHPUnit\Framework\MockObject\MockObject; +use Test\AppFramework\Middleware\Mock\UseSessionController; use Test\TestCase; class SessionMiddlewareTest extends TestCase { @@ -29,18 +29,7 @@ protected function setUp(): void { $this->reflector = $this->createMock(ControllerMethodReflector::class); $this->session = $this->createMock(ISession::class); - $this->controller = new class('app', $this->createMock(IRequest::class)) extends Controller { - /** - * @UseSession - */ - public function withAnnotation() { - } - #[UseSession] - public function withAttribute() { - } - public function without() { - } - }; + $this->controller = new UseSessionController('app', $this->createMock(IRequest::class)); $this->middleware = new SessionMiddleware( $this->reflector, $this->session, diff --git a/tests/lib/DB/QueryBuilder/QueryBuilderTest.php b/tests/lib/DB/QueryBuilder/QueryBuilderTest.php index a2107a7491f7a..a1c3ae3d905f2 100644 --- a/tests/lib/DB/QueryBuilder/QueryBuilderTest.php +++ b/tests/lib/DB/QueryBuilder/QueryBuilderTest.php @@ -189,7 +189,7 @@ public function testSelect(array $selectArguments, array $expected, string $expe array_walk_recursive( $selectArguments, - function (string &$arg) { + function (string &$arg): void { if (\str_starts_with($arg, 'l::')) { $arg = $this->queryBuilder->expr()->literal(substr($arg, 3)); } @@ -357,7 +357,7 @@ public function testAddSelect(array $selectArguments, array $expected, string $e array_walk_recursive( $selectArguments, - function (string &$arg) { + function (string &$arg): void { if (\str_starts_with($arg, 'l::')) { $arg = $this->queryBuilder->expr()->literal(substr($arg, 3)); } diff --git a/tests/lib/SystemTag/SystemTagObjectMapperTest.php b/tests/lib/SystemTag/SystemTagObjectMapperTest.php index ed51dd3ffd6fd..e459b81512d75 100644 --- a/tests/lib/SystemTag/SystemTagObjectMapperTest.php +++ b/tests/lib/SystemTag/SystemTagObjectMapperTest.php @@ -212,7 +212,7 @@ public function testGetObjectsForNonExistingTag(): void { public function testAssignUnassignTags(): void { $event = null; - $this->dispatcher->expects($this->any())->method('dispatchTyped')->willReturnCallback(function (Event $e) use (&$event) { + $this->dispatcher->expects($this->any())->method('dispatchTyped')->willReturnCallback(function (Event $e) use (&$event): void { $event = $e; });