Commit 4e2d3ba4 authored by catch's avatar catch

Issue #2909952 by edwardaa: Flood MemoryBackend::isAllowed() throws exception:...

Issue #2909952 by edwardaa: Flood MemoryBackend::isAllowed() throws exception: 'Undefined index: xxx'
parent 4577185c
......@@ -61,6 +61,9 @@ public function isAllowed($name, $threshold, $window = 3600, $identifier = NULL)
if (!isset($identifier)) {
$identifier = $this->requestStack->getCurrentRequest()->getClientIp();
}
if (!isset($this->events[$name][$identifier])) {
return $threshold > 0;
}
$limit = microtime(TRUE) - $window;
$number = count(array_filter($this->events[$name][$identifier], function ($timestamp) use ($limit) {
return $timestamp > $limit;
......
......@@ -34,8 +34,9 @@ public function testCleanUp() {
$window_expired = -1;
$name = 'flood_test_cleanup';
// Register expired event.
$flood = \Drupal::flood();
$this->assertTrue($flood->isAllowed($name, $threshold));
// Register expired event.
$flood->register($name, $window_expired);
// Verify event is not allowed.
$this->assertFalse($flood->isAllowed($name, $threshold));
......@@ -62,6 +63,7 @@ public function testMemoryBackend() {
$request_stack = \Drupal::service('request_stack');
$flood = new MemoryBackend($request_stack);
$this->assertTrue($flood->isAllowed($name, $threshold));
// Register expired event.
$flood->register($name, $window_expired);
// Verify event is not allowed.
......@@ -90,6 +92,7 @@ public function testDatabaseBackend() {
$connection = \Drupal::service('database');
$request_stack = \Drupal::service('request_stack');
$flood = new DatabaseBackend($connection, $request_stack);
$this->assertTrue($flood->isAllowed($name, $threshold));
// Register expired event.
$flood->register($name, $window_expired);
// Verify event is not allowed.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment