Community Documentation

drupal_valid_test_ua

7 bootstrap.inc drupal_valid_test_ua()
8 bootstrap.inc drupal_valid_test_ua()

Returns the test prefix if this is an internal request from SimpleTest.

Return value

Either the simpletest prefix (the string "simpletest" followed by any number of digits) or FALSE if the user agent does not contain a valid HMAC and timestamp.

▾ 5 functions call drupal_valid_test_ua()

SimpleTestBrokenSetUp::setUp in modules/simpletest/simpletest.test
Generates a random database prefix, runs the install scripts on the prefixed database and enable the specified modules. After installation many caches are flushed and the internal browser is setup so that the page requests will run on the new prefix.…
SimpleTestBrokenSetUp::tearDown in modules/simpletest/simpletest.test
Delete created files and temporary files directory, delete the tables created by setUp(), and reset the database prefix.
SimpleTestBrokenSetUp::testBreakSetUp in modules/simpletest/simpletest.test
Runs this test case from within the simpletest child site.
SimpleTestFunctionalTest::inCURL in modules/simpletest/simpletest.test
Check if the test is being run from inside a CURL request.
_drupal_bootstrap_database in includes/bootstrap.inc
Initializes the database system and registers autoload functions.

File

includes/bootstrap.inc, line 2406
Functions that need to be loaded on every Drupal request.

Code

<?php
function drupal_valid_test_ua() {
  global $drupal_hash_salt;
  // No reason to reset this.
  static $test_prefix;

  if (isset($test_prefix)) {
    return $test_prefix;
  }

  if (isset($_SERVER['HTTP_USER_AGENT']) && preg_match("/^(simpletest\d+);(.+);(.+);(.+)$/", $_SERVER['HTTP_USER_AGENT'], $matches)) {
    list(, $prefix, $time, $salt, $hmac) = $matches;
    $check_string =  $prefix . ';' . $time . ';' . $salt;
    // We use the salt from settings.php to make the HMAC key, since
    // the database is not yet initialized and we can't access any Drupal variables.
    // The file properties add more entropy not easily accessible to others.
    $key = $drupal_hash_salt . filectime(__FILE__) . fileinode(__FILE__);
    $time_diff = REQUEST_TIME - $time;
    // Since we are making a local request a 5 second time window is allowed,
    // and the HMAC must match.
    if ($time_diff >= 0 && $time_diff <= 5 && $hmac == drupal_hmac_base64($check_string, $key)) {
      $test_prefix = $prefix;
      return $test_prefix;
    }
  }

  return FALSE;
}
?>
Login or register to post comments