Skip to content

Commit

Permalink
fixup! fix(dav): Rate limit calendar/subscription creation
Browse files Browse the repository at this point in the history
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
  • Loading branch information
ChristophWurst committed Feb 22, 2024
1 parent 583cdb6 commit 4865c56
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
12 changes: 6 additions & 6 deletions apps/dav/lib/CalDAV/Security/RateLimitingPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
use OC\Security\RateLimiting\Limiter;
use OCA\DAV\CalDAV\CalDavBackend;
use OCA\DAV\Connector\Sabre\Exception\TooManyRequests;
use OCP\IAppConfig;
use OCP\IConfig;
use OCP\IUserManager;
use Psr\Log\LoggerInterface;
use Sabre\DAV;
Expand All @@ -43,15 +43,15 @@ class RateLimitingPlugin extends ServerPlugin {
private Limiter $limiter;
private IUserManager $userManager;
private CalDavBackend $calDavBackend;
private IAppConfig $config;
private IConfig $config;
private LoggerInterface $logger;
private ?string $userId;

public function __construct(Limiter $limiter,
IUserManager $userManager,
CalDavBackend $calDavBackend,
LoggerInterface $logger,
IAppConfig $config,
IConfig $config,
?string $userId) {
$this->limiter = $limiter;
$this->userManager = $userManager;
Expand Down Expand Up @@ -82,15 +82,15 @@ public function beforeBind(string $path): void {
try {
$this->limiter->registerUserRequest(
'caldav-create-calendar',
$this->config->getValueInt('dav', 'rateLimitCalendarCreation', 10),
$this->config->getValueInt('dav', 'rateLimitPeriodCalendarCreation', 3600),
(int) $this->config->getAppValue('dav', 'rateLimitCalendarCreation', '10'),
(int) $this->config->getAppValue('dav', 'rateLimitPeriodCalendarCreation', '3600'),
$user
);
} catch (RateLimitExceededException $e) {
throw new TooManyRequests('Too many calendars created', 0, $e);
}

$calendarLimit = $this->config->getValueInt('dav', 'maximumCalendarsSubscriptions', 30);
$calendarLimit = (int) $this->config->getAppValue('dav', 'maximumCalendarsSubscriptions', '30');
if ($calendarLimit === -1) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function testRegisterCalendarCreation(): void {
->with($this->userId)
->willReturn($user);
$this->config
->method('getValueInt')
->method('getAppValue')
->with('dav')
->willReturnArgument(2);
$this->limiter->expects(self::once())
Expand All @@ -114,7 +114,7 @@ public function testCalendarCreationRateLimitExceeded(): void {
->with($this->userId)
->willReturn($user);
$this->config
->method('getValueInt')
->method('getAppValue')
->with('dav')
->willReturnArgument(2);
$this->limiter->expects(self::once())
Expand All @@ -139,7 +139,7 @@ public function testCalendarLimitReached(): void {
->willReturn($user);
$user->method('getUID')->willReturn('user123');
$this->config
->method('getValueInt')
->method('getAppValue')
->with('dav')
->willReturnArgument(2);
$this->limiter->expects(self::once())
Expand Down

0 comments on commit 4865c56

Please sign in to comment.