Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorLukas Reschke <lukas@statuscode.ch>2021-09-06 18:31:36 +0300
committerLukas Reschke <lukas@statuscode.ch>2021-09-06 18:31:36 +0300
commit378cc922c429524b872e83c7b3842eb86bc4b770 (patch)
treedbb0e7ef8ab4d859f8f8d7c71155c5a50bd660b3 /tests
parentd4f97affc1a0ecfaacfbdc26aab820cad1650a06 (diff)
Adjust logic to store period instead of current timestamp
Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/Security/RateLimiting/Backend/MemoryCacheBackendTest.php (renamed from tests/lib/Security/RateLimiting/Backend/MemoryCacheTest.php)14
-rw-r--r--tests/lib/Security/RateLimiting/LimiterTest.php13
2 files changed, 7 insertions, 20 deletions
diff --git a/tests/lib/Security/RateLimiting/Backend/MemoryCacheTest.php b/tests/lib/Security/RateLimiting/Backend/MemoryCacheBackendTest.php
index ff58bd5c09e..8bbf88e8a8e 100644
--- a/tests/lib/Security/RateLimiting/Backend/MemoryCacheTest.php
+++ b/tests/lib/Security/RateLimiting/Backend/MemoryCacheBackendTest.php
@@ -24,20 +24,20 @@ declare(strict_types=1);
namespace Test\Security\RateLimiting\Backend;
-use OC\Security\RateLimiting\Backend\MemoryCache;
+use OC\Security\RateLimiting\Backend\MemoryCacheBackend;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\ICache;
use OCP\ICacheFactory;
use Test\TestCase;
-class MemoryCacheTest extends TestCase {
+class MemoryCacheBackendTest extends TestCase {
/** @var ICacheFactory|\PHPUnit\Framework\MockObject\MockObject */
private $cacheFactory;
/** @var ITimeFactory|\PHPUnit\Framework\MockObject\MockObject */
private $timeFactory;
/** @var ICache|\PHPUnit\Framework\MockObject\MockObject */
private $cache;
- /** @var MemoryCache */
+ /** @var MemoryCacheBackend */
private $memoryCache;
protected function setUp(): void {
@@ -50,10 +50,10 @@ class MemoryCacheTest extends TestCase {
$this->cacheFactory
->expects($this->once())
->method('createDistributed')
- ->with('OC\Security\RateLimiting\Backend\MemoryCache')
+ ->with('OC\Security\RateLimiting\Backend\MemoryCacheBackend')
->willReturn($this->cache);
- $this->memoryCache = new MemoryCache(
+ $this->memoryCache = new MemoryCacheBackend(
$this->cacheFactory,
$this->timeFactory
);
@@ -66,7 +66,7 @@ class MemoryCacheTest extends TestCase {
->with('eea460b8d756885099c7f0a4c083bf6a745069ee4a301984e726df58fd4510bffa2dac4b7fd5d835726a6753ffa8343ba31c7e902bbef78fc68c2e743667cb4b')
->willReturn(null);
- $this->assertSame(0, $this->memoryCache->getAttempts('Method', 'User', 123));
+ $this->assertSame(0, $this->memoryCache->getAttempts('Method', 'User'));
}
public function testGetAttempts() {
@@ -87,7 +87,7 @@ class MemoryCacheTest extends TestCase {
'124',
]));
- $this->assertSame(3, $this->memoryCache->getAttempts('Method', 'User', 123));
+ $this->assertSame(3, $this->memoryCache->getAttempts('Method', 'User'));
}
public function testRegisterAttemptWithNoAttemptsBefore() {
diff --git a/tests/lib/Security/RateLimiting/LimiterTest.php b/tests/lib/Security/RateLimiting/LimiterTest.php
index 8b3509a4790..31c877cbda3 100644
--- a/tests/lib/Security/RateLimiting/LimiterTest.php
+++ b/tests/lib/Security/RateLimiting/LimiterTest.php
@@ -26,13 +26,10 @@ namespace Test\Security\RateLimiting;
use OC\Security\RateLimiting\Backend\IBackend;
use OC\Security\RateLimiting\Limiter;
-use OCP\AppFramework\Utility\ITimeFactory;
use OCP\IUser;
use Test\TestCase;
class LimiterTest extends TestCase {
- /** @var ITimeFactory|\PHPUnit\Framework\MockObject\MockObject */
- private $timeFactory;
/** @var IBackend|\PHPUnit\Framework\MockObject\MockObject */
private $backend;
/** @var Limiter */
@@ -41,11 +38,9 @@ class LimiterTest extends TestCase {
protected function setUp(): void {
parent::setUp();
- $this->timeFactory = $this->createMock(ITimeFactory::class);
$this->backend = $this->createMock(IBackend::class);
$this->limiter = new Limiter(
- $this->timeFactory,
$this->backend
);
}
@@ -69,10 +64,6 @@ class LimiterTest extends TestCase {
}
public function testRegisterAnonRequestSuccess() {
- $this->timeFactory
- ->expects($this->once())
- ->method('getTime')
- ->willReturn(2000);
$this->backend
->expects($this->once())
->method('getAttempts')
@@ -126,10 +117,6 @@ class LimiterTest extends TestCase {
->method('getUID')
->willReturn('MyUid');
- $this->timeFactory
- ->expects($this->once())
- ->method('getTime')
- ->willReturn(2000);
$this->backend
->expects($this->once())
->method('getAttempts')