You are here

public function LoginTest::testBlacklist in Lightweight Directory Access Protocol (LDAP) 8.4

Test the blacklist.

DN contains "hogwarts", case-insensitive check is made. Error is only shown in exclusive mode (since Drupal could still allow it).

File

ldap_authentication/tests/src/Kernel/LoginTest.php, line 209

Class

LoginTest
Login tests.

Namespace

Drupal\Tests\ldap_authentication\Kernel

Code

public function testBlacklist() : void {
  $this
    ->config('ldap_authentication.settings')
    ->set('excludeIfTextInDn', [
    'Hogwarts',
  ])
    ->set('authenticationMode', 'exclusive')
    ->save();
  $this->container
    ->get('config.factory')
    ->reset();
  $form_state = new FormState();
  $form_state
    ->setValues([
    'name' => 'hpotter',
    'pass' => 'pass',
  ]);
  $this->validator
    ->validateLogin($form_state);

  /** @var \Drupal\Core\Messenger\MessengerInterface $messenger */
  $messenger = $this->container
    ->get('messenger');
  $messenger_errors = $messenger
    ->messagesByType(MessengerInterface::TYPE_ERROR);
  self::assertCount(1, $messenger_errors);
  self::assertCount(0, $this->container
    ->get('entity_type.manager')
    ->getStorage('user')
    ->loadMultiple());
}