public function BasicAuthTest::testGlobalLoginFloodControl in Drupal 8
Same name and namespace in other branches
- 9 core/modules/basic_auth/tests/src/Functional/BasicAuthTest.php \Drupal\Tests\basic_auth\Functional\BasicAuthTest::testGlobalLoginFloodControl()
Test the global login flood control.
File
- core/
modules/ basic_auth/ tests/ src/ Functional/ BasicAuthTest.php, line 97
Class
- BasicAuthTest
- Tests for BasicAuth authentication provider.
Namespace
Drupal\Tests\basic_auth\FunctionalCode
public function testGlobalLoginFloodControl() {
$this
->config('user.flood')
->set('ip_limit', 2)
->set('user_limit', 4000)
->save();
$user = $this
->drupalCreateUser([]);
$incorrect_user = clone $user;
$incorrect_user->pass_raw .= 'incorrect';
$url = Url::fromRoute('router_test.11');
// Try 2 failed logins.
for ($i = 0; $i < 2; $i++) {
$this
->basicAuthGet($url, $incorrect_user
->getAccountName(), $incorrect_user->pass_raw);
}
// IP limit has reached to its limit. Even valid user credentials will fail.
$this
->basicAuthGet($url, $user
->getAccountName(), $user->pass_raw);
$this
->assertSession()
->statusCodeEquals(403);
}