You are here

public function SamlTest::testLoginNotAllowed in SAML Authentication 8.2

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

Test login without mapping or user creation.

File

src/Tests/SamlTest.php, line 65

Class

SamlTest
Tests SAML authentication.

Namespace

Drupal\samlauth\Tests

Code

public function testLoginNotAllowed() {

  // Ensure that this test is run as an anonymous user.
  if ($this->loggedInUser) {
    $this
      ->drupalLogout();
  }

  // Since the SP is properly configured (done in setUp()), this should be a
  // redirect.
  $this
    ->drupalGet('saml/login');
  $url = Url::fromUri('https://idp.testshib.org:443/idp/Authn/UserPassword');
  $this
    ->assertUrl($url, [], 'Correct iDP page loaded');
  $this
    ->assertResponse(200, 'iDP page loaded successfully');

  // Submit the login form with the testshib credentials.
  $this
    ->drupalPost('https://idp.testshib.org/idp/Authn/UserPassword', '*', array(
    'j_username' => 'myself',
    'j_password' => 'myself',
  ));

  // When mapping and creation aren't enabled, users are taken to user/login.
  // @todo the return url tests aren't quite working yet. missing state on the iDP? might need to store JSESSIONID and _idp_authn_lc_key cookies?
  //    $url = Url::fromRoute('user.page');
  //    $this->assertUrl($url, [], 'User was redirected to user/login after iDP authentication.');
  //    $this->assertText('No existing user account matches the SAML ID provided', 'Error message was displayed to the user.');
}