diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index e1c15fe..673648a 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -429,6 +429,11 @@ function conf_path($require_settings = TRUE, $reset = FALSE) { if ($conf && !$reset) { return $conf; } + // Keep the conf_path alive across drupal_static_reset() calls. + if (class_exists('Drupal\Component\Utility\Settings') && ($simpletest_conf_path = settings()->get('simpletest_conf_path')) && drupal_valid_test_ua()) { + $conf = $simpletest_conf_path; + return $conf; + } $script_name = $_SERVER['SCRIPT_NAME']; if (!$script_name) { @@ -517,11 +522,7 @@ function find_conf_path($http_host, $script_name, $require_settings = TRUE) { function config_get_config_directory($type = CONFIG_ACTIVE_DIRECTORY) { global $config_directories; - if ($test_prefix = drupal_valid_test_ua()) { - // @see Drupal\simpletest\WebTestBase::setUp() - $path = conf_path() . '/files/simpletest/' . substr($test_prefix, 10) . '/config_' . $type; - } - elseif (!empty($config_directories[$type])) { + if (!empty($config_directories[$type])) { // Allow a configuration directory path to be outside of webroot. if (empty($config_directories[$type]['absolute'])) { $path = conf_path() . '/files/' . $config_directories[$type]['path']; @@ -2596,8 +2597,8 @@ function drupal_valid_test_ua($new_prefix = NULL) { return $test_prefix; } - if (isset($_SERVER['HTTP_USER_AGENT']) && preg_match("/^(simpletest\d+);(.+);(.+);(.+)$/", $_SERVER['HTTP_USER_AGENT'], $matches)) { - list(, $prefix, $time, $salt, $hmac) = $matches; + if (isset($_SERVER['HTTP_USER_AGENT']) && preg_match("/^(simpletest\d+);(.+);(.+);(.+)([YN])$/", $_SERVER['HTTP_USER_AGENT'], $matches)) { + list(, $prefix, $time, $salt, $hmac, $config) = $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. @@ -2608,6 +2609,7 @@ function drupal_valid_test_ua($new_prefix = NULL) { // and the HMAC must match. if ($time_diff >= 0 && $time_diff <= 5 && $hmac == drupal_hmac_base64($check_string, $key)) { $test_prefix = $prefix; + _drupal_load_test_overrides($test_prefix, $config); return $test_prefix; } } @@ -2617,9 +2619,50 @@ function drupal_valid_test_ua($new_prefix = NULL) { } /** + * Overrides low level and environment specific configuration. + * + * Very strictly for internal use only. + * + * Loads settings.php from the simpletest public files + * directory. These files can change the global $conf, the global + * $config_directories, the return value of conf_path() and + * settings(). + * + * @param $test_prefix + * The simpletest prefix. + * @param $config + * Y to use config_active/config_staging directories inside the simpletest + * directory as config directories. N to start with empty + * $config_directories. + */ +function _drupal_load_test_overrides($test_prefix, $config) { + global $conf, $config_directories; + $path_prefix = 'simpletest/' . substr($test_prefix, 10); + if ($config === 'Y') { + foreach (array(CONFIG_ACTIVE_DIRECTORY, CONFIG_STAGING_DIRECTORY) as $type) { + $config_directories[$type] = array('path' => $path_prefix . '/config_' . $type); + } + } + else { + $config_directories = array(); + } + $filename = conf_path() . '/files/' . $path_prefix . '/settings.php'; + if (file_exists($filename)) { + $settings = settings()->getAll(); + $conf_path = &drupal_static('conf_path'); + // This can override $conf, $conf_path, $settings and + // $config_directories + include $filename; + // Keep the conf_path alive across drupal_static_reset() calls. + $settings['simpletest_conf_path'] = $conf_path; + new Settings($settings); + } +} + +/** * Generates a user agent string with a HMAC and timestamp for simpletest. */ -function drupal_generate_test_ua($prefix) { +function drupal_generate_test_ua($prefix, $config = TRUE) { global $drupal_hash_salt; static $key; @@ -2632,7 +2675,7 @@ function drupal_generate_test_ua($prefix) { // Generate a moderately secure HMAC based on the database credentials. $salt = uniqid('', TRUE); $check_string = $prefix . ';' . time() . ';' . $salt; - return $check_string . ';' . drupal_hmac_base64($check_string, $key); + return $check_string . ';' . drupal_hmac_base64($check_string, $key) . ($config ? 'Y' : 'N'); } /** diff --git a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php index 5cca38a..119c148 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php @@ -157,6 +157,15 @@ protected $kernel; /** + * Whether the config directories are pregenerated. + * + * @var bool + * Set to FALSE if you want the child Drupal to not use the pregenerated + * config directory path. + */ + protected $pregeneratedConfigDirectories = TRUE; + + /** * Constructor for Drupal\simpletest\WebTestBase. */ function __construct($test_id = NULL) { @@ -959,7 +968,7 @@ protected function curlInitialize() { // We set the user agent header on each request so as to use the current // time and a new uniqid. if (preg_match('/simpletest\d+/', $this->databasePrefix, $matches)) { - curl_setopt($this->curlHandle, CURLOPT_USERAGENT, drupal_generate_test_ua($matches[0])); + curl_setopt($this->curlHandle, CURLOPT_USERAGENT, drupal_generate_test_ua($matches[0], $this->pregeneratedConfigDirectories)); } } diff --git a/core/modules/system/lib/Drupal/system/Tests/Upgrade/BareMinimalAnonymousUpgradePathTest.php b/core/modules/system/lib/Drupal/system/Tests/Upgrade/BareMinimalAnonymousUpgradePathTest.php new file mode 100644 index 0000000..6299c57 --- /dev/null +++ b/core/modules/system/lib/Drupal/system/Tests/Upgrade/BareMinimalAnonymousUpgradePathTest.php @@ -0,0 +1,42 @@ + 'Basic minimal profile upgrade, free access', + 'description' => 'Basic upgrade path tests for a minimal profile install with a bare database and update_free_access set to TRUE.', + 'group' => 'Upgrade path', + ); + } + + /** + * Overrides \Drupal\system\Tests\Upgrade\UpgradePathTestBase::prepareD8Session(). + */ + protected function prepareD8Session() { + $new_settings['settings']['update_free_access'] = (object) array( + 'value' => TRUE, + 'required' => TRUE, + ); + include_once DRUPAL_ROOT . '/core/includes/install.inc'; + $filename = $this->public_files_directory . '/settings.php'; + file_put_contents($filename, " 'Basic minimal profile upgrade, no config', + 'description' => 'Basic upgrade path tests for a minimal profile install with a bare database and config directory not pre-created.', + 'group' => 'Upgrade path', + ); + } + + /** + * Overrides \Drupal\system\Tests\Upgrade\UpgradePathTestBase::prepareConfigDirectories(). + */ + protected function prepareConfigDirectories() { + $new_settings['conf_path'] = (object) array( + 'value' => $this->public_files_directory, + 'required' => TRUE, + ); + include_once DRUPAL_ROOT . '/core/includes/install.inc'; + $filename = $this->public_files_directory . '/settings.php'; + file_put_contents($filename, "pregeneratedConfigDirectories = FALSE; + } + + /** + * Overrides \Drupal\system\Tests\Upgrade\UpgradePathTestBase::refreshVariables(). + */ + protected function refreshVariables() { + // Refresh the variables only if the site was already upgraded. + if ($this->upgradedSite) { + // update.php puts the new, randomized config directries in this file. + include $this->public_files_directory . '/settings.php'; + $GLOBALS['config_directories'] = array(); + foreach ($config_directories as $type => $data) { + $GLOBALS['config_directories'][$type]['path'] = 'simpletest/' . substr($this->databasePrefix, 10) . '/files/' . $data['path']; + } + parent::refreshVariables(); + } + } + +} diff --git a/core/modules/system/lib/Drupal/system/Tests/Upgrade/BareMinimalUpgradePathTest.php b/core/modules/system/lib/Drupal/system/Tests/Upgrade/BareMinimalUpgradePathTest.php index 9c51bee..1156616 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Upgrade/BareMinimalUpgradePathTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Upgrade/BareMinimalUpgradePathTest.php @@ -2,7 +2,7 @@ /** * @file - * Definition of Drupal\system\Tests\Upgrade\BareMinimalUpgradePathTest. + * Contains \Drupal\system\Tests\Upgrade\BareMinimalUpgradePathTest. */ namespace Drupal\system\Tests\Upgrade; @@ -43,12 +43,7 @@ public function testBasicMinimalUpgrade() { $this->assertResponse(200); // Verify that we are still logged in. - $this->drupalGet('user'); - $this->clickLink(t('Edit')); - $this->assertEqual($this->getUrl(), url('user/1/edit', array('absolute' => TRUE)), 'We are still logged in as admin at the end of the upgrade.'); - - // Logout and verify that we can login back in with our initial password. - $this->drupalLogout(); + $this->assertSessionKept(); $this->drupalLogin((object) array( 'uid' => 1, 'name' => 'admin', @@ -95,4 +90,14 @@ public function testBasicMinimalUpgrade() { $this->assertEqual(array('default' => 'Drupal\Core\Mail\PhpMail'), config('system.mail')->get('interface'), 'Default mail configuration set.'); } + /** + * Asserts that the session was kept during update. Also, log out. + */ + protected function assertSessionKept() { + $this->drupalGet('user'); + $this->clickLink(t('Edit')); + $this->assertEqual($this->getUrl(), url('user/1/edit', array('absolute' => TRUE)), 'We are still logged in as admin at the end of the upgrade.'); + $this->drupalLogout(); + } + }