You are here

function BasicAuthTest::testGlobalLoginFloodControl in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/basic_auth/src/Tests/Authentication/BasicAuthTest.php \Drupal\basic_auth\Tests\Authentication\BasicAuthTest::testGlobalLoginFloodControl()

Test the global login flood control.

File

core/modules/basic_auth/src/Tests/Authentication/BasicAuthTest.php, line 83
Contains \Drupal\basic_auth\Tests\Authentication\BasicAuthTest.

Class

BasicAuthTest
Tests for BasicAuth authentication provider.

Namespace

Drupal\basic_auth\Tests\Authentication

Code

function testGlobalLoginFloodControl() {
  $this
    ->config('user.flood')
    ->set('ip_limit', 2)
    ->set('user_limit', 4000)
    ->save();
  $user = $this
    ->drupalCreateUser(array());
  $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
      ->getUsername(), $incorrect_user->pass_raw);
  }

  // IP limit has reached to its limit. Even valid user credentials will fail.
  $this
    ->basicAuthGet($url, $user
    ->getUsername(), $user->pass_raw);
  $this
    ->assertResponse('403', 'Access is blocked because of IP based flood prevention.');
}