Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions lib/private/Security/RateLimiting/Limiter.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@
use OC\Security\RateLimiting\Backend\IBackend;
use OC\Security\RateLimiting\Exception\RateLimitExceededException;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\IRequest;
use OCP\IUser;
use OCP\IUserSession;

class Limiter {
/** @var IBackend */
Expand All @@ -39,14 +37,10 @@ class Limiter {
private $timeFactory;

/**
* @param IUserSession $userSession
* @param IRequest $request
* @param ITimeFactory $timeFactory
* @param IBackend $backend
*/
public function __construct(IUserSession $userSession,
IRequest $request,
ITimeFactory $timeFactory,
public function __construct(ITimeFactory $timeFactory,
IBackend $backend) {
$this->backend = $backend;
$this->timeFactory = $timeFactory;
Expand All @@ -62,7 +56,7 @@ public function __construct(IUserSession $userSession,
private function register(string $methodIdentifier,
string $userIdentifier,
int $period,
int $limit) {
int $limit): void {
$existingAttempts = $this->backend->getAttempts($methodIdentifier, $userIdentifier, $period);
if ($existingAttempts >= $limit) {
throw new RateLimitExceededException();
Expand All @@ -83,7 +77,7 @@ private function register(string $methodIdentifier,
public function registerAnonRequest(string $identifier,
int $anonLimit,
int $anonPeriod,
string $ip) {
string $ip): void {
$ipSubnet = (new IpAddress($ip))->getSubnet();

$anonHashIdentifier = hash('sha512', 'anon::' . $identifier . $ipSubnet);
Expand All @@ -102,7 +96,7 @@ public function registerAnonRequest(string $identifier,
public function registerUserRequest(string $identifier,
int $userLimit,
int $userPeriod,
IUser $user) {
IUser $user): void {
$userHashIdentifier = hash('sha512', 'user::' . $identifier . $user->getUID());
$this->register($identifier, $userHashIdentifier, $userPeriod, $userLimit);
}
Expand Down
8 changes: 0 additions & 8 deletions lib/private/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -597,14 +597,6 @@ public function __construct($webRoot, \OC\Config $config) {
});
$this->registerAlias('Search', \OCP\ISearch::class);

$this->registerService(\OC\Security\RateLimiting\Limiter::class, function (Server $c) {
return new \OC\Security\RateLimiting\Limiter(
$this->getUserSession(),
$this->getRequest(),
new \OC\AppFramework\Utility\TimeFactory(),
$c->query(\OC\Security\RateLimiting\Backend\IBackend::class)
);
});
$this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) {
return new \OC\Security\RateLimiting\Backend\MemoryCache(
$this->getMemCacheFactory(),
Expand Down
8 changes: 0 additions & 8 deletions tests/lib/Security/RateLimiting/LimiterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@
use Test\TestCase;

class LimiterTest extends TestCase {
/** @var IUserSession|\PHPUnit_Framework_MockObject_MockObject */
private $userSession;
/** @var IRequest|\PHPUnit_Framework_MockObject_MockObject */
private $request;
/** @var ITimeFactory|\PHPUnit_Framework_MockObject_MockObject */
private $timeFactory;
/** @var IBackend|\PHPUnit_Framework_MockObject_MockObject */
Expand All @@ -45,14 +41,10 @@ class LimiterTest extends TestCase {
public function setUp() {
parent::setUp();

$this->userSession = $this->createMock(IUserSession::class);
$this->request = $this->createMock(IRequest::class);
$this->timeFactory = $this->createMock(ITimeFactory::class);
$this->backend = $this->createMock(IBackend::class);

$this->limiter = new Limiter(
$this->userSession,
$this->request,
$this->timeFactory,
$this->backend
);
Expand Down