Issue #2909952 by edwardaa: Flood MemoryBackend::isAllowed() throws exception: 'Undefined index: xxx'

8.5.x
Nathaniel Catchpole 2017-09-22 13:50:28 +01:00
parent 4577185c9b
commit 4e2d3ba4c8
2 changed files with 7 additions and 1 deletions

View File

@ -61,6 +61,9 @@ class MemoryBackend implements FloodInterface {
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;

View File

@ -34,8 +34,9 @@ class FloodTest extends WebTestBase {
$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 @@ class FloodTest extends WebTestBase {
$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 @@ class FloodTest extends WebTestBase {
$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.