You are here

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

Test the whitelist.

File

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

Class

LoginTest
Login tests.

Namespace

Drupal\Tests\ldap_authentication\Kernel

Code

public function testWhiteListMissing() : void {
  $this
    ->config('ldap_authentication.settings')
    ->set('allowOnlyIfTextInDn', [
    'HGRANGER',
  ])
    ->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());
}