function BasicAuthTest::testGlobalLoginFloodControl

Same name in other branches
  1. 8.9.x core/modules/basic_auth/tests/src/Functional/BasicAuthTest.php \Drupal\Tests\basic_auth\Functional\BasicAuthTest::testGlobalLoginFloodControl()
  2. 10 core/modules/basic_auth/tests/src/Functional/BasicAuthTest.php \Drupal\Tests\basic_auth\Functional\BasicAuthTest::testGlobalLoginFloodControl()
  3. 11.x core/modules/basic_auth/tests/src/Functional/BasicAuthTest.php \Drupal\Tests\basic_auth\Functional\BasicAuthTest::testGlobalLoginFloodControl()

Tests the global login flood control.

File

core/modules/basic_auth/tests/src/Functional/BasicAuthTest.php, line 96

Class

BasicAuthTest
Tests for BasicAuth authentication provider.

Namespace

Drupal\Tests\basic_auth\Functional

Code

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);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.