From cb293142ff3f20ad0e60c3f55cbea115af705e14 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 1 Dec 2023 16:17:43 +0100 Subject: [PATCH] fix(API): Remove unused variables and deprecated methods Signed-off-by: Joas Schilling --- lib/Controller/SignalingController.php | 4 ---- lib/Middleware/InjectionMiddleware.php | 7 ++++++- tests/php/Controller/SignalingControllerTest.php | 3 --- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/Controller/SignalingController.php b/lib/Controller/SignalingController.php index 050e62b54cf..cd8af6022f4 100644 --- a/lib/Controller/SignalingController.php +++ b/lib/Controller/SignalingController.php @@ -54,12 +54,10 @@ use OCP\DB\Exception; use OCP\EventDispatcher\IEventDispatcher; use OCP\Http\Client\IClientService; -use OCP\IConfig; use OCP\IDBConnection; use OCP\IRequest; use OCP\IUser; use OCP\IUserManager; -use OCP\Security\Bruteforce\IThrottler; use Psr\Log\LoggerInterface; /** @@ -76,7 +74,6 @@ class SignalingController extends OCSController { public function __construct( string $appName, IRequest $request, - IConfig $serverConfig, private Config $talkConfig, private \OCA\Talk\Signaling\Manager $signalingManager, private TalkSession $session, @@ -90,7 +87,6 @@ public function __construct( private IEventDispatcher $dispatcher, private ITimeFactory $timeFactory, private IClientService $clientService, - IThrottler $throttler, private LoggerInterface $logger, private ?string $userId, ) { diff --git a/lib/Middleware/InjectionMiddleware.php b/lib/Middleware/InjectionMiddleware.php index 0c0a939038d..7f48a4eaccf 100644 --- a/lib/Middleware/InjectionMiddleware.php +++ b/lib/Middleware/InjectionMiddleware.php @@ -57,6 +57,7 @@ use OCP\Federation\ICloudIdManager; use OCP\IRequest; use OCP\Security\Bruteforce\IThrottler; +use OCP\Security\Bruteforce\MaxDelayReached; class InjectionMiddleware extends Middleware { protected bool $isTalkFederation = false; @@ -316,7 +317,11 @@ public function afterException($controller, $methodName, \Exception $exception): $action = $protection->getAction(); if ('talkRoomToken' === $action) { - $this->throttler->sleepDelay($this->request->getRemoteAddress(), $action); + try { + $this->throttler->sleepDelayOrThrowOnMax($this->request->getRemoteAddress(), $action); + } catch (MaxDelayReached $e) { + throw new OCSException($e->getMessage(), Http::STATUS_TOO_MANY_REQUESTS); + } $this->throttler->registerAttempt($action, $this->request->getRemoteAddress(), [ 'token' => $this->request->getParam('token') ?? '', ]); diff --git a/tests/php/Controller/SignalingControllerTest.php b/tests/php/Controller/SignalingControllerTest.php index 965ab1e9742..1ea95c5f1d1 100644 --- a/tests/php/Controller/SignalingControllerTest.php +++ b/tests/php/Controller/SignalingControllerTest.php @@ -136,7 +136,6 @@ public function setUp(): void { $this->messages = $this->createMock(Messages::class); $this->timeFactory = $this->createMock(ITimeFactory::class); $this->clientService = $this->createMock(IClientService::class); - $this->throttler = $this->createMock(IThrottler::class); $this->logger = $this->createMock(LoggerInterface::class); $this->recreateSignalingController(); } @@ -145,7 +144,6 @@ private function recreateSignalingController() { $this->controller = new CustomInputSignalingController( 'spreed', $this->createMock(IRequest::class), - $this->serverConfig, $this->config, $this->signalingManager, $this->session, @@ -159,7 +157,6 @@ private function recreateSignalingController() { $this->dispatcher, $this->timeFactory, $this->clientService, - $this->throttler, $this->logger, $this->userId );