You are here

public function SamlTest::testDrupalLoginNotAllowed in SAML Authentication 8

Same name and namespace in other branches
  1. 8.2 src/Tests/SamlTest.php \Drupal\samlauth\Tests\SamlTest::testDrupalLoginNotAllowed()

Test that Drupal login is not allowed for SAML users when configured.

This test relies on implicit behavior. The drupal_saml_login option is disabled by default.

File

src/Tests/SamlTest.php, line 100
Simpletests for samlauth functionality.

Class

SamlTest
Tests SAML authentication.

Namespace

Drupal\samlauth\Tests

Code

public function testDrupalLoginNotAllowed() {

  // Create a user.
  $saml_user = $this
    ->createUser();

  // Manually set the SAML ID (this would normally be done by mapping or creating saml users)
  \Drupal::service('user.data')
    ->set('samlauth', $saml_user
    ->id(), 'saml_id', '12345');
  $edit = array(
    'name' => $saml_user
      ->getUsername(),
    'pass' => $saml_user->pass_raw,
  );
  $this
    ->drupalPostForm('user/login', $edit, t('Log in'));
  $this
    ->assert(!$this
    ->drupalUserIsLoggedIn($saml_user), 'SAML user is not logged in.');
  $this
    ->assertText('SAML users must sign in with SSO', 'Error is displayed to the user.');
}