Commit 2a4eab99 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #2771547 by Lendude, klausi, dawehner, alexpott, pwolanin: In Browser...

Issue #2771547 by Lendude, klausi, dawehner, alexpott, pwolanin: In Browser and FunctionalJavascript tests SIMPLETEST_USER_AGENT cookie needs to be set every 5 seconds

(cherry picked from commit ee38d6f7)
parent 3b755dce
Loading
Loading
Loading
Loading
+6 −2
Changes for core/includes/bootstrap.inc: 6 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -640,11 +640,15 @@ function drupal_valid_test_ua($new_prefix = NULL) {
    $key = $private_key . filectime(__FILE__) . fileinode(__FILE__);
    $time_diff = REQUEST_TIME - $time;
    $test_hmac = Crypt::hmacBase64($check_string, $key);
    // Since we are making a local request a 5 second time window is allowed,
    // Since we are making a local request a 600 second time window is allowed,
    // and the HMAC must match.
    if ($time_diff >= 0 && $time_diff <= 5 && $hmac === $test_hmac) {
    if ($time_diff >= 0 && $time_diff <= 600 && $hmac === $test_hmac) {
      $test_prefix = $prefix;
    }
    else {
      header($_SERVER['SERVER_PROTOCOL'] . ' 403 Forbidden (SIMPLETEST_USER_AGENT invalid)');
      exit;
    }
  }
  return $test_prefix;
}
+61 −0
Changes for core/tests/Drupal/FunctionalJavascriptTests/Core/Session/SessionTest.php: 61 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

namespace Drupal\FunctionalJavascriptTests\Core\Session;

use Drupal\FunctionalJavascriptTests\JavascriptTestBase;
use Drupal\menu_link_content\Entity\MenuLinkContent;

/**
 * Tests that sessions don't expire.
 *
 * @group session
 */
class SessionTest extends JavascriptTestBase {

  /**
   * {@inheritdoc}
   */
  public static $modules = ['menu_link_content', 'block'];

  /**
   * {@inheritdoc}
   */
  protected function setUp() {
    parent::setUp();

    $account = $this->drupalCreateUser();
    $this->drupalLogin($account);

    $menu_link_content = MenuLinkContent::create([
      'title' => 'Link to front page',
      'menu_name' => 'tools',
      'link' => ['uri' => 'route:<front>'],
    ]);
    $menu_link_content->save();

    $this->drupalPlaceBlock('system_menu_block:tools');
  }

  /**
   * Tests that the session doesn't expire.
   *
   * Makes sure that drupal_valid_test_ua() works for multiple requests
   * performed by the Mink browser. The SIMPLETEST_USER_AGENT cookie must always
   * be valid.
   */
  public function testSessionExpiration() {
    // Visit the front page and click the link back to the front page a large
    // number of times.
    $this->drupalGet('<front>');

    $session_assert = $this->assertSession();

    $page = $this->getSession()->getPage();

    for ($i = 0; $i < 25; $i++) {
      $page->clickLink('Link to front page');
      $session_assert->statusCodeEquals(200);
    }
  }

}