FloodTest.php in Username Enumeration Prevention 8
File
tests/src/Functional/FloodTest.php
View source
<?php
namespace Drupal\Tests\username_enumeration_prevention\Functional;
use Drupal\Core\Test\AssertMailTrait;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Tests\system\Functional\Cache\PageCacheTagsTestBase;
use Drupal\Tests\user\Traits\UserCreationTrait;
class FloodTest extends PageCacheTagsTestBase {
use AssertMailTrait {
getMails as drupalGetMails;
}
use UserCreationTrait;
use StringTranslationTrait;
public static $modules = [
'username_enumeration_prevention',
];
public function testUserResetPasswordIpFloodControl() {
\Drupal::configFactory()
->getEditable('user.flood')
->set('ip_limit', 3)
->save();
$name = 'foo';
$this
->createUser([], $name, FALSE, [
'mail' => 'foo@bar',
]);
for ($i = 0; $i < 3; $i++) {
$this
->drupalGet('user/password');
$edit = [
'name' => $name,
];
$this
->drupalPostForm(NULL, $edit, $this
->t('Submit'));
}
$this
->drupalGet('user/password');
$edit = [
'name' => $this
->randomMachineName(),
];
$this
->drupalPostForm(NULL, $edit, $this
->t('Submit'));
$this
->assertNoText($this
->t('Too many password recovery requests from your IP address. It is temporarily blocked. Try again later or contact the site administrator.'));
$mail = $this
->drupalGetMails();
$this
->assert(!empty($mail), "password reset mails were sent");
}
}
Classes
Name |
Description |
FloodTest |
Ensure flood protection works, despite lack of end-user feedback. |