mirror of
https://github.com/nextcloud/server.git
synced 2026-02-27 18:37:17 +01:00
Merge pull request #55360 from nextcloud/refactor/rector
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -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 @@ class Result extends BaseResult {
|
||||
*/
|
||||
public string $authorName,
|
||||
string $path,
|
||||
int $fileId,
|
||||
/**
|
||||
* @deprecated 20.0.0
|
||||
*/
|
||||
public int $fileId,
|
||||
) {
|
||||
parent::__construct(
|
||||
$comment->getId(),
|
||||
@@ -63,7 +62,6 @@ class Result extends BaseResult {
|
||||
$this->authorId = $comment->getActorId();
|
||||
$this->fileName = basename($path);
|
||||
$this->path = $this->getVisiblePath($path);
|
||||
$this->fileId = $fileId;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -24,6 +24,7 @@ use OCA\DAV\Connector\Sabre\Principal;
|
||||
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 @@ $calDavBackend = new CalDavBackend(
|
||||
$config,
|
||||
Server::get(\OCA\DAV\CalDAV\Sharing\Backend::class),
|
||||
Server::get(FederatedCalendarMapper::class),
|
||||
Server::get(\OCP\ICacheFactory::class),
|
||||
Server::get(ICacheFactory::class),
|
||||
true
|
||||
);
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ namespace OCA\DAV\CalDAV\Federation;
|
||||
|
||||
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 @@ class CalendarFederationProvider implements ICloudFederationProvider {
|
||||
case CalendarFederationProtocolV1::VERSION:
|
||||
try {
|
||||
$protocol = CalendarFederationProtocolV1::parse($rawProtocol);
|
||||
} catch (Protocol\CalendarProtocolParseException $e) {
|
||||
} catch (CalendarProtocolParseException $e) {
|
||||
throw new ProviderCouldNotAddShareException(
|
||||
'Invalid protocol data (v1)',
|
||||
'',
|
||||
|
||||
@@ -10,6 +10,7 @@ declare(strict_types=1);
|
||||
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 @@ class RemoteUserPrincipalBackend implements BackendInterface {
|
||||
}
|
||||
|
||||
/**
|
||||
* @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);
|
||||
|
||||
@@ -105,9 +105,7 @@ class PropFindMonitorPluginTest extends TestCase {
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @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')
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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 @@ class SettingsController extends Controller {
|
||||
private ISession $ocSession,
|
||||
private Util $util,
|
||||
) {
|
||||
parent::__construct($AppName, $request);
|
||||
parent::__construct($appName, $request);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -22,13 +22,13 @@ use Psr\Log\LoggerInterface;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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 @@ class GlobalStoragesController extends StoragesController {
|
||||
IConfig $config,
|
||||
) {
|
||||
parent::__construct(
|
||||
$AppName,
|
||||
$appName,
|
||||
$request,
|
||||
$l10n,
|
||||
$globalStoragesService,
|
||||
|
||||
@@ -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 @@ abstract class StoragesController extends Controller {
|
||||
protected IGroupManager $groupManager,
|
||||
protected IConfig $config,
|
||||
) {
|
||||
parent::__construct($AppName, $request);
|
||||
parent::__construct($appName, $request);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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 @@ class UserGlobalStoragesController extends StoragesController {
|
||||
IConfig $config,
|
||||
) {
|
||||
parent::__construct(
|
||||
$AppName,
|
||||
$appName,
|
||||
$request,
|
||||
$l10n,
|
||||
$userGlobalStoragesService,
|
||||
|
||||
@@ -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 @@ class UserStoragesController extends StoragesController {
|
||||
IConfig $config,
|
||||
) {
|
||||
parent::__construct(
|
||||
$AppName,
|
||||
$appName,
|
||||
$request,
|
||||
$l10n,
|
||||
$userStoragesService,
|
||||
|
||||
@@ -240,8 +240,8 @@ class ApiTest extends TestCase {
|
||||
|
||||
/**
|
||||
* @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 @@ class ApiTest extends TestCase {
|
||||
|
||||
/**
|
||||
* @medium
|
||||
* @dataProvider dataAllowFederationOnPublicShares
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('dataAllowFederationOnPublicShares')]
|
||||
public function testUpdateShareUpload(array $appConfig, int $permissions): void {
|
||||
$this->appConfig->method('getValueBool')->willReturnMap([
|
||||
$appConfig,
|
||||
|
||||
@@ -19,6 +19,7 @@ use OCP\IAppConfig;
|
||||
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 @@ class ExpireTrash extends TimedJob {
|
||||
}
|
||||
|
||||
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 @@ class ExpireTrash extends TimedJob {
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -64,9 +64,7 @@ class ExpireTrashTest extends TestCase {
|
||||
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);
|
||||
|
||||
@@ -16,11 +16,11 @@ use OCP\IRequest;
|
||||
|
||||
class AuthorizedGroupController extends Controller {
|
||||
public function __construct(
|
||||
string $AppName,
|
||||
string $appName,
|
||||
IRequest $request,
|
||||
private AuthorizedGroupService $authorizedGroupService,
|
||||
) {
|
||||
parent::__construct($AppName, $request);
|
||||
parent::__construct($appName, $request);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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 @@ class CheckSetupController extends Controller {
|
||||
private LoggerInterface $logger,
|
||||
private ISetupCheckManager $setupCheckManager,
|
||||
) {
|
||||
parent::__construct($AppName, $request);
|
||||
parent::__construct($appName, $request);
|
||||
$this->checker = $checker;
|
||||
}
|
||||
|
||||
|
||||
@@ -71,8 +71,6 @@
|
||||
<code><![CDATA[$result->authorId]]></code>
|
||||
<code><![CDATA[$result->authorId]]></code>
|
||||
<code><![CDATA[$result->authorId]]></code>
|
||||
<code><![CDATA[$result->fileId]]></code>
|
||||
<code><![CDATA[$result->fileId]]></code>
|
||||
<code><![CDATA[$result->name]]></code>
|
||||
<code><![CDATA[$result->path]]></code>
|
||||
</DeprecatedProperty>
|
||||
@@ -111,7 +109,6 @@
|
||||
<DeprecatedProperty>
|
||||
<code><![CDATA[$this->authorId]]></code>
|
||||
<code><![CDATA[$this->comment]]></code>
|
||||
<code><![CDATA[$this->fileId]]></code>
|
||||
<code><![CDATA[$this->fileName]]></code>
|
||||
<code><![CDATA[$this->path]]></code>
|
||||
</DeprecatedProperty>
|
||||
|
||||
@@ -77,6 +77,9 @@ $config = RectorConfig::configure()
|
||||
$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 @@ $config = RectorConfig::configure()
|
||||
'rename_property' => true,
|
||||
])
|
||||
->withSets([
|
||||
NextcloudSets::NEXTCLOUD_25,
|
||||
NextcloudSets::NEXTCLOUD_27,
|
||||
]);
|
||||
|
||||
$config->registerService(NextcloudNamespaceSkipVoter::class, tag:ClassNameImportSkipVoterInterface::class);
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
declare(strict_types=1);
|
||||
|
||||
use OCP\IConfig;
|
||||
use OCP\IURLGenerator;
|
||||
use OCP\Server;
|
||||
|
||||
/**
|
||||
@@ -100,7 +101,7 @@ try {
|
||||
$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(),
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -14,6 +14,7 @@ use OCP\AppFramework\Http\Attribute\FrontpageRoute;
|
||||
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 @@ class TwoFactorChallengeController extends Controller {
|
||||
/**
|
||||
* @TwoFactorSetUpDoneRequired
|
||||
*
|
||||
* @UserRateThrottle(limit=5, period=100)
|
||||
*
|
||||
* @param string $challengeProviderId
|
||||
* @param string $challenge
|
||||
@@ -161,6 +161,7 @@ class TwoFactorChallengeController extends Controller {
|
||||
#[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);
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Test\AppFramework\Middleware\Mock;
|
||||
|
||||
use OCP\AppFramework\Controller;
|
||||
use OCP\AppFramework\Http\Attribute\UseSession;
|
||||
|
||||
class UseSessionController extends Controller {
|
||||
/**
|
||||
* @UseSession
|
||||
*/
|
||||
public function withAnnotation() {
|
||||
}
|
||||
#[UseSession]
|
||||
public function withAttribute() {
|
||||
}
|
||||
public function without() {
|
||||
}
|
||||
}
|
||||
@@ -9,34 +9,13 @@ namespace Test\AppFramework\Middleware\Security;
|
||||
|
||||
use OC\AppFramework\Middleware\Security\BruteForceMiddleware;
|
||||
use OC\AppFramework\Utility\ControllerMethodReflector;
|
||||
use OCP\AppFramework\Controller;
|
||||
use OCP\AppFramework\Http\Attribute\BruteForceProtection;
|
||||
use OCP\AppFramework\Http\Response;
|
||||
use OCP\IRequest;
|
||||
use OCP\Security\Bruteforce\IThrottler;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Test\AppFramework\Middleware\Security\Mock\BruteForceMiddlewareController;
|
||||
use Test\TestCase;
|
||||
|
||||
class TestController extends Controller {
|
||||
/**
|
||||
* @BruteForceProtection(action=login)
|
||||
*/
|
||||
public function testMethodWithAnnotation() {
|
||||
}
|
||||
|
||||
public function testMethodWithoutAnnotation() {
|
||||
}
|
||||
|
||||
#[BruteForceProtection(action: 'single')]
|
||||
public function singleAttribute(): void {
|
||||
}
|
||||
|
||||
#[BruteForceProtection(action: 'first')]
|
||||
#[BruteForceProtection(action: 'second')]
|
||||
public function multipleAttributes(): void {
|
||||
}
|
||||
}
|
||||
|
||||
class BruteForceMiddlewareTest extends TestCase {
|
||||
/** @var ControllerMethodReflector */
|
||||
private $reflector;
|
||||
@@ -74,7 +53,7 @@ class BruteForceMiddlewareTest extends TestCase {
|
||||
->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 @@ class BruteForceMiddlewareTest extends TestCase {
|
||||
->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 @@ class BruteForceMiddlewareTest extends TestCase {
|
||||
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 @@ class BruteForceMiddlewareTest extends TestCase {
|
||||
->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 @@ class BruteForceMiddlewareTest extends TestCase {
|
||||
->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 @@ class BruteForceMiddlewareTest extends TestCase {
|
||||
->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 @@ class BruteForceMiddlewareTest extends TestCase {
|
||||
->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 @@ class BruteForceMiddlewareTest extends TestCase {
|
||||
$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 @@ class BruteForceMiddlewareTest extends TestCase {
|
||||
->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 @@ class BruteForceMiddlewareTest extends TestCase {
|
||||
->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 @@ class BruteForceMiddlewareTest extends TestCase {
|
||||
->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 @@ class BruteForceMiddlewareTest extends TestCase {
|
||||
|
||||
$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);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace Test\AppFramework\Middleware\Security\Mock;
|
||||
|
||||
use OCP\AppFramework\Controller;
|
||||
use OCP\AppFramework\Http\Attribute\BruteForceProtection;
|
||||
|
||||
class BruteForceMiddlewareController extends Controller {
|
||||
/**
|
||||
* @BruteForceProtection(action=login)
|
||||
*/
|
||||
public function testMethodWithAnnotation() {
|
||||
}
|
||||
|
||||
public function testMethodWithoutAnnotation() {
|
||||
}
|
||||
|
||||
#[BruteForceProtection(action: 'single')]
|
||||
public function singleAttribute(): void {
|
||||
}
|
||||
|
||||
#[BruteForceProtection(action: 'first')]
|
||||
#[BruteForceProtection(action: 'second')]
|
||||
public function multipleAttributes(): void {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace Test\AppFramework\Middleware\Security\Mock;
|
||||
|
||||
use OCP\AppFramework\Controller;
|
||||
use OCP\AppFramework\Http\Attribute\AnonRateLimit;
|
||||
use OCP\AppFramework\Http\Attribute\UserRateLimit;
|
||||
|
||||
class RateLimitingMiddlewareController extends Controller {
|
||||
/**
|
||||
* @UserRateThrottle(limit=20, period=200)
|
||||
* @AnonRateThrottle(limit=10, period=100)
|
||||
*/
|
||||
public function testMethodWithAnnotation() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @AnonRateThrottle(limit=10, period=100)
|
||||
*/
|
||||
public function testMethodWithAnnotationFallback() {
|
||||
}
|
||||
|
||||
public function testMethodWithoutAnnotation() {
|
||||
}
|
||||
|
||||
#[UserRateLimit(limit: 20, period: 200)]
|
||||
#[AnonRateLimit(limit: 10, period: 100)]
|
||||
public function testMethodWithAttributes() {
|
||||
}
|
||||
|
||||
#[AnonRateLimit(limit: 10, period: 100)]
|
||||
public function testMethodWithAttributesFallback() {
|
||||
}
|
||||
}
|
||||
@@ -14,9 +14,6 @@ use OC\AppFramework\Utility\ControllerMethodReflector;
|
||||
use OC\Security\Ip\BruteforceAllowList;
|
||||
use OC\Security\RateLimiting\Exception\RateLimitExceededException;
|
||||
use OC\Security\RateLimiting\Limiter;
|
||||
use OCP\AppFramework\Controller;
|
||||
use OCP\AppFramework\Http\Attribute\AnonRateLimit;
|
||||
use OCP\AppFramework\Http\Attribute\UserRateLimit;
|
||||
use OCP\AppFramework\Http\DataResponse;
|
||||
use OCP\AppFramework\Http\TemplateResponse;
|
||||
use OCP\IAppConfig;
|
||||
@@ -25,35 +22,9 @@ use OCP\ISession;
|
||||
use OCP\IUser;
|
||||
use OCP\IUserSession;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Test\AppFramework\Middleware\Security\Mock\RateLimitingMiddlewareController;
|
||||
use Test\TestCase;
|
||||
|
||||
class TestRateLimitController extends Controller {
|
||||
/**
|
||||
* @UserRateThrottle(limit=20, period=200)
|
||||
* @AnonRateThrottle(limit=10, period=100)
|
||||
*/
|
||||
public function testMethodWithAnnotation() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @AnonRateThrottle(limit=10, period=100)
|
||||
*/
|
||||
public function testMethodWithAnnotationFallback() {
|
||||
}
|
||||
|
||||
public function testMethodWithoutAnnotation() {
|
||||
}
|
||||
|
||||
#[UserRateLimit(limit: 20, period: 200)]
|
||||
#[AnonRateLimit(limit: 10, period: 100)]
|
||||
public function testMethodWithAttributes() {
|
||||
}
|
||||
|
||||
#[AnonRateLimit(limit: 10, period: 100)]
|
||||
public function testMethodWithAttributesFallback() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DB
|
||||
*/
|
||||
@@ -101,8 +72,8 @@ class RateLimitingMiddlewareTest extends TestCase {
|
||||
->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 @@ class RateLimitingMiddlewareTest extends TestCase {
|
||||
->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 @@ class RateLimitingMiddlewareTest extends TestCase {
|
||||
}
|
||||
|
||||
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 @@ class RateLimitingMiddlewareTest extends TestCase {
|
||||
}
|
||||
|
||||
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 @@ class RateLimitingMiddlewareTest extends TestCase {
|
||||
}
|
||||
|
||||
public function testBeforeControllerAttributesForAnon(): void {
|
||||
$controller = new TestRateLimitController('test', $this->request);
|
||||
$controller = new RateLimitingMiddlewareController('test', $this->request);
|
||||
|
||||
$this->request
|
||||
->method('getRemoteAddress')
|
||||
@@ -226,7 +197,7 @@ class RateLimitingMiddlewareTest extends TestCase {
|
||||
}
|
||||
|
||||
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 @@ class RateLimitingMiddlewareTest extends TestCase {
|
||||
}
|
||||
|
||||
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 @@ class RateLimitingMiddlewareTest extends TestCase {
|
||||
$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 @@ class RateLimitingMiddlewareTest extends TestCase {
|
||||
}
|
||||
|
||||
public function testAfterExceptionWithHtmlBody(): void {
|
||||
$controller = new TestRateLimitController('test', $this->request);
|
||||
$controller = new RateLimitingMiddlewareController('test', $this->request);
|
||||
$this->request
|
||||
->expects($this->once())
|
||||
->method('getHeader')
|
||||
|
||||
@@ -11,11 +11,11 @@ namespace Test\AppFramework\Middleware;
|
||||
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 @@ class SessionMiddlewareTest extends TestCase {
|
||||
|
||||
$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,
|
||||
|
||||
@@ -189,7 +189,7 @@ class QueryBuilderTest extends \Test\TestCase {
|
||||
|
||||
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 @@ class QueryBuilderTest extends \Test\TestCase {
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
@@ -212,7 +212,7 @@ class SystemTagObjectMapperTest extends TestCase {
|
||||
|
||||
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;
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user