You are here

function SessionTest::testEmptySessionID in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/Session/SessionTest.php \Drupal\system\Tests\Session\SessionTest::testEmptySessionID()

Test that empty session IDs are not allowed.

File

core/modules/system/src/Tests/Session/SessionTest.php, line 266
Contains \Drupal\system\Tests\Session\SessionTest.

Class

SessionTest
Drupal session handling tests.

Namespace

Drupal\system\Tests\Session

Code

function testEmptySessionID() {
  $user = $this
    ->drupalCreateUser(array());
  $this
    ->drupalLogin($user);
  $this
    ->drupalGet('session-test/is-logged-in');
  $this
    ->assertResponse(200, 'User is logged in.');

  // Reset the sid in {sessions} to a blank string. This may exist in the
  // wild in some cases, although we normally prevent it from happening.
  db_query("UPDATE {sessions} SET sid = '' WHERE uid = :uid", array(
    ':uid' => $user
      ->id(),
  ));

  // Send a blank sid in the session cookie, and the session should no longer
  // be valid. Closing the curl handler will stop the previous session ID
  // from persisting.
  $this
    ->curlClose();
  $this->additionalCurlOptions[CURLOPT_COOKIE] = rawurlencode($this
    ->getSessionName()) . '=;';
  $this
    ->drupalGet('session-test/id-from-cookie');
  $this
    ->assertRaw("session_id:\n", 'Session ID is blank as sent from cookie header.');

  // Assert that we have an anonymous session now.
  $this
    ->drupalGet('session-test/is-logged-in');
  $this
    ->assertResponse(403, 'An empty session ID is not allowed.');
}